mib2_impl.c
Go to the documentation of this file.
1 /**
2  * @file mib2_impl.c
3  * @brief MIB-II module implementation
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2026 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  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.6.0
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL SNMP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mibs/mib_common.h"
37 #include "mibs/mib2_module.h"
38 #include "mibs/mib2_impl.h"
39 #include "core/crypto.h"
40 #include "encoding/asn1.h"
41 #include "encoding/oid.h"
42 #include "debug.h"
43 
44 //Check TCP/IP stack configuration
45 #if (MIB2_SUPPORT == ENABLED)
46 
47 
48 /**
49  * @brief MIB-II module initialization
50  * @return Error code
51  **/
52 
54 {
55  //Debug message
56  TRACE_INFO("Initializing MIB-II base...\r\n");
57 
58  //Clear MIB-II base
59  osMemset(&mib2Base, 0, sizeof(mib2Base));
60 
61 #if (MIB2_SYS_GROUP_SUPPORT == ENABLED)
62  //System group initialization
64 #endif
65 
66 #if (MIB2_IP_GROUP_SUPPORT == ENABLED)
67  //IP group initialization
69 #endif
70 
71 #if (MIB2_TCP_GROUP_SUPPORT == ENABLED)
72  //TCP group initialization
74 #endif
75 
76 #if (MIB2_SNMP_GROUP_SUPPORT == ENABLED)
77  //SNMP group initialization
79 #endif
80 
81  //Successful processing
82  return NO_ERROR;
83 }
84 
85 
86 /**
87  * @brief System group initialization
88  * @param[in] sysGroup Pointer to the System group
89  **/
90 
92 {
93 #if (MIB2_SYS_DESCR_SIZE > 0)
94  //sysDescr object
95  osStrcpy(sysGroup->sysDescr, "Description");
96  sysGroup->sysDescrLen = osStrlen(sysGroup->sysDescr);
97 #endif
98 
99 #if (MIB2_SYS_OBJECT_ID_SIZE > 0)
100  //sysObjectID object
101  sysGroup->sysObjectID[0] = 0;
102  sysGroup->sysObjectIDLen = 1;
103 #endif
104 
105 #if (MIB2_SYS_CONTACT_SIZE > 0)
106  //sysContact object
107  osStrcpy(sysGroup->sysContact, "Contact");
108  sysGroup->sysContactLen = osStrlen(sysGroup->sysContact);
109 #endif
110 
111 #if (MIB2_SYS_NAME_SIZE > 0)
112  //sysName object
113  osStrcpy(sysGroup->sysName, "Name");
114  sysGroup->sysNameLen = osStrlen(sysGroup->sysName);
115 #endif
116 
117 #if (MIB2_SYS_LOCATION_SIZE > 0)
118  //sysLocation object
119  osStrcpy(sysGroup->sysLocation, "Location");
120  sysGroup->sysLocationLen = osStrlen(sysGroup->sysLocation);
121 #endif
122 
123  //sysServices object
125 }
126 
127 
128 /**
129  * @brief IP group initialization
130  * @param[in] ipGroup Pointer to the IP group
131  **/
132 
134 {
135  //ipForwarding object
137  //ipDefaultTTL object
138  ipGroup->ipDefaultTTL = IPV4_DEFAULT_TTL;
139  //ipReasmTimeout object
140  ipGroup->ipReasmTimeout = IPV4_FRAG_TIME_TO_LIVE / 1000;
141 }
142 
143 
144 /**
145  * @brief TCP group initialization
146  * @param[in] tcpGroup Pointer to the TCP group
147  **/
148 
150 {
151  //tcpRtoAlgorithm object
153  //tcpRtoMin object
154  tcpGroup->tcpRtoMin = TCP_MIN_RTO;
155  //tcpRtoMax object
156  tcpGroup->tcpRtoMax = TCP_MAX_RTO;
157  //tcpMaxConn object
158  tcpGroup->tcpMaxConn = SOCKET_MAX_COUNT;
159 }
160 
161 
162 /**
163  * @brief SNMP group initialization
164  * @param[in] snmpGroup Pointer to the SNMP group
165  **/
166 
168 {
169  //snmpEnableAuthenTraps object
171 }
172 
173 #endif
SNMP group.
Definition: mib2_module.h:396
MIB-II module.
char_t sysName[MIB2_SYS_NAME_SIZE]
Definition: mib2_module.h:332
#define TCP_MAX_RTO
Definition: tcp.h:131
OID (Object Identifier)
int32_t sysServices
Definition: mib2_module.h:339
int32_t snmpEnableAuthenTraps
Definition: mib2_module.h:424
@ MIB2_IP_FORWARDING_DISABLED
Definition: mib2_module.h:250
#define osStrlen(s)
Definition: os_port.h:168
int32_t tcpRtoMin
Definition: mib2_module.h:363
void mib2InitIpGroup(Mib2IpGroup *ipGroup)
IP group initialization.
Definition: mib2_impl.c:133
size_t sysObjectIDLen
Definition: mib2_module.h:324
void mib2InitSysGroup(Mib2SysGroup *sysGroup)
System group initialization.
Definition: mib2_impl.c:91
int32_t ipReasmTimeout
Definition: mib2_module.h:351
Mib2TcpGroup tcpGroup
Definition: mib2_module.h:441
error_t
Error codes.
Definition: error.h:43
TCP group.
Definition: mib2_module.h:361
@ MIB2_SYS_SERVICE_INTERNET
Definition: mib2_module.h:188
@ MIB2_AUTHEN_TRAPS_DISABLED
Definition: mib2_module.h:308
General definitions for cryptographic algorithms.
size_t sysContactLen
Definition: mib2_module.h:329
int32_t tcpRtoMax
Definition: mib2_module.h:364
#define TRACE_INFO(...)
Definition: debug.h:105
#define IPV4_FRAG_TIME_TO_LIVE
Definition: ipv4_frag.h:76
size_t sysLocationLen
Definition: mib2_module.h:337
#define IPV4_DEFAULT_TTL
Definition: ipv4.h:73
int32_t ipDefaultTTL
Definition: mib2_module.h:350
MIB-II module implementation.
Mib2IpGroup ipGroup
Definition: mib2_module.h:438
Common definitions for MIB modules.
@ MIB2_TCP_RTO_ALGORITHM_VANJ
Definition: mib2_module.h:276
char_t sysDescr[MIB2_SYS_DESCR_SIZE]
Definition: mib2_module.h:319
int32_t tcpMaxConn
Definition: mib2_module.h:365
void mib2InitTcpGroup(Mib2TcpGroup *tcpGroup)
TCP group initialization.
Definition: mib2_impl.c:149
void mib2InitSnmpGroup(Mib2SnmpGroup *snmpGroup)
SNMP group initialization.
Definition: mib2_impl.c:167
#define TCP_MIN_RTO
Definition: tcp.h:124
IP group.
Definition: mib2_module.h:348
char_t sysLocation[MIB2_SYS_LOCATION_SIZE]
Definition: mib2_module.h:336
Mib2Base mib2Base
MIB-II base.
Definition: mib2_module.c:64
size_t sysNameLen
Definition: mib2_module.h:333
error_t mib2Init(void)
MIB-II module initialization.
Definition: mib2_impl.c:53
int32_t ipForwarding
Definition: mib2_module.h:349
uint8_t sysObjectID[MIB2_SYS_OBJECT_ID_SIZE]
Definition: mib2_module.h:323
#define osMemset(p, value, length)
Definition: os_port.h:138
TCP/IP stack core.
char_t sysContact[MIB2_SYS_CONTACT_SIZE]
Definition: mib2_module.h:328
Mib2SysGroup sysGroup
Definition: mib2_module.h:435
#define SOCKET_MAX_COUNT
Definition: socket.h:46
int32_t tcpRtoAlgorithm
Definition: mib2_module.h:362
#define osStrcpy(s1, s2)
Definition: os_port.h:210
Mib2SnmpGroup snmpGroup
Definition: mib2_module.h:447
size_t sysDescrLen
Definition: mib2_module.h:320
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
ASN.1 (Abstract Syntax Notation One)
System group.
Definition: mib2_module.h:317