mib_common.h
Go to the documentation of this file.
1 /**
2  * @file mib_common.h
3  * @brief Common definitions for MIB modules
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 #ifndef _MIB_COMMON_H
32 #define _MIB_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //Maximum OID size
38 #ifndef MIB_MAX_OID_SIZE
39  #define MIB_MAX_OID_SIZE 16
40 #elif (MIB_MAX_OID_SIZE < 1)
41  #error MIB_MAX_OID_SIZE parameter is not valid
42 #endif
43 
44 //Forward declaration of MibObject structure
45 struct _MibObject;
46 #define MibObject struct _MibObject
47 
48 //C++ guard
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
53 
54 /**
55  * @brief MIB object types
56  **/
57 
58 typedef enum
59 {
68 
69 
70 /**
71  * @brief Access modes
72  **/
73 
74 typedef enum
75 {
83 
84 
85 /**
86  * @brief Truth value
87  **/
88 
89 typedef enum
90 {
94 
95 
96 /**
97  * @brief Row status
98  **/
99 
100 typedef enum
101 {
110 
111 
112 /**
113  * @brief Storage type
114  **/
115 
116 typedef enum
117 {
124 
125 
126 /**
127  * @brief Internet address types
128  **/
129 
130 typedef enum
131 {
137  INET_ADDR_TYPE_DNS = 16
139 
140 
141 /**
142  * @brief Internet address scope
143  **/
144 
145 typedef enum
146 {
156 
157 
158 /**
159  * @brief IP protocol version
160  **/
161 
162 typedef enum
163 {
168 
169 
170 //CC-RX, CodeWarrior or Win32 compiler?
171 #if defined(__CCRX__)
172  #pragma pack
173 #elif defined(__CWCC__) || defined(_WIN32)
174  #pragma pack(push, 1)
175 #endif
176 
177 
178 /**
179  * @brief Variant data type
180  **/
181 
183 {
184  __packed_union
185  {
186  int32_t integer;
187  uint8_t octetString[1];
188  uint8_t oid[1];
189  uint8_t ipAddr[4];
190  uint32_t counter32;
191  uint32_t gauge32;
192  uint32_t unsigned32;
193  uint32_t timeTicks;
194  uint64_t counter64;
195  };
197 
198 
199 //CC-RX, CodeWarrior or Win32 compiler?
200 #if defined(__CCRX__)
201  #pragma unpack
202 #elif defined(__CWCC__) || defined(_WIN32)
203  #pragma pack(pop)
204 #endif
205 
206 
207 /**
208  * @brief Set object value
209  **/
210 
211 typedef error_t (*MibSetValue)(const MibObject *object, const uint8_t *oid,
212  size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit);
213 
214 
215 /**
216  * @brief Get object value
217  **/
218 
219 typedef error_t (*MibGetValue)(const MibObject *object, const uint8_t *oid,
220  size_t oidLen, MibVariant *value, size_t *valueLen);
221 
222 
223 /**
224  * @brief Get next object
225  **/
226 
227 typedef error_t (*MibGetNext)(const MibObject *object, const uint8_t *oid,
228  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen);
229 
230 
231 /**
232  * @brief MIB object descriptor
233  **/
234 
236 {
237  const char_t *name;
239  size_t oidLen;
243  void *value;
244  size_t *valueLen;
245  size_t valueSize;
249 };
250 
251 
252 /**
253  * @brief MIB initialization
254  **/
255 
256 typedef error_t (*MibInit)(void);
257 
258 
259 /**
260  * @brief Load MIB
261  **/
262 
263 typedef error_t (*MibLoad)(void *context);
264 
265 
266 /**
267  * @brief Unload MIB
268  **/
269 
270 typedef void (*MibUnload)(void *context);
271 
272 
273 /**
274  * @brief Lock MIB
275  **/
276 
277 typedef void (*MibLock)(void);
278 
279 
280 /**
281  * @brief Unlock MIB
282  **/
283 
284 typedef void (*MibUnlock)(void);
285 
286 
287 /**
288  * @brief MIB module
289  **/
290 
291 typedef struct
292 {
293  const char_t *name;
295  size_t oidLen;
303 } MibModule;
304 
305 
306 //MIB related functions
307 error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos,
308  uint_t index);
309 
310 error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos,
311  uint_t *index);
312 
313 error_t mibEncodeUnsigned32(uint8_t *oid, size_t maxOidLen, size_t *pos,
314  uint32_t value);
315 
316 error_t mibDecodeUnsigned32(const uint8_t *oid, size_t oidLen, size_t *pos,
317  uint32_t *value);
318 
319 error_t mibEncodeString(uint8_t *oid, size_t maxOidLen, size_t *pos,
320  const char_t *string, bool_t implied);
321 
322 error_t mibDecodeString(const uint8_t *oid, size_t oidLen, size_t *pos,
323  char_t *string, size_t maxStringLen, bool_t implied);
324 
325 error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos,
326  const uint8_t *data, size_t dataLen, bool_t implied);
327 
328 error_t mibDecodeOctetString(const uint8_t *oid, size_t oidLen, size_t *pos,
329  uint8_t *data, size_t maxDataLen, size_t *dataLen, bool_t implied);
330 
331 error_t mibEncodeObjectIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos,
332  const uint8_t *objectId, size_t objectIdLen, bool_t implied);
333 
334 error_t mibDecodeObjectIdentifier(const uint8_t *oid, size_t oidLen, size_t *pos,
335  uint8_t *objectId, size_t maxObjectIdLen, size_t *objectIdLen, bool_t implied);
336 
337 error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos,
338  uint16_t port);
339 
340 error_t mibDecodePort(const uint8_t *oid, size_t oidLen, size_t *pos,
341  uint16_t *port);
342 
343 error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
344  const MacAddr *macAddr);
345 
346 error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
347  MacAddr *macAddr);
348 
349 error_t mibEncodePhysAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
350  const MacAddr *macAddr);
351 
352 error_t mibDecodePhysAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
353  MacAddr *macAddr);
354 
355 error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
356  Ipv4Addr ipAddr);
357 
358 error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
359  Ipv4Addr *ipAddr);
360 
361 error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
362  const Ipv6Addr *ipAddr);
363 
364 error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
365  Ipv6Addr *ipAddr);
366 
367 error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
368  const IpAddr *ipAddr);
369 
370 error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
371  IpAddr *ipAddr);
372 
373 int_t mibCompMacAddr(const MacAddr *macAddr1, const MacAddr *macAddr2);
374 int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2);
375 
376 error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit);
377 
378 //C++ guard
379 #ifdef __cplusplus
380 }
381 #endif
382 
383 #endif
error_t mibDecodePort(const uint8_t *oid, size_t oidLen, size_t *pos, uint16_t *port)
Decode instance identifier (port number)
Definition: mib_common.c:495
InetScopeType
Internet address scope.
Definition: mib_common.h:146
@ MIB_ROW_STATUS_NOT_IN_SERVICE
Definition: mib_common.h:104
@ INET_ADDR_TYPE_UNKNOWN
Definition: mib_common.h:132
InetVersion
IP protocol version.
Definition: mib_common.h:163
error_t mibDecodeObjectIdentifier(const uint8_t *oid, size_t oidLen, size_t *pos, uint8_t *objectId, size_t maxObjectIdLen, size_t *objectIdLen, bool_t implied)
Decode instance identifier (object identifier)
Definition: mib_common.c:377
MibInit init
Definition: mib_common.h:298
@ INET_VERSION_IPV6
Definition: mib_common.h:166
@ MIB_TYPE_IP_ADDRESS
Definition: mib_common.h:60
MibGetNext getNext
Definition: mib_common.h:248
MibLoad load
Definition: mib_common.h:299
const MibObject * objects
Definition: mib_common.h:296
int bool_t
Definition: compiler_port.h:53
MibStorageType
Storage type.
Definition: mib_common.h:117
@ MIB_TYPE_OPAQUE
Definition: mib_common.h:65
error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos, const uint8_t *data, size_t dataLen, bool_t implied)
Encode instance identifier (octet string)
Definition: mib_common.c:182
void * value
Definition: mib_common.h:243
error_t mibEncodeObjectIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos, const uint8_t *objectId, size_t objectIdLen, bool_t implied)
Encode instance identifier (object identifier)
Definition: mib_common.c:297
@ MIB_ROW_STATUS_CREATE_AND_GO
Definition: mib_common.h:106
error_t(* MibSetValue)(const MibObject *object, const uint8_t *oid, size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit)
Set object value.
Definition: mib_common.h:211
@ MIB_STORAGE_TYPE_NON_VOLATILE
Definition: mib_common.h:120
signed int int_t
Definition: compiler_port.h:49
IP network address.
Definition: ip.h:90
@ INET_ADDR_TYPE_IPV4Z
Definition: mib_common.h:135
@ MIB_ACCESS_WRITE_ONLY
Definition: mib_common.h:78
error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos, MacAddr *macAddr)
Decode instance identifier (MAC address)
Definition: mib_common.c:558
error_t mibDecodeOctetString(const uint8_t *oid, size_t oidLen, size_t *pos, uint8_t *data, size_t maxDataLen, size_t *dataLen, bool_t implied)
Decode instance identifier (octet string)
Definition: mib_common.c:225
void(* MibUnload)(void *context)
Unload MIB.
Definition: mib_common.h:270
MibAccess access
Definition: mib_common.h:242
@ MIB_STORAGE_TYPE_OTHER
Definition: mib_common.h:118
uint8_t data[]
Definition: ethernet.h:222
error_t mibEncodeString(uint8_t *oid, size_t maxOidLen, size_t *pos, const char_t *string, bool_t implied)
Encode instance identifier (string)
Definition: mib_common.c:129
error_t(* MibInit)(void)
MIB initialization.
Definition: mib_common.h:256
error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const MacAddr *macAddr)
Encode instance identifier (MAC address)
Definition: mib_common.c:528
@ MIB_ACCESS_READ_ONLY
Definition: mib_common.h:79
void(* MibUnlock)(void)
Unlock MIB.
Definition: mib_common.h:284
@ MIB_TRUTH_VALUE_TRUE
Definition: mib_common.h:91
Ipv6Addr
Definition: ipv6.h:260
const char_t * name
Definition: mib_common.h:237
MibAccess
Access modes.
Definition: mib_common.h:75
error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos, uint16_t port)
Encode instance identifier (port number)
Definition: mib_common.c:478
size_t * valueLen
Definition: mib_common.h:244
uint8_t oid[MIB_MAX_OID_SIZE]
Definition: mib_common.h:238
MibTruthValue
Truth value.
Definition: mib_common.h:90
@ INET_SCOPE_TYPE_SUBNET_LOCAL
Definition: mib_common.h:150
MibType
MIB object types.
Definition: mib_common.h:59
typedef __packed_struct
Variant data type.
Definition: mib_common.h:183
@ INET_ADDR_TYPE_IPV6
Definition: mib_common.h:134
@ MIB_ROW_STATUS_NOT_READY
Definition: mib_common.h:105
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:297
error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv4Addr *ipAddr)
Decode instance identifier (IPv4 address)
Definition: mib_common.c:698
@ INET_SCOPE_TYPE_SITE_LOCAL
Definition: mib_common.h:152
@ MIB_ROW_STATUS_DESTROY
Definition: mib_common.h:108
uint8_t oid[]
Definition: lldp_tlv.h:300
MibSetValue setValue
Definition: mib_common.h:246
@ MIB_STORAGE_TYPE_READ_ONLY
Definition: mib_common.h:122
int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2)
Compare IP addresses.
Definition: mib_common.c:968
@ INET_SCOPE_TYPE_GLOBAL
Definition: mib_common.h:154
uint_t numObjects
Definition: mib_common.h:297
@ MIB_ACCESS_READ_WRITE
Definition: mib_common.h:80
size_t valueSize
Definition: mib_common.h:245
@ MIB_TYPE_COUNTER32
Definition: mib_common.h:61
@ MIB_TYPE_GAUGE32
Definition: mib_common.h:62
error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos, IpAddr *ipAddr)
Decode instance identifier (IP address)
Definition: mib_common.c:886
error_t
Error codes.
Definition: error.h:43
#define MIB_MAX_OID_SIZE
Definition: mib_common.h:39
error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit)
Test and increment spin lock.
Definition: mib_common.c:1006
error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, Ipv4Addr ipAddr)
Encode instance identifier (IPv4 address)
Definition: mib_common.c:664
error_t mibEncodeUnsigned32(uint8_t *oid, size_t maxOidLen, size_t *pos, uint32_t value)
Encode instance identifier (unsigned 32-bit integer)
Definition: mib_common.c:94
@ MIB_ACCESS_NONE
Definition: mib_common.h:76
@ MIB_ACCESS_FOR_NOTIFY
Definition: mib_common.h:77
const char_t * name
Definition: mib_common.h:293
@ MIB_ROW_STATUS_UNUSED
Definition: mib_common.h:102
@ MIB_TYPE_UNSIGNED32
Definition: mib_common.h:63
error_t mibDecodePhysAddr(const uint8_t *oid, size_t oidLen, size_t *pos, MacAddr *macAddr)
Decode instance identifier (physical address)
Definition: mib_common.c:625
error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos, uint_t *index)
Decode instance identifier (index)
Definition: mib_common.c:64
@ INET_VERSION_UNKNOWN
Definition: mib_common.h:164
size_t oidLen
Definition: mib_common.h:239
@ INET_ADDR_TYPE_DNS
Definition: mib_common.h:137
error_t mibDecodeUnsigned32(const uint8_t *oid, size_t oidLen, size_t *pos, uint32_t *value)
Decode instance identifier (unsigned 32-bit integer)
Definition: mib_common.c:111
int_t mibCompMacAddr(const MacAddr *macAddr1, const MacAddr *macAddr2)
Compare MAC addresses.
Definition: mib_common.c:954
MIB module.
Definition: mib_common.h:292
uint32_t dataLen
Definition: sftp_common.h:229
size_t oidLen
Definition: mib_common.h:295
uint_t objType
Definition: mib_common.h:241
uint_t objClass
Definition: mib_common.h:240
MacAddr
Definition: ethernet.h:195
@ INET_ADDR_TYPE_IPV4
Definition: mib_common.h:133
uint16_t port
Definition: dns_common.h:267
@ INET_SCOPE_TYPE_INTERFACE_LOCAL
Definition: mib_common.h:148
error_t(* MibLoad)(void *context)
Load MIB.
Definition: mib_common.h:263
char char_t
Definition: compiler_port.h:48
@ MIB_TRUTH_VALUE_FALSE
Definition: mib_common.h:92
@ MIB_ROW_STATUS_ACTIVE
Definition: mib_common.h:103
@ MIB_TYPE_TIME_TICKS
Definition: mib_common.h:64
MibRowStatus
Row status.
Definition: mib_common.h:101
MibUnlock unlock
Definition: mib_common.h:302
@ INET_VERSION_IPV4
Definition: mib_common.h:165
#define MibObject
Definition: mib_common.h:46
uint8_t value[]
Definition: tcp.h:369
uint8_t oidLen
Definition: lldp_tlv.h:299
MIB object descriptor.
Definition: mib_common.h:236
@ MIB_ROW_STATUS_CREATE_AND_WAIT
Definition: mib_common.h:107
error_t(* MibGetNext)(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next object.
Definition: mib_common.h:227
@ MIB_STORAGE_TYPE_VOLATILE
Definition: mib_common.h:119
@ INET_SCOPE_TYPE_RESERVED
Definition: mib_common.h:147
error_t mibDecodeString(const uint8_t *oid, size_t oidLen, size_t *pos, char_t *string, size_t maxStringLen, bool_t implied)
Decode instance identifier (string)
Definition: mib_common.c:149
Ipv4Addr ipAddr
Definition: ipcp.h:105
error_t mibEncodePhysAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const MacAddr *macAddr)
Encode instance identifier (physical address)
Definition: mib_common.c:596
error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv6Addr *ipAddr)
Decode instance identifier (IPv6 address)
Definition: mib_common.c:770
@ INET_SCOPE_TYPE_ORGANIZATION_LOCAL
Definition: mib_common.h:153
error_t(* MibGetValue)(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get object value.
Definition: mib_common.h:219
MibVariant
Definition: mib_common.h:196
MibLock lock
Definition: mib_common.h:301
MibUnload unload
Definition: mib_common.h:300
@ MIB_TYPE_COUNTER64
Definition: mib_common.h:66
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
void(* MibLock)(void)
Lock MIB.
Definition: mib_common.h:277
@ INET_ADDR_TYPE_IPV6Z
Definition: mib_common.h:136
@ INET_SCOPE_TYPE_ADMIN_LOCAL
Definition: mib_common.h:151
error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, const Ipv6Addr *ipAddr)
Encode instance identifier (IPv6 address)
Definition: mib_common.c:740
MibGetValue getValue
Definition: mib_common.h:247
@ MIB_ACCESS_READ_CREATE
Definition: mib_common.h:81
@ INET_SCOPE_TYPE_LINK_LOCAL
Definition: mib_common.h:149
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:47
@ MIB_STORAGE_TYPE_PERMANENT
Definition: mib_common.h:121
InetAddrType
Internet address types.
Definition: mib_common.h:131
error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const IpAddr *ipAddr)
Encode instance identifier (IP address)
Definition: mib_common.c:808