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  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @section Description
28  *
29  * The SNMP-MIB describes managed objects which describe the behavior
30  * of an SNMP entity. Refer to RFC 3418 for more details
31  *
32  * @author Oryx Embedded SARL (www.oryx-embedded.com)
33  * @version 1.9.6
34  **/
35 
36 //Switch to the appropriate trace level
37 #define TRACE_LEVEL SNMP_TRACE_LEVEL
38 
39 //Dependencies
40 #include "core/net.h"
41 #include "mibs/mib_common.h"
42 #include "mibs/snmp_mib_module.h"
43 #include "mibs/snmp_mib_impl.h"
44 #include "core/crypto.h"
45 #include "encoding/asn1.h"
46 #include "encoding/oid.h"
47 #include "debug.h"
48 
49 //Check TCP/IP stack configuration
50 #if (SNMP_MIB_SUPPORT == ENABLED)
51 
52 
53 /**
54  * @brief SNMP MIB base
55  **/
56 
58 
59 
60 /**
61  * @brief SNMP MIB objects
62  **/
63 
65 {
66  //sysDescr object (1.3.6.1.2.1.1.1)
67  {
68  "sysDescr",
69  {43, 6, 1, 2, 1, 1, 1},
70  7,
74 #if (SNMP_MIB_SYS_DESCR_SIZE > 0)
78  NULL,
79  NULL,
80  NULL
81 #else
82  NULL,
83  NULL,
84  0,
85  NULL,
87  NULL
88 #endif
89  },
90  //sysObjectID object (1.3.6.1.2.1.1.2)
91  {
92  "sysObjectID",
93  {43, 6, 1, 2, 1, 1, 2},
94  7,
98 #if (SNMP_MIB_SYS_OBJECT_ID_SIZE > 0)
102  NULL,
103  NULL,
104  NULL
105 #else
106  NULL,
107  NULL,
108  0,
109  NULL,
111  NULL
112 #endif
113  },
114  //sysUpTime object (1.3.6.1.2.1.1.3)
115  {
116  "sysUpTime",
117  {43, 6, 1, 2, 1, 1, 3},
118  7,
122  NULL,
123  NULL,
124  sizeof(uint32_t),
125  NULL,
127  NULL
128  },
129  //sysContact object (1.3.6.1.2.1.1.4)
130  {
131  "sysContact",
132  {43, 6, 1, 2, 1, 1, 4},
133  7,
137 #if (SNMP_MIB_SYS_CONTACT_SIZE > 0)
141  NULL,
142  NULL,
143  NULL
144 #else
145  NULL,
146  NULL,
147  0,
150  NULL
151 #endif
152  },
153  //sysName object (1.3.6.1.2.1.1.5)
154  {
155  "sysName",
156  {43, 6, 1, 2, 1, 1, 5},
157  7,
161 #if (SNMP_MIB_SYS_NAME_SIZE > 0)
165  NULL,
166  NULL,
167  NULL
168 #else
169  NULL,
170  NULL,
171  0,
174  NULL
175 #endif
176  },
177  //sysLocation object (1.3.6.1.2.1.1.6)
178  {
179  "sysLocation",
180  {43, 6, 1, 2, 1, 1, 6},
181  7,
185 #if (SNMP_MIB_SYS_LOCATION_SIZE > 0)
189  NULL,
190  NULL,
191  NULL
192 #else
193  NULL,
194  NULL,
195  0,
198  NULL
199 #endif
200  },
201  //sysServices object (1.3.6.1.2.1.1.7)
202  {
203  "sysServices",
204  {43, 6, 1, 2, 1, 1, 7},
205  7,
210  NULL,
211  sizeof(int32_t),
212  NULL,
213  NULL,
214  NULL
215  },
216  //sysORLastChange object (1.3.6.1.2.1.1.8)
217  {
218  "sysORLastChange",
219  {43, 6, 1, 2, 1, 1, 8},
220  7,
225  NULL,
226  sizeof(uint32_t),
227  NULL,
228  NULL,
229  NULL
230  },
231  //sysORID object (1.3.6.1.2.1.1.9.1.2)
232  {
233  "sysORID",
234  {43, 6, 1, 2, 1, 1, 9, 1, 2},
235  9,
239  NULL,
240  NULL,
241  0,
242  NULL,
245  },
246  //sysORDescr object (1.3.6.1.2.1.1.9.1.3)
247  {
248  "sysORDescr",
249  {43, 6, 1, 2, 1, 1, 9, 1, 3},
250  9,
254  NULL,
255  NULL,
256  0,
257  NULL,
260  },
261  //sysORUpTime object (1.3.6.1.2.1.1.9.1.4)
262  {
263  "sysORUpTime",
264  {43, 6, 1, 2, 1, 1, 9, 1, 4},
265  9,
269  NULL,
270  NULL,
271  sizeof(uint32_t),
272  NULL,
275  },
276  //snmpInPkts object (1.3.6.1.2.1.11.1)
277  {
278  "snmpInPkts",
279  {43, 6, 1, 2, 1, 11, 1},
280  7,
285  NULL,
286  sizeof(uint32_t),
287  NULL,
288  NULL,
289  NULL
290  },
291  //snmpInBadVersions object (1.3.6.1.2.1.11.3)
292  {
293  "snmpInBadVersions",
294  {43, 6, 1, 2, 1, 11, 3},
295  7,
300  NULL,
301  sizeof(uint32_t),
302  NULL,
303  NULL,
304  NULL
305  },
306  //snmpInBadCommunityNames object (1.3.6.1.2.1.11.4)
307  {
308  "snmpInBadCommunityNames",
309  {43, 6, 1, 2, 1, 11, 4},
310  7,
315  NULL,
316  sizeof(uint32_t),
317  NULL,
318  NULL,
319  NULL
320  },
321  //snmpInBadCommunityUses object (1.3.6.1.2.1.11.5)
322  {
323  "snmpInBadCommunityUses",
324  {43, 6, 1, 2, 1, 11, 5},
325  7,
330  NULL,
331  sizeof(uint32_t),
332  NULL,
333  NULL,
334  NULL
335  },
336  //snmpInASNParseErrs object (1.3.6.1.2.1.11.6)
337  {
338  "snmpInASNParseErrs",
339  {43, 6, 1, 2, 1, 11, 6},
340  7,
345  NULL,
346  sizeof(uint32_t),
347  NULL,
348  NULL,
349  NULL
350  },
351  //snmpEnableAuthenTraps object (1.3.6.1.2.1.11.30)
352  {
353  "snmpEnableAuthenTraps",
354  {43, 6, 1, 2, 1, 11, 30},
355  7,
360  NULL,
361  sizeof(int32_t),
362  NULL,
363  NULL,
364  NULL
365  },
366  //snmpSilentDrops object (1.3.6.1.2.1.11.31)
367  {
368  "snmpSilentDrops",
369  {43, 6, 1, 2, 1, 11, 31},
370  7,
375  NULL,
376  sizeof(uint32_t),
377  NULL,
378  NULL,
379  NULL
380  },
381  //snmpProxyDrops object (1.3.6.1.2.1.11.32)
382  {
383  "snmpProxyDrops",
384  {43, 6, 1, 2, 1, 11, 32},
385  7,
390  NULL,
391  sizeof(uint32_t),
392  NULL,
393  NULL,
394  NULL
395  },
396  //snmpTrapOID object (1.3.6.1.6.3.1.1.4.1)
397  {
398  "snmpTrapOID",
399  {43, 6, 1, 6, 3, 1, 1, 4, 1},
400  9,
404  NULL,
405  NULL,
406  0,
407  NULL,
409  NULL
410  },
411  //snmpTrapEnterprise object (1.3.6.1.6.3.1.1.4.3)
412  {
413  "snmpTrapEnterprise",
414  {43, 6, 1, 6, 3, 1, 1, 4, 3},
415  9,
419  NULL,
420  NULL,
421  0,
422  NULL,
424  NULL
425  },
426  //snmpSetSerialNo object (1.3.6.1.6.3.1.1.6.1)
427  {
428  "snmpSetSerialNo",
429  {43, 6, 1, 6, 3, 1, 1, 6, 1},
430  9,
434  NULL,
435  NULL,
436  sizeof(int32_t),
439  NULL
440  }
441 };
442 
443 
444 /**
445  * @brief SNMP MIB module
446  **/
447 
449 {
450  "SNMPv2-MIB",
451  {43, 6, 1, 6, 3, 1},
452  6,
455  snmpMibInit,
456  snmpMibLoad,
458  snmpMibLock,
460 };
461 
462 #endif
const MibObject snmpMibObjects[]
SNMP MIB objects.
void snmpMibUnlock(void)
Unlock SNMP MIB base.
SnmpMibSysGroup sysGroup
error_t snmpMibLoad(void *context)
Load SNMP MIB module.
uint32_t snmpInBadCommunityNames
char_t sysDescr[SNMP_MIB_SYS_DESCR_SIZE]
error_t snmpMibGetSysDescr(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
error_t snmpMibGetSysUpTime(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get sysUpTime object value.
OID (Object Identifier)
@ MIB_ACCESS_READ_ONLY
Definition: mib_common.h:79
uint32_t snmpInBadVersions
error_t snmpv2MibGetSnmpTrapEnterprise(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpTrapEnterprise object value.
#define SNMP_MIB_SYS_LOCATION_SIZE
error_t snmpMibSetSysLocation(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
uint32_t sysORLastChange
SNMP MIB module.
#define SNMP_MIB_SYS_CONTACT_SIZE
SNMP MIB base.
error_t snmpv2MibGetSnmpTrapOID(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get snmpTrapOID object value.
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 snmpMibSetSysName(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
@ MIB_ACCESS_READ_WRITE
Definition: mib_common.h:80
@ MIB_TYPE_COUNTER32
Definition: mib_common.h:61
error_t snmpMibGetNextSysOREntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next sysOREntry object.
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.
const MibModule snmpMibModule
SNMP MIB module.
#define SNMP_MIB_SYS_DESCR_SIZE
#define ASN1_CLASS_UNIVERSAL
Definition: asn1.h:48
error_t snmpMibGetSysOREntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get sysOREntry object value.
@ MIB_ACCESS_FOR_NOTIFY
Definition: mib_common.h:77
SNMP MIB module implementation.
General definitions for cryptographic algorithms.
SnmpMibSnmpGroup snmpGroup
uint8_t sysObjectID[SNMP_MIB_SYS_OBJECT_ID_SIZE]
error_t snmpMibGetSysLocation(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
uint32_t snmpInBadCommunityUses
MIB module.
Definition: mib_common.h:287
SnmpMibBase snmpMibBase
SNMP MIB base.
#define SNMP_MIB_SYS_NAME_SIZE
uint32_t snmpInASNParseErrs
@ ASN1_TYPE_OCTET_STRING
Definition: asn1.h:68
@ ASN1_TYPE_INTEGER
Definition: asn1.h:66
error_t snmpMibInit(void)
SNMP MIB module initialization.
Definition: snmp_mib_impl.c:54
char_t sysLocation[SNMP_MIB_SYS_LOCATION_SIZE]
@ MIB_TYPE_TIME_TICKS
Definition: mib_common.h:64
void snmpMibLock(void)
Lock SNMP MIB base.
error_t snmpMibGetSysName(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Common definitions for MIB modules.
error_t snmpMibGetSysContact(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
char_t sysName[SNMP_MIB_SYS_NAME_SIZE]
void snmpMibUnload(void *context)
Unload SNMP MIB module.
int32_t snmpEnableAuthenTraps
#define MibObject
Definition: mib_common.h:46
uint32_t snmpSilentDrops
char_t sysContact[SNMP_MIB_SYS_CONTACT_SIZE]
error_t snmpMibGetSysObjectID(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
@ ASN1_TYPE_OBJECT_IDENTIFIER
Definition: asn1.h:70
TCP/IP stack core.
error_t snmpMibSetSysContact(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
#define ASN1_CLASS_APPLICATION
Definition: asn1.h:49
Debugging facilities.
ASN.1 (Abstract Syntax Notation One)
#define arraysize(a)
Definition: os_port.h:70