FreeRTOS
[armadillo_firmware.git] / FreeRTOS / Common / ethernet / lwIP / core / snmp / mib2.c
blob035c8b1b4da0b491c9c528ae3f511f3ea9aaddca
1 /**
2 * @file
3 * Management Information Base II (RFC1213) objects and functions.
5 * @note the object identifiers for this MIB-2 and private MIB tree
6 * must be kept in sorted ascending order. This to ensure correct getnext operation.
7 */
9 /*
10 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
11 * All rights reserved.
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
16 * 1. Redistributions of source code must retain the above copyright notice,
17 * this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright notice,
19 * this list of conditions and the following disclaimer in the documentation
20 * and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
27 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
29 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 * OF SUCH DAMAGE.
35 * Author: Christiaan Simons <christiaan.simons@axon.tv>
38 #include "arch/cc.h"
39 #include "lwip/opt.h"
41 #if LWIP_SNMP
42 #include "lwip/snmp.h"
43 #include "lwip/netif.h"
44 #include "netif/etharp.h"
45 #include "lwip/ip.h"
46 #include "lwip/ip_frag.h"
47 #include "lwip/tcp.h"
48 #include "lwip/udp.h"
49 #include "lwip/snmp_asn1.h"
50 #include "lwip/snmp_structs.h"
52 /**
53 * IANA assigned enterprise ID for lwIP is 26381
54 * @see http://www.iana.org/assignments/enterprise-numbers
56 * @note this enterprise ID is assigned to the lwIP project,
57 * all object identifiers living under this ID are assigned
58 * by the lwIP maintainers (contact Christiaan Simons)!
59 * @note don't change this define, use snmp_set_sysobjid()
61 * If you need to create your own private MIB you'll need
62 * to apply for your own enterprise ID with IANA:
63 * http://www.iana.org/numbers.html
65 #define SNMP_ENTERPRISE_ID 26381
66 #define SNMP_SYSOBJID_LEN 7
67 #define SNMP_SYSOBJID {1, 3, 6, 1, 4, 1, SNMP_ENTERPRISE_ID}
69 #ifndef SNMP_SYSSERVICES
70 #define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2))
71 #endif
73 static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
74 static void system_get_value(struct obj_def *od, u16_t len, void *value);
75 static u8_t system_set_test(struct obj_def *od, u16_t len, void *value);
76 static void system_set_value(struct obj_def *od, u16_t len, void *value);
77 static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
78 static void interfaces_get_value(struct obj_def *od, u16_t len, void *value);
79 static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
80 static void ifentry_get_value(struct obj_def *od, u16_t len, void *value);
81 static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
82 static void atentry_get_value(struct obj_def *od, u16_t len, void *value);
83 static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
84 static void ip_get_value(struct obj_def *od, u16_t len, void *value);
85 static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value);
86 static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
87 static void ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value);
88 static void ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
89 static void ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value);
90 static void ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
91 static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value);
92 static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
93 static void icmp_get_value(struct obj_def *od, u16_t len, void *value);
94 #if LWIP_TCP
95 static void tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
96 static void tcp_get_value(struct obj_def *od, u16_t len, void *value);
97 static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
98 static void tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value);
99 #endif
100 static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
101 static void udp_get_value(struct obj_def *od, u16_t len, void *value);
102 static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
103 static void udpentry_get_value(struct obj_def *od, u16_t len, void *value);
104 static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
105 static void snmp_get_value(struct obj_def *od, u16_t len, void *value);
106 static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value);
107 static void snmp_set_value(struct obj_def *od, u16_t len, void *value);
110 /* snmp .1.3.6.1.2.1.11 */
111 const mib_scalar_node snmp_scalar = {
112 &snmp_get_object_def,
113 &snmp_get_value,
114 &snmp_set_test,
115 &snmp_set_value,
116 MIB_NODE_SC,
119 const s32_t snmp_ids[28] = {
120 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
121 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30
123 struct mib_node* const snmp_nodes[28] = {
124 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
125 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
126 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
127 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
128 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
129 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
130 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
131 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
132 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
133 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
134 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
135 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
136 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
137 (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar
139 const struct mib_array_node snmp = {
140 &noleafs_get_object_def,
141 &noleafs_get_value,
142 &noleafs_set_test,
143 &noleafs_set_value,
144 MIB_NODE_AR,
146 snmp_ids,
147 snmp_nodes
150 /* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */
151 /* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */
152 /* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */
154 /* udp .1.3.6.1.2.1.7 */
155 /** index root node for udpTable */
156 struct mib_list_rootnode udp_root = {
157 &noleafs_get_object_def,
158 &noleafs_get_value,
159 &noleafs_set_test,
160 &noleafs_set_value,
161 MIB_NODE_LR,
163 NULL,
164 NULL,
167 const s32_t udpentry_ids[2] = { 1, 2 };
168 struct mib_node* const udpentry_nodes[2] = {
169 (struct mib_node* const)&udp_root, (struct mib_node* const)&udp_root,
171 const struct mib_array_node udpentry = {
172 &noleafs_get_object_def,
173 &noleafs_get_value,
174 &noleafs_set_test,
175 &noleafs_set_value,
176 MIB_NODE_AR,
178 udpentry_ids,
179 udpentry_nodes
182 s32_t udptable_id = 1;
183 struct mib_node* udptable_node = (struct mib_node* const)&udpentry;
184 struct mib_ram_array_node udptable = {
185 &noleafs_get_object_def,
186 &noleafs_get_value,
187 &noleafs_set_test,
188 &noleafs_set_value,
189 MIB_NODE_RA,
191 &udptable_id,
192 &udptable_node
195 const mib_scalar_node udp_scalar = {
196 &udp_get_object_def,
197 &udp_get_value,
198 &noleafs_set_test,
199 &noleafs_set_value,
200 MIB_NODE_SC,
203 const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 };
204 struct mib_node* const udp_nodes[5] = {
205 (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar,
206 (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar,
207 (struct mib_node* const)&udptable
209 const struct mib_array_node udp = {
210 &noleafs_get_object_def,
211 &noleafs_get_value,
212 &noleafs_set_test,
213 &noleafs_set_value,
214 MIB_NODE_AR,
216 udp_ids,
217 udp_nodes
220 /* tcp .1.3.6.1.2.1.6 */
221 #if LWIP_TCP
222 /* only if the TCP protocol is available may implement this group */
223 /** index root node for tcpConnTable */
224 struct mib_list_rootnode tcpconntree_root = {
225 &noleafs_get_object_def,
226 &noleafs_get_value,
227 &noleafs_set_test,
228 &noleafs_set_value,
229 MIB_NODE_LR,
231 NULL,
232 NULL,
235 const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 };
236 struct mib_node* const tcpconnentry_nodes[5] = {
237 (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root,
238 (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root,
239 (struct mib_node* const)&tcpconntree_root
241 const struct mib_array_node tcpconnentry = {
242 &noleafs_get_object_def,
243 &noleafs_get_value,
244 &noleafs_set_test,
245 &noleafs_set_value,
246 MIB_NODE_AR,
248 tcpconnentry_ids,
249 tcpconnentry_nodes
252 s32_t tcpconntable_id = 1;
253 struct mib_node* tcpconntable_node = (struct mib_node* const)&tcpconnentry;
254 struct mib_ram_array_node tcpconntable = {
255 &noleafs_get_object_def,
256 &noleafs_get_value,
257 &noleafs_set_test,
258 &noleafs_set_value,
259 MIB_NODE_RA,
260 /** @todo update maxlength when inserting / deleting from table
261 0 when table is empty, 1 when more than one entry */
263 &tcpconntable_id,
264 &tcpconntable_node
267 const mib_scalar_node tcp_scalar = {
268 &tcp_get_object_def,
269 &tcp_get_value,
270 &noleafs_set_test,
271 &noleafs_set_value,
272 MIB_NODE_SC,
275 const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
276 struct mib_node* const tcp_nodes[15] = {
277 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
278 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
279 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
280 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
281 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
282 (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
283 (struct mib_node* const)&tcpconntable, (struct mib_node* const)&tcp_scalar,
284 (struct mib_node* const)&tcp_scalar
286 const struct mib_array_node tcp = {
287 &noleafs_get_object_def,
288 &noleafs_get_value,
289 &noleafs_set_test,
290 &noleafs_set_value,
291 MIB_NODE_AR,
293 tcp_ids,
294 tcp_nodes
296 #endif
298 /* icmp .1.3.6.1.2.1.5 */
299 const mib_scalar_node icmp_scalar = {
300 &icmp_get_object_def,
301 &icmp_get_value,
302 &noleafs_set_test,
303 &noleafs_set_value,
304 MIB_NODE_SC,
307 const s32_t icmp_ids[26] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
308 struct mib_node* const icmp_nodes[26] = {
309 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
310 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
311 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
312 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
313 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
314 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
315 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
316 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
317 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
318 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
319 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
320 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
321 (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar
323 const struct mib_array_node icmp = {
324 &noleafs_get_object_def,
325 &noleafs_get_value,
326 &noleafs_set_test,
327 &noleafs_set_value,
328 MIB_NODE_AR,
330 icmp_ids,
331 icmp_nodes
334 /** index root node for ipNetToMediaTable */
335 struct mib_list_rootnode ipntomtree_root = {
336 &noleafs_get_object_def,
337 &noleafs_get_value,
338 &noleafs_set_test,
339 &noleafs_set_value,
340 MIB_NODE_LR,
342 NULL,
343 NULL,
346 const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 };
347 struct mib_node* const ipntomentry_nodes[4] = {
348 (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root,
349 (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root
351 const struct mib_array_node ipntomentry = {
352 &noleafs_get_object_def,
353 &noleafs_get_value,
354 &noleafs_set_test,
355 &noleafs_set_value,
356 MIB_NODE_AR,
358 ipntomentry_ids,
359 ipntomentry_nodes
362 s32_t ipntomtable_id = 1;
363 struct mib_node* ipntomtable_node = (struct mib_node* const)&ipntomentry;
364 struct mib_ram_array_node ipntomtable = {
365 &noleafs_get_object_def,
366 &noleafs_get_value,
367 &noleafs_set_test,
368 &noleafs_set_value,
369 MIB_NODE_RA,
371 &ipntomtable_id,
372 &ipntomtable_node
375 /** index root node for ipRouteTable */
376 struct mib_list_rootnode iprtetree_root = {
377 &noleafs_get_object_def,
378 &noleafs_get_value,
379 &noleafs_set_test,
380 &noleafs_set_value,
381 MIB_NODE_LR,
383 NULL,
384 NULL,
387 const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
388 struct mib_node* const iprteentry_nodes[13] = {
389 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
390 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
391 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
392 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
393 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
394 (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
395 (struct mib_node* const)&iprtetree_root
397 const struct mib_array_node iprteentry = {
398 &noleafs_get_object_def,
399 &noleafs_get_value,
400 &noleafs_set_test,
401 &noleafs_set_value,
402 MIB_NODE_AR,
404 iprteentry_ids,
405 iprteentry_nodes
408 s32_t iprtetable_id = 1;
409 struct mib_node* iprtetable_node = (struct mib_node* const)&iprteentry;
410 struct mib_ram_array_node iprtetable = {
411 &noleafs_get_object_def,
412 &noleafs_get_value,
413 &noleafs_set_test,
414 &noleafs_set_value,
415 MIB_NODE_RA,
417 &iprtetable_id,
418 &iprtetable_node
421 /** index root node for ipAddrTable */
422 struct mib_list_rootnode ipaddrtree_root = {
423 &noleafs_get_object_def,
424 &noleafs_get_value,
425 &noleafs_set_test,
426 &noleafs_set_value,
427 MIB_NODE_LR,
429 NULL,
430 NULL,
433 const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 };
434 struct mib_node* const ipaddrentry_nodes[5] = {
435 (struct mib_node* const)&ipaddrtree_root,
436 (struct mib_node* const)&ipaddrtree_root,
437 (struct mib_node* const)&ipaddrtree_root,
438 (struct mib_node* const)&ipaddrtree_root,
439 (struct mib_node* const)&ipaddrtree_root
441 const struct mib_array_node ipaddrentry = {
442 &noleafs_get_object_def,
443 &noleafs_get_value,
444 &noleafs_set_test,
445 &noleafs_set_value,
446 MIB_NODE_AR,
448 ipaddrentry_ids,
449 ipaddrentry_nodes
452 s32_t ipaddrtable_id = 1;
453 struct mib_node* ipaddrtable_node = (struct mib_node* const)&ipaddrentry;
454 struct mib_ram_array_node ipaddrtable = {
455 &noleafs_get_object_def,
456 &noleafs_get_value,
457 &noleafs_set_test,
458 &noleafs_set_value,
459 MIB_NODE_RA,
461 &ipaddrtable_id,
462 &ipaddrtable_node
465 /* ip .1.3.6.1.2.1.4 */
466 const mib_scalar_node ip_scalar = {
467 &ip_get_object_def,
468 &ip_get_value,
469 &ip_set_test,
470 &noleafs_set_value,
471 MIB_NODE_SC,
474 const s32_t ip_ids[23] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
475 struct mib_node* const ip_nodes[23] = {
476 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
477 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
478 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
479 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
480 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
481 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
482 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
483 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
484 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
485 (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ipaddrtable,
486 (struct mib_node* const)&iprtetable, (struct mib_node* const)&ipntomtable,
487 (struct mib_node* const)&ip_scalar
489 const struct mib_array_node ip = {
490 &noleafs_get_object_def,
491 &noleafs_get_value,
492 &noleafs_set_test,
493 &noleafs_set_value,
494 MIB_NODE_AR,
496 ip_ids,
497 ip_nodes
500 /** index root node for atTable */
501 struct mib_list_rootnode arptree_root = {
502 &noleafs_get_object_def,
503 &noleafs_get_value,
504 &noleafs_set_test,
505 &noleafs_set_value,
506 MIB_NODE_LR,
508 NULL,
509 NULL,
512 const s32_t atentry_ids[3] = { 1, 2, 3 };
513 struct mib_node* const atentry_nodes[3] = {
514 (struct mib_node* const)&arptree_root,
515 (struct mib_node* const)&arptree_root,
516 (struct mib_node* const)&arptree_root
518 const struct mib_array_node atentry = {
519 &noleafs_get_object_def,
520 &noleafs_get_value,
521 &noleafs_set_test,
522 &noleafs_set_value,
523 MIB_NODE_AR,
525 atentry_ids,
526 atentry_nodes
529 const s32_t attable_id = 1;
530 struct mib_node* const attable_node = (struct mib_node* const)&atentry;
531 const struct mib_array_node attable = {
532 &noleafs_get_object_def,
533 &noleafs_get_value,
534 &noleafs_set_test,
535 &noleafs_set_value,
536 MIB_NODE_AR,
538 &attable_id,
539 &attable_node
542 /* at .1.3.6.1.2.1.3 */
543 s32_t at_id = 1;
544 struct mib_node* at_node = (struct mib_node* const)&attable;
545 struct mib_ram_array_node at = {
546 &noleafs_get_object_def,
547 &noleafs_get_value,
548 &noleafs_set_test,
549 &noleafs_set_value,
550 MIB_NODE_RA,
552 &at_id,
553 &at_node
556 /** index root node for ifTable */
557 struct mib_list_rootnode iflist_root = {
558 &ifentry_get_object_def,
559 &ifentry_get_value,
560 &noleafs_set_test,
561 &noleafs_set_value,
562 MIB_NODE_LR,
564 NULL,
565 NULL,
568 const s32_t ifentry_ids[22] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 };
569 struct mib_node* const ifentry_nodes[22] = {
570 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
571 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
572 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
573 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
574 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
575 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
576 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
577 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
578 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
579 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
580 (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root
582 const struct mib_array_node ifentry = {
583 &noleafs_get_object_def,
584 &noleafs_get_value,
585 &noleafs_set_test,
586 &noleafs_set_value,
587 MIB_NODE_AR,
589 ifentry_ids,
590 ifentry_nodes
593 s32_t iftable_id = 1;
594 struct mib_node* iftable_node = (struct mib_node* const)&ifentry;
595 struct mib_ram_array_node iftable = {
596 &noleafs_get_object_def,
597 &noleafs_get_value,
598 &noleafs_set_test,
599 &noleafs_set_value,
600 MIB_NODE_RA,
602 &iftable_id,
603 &iftable_node
606 /* interfaces .1.3.6.1.2.1.2 */
607 const mib_scalar_node interfaces_scalar = {
608 &interfaces_get_object_def,
609 &interfaces_get_value,
610 &noleafs_set_test,
611 &noleafs_set_value,
612 MIB_NODE_SC,
615 const s32_t interfaces_ids[2] = { 1, 2 };
616 struct mib_node* const interfaces_nodes[2] = {
617 (struct mib_node* const)&interfaces_scalar, (struct mib_node* const)&iftable
619 const struct mib_array_node interfaces = {
620 &noleafs_get_object_def,
621 &noleafs_get_value,
622 &noleafs_set_test,
623 &noleafs_set_value,
624 MIB_NODE_AR,
626 interfaces_ids,
627 interfaces_nodes
631 /* 0 1 2 3 4 5 6 */
632 /* system .1.3.6.1.2.1.1 */
633 const mib_scalar_node sys_tem_scalar = {
634 &system_get_object_def,
635 &system_get_value,
636 &system_set_test,
637 &system_set_value,
638 MIB_NODE_SC,
641 const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };
642 struct mib_node* const sys_tem_nodes[7] = {
643 (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,
644 (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,
645 (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,
646 (struct mib_node* const)&sys_tem_scalar
648 /* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */
649 const struct mib_array_node sys_tem = {
650 &noleafs_get_object_def,
651 &noleafs_get_value,
652 &noleafs_set_test,
653 &noleafs_set_value,
654 MIB_NODE_AR,
656 sys_tem_ids,
657 sys_tem_nodes
660 /* mib-2 .1.3.6.1.2.1 */
661 #if LWIP_TCP
662 #define MIB2_GROUPS 8
663 #else
664 #define MIB2_GROUPS 7
665 #endif
666 const s32_t mib2_ids[MIB2_GROUPS] =
673 #if LWIP_TCP
675 #endif
679 struct mib_node* const mib2_nodes[MIB2_GROUPS] = {
680 (struct mib_node* const)&sys_tem,
681 (struct mib_node* const)&interfaces,
682 (struct mib_node* const)&at,
683 (struct mib_node* const)&ip,
684 (struct mib_node* const)&icmp,
685 #if LWIP_TCP
686 (struct mib_node* const)&tcp,
687 #endif
688 (struct mib_node* const)&udp,
689 (struct mib_node* const)&snmp
692 const struct mib_array_node mib2 = {
693 &noleafs_get_object_def,
694 &noleafs_get_value,
695 &noleafs_set_test,
696 &noleafs_set_value,
697 MIB_NODE_AR,
698 MIB2_GROUPS,
699 mib2_ids,
700 mib2_nodes
703 /* mgmt .1.3.6.1.2 */
704 const s32_t mgmt_ids[1] = { 1 };
705 struct mib_node* const mgmt_nodes[1] = { (struct mib_node* const)&mib2 };
706 const struct mib_array_node mgmt = {
707 &noleafs_get_object_def,
708 &noleafs_get_value,
709 &noleafs_set_test,
710 &noleafs_set_value,
711 MIB_NODE_AR,
713 mgmt_ids,
714 mgmt_nodes
717 /* internet .1.3.6.1 */
718 #if SNMP_PRIVATE_MIB
719 s32_t internet_ids[2] = { 2, 4 };
720 struct mib_node* const internet_nodes[2] = { (struct mib_node* const)&mgmt, (struct mib_node* const)&private };
721 const struct mib_array_node internet = {
722 &noleafs_get_object_def,
723 &noleafs_get_value,
724 &noleafs_set_test,
725 &noleafs_set_value,
726 MIB_NODE_AR,
728 internet_ids,
729 internet_nodes
731 #else
732 const s32_t internet_ids[1] = { 2 };
733 struct mib_node* const internet_nodes[1] = { (struct mib_node* const)&mgmt };
734 const struct mib_array_node internet = {
735 &noleafs_get_object_def,
736 &noleafs_get_value,
737 &noleafs_set_test,
738 &noleafs_set_value,
739 MIB_NODE_AR,
741 internet_ids,
742 internet_nodes
744 #endif
746 /** mib-2.system.sysObjectID */
747 static struct snmp_obj_id sysobjid = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID};
748 /** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */
749 static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}};
750 /** mib-2.system.sysServices */
751 static const s32_t sysservices = SNMP_SYSSERVICES;
753 /** mib-2.system.sysDescr */
754 static const u8_t sysdescr_len_default = 4;
755 static const u8_t sysdescr_default[] = "lwIP";
756 static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default;
757 static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0];
758 /** mib-2.system.sysContact */
759 static const u8_t syscontact_len_default = 0;
760 static const u8_t syscontact_default[] = "";
761 static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default;
762 static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0];
763 /** mib-2.system.sysName */
764 static const u8_t sysname_len_default = 8;
765 static const u8_t sysname_default[] = "FQDN-unk";
766 static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default;
767 static u8_t* sysname_ptr = (u8_t*)&sysname_default[0];
768 /** mib-2.system.sysLocation */
769 static const u8_t syslocation_len_default = 0;
770 static const u8_t syslocation_default[] = "";
771 static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default;
772 static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0];
773 /** mib-2.snmp.snmpEnableAuthenTraps */
774 static const u8_t snmpenableauthentraps_default = 2; /* disabled */
775 static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default;
777 /** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */
778 static const struct snmp_obj_id ifspecific = {2, {0, 0}};
779 /** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */
780 static const struct snmp_obj_id iprouteinfo = {2, {0, 0}};
784 /* mib-2.system counter(s) */
785 static u32_t sysuptime = 0;
787 /* mib-2.ip counter(s) */
788 static u32_t ipinreceives = 0,
789 ipinhdrerrors = 0,
790 ipinaddrerrors = 0,
791 ipforwdatagrams = 0,
792 ipinunknownprotos = 0,
793 ipindiscards = 0,
794 ipindelivers = 0,
795 ipoutrequests = 0,
796 ipoutdiscards = 0,
797 ipoutnoroutes = 0,
798 ipreasmreqds = 0,
799 ipreasmoks = 0,
800 ipreasmfails = 0,
801 ipfragoks = 0,
802 ipfragfails = 0,
803 ipfragcreates = 0,
804 iproutingdiscards = 0;
805 /* mib-2.icmp counter(s) */
806 static u32_t icmpinmsgs = 0,
807 icmpinerrors = 0,
808 icmpindestunreachs = 0,
809 icmpintimeexcds = 0,
810 icmpinparmprobs = 0,
811 icmpinsrcquenchs = 0,
812 icmpinredirects = 0,
813 icmpinechos = 0,
814 icmpinechoreps = 0,
815 icmpintimestamps = 0,
816 icmpintimestampreps = 0,
817 icmpinaddrmasks = 0,
818 icmpinaddrmaskreps = 0,
819 icmpoutmsgs = 0,
820 icmpouterrors = 0,
821 icmpoutdestunreachs = 0,
822 icmpouttimeexcds = 0,
823 icmpoutparmprobs = 0,
824 icmpoutsrcquenchs = 0,
825 icmpoutredirects = 0,
826 icmpoutechos = 0,
827 icmpoutechoreps = 0,
828 icmpouttimestamps = 0,
829 icmpouttimestampreps = 0,
830 icmpoutaddrmasks = 0,
831 icmpoutaddrmaskreps = 0;
832 /* mib-2.tcp counter(s) */
833 static u32_t tcpactiveopens = 0,
834 tcppassiveopens = 0,
835 tcpattemptfails = 0,
836 tcpestabresets = 0,
837 tcpinsegs = 0,
838 tcpoutsegs = 0,
839 tcpretranssegs = 0,
840 tcpinerrs = 0,
841 tcpoutrsts = 0;
842 /* mib-2.udp counter(s) */
843 static u32_t udpindatagrams = 0,
844 udpnoports = 0,
845 udpinerrors = 0,
846 udpoutdatagrams = 0;
847 /* mib-2.snmp counter(s) */
848 static u32_t snmpinpkts = 0,
849 snmpoutpkts = 0,
850 snmpinbadversions = 0,
851 snmpinbadcommunitynames = 0,
852 snmpinbadcommunityuses = 0,
853 snmpinasnparseerrs = 0,
854 snmpintoobigs = 0,
855 snmpinnosuchnames = 0,
856 snmpinbadvalues = 0,
857 snmpinreadonlys = 0,
858 snmpingenerrs = 0,
859 snmpintotalreqvars = 0,
860 snmpintotalsetvars = 0,
861 snmpingetrequests = 0,
862 snmpingetnexts = 0,
863 snmpinsetrequests = 0,
864 snmpingetresponses = 0,
865 snmpintraps = 0,
866 snmpouttoobigs = 0,
867 snmpoutnosuchnames = 0,
868 snmpoutbadvalues = 0,
869 snmpoutgenerrs = 0,
870 snmpoutgetrequests = 0,
871 snmpoutgetnexts = 0,
872 snmpoutsetrequests = 0,
873 snmpoutgetresponses = 0,
874 snmpouttraps = 0;
878 /* prototypes of the following functions are in lwip/src/include/lwip/snmp.h */
880 * Copy octet string.
882 * @param dst points to destination
883 * @param src points to source
884 * @param n number of octets to copy.
886 void ocstrncpy(u8_t *dst, u8_t *src, u8_t n)
888 while (n > 0)
890 n--;
891 *dst++ = *src++;
896 * Copy object identifier (s32_t) array.
898 * @param dst points to destination
899 * @param src points to source
900 * @param n number of sub identifiers to copy.
902 void objectidncpy(s32_t *dst, s32_t *src, u8_t n)
904 while(n > 0)
906 n--;
907 *dst++ = *src++;
912 * Initializes sysDescr pointers.
914 * @param str if non-NULL then copy str pointer
915 * @param strlen points to string length, excluding zero terminator
917 void snmp_set_sysdesr(u8_t *str, u8_t *strlen)
919 if (str != NULL)
921 sysdescr_ptr = str;
922 sysdescr_len_ptr = strlen;
926 void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid)
928 *oid = &sysobjid;
932 * Initializes sysObjectID value.
934 * @param oid points to stuct snmp_obj_id to copy
936 void snmp_set_sysobjid(struct snmp_obj_id *oid)
938 sysobjid = *oid;
942 * Must be called at regular 10 msec interval from a timer interrupt
943 * or signal handler depending on your runtime environment.
945 void snmp_inc_sysuptime(void)
947 sysuptime++;
950 void snmp_get_sysuptime(u32_t *value)
952 *value = sysuptime;
956 * Initializes sysContact pointers,
957 * e.g. ptrs to non-volatile memory external to lwIP.
959 * @param str if non-NULL then copy str pointer
960 * @param strlen points to string length, excluding zero terminator
962 void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen)
964 if (ocstr != NULL)
966 syscontact_ptr = ocstr;
967 syscontact_len_ptr = ocstrlen;
972 * Initializes sysName pointers,
973 * e.g. ptrs to non-volatile memory external to lwIP.
975 * @param str if non-NULL then copy str pointer
976 * @param strlen points to string length, excluding zero terminator
978 void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen)
980 if (ocstr != NULL)
982 sysname_ptr = ocstr;
983 sysname_len_ptr = ocstrlen;
988 * Initializes sysLocation pointers,
989 * e.g. ptrs to non-volatile memory external to lwIP.
991 * @param str if non-NULL then copy str pointer
992 * @param strlen points to string length, excluding zero terminator
994 void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen)
996 if (ocstr != NULL)
998 syslocation_ptr = ocstr;
999 syslocation_len_ptr = ocstrlen;
1004 void snmp_add_ifinoctets(struct netif *ni, u32_t value)
1006 ni->ifinoctets += value;
1009 void snmp_inc_ifinucastpkts(struct netif *ni)
1011 (ni->ifinucastpkts)++;
1014 void snmp_inc_ifinnucastpkts(struct netif *ni)
1016 (ni->ifinnucastpkts)++;
1019 void snmp_inc_ifindiscards(struct netif *ni)
1021 (ni->ifindiscards)++;
1024 void snmp_add_ifoutoctets(struct netif *ni, u32_t value)
1026 ni->ifoutoctets += value;
1029 void snmp_inc_ifoutucastpkts(struct netif *ni)
1031 (ni->ifoutucastpkts)++;
1034 void snmp_inc_ifoutnucastpkts(struct netif *ni)
1036 (ni->ifoutnucastpkts)++;
1039 void snmp_inc_ifoutdiscards(struct netif *ni)
1041 (ni->ifoutdiscards)++;
1044 void snmp_inc_iflist(void)
1046 struct mib_list_node *if_node = NULL;
1048 snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node);
1049 /* enable getnext traversal on filled table */
1050 iftable.maxlength = 1;
1053 void snmp_dec_iflist(void)
1055 snmp_mib_node_delete(&iflist_root, iflist_root.tail);
1056 /* disable getnext traversal on empty table */
1057 if(iflist_root.count == 0) iftable.maxlength = 0;
1061 * Inserts ARP table indexes (.xIfIndex.xNetAddress)
1062 * into arp table index trees (both atTable and ipNetToMediaTable).
1064 void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip)
1066 struct mib_list_rootnode *at_rn;
1067 struct mib_list_node *at_node;
1068 struct ip_addr hip;
1069 s32_t arpidx[5];
1070 u8_t level, tree;
1072 LWIP_ASSERT("ni != NULL", ni != NULL);
1073 snmp_netiftoifindex(ni, &arpidx[0]);
1074 hip.addr = ntohl(ip->addr);
1075 snmp_iptooid(&hip, &arpidx[1]);
1077 for (tree = 0; tree < 2; tree++)
1079 if (tree == 0)
1081 at_rn = &arptree_root;
1083 else
1085 at_rn = &ipntomtree_root;
1087 for (level = 0; level < 5; level++)
1089 at_node = NULL;
1090 snmp_mib_node_insert(at_rn, arpidx[level], &at_node);
1091 if ((level != 4) && (at_node != NULL))
1093 if (at_node->nptr == NULL)
1095 at_rn = snmp_mib_lrn_alloc();
1096 at_node->nptr = (struct mib_node*)at_rn;
1097 if (at_rn != NULL)
1099 if (level == 3)
1101 if (tree == 0)
1103 at_rn->get_object_def = atentry_get_object_def;
1104 at_rn->get_value = atentry_get_value;
1106 else
1108 at_rn->get_object_def = ip_ntomentry_get_object_def;
1109 at_rn->get_value = ip_ntomentry_get_value;
1111 at_rn->set_test = noleafs_set_test;
1112 at_rn->set_value = noleafs_set_value;
1115 else
1117 /* at_rn == NULL, malloc failure */
1118 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full"));
1119 break;
1122 else
1124 at_rn = (struct mib_list_rootnode*)at_node->nptr;
1129 /* enable getnext traversal on filled tables */
1130 at.maxlength = 1;
1131 ipntomtable.maxlength = 1;
1135 * Removes ARP table indexes (.xIfIndex.xNetAddress)
1136 * from arp table index trees.
1138 void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip)
1140 struct mib_list_rootnode *at_rn, *next, *del_rn[5];
1141 struct mib_list_node *at_n, *del_n[5];
1142 struct ip_addr hip;
1143 s32_t arpidx[5];
1144 u8_t fc, tree, level, del_cnt;
1146 snmp_netiftoifindex(ni, &arpidx[0]);
1147 hip.addr = ntohl(ip->addr);
1148 snmp_iptooid(&hip, &arpidx[1]);
1150 for (tree = 0; tree < 2; tree++)
1152 /* mark nodes for deletion */
1153 if (tree == 0)
1155 at_rn = &arptree_root;
1157 else
1159 at_rn = &ipntomtree_root;
1161 level = 0;
1162 del_cnt = 0;
1163 while ((level < 5) && (at_rn != NULL))
1165 fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n);
1166 if (fc == 0)
1168 /* arpidx[level] does not exist */
1169 del_cnt = 0;
1170 at_rn = NULL;
1172 else if (fc == 1)
1174 del_rn[del_cnt] = at_rn;
1175 del_n[del_cnt] = at_n;
1176 del_cnt++;
1177 at_rn = (struct mib_list_rootnode*)(at_n->nptr);
1179 else if (fc == 2)
1181 /* reset delete (2 or more childs) */
1182 del_cnt = 0;
1183 at_rn = (struct mib_list_rootnode*)(at_n->nptr);
1185 level++;
1187 /* delete marked index nodes */
1188 while (del_cnt > 0)
1190 del_cnt--;
1192 at_rn = del_rn[del_cnt];
1193 at_n = del_n[del_cnt];
1195 next = snmp_mib_node_delete(at_rn, at_n);
1196 if (next != NULL)
1198 LWIP_ASSERT("next_count == 0",next->count == 0);
1199 snmp_mib_lrn_free(next);
1203 /* disable getnext traversal on empty tables */
1204 if(arptree_root.count == 0) at.maxlength = 0;
1205 if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0;
1208 void snmp_inc_ipinreceives(void)
1210 ipinreceives++;
1213 void snmp_inc_ipinhdrerrors(void)
1215 ipinhdrerrors++;
1218 void snmp_inc_ipinaddrerrors(void)
1220 ipinaddrerrors++;
1223 void snmp_inc_ipforwdatagrams(void)
1225 ipforwdatagrams++;
1228 void snmp_inc_ipinunknownprotos(void)
1230 ipinunknownprotos++;
1233 void snmp_inc_ipindiscards(void)
1235 ipindiscards++;
1238 void snmp_inc_ipindelivers(void)
1240 ipindelivers++;
1243 void snmp_inc_ipoutrequests(void)
1245 ipoutrequests++;
1248 void snmp_inc_ipoutdiscards(void)
1250 ipoutdiscards++;
1253 void snmp_inc_ipoutnoroutes(void)
1255 ipoutnoroutes++;
1258 void snmp_inc_ipreasmreqds(void)
1260 ipreasmreqds++;
1263 void snmp_inc_ipreasmoks(void)
1265 ipreasmoks++;
1268 void snmp_inc_ipreasmfails(void)
1270 ipreasmfails++;
1273 void snmp_inc_ipfragoks(void)
1275 ipfragoks++;
1278 void snmp_inc_ipfragfails(void)
1280 ipfragfails++;
1283 void snmp_inc_ipfragcreates(void)
1285 ipfragcreates++;
1288 void snmp_inc_iproutingdiscards(void)
1290 iproutingdiscards++;
1294 * Inserts ipAddrTable indexes (.ipAdEntAddr)
1295 * into index tree.
1297 void snmp_insert_ipaddridx_tree(struct netif *ni)
1299 struct mib_list_rootnode *ipa_rn;
1300 struct mib_list_node *ipa_node;
1301 struct ip_addr ip;
1302 s32_t ipaddridx[4];
1303 u8_t level;
1305 LWIP_ASSERT("ni != NULL", ni != NULL);
1306 ip.addr = ntohl(ni->ip_addr.addr);
1307 snmp_iptooid(&ip, &ipaddridx[0]);
1309 level = 0;
1310 ipa_rn = &ipaddrtree_root;
1311 while (level < 4)
1313 ipa_node = NULL;
1314 snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node);
1315 if ((level != 3) && (ipa_node != NULL))
1317 if (ipa_node->nptr == NULL)
1319 ipa_rn = snmp_mib_lrn_alloc();
1320 ipa_node->nptr = (struct mib_node*)ipa_rn;
1321 if (ipa_rn != NULL)
1323 if (level == 2)
1325 ipa_rn->get_object_def = ip_addrentry_get_object_def;
1326 ipa_rn->get_value = ip_addrentry_get_value;
1327 ipa_rn->set_test = noleafs_set_test;
1328 ipa_rn->set_value = noleafs_set_value;
1331 else
1333 /* ipa_rn == NULL, malloc failure */
1334 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full"));
1335 break;
1338 else
1340 ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr;
1343 level++;
1345 /* enable getnext traversal on filled table */
1346 ipaddrtable.maxlength = 1;
1350 * Removes ipAddrTable indexes (.ipAdEntAddr)
1351 * from index tree.
1353 void snmp_delete_ipaddridx_tree(struct netif *ni)
1355 struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];
1356 struct mib_list_node *ipa_n, *del_n[4];
1357 struct ip_addr ip;
1358 s32_t ipaddridx[4];
1359 u8_t fc, level, del_cnt;
1361 LWIP_ASSERT("ni != NULL", ni != NULL);
1362 ip.addr = ntohl(ni->ip_addr.addr);
1363 snmp_iptooid(&ip, &ipaddridx[0]);
1365 /* mark nodes for deletion */
1366 level = 0;
1367 del_cnt = 0;
1368 ipa_rn = &ipaddrtree_root;
1369 while ((level < 4) && (ipa_rn != NULL))
1371 fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n);
1372 if (fc == 0)
1374 /* ipaddridx[level] does not exist */
1375 del_cnt = 0;
1376 ipa_rn = NULL;
1378 else if (fc == 1)
1380 del_rn[del_cnt] = ipa_rn;
1381 del_n[del_cnt] = ipa_n;
1382 del_cnt++;
1383 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
1385 else if (fc == 2)
1387 /* reset delete (2 or more childs) */
1388 del_cnt = 0;
1389 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
1391 level++;
1393 /* delete marked index nodes */
1394 while (del_cnt > 0)
1396 del_cnt--;
1398 ipa_rn = del_rn[del_cnt];
1399 ipa_n = del_n[del_cnt];
1401 next = snmp_mib_node_delete(ipa_rn, ipa_n);
1402 if (next != NULL)
1404 LWIP_ASSERT("next_count == 0",next->count == 0);
1405 snmp_mib_lrn_free(next);
1408 /* disable getnext traversal on empty table */
1409 if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0;
1413 * Inserts ipRouteTable indexes (.ipRouteDest)
1414 * into index tree.
1416 * @param dflt non-zero for the default rte, zero for network rte
1417 * @param netif points to network interface for this rte
1419 * @todo record sysuptime for _this_ route when it is installed
1420 * (needed for ipRouteAge) in the netif.
1422 void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
1424 u8_t insert = 0;
1425 struct ip_addr dst;
1427 if (dflt != 0)
1429 /* the default route 0.0.0.0 */
1430 dst.addr = 0;
1431 insert = 1;
1433 else
1435 /* route to the network address */
1436 dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
1437 /* exclude 0.0.0.0 network (reserved for default rte) */
1438 if (dst.addr != 0) insert = 1;
1440 if (insert)
1442 struct mib_list_rootnode *iprte_rn;
1443 struct mib_list_node *iprte_node;
1444 s32_t iprteidx[4];
1445 u8_t level;
1447 snmp_iptooid(&dst, &iprteidx[0]);
1448 level = 0;
1449 iprte_rn = &iprtetree_root;
1450 while (level < 4)
1452 iprte_node = NULL;
1453 snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node);
1454 if ((level != 3) && (iprte_node != NULL))
1456 if (iprte_node->nptr == NULL)
1458 iprte_rn = snmp_mib_lrn_alloc();
1459 iprte_node->nptr = (struct mib_node*)iprte_rn;
1460 if (iprte_rn != NULL)
1462 if (level == 2)
1464 iprte_rn->get_object_def = ip_rteentry_get_object_def;
1465 iprte_rn->get_value = ip_rteentry_get_value;
1466 iprte_rn->set_test = noleafs_set_test;
1467 iprte_rn->set_value = noleafs_set_value;
1470 else
1472 /* iprte_rn == NULL, malloc failure */
1473 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full"));
1474 break;
1477 else
1479 iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr;
1482 level++;
1485 /* enable getnext traversal on filled table */
1486 iprtetable.maxlength = 1;
1490 * Removes ipRouteTable indexes (.ipRouteDest)
1491 * from index tree.
1493 * @param dflt non-zero for the default rte, zero for network rte
1494 * @param netif points to network interface for this rte or NULL
1495 * for default route to be removed.
1497 void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
1499 u8_t delete = 0;
1500 struct ip_addr dst;
1502 if (dflt != 0)
1504 /* the default route 0.0.0.0 */
1505 dst.addr = 0;
1506 delete = 1;
1508 else
1510 /* route to the network address */
1511 dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
1512 /* exclude 0.0.0.0 network (reserved for default rte) */
1513 if (dst.addr != 0) delete = 1;
1515 if (delete)
1517 struct mib_list_rootnode *iprte_rn, *next, *del_rn[4];
1518 struct mib_list_node *iprte_n, *del_n[4];
1519 s32_t iprteidx[4];
1520 u8_t fc, level, del_cnt;
1522 snmp_iptooid(&dst, &iprteidx[0]);
1523 /* mark nodes for deletion */
1524 level = 0;
1525 del_cnt = 0;
1526 iprte_rn = &iprtetree_root;
1527 while ((level < 4) && (iprte_rn != NULL))
1529 fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n);
1530 if (fc == 0)
1532 /* iprteidx[level] does not exist */
1533 del_cnt = 0;
1534 iprte_rn = NULL;
1536 else if (fc == 1)
1538 del_rn[del_cnt] = iprte_rn;
1539 del_n[del_cnt] = iprte_n;
1540 del_cnt++;
1541 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
1543 else if (fc == 2)
1545 /* reset delete (2 or more childs) */
1546 del_cnt = 0;
1547 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
1549 level++;
1551 /* delete marked index nodes */
1552 while (del_cnt > 0)
1554 del_cnt--;
1556 iprte_rn = del_rn[del_cnt];
1557 iprte_n = del_n[del_cnt];
1559 next = snmp_mib_node_delete(iprte_rn, iprte_n);
1560 if (next != NULL)
1562 LWIP_ASSERT("next_count == 0",next->count == 0);
1563 snmp_mib_lrn_free(next);
1567 /* disable getnext traversal on empty table */
1568 if (iprtetree_root.count == 0) iprtetable.maxlength = 0;
1572 void snmp_inc_icmpinmsgs(void)
1574 icmpinmsgs++;
1577 void snmp_inc_icmpinerrors(void)
1579 icmpinerrors++;
1582 void snmp_inc_icmpindestunreachs(void)
1584 icmpindestunreachs++;
1587 void snmp_inc_icmpintimeexcds(void)
1589 icmpintimeexcds++;
1592 void snmp_inc_icmpinparmprobs(void)
1594 icmpinparmprobs++;
1597 void snmp_inc_icmpinsrcquenchs(void)
1599 icmpinsrcquenchs++;
1602 void snmp_inc_icmpinredirects(void)
1604 icmpinredirects++;
1607 void snmp_inc_icmpinechos(void)
1609 icmpinechos++;
1612 void snmp_inc_icmpinechoreps(void)
1614 icmpinechoreps++;
1617 void snmp_inc_icmpintimestamps(void)
1619 icmpintimestamps++;
1622 void snmp_inc_icmpintimestampreps(void)
1624 icmpintimestampreps++;
1627 void snmp_inc_icmpinaddrmasks(void)
1629 icmpinaddrmasks++;
1632 void snmp_inc_icmpinaddrmaskreps(void)
1634 icmpinaddrmaskreps++;
1637 void snmp_inc_icmpoutmsgs(void)
1639 icmpoutmsgs++;
1642 void snmp_inc_icmpouterrors(void)
1644 icmpouterrors++;
1647 void snmp_inc_icmpoutdestunreachs(void)
1649 icmpoutdestunreachs++;
1652 void snmp_inc_icmpouttimeexcds(void)
1654 icmpouttimeexcds++;
1657 void snmp_inc_icmpoutparmprobs(void)
1659 icmpoutparmprobs++;
1662 void snmp_inc_icmpoutsrcquenchs(void)
1664 icmpoutsrcquenchs++;
1667 void snmp_inc_icmpoutredirects(void)
1669 icmpoutredirects++;
1672 void snmp_inc_icmpoutechos(void)
1674 icmpoutechos++;
1677 void snmp_inc_icmpoutechoreps(void)
1679 icmpoutechoreps++;
1682 void snmp_inc_icmpouttimestamps(void)
1684 icmpouttimestamps++;
1687 void snmp_inc_icmpouttimestampreps(void)
1689 icmpouttimestampreps++;
1692 void snmp_inc_icmpoutaddrmasks(void)
1694 icmpoutaddrmasks++;
1697 void snmp_inc_icmpoutaddrmaskreps(void)
1699 icmpoutaddrmaskreps++;
1702 void snmp_inc_tcpactiveopens(void)
1704 tcpactiveopens++;
1707 void snmp_inc_tcppassiveopens(void)
1709 tcppassiveopens++;
1712 void snmp_inc_tcpattemptfails(void)
1714 tcpattemptfails++;
1717 void snmp_inc_tcpestabresets(void)
1719 tcpestabresets++;
1722 void snmp_inc_tcpinsegs(void)
1724 tcpinsegs++;
1727 void snmp_inc_tcpoutsegs(void)
1729 tcpoutsegs++;
1732 void snmp_inc_tcpretranssegs(void)
1734 tcpretranssegs++;
1737 void snmp_inc_tcpinerrs(void)
1739 tcpinerrs++;
1742 void snmp_inc_tcpoutrsts(void)
1744 tcpoutrsts++;
1747 void snmp_inc_udpindatagrams(void)
1749 udpindatagrams++;
1752 void snmp_inc_udpnoports(void)
1754 udpnoports++;
1757 void snmp_inc_udpinerrors(void)
1759 udpinerrors++;
1762 void snmp_inc_udpoutdatagrams(void)
1764 udpoutdatagrams++;
1768 * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort)
1769 * into index tree.
1771 void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
1773 struct mib_list_rootnode *udp_rn;
1774 struct mib_list_node *udp_node;
1775 struct ip_addr ip;
1776 s32_t udpidx[5];
1777 u8_t level;
1779 LWIP_ASSERT("pcb != NULL", pcb != NULL);
1780 ip.addr = ntohl(pcb->local_ip.addr);
1781 snmp_iptooid(&ip, &udpidx[0]);
1782 udpidx[4] = pcb->local_port;
1784 udp_rn = &udp_root;
1785 for (level = 0; level < 5; level++)
1787 udp_node = NULL;
1788 snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node);
1789 if ((level != 4) && (udp_node != NULL))
1791 if (udp_node->nptr == NULL)
1793 udp_rn = snmp_mib_lrn_alloc();
1794 udp_node->nptr = (struct mib_node*)udp_rn;
1795 if (udp_rn != NULL)
1797 if (level == 3)
1799 udp_rn->get_object_def = udpentry_get_object_def;
1800 udp_rn->get_value = udpentry_get_value;
1801 udp_rn->set_test = noleafs_set_test;
1802 udp_rn->set_value = noleafs_set_value;
1805 else
1807 /* udp_rn == NULL, malloc failure */
1808 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full"));
1809 break;
1812 else
1814 udp_rn = (struct mib_list_rootnode*)udp_node->nptr;
1818 udptable.maxlength = 1;
1822 * Removes udpTable indexes (.udpLocalAddress.udpLocalPort)
1823 * from index tree.
1825 void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
1827 struct mib_list_rootnode *udp_rn, *next, *del_rn[5];
1828 struct mib_list_node *udp_n, *del_n[5];
1829 struct ip_addr ip;
1830 s32_t udpidx[5];
1831 u8_t bindings, fc, level, del_cnt;
1833 LWIP_ASSERT("pcb != NULL", pcb != NULL);
1834 ip.addr = ntohl(pcb->local_ip.addr);
1835 snmp_iptooid(&ip, &udpidx[0]);
1836 udpidx[4] = pcb->local_port;
1838 /* count PCBs for a given binding
1839 (e.g. when reusing ports or for temp output PCBs) */
1840 bindings = 0;
1841 pcb = udp_pcbs;
1842 while ((pcb != NULL))
1844 if ((pcb->local_ip.addr == ip.addr) &&
1845 (pcb->local_port == udpidx[4]))
1847 bindings++;
1849 pcb = pcb->next;
1851 if (bindings == 1)
1853 /* selectively remove */
1854 /* mark nodes for deletion */
1855 level = 0;
1856 del_cnt = 0;
1857 udp_rn = &udp_root;
1858 while ((level < 5) && (udp_rn != NULL))
1860 fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n);
1861 if (fc == 0)
1863 /* udpidx[level] does not exist */
1864 del_cnt = 0;
1865 udp_rn = NULL;
1867 else if (fc == 1)
1869 del_rn[del_cnt] = udp_rn;
1870 del_n[del_cnt] = udp_n;
1871 del_cnt++;
1872 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
1874 else if (fc == 2)
1876 /* reset delete (2 or more childs) */
1877 del_cnt = 0;
1878 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
1880 level++;
1882 /* delete marked index nodes */
1883 while (del_cnt > 0)
1885 del_cnt--;
1887 udp_rn = del_rn[del_cnt];
1888 udp_n = del_n[del_cnt];
1890 next = snmp_mib_node_delete(udp_rn, udp_n);
1891 if (next != NULL)
1893 LWIP_ASSERT("next_count == 0",next->count == 0);
1894 snmp_mib_lrn_free(next);
1898 /* disable getnext traversal on empty table */
1899 if (udp_root.count == 0) udptable.maxlength = 0;
1903 void snmp_inc_snmpinpkts(void)
1905 snmpinpkts++;
1908 void snmp_inc_snmpoutpkts(void)
1910 snmpoutpkts++;
1913 void snmp_inc_snmpinbadversions(void)
1915 snmpinbadversions++;
1918 void snmp_inc_snmpinbadcommunitynames(void)
1920 snmpinbadcommunitynames++;
1923 void snmp_inc_snmpinbadcommunityuses(void)
1925 snmpinbadcommunityuses++;
1928 void snmp_inc_snmpinasnparseerrs(void)
1930 snmpinasnparseerrs++;
1933 void snmp_inc_snmpintoobigs(void)
1935 snmpintoobigs++;
1938 void snmp_inc_snmpinnosuchnames(void)
1940 snmpinnosuchnames++;
1943 void snmp_inc_snmpinbadvalues(void)
1945 snmpinbadvalues++;
1948 void snmp_inc_snmpinreadonlys(void)
1950 snmpinreadonlys++;
1953 void snmp_inc_snmpingenerrs(void)
1955 snmpingenerrs++;
1958 void snmp_add_snmpintotalreqvars(u8_t value)
1960 snmpintotalreqvars += value;
1963 void snmp_add_snmpintotalsetvars(u8_t value)
1965 snmpintotalsetvars += value;
1968 void snmp_inc_snmpingetrequests(void)
1970 snmpingetrequests++;
1973 void snmp_inc_snmpingetnexts(void)
1975 snmpingetnexts++;
1978 void snmp_inc_snmpinsetrequests(void)
1980 snmpinsetrequests++;
1983 void snmp_inc_snmpingetresponses(void)
1985 snmpingetresponses++;
1988 void snmp_inc_snmpintraps(void)
1990 snmpintraps++;
1993 void snmp_inc_snmpouttoobigs(void)
1995 snmpouttoobigs++;
1998 void snmp_inc_snmpoutnosuchnames(void)
2000 snmpoutnosuchnames++;
2003 void snmp_inc_snmpoutbadvalues(void)
2005 snmpoutbadvalues++;
2008 void snmp_inc_snmpoutgenerrs(void)
2010 snmpoutgenerrs++;
2013 void snmp_inc_snmpoutgetrequests(void)
2015 snmpoutgetrequests++;
2018 void snmp_inc_snmpoutgetnexts(void)
2020 snmpoutgetnexts++;
2023 void snmp_inc_snmpoutsetrequests(void)
2025 snmpoutsetrequests++;
2028 void snmp_inc_snmpoutgetresponses(void)
2030 snmpoutgetresponses++;
2033 void snmp_inc_snmpouttraps(void)
2035 snmpouttraps++;
2038 void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)
2040 *oid = &snmpgrp_id;
2043 void snmp_set_snmpenableauthentraps(u8_t *value)
2045 if (value != NULL)
2047 snmpenableauthentraps_ptr = value;
2051 void snmp_get_snmpenableauthentraps(u8_t *value)
2053 *value = *snmpenableauthentraps_ptr;
2056 void
2057 noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2059 if (ident_len){}
2060 if (ident){}
2061 od->instance = MIB_OBJECT_NONE;
2064 void
2065 noleafs_get_value(struct obj_def *od, u16_t len, void *value)
2067 if (od){}
2068 if (len){}
2069 if (value){}
2072 u8_t
2073 noleafs_set_test(struct obj_def *od, u16_t len, void *value)
2075 if (od){}
2076 if (len){}
2077 if (value){}
2078 /* can't set */
2079 return 0;
2082 void
2083 noleafs_set_value(struct obj_def *od, u16_t len, void *value)
2085 if (od){}
2086 if (len){}
2087 if (value){}
2092 * Returns systems object definitions.
2094 * @param ident_len the address length (2)
2095 * @param ident points to objectname.0 (object id trailer)
2096 * @param od points to object definition.
2098 static void
2099 system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2101 u8_t id;
2103 /* return to object name, adding index depth (1) */
2104 ident_len += 1;
2105 ident -= 1;
2106 if (ident_len == 2)
2108 od->id_inst_len = ident_len;
2109 od->id_inst_ptr = ident;
2111 id = ident[0];
2112 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id));
2113 switch (id)
2115 case 1: /* sysDescr */
2116 od->instance = MIB_OBJECT_SCALAR;
2117 od->access = MIB_OBJECT_READ_ONLY;
2118 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2119 od->v_len = *sysdescr_len_ptr;
2120 break;
2121 case 2: /* sysObjectID */
2122 od->instance = MIB_OBJECT_SCALAR;
2123 od->access = MIB_OBJECT_READ_ONLY;
2124 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
2125 od->v_len = sysobjid.len * sizeof(s32_t);
2126 break;
2127 case 3: /* sysUpTime */
2128 od->instance = MIB_OBJECT_SCALAR;
2129 od->access = MIB_OBJECT_READ_ONLY;
2130 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
2131 od->v_len = sizeof(u32_t);
2132 break;
2133 case 4: /* sysContact */
2134 od->instance = MIB_OBJECT_SCALAR;
2135 od->access = MIB_OBJECT_READ_WRITE;
2136 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2137 od->v_len = *syscontact_len_ptr;
2138 break;
2139 case 5: /* sysName */
2140 od->instance = MIB_OBJECT_SCALAR;
2141 od->access = MIB_OBJECT_READ_WRITE;
2142 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2143 od->v_len = *sysname_len_ptr;
2144 break;
2145 case 6: /* sysLocation */
2146 od->instance = MIB_OBJECT_SCALAR;
2147 od->access = MIB_OBJECT_READ_WRITE;
2148 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2149 od->v_len = *syslocation_len_ptr;
2150 break;
2151 case 7: /* sysServices */
2152 od->instance = MIB_OBJECT_SCALAR;
2153 od->access = MIB_OBJECT_READ_ONLY;
2154 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2155 od->v_len = sizeof(s32_t);
2156 break;
2157 default:
2158 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n"));
2159 od->instance = MIB_OBJECT_NONE;
2160 break;
2163 else
2165 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n"));
2166 od->instance = MIB_OBJECT_NONE;
2171 * Returns system object value.
2173 * @param ident_len the address length (2)
2174 * @param ident points to objectname.0 (object id trailer)
2175 * @param len return value space (in bytes)
2176 * @param value points to (varbind) space to copy value into.
2178 static void
2179 system_get_value(struct obj_def *od, u16_t len, void *value)
2181 u8_t id;
2183 id = od->id_inst_ptr[0];
2184 switch (id)
2186 case 1: /* sysDescr */
2187 ocstrncpy(value,sysdescr_ptr,len);
2188 break;
2189 case 2: /* sysObjectID */
2190 objectidncpy((s32_t*)value,(s32_t*)sysobjid.id,len / sizeof(s32_t));
2191 break;
2192 case 3: /* sysUpTime */
2194 u32_t *uint_ptr = value;
2195 *uint_ptr = sysuptime;
2197 break;
2198 case 4: /* sysContact */
2199 ocstrncpy(value,syscontact_ptr,len);
2200 break;
2201 case 5: /* sysName */
2202 ocstrncpy(value,sysname_ptr,len);
2203 break;
2204 case 6: /* sysLocation */
2205 ocstrncpy(value,syslocation_ptr,len);
2206 break;
2207 case 7: /* sysServices */
2209 s32_t *sint_ptr = value;
2210 *sint_ptr = sysservices;
2212 break;
2216 static u8_t
2217 system_set_test(struct obj_def *od, u16_t len, void *value)
2219 u8_t id, set_ok;
2221 if (value) {}
2222 set_ok = 0;
2223 id = od->id_inst_ptr[0];
2224 switch (id)
2226 case 4: /* sysContact */
2227 if ((syscontact_ptr != syscontact_default) &&
2228 (len <= 255))
2230 set_ok = 1;
2232 break;
2233 case 5: /* sysName */
2234 if ((sysname_ptr != sysname_default) &&
2235 (len <= 255))
2237 set_ok = 1;
2239 break;
2240 case 6: /* sysLocation */
2241 if ((syslocation_ptr != syslocation_default) &&
2242 (len <= 255))
2244 set_ok = 1;
2246 break;
2248 return set_ok;
2251 static void
2252 system_set_value(struct obj_def *od, u16_t len, void *value)
2254 u8_t id;
2256 id = od->id_inst_ptr[0];
2257 switch (id)
2259 case 4: /* sysContact */
2260 ocstrncpy(syscontact_ptr,value,len);
2261 *syscontact_len_ptr = len;
2262 break;
2263 case 5: /* sysName */
2264 ocstrncpy(sysname_ptr,value,len);
2265 *sysname_len_ptr = len;
2266 break;
2267 case 6: /* sysLocation */
2268 ocstrncpy(syslocation_ptr,value,len);
2269 *syslocation_len_ptr = len;
2270 break;
2275 * Returns interfaces.ifnumber object definition.
2277 * @param ident_len the address length (2)
2278 * @param ident points to objectname.index
2279 * @param od points to object definition.
2281 static void
2282 interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2284 /* return to object name, adding index depth (1) */
2285 ident_len += 1;
2286 ident -= 1;
2287 if (ident_len == 2)
2289 od->id_inst_len = ident_len;
2290 od->id_inst_ptr = ident;
2292 od->instance = MIB_OBJECT_SCALAR;
2293 od->access = MIB_OBJECT_READ_ONLY;
2294 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2295 od->v_len = sizeof(s32_t);
2297 else
2299 LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n"));
2300 od->instance = MIB_OBJECT_NONE;
2305 * Returns interfaces.ifnumber object value.
2307 * @param ident_len the address length (2)
2308 * @param ident points to objectname.0 (object id trailer)
2309 * @param len return value space (in bytes)
2310 * @param value points to (varbind) space to copy value into.
2312 static void
2313 interfaces_get_value(struct obj_def *od, u16_t len, void *value)
2315 if (len){}
2316 if (od->id_inst_ptr[0] == 1)
2318 s32_t *sint_ptr = value;
2319 *sint_ptr = iflist_root.count;
2324 * Returns ifentry object definitions.
2326 * @param ident_len the address length (2)
2327 * @param ident points to objectname.index
2328 * @param od points to object definition.
2330 static void
2331 ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2333 u8_t id;
2335 /* return to object name, adding index depth (1) */
2336 ident_len += 1;
2337 ident -= 1;
2338 if (ident_len == 2)
2340 od->id_inst_len = ident_len;
2341 od->id_inst_ptr = ident;
2343 id = ident[0];
2344 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id));
2345 switch (id)
2347 case 1: /* ifIndex */
2348 case 3: /* ifType */
2349 case 4: /* ifMtu */
2350 case 8: /* ifOperStatus */
2351 od->instance = MIB_OBJECT_TAB;
2352 od->access = MIB_OBJECT_READ_ONLY;
2353 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2354 od->v_len = sizeof(s32_t);
2355 break;
2356 case 2: /* ifDescr */
2357 od->instance = MIB_OBJECT_TAB;
2358 od->access = MIB_OBJECT_READ_ONLY;
2359 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2360 /** @todo this should be some sort of sizeof(struct netif.name) */
2361 od->v_len = 2;
2362 break;
2363 case 5: /* ifSpeed */
2364 case 21: /* ifOutQLen */
2365 od->instance = MIB_OBJECT_TAB;
2366 od->access = MIB_OBJECT_READ_ONLY;
2367 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
2368 od->v_len = sizeof(u32_t);
2369 break;
2370 case 6: /* ifPhysAddress */
2372 struct netif *netif;
2374 snmp_ifindextonetif(ident[1], &netif);
2375 od->instance = MIB_OBJECT_TAB;
2376 od->access = MIB_OBJECT_READ_ONLY;
2377 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2378 od->v_len = netif->hwaddr_len;
2380 break;
2381 case 7: /* ifAdminStatus */
2382 od->instance = MIB_OBJECT_TAB;
2383 od->access = MIB_OBJECT_READ_WRITE;
2384 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2385 od->v_len = sizeof(s32_t);
2386 break;
2387 case 9: /* ifLastChange */
2388 od->instance = MIB_OBJECT_TAB;
2389 od->access = MIB_OBJECT_READ_ONLY;
2390 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
2391 od->v_len = sizeof(u32_t);
2392 break;
2393 case 10: /* ifInOctets */
2394 case 11: /* ifInUcastPkts */
2395 case 12: /* ifInNUcastPkts */
2396 case 13: /* ifInDiscarts */
2397 case 14: /* ifInErrors */
2398 case 15: /* ifInUnkownProtos */
2399 case 16: /* ifOutOctets */
2400 case 17: /* ifOutUcastPkts */
2401 case 18: /* ifOutNUcastPkts */
2402 case 19: /* ifOutDiscarts */
2403 case 20: /* ifOutErrors */
2404 od->instance = MIB_OBJECT_TAB;
2405 od->access = MIB_OBJECT_READ_ONLY;
2406 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
2407 od->v_len = sizeof(u32_t);
2408 break;
2409 case 22: /* ifSpecific */
2410 /** @note returning zeroDotZero (0.0) no media specific MIB support */
2411 od->instance = MIB_OBJECT_TAB;
2412 od->access = MIB_OBJECT_READ_ONLY;
2413 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
2414 od->v_len = ifspecific.len * sizeof(s32_t);
2415 break;
2416 default:
2417 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n"));
2418 od->instance = MIB_OBJECT_NONE;
2419 break;
2422 else
2424 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n"));
2425 od->instance = MIB_OBJECT_NONE;
2430 * Returns ifentry object value.
2432 * @param ident_len the address length (2)
2433 * @param ident points to objectname.0 (object id trailer)
2434 * @param len return value space (in bytes)
2435 * @param value points to (varbind) space to copy value into.
2437 static void
2438 ifentry_get_value(struct obj_def *od, u16_t len, void *value)
2440 struct netif *netif;
2441 u8_t id;
2443 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2444 id = od->id_inst_ptr[0];
2445 switch (id)
2447 case 1: /* ifIndex */
2449 s32_t *sint_ptr = value;
2450 *sint_ptr = od->id_inst_ptr[1];
2452 break;
2453 case 2: /* ifDescr */
2454 ocstrncpy(value,(u8_t*)netif->name,len);
2455 break;
2456 case 3: /* ifType */
2458 s32_t *sint_ptr = value;
2459 *sint_ptr = netif->link_type;
2461 break;
2462 case 4: /* ifMtu */
2464 s32_t *sint_ptr = value;
2465 *sint_ptr = netif->mtu;
2467 break;
2468 case 5: /* ifSpeed */
2470 u32_t *uint_ptr = value;
2471 *uint_ptr = netif->link_speed;
2473 break;
2474 case 6: /* ifPhysAddress */
2475 ocstrncpy(value,netif->hwaddr,len);
2476 break;
2477 case 7: /* ifAdminStatus */
2478 case 8: /* ifOperStatus */
2480 s32_t *sint_ptr = value;
2481 if (netif_is_up(netif))
2483 *sint_ptr = 1;
2485 else
2487 *sint_ptr = 2;
2490 break;
2491 case 9: /* ifLastChange */
2493 u32_t *uint_ptr = value;
2494 *uint_ptr = netif->ts;
2496 break;
2497 case 10: /* ifInOctets */
2499 u32_t *uint_ptr = value;
2500 *uint_ptr = netif->ifinoctets;
2502 break;
2503 case 11: /* ifInUcastPkts */
2505 u32_t *uint_ptr = value;
2506 *uint_ptr = netif->ifinucastpkts;
2508 break;
2509 case 12: /* ifInNUcastPkts */
2511 u32_t *uint_ptr = value;
2512 *uint_ptr = netif->ifinnucastpkts;
2514 break;
2515 case 13: /* ifInDiscarts */
2517 u32_t *uint_ptr = value;
2518 *uint_ptr = netif->ifindiscards;
2520 break;
2521 case 14: /* ifInErrors */
2522 case 15: /* ifInUnkownProtos */
2523 /** @todo add these counters! */
2525 u32_t *uint_ptr = value;
2526 *uint_ptr = 0;
2528 break;
2529 case 16: /* ifOutOctets */
2531 u32_t *uint_ptr = value;
2532 *uint_ptr = netif->ifoutoctets;
2534 break;
2535 case 17: /* ifOutUcastPkts */
2537 u32_t *uint_ptr = value;
2538 *uint_ptr = netif->ifoutucastpkts;
2540 break;
2541 case 18: /* ifOutNUcastPkts */
2543 u32_t *uint_ptr = value;
2544 *uint_ptr = netif->ifoutnucastpkts;
2546 break;
2547 case 19: /* ifOutDiscarts */
2549 u32_t *uint_ptr = value;
2550 *uint_ptr = netif->ifoutdiscards;
2552 break;
2553 case 20: /* ifOutErrors */
2554 /** @todo add this counter! */
2556 u32_t *uint_ptr = value;
2557 *uint_ptr = 0;
2559 break;
2560 case 21: /* ifOutQLen */
2561 /** @todo figure out if this must be 0 (no queue) or 1? */
2563 u32_t *uint_ptr = value;
2564 *uint_ptr = 0;
2566 break;
2567 case 22: /* ifSpecific */
2568 objectidncpy((s32_t*)value,(s32_t*)ifspecific.id,len / sizeof(s32_t));
2569 break;
2574 * Returns atentry object definitions.
2576 * @param ident_len the address length (6)
2577 * @param ident points to objectname.atifindex.atnetaddress
2578 * @param od points to object definition.
2580 static void
2581 atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2583 /* return to object name, adding index depth (5) */
2584 ident_len += 5;
2585 ident -= 5;
2587 if (ident_len == 6)
2589 od->id_inst_len = ident_len;
2590 od->id_inst_ptr = ident;
2592 switch (ident[0])
2594 case 1: /* atIfIndex */
2595 od->instance = MIB_OBJECT_TAB;
2596 od->access = MIB_OBJECT_READ_WRITE;
2597 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2598 od->v_len = sizeof(s32_t);
2599 break;
2600 case 2: /* atPhysAddress */
2601 od->instance = MIB_OBJECT_TAB;
2602 od->access = MIB_OBJECT_READ_WRITE;
2603 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2604 od->v_len = sizeof(struct eth_addr);
2605 break;
2606 case 3: /* atNetAddress */
2607 od->instance = MIB_OBJECT_TAB;
2608 od->access = MIB_OBJECT_READ_WRITE;
2609 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
2610 od->v_len = 4;
2611 break;
2612 default:
2613 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n"));
2614 od->instance = MIB_OBJECT_NONE;
2615 break;
2618 else
2620 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n"));
2621 od->instance = MIB_OBJECT_NONE;
2625 static void
2626 atentry_get_value(struct obj_def *od, u16_t len, void *value)
2628 u8_t id;
2629 struct eth_addr* ethaddr_ret;
2630 struct ip_addr* ipaddr_ret;
2631 struct ip_addr ip;
2632 struct netif *netif;
2634 if (len) {}
2636 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2637 snmp_oidtoip(&od->id_inst_ptr[2], &ip);
2638 ip.addr = htonl(ip.addr);
2640 if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
2642 id = od->id_inst_ptr[0];
2643 switch (id)
2645 case 1: /* atIfIndex */
2647 s32_t *sint_ptr = value;
2648 *sint_ptr = od->id_inst_ptr[1];
2650 break;
2651 case 2: /* atPhysAddress */
2653 struct eth_addr *dst = value;
2655 *dst = *ethaddr_ret;
2657 break;
2658 case 3: /* atNetAddress */
2660 struct ip_addr *dst = value;
2662 *dst = *ipaddr_ret;
2664 break;
2669 static void
2670 ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2672 u8_t id;
2674 /* return to object name, adding index depth (1) */
2675 ident_len += 1;
2676 ident -= 1;
2677 if (ident_len == 2)
2679 od->id_inst_len = ident_len;
2680 od->id_inst_ptr = ident;
2682 id = ident[0];
2683 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id));
2684 switch (id)
2686 case 1: /* ipForwarding */
2687 case 2: /* ipDefaultTTL */
2688 od->instance = MIB_OBJECT_SCALAR;
2689 od->access = MIB_OBJECT_READ_WRITE;
2690 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2691 od->v_len = sizeof(s32_t);
2692 break;
2693 case 3: /* ipInReceives */
2694 case 4: /* ipInHdrErrors */
2695 case 5: /* ipInAddrErrors */
2696 case 6: /* ipForwDatagrams */
2697 case 7: /* ipInUnknownProtos */
2698 case 8: /* ipInDiscards */
2699 case 9: /* ipInDelivers */
2700 case 10: /* ipOutRequests */
2701 case 11: /* ipOutDiscards */
2702 case 12: /* ipOutNoRoutes */
2703 case 14: /* ipReasmReqds */
2704 case 15: /* ipReasmOKs */
2705 case 16: /* ipReasmFails */
2706 case 17: /* ipFragOKs */
2707 case 18: /* ipFragFails */
2708 case 19: /* ipFragCreates */
2709 case 23: /* ipRoutingDiscards */
2710 od->instance = MIB_OBJECT_SCALAR;
2711 od->access = MIB_OBJECT_READ_ONLY;
2712 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
2713 od->v_len = sizeof(u32_t);
2714 break;
2715 case 13: /* ipReasmTimeout */
2716 od->instance = MIB_OBJECT_SCALAR;
2717 od->access = MIB_OBJECT_READ_ONLY;
2718 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2719 od->v_len = sizeof(s32_t);
2720 break;
2721 default:
2722 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n"));
2723 od->instance = MIB_OBJECT_NONE;
2724 break;
2727 else
2729 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n"));
2730 od->instance = MIB_OBJECT_NONE;
2734 static void
2735 ip_get_value(struct obj_def *od, u16_t len, void *value)
2737 u8_t id;
2739 if (len) {}
2740 id = od->id_inst_ptr[0];
2741 switch (id)
2743 case 1: /* ipForwarding */
2745 s32_t *sint_ptr = value;
2746 #if IP_FORWARD
2747 /* forwarding */
2748 *sint_ptr = 1;
2749 #else
2750 /* not-forwarding */
2751 *sint_ptr = 2;
2752 #endif
2754 break;
2755 case 2: /* ipDefaultTTL */
2757 s32_t *sint_ptr = value;
2758 *sint_ptr = IP_DEFAULT_TTL;
2760 break;
2761 case 3: /* ipInReceives */
2763 u32_t *uint_ptr = value;
2764 *uint_ptr = ipinreceives;
2766 break;
2767 case 4: /* ipInHdrErrors */
2769 u32_t *uint_ptr = value;
2770 *uint_ptr = ipinhdrerrors;
2772 break;
2773 case 5: /* ipInAddrErrors */
2775 u32_t *uint_ptr = value;
2776 *uint_ptr = ipinaddrerrors;
2778 break;
2779 case 6: /* ipForwDatagrams */
2781 u32_t *uint_ptr = value;
2782 *uint_ptr = ipforwdatagrams;
2784 break;
2785 case 7: /* ipInUnknownProtos */
2787 u32_t *uint_ptr = value;
2788 *uint_ptr = ipinunknownprotos;
2790 break;
2791 case 8: /* ipInDiscards */
2793 u32_t *uint_ptr = value;
2794 *uint_ptr = ipindiscards;
2796 break;
2797 case 9: /* ipInDelivers */
2799 u32_t *uint_ptr = value;
2800 *uint_ptr = ipindelivers;
2802 break;
2803 case 10: /* ipOutRequests */
2805 u32_t *uint_ptr = value;
2806 *uint_ptr = ipoutrequests;
2808 break;
2809 case 11: /* ipOutDiscards */
2811 u32_t *uint_ptr = value;
2812 *uint_ptr = ipoutdiscards;
2814 break;
2815 case 12: /* ipOutNoRoutes */
2817 u32_t *uint_ptr = value;
2818 *uint_ptr = ipoutnoroutes;
2820 break;
2821 case 13: /* ipReasmTimeout */
2823 s32_t *sint_ptr = value;
2824 #if IP_REASSEMBLY
2825 *sint_ptr = IP_REASS_MAXAGE;
2826 #else
2827 *sint_ptr = 0;
2828 #endif
2830 break;
2831 case 14: /* ipReasmReqds */
2833 u32_t *uint_ptr = value;
2834 *uint_ptr = ipreasmreqds;
2836 break;
2837 case 15: /* ipReasmOKs */
2839 u32_t *uint_ptr = value;
2840 *uint_ptr = ipreasmoks;
2842 break;
2843 case 16: /* ipReasmFails */
2845 u32_t *uint_ptr = value;
2846 *uint_ptr = ipreasmfails;
2848 break;
2849 case 17: /* ipFragOKs */
2851 u32_t *uint_ptr = value;
2852 *uint_ptr = ipfragoks;
2854 break;
2855 case 18: /* ipFragFails */
2857 u32_t *uint_ptr = value;
2858 *uint_ptr = ipfragfails;
2860 break;
2861 case 19: /* ipFragCreates */
2863 u32_t *uint_ptr = value;
2864 *uint_ptr = ipfragcreates;
2866 break;
2867 case 23: /* ipRoutingDiscards */
2868 /** @todo can lwIP discard routes at all?? hardwire this to 0?? */
2870 u32_t *uint_ptr = value;
2871 *uint_ptr = iproutingdiscards;
2873 break;
2878 * Test ip object value before setting.
2880 * @param od is the object definition
2881 * @param len return value space (in bytes)
2882 * @param value points to (varbind) space to copy value from.
2884 * @note we allow set if the value matches the hardwired value,
2885 * otherwise return badvalue.
2887 static u8_t
2888 ip_set_test(struct obj_def *od, u16_t len, void *value)
2890 u8_t id, set_ok;
2891 s32_t *sint_ptr = value;
2893 if (len) {}
2894 set_ok = 0;
2895 id = od->id_inst_ptr[0];
2896 switch (id)
2898 case 1: /* ipForwarding */
2899 #if IP_FORWARD
2900 /* forwarding */
2901 if (*sint_ptr == 1)
2902 #else
2903 /* not-forwarding */
2904 if (*sint_ptr == 2)
2905 #endif
2907 set_ok = 1;
2909 break;
2910 case 2: /* ipDefaultTTL */
2911 if (*sint_ptr == IP_DEFAULT_TTL)
2913 set_ok = 1;
2915 break;
2917 return set_ok;
2920 static void
2921 ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2923 /* return to object name, adding index depth (4) */
2924 ident_len += 4;
2925 ident -= 4;
2927 if (ident_len == 5)
2929 u8_t id;
2931 od->id_inst_len = ident_len;
2932 od->id_inst_ptr = ident;
2934 id = ident[0];
2935 switch (id)
2937 case 1: /* ipAdEntAddr */
2938 case 3: /* ipAdEntNetMask */
2939 od->instance = MIB_OBJECT_TAB;
2940 od->access = MIB_OBJECT_READ_ONLY;
2941 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
2942 od->v_len = 4;
2943 break;
2944 case 2: /* ipAdEntIfIndex */
2945 case 4: /* ipAdEntBcastAddr */
2946 case 5: /* ipAdEntReasmMaxSize */
2947 od->instance = MIB_OBJECT_TAB;
2948 od->access = MIB_OBJECT_READ_ONLY;
2949 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2950 od->v_len = sizeof(s32_t);
2951 break;
2952 default:
2953 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n"));
2954 od->instance = MIB_OBJECT_NONE;
2955 break;
2958 else
2960 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n"));
2961 od->instance = MIB_OBJECT_NONE;
2965 static void
2966 ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
2968 u8_t id;
2969 u16_t ifidx;
2970 struct ip_addr ip;
2971 struct netif *netif = netif_list;
2973 if (len) {}
2974 snmp_oidtoip(&od->id_inst_ptr[1], &ip);
2975 ip.addr = htonl(ip.addr);
2976 ifidx = 0;
2977 while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
2979 netif = netif->next;
2980 ifidx++;
2983 if (netif != NULL)
2985 id = od->id_inst_ptr[0];
2986 switch (id)
2988 case 1: /* ipAdEntAddr */
2990 struct ip_addr *dst = value;
2991 *dst = netif->ip_addr;
2993 break;
2994 case 2: /* ipAdEntIfIndex */
2996 s32_t *sint_ptr = value;
2997 *sint_ptr = ifidx + 1;
2999 break;
3000 case 3: /* ipAdEntNetMask */
3002 struct ip_addr *dst = value;
3003 *dst = netif->netmask;
3005 break;
3006 case 4: /* ipAdEntBcastAddr */
3008 s32_t *sint_ptr = value;
3010 /* lwIP oddity, there's no broadcast
3011 address in the netif we can rely on */
3012 *sint_ptr = ip_addr_broadcast.addr & 1;
3014 break;
3015 case 5: /* ipAdEntReasmMaxSize */
3017 s32_t *sint_ptr = value;
3018 #if IP_REASSEMBLY
3019 *sint_ptr = (IP_HLEN + IP_REASS_BUFSIZE);
3020 #else
3021 /** @todo returning MTU would be a bad thing and
3022 returning a wild guess like '576' isn't good either */
3023 *sint_ptr = 0;
3024 #endif
3026 break;
3032 * @note
3033 * lwIP IP routing is currently using the network addresses in netif_list.
3034 * if no suitable network IP is found in netif_list, the default_netif is used.
3036 static void
3037 ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3039 u8_t id;
3041 /* return to object name, adding index depth (4) */
3042 ident_len += 4;
3043 ident -= 4;
3045 if (ident_len == 5)
3047 od->id_inst_len = ident_len;
3048 od->id_inst_ptr = ident;
3050 id = ident[0];
3051 switch (id)
3053 case 1: /* ipRouteDest */
3054 case 7: /* ipRouteNextHop */
3055 case 11: /* ipRouteMask */
3056 od->instance = MIB_OBJECT_TAB;
3057 od->access = MIB_OBJECT_READ_WRITE;
3058 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3059 od->v_len = 4;
3060 break;
3061 case 2: /* ipRouteIfIndex */
3062 case 3: /* ipRouteMetric1 */
3063 case 4: /* ipRouteMetric2 */
3064 case 5: /* ipRouteMetric3 */
3065 case 6: /* ipRouteMetric4 */
3066 case 8: /* ipRouteType */
3067 case 10: /* ipRouteAge */
3068 case 12: /* ipRouteMetric5 */
3069 od->instance = MIB_OBJECT_TAB;
3070 od->access = MIB_OBJECT_READ_WRITE;
3071 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3072 od->v_len = sizeof(s32_t);
3073 break;
3074 case 9: /* ipRouteProto */
3075 od->instance = MIB_OBJECT_TAB;
3076 od->access = MIB_OBJECT_READ_ONLY;
3077 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3078 od->v_len = sizeof(s32_t);
3079 break;
3080 case 13: /* ipRouteInfo */
3081 /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */
3082 od->instance = MIB_OBJECT_TAB;
3083 od->access = MIB_OBJECT_READ_ONLY;
3084 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
3085 od->v_len = iprouteinfo.len * sizeof(s32_t);
3086 break;
3087 default:
3088 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n"));
3089 od->instance = MIB_OBJECT_NONE;
3090 break;
3093 else
3095 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n"));
3096 od->instance = MIB_OBJECT_NONE;
3100 static void
3101 ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
3103 struct netif *netif;
3104 struct ip_addr dest;
3105 s32_t *ident;
3106 u8_t id;
3108 ident = od->id_inst_ptr;
3109 snmp_oidtoip(&ident[1], &dest);
3110 dest.addr = htonl(dest.addr);
3112 if (dest.addr == 0)
3114 /* ip_route() uses default netif for default route */
3115 netif = netif_default;
3117 else
3119 /* not using ip_route(), need exact match! */
3120 netif = netif_list;
3121 while ((netif != NULL) &&
3122 !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
3124 netif = netif->next;
3127 if (netif != NULL)
3129 id = ident[0];
3130 switch (id)
3132 case 1: /* ipRouteDest */
3134 struct ip_addr *dst = value;
3136 if (dest.addr == 0)
3138 /* default rte has 0.0.0.0 dest */
3139 dst->addr = 0;
3141 else
3143 /* netifs have netaddress dest */
3144 dst->addr = netif->ip_addr.addr & netif->netmask.addr;
3147 break;
3148 case 2: /* ipRouteIfIndex */
3150 s32_t *sint_ptr = value;
3152 snmp_netiftoifindex(netif, sint_ptr);
3154 break;
3155 case 3: /* ipRouteMetric1 */
3157 s32_t *sint_ptr = value;
3159 if (dest.addr == 0)
3161 /* default rte has metric 1 */
3162 *sint_ptr = 1;
3164 else
3166 /* other rtes have metric 0 */
3167 *sint_ptr = 0;
3170 break;
3171 case 4: /* ipRouteMetric2 */
3172 case 5: /* ipRouteMetric3 */
3173 case 6: /* ipRouteMetric4 */
3174 case 12: /* ipRouteMetric5 */
3176 s32_t *sint_ptr = value;
3177 /* not used */
3178 *sint_ptr = -1;
3180 break;
3181 case 7: /* ipRouteNextHop */
3183 struct ip_addr *dst = value;
3185 if (dest.addr == 0)
3187 /* default rte: gateway */
3188 *dst = netif->gw;
3190 else
3192 /* other rtes: netif ip_addr */
3193 *dst = netif->ip_addr;
3196 break;
3197 case 8: /* ipRouteType */
3199 s32_t *sint_ptr = value;
3201 if (dest.addr == 0)
3203 /* default rte is indirect */
3204 *sint_ptr = 4;
3206 else
3208 /* other rtes are direct */
3209 *sint_ptr = 3;
3212 break;
3213 case 9: /* ipRouteProto */
3215 s32_t *sint_ptr = value;
3216 /* locally defined routes */
3217 *sint_ptr = 2;
3219 break;
3220 case 10: /* ipRouteAge */
3222 s32_t *sint_ptr = value;
3223 /** @todo (sysuptime - timestamp last change) / 100
3224 @see snmp_insert_iprteidx_tree() */
3225 *sint_ptr = 0;
3227 break;
3228 case 11: /* ipRouteMask */
3230 struct ip_addr *dst = value;
3232 if (dest.addr == 0)
3234 /* default rte use 0.0.0.0 mask */
3235 dst->addr = 0;
3237 else
3239 /* other rtes use netmask */
3240 *dst = netif->netmask;
3243 break;
3244 case 13: /* ipRouteInfo */
3245 objectidncpy((s32_t*)value,(s32_t*)iprouteinfo.id,len / sizeof(s32_t));
3246 break;
3251 static void
3252 ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3254 /* return to object name, adding index depth (5) */
3255 ident_len += 5;
3256 ident -= 5;
3258 if (ident_len == 6)
3260 u8_t id;
3262 od->id_inst_len = ident_len;
3263 od->id_inst_ptr = ident;
3265 id = ident[0];
3266 switch (id)
3268 case 1: /* ipNetToMediaIfIndex */
3269 case 4: /* ipNetToMediaType */
3270 od->instance = MIB_OBJECT_TAB;
3271 od->access = MIB_OBJECT_READ_WRITE;
3272 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3273 od->v_len = sizeof(s32_t);
3274 break;
3275 case 2: /* ipNetToMediaPhysAddress */
3276 od->instance = MIB_OBJECT_TAB;
3277 od->access = MIB_OBJECT_READ_WRITE;
3278 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
3279 od->v_len = sizeof(struct eth_addr);
3280 break;
3281 case 3: /* ipNetToMediaNetAddress */
3282 od->instance = MIB_OBJECT_TAB;
3283 od->access = MIB_OBJECT_READ_WRITE;
3284 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3285 od->v_len = 4;
3286 break;
3287 default:
3288 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n"));
3289 od->instance = MIB_OBJECT_NONE;
3290 break;
3293 else
3295 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n"));
3296 od->instance = MIB_OBJECT_NONE;
3300 static void
3301 ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
3303 u8_t id;
3304 struct eth_addr* ethaddr_ret;
3305 struct ip_addr* ipaddr_ret;
3306 struct ip_addr ip;
3307 struct netif *netif;
3309 if (len) {}
3311 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
3312 snmp_oidtoip(&od->id_inst_ptr[2], &ip);
3313 ip.addr = htonl(ip.addr);
3315 if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
3317 id = od->id_inst_ptr[0];
3318 switch (id)
3320 case 1: /* ipNetToMediaIfIndex */
3322 s32_t *sint_ptr = value;
3323 *sint_ptr = od->id_inst_ptr[1];
3325 break;
3326 case 2: /* ipNetToMediaPhysAddress */
3328 struct eth_addr *dst = value;
3330 *dst = *ethaddr_ret;
3332 break;
3333 case 3: /* ipNetToMediaNetAddress */
3335 struct ip_addr *dst = value;
3337 *dst = *ipaddr_ret;
3339 break;
3340 case 4: /* ipNetToMediaType */
3342 s32_t *sint_ptr = value;
3343 /* dynamic (?) */
3344 *sint_ptr = 3;
3346 break;
3351 static void
3352 icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3354 /* return to object name, adding index depth (1) */
3355 ident_len += 1;
3356 ident -= 1;
3357 if ((ident_len == 2) &&
3358 (ident[0] > 0) && (ident[0] < 27))
3360 od->id_inst_len = ident_len;
3361 od->id_inst_ptr = ident;
3363 od->instance = MIB_OBJECT_SCALAR;
3364 od->access = MIB_OBJECT_READ_ONLY;
3365 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3366 od->v_len = sizeof(u32_t);
3368 else
3370 LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n"));
3371 od->instance = MIB_OBJECT_NONE;
3375 static void
3376 icmp_get_value(struct obj_def *od, u16_t len, void *value)
3378 u32_t *uint_ptr = value;
3379 u8_t id;
3381 if (len){}
3382 id = od->id_inst_ptr[0];
3383 switch (id)
3385 case 1: /* icmpInMsgs */
3386 *uint_ptr = icmpinmsgs;
3387 break;
3388 case 2: /* icmpInErrors */
3389 *uint_ptr = icmpinerrors;
3390 break;
3391 case 3: /* icmpInDestUnreachs */
3392 *uint_ptr = icmpindestunreachs;
3393 break;
3394 case 4: /* icmpInTimeExcds */
3395 *uint_ptr = icmpintimeexcds;
3396 break;
3397 case 5: /* icmpInParmProbs */
3398 *uint_ptr = icmpinparmprobs;
3399 break;
3400 case 6: /* icmpInSrcQuenchs */
3401 *uint_ptr = icmpinsrcquenchs;
3402 break;
3403 case 7: /* icmpInRedirects */
3404 *uint_ptr = icmpinredirects;
3405 break;
3406 case 8: /* icmpInEchos */
3407 *uint_ptr = icmpinechos;
3408 break;
3409 case 9: /* icmpInEchoReps */
3410 *uint_ptr = icmpinechoreps;
3411 break;
3412 case 10: /* icmpInTimestamps */
3413 *uint_ptr = icmpintimestamps;
3414 break;
3415 case 11: /* icmpInTimestampReps */
3416 *uint_ptr = icmpintimestampreps;
3417 break;
3418 case 12: /* icmpInAddrMasks */
3419 *uint_ptr = icmpinaddrmasks;
3420 break;
3421 case 13: /* icmpInAddrMaskReps */
3422 *uint_ptr = icmpinaddrmaskreps;
3423 break;
3424 case 14: /* icmpOutMsgs */
3425 *uint_ptr = icmpoutmsgs;
3426 break;
3427 case 15: /* icmpOutErrors */
3428 *uint_ptr = icmpouterrors;
3429 break;
3430 case 16: /* icmpOutDestUnreachs */
3431 *uint_ptr = icmpoutdestunreachs;
3432 break;
3433 case 17: /* icmpOutTimeExcds */
3434 *uint_ptr = icmpouttimeexcds;
3435 break;
3436 case 18: /* icmpOutParmProbs */
3437 *uint_ptr = icmpoutparmprobs;
3438 break;
3439 case 19: /* icmpOutSrcQuenchs */
3440 *uint_ptr = icmpoutsrcquenchs;
3441 break;
3442 case 20: /* icmpOutRedirects */
3443 *uint_ptr = icmpoutredirects;
3444 break;
3445 case 21: /* icmpOutEchos */
3446 *uint_ptr = icmpoutechos;
3447 break;
3448 case 22: /* icmpOutEchoReps */
3449 *uint_ptr = icmpoutechoreps;
3450 break;
3451 case 23: /* icmpOutTimestamps */
3452 *uint_ptr = icmpouttimestamps;
3453 break;
3454 case 24: /* icmpOutTimestampReps */
3455 *uint_ptr = icmpouttimestampreps;
3456 break;
3457 case 25: /* icmpOutAddrMasks */
3458 *uint_ptr = icmpoutaddrmasks;
3459 break;
3460 case 26: /* icmpOutAddrMaskReps */
3461 *uint_ptr = icmpoutaddrmaskreps;
3462 break;
3466 #if LWIP_TCP
3467 /** @todo tcp grp */
3468 static void
3469 tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3471 u8_t id;
3473 /* return to object name, adding index depth (1) */
3474 ident_len += 1;
3475 ident -= 1;
3476 if (ident_len == 2)
3478 od->id_inst_len = ident_len;
3479 od->id_inst_ptr = ident;
3481 id = ident[0];
3482 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
3484 switch (id)
3486 case 1: /* tcpRtoAlgorithm */
3487 case 2: /* tcpRtoMin */
3488 case 3: /* tcpRtoMax */
3489 case 4: /* tcpMaxConn */
3490 od->instance = MIB_OBJECT_SCALAR;
3491 od->access = MIB_OBJECT_READ_ONLY;
3492 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3493 od->v_len = sizeof(s32_t);
3494 break;
3495 case 5: /* tcpActiveOpens */
3496 case 6: /* tcpPassiveOpens */
3497 case 7: /* tcpAttemptFails */
3498 case 8: /* tcpEstabResets */
3499 case 10: /* tcpInSegs */
3500 case 11: /* tcpOutSegs */
3501 case 12: /* tcpRetransSegs */
3502 case 14: /* tcpInErrs */
3503 case 15: /* tcpOutRsts */
3504 od->instance = MIB_OBJECT_SCALAR;
3505 od->access = MIB_OBJECT_READ_ONLY;
3506 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3507 od->v_len = sizeof(u32_t);
3508 break;
3509 case 9: /* tcpCurrEstab */
3510 od->instance = MIB_OBJECT_TAB;
3511 od->access = MIB_OBJECT_READ_ONLY;
3512 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
3513 od->v_len = sizeof(u32_t);
3514 break;
3515 default:
3516 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n"));
3517 od->instance = MIB_OBJECT_NONE;
3518 break;
3521 else
3523 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n"));
3524 od->instance = MIB_OBJECT_NONE;
3528 static void
3529 tcp_get_value(struct obj_def *od, u16_t len, void *value)
3531 u32_t *uint_ptr = value;
3532 s32_t *sint_ptr = value;
3533 u8_t id;
3535 if (len){}
3536 id = od->id_inst_ptr[0];
3537 switch (id)
3539 case 1: /* tcpRtoAlgorithm, vanj(4) */
3540 *sint_ptr = 4;
3541 break;
3542 case 2: /* tcpRtoMin */
3543 /* @todo not the actual value, a guess,
3544 needs to be calculated */
3545 *sint_ptr = 1000;
3546 break;
3547 case 3: /* tcpRtoMax */
3548 /* @todo not the actual value, a guess,
3549 needs to be calculated */
3550 *sint_ptr = 60000;
3551 break;
3552 case 4: /* tcpMaxConn */
3553 *sint_ptr = MEMP_NUM_TCP_PCB;
3554 break;
3555 case 5: /* tcpActiveOpens */
3556 *uint_ptr = tcpactiveopens;
3557 break;
3558 case 6: /* tcpPassiveOpens */
3559 *uint_ptr = tcppassiveopens;
3560 break;
3561 case 7: /* tcpAttemptFails */
3562 *uint_ptr = tcpattemptfails;
3563 break;
3564 case 8: /* tcpEstabResets */
3565 *uint_ptr = tcpestabresets;
3566 break;
3567 case 9: /* tcpCurrEstab */
3569 u16_t tcpcurrestab = 0;
3570 struct tcp_pcb *pcb = tcp_active_pcbs;
3571 while (pcb != NULL)
3573 if ((pcb->state == ESTABLISHED) ||
3574 (pcb->state == CLOSE_WAIT))
3576 tcpcurrestab++;
3578 pcb = pcb->next;
3580 *uint_ptr = tcpcurrestab;
3582 break;
3583 case 10: /* tcpInSegs */
3584 *uint_ptr = tcpinsegs;
3585 break;
3586 case 11: /* tcpOutSegs */
3587 *uint_ptr = tcpoutsegs;
3588 break;
3589 case 12: /* tcpRetransSegs */
3590 *uint_ptr = tcpretranssegs;
3591 break;
3592 case 14: /* tcpInErrs */
3593 *uint_ptr = tcpinerrs;
3594 break;
3595 case 15: /* tcpOutRsts */
3596 *uint_ptr = tcpoutrsts;
3597 break;
3601 static void
3602 tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3604 /* return to object name, adding index depth (10) */
3605 ident_len += 10;
3606 ident -= 10;
3608 if (ident_len == 11)
3610 u8_t id;
3612 od->id_inst_len = ident_len;
3613 od->id_inst_ptr = ident;
3615 id = ident[0];
3616 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
3618 switch (id)
3620 case 1: /* tcpConnState */
3621 od->instance = MIB_OBJECT_TAB;
3622 od->access = MIB_OBJECT_READ_WRITE;
3623 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3624 od->v_len = sizeof(s32_t);
3625 break;
3626 case 2: /* tcpConnLocalAddress */
3627 case 4: /* tcpConnRemAddress */
3628 od->instance = MIB_OBJECT_TAB;
3629 od->access = MIB_OBJECT_READ_ONLY;
3630 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3631 od->v_len = 4;
3632 break;
3633 case 3: /* tcpConnLocalPort */
3634 case 5: /* tcpConnRemPort */
3635 od->instance = MIB_OBJECT_TAB;
3636 od->access = MIB_OBJECT_READ_ONLY;
3637 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3638 od->v_len = sizeof(s32_t);
3639 break;
3640 default:
3641 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
3642 od->instance = MIB_OBJECT_NONE;
3643 break;
3646 else
3648 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
3649 od->instance = MIB_OBJECT_NONE;
3653 static void
3654 tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)
3656 struct ip_addr lip, rip;
3657 u16_t lport, rport;
3658 s32_t *ident;
3660 ident = od->id_inst_ptr;
3661 snmp_oidtoip(&ident[1], &lip);
3662 lip.addr = htonl(lip.addr);
3663 lport = ident[5];
3664 snmp_oidtoip(&ident[6], &rip);
3665 rip.addr = htonl(rip.addr);
3666 rport = ident[10];
3668 /** @todo find matching PCB */
3670 #endif
3672 static void
3673 udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3675 /* return to object name, adding index depth (1) */
3676 ident_len += 1;
3677 ident -= 1;
3678 if ((ident_len == 2) &&
3679 (ident[0] > 0) && (ident[0] < 6))
3681 od->id_inst_len = ident_len;
3682 od->id_inst_ptr = ident;
3684 od->instance = MIB_OBJECT_SCALAR;
3685 od->access = MIB_OBJECT_READ_ONLY;
3686 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3687 od->v_len = sizeof(u32_t);
3689 else
3691 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n"));
3692 od->instance = MIB_OBJECT_NONE;
3696 static void
3697 udp_get_value(struct obj_def *od, u16_t len, void *value)
3699 u32_t *uint_ptr = value;
3700 u8_t id;
3702 if (len){}
3703 id = od->id_inst_ptr[0];
3704 switch (id)
3706 case 1: /* udpInDatagrams */
3707 *uint_ptr = udpindatagrams;
3708 break;
3709 case 2: /* udpNoPorts */
3710 *uint_ptr = udpnoports;
3711 break;
3712 case 3: /* udpInErrors */
3713 *uint_ptr = udpinerrors;
3714 break;
3715 case 4: /* udpOutDatagrams */
3716 *uint_ptr = udpoutdatagrams;
3717 break;
3721 static void
3722 udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3724 /* return to object name, adding index depth (5) */
3725 ident_len += 5;
3726 ident -= 5;
3728 if (ident_len == 6)
3730 od->id_inst_len = ident_len;
3731 od->id_inst_ptr = ident;
3733 switch (ident[0])
3735 case 1: /* udpLocalAddress */
3736 od->instance = MIB_OBJECT_TAB;
3737 od->access = MIB_OBJECT_READ_ONLY;
3738 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3739 od->v_len = 4;
3740 break;
3741 case 2: /* udpLocalPort */
3742 od->instance = MIB_OBJECT_TAB;
3743 od->access = MIB_OBJECT_READ_ONLY;
3744 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3745 od->v_len = sizeof(s32_t);
3746 break;
3747 default:
3748 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n"));
3749 od->instance = MIB_OBJECT_NONE;
3750 break;
3753 else
3755 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n"));
3756 od->instance = MIB_OBJECT_NONE;
3760 static void
3761 udpentry_get_value(struct obj_def *od, u16_t len, void *value)
3763 u8_t id;
3764 struct udp_pcb *pcb;
3765 struct ip_addr ip;
3766 u16_t port;
3768 if (len){}
3769 snmp_oidtoip(&od->id_inst_ptr[1], &ip);
3770 ip.addr = htonl(ip.addr);
3771 port = od->id_inst_ptr[5];
3773 pcb = udp_pcbs;
3774 while ((pcb != NULL) &&
3775 !((pcb->local_ip.addr == ip.addr) &&
3776 (pcb->local_port == port)))
3778 pcb = pcb->next;
3781 if (pcb != NULL)
3783 id = od->id_inst_ptr[0];
3784 switch (id)
3786 case 1: /* udpLocalAddress */
3788 struct ip_addr *dst = value;
3789 *dst = pcb->local_ip;
3791 break;
3792 case 2: /* udpLocalPort */
3794 s32_t *sint_ptr = value;
3795 *sint_ptr = pcb->local_port;
3797 break;
3802 static void
3803 snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3805 /* return to object name, adding index depth (1) */
3806 ident_len += 1;
3807 ident -= 1;
3808 if (ident_len == 2)
3810 u8_t id;
3812 od->id_inst_len = ident_len;
3813 od->id_inst_ptr = ident;
3815 id = ident[0];
3816 switch (id)
3818 case 1: /* snmpInPkts */
3819 case 2: /* snmpOutPkts */
3820 case 3: /* snmpInBadVersions */
3821 case 4: /* snmpInBadCommunityNames */
3822 case 5: /* snmpInBadCommunityUses */
3823 case 6: /* snmpInASNParseErrs */
3824 case 8: /* snmpInTooBigs */
3825 case 9: /* snmpInNoSuchNames */
3826 case 10: /* snmpInBadValues */
3827 case 11: /* snmpInReadOnlys */
3828 case 12: /* snmpInGenErrs */
3829 case 13: /* snmpInTotalReqVars */
3830 case 14: /* snmpInTotalSetVars */
3831 case 15: /* snmpInGetRequests */
3832 case 16: /* snmpInGetNexts */
3833 case 17: /* snmpInSetRequests */
3834 case 18: /* snmpInGetResponses */
3835 case 19: /* snmpInTraps */
3836 case 20: /* snmpOutTooBigs */
3837 case 21: /* snmpOutNoSuchNames */
3838 case 22: /* snmpOutBadValues */
3839 case 24: /* snmpOutGenErrs */
3840 case 25: /* snmpOutGetRequests */
3841 case 26: /* snmpOutGetNexts */
3842 case 27: /* snmpOutSetRequests */
3843 case 28: /* snmpOutGetResponses */
3844 case 29: /* snmpOutTraps */
3845 od->instance = MIB_OBJECT_SCALAR;
3846 od->access = MIB_OBJECT_READ_ONLY;
3847 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3848 od->v_len = sizeof(u32_t);
3849 break;
3850 case 30: /* snmpEnableAuthenTraps */
3851 od->instance = MIB_OBJECT_SCALAR;
3852 od->access = MIB_OBJECT_READ_WRITE;
3853 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3854 od->v_len = sizeof(s32_t);
3855 break;
3856 default:
3857 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n"));
3858 od->instance = MIB_OBJECT_NONE;
3859 break;
3862 else
3864 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n"));
3865 od->instance = MIB_OBJECT_NONE;
3869 static void
3870 snmp_get_value(struct obj_def *od, u16_t len, void *value)
3872 u32_t *uint_ptr = value;
3873 u8_t id;
3875 if (len){}
3876 id = od->id_inst_ptr[0];
3877 switch (id)
3879 case 1: /* snmpInPkts */
3880 *uint_ptr = snmpinpkts;
3881 break;
3882 case 2: /* snmpOutPkts */
3883 *uint_ptr = snmpoutpkts;
3884 break;
3885 case 3: /* snmpInBadVersions */
3886 *uint_ptr = snmpinbadversions;
3887 break;
3888 case 4: /* snmpInBadCommunityNames */
3889 *uint_ptr = snmpinbadcommunitynames;
3890 break;
3891 case 5: /* snmpInBadCommunityUses */
3892 *uint_ptr = snmpinbadcommunityuses;
3893 break;
3894 case 6: /* snmpInASNParseErrs */
3895 *uint_ptr = snmpinasnparseerrs;
3896 break;
3897 case 8: /* snmpInTooBigs */
3898 *uint_ptr = snmpintoobigs;
3899 break;
3900 case 9: /* snmpInNoSuchNames */
3901 *uint_ptr = snmpinnosuchnames;
3902 break;
3903 case 10: /* snmpInBadValues */
3904 *uint_ptr = snmpinbadvalues;
3905 break;
3906 case 11: /* snmpInReadOnlys */
3907 *uint_ptr = snmpinreadonlys;
3908 break;
3909 case 12: /* snmpInGenErrs */
3910 *uint_ptr = snmpingenerrs;
3911 break;
3912 case 13: /* snmpInTotalReqVars */
3913 *uint_ptr = snmpintotalreqvars;
3914 break;
3915 case 14: /* snmpInTotalSetVars */
3916 *uint_ptr = snmpintotalsetvars;
3917 break;
3918 case 15: /* snmpInGetRequests */
3919 *uint_ptr = snmpingetrequests;
3920 break;
3921 case 16: /* snmpInGetNexts */
3922 *uint_ptr = snmpingetnexts;
3923 break;
3924 case 17: /* snmpInSetRequests */
3925 *uint_ptr = snmpinsetrequests;
3926 break;
3927 case 18: /* snmpInGetResponses */
3928 *uint_ptr = snmpingetresponses;
3929 break;
3930 case 19: /* snmpInTraps */
3931 *uint_ptr = snmpintraps;
3932 break;
3933 case 20: /* snmpOutTooBigs */
3934 *uint_ptr = snmpouttoobigs;
3935 break;
3936 case 21: /* snmpOutNoSuchNames */
3937 *uint_ptr = snmpoutnosuchnames;
3938 break;
3939 case 22: /* snmpOutBadValues */
3940 *uint_ptr = snmpoutbadvalues;
3941 break;
3942 case 24: /* snmpOutGenErrs */
3943 *uint_ptr = snmpoutgenerrs;
3944 break;
3945 case 25: /* snmpOutGetRequests */
3946 *uint_ptr = snmpoutgetrequests;
3947 break;
3948 case 26: /* snmpOutGetNexts */
3949 *uint_ptr = snmpoutgetnexts;
3950 break;
3951 case 27: /* snmpOutSetRequests */
3952 *uint_ptr = snmpoutsetrequests;
3953 break;
3954 case 28: /* snmpOutGetResponses */
3955 *uint_ptr = snmpoutgetresponses;
3956 break;
3957 case 29: /* snmpOutTraps */
3958 *uint_ptr = snmpouttraps;
3959 break;
3960 case 30: /* snmpEnableAuthenTraps */
3961 *uint_ptr = *snmpenableauthentraps_ptr;
3962 break;
3967 * Test snmp object value before setting.
3969 * @param od is the object definition
3970 * @param len return value space (in bytes)
3971 * @param value points to (varbind) space to copy value from.
3973 static u8_t
3974 snmp_set_test(struct obj_def *od, u16_t len, void *value)
3976 u8_t id, set_ok;
3978 if (len) {}
3979 set_ok = 0;
3980 id = od->id_inst_ptr[0];
3981 if (id == 30)
3983 /* snmpEnableAuthenTraps */
3984 s32_t *sint_ptr = value;
3986 if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default)
3988 /* we should have writable non-volatile mem here */
3989 if ((*sint_ptr == 1) || (*sint_ptr == 2))
3991 set_ok = 1;
3994 else
3996 /* const or hardwired value */
3997 if (*sint_ptr == snmpenableauthentraps_default)
3999 set_ok = 1;
4003 return set_ok;
4006 static void
4007 snmp_set_value(struct obj_def *od, u16_t len, void *value)
4009 u8_t id;
4011 if (len) {}
4012 id = od->id_inst_ptr[0];
4013 if (id == 30)
4015 /* snmpEnableAuthenTraps */
4016 s32_t *sint_ptr = value;
4017 *snmpenableauthentraps_ptr = *sint_ptr;
4021 #endif /* LWIP_SNMP */