36 #ifndef LWIP_HDR_APPS_SNMP_CORE_H
37 #define LWIP_HDR_APPS_SNMP_CORE_H
51 #define SNMP_ASN1_CLASS_UNIVERSAL 0x00
52 #define SNMP_ASN1_CLASS_APPLICATION 0x40
53 #define SNMP_ASN1_CLASS_CONTEXT 0x80
54 #define SNMP_ASN1_CLASS_PRIVATE 0xC0
56 #define SNMP_ASN1_CONTENTTYPE_PRIMITIVE 0x00
57 #define SNMP_ASN1_CONTENTTYPE_CONSTRUCTED 0x20
60 #define SNMP_ASN1_UNIVERSAL_END_OF_CONTENT 0
61 #define SNMP_ASN1_UNIVERSAL_INTEGER 2
62 #define SNMP_ASN1_UNIVERSAL_OCTET_STRING 4
63 #define SNMP_ASN1_UNIVERSAL_NULL 5
64 #define SNMP_ASN1_UNIVERSAL_OBJECT_ID 6
65 #define SNMP_ASN1_UNIVERSAL_SEQUENCE_OF 16
68 #define SNMP_ASN1_APPLICATION_IPADDR 0
69 #define SNMP_ASN1_APPLICATION_COUNTER 1
70 #define SNMP_ASN1_APPLICATION_GAUGE 2
71 #define SNMP_ASN1_APPLICATION_TIMETICKS 3
72 #define SNMP_ASN1_APPLICATION_OPAQUE 4
73 #define SNMP_ASN1_APPLICATION_COUNTER64 6
76 #define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_INSTANCE 1
79 #define SNMP_ASN1_TYPE_END_OF_CONTENT (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_END_OF_CONTENT)
80 #define SNMP_ASN1_TYPE_INTEGER (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_INTEGER)
81 #define SNMP_ASN1_TYPE_OCTET_STRING (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_OCTET_STRING)
82 #define SNMP_ASN1_TYPE_NULL (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_NULL)
83 #define SNMP_ASN1_TYPE_OBJECT_ID (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_UNIVERSAL_OBJECT_ID)
84 #define SNMP_ASN1_TYPE_SEQUENCE (SNMP_ASN1_CLASS_UNIVERSAL | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_UNIVERSAL_SEQUENCE_OF)
85 #define SNMP_ASN1_TYPE_IPADDR (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_IPADDR)
86 #define SNMP_ASN1_TYPE_IPADDRESS SNMP_ASN1_TYPE_IPADDR
87 #define SNMP_ASN1_TYPE_COUNTER (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_COUNTER)
88 #define SNMP_ASN1_TYPE_COUNTER32 SNMP_ASN1_TYPE_COUNTER
89 #define SNMP_ASN1_TYPE_GAUGE (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_GAUGE)
90 #define SNMP_ASN1_TYPE_GAUGE32 SNMP_ASN1_TYPE_GAUGE
91 #define SNMP_ASN1_TYPE_UNSIGNED32 SNMP_ASN1_TYPE_GAUGE
92 #define SNMP_ASN1_TYPE_TIMETICKS (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_TIMETICKS)
93 #define SNMP_ASN1_TYPE_OPAQUE (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_OPAQUE)
94 #define SNMP_ASN1_TYPE_COUNTER64 (SNMP_ASN1_CLASS_APPLICATION | SNMP_ASN1_CONTENTTYPE_PRIMITIVE | SNMP_ASN1_APPLICATION_COUNTER64)
96 #define SNMP_VARBIND_EXCEPTION_OFFSET 0xF0
97 #define SNMP_VARBIND_EXCEPTION_MASK 0x0F
101 SNMP_ERR_NOERROR = 0,
108 SNMP_ERR_GENERROR = 5,
109 SNMP_ERR_NOACCESS = 6,
110 SNMP_ERR_WRONGTYPE = 7,
111 SNMP_ERR_WRONGLENGTH = 8,
112 SNMP_ERR_WRONGENCODING = 9,
113 SNMP_ERR_WRONGVALUE = 10,
114 SNMP_ERR_NOCREATION = 11,
115 SNMP_ERR_INCONSISTENTVALUE = 12,
116 SNMP_ERR_RESOURCEUNAVAILABLE = 13,
117 SNMP_ERR_COMMITFAILED = 14,
118 SNMP_ERR_UNDOFAILED = 15,
119 SNMP_ERR_NOTWRITABLE = 17,
120 SNMP_ERR_INCONSISTENTNAME = 18,
122 SNMP_ERR_NOSUCHINSTANCE = SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_INSTANCE
132 struct snmp_obj_id_const_ref
138 extern const struct snmp_obj_id_const_ref snmp_zero_dot_zero;
141 union snmp_variant_value
144 const void* const_ptr;
156 #define SNMP_NODE_TREE 0x00
158 #define SNMP_NODE_SCALAR 0x01
159 #define SNMP_NODE_SCALAR_ARRAY 0x02
160 #define SNMP_NODE_TABLE 0x03
161 #define SNMP_NODE_THREADSYNC 0x04
174 SNMP_NODE_INSTANCE_ACCESS_READ = 1,
175 SNMP_NODE_INSTANCE_ACCESS_WRITE = 2,
176 SNMP_NODE_INSTANCE_READ_ONLY = SNMP_NODE_INSTANCE_ACCESS_READ,
177 SNMP_NODE_INSTANCE_READ_WRITE = (SNMP_NODE_INSTANCE_ACCESS_READ | SNMP_NODE_INSTANCE_ACCESS_WRITE),
178 SNMP_NODE_INSTANCE_WRITE_ONLY = SNMP_NODE_INSTANCE_ACCESS_WRITE,
179 SNMP_NODE_INSTANCE_NOT_ACCESSIBLE = 0
182 struct snmp_node_instance;
184 typedef s16_t (*node_instance_get_value_method)(
struct snmp_node_instance*,
void*);
185 typedef snmp_err_t (*node_instance_set_test_method)(
struct snmp_node_instance*,
u16_t,
void*);
186 typedef snmp_err_t (*node_instance_set_value_method)(
struct snmp_node_instance*,
u16_t,
void*);
187 typedef void (*node_instance_release_method)(
struct snmp_node_instance*);
189 #define SNMP_GET_VALUE_RAW_DATA 0x8000
192 struct snmp_node_instance
195 const struct snmp_node* node;
197 struct snmp_obj_id instance_oid;
202 snmp_access_t access;
205 node_instance_get_value_method get_value;
207 node_instance_set_test_method set_test;
209 node_instance_set_value_method set_value;
211 node_instance_release_method release_instance;
214 union snmp_variant_value reference;
221 struct snmp_tree_node
224 struct snmp_node node;
226 const struct snmp_node*
const *subnodes;
229 #define SNMP_CREATE_TREE_NODE(oid, subnodes) \
230 {{ SNMP_NODE_TREE, (oid) }, \
231 (u16_t)LWIP_ARRAYSIZE(subnodes), (subnodes) }
233 #define SNMP_CREATE_EMPTY_TREE_NODE(oid) \
234 {{ SNMP_NODE_TREE, (oid) }, \
238 struct snmp_leaf_node
241 struct snmp_node node;
242 snmp_err_t (*get_instance)(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance);
243 snmp_err_t (*get_next_instance)(
const u32_t *root_oid,
u8_t root_oid_len,
struct snmp_node_instance* instance);
249 const u32_t *base_oid;
251 const struct snmp_node *root_node;
254 #define SNMP_MIB_CREATE(oid_list, root_node) { (oid_list), (u8_t)LWIP_ARRAYSIZE(oid_list), root_node }
257 struct snmp_oid_range
264 u8_t snmp_oid_in_range(
const u32_t *oid_in,
u8_t oid_len,
const struct snmp_oid_range *oid_ranges,
u8_t oid_ranges_len);
267 SNMP_NEXT_OID_STATUS_SUCCESS,
268 SNMP_NEXT_OID_STATUS_NO_MATCH,
269 SNMP_NEXT_OID_STATUS_BUF_TO_SMALL
270 } snmp_next_oid_status_t;
273 struct snmp_next_oid_state
275 const u32_t* start_oid;
280 u8_t next_oid_max_len;
282 snmp_next_oid_status_t
status;
286 void snmp_next_oid_init(
struct snmp_next_oid_state *
state,
287 const u32_t *start_oid,
u8_t start_oid_len,
288 u32_t *next_oid_buf,
u8_t next_oid_max_len);
289 u8_t snmp_next_oid_precheck(
struct snmp_next_oid_state *
state,
const u32_t *oid,
const u8_t oid_len);
290 u8_t snmp_next_oid_check(
struct snmp_next_oid_state *
state,
const u32_t *oid,
const u8_t oid_len,
void* reference);
292 void snmp_oid_assign(
struct snmp_obj_id* target,
const u32_t *oid,
u8_t oid_len);
293 void snmp_oid_combine(
struct snmp_obj_id* target,
const u32_t *oid1,
u8_t oid1_len,
const u32_t *oid2,
u8_t oid2_len);
294 void snmp_oid_prefix(
struct snmp_obj_id* target,
const u32_t *oid,
u8_t oid_len);
295 void snmp_oid_append(
struct snmp_obj_id* target,
const u32_t *oid,
u8_t oid_len);
300 u8_t snmp_oid_to_ip4(
const u32_t *oid, ip4_addr_t *ip);
301 void snmp_ip4_to_oid(
const ip4_addr_t *ip,
u32_t *oid);
304 u8_t snmp_oid_to_ip6(
const u32_t *oid, ip6_addr_t *ip);
305 void snmp_ip6_to_oid(
const ip6_addr_t *ip,
u32_t *oid);
307 #if LWIP_IPV4 || LWIP_IPV6
318 snmp_err_t snmp_set_test_ok(
struct snmp_node_instance* instance,
u16_t value_len,
void* value);
321 err_t snmp_decode_truthvalue(
const s32_t *asn1_value,
u8_t *bool_value);
325 struct snmp_statistics
330 u32_t inbadcommunitynames;
331 u32_t inbadcommunityuses;
332 u32_t inasnparseerrs;
338 u32_t intotalreqvars;
339 u32_t intotalsetvars;
343 u32_t ingetresponses;
346 u32_t outnosuchnames;
349 u32_t outgetrequests;
351 u32_t outsetrequests;
352 u32_t outgetresponses;
356 extern struct snmp_statistics snmp_stats;