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-2024 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.4.4
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_IF_GROUP_SUPPORT == ENABLED)
67  //Interface group initialization
69 #endif
70 
71 #if (MIB2_IP_GROUP_SUPPORT == ENABLED)
72  //IP group initialization
74 #endif
75 
76 #if (MIB2_TCP_GROUP_SUPPORT == ENABLED)
77  //TCP group initialization
79 #endif
80 
81 #if (MIB2_SNMP_GROUP_SUPPORT == ENABLED)
82  //SNMP group initialization
84 #endif
85 
86  //Successful processing
87  return NO_ERROR;
88 }
89 
90 
91 /**
92  * @brief System group initialization
93  * @param[in] sysGroup Pointer to the System group
94  **/
95 
97 {
98 #if (MIB2_SYS_DESCR_SIZE > 0)
99  //sysDescr object
100  osStrcpy(sysGroup->sysDescr, "Description");
101  sysGroup->sysDescrLen = osStrlen(sysGroup->sysDescr);
102 #endif
103 
104 #if (MIB2_SYS_OBJECT_ID_SIZE > 0)
105  //sysObjectID object
106  sysGroup->sysObjectID[0] = 0;
107  sysGroup->sysObjectIDLen = 1;
108 #endif
109 
110 #if (MIB2_SYS_CONTACT_SIZE > 0)
111  //sysContact object
112  osStrcpy(sysGroup->sysContact, "Contact");
113  sysGroup->sysContactLen = osStrlen(sysGroup->sysContact);
114 #endif
115 
116 #if (MIB2_SYS_NAME_SIZE > 0)
117  //sysName object
118  osStrcpy(sysGroup->sysName, "Name");
119  sysGroup->sysNameLen = osStrlen(sysGroup->sysName);
120 #endif
121 
122 #if (MIB2_SYS_LOCATION_SIZE > 0)
123  //sysLocation object
124  osStrcpy(sysGroup->sysLocation, "Location");
125  sysGroup->sysLocationLen = osStrlen(sysGroup->sysLocation);
126 #endif
127 
128  //sysServices object
130 }
131 
132 
133 /**
134  * @brief Interface group initialization
135  * @param[in] ifGroup Pointer to the Interface group
136  **/
137 
139 {
140  uint_t i;
141 
142  //ifNumber object
143  ifGroup->ifNumber = NET_INTERFACE_COUNT;
144 
145  //Interfaces table entry
146  for(i = 0; i < NET_INTERFACE_COUNT; i++)
147  {
148  //ifSpecific object
149  ifGroup->ifTable[i].ifSpecific[0] = 0;
150  ifGroup->ifTable[i].ifSpecificLen = 1;
151  }
152 }
153 
154 
155 /**
156  * @brief IP group initialization
157  * @param[in] ipGroup Pointer to the IP group
158  **/
159 
161 {
162  //ipForwarding object
164  //ipDefaultTTL object
165  ipGroup->ipDefaultTTL = IPV4_DEFAULT_TTL;
166  //ipReasmTimeout object
167  ipGroup->ipReasmTimeout = IPV4_FRAG_TIME_TO_LIVE / 1000;
168 }
169 
170 
171 /**
172  * @brief TCP group initialization
173  * @param[in] tcpGroup Pointer to the TCP group
174  **/
175 
177 {
178  //tcpRtoAlgorithm object
180  //tcpRtoMin object
181  tcpGroup->tcpRtoMin = TCP_MIN_RTO;
182  //tcpRtoMax object
183  tcpGroup->tcpRtoMax = TCP_MAX_RTO;
184  //tcpMaxConn object
185  tcpGroup->tcpMaxConn = SOCKET_MAX_COUNT;
186 }
187 
188 
189 /**
190  * @brief SNMP group initialization
191  * @param[in] snmpGroup Pointer to the SNMP group
192  **/
193 
195 {
196  //snmpEnableAuthenTraps object
198 }
199 
200 #endif
SNMP group.
Definition: mib2_module.h:505
MIB-II module.
char_t sysName[MIB2_SYS_NAME_SIZE]
Definition: mib2_module.h:355
Interfaces group.
Definition: mib2_module.h:395
#define TCP_MAX_RTO
Definition: tcp.h:131
OID (Object Identifier)
int32_t sysServices
Definition: mib2_module.h:362
int32_t snmpEnableAuthenTraps
Definition: mib2_module.h:533
uint8_t ifSpecific[MIB2_IF_SPECIFIC_SIZE]
Definition: mib2_module.h:385
#define NET_INTERFACE_COUNT
Definition: net.h:114
@ MIB2_IP_FORWARDING_DISABLED
Definition: mib2_module.h:273
#define osStrlen(s)
Definition: os_port.h:165
int32_t tcpRtoMin
Definition: mib2_module.h:472
void mib2InitIpGroup(Mib2IpGroup *ipGroup)
IP group initialization.
Definition: mib2_impl.c:160
size_t sysObjectIDLen
Definition: mib2_module.h:347
void mib2InitSysGroup(Mib2SysGroup *sysGroup)
System group initialization.
Definition: mib2_impl.c:96
Mib2IfEntry ifTable[NET_INTERFACE_COUNT]
Definition: mib2_module.h:397
int32_t ipReasmTimeout
Definition: mib2_module.h:419
Mib2TcpGroup tcpGroup
Definition: mib2_module.h:556
int32_t ifNumber
Definition: mib2_module.h:396
error_t
Error codes.
Definition: error.h:43
TCP group.
Definition: mib2_module.h:470
Mib2IfGroup ifGroup
Definition: mib2_module.h:547
@ MIB2_SYS_SERVICE_INTERNET
Definition: mib2_module.h:211
@ MIB2_AUTHEN_TRAPS_DISABLED
Definition: mib2_module.h:331
General definitions for cryptographic algorithms.
size_t sysContactLen
Definition: mib2_module.h:352
int32_t tcpRtoMax
Definition: mib2_module.h:473
#define TRACE_INFO(...)
Definition: debug.h:95
#define IPV4_FRAG_TIME_TO_LIVE
Definition: ipv4_frag.h:76
size_t sysLocationLen
Definition: mib2_module.h:360
#define IPV4_DEFAULT_TTL
Definition: ipv4.h:62
int32_t ipDefaultTTL
Definition: mib2_module.h:408
MIB-II module implementation.
Mib2IpGroup ipGroup
Definition: mib2_module.h:550
Common definitions for MIB modules.
@ MIB2_TCP_RTO_ALGORITHM_VANJ
Definition: mib2_module.h:299
char_t sysDescr[MIB2_SYS_DESCR_SIZE]
Definition: mib2_module.h:342
int32_t tcpMaxConn
Definition: mib2_module.h:474
void mib2InitTcpGroup(Mib2TcpGroup *tcpGroup)
TCP group initialization.
Definition: mib2_impl.c:176
void mib2InitSnmpGroup(Mib2SnmpGroup *snmpGroup)
SNMP group initialization.
Definition: mib2_impl.c:194
#define TCP_MIN_RTO
Definition: tcp.h:124
IP group.
Definition: mib2_module.h:406
char_t sysLocation[MIB2_SYS_LOCATION_SIZE]
Definition: mib2_module.h:359
Mib2Base mib2Base
MIB-II base.
Definition: mib2_module.c:63
size_t sysNameLen
Definition: mib2_module.h:356
error_t mib2Init(void)
MIB-II module initialization.
Definition: mib2_impl.c:53
int32_t ipForwarding
Definition: mib2_module.h:407
uint8_t sysObjectID[MIB2_SYS_OBJECT_ID_SIZE]
Definition: mib2_module.h:346
unsigned int uint_t
Definition: compiler_port.h:50
#define osMemset(p, value, length)
Definition: os_port.h:135
TCP/IP stack core.
char_t sysContact[MIB2_SYS_CONTACT_SIZE]
Definition: mib2_module.h:351
Mib2SysGroup sysGroup
Definition: mib2_module.h:544
#define SOCKET_MAX_COUNT
Definition: socket.h:46
int32_t tcpRtoAlgorithm
Definition: mib2_module.h:471
#define osStrcpy(s1, s2)
Definition: os_port.h:207
size_t ifSpecificLen
Definition: mib2_module.h:386
Mib2SnmpGroup snmpGroup
Definition: mib2_module.h:562
size_t sysDescrLen
Definition: mib2_module.h:343
@ NO_ERROR
Success.
Definition: error.h:44
Debugging facilities.
ASN.1 (Abstract Syntax Notation One)
System group.
Definition: mib2_module.h:340
void mib2InitIfGroup(Mib2IfGroup *ifGroup)
Interface group initialization.
Definition: mib2_impl.c:138