mikroSDK Reference Manual
mib_common.h
Go to the documentation of this file.
1
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
45struct _MibObject;
46#define MibObject struct _MibObject
47
48//C++ guard
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53
58typedef enum
59{
60 MIB_TYPE_IP_ADDRESS = 0,
61 MIB_TYPE_COUNTER32 = 1,
62 MIB_TYPE_GAUGE32 = 2,
63 MIB_TYPE_UNSIGNED32 = 2,
64 MIB_TYPE_TIME_TICKS = 3,
65 MIB_TYPE_OPAQUE = 4,
66 MIB_TYPE_COUNTER64 = 6
67} MibType;
68
69
74typedef enum
75{
76 MIB_ACCESS_NONE = 0,
77 MIB_ACCESS_FOR_NOTIFY = 1,
78 MIB_ACCESS_WRITE_ONLY = 2,
79 MIB_ACCESS_READ_ONLY = 3,
80 MIB_ACCESS_READ_WRITE = 4,
81 MIB_ACCESS_READ_CREATE = 5,
82} MibAccess;
83
84
89typedef enum
90{
91 MIB_TRUTH_VALUE_TRUE = 1,
92 MIB_TRUTH_VALUE_FALSE = 2
94
95
100typedef enum
101{
102 MIB_ROW_STATUS_UNUSED = 0,
103 MIB_ROW_STATUS_ACTIVE = 1,
104 MIB_ROW_STATUS_NOT_IN_SERVICE = 2,
105 MIB_ROW_STATUS_NOT_READY = 3,
106 MIB_ROW_STATUS_CREATE_AND_GO = 4,
107 MIB_ROW_STATUS_CREATE_AND_WAIT = 5,
108 MIB_ROW_STATUS_DESTROY = 6
110
111
116typedef enum
117{
118 MIB_STORAGE_TYPE_OTHER = 1,
119 MIB_STORAGE_TYPE_VOLATILE = 2,
120 MIB_STORAGE_TYPE_NON_VOLATILE = 3,
121 MIB_STORAGE_TYPE_PERMANENT = 4,
122 MIB_STORAGE_TYPE_READ_ONLY = 5,
124
125
130typedef enum
131{
132 INET_ADDR_TYPE_UNKNOWN = 0,
133 INET_ADDR_TYPE_IPV4 = 1,
134 INET_ADDR_TYPE_IPV6 = 2,
135 INET_ADDR_TYPE_IPV4Z = 3,
136 INET_ADDR_TYPE_IPV6Z = 4,
137 INET_ADDR_TYPE_DNS = 16
139
140
145typedef enum
146{
147 INET_SCOPE_TYPE_RESERVED = 0,
148 INET_SCOPE_TYPE_INTERFACE_LOCAL = 1,
149 INET_SCOPE_TYPE_LINK_LOCAL = 2,
150 INET_SCOPE_TYPE_SUBNET_LOCAL = 3,
151 INET_SCOPE_TYPE_ADMIN_LOCAL = 4,
152 INET_SCOPE_TYPE_SITE_LOCAL = 5,
153 INET_SCOPE_TYPE_ORGANIZATION_LOCAL = 8,
154 INET_SCOPE_TYPE_GLOBAL = 14
156
157
162typedef enum
163{
164 INET_VERSION_UNKNOWN = 0,
165 INET_VERSION_IPV4 = 1,
166 INET_VERSION_IPV6 = 2
168
169
170//CodeWarrior or Win32 compiler?
171#if defined(__CWCC__) || defined(_WIN32)
172 #pragma pack(push, 1)
173#endif
174
175
181{
182 __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 };
194} MibVariant;
195
196
197//CodeWarrior or Win32 compiler?
198#if defined(__CWCC__) || defined(_WIN32)
199 #pragma pack(pop)
200#endif
201
202
207typedef 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
215typedef error_t (*MibGetValue)(const MibObject *object, const uint8_t *oid,
216 size_t oidLen, MibVariant *value, size_t *valueLen);
217
218
223typedef error_t (*MibGetNext)(const MibObject *object, const uint8_t *oid,
224 size_t oidLen, uint8_t *nextOid, size_t *nextOidLen);
225
226
232{
233 const char_t *name;
234 uint8_t oid[MIB_MAX_OID_SIZE];
235 size_t oidLen;
236 uint_t objClass;
237 uint_t objType;
238 MibAccess access;
239 void *value;
240 size_t *valueLen;
241 size_t valueSize;
242 MibSetValue setValue;
243 MibGetValue getValue;
244 MibGetNext getNext;
245};
246
247
252typedef error_t (*MibInit)(void);
253
254
259typedef error_t (*MibLoad)(void *context);
260
261
266typedef void (*MibUnload)(void *context);
267
268
273typedef void (*MibLock)(void);
274
275
280typedef void (*MibUnlock)(void);
281
282
287typedef struct
288{
289 const char_t *name;
290 uint8_t oid[MIB_MAX_OID_SIZE];
291 size_t oidLen;
292 const MibObject *objects;
293 uint_t numObjects;
294 MibInit init;
295 MibLoad load;
296 MibUnload unload;
297 MibLock lock;
298 MibUnlock unlock;
299} MibModule;
300
301
302//MIB related functions
303error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos,
304 uint_t index);
305
306error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos,
307 uint_t *index);
308
309error_t mibEncodeUnsigned32(uint8_t *oid, size_t maxOidLen, size_t *pos,
310 uint32_t value);
311
312error_t mibDecodeUnsigned32(const uint8_t *oid, size_t oidLen, size_t *pos,
313 uint32_t *value);
314
315error_t mibEncodeString(uint8_t *oid, size_t maxOidLen, size_t *pos,
316 const char_t *string, bool_t implied);
317
318error_t mibDecodeString(const uint8_t *oid, size_t oidLen, size_t *pos,
319 char_t *string, size_t maxStringLen, bool_t implied);
320
321error_t mibEncodeOctetString(uint8_t *oid, size_t maxOidLen, size_t *pos,
322 const uint8_t *data, size_t dataLen, bool_t implied);
323
324error_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
327error_t mibEncodeObjectIdentifier(uint8_t *oid, size_t maxOidLen, size_t *pos,
328 const uint8_t *objectId, size_t objectIdLen, bool_t implied);
329
330error_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
333error_t mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos,
334 uint16_t port);
335
336error_t mibDecodePort(const uint8_t *oid, size_t oidLen, size_t *pos,
337 uint16_t *port);
338
339error_t mibEncodeMacAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
340 const MacAddr *macAddr);
341
342error_t mibDecodeMacAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
343 MacAddr *macAddr);
344
345error_t mibEncodePhysAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
346 const MacAddr *macAddr);
347
348error_t mibDecodePhysAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
349 MacAddr *macAddr);
350
351error_t mibEncodeIpv4Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
352 Ipv4Addr ipAddr);
353
354error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
355 Ipv4Addr *ipAddr);
356
357error_t mibEncodeIpv6Addr(uint8_t *oid, size_t maxOidLen, size_t *pos,
358 const Ipv6Addr *ipAddr);
359
360error_t mibDecodeIpv6Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
361 Ipv6Addr *ipAddr);
362
363error_t mibEncodeIpAddr(uint8_t *oid, size_t maxOidLen, size_t *pos,
364 const IpAddr *ipAddr);
365
366error_t mibDecodeIpAddr(const uint8_t *oid, size_t oidLen, size_t *pos,
367 IpAddr *ipAddr);
368
369int_t mibCompMacAddr(const MacAddr *macAddr1, const MacAddr *macAddr2);
370int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2);
371
372error_t mibTestAndIncSpinLock(int32_t *spinLock, int32_t value, bool_t commit);
373
374//C++ guard
375#ifdef __cplusplus
376}
377#endif
378
379#endif
error_t
Error codes.
Definition error.h:43
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
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
MibTruthValue
Truth value.
Definition mib_common.h:90
MibRowStatus
Row status.
Definition mib_common.h:101
InetVersion
IP protocol version.
Definition mib_common.h:163
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
MibStorageType
Storage type.
Definition mib_common.h:117
void(* MibLock)(void)
Lock MIB.
Definition mib_common.h:273
MibAccess
Access modes.
Definition mib_common.h:75
MibType
MIB object types.
Definition mib_common.h:59
void(* MibUnload)(void *context)
Unload MIB.
Definition mib_common.h:266
error_t(* MibLoad)(void *context)
Load MIB.
Definition mib_common.h:259
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
typedef __packed_struct
Variant data type.
Definition mib_common.h:181
void(* MibUnlock)(void)
Unlock MIB.
Definition mib_common.h:280
InetScopeType
Internet address scope.
Definition mib_common.h:146
InetAddrType
Internet address types.
Definition mib_common.h:131
error_t(* MibInit)(void)
MIB initialization.
Definition mib_common.h:252
TCP/IP stack core.
IP network address.
Definition ip.h:72
MIB module.
Definition mib_common.h:288
MIB object descriptor.
Definition mib_common.h:232