snmp_mib_module.c
Go to the documentation of this file.
1 /**
2  * @file snmp_mib_module.c
3  * @brief SNMP MIB module
4  *
5  * @section License
6  *
7  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @section Description
26  *
27  * The SNMP-MIB describes managed objects which describe the behavior
28  * of an SNMP entity. Refer to RFC 3418 for more details
29  *
30  * @author Oryx Embedded SARL (www.oryx-embedded.com)
31  * @version 1.9.0
32  **/
33 
34 //Switch to the appropriate trace level
35 #define TRACE_LEVEL SNMP_TRACE_LEVEL
36 
37 //Dependencies
38 #include "core/net.h"
39 #include "mibs/mib_common.h"
40 #include "mibs/snmp_mib_module.h"
41 #include "mibs/snmp_mib_impl.h"
42 #include "core/crypto.h"
43 #include "encoding/asn1.h"
44 #include "encoding/oid.h"
45 #include "debug.h"
46 
47 //Check TCP/IP stack configuration
48 #if (SNMP_MIB_SUPPORT == ENABLED)
49 
50 
51 /**
52  * @brief SNMP MIB base
53  **/
54 
56 
57 
58 /**
59  * @brief SNMP MIB objects
60  **/
61 
63 {
64  //sysDescr object (1.3.6.1.2.1.1.1)
65  {
66  "sysDescr",
67  {43, 6, 1, 2, 1, 1, 1},
68  7,
72 #if (SNMP_MIB_SYS_DESCR_SIZE > 0)
76  NULL,
77  NULL,
78  NULL
79 #else
80  NULL,
81  NULL,
82  0,
83  NULL,
85  NULL
86 #endif
87  },
88  //sysObjectID object (1.3.6.1.2.1.1.2)
89  {
90  "sysObjectID",
91  {43, 6, 1, 2, 1, 1, 2},
92  7,
96 #if (SNMP_MIB_SYS_OBJECT_ID_SIZE > 0)
100  NULL,
101  NULL,
102  NULL
103 #else
104  NULL,
105  NULL,
106  0,
107  NULL,
109  NULL
110 #endif
111  },
112  //sysUpTime object (1.3.6.1.2.1.1.3)
113  {
114  "sysUpTime",
115  {43, 6, 1, 2, 1, 1, 3},
116  7,
120  NULL,
121  NULL,
122  sizeof(uint32_t),
123  NULL,
125  NULL
126  },
127  //sysContact object (1.3.6.1.2.1.1.4)
128  {
129  "sysContact",
130  {43, 6, 1, 2, 1, 1, 4},
131  7,
135 #if (SNMP_MIB_SYS_CONTACT_SIZE > 0)
139  NULL,
140  NULL,
141  NULL
142 #else
143  NULL,
144  NULL,
145  0,
148  NULL
149 #endif
150  },
151  //sysName object (1.3.6.1.2.1.1.5)
152  {
153  "sysName",
154  {43, 6, 1, 2, 1, 1, 5},
155  7,
159 #if (SNMP_MIB_SYS_NAME_SIZE > 0)
163  NULL,
164  NULL,
165  NULL
166 #else
167  NULL,
168  NULL,
169  0,
172  NULL
173 #endif
174  },
175  //sysLocation object (1.3.6.1.2.1.1.6)
176  {
177  "sysLocation",
178  {43, 6, 1, 2, 1, 1, 6},
179  7,
183 #if (SNMP_MIB_SYS_LOCATION_SIZE > 0)
187  NULL,
188  NULL,
189  NULL
190 #else
191  NULL,
192  NULL,
193  0,
196  NULL
197 #endif
198  },
199  //sysServices object (1.3.6.1.2.1.1.7)
200  {
201  "sysServices",
202  {43, 6, 1, 2, 1, 1, 7},
203  7,
208  NULL,
209  sizeof(int32_t),
210  NULL,
211  NULL,
212  NULL
213  },
214  //sysORLastChange object (1.3.6.1.2.1.1.8)
215  {
216  "sysORLastChange",
217  {43, 6, 1, 2, 1, 1, 8},
218  7,
223  NULL,
224  sizeof(uint32_t),
225  NULL,
226  NULL,
227  NULL
228  },
229  //sysORID object (1.3.6.1.2.1.1.9.1.2)
230  {
231  "sysORID",
232  {43, 6, 1, 2, 1, 1, 9, 1, 2},
233  9,
237  NULL,
238  NULL,
239  0,
240  NULL,
243  },
244  //sysORDescr object (1.3.6.1.2.1.1.9.1.3)
245  {
246  "sysORDescr",
247  {43, 6, 1, 2, 1, 1, 9, 1, 3},
248  9,
252  NULL,
253  NULL,
254  0,
255  NULL,
258  },
259  //sysORUpTime object (1.3.6.1.2.1.1.9.1.4)
260  {
261  "sysORUpTime",
262  {43, 6, 1, 2, 1, 1, 9, 1, 4},
263  9,
267  NULL,
268  NULL,
269  sizeof(uint32_t),
270  NULL,
273  },
274  //snmpInPkts object (1.3.6.1.2.1.11.1)
275  {
276  "snmpInPkts",
277  {43, 6, 1, 2, 1, 11, 1},
278  7,
283  NULL,
284  sizeof(uint32_t),
285  NULL,
286  NULL,
287  NULL
288  },
289  //snmpInBadVersions object (1.3.6.1.2.1.11.3)
290  {
291  "snmpInBadVersions",
292  {43, 6, 1, 2, 1, 11, 3},
293  7,
298  NULL,
299  sizeof(uint32_t),
300  NULL,
301  NULL,
302  NULL
303  },
304  //snmpInBadCommunityNames object (1.3.6.1.2.1.11.4)
305  {
306  "snmpInBadCommunityNames",
307  {43, 6, 1, 2, 1, 11, 4},
308  7,
313  NULL,
314  sizeof(uint32_t),
315  NULL,
316  NULL,
317  NULL
318  },
319  //snmpInBadCommunityUses object (1.3.6.1.2.1.11.5)
320  {
321  "snmpInBadCommunityUses",
322  {43, 6, 1, 2, 1, 11, 5},
323  7,
328  NULL,
329  sizeof(uint32_t),
330  NULL,
331  NULL,
332  NULL
333  },
334  //snmpInASNParseErrs object (1.3.6.1.2.1.11.6)
335  {
336  "snmpInASNParseErrs",
337  {43, 6, 1, 2, 1, 11, 6},
338  7,
343  NULL,
344  sizeof(uint32_t),
345  NULL,
346  NULL,
347  NULL
348  },
349  //snmpEnableAuthenTraps object (1.3.6.1.2.1.11.30)
350  {
351  "snmpEnableAuthenTraps",
352  {43, 6, 1, 2, 1, 11, 30},
353  7,
358  NULL,
359  sizeof(int32_t),
360  NULL,
361  NULL,
362  NULL
363  },
364  //snmpSilentDrops object (1.3.6.1.2.1.11.31)
365  {
366  "snmpSilentDrops",
367  {43, 6, 1, 2, 1, 11, 31},
368  7,
373  NULL,
374  sizeof(uint32_t),
375  NULL,
376  NULL,
377  NULL
378  },
379  //snmpProxyDrops object (1.3.6.1.2.1.11.32)
380  {
381  "snmpProxyDrops",
382  {43, 6, 1, 2, 1, 11, 32},
383  7,
388  NULL,
389  sizeof(uint32_t),
390  NULL,
391  NULL,
392  NULL
393  },
394  //snmpTrapOID object (1.3.6.1.6.3.1.1.4.1)
395  {
396  "snmpTrapOID",
397  {43, 6, 1, 6, 3, 1, 1, 4, 1},
398  9,
402  NULL,
403  NULL,
404  0,
405  NULL,
407  NULL
408  },
409  //snmpTrapEnterprise object (1.3.6.1.6.3.1.1.4.3)
410  {
411  "snmpTrapEnterprise",
412  {43, 6, 1, 6, 3, 1, 1, 4, 3},
413  9,
417  NULL,
418  NULL,
419  0,
420  NULL,
422  NULL
423  },
424  //snmpSetSerialNo object (1.3.6.1.6.3.1.1.6.1)
425  {
426  "snmpSetSerialNo",
427  {43, 6, 1, 6, 3, 1, 1, 6, 1},
428  9,
432  NULL,
433  NULL,
434  sizeof(int32_t),
437  NULL
438  }
439 };
440 
441 
442 /**
443  * @brief SNMP MIB module
444  **/
445 
447 {
448  "SNMPv2-MIB",
449  {43, 6, 1, 6, 3, 1},
450  6,
453  snmpMibInit,
454  snmpMibLoad,
456  snmpMibLock,
458 };
459 
460 #endif
SNMP MIB module implementation.
char_t sysContact[SNMP_MIB_SYS_CONTACT_SIZE]
error_t snmpMibGetSysContact(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
TCP/IP stack core.
Debugging facilities.
SnmpMibSnmpGroup snmpGroup
error_t snmpMibSetSysContact(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
error_t snmpMibGetSysLocation(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
#define MibObject
Definition: mib_common.h:44
General definitions for cryptographic algorithms.
error_t snmpMibGetSysDescr(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
int32_t snmpEnableAuthenTraps
const MibObject snmpMibObjects[]
SNMP MIB objects.
error_t snmpMibGetNextSysOREntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next sysOREntry object.
char_t sysLocation[SNMP_MIB_SYS_LOCATION_SIZE]
#define SNMP_MIB_SYS_NAME_SIZE
SNMP MIB module.
uint32_t snmpInASNParseErrs
OID (Object Identifier)
#define arraysize(a)
Definition: os_port.h:68
error_t snmpMibSetSysName(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
error_t snmpMibInit(void)
SNMP MIB module initialization.
Definition: snmp_mib_impl.c:52
ASN.1 (Abstract Syntax Notation One)
#define ASN1_CLASS_APPLICATION
Definition: asn1.h:46
error_t snmpv2MibGetSnmpTrapEnterprise(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpTrapEnterprise object value.
error_t snmpMibGetSysOREntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get sysOREntry object value.
void snmpMibUnload(void *context)
Unload SNMP MIB module.
SNMP MIB base.
#define SNMP_MIB_SYS_LOCATION_SIZE
uint32_t snmpSilentDrops
error_t snmpMibGetSnmpSetSerialNo(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpSetSerialNo object value.
#define SNMP_MIB_SYS_OBJECT_ID_SIZE
error_t snmpMibGetSysUpTime(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get sysUpTime object value.
char_t sysDescr[SNMP_MIB_SYS_DESCR_SIZE]
#define SNMP_MIB_SYS_CONTACT_SIZE
error_t snmpv2MibGetSnmpTrapOID(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpTrapOID object value.
error_t snmpMibLoad(void *context)
Load SNMP MIB module.
uint32_t sysORLastChange
uint32_t snmpInBadVersions
uint32_t snmpInBadCommunityUses
SnmpMibSysGroup sysGroup
const MibModule snmpMibModule
SNMP MIB module.
error_t snmpMibGetSysName(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
#define SNMP_MIB_SYS_DESCR_SIZE
Common definitions for MIB modules.
void snmpMibUnlock(void)
Unlock SNMP MIB base.
error_t snmpMibSetSnmpSetSerialNo(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
Set snmpSetSerialNo object value.
uint32_t snmpInBadCommunityNames
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:45
SnmpMibBase snmpMibBase
SNMP MIB base.
MIB module.
Definition: mib_common.h:285
char_t sysName[SNMP_MIB_SYS_NAME_SIZE]
error_t snmpMibGetSysObjectID(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
error_t snmpMibSetSysLocation(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
void snmpMibLock(void)
Lock SNMP MIB base.
uint8_t sysObjectID[SNMP_MIB_SYS_OBJECT_ID_SIZE]