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-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  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.6
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 {
67 } MibType;
68 
69 
70 /**
71  * @brief Access modes
72  **/
73 
74 typedef enum
75 {
82 } MibAccess;
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 {
109 } MibRowStatus;
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 {
138 } InetAddrType;
139 
140 
141 /**
142  * @brief Internet address scope
143  **/
144 
145 typedef enum
146 {
155 } InetScopeType;
156 
157 
158 /**
159  * @brief IP protocol version
160  **/
161 
162 typedef enum
163 {
167 } InetVersion;
168 
169 
170 //CodeWarrior or Win32 compiler?
171 #if defined(__CWCC__) || defined(_WIN32)
172  #pragma pack(push, 1)
173 #endif
174 
175 
176 /**
177  * @brief Variant data type
178  **/
179 
180 typedef __start_packed struct
181 {
182  __start_packed union
183  {
184  int32_t integer;
185  uint8_t octetString[1];
186  uint8_t oid[1];
187  uint8_t ipAddr[4];
188  uint32_t counter32;
189  uint32_t gauge32;
190  uint32_t unsigned32;
191  uint32_t timeTicks;
192  uint64_t counter64;
193  };
195 
196 
197 //CodeWarrior or Win32 compiler?
198 #if defined(__CWCC__) || defined(_WIN32)
199  #pragma pack(pop)
200 #endif
201 
202 
203 /**
204  * @brief Set object value
205  **/
206 
207 typedef error_t (*MibSetValue)(const MibObject *object, const uint8_t *oid,
208  size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit);
209 
210 
211 /**
212  * @brief Get object value
213  **/
214 
215 typedef error_t (*MibGetValue)(const MibObject *object, const uint8_t *oid,
216  size_t oidLen, MibVariant *value, size_t *valueLen);
217 
218 
219 /**
220  * @brief Get next object
221  **/
222 
223 typedef error_t (*MibGetNext)(const MibObject *object, const uint8_t *oid,
224  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen);
225 
226 
227 /**
228  * @brief MIB object descriptor
229  **/
230 
232 {
233  const char_t *name;
235  size_t oidLen;
239  void *value;
240  size_t *valueLen;
241  size_t valueSize;
245 };
246 
247 
248 /**
249  * @brief MIB initialization
250  **/
251 
252 typedef error_t (*MibInit)(void);
253 
254 
255 /**
256  * @brief Load MIB
257  **/
258 
259 typedef error_t (*MibLoad)(void *context);
260 
261 
262 /**
263  * @brief Unload MIB
264  **/
265 
266 typedef void (*MibUnload)(void *context);
267 
268 
269 /**
270  * @brief Lock MIB
271  **/
272 
273 typedef void (*MibLock)(void);
274 
275 
276 /**
277  * @brief Unlock MIB
278  **/
279 
280 typedef void (*MibUnlock)(void);
281 
282 
283 /**
284  * @brief MIB module
285  **/
286 
287 typedef struct
288 {
289  const char_t *name;
291  size_t oidLen;
299 } MibModule;
300 
301 
302 //MIB related functions
303 error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos,
304  uint_t index);
305 
306 error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos,
307  uint_t *index);
308 
309 error_t mibEncodeUnsigned32(uint8_t *oid, size_t maxOidLen, size_t *pos,
310  uint32_t value);
311 
312 error_t mibDecodeUnsigned32(const uint8_t *oid, size_t oidLen, size_t *pos,
313  uint32_t *value);
314 
315 error_t mibEncodeString(uint8_t *oid, size_t maxOidLen, size_t *pos,
316  const char_t *string, bool_t implied);
317 
318 error_t mibDecodeString(const uint8_t *oid, size_t oidLen, size_t *pos,
319  char_t *string, size_t maxStringLen, bool_t implied);
320 
321 error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos,
322  const uint8_t *data, size_t dataLen, bool_t implied);
323 
324 error_t mibDecodeOctetString(const uint8_t *oid, size_t oidLen, size_t *pos,
325  uint8_t *data, size_t maxDataLen, size_t *dataLen, bool_t implied);
326 
327 error_t mibEncodeObjectIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos,
328  const uint8_t *objectId, size_t objectIdLen, bool_t implied);
329 
330 error_t mibDecodeObjectIdentifier(const uint8_t *oid, size_t oidLen, size_t *pos,
331  uint8_t *objectId, size_t maxObjectIdLen, size_t *objectIdLen, bool_t implied);
332 
333 error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos,
334  uint16_t port);
335 
336 error_t mibDecodePort(const uint8_t *oid, size_t oidLen, size_t *pos,
337  uint16_t *port);
338 
339 error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
340  const MacAddr *macAddr);
341 
342 error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
343  MacAddr *macAddr);
344 
345 error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
346  Ipv4Addr ipAddr);
347 
348 error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
349  Ipv4Addr *ipAddr);
350 
351 error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
352  const Ipv6Addr *ipAddr);
353 
354 error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
355  Ipv6Addr *ipAddr);
356 
357 error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
358  const IpAddr *ipAddr);
359 
360 error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
361  IpAddr *ipAddr);
362 
363 int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2);
364 
365 error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit);
366 
367 //C++ guard
368 #ifdef __cplusplus
369 }
370 #endif
371 
372 #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:145
@ 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:162
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:294
@ INET_VERSION_IPV6
Definition: mib_common.h:166
@ MIB_TYPE_IP_ADDRESS
Definition: mib_common.h:60
MibGetNext getNext
Definition: mib_common.h:244
MibLoad load
Definition: mib_common.h:295
const MibObject * objects
Definition: mib_common.h:292
int bool_t
Definition: compiler_port.h:49
MibStorageType
Storage type.
Definition: mib_common.h:116
@ MIB_TYPE_OPAQUE
Definition: mib_common.h:65
uint32_t counter32
Definition: mib_common.h:188
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:239
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:207
@ MIB_STORAGE_TYPE_NON_VOLATILE
Definition: mib_common.h:120
signed int int_t
Definition: compiler_port.h:44
IP network address.
Definition: ip.h:71
@ 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:564
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:266
MibAccess access
Definition: mib_common.h:238
@ MIB_STORAGE_TYPE_OTHER
Definition: mib_common.h:118
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:252
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:280
@ MIB_TRUTH_VALUE_TRUE
Definition: mib_common.h:91
const char_t * name
Definition: mib_common.h:233
MibAccess
Access modes.
Definition: mib_common.h:74
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:240
uint8_t oid[MIB_MAX_OID_SIZE]
Definition: mib_common.h:234
__start_packed struct @205 MibVariant
Variant data type.
MibTruthValue
Truth value.
Definition: mib_common.h:89
@ INET_SCOPE_TYPE_SUBNET_LOCAL
Definition: mib_common.h:150
MibType
MIB object types.
Definition: mib_common.h:58
@ 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:239
error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv4Addr *ipAddr)
Decode instance identifier (IPv4 address)
Definition: mib_common.c:647
@ INET_SCOPE_TYPE_SITE_LOCAL
Definition: mib_common.h:152
@ MIB_ROW_STATUS_DESTROY
Definition: mib_common.h:108
MibSetValue setValue
Definition: mib_common.h:242
@ 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:903
@ INET_SCOPE_TYPE_GLOBAL
Definition: mib_common.h:154
uint_t numObjects
Definition: mib_common.h:293
@ MIB_ACCESS_READ_WRITE
Definition: mib_common.h:80
size_t valueSize
Definition: mib_common.h:241
@ 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:835
error_t
Error codes.
Definition: error.h:42
#define MIB_MAX_OID_SIZE
Definition: mib_common.h:39
int32_t integer
Definition: mib_common.h:184
error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit)
Test and increment spin lock.
Definition: mib_common.c:941
error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, Ipv4Addr ipAddr)
Encode instance identifier (IPv4 address)
Definition: mib_common.c:613
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:289
@ MIB_ROW_STATUS_UNUSED
Definition: mib_common.h:102
@ MIB_TYPE_UNSIGNED32
Definition: mib_common.h:63
uint8_t oid[1]
Definition: mib_common.h:186
__start_packed struct _Ipv4Header __end_packed
uint64_t counter64
Definition: mib_common.h:192
uint32_t unsigned32
Definition: mib_common.h:190
__start_packed struct @179 Ipv6Addr
IPv6 network address.
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
uint32_t gauge32
Definition: mib_common.h:189
size_t oidLen
Definition: mib_common.h:235
@ 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
MIB module.
Definition: mib_common.h:287
size_t oidLen
Definition: mib_common.h:291
uint_t objType
Definition: mib_common.h:237
uint_t objClass
Definition: mib_common.h:236
@ INET_ADDR_TYPE_IPV4
Definition: mib_common.h:133
uint16_t port
Definition: dns_common.h:223
@ INET_SCOPE_TYPE_INTERFACE_LOCAL
Definition: mib_common.h:148
error_t(* MibLoad)(void *context)
Load MIB.
Definition: mib_common.h:259
char char_t
Definition: compiler_port.h:43
@ 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:100
MibUnlock unlock
Definition: mib_common.h:298
@ INET_VERSION_IPV4
Definition: mib_common.h:165
#define MibObject
Definition: mib_common.h:46
MIB object descriptor.
Definition: mib_common.h:231
@ 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:223
@ MIB_STORAGE_TYPE_VOLATILE
Definition: mib_common.h:119
uint8_t octetString[1]
Definition: mib_common.h:185
@ 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
uint32_t timeTicks
Definition: mib_common.h:191
error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv6Addr *ipAddr)
Decode instance identifier (IPv6 address)
Definition: mib_common.c:719
@ 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:215
MibLock lock
Definition: mib_common.h:297
MibUnload unload
Definition: mib_common.h:296
uint8_t value[]
Definition: dtls_misc.h:150
@ MIB_TYPE_COUNTER64
Definition: mib_common.h:66
unsigned int uint_t
Definition: compiler_port.h:45
TCP/IP stack core.
uint8_t data[]
Definition: dtls_misc.h:176
void(* MibLock)(void)
Lock MIB.
Definition: mib_common.h:273
@ 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:689
uint8_t ipAddr[4]
Definition: mib_common.h:187
MibGetValue getValue
Definition: mib_common.h:243
@ 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
__start_packed struct @108 MacAddr
MAC address.
@ MIB_STORAGE_TYPE_PERMANENT
Definition: mib_common.h:121
InetAddrType
Internet address types.
Definition: mib_common.h:130
error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const IpAddr *ipAddr)
Encode instance identifier (IP address)
Definition: mib_common.c:757