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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _MIB_COMMON_H
30 #define _MIB_COMMON_H
31 
32 //Dependencies
33 #include "core/net.h"
34 
35 //Maximum OID size
36 #ifndef MIB_MAX_OID_SIZE
37  #define MIB_MAX_OID_SIZE 16
38 #elif (MIB_MAX_OID_SIZE < 1)
39  #error MIB_MAX_OID_SIZE parameter is not valid
40 #endif
41 
42 //Forward declaration of MibObject structure
43 struct _MibObject;
44 #define MibObject struct _MibObject
45 
46 //C++ guard
47 #ifdef __cplusplus
48  extern "C" {
49 #endif
50 
51 
52 /**
53  * @brief MIB object types
54  **/
55 
56 typedef enum
57 {
65 } MibType;
66 
67 
68 /**
69  * @brief Access modes
70  **/
71 
72 typedef enum
73 {
80 } MibAccess;
81 
82 
83 /**
84  * @brief Truth value
85  **/
86 
87 typedef enum
88 {
92 
93 
94 /**
95  * @brief Row status
96  **/
97 
98 typedef enum
99 {
107 } MibRowStatus;
108 
109 
110 /**
111  * @brief Storage type
112  **/
113 
114 typedef enum
115 {
122 
123 
124 /**
125  * @brief Internet address types
126  **/
127 
128 typedef enum
129 {
136 } InetAddrType;
137 
138 
139 /**
140  * @brief Internet address scope
141  **/
142 
143 typedef enum
144 {
153 } InetScopeType;
154 
155 
156 /**
157  * @brief IP protocol version
158  **/
159 
160 typedef enum
161 {
165 } InetVersion;
166 
167 
168 //CodeWarrior or Win32 compiler?
169 #if defined(__CWCC__) || defined(_WIN32)
170  #pragma pack(push, 1)
171 #endif
172 
173 
174 /**
175  * @brief Variant data type
176  **/
177 
178 typedef __start_packed struct
179 {
180  __start_packed union
181  {
182  int32_t integer;
183  uint8_t octetString[1];
184  uint8_t oid[1];
185  uint8_t ipAddr[4];
186  uint32_t counter32;
187  uint32_t gauge32;
188  uint32_t unsigned32;
189  uint32_t timeTicks;
190  uint64_t counter64;
191  };
193 
194 
195 //CodeWarrior or Win32 compiler?
196 #if defined(__CWCC__) || defined(_WIN32)
197  #pragma pack(pop)
198 #endif
199 
200 
201 /**
202  * @brief Set object value
203  **/
204 
205 typedef error_t (*MibSetValue)(const MibObject *object, const uint8_t *oid,
206  size_t oidLen, const MibVariant *value, size_t valueLen, bool_t commit);
207 
208 
209 /**
210  * @brief Get object value
211  **/
212 
213 typedef error_t (*MibGetValue)(const MibObject *object, const uint8_t *oid,
214  size_t oidLen, MibVariant *value, size_t *valueLen);
215 
216 
217 /**
218  * @brief Get next object
219  **/
220 
221 typedef error_t (*MibGetNext)(const MibObject *object, const uint8_t *oid,
222  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen);
223 
224 
225 /**
226  * @brief MIB object descriptor
227  **/
228 
230 {
231  const char_t *name;
233  size_t oidLen;
237  void *value;
238  size_t *valueLen;
239  size_t valueSize;
243 };
244 
245 
246 /**
247  * @brief MIB initialization
248  **/
249 
250 typedef error_t (*MibInit)(void);
251 
252 
253 /**
254  * @brief Load MIB
255  **/
256 
257 typedef error_t (*MibLoad)(void *context);
258 
259 
260 /**
261  * @brief Unload MIB
262  **/
263 
264 typedef void (*MibUnload)(void *context);
265 
266 
267 /**
268  * @brief Lock MIB
269  **/
270 
271 typedef void (*MibLock)(void);
272 
273 
274 /**
275  * @brief Unlock MIB
276  **/
277 
278 typedef void (*MibUnlock)(void);
279 
280 
281 /**
282  * @brief MIB module
283  **/
284 
285 typedef struct
286 {
287  const char_t *name;
289  size_t oidLen;
297 } MibModule;
298 
299 
300 //MIB related functions
301 error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos,
302  uint_t index);
303 
304 error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos,
305  uint_t *index);
306 
307 error_t mibEncodeUnsigned32(uint8_t *oid, size_t maxOidLen, size_t *pos,
308  uint32_t value);
309 
310 error_t mibDecodeUnsigned32(const uint8_t *oid, size_t oidLen, size_t *pos,
311  uint32_t *value);
312 
313 error_t mibEncodeString(uint8_t *oid, size_t maxOidLen, size_t *pos,
314  const char_t *string, bool_t implied);
315 
316 error_t mibDecodeString(const uint8_t *oid, size_t oidLen, size_t *pos,
317  char_t *string, size_t maxStringLen, bool_t implied);
318 
319 error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos,
320  const uint8_t *data, size_t dataLen, bool_t implied);
321 
322 error_t mibDecodeOctetString(const uint8_t *oid, size_t oidLen, size_t *pos,
323  uint8_t *data, size_t maxDataLen, size_t *dataLen, bool_t implied);
324 
325 error_t mibEncodeObjectIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos,
326  const uint8_t *objectId, size_t objectIdLen, bool_t implied);
327 
328 error_t mibDecodeObjectIdentifier(const uint8_t *oid, size_t oidLen, size_t *pos,
329  uint8_t *objectId, size_t maxObjectIdLen, size_t *objectIdLen, bool_t implied);
330 
331 error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos,
332  uint16_t port);
333 
334 error_t mibDecodePort(const uint8_t *oid, size_t oidLen, size_t *pos,
335  uint16_t *port);
336 
337 error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
338  const MacAddr *macAddr);
339 
340 error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
341  MacAddr *macAddr);
342 
343 error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
344  Ipv4Addr ipAddr);
345 
346 error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
347  Ipv4Addr *ipAddr);
348 
349 error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
350  const Ipv6Addr *ipAddr);
351 
352 error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
353  Ipv6Addr *ipAddr);
354 
355 error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
356  const IpAddr *ipAddr);
357 
358 error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
359  IpAddr *ipAddr);
360 
361 int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2);
362 
363 error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit);
364 
365 //C++ guard
366 #ifdef __cplusplus
367  }
368 #endif
369 
370 #endif
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:232
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:45
void(* MibUnlock)(void)
Unlock MIB.
Definition: mib_common.h:278
MibStorageType
Storage type.
Definition: mib_common.h:114
size_t * valueLen
Definition: mib_common.h:238
uint8_t oid[MIB_MAX_OID_SIZE]
Definition: mib_common.h:232
char char_t
Definition: compiler_port.h:41
const char_t * name
Definition: mib_common.h:231
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:223
size_t oidLen
Definition: mib_common.h:289
TCP/IP stack core.
error_t(* MibLoad)(void *context)
Load MIB.
Definition: mib_common.h:257
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:205
error_t(* MibInit)(void)
MIB initialization.
Definition: mib_common.h:250
MibLoad load
Definition: mib_common.h:293
MibRowStatus
Row status.
Definition: mib_common.h:98
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:493
InetScopeType
Internet address scope.
Definition: mib_common.h:143
#define MibObject
Definition: mib_common.h:44
MibAccess
Access modes.
Definition: mib_common.h:72
IP network address.
Definition: ip.h:57
uint32_t counter32
Definition: mib_common.h:186
__start_packed struct @183 Ipv6Addr
IPv6 network address.
uint_t numObjects
Definition: mib_common.h:291
error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv4Addr *ipAddr)
Decode instance identifier (IPv4 address)
Definition: mib_common.c:645
error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv6Addr *ipAddr)
Decode instance identifier (IPv6 address)
Definition: mib_common.c:717
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:92
MibAccess access
Definition: mib_common.h:236
int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2)
Compare IP addresses.
Definition: mib_common.c:901
uint_t objClass
Definition: mib_common.h:234
MibLock lock
Definition: mib_common.h:295
size_t valueSize
Definition: mib_common.h:239
uint8_t ipAddr[4]
Definition: mib_common.h:185
uint32_t gauge32
Definition: mib_common.h:187
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:109
MibSetValue setValue
Definition: mib_common.h:240
int32_t integer
Definition: mib_common.h:182
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:147
MIB object descriptor.
Definition: mib_common.h:229
signed int int_t
Definition: compiler_port.h:42
uint64_t counter64
Definition: mib_common.h:190
error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit)
Test and increment spin lock.
Definition: mib_common.c:939
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:295
MibTruthValue
Truth value.
Definition: mib_common.h:87
error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos, MacAddr *macAddr)
Decode instance identifier (MAC address)
Definition: mib_common.c:562
MibType
MIB object types.
Definition: mib_common.h:56
uint32_t timeTicks
Definition: mib_common.h:189
uint32_t unsigned32
Definition: mib_common.h:188
size_t oidLen
Definition: mib_common.h:233
uint_t objType
Definition: mib_common.h:235
error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const IpAddr *ipAddr)
Encode instance identifier (IP address)
Definition: mib_common.c:755
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:375
error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos, uint16_t port)
Encode instance identifier (port number)
Definition: mib_common.c:476
uint8_t octetString[1]
Definition: mib_common.h:183
__start_packed struct _Ipv4Header __end_packed
MibUnlock unlock
Definition: mib_common.h:296
MibUnload unload
Definition: mib_common.h:294
error_t
Error codes.
Definition: error.h:40
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:213
__start_packed struct @208 MibVariant
Variant data type.
unsigned int uint_t
Definition: compiler_port.h:43
__start_packed struct @112 MacAddr
MAC address.
uint8_t data[]
Definition: dtls_misc.h:167
uint8_t value[]
Definition: dtls_misc.h:141
uint16_t port
Definition: dns_common.h:221
const char_t * name
Definition: mib_common.h:287
const MibObject * objects
Definition: mib_common.h:290
MibGetValue getValue
Definition: mib_common.h:241
error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos, IpAddr *ipAddr)
Decode instance identifier (IP address)
Definition: mib_common.c:833
MIB module.
Definition: mib_common.h:285
InetVersion
IP protocol version.
Definition: mib_common.h:160
void(* MibLock)(void)
Lock MIB.
Definition: mib_common.h:271
error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, Ipv4Addr ipAddr)
Encode instance identifier (IPv4 address)
Definition: mib_common.c:611
MibGetNext getNext
Definition: mib_common.h:242
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:127
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:180
MibInit init
Definition: mib_common.h:292
uint8_t oid[1]
Definition: mib_common.h:184
void * value
Definition: mib_common.h:237
error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos, uint_t *index)
Decode instance identifier (index)
Definition: mib_common.c:62
int bool_t
Definition: compiler_port.h:47
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:221
error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos, const Ipv6Addr *ipAddr)
Encode instance identifier (IPv6 address)
Definition: mib_common.c:687
InetAddrType
Internet address types.
Definition: mib_common.h:128
#define MIB_MAX_OID_SIZE
Definition: mib_common.h:37
void(* MibUnload)(void *context)
Unload MIB.
Definition: mib_common.h:264
error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos, const MacAddr *macAddr)
Encode instance identifier (MAC address)
Definition: mib_common.c:526