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-2021 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.1.2
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
45struct _MibObject;
46#define MibObject struct _MibObject
47
48//C++ guard
49#ifdef __cplusplus
50extern "C" {
51#endif
52
53
54/**
55 * @brief MIB object types
56 **/
57
58typedef enum
59{
68
69
70/**
71 * @brief Access modes
72 **/
73
74typedef enum
75{
82} MibAccess;
83
84
85/**
86 * @brief Truth value
87 **/
88
89typedef enum
90{
94
95
96/**
97 * @brief Row status
98 **/
99
100typedef enum
101{
110
111
112/**
113 * @brief Storage type
114 **/
115
116typedef enum
117{
124
125
126/**
127 * @brief Internet address types
128 **/
129
130typedef enum
131{
139
140
141/**
142 * @brief Internet address scope
143 **/
144
145typedef enum
146{
156
157
158/**
159 * @brief IP protocol version
160 **/
161
162typedef enum
163{
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
180typedef __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
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
211/**
212 * @brief Get object value
213 **/
214
215typedef 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
223typedef 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
252typedef error_t (*MibInit)(void);
253
254
255/**
256 * @brief Load MIB
257 **/
258
259typedef error_t (*MibLoad)(void *context);
260
261
262/**
263 * @brief Unload MIB
264 **/
265
266typedef void (*MibUnload)(void *context);
267
268
269/**
270 * @brief Lock MIB
271 **/
272
273typedef void (*MibLock)(void);
274
275
276/**
277 * @brief Unlock MIB
278 **/
279
280typedef void (*MibUnlock)(void);
281
282
283/**
284 * @brief MIB module
285 **/
286
287typedef struct
288{
289 const char_t *name;
291 size_t oidLen;
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,
353
354error_t mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos,
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,
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
signed int int_t
Definition: compiler_port.h:44
unsigned int uint_t
Definition: compiler_port.h:45
char char_t
Definition: compiler_port.h:43
int bool_t
Definition: compiler_port.h:49
uint16_t port
Definition: dns_common.h:223
uint8_t value[]
Definition: dtls_misc.h:150
error_t
Error codes.
Definition: error.h:43
__start_packed struct @116 MacAddr
MAC address.
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:239
__start_packed struct _Ipv4Header __end_packed
__start_packed struct @188 Ipv6Addr
IPv6 network address.
uint32_t timeTicks
Definition: mib_common.h:191
__start_packed struct @214 MibVariant
Variant data type.
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
uint8_t octetString[1]
Definition: mib_common.h:185
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
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
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
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 mibEncodePort(uint8_t *oid, size_t maxOidLen, size_t *pos, uint16_t port)
Encode instance identifier (port number)
Definition: mib_common.c:478
#define MibObject
Definition: mib_common.h:46
MibTruthValue
Truth value.
Definition: mib_common.h:90
@ MIB_TRUTH_VALUE_TRUE
Definition: mib_common.h:91
@ MIB_TRUTH_VALUE_FALSE
Definition: mib_common.h:92
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
int32_t integer
Definition: mib_common.h:184
uint8_t ipAddr[4]
Definition: mib_common.h:187
MibRowStatus
Row status.
Definition: mib_common.h:101
@ MIB_ROW_STATUS_CREATE_AND_WAIT
Definition: mib_common.h:107
@ MIB_ROW_STATUS_UNUSED
Definition: mib_common.h:102
@ MIB_ROW_STATUS_ACTIVE
Definition: mib_common.h:103
@ MIB_ROW_STATUS_NOT_IN_SERVICE
Definition: mib_common.h:104
@ MIB_ROW_STATUS_DESTROY
Definition: mib_common.h:108
@ MIB_ROW_STATUS_CREATE_AND_GO
Definition: mib_common.h:106
@ MIB_ROW_STATUS_NOT_READY
Definition: mib_common.h:105
InetVersion
IP protocol version.
Definition: mib_common.h:163
@ INET_VERSION_IPV6
Definition: mib_common.h:166
@ INET_VERSION_IPV4
Definition: mib_common.h:165
@ INET_VERSION_UNKNOWN
Definition: mib_common.h:164
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
int_t mibCompIpAddr(const IpAddr *ipAddr1, const IpAddr *ipAddr2)
Compare IP addresses.
Definition: mib_common.c:968
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
uint64_t counter64
Definition: mib_common.h:192
uint8_t oid[1]
Definition: mib_common.h:186
MibStorageType
Storage type.
Definition: mib_common.h:117
@ MIB_STORAGE_TYPE_NON_VOLATILE
Definition: mib_common.h:120
@ MIB_STORAGE_TYPE_OTHER
Definition: mib_common.h:118
@ MIB_STORAGE_TYPE_READ_ONLY
Definition: mib_common.h:122
@ MIB_STORAGE_TYPE_PERMANENT
Definition: mib_common.h:121
@ MIB_STORAGE_TYPE_VOLATILE
Definition: mib_common.h:119
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
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 mibDecodeIpv4Addr(const uint8_t *oid, size_t oidLen, size_t *pos, Ipv4Addr *ipAddr)
Decode instance identifier (IPv4 address)
Definition: mib_common.c:698
#define MIB_MAX_OID_SIZE
Definition: mib_common.h:39
void(* MibLock)(void)
Lock MIB.
Definition: mib_common.h:273
MibAccess
Access modes.
Definition: mib_common.h:75
@ MIB_ACCESS_WRITE_ONLY
Definition: mib_common.h:78
@ MIB_ACCESS_READ_ONLY
Definition: mib_common.h:79
@ MIB_ACCESS_READ_CREATE
Definition: mib_common.h:81
@ MIB_ACCESS_NONE
Definition: mib_common.h:76
@ MIB_ACCESS_READ_WRITE
Definition: mib_common.h:80
@ MIB_ACCESS_FOR_NOTIFY
Definition: mib_common.h:77
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
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 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
MibType
MIB object types.
Definition: mib_common.h:59
@ MIB_TYPE_TIME_TICKS
Definition: mib_common.h:64
@ MIB_TYPE_COUNTER32
Definition: mib_common.h:61
@ MIB_TYPE_OPAQUE
Definition: mib_common.h:65
@ MIB_TYPE_COUNTER64
Definition: mib_common.h:66
@ MIB_TYPE_IP_ADDRESS
Definition: mib_common.h:60
@ MIB_TYPE_GAUGE32
Definition: mib_common.h:62
@ MIB_TYPE_UNSIGNED32
Definition: mib_common.h:63
void(* MibUnload)(void *context)
Unload MIB.
Definition: mib_common.h:266
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
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
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
uint32_t counter32
Definition: mib_common.h:188
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
uint32_t gauge32
Definition: mib_common.h:189
void(* MibUnlock)(void)
Unlock MIB.
Definition: mib_common.h:280
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
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
InetScopeType
Internet address scope.
Definition: mib_common.h:146
@ INET_SCOPE_TYPE_INTERFACE_LOCAL
Definition: mib_common.h:148
@ INET_SCOPE_TYPE_ADMIN_LOCAL
Definition: mib_common.h:151
@ INET_SCOPE_TYPE_GLOBAL
Definition: mib_common.h:154
@ INET_SCOPE_TYPE_SITE_LOCAL
Definition: mib_common.h:152
@ INET_SCOPE_TYPE_RESERVED
Definition: mib_common.h:147
@ INET_SCOPE_TYPE_SUBNET_LOCAL
Definition: mib_common.h:150
@ INET_SCOPE_TYPE_LINK_LOCAL
Definition: mib_common.h:149
@ INET_SCOPE_TYPE_ORGANIZATION_LOCAL
Definition: mib_common.h:153
InetAddrType
Internet address types.
Definition: mib_common.h:131
@ INET_ADDR_TYPE_UNKNOWN
Definition: mib_common.h:132
@ INET_ADDR_TYPE_IPV4Z
Definition: mib_common.h:135
@ INET_ADDR_TYPE_IPV6Z
Definition: mib_common.h:136
@ INET_ADDR_TYPE_DNS
Definition: mib_common.h:137
@ INET_ADDR_TYPE_IPV4
Definition: mib_common.h:133
@ INET_ADDR_TYPE_IPV6
Definition: mib_common.h:134
int_t mibCompMacAddr(const MacAddr *macAddr1, const MacAddr *macAddr2)
Compare MAC addresses.
Definition: mib_common.c:954
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
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:47
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
uint32_t unsigned32
Definition: mib_common.h:190
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
TCP/IP stack core.
uint8_t data[]
Definition: sftp_common.h:228
uint32_t dataLen
Definition: sftp_common.h:227
MIB object descriptor.
Definition: mib_common.h:232
MibGetValue getValue
Definition: mib_common.h:243
void * value
Definition: mib_common.h:239
MibSetValue setValue
Definition: mib_common.h:242
size_t * valueLen
Definition: mib_common.h:240
const char_t * name
Definition: mib_common.h:233
size_t oidLen
Definition: mib_common.h:235
MibGetNext getNext
Definition: mib_common.h:244
uint_t objClass
Definition: mib_common.h:236
uint8_t oid[MIB_MAX_OID_SIZE]
Definition: mib_common.h:234
MibAccess access
Definition: mib_common.h:238
uint_t objType
Definition: mib_common.h:237
size_t valueSize
Definition: mib_common.h:241
IP network address.
Definition: ip.h:79
MIB module.
Definition: mib_common.h:288
const MibObject * objects
Definition: mib_common.h:292
MibInit init
Definition: mib_common.h:294
const char_t * name
Definition: mib_common.h:289
MibLock lock
Definition: mib_common.h:297
size_t oidLen
Definition: mib_common.h:291
MibLoad load
Definition: mib_common.h:295
MibUnlock unlock
Definition: mib_common.h:298
uint_t numObjects
Definition: mib_common.h:293
MibUnload unload
Definition: mib_common.h:296