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.
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
35 * Author: Christiaan Simons <christiaan.simons@axon.tv>
40 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
42 #include "lwip/snmp.h"
43 #include "lwip/netif.h"
45 #include "lwip/ip_frag.h"
46 #include "lwip/tcp_impl.h"
48 #include "lwip/snmp_asn1.h"
49 #include "lwip/snmp_structs.h"
50 #include "netif/etharp.h"
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))
73 #ifndef SNMP_GET_SYSUPTIME
74 #define SNMP_GET_SYSUPTIME(sysuptime)
77 static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
78 static void system_get_value(struct obj_def *od, u16_t len, void *value);
79 static u8_t system_set_test(struct obj_def *od, u16_t len, void *value);
80 static void system_set_value(struct obj_def *od, u16_t len, void *value);
81 static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
82 static void interfaces_get_value(struct obj_def *od, u16_t len, void *value);
83 static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
84 static void ifentry_get_value(struct obj_def *od, u16_t len, void *value);
85 #if !SNMP_SAFE_REQUESTS
86 static u8_t ifentry_set_test (struct obj_def *od, u16_t len, void *value);
87 static void ifentry_set_value (struct obj_def *od, u16_t len, void *value);
88 #endif /* SNMP_SAFE_REQUESTS */
89 static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
90 static void atentry_get_value(struct obj_def *od, u16_t len, void *value);
91 static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
92 static void ip_get_value(struct obj_def *od, u16_t len, void *value);
93 static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value);
94 static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
95 static void ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value);
96 static void ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
97 static void ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value);
98 static void ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
99 static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value);
100 static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
101 static void icmp_get_value(struct obj_def *od, u16_t len, void *value);
103 static void tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
104 static void tcp_get_value(struct obj_def *od, u16_t len, void *value);
105 #ifdef THIS_SEEMS_UNUSED
106 static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
107 static void tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value);
110 static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
111 static void udp_get_value(struct obj_def *od, u16_t len, void *value);
112 static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
113 static void udpentry_get_value(struct obj_def *od, u16_t len, void *value);
114 static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
115 static void snmp_get_value(struct obj_def *od, u16_t len, void *value);
116 static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value);
117 static void snmp_set_value(struct obj_def *od, u16_t len, void *value);
120 /* snmp .1.3.6.1.2.1.11 */
121 const mib_scalar_node snmp_scalar = {
122 &snmp_get_object_def,
129 const s32_t snmp_ids[28] = {
130 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
131 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30
133 struct mib_node* const snmp_nodes[28] = {
134 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
135 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
136 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
137 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
138 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
139 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
140 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
141 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
142 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
143 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
144 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
145 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
146 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
147 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar
149 const struct mib_array_node snmp = {
150 &noleafs_get_object_def,
160 /* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */
161 /* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */
162 /* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */
164 /* udp .1.3.6.1.2.1.7 */
165 /** index root node for udpTable */
166 struct mib_list_rootnode udp_root = {
167 &noleafs_get_object_def,
177 const s32_t udpentry_ids[2] = { 1, 2 };
178 struct mib_node* const udpentry_nodes[2] = {
179 (struct mib_node*)&udp_root, (struct mib_node*)&udp_root,
181 const struct mib_array_node udpentry = {
182 &noleafs_get_object_def,
192 s32_t udptable_id = 1;
193 struct mib_node* udptable_node = (struct mib_node*)&udpentry;
194 struct mib_ram_array_node udptable = {
195 &noleafs_get_object_def,
205 const mib_scalar_node udp_scalar = {
213 const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 };
214 struct mib_node* const udp_nodes[5] = {
215 (struct mib_node*)&udp_scalar, (struct mib_node*)&udp_scalar,
216 (struct mib_node*)&udp_scalar, (struct mib_node*)&udp_scalar,
217 (struct mib_node*)&udptable
219 const struct mib_array_node udp = {
220 &noleafs_get_object_def,
230 /* tcp .1.3.6.1.2.1.6 */
232 /* only if the TCP protocol is available may implement this group */
233 /** index root node for tcpConnTable */
234 struct mib_list_rootnode tcpconntree_root = {
235 &noleafs_get_object_def,
245 const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 };
246 struct mib_node* const tcpconnentry_nodes[5] = {
247 (struct mib_node*)&tcpconntree_root, (struct mib_node*)&tcpconntree_root,
248 (struct mib_node*)&tcpconntree_root, (struct mib_node*)&tcpconntree_root,
249 (struct mib_node*)&tcpconntree_root
251 const struct mib_array_node tcpconnentry = {
252 &noleafs_get_object_def,
262 s32_t tcpconntable_id = 1;
263 struct mib_node* tcpconntable_node = (struct mib_node*)&tcpconnentry;
264 struct mib_ram_array_node tcpconntable = {
265 &noleafs_get_object_def,
270 /** @todo update maxlength when inserting / deleting from table
271 0 when table is empty, 1 when more than one entry */
277 const mib_scalar_node tcp_scalar = {
285 const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
286 struct mib_node* const tcp_nodes[15] = {
287 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
288 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
289 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
290 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
291 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
292 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
293 (struct mib_node*)&tcpconntable, (struct mib_node*)&tcp_scalar,
294 (struct mib_node*)&tcp_scalar
296 const struct mib_array_node tcp = {
297 &noleafs_get_object_def,
308 /* icmp .1.3.6.1.2.1.5 */
309 const mib_scalar_node icmp_scalar = {
310 &icmp_get_object_def,
317 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 };
318 struct mib_node* const icmp_nodes[26] = {
319 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
320 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
321 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
322 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
323 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
324 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
325 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
326 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
327 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
328 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
329 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
330 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
331 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar
333 const struct mib_array_node icmp = {
334 &noleafs_get_object_def,
344 /** index root node for ipNetToMediaTable */
345 struct mib_list_rootnode ipntomtree_root = {
346 &noleafs_get_object_def,
356 const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 };
357 struct mib_node* const ipntomentry_nodes[4] = {
358 (struct mib_node*)&ipntomtree_root, (struct mib_node*)&ipntomtree_root,
359 (struct mib_node*)&ipntomtree_root, (struct mib_node*)&ipntomtree_root
361 const struct mib_array_node ipntomentry = {
362 &noleafs_get_object_def,
372 s32_t ipntomtable_id = 1;
373 struct mib_node* ipntomtable_node = (struct mib_node*)&ipntomentry;
374 struct mib_ram_array_node ipntomtable = {
375 &noleafs_get_object_def,
385 /** index root node for ipRouteTable */
386 struct mib_list_rootnode iprtetree_root = {
387 &noleafs_get_object_def,
397 const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
398 struct mib_node* const iprteentry_nodes[13] = {
399 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
400 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
401 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
402 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
403 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
404 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
405 (struct mib_node*)&iprtetree_root
407 const struct mib_array_node iprteentry = {
408 &noleafs_get_object_def,
418 s32_t iprtetable_id = 1;
419 struct mib_node* iprtetable_node = (struct mib_node*)&iprteentry;
420 struct mib_ram_array_node iprtetable = {
421 &noleafs_get_object_def,
431 /** index root node for ipAddrTable */
432 struct mib_list_rootnode ipaddrtree_root = {
433 &noleafs_get_object_def,
443 const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 };
444 struct mib_node* const ipaddrentry_nodes[5] = {
445 (struct mib_node*)&ipaddrtree_root,
446 (struct mib_node*)&ipaddrtree_root,
447 (struct mib_node*)&ipaddrtree_root,
448 (struct mib_node*)&ipaddrtree_root,
449 (struct mib_node*)&ipaddrtree_root
451 const struct mib_array_node ipaddrentry = {
452 &noleafs_get_object_def,
462 s32_t ipaddrtable_id = 1;
463 struct mib_node* ipaddrtable_node = (struct mib_node*)&ipaddrentry;
464 struct mib_ram_array_node ipaddrtable = {
465 &noleafs_get_object_def,
475 /* ip .1.3.6.1.2.1.4 */
476 const mib_scalar_node ip_scalar = {
484 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 };
485 struct mib_node* const ip_nodes[23] = {
486 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
487 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
488 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
489 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
490 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
491 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
492 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
493 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
494 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
495 (struct mib_node*)&ip_scalar, (struct mib_node*)&ipaddrtable,
496 (struct mib_node*)&iprtetable, (struct mib_node*)&ipntomtable,
497 (struct mib_node*)&ip_scalar
499 const struct mib_array_node mib2_ip = {
500 &noleafs_get_object_def,
510 /** index root node for atTable */
511 struct mib_list_rootnode arptree_root = {
512 &noleafs_get_object_def,
522 const s32_t atentry_ids[3] = { 1, 2, 3 };
523 struct mib_node* const atentry_nodes[3] = {
524 (struct mib_node*)&arptree_root,
525 (struct mib_node*)&arptree_root,
526 (struct mib_node*)&arptree_root
528 const struct mib_array_node atentry = {
529 &noleafs_get_object_def,
539 const s32_t attable_id = 1;
540 struct mib_node* const attable_node = (struct mib_node*)&atentry;
541 const struct mib_array_node attable = {
542 &noleafs_get_object_def,
552 /* at .1.3.6.1.2.1.3 */
554 struct mib_node* mib2_at_node = (struct mib_node*)&attable;
555 struct mib_ram_array_node at = {
556 &noleafs_get_object_def,
566 /** index root node for ifTable */
567 struct mib_list_rootnode iflist_root = {
568 &ifentry_get_object_def,
570 #if SNMP_SAFE_REQUESTS
573 #else /* SNMP_SAFE_REQUESTS */
576 #endif /* SNMP_SAFE_REQUESTS */
583 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 };
584 struct mib_node* const ifentry_nodes[22] = {
585 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
586 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
587 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
588 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
589 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
590 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
591 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
592 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
593 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
594 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
595 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root
597 const struct mib_array_node ifentry = {
598 &noleafs_get_object_def,
608 s32_t iftable_id = 1;
609 struct mib_node* iftable_node = (struct mib_node*)&ifentry;
610 struct mib_ram_array_node iftable = {
611 &noleafs_get_object_def,
621 /* interfaces .1.3.6.1.2.1.2 */
622 const mib_scalar_node interfaces_scalar = {
623 &interfaces_get_object_def,
624 &interfaces_get_value,
630 const s32_t interfaces_ids[2] = { 1, 2 };
631 struct mib_node* const interfaces_nodes[2] = {
632 (struct mib_node*)&interfaces_scalar, (struct mib_node*)&iftable
634 const struct mib_array_node interfaces = {
635 &noleafs_get_object_def,
647 /* system .1.3.6.1.2.1.1 */
648 const mib_scalar_node sys_tem_scalar = {
649 &system_get_object_def,
656 const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };
657 struct mib_node* const sys_tem_nodes[7] = {
658 (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
659 (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
660 (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
661 (struct mib_node*)&sys_tem_scalar
663 /* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */
664 const struct mib_array_node sys_tem = {
665 &noleafs_get_object_def,
675 /* mib-2 .1.3.6.1.2.1 */
677 #define MIB2_GROUPS 8
679 #define MIB2_GROUPS 7
681 const s32_t mib2_ids[MIB2_GROUPS] =
694 struct mib_node* const mib2_nodes[MIB2_GROUPS] = {
695 (struct mib_node*)&sys_tem,
696 (struct mib_node*)&interfaces,
697 (struct mib_node*)&at,
698 (struct mib_node*)&mib2_ip,
699 (struct mib_node*)&icmp,
701 (struct mib_node*)&tcp,
703 (struct mib_node*)&udp,
704 (struct mib_node*)&snmp
707 const struct mib_array_node mib2 = {
708 &noleafs_get_object_def,
718 /* mgmt .1.3.6.1.2 */
719 const s32_t mgmt_ids[1] = { 1 };
720 struct mib_node* const mgmt_nodes[1] = { (struct mib_node*)&mib2 };
721 const struct mib_array_node mgmt = {
722 &noleafs_get_object_def,
732 /* internet .1.3.6.1 */
734 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
735 * a 'struct mib_array_node mib_private' which contains your MIB. */
736 s32_t internet_ids[2] = { 2, 4 };
737 struct mib_node* const internet_nodes[2] = { (struct mib_node*)&mgmt, (struct mib_node*)&mib_private };
738 const struct mib_array_node internet = {
739 &noleafs_get_object_def,
749 const s32_t internet_ids[1] = { 2 };
750 struct mib_node* const internet_nodes[1] = { (struct mib_node*)&mgmt };
751 const struct mib_array_node internet = {
752 &noleafs_get_object_def,
763 /** mib-2.system.sysObjectID */
764 static struct snmp_obj_id sysobjid = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID};
765 /** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */
766 static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}};
767 /** mib-2.system.sysServices */
768 static const s32_t sysservices = SNMP_SYSSERVICES;
770 /** mib-2.system.sysDescr */
771 static const u8_t sysdescr_len_default = 4;
772 static const u8_t sysdescr_default[] = "lwIP";
773 static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default;
774 static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0];
775 /** mib-2.system.sysContact */
776 static const u8_t syscontact_len_default = 0;
777 static const u8_t syscontact_default[] = "";
778 static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default;
779 static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0];
780 /** mib-2.system.sysName */
781 static const u8_t sysname_len_default = 8;
782 static const u8_t sysname_default[] = "FQDN-unk";
783 static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default;
784 static u8_t* sysname_ptr = (u8_t*)&sysname_default[0];
785 /** mib-2.system.sysLocation */
786 static const u8_t syslocation_len_default = 0;
787 static const u8_t syslocation_default[] = "";
788 static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default;
789 static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0];
790 /** mib-2.snmp.snmpEnableAuthenTraps */
791 static const u8_t snmpenableauthentraps_default = 2; /* disabled */
792 static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default;
794 /** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */
795 static const struct snmp_obj_id ifspecific = {2, {0, 0}};
796 /** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */
797 static const struct snmp_obj_id iprouteinfo = {2, {0, 0}};
801 /* mib-2.system counter(s) */
802 static u32_t sysuptime = 0;
804 /* mib-2.ip counter(s) */
805 static u32_t ipinreceives = 0,
809 ipinunknownprotos = 0,
821 iproutingdiscards = 0;
822 /* mib-2.icmp counter(s) */
823 static u32_t icmpinmsgs = 0,
825 icmpindestunreachs = 0,
828 icmpinsrcquenchs = 0,
832 icmpintimestamps = 0,
833 icmpintimestampreps = 0,
835 icmpinaddrmaskreps = 0,
838 icmpoutdestunreachs = 0,
839 icmpouttimeexcds = 0,
840 icmpoutparmprobs = 0,
841 icmpoutsrcquenchs = 0,
842 icmpoutredirects = 0,
845 icmpouttimestamps = 0,
846 icmpouttimestampreps = 0,
847 icmpoutaddrmasks = 0,
848 icmpoutaddrmaskreps = 0;
849 /* mib-2.tcp counter(s) */
850 static u32_t tcpactiveopens = 0,
859 /* mib-2.udp counter(s) */
860 static u32_t udpindatagrams = 0,
864 /* mib-2.snmp counter(s) */
865 static u32_t snmpinpkts = 0,
867 snmpinbadversions = 0,
868 snmpinbadcommunitynames = 0,
869 snmpinbadcommunityuses = 0,
870 snmpinasnparseerrs = 0,
872 snmpinnosuchnames = 0,
876 snmpintotalreqvars = 0,
877 snmpintotalsetvars = 0,
878 snmpingetrequests = 0,
880 snmpinsetrequests = 0,
881 snmpingetresponses = 0,
884 snmpoutnosuchnames = 0,
885 snmpoutbadvalues = 0,
887 snmpoutgetrequests = 0,
889 snmpoutsetrequests = 0,
890 snmpoutgetresponses = 0,
895 /* prototypes of the following functions are in lwip/src/include/lwip/snmp.h */
899 * @param dst points to destination
900 * @param src points to source
901 * @param n number of octets to copy.
903 static void ocstrncpy(u8_t *dst, u8_t *src, u16_t n)
913 * Copy object identifier (s32_t) array.
915 * @param dst points to destination
916 * @param src points to source
917 * @param n number of sub identifiers to copy.
919 void objectidncpy(s32_t *dst, s32_t *src, u8_t n)
929 * Initializes sysDescr pointers.
931 * @param str if non-NULL then copy str pointer
932 * @param len points to string length, excluding zero terminator
934 void snmp_set_sysdesr(u8_t *str, u8_t *len)
939 sysdescr_len_ptr = len;
943 void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid)
949 * Initializes sysObjectID value.
951 * @param oid points to stuct snmp_obj_id to copy
953 void snmp_set_sysobjid(struct snmp_obj_id *oid)
959 * Must be called at regular 10 msec interval from a timer interrupt
960 * or signal handler depending on your runtime environment.
962 void snmp_inc_sysuptime(void)
967 void snmp_add_sysuptime(u32_t value)
972 void snmp_get_sysuptime(u32_t *value)
974 SNMP_GET_SYSUPTIME(sysuptime);
979 * Initializes sysContact pointers,
980 * e.g. ptrs to non-volatile memory external to lwIP.
982 * @param ocstr if non-NULL then copy str pointer
983 * @param ocstrlen points to string length, excluding zero terminator
985 void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen)
989 syscontact_ptr = ocstr;
990 syscontact_len_ptr = ocstrlen;
995 * Initializes sysName pointers,
996 * e.g. ptrs to non-volatile memory external to lwIP.
998 * @param ocstr if non-NULL then copy str pointer
999 * @param ocstrlen points to string length, excluding zero terminator
1001 void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen)
1005 sysname_ptr = ocstr;
1006 sysname_len_ptr = ocstrlen;
1011 * Initializes sysLocation pointers,
1012 * e.g. ptrs to non-volatile memory external to lwIP.
1014 * @param ocstr if non-NULL then copy str pointer
1015 * @param ocstrlen points to string length, excluding zero terminator
1017 void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen)
1021 syslocation_ptr = ocstr;
1022 syslocation_len_ptr = ocstrlen;
1027 void snmp_add_ifinoctets(struct netif *ni, u32_t value)
1029 ni->ifinoctets += value;
1032 void snmp_inc_ifinucastpkts(struct netif *ni)
1034 (ni->ifinucastpkts)++;
1037 void snmp_inc_ifinnucastpkts(struct netif *ni)
1039 (ni->ifinnucastpkts)++;
1042 void snmp_inc_ifindiscards(struct netif *ni)
1044 (ni->ifindiscards)++;
1047 void snmp_add_ifoutoctets(struct netif *ni, u32_t value)
1049 ni->ifoutoctets += value;
1052 void snmp_inc_ifoutucastpkts(struct netif *ni)
1054 (ni->ifoutucastpkts)++;
1057 void snmp_inc_ifoutnucastpkts(struct netif *ni)
1059 (ni->ifoutnucastpkts)++;
1062 void snmp_inc_ifoutdiscards(struct netif *ni)
1064 (ni->ifoutdiscards)++;
1067 void snmp_inc_iflist(void)
1069 struct mib_list_node *if_node = NULL;
1071 snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node);
1072 /* enable getnext traversal on filled table */
1073 iftable.maxlength = 1;
1076 void snmp_dec_iflist(void)
1078 snmp_mib_node_delete(&iflist_root, iflist_root.tail);
1079 /* disable getnext traversal on empty table */
1080 if(iflist_root.count == 0) iftable.maxlength = 0;
1084 * Inserts ARP table indexes (.xIfIndex.xNetAddress)
1085 * into arp table index trees (both atTable and ipNetToMediaTable).
1087 void snmp_insert_arpidx_tree(struct netif *ni, ip_addr_t *ip)
1089 struct mib_list_rootnode *at_rn;
1090 struct mib_list_node *at_node;
1094 LWIP_ASSERT("ni != NULL", ni != NULL);
1095 snmp_netiftoifindex(ni, &arpidx[0]);
1096 snmp_iptooid(ip, &arpidx[1]);
1098 for (tree = 0; tree < 2; tree++)
1102 at_rn = &arptree_root;
1106 at_rn = &ipntomtree_root;
1108 for (level = 0; level < 5; level++)
1111 snmp_mib_node_insert(at_rn, arpidx[level], &at_node);
1112 if ((level != 4) && (at_node != NULL))
1114 if (at_node->nptr == NULL)
1116 at_rn = snmp_mib_lrn_alloc();
1117 at_node->nptr = (struct mib_node*)at_rn;
1124 at_rn->get_object_def = atentry_get_object_def;
1125 at_rn->get_value = atentry_get_value;
1129 at_rn->get_object_def = ip_ntomentry_get_object_def;
1130 at_rn->get_value = ip_ntomentry_get_value;
1132 at_rn->set_test = noleafs_set_test;
1133 at_rn->set_value = noleafs_set_value;
1138 /* at_rn == NULL, malloc failure */
1139 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full"));
1145 at_rn = (struct mib_list_rootnode*)at_node->nptr;
1150 /* enable getnext traversal on filled tables */
1152 ipntomtable.maxlength = 1;
1156 * Removes ARP table indexes (.xIfIndex.xNetAddress)
1157 * from arp table index trees.
1159 void snmp_delete_arpidx_tree(struct netif *ni, ip_addr_t *ip)
1161 struct mib_list_rootnode *at_rn, *next, *del_rn[5];
1162 struct mib_list_node *at_n, *del_n[5];
1164 u8_t fc, tree, level, del_cnt;
1166 snmp_netiftoifindex(ni, &arpidx[0]);
1167 snmp_iptooid(ip, &arpidx[1]);
1169 for (tree = 0; tree < 2; tree++)
1171 /* mark nodes for deletion */
1174 at_rn = &arptree_root;
1178 at_rn = &ipntomtree_root;
1182 while ((level < 5) && (at_rn != NULL))
1184 fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n);
1187 /* arpidx[level] does not exist */
1193 del_rn[del_cnt] = at_rn;
1194 del_n[del_cnt] = at_n;
1196 at_rn = (struct mib_list_rootnode*)(at_n->nptr);
1200 /* reset delete (2 or more childs) */
1202 at_rn = (struct mib_list_rootnode*)(at_n->nptr);
1206 /* delete marked index nodes */
1211 at_rn = del_rn[del_cnt];
1212 at_n = del_n[del_cnt];
1214 next = snmp_mib_node_delete(at_rn, at_n);
1217 LWIP_ASSERT("next_count == 0",next->count == 0);
1218 snmp_mib_lrn_free(next);
1222 /* disable getnext traversal on empty tables */
1223 if(arptree_root.count == 0) at.maxlength = 0;
1224 if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0;
1227 void snmp_inc_ipinreceives(void)
1232 void snmp_inc_ipinhdrerrors(void)
1237 void snmp_inc_ipinaddrerrors(void)
1242 void snmp_inc_ipforwdatagrams(void)
1247 void snmp_inc_ipinunknownprotos(void)
1249 ipinunknownprotos++;
1252 void snmp_inc_ipindiscards(void)
1257 void snmp_inc_ipindelivers(void)
1262 void snmp_inc_ipoutrequests(void)
1267 void snmp_inc_ipoutdiscards(void)
1272 void snmp_inc_ipoutnoroutes(void)
1277 void snmp_inc_ipreasmreqds(void)
1282 void snmp_inc_ipreasmoks(void)
1287 void snmp_inc_ipreasmfails(void)
1292 void snmp_inc_ipfragoks(void)
1297 void snmp_inc_ipfragfails(void)
1302 void snmp_inc_ipfragcreates(void)
1307 void snmp_inc_iproutingdiscards(void)
1309 iproutingdiscards++;
1313 * Inserts ipAddrTable indexes (.ipAdEntAddr)
1316 void snmp_insert_ipaddridx_tree(struct netif *ni)
1318 struct mib_list_rootnode *ipa_rn;
1319 struct mib_list_node *ipa_node;
1323 LWIP_ASSERT("ni != NULL", ni != NULL);
1324 snmp_iptooid(&ni->ip_addr, &ipaddridx[0]);
1327 ipa_rn = &ipaddrtree_root;
1331 snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node);
1332 if ((level != 3) && (ipa_node != NULL))
1334 if (ipa_node->nptr == NULL)
1336 ipa_rn = snmp_mib_lrn_alloc();
1337 ipa_node->nptr = (struct mib_node*)ipa_rn;
1342 ipa_rn->get_object_def = ip_addrentry_get_object_def;
1343 ipa_rn->get_value = ip_addrentry_get_value;
1344 ipa_rn->set_test = noleafs_set_test;
1345 ipa_rn->set_value = noleafs_set_value;
1350 /* ipa_rn == NULL, malloc failure */
1351 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full"));
1357 ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr;
1362 /* enable getnext traversal on filled table */
1363 ipaddrtable.maxlength = 1;
1367 * Removes ipAddrTable indexes (.ipAdEntAddr)
1370 void snmp_delete_ipaddridx_tree(struct netif *ni)
1372 struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];
1373 struct mib_list_node *ipa_n, *del_n[4];
1375 u8_t fc, level, del_cnt;
1377 LWIP_ASSERT("ni != NULL", ni != NULL);
1378 snmp_iptooid(&ni->ip_addr, &ipaddridx[0]);
1380 /* mark nodes for deletion */
1383 ipa_rn = &ipaddrtree_root;
1384 while ((level < 4) && (ipa_rn != NULL))
1386 fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n);
1389 /* ipaddridx[level] does not exist */
1395 del_rn[del_cnt] = ipa_rn;
1396 del_n[del_cnt] = ipa_n;
1398 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
1402 /* reset delete (2 or more childs) */
1404 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
1408 /* delete marked index nodes */
1413 ipa_rn = del_rn[del_cnt];
1414 ipa_n = del_n[del_cnt];
1416 next = snmp_mib_node_delete(ipa_rn, ipa_n);
1419 LWIP_ASSERT("next_count == 0",next->count == 0);
1420 snmp_mib_lrn_free(next);
1423 /* disable getnext traversal on empty table */
1424 if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0;
1428 * Inserts ipRouteTable indexes (.ipRouteDest)
1431 * @param dflt non-zero for the default rte, zero for network rte
1432 * @param ni points to network interface for this rte
1434 * @todo record sysuptime for _this_ route when it is installed
1435 * (needed for ipRouteAge) in the netif.
1437 void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
1444 /* the default route 0.0.0.0 */
1445 ip_addr_set_any(&dst);
1450 /* route to the network address */
1451 ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
1452 /* exclude 0.0.0.0 network (reserved for default rte) */
1453 if (!ip_addr_isany(&dst)) {
1459 struct mib_list_rootnode *iprte_rn;
1460 struct mib_list_node *iprte_node;
1464 snmp_iptooid(&dst, &iprteidx[0]);
1466 iprte_rn = &iprtetree_root;
1470 snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node);
1471 if ((level != 3) && (iprte_node != NULL))
1473 if (iprte_node->nptr == NULL)
1475 iprte_rn = snmp_mib_lrn_alloc();
1476 iprte_node->nptr = (struct mib_node*)iprte_rn;
1477 if (iprte_rn != NULL)
1481 iprte_rn->get_object_def = ip_rteentry_get_object_def;
1482 iprte_rn->get_value = ip_rteentry_get_value;
1483 iprte_rn->set_test = noleafs_set_test;
1484 iprte_rn->set_value = noleafs_set_value;
1489 /* iprte_rn == NULL, malloc failure */
1490 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full"));
1496 iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr;
1502 /* enable getnext traversal on filled table */
1503 iprtetable.maxlength = 1;
1507 * Removes ipRouteTable indexes (.ipRouteDest)
1510 * @param dflt non-zero for the default rte, zero for network rte
1511 * @param ni points to network interface for this rte or NULL
1512 * for default route to be removed.
1514 void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
1521 /* the default route 0.0.0.0 */
1522 ip_addr_set_any(&dst);
1527 /* route to the network address */
1528 ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
1529 /* exclude 0.0.0.0 network (reserved for default rte) */
1530 if (!ip_addr_isany(&dst)) {
1536 struct mib_list_rootnode *iprte_rn, *next, *del_rn[4];
1537 struct mib_list_node *iprte_n, *del_n[4];
1539 u8_t fc, level, del_cnt;
1541 snmp_iptooid(&dst, &iprteidx[0]);
1542 /* mark nodes for deletion */
1545 iprte_rn = &iprtetree_root;
1546 while ((level < 4) && (iprte_rn != NULL))
1548 fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n);
1551 /* iprteidx[level] does not exist */
1557 del_rn[del_cnt] = iprte_rn;
1558 del_n[del_cnt] = iprte_n;
1560 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
1564 /* reset delete (2 or more childs) */
1566 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
1570 /* delete marked index nodes */
1575 iprte_rn = del_rn[del_cnt];
1576 iprte_n = del_n[del_cnt];
1578 next = snmp_mib_node_delete(iprte_rn, iprte_n);
1581 LWIP_ASSERT("next_count == 0",next->count == 0);
1582 snmp_mib_lrn_free(next);
1586 /* disable getnext traversal on empty table */
1587 if (iprtetree_root.count == 0) iprtetable.maxlength = 0;
1591 void snmp_inc_icmpinmsgs(void)
1596 void snmp_inc_icmpinerrors(void)
1601 void snmp_inc_icmpindestunreachs(void)
1603 icmpindestunreachs++;
1606 void snmp_inc_icmpintimeexcds(void)
1611 void snmp_inc_icmpinparmprobs(void)
1616 void snmp_inc_icmpinsrcquenchs(void)
1621 void snmp_inc_icmpinredirects(void)
1626 void snmp_inc_icmpinechos(void)
1631 void snmp_inc_icmpinechoreps(void)
1636 void snmp_inc_icmpintimestamps(void)
1641 void snmp_inc_icmpintimestampreps(void)
1643 icmpintimestampreps++;
1646 void snmp_inc_icmpinaddrmasks(void)
1651 void snmp_inc_icmpinaddrmaskreps(void)
1653 icmpinaddrmaskreps++;
1656 void snmp_inc_icmpoutmsgs(void)
1661 void snmp_inc_icmpouterrors(void)
1666 void snmp_inc_icmpoutdestunreachs(void)
1668 icmpoutdestunreachs++;
1671 void snmp_inc_icmpouttimeexcds(void)
1676 void snmp_inc_icmpoutparmprobs(void)
1681 void snmp_inc_icmpoutsrcquenchs(void)
1683 icmpoutsrcquenchs++;
1686 void snmp_inc_icmpoutredirects(void)
1691 void snmp_inc_icmpoutechos(void)
1696 void snmp_inc_icmpoutechoreps(void)
1701 void snmp_inc_icmpouttimestamps(void)
1703 icmpouttimestamps++;
1706 void snmp_inc_icmpouttimestampreps(void)
1708 icmpouttimestampreps++;
1711 void snmp_inc_icmpoutaddrmasks(void)
1716 void snmp_inc_icmpoutaddrmaskreps(void)
1718 icmpoutaddrmaskreps++;
1721 void snmp_inc_tcpactiveopens(void)
1726 void snmp_inc_tcppassiveopens(void)
1731 void snmp_inc_tcpattemptfails(void)
1736 void snmp_inc_tcpestabresets(void)
1741 void snmp_inc_tcpinsegs(void)
1746 void snmp_inc_tcpoutsegs(void)
1751 void snmp_inc_tcpretranssegs(void)
1756 void snmp_inc_tcpinerrs(void)
1761 void snmp_inc_tcpoutrsts(void)
1766 void snmp_inc_udpindatagrams(void)
1771 void snmp_inc_udpnoports(void)
1776 void snmp_inc_udpinerrors(void)
1781 void snmp_inc_udpoutdatagrams(void)
1787 * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort)
1790 void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
1792 struct mib_list_rootnode *udp_rn;
1793 struct mib_list_node *udp_node;
1797 LWIP_ASSERT("pcb != NULL", pcb != NULL);
1798 snmp_iptooid(&pcb->local_ip, &udpidx[0]);
1799 udpidx[4] = pcb->local_port;
1802 for (level = 0; level < 5; level++)
1805 snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node);
1806 if ((level != 4) && (udp_node != NULL))
1808 if (udp_node->nptr == NULL)
1810 udp_rn = snmp_mib_lrn_alloc();
1811 udp_node->nptr = (struct mib_node*)udp_rn;
1816 udp_rn->get_object_def = udpentry_get_object_def;
1817 udp_rn->get_value = udpentry_get_value;
1818 udp_rn->set_test = noleafs_set_test;
1819 udp_rn->set_value = noleafs_set_value;
1824 /* udp_rn == NULL, malloc failure */
1825 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full"));
1831 udp_rn = (struct mib_list_rootnode*)udp_node->nptr;
1835 udptable.maxlength = 1;
1839 * Removes udpTable indexes (.udpLocalAddress.udpLocalPort)
1842 void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
1844 struct udp_pcb *npcb;
1845 struct mib_list_rootnode *udp_rn, *next, *del_rn[5];
1846 struct mib_list_node *udp_n, *del_n[5];
1848 u8_t bindings, fc, level, del_cnt;
1850 LWIP_ASSERT("pcb != NULL", pcb != NULL);
1851 snmp_iptooid(&pcb->local_ip, &udpidx[0]);
1852 udpidx[4] = pcb->local_port;
1854 /* count PCBs for a given binding
1855 (e.g. when reusing ports or for temp output PCBs) */
1858 while ((npcb != NULL))
1860 if (ip_addr_cmp(&npcb->local_ip, &pcb->local_ip) &&
1861 (npcb->local_port == udpidx[4]))
1869 /* selectively remove */
1870 /* mark nodes for deletion */
1874 while ((level < 5) && (udp_rn != NULL))
1876 fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n);
1879 /* udpidx[level] does not exist */
1885 del_rn[del_cnt] = udp_rn;
1886 del_n[del_cnt] = udp_n;
1888 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
1892 /* reset delete (2 or more childs) */
1894 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
1898 /* delete marked index nodes */
1903 udp_rn = del_rn[del_cnt];
1904 udp_n = del_n[del_cnt];
1906 next = snmp_mib_node_delete(udp_rn, udp_n);
1909 LWIP_ASSERT("next_count == 0",next->count == 0);
1910 snmp_mib_lrn_free(next);
1914 /* disable getnext traversal on empty table */
1915 if (udp_root.count == 0) udptable.maxlength = 0;
1919 void snmp_inc_snmpinpkts(void)
1924 void snmp_inc_snmpoutpkts(void)
1929 void snmp_inc_snmpinbadversions(void)
1931 snmpinbadversions++;
1934 void snmp_inc_snmpinbadcommunitynames(void)
1936 snmpinbadcommunitynames++;
1939 void snmp_inc_snmpinbadcommunityuses(void)
1941 snmpinbadcommunityuses++;
1944 void snmp_inc_snmpinasnparseerrs(void)
1946 snmpinasnparseerrs++;
1949 void snmp_inc_snmpintoobigs(void)
1954 void snmp_inc_snmpinnosuchnames(void)
1956 snmpinnosuchnames++;
1959 void snmp_inc_snmpinbadvalues(void)
1964 void snmp_inc_snmpinreadonlys(void)
1969 void snmp_inc_snmpingenerrs(void)
1974 void snmp_add_snmpintotalreqvars(u8_t value)
1976 snmpintotalreqvars += value;
1979 void snmp_add_snmpintotalsetvars(u8_t value)
1981 snmpintotalsetvars += value;
1984 void snmp_inc_snmpingetrequests(void)
1986 snmpingetrequests++;
1989 void snmp_inc_snmpingetnexts(void)
1994 void snmp_inc_snmpinsetrequests(void)
1996 snmpinsetrequests++;
1999 void snmp_inc_snmpingetresponses(void)
2001 snmpingetresponses++;
2004 void snmp_inc_snmpintraps(void)
2009 void snmp_inc_snmpouttoobigs(void)
2014 void snmp_inc_snmpoutnosuchnames(void)
2016 snmpoutnosuchnames++;
2019 void snmp_inc_snmpoutbadvalues(void)
2024 void snmp_inc_snmpoutgenerrs(void)
2029 void snmp_inc_snmpoutgetrequests(void)
2031 snmpoutgetrequests++;
2034 void snmp_inc_snmpoutgetnexts(void)
2039 void snmp_inc_snmpoutsetrequests(void)
2041 snmpoutsetrequests++;
2044 void snmp_inc_snmpoutgetresponses(void)
2046 snmpoutgetresponses++;
2049 void snmp_inc_snmpouttraps(void)
2054 void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)
2059 void snmp_set_snmpenableauthentraps(u8_t *value)
2063 snmpenableauthentraps_ptr = value;
2067 void snmp_get_snmpenableauthentraps(u8_t *value)
2069 *value = *snmpenableauthentraps_ptr;
2073 noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2075 LWIP_UNUSED_ARG(ident_len);
2076 LWIP_UNUSED_ARG(ident);
2077 od->instance = MIB_OBJECT_NONE;
2081 noleafs_get_value(struct obj_def *od, u16_t len, void *value)
2083 LWIP_UNUSED_ARG(od);
2084 LWIP_UNUSED_ARG(len);
2085 LWIP_UNUSED_ARG(value);
2089 noleafs_set_test(struct obj_def *od, u16_t len, void *value)
2091 LWIP_UNUSED_ARG(od);
2092 LWIP_UNUSED_ARG(len);
2093 LWIP_UNUSED_ARG(value);
2099 noleafs_set_value(struct obj_def *od, u16_t len, void *value)
2101 LWIP_UNUSED_ARG(od);
2102 LWIP_UNUSED_ARG(len);
2103 LWIP_UNUSED_ARG(value);
2108 * Returns systems object definitions.
2110 * @param ident_len the address length (2)
2111 * @param ident points to objectname.0 (object id trailer)
2112 * @param od points to object definition.
2115 system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2119 /* return to object name, adding index depth (1) */
2124 od->id_inst_len = ident_len;
2125 od->id_inst_ptr = ident;
2127 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
2128 id = (u8_t)ident[0];
2129 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id));
2132 case 1: /* sysDescr */
2133 od->instance = MIB_OBJECT_SCALAR;
2134 od->access = MIB_OBJECT_READ_ONLY;
2135 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2136 od->v_len = *sysdescr_len_ptr;
2138 case 2: /* sysObjectID */
2139 od->instance = MIB_OBJECT_SCALAR;
2140 od->access = MIB_OBJECT_READ_ONLY;
2141 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
2142 od->v_len = sysobjid.len * sizeof(s32_t);
2144 case 3: /* sysUpTime */
2145 od->instance = MIB_OBJECT_SCALAR;
2146 od->access = MIB_OBJECT_READ_ONLY;
2147 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
2148 od->v_len = sizeof(u32_t);
2150 case 4: /* sysContact */
2151 od->instance = MIB_OBJECT_SCALAR;
2152 od->access = MIB_OBJECT_READ_WRITE;
2153 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2154 od->v_len = *syscontact_len_ptr;
2156 case 5: /* sysName */
2157 od->instance = MIB_OBJECT_SCALAR;
2158 od->access = MIB_OBJECT_READ_WRITE;
2159 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2160 od->v_len = *sysname_len_ptr;
2162 case 6: /* sysLocation */
2163 od->instance = MIB_OBJECT_SCALAR;
2164 od->access = MIB_OBJECT_READ_WRITE;
2165 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2166 od->v_len = *syslocation_len_ptr;
2168 case 7: /* sysServices */
2169 od->instance = MIB_OBJECT_SCALAR;
2170 od->access = MIB_OBJECT_READ_ONLY;
2171 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2172 od->v_len = sizeof(s32_t);
2175 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n"));
2176 od->instance = MIB_OBJECT_NONE;
2182 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n"));
2183 od->instance = MIB_OBJECT_NONE;
2188 * Returns system object value.
2190 * @param ident_len the address length (2)
2191 * @param ident points to objectname.0 (object id trailer)
2192 * @param len return value space (in bytes)
2193 * @param value points to (varbind) space to copy value into.
2196 system_get_value(struct obj_def *od, u16_t len, void *value)
2200 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2201 id = (u8_t)od->id_inst_ptr[0];
2204 case 1: /* sysDescr */
2205 ocstrncpy((u8_t*)value, sysdescr_ptr, len);
2207 case 2: /* sysObjectID */
2208 objectidncpy((s32_t*)value, (s32_t*)sysobjid.id, (u8_t)(len / sizeof(s32_t)));
2210 case 3: /* sysUpTime */
2212 snmp_get_sysuptime((u32_t*)value);
2215 case 4: /* sysContact */
2216 ocstrncpy((u8_t*)value, syscontact_ptr, len);
2218 case 5: /* sysName */
2219 ocstrncpy((u8_t*)value, sysname_ptr, len);
2221 case 6: /* sysLocation */
2222 ocstrncpy((u8_t*)value, syslocation_ptr, len);
2224 case 7: /* sysServices */
2226 s32_t *sint_ptr = (s32_t*)value;
2227 *sint_ptr = sysservices;
2234 system_set_test(struct obj_def *od, u16_t len, void *value)
2238 LWIP_UNUSED_ARG(value);
2240 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2241 id = (u8_t)od->id_inst_ptr[0];
2244 case 4: /* sysContact */
2245 if ((syscontact_ptr != syscontact_default) &&
2251 case 5: /* sysName */
2252 if ((sysname_ptr != sysname_default) &&
2258 case 6: /* sysLocation */
2259 if ((syslocation_ptr != syslocation_default) &&
2270 system_set_value(struct obj_def *od, u16_t len, void *value)
2274 LWIP_ASSERT("invalid len", len <= 0xff);
2275 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2276 id = (u8_t)od->id_inst_ptr[0];
2279 case 4: /* sysContact */
2280 ocstrncpy(syscontact_ptr, (u8_t*)value, len);
2281 *syscontact_len_ptr = (u8_t)len;
2283 case 5: /* sysName */
2284 ocstrncpy(sysname_ptr, (u8_t*)value, len);
2285 *sysname_len_ptr = (u8_t)len;
2287 case 6: /* sysLocation */
2288 ocstrncpy(syslocation_ptr, (u8_t*)value, len);
2289 *syslocation_len_ptr = (u8_t)len;
2295 * Returns interfaces.ifnumber object definition.
2297 * @param ident_len the address length (2)
2298 * @param ident points to objectname.index
2299 * @param od points to object definition.
2302 interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2304 /* return to object name, adding index depth (1) */
2309 od->id_inst_len = ident_len;
2310 od->id_inst_ptr = ident;
2312 od->instance = MIB_OBJECT_SCALAR;
2313 od->access = MIB_OBJECT_READ_ONLY;
2314 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2315 od->v_len = sizeof(s32_t);
2319 LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n"));
2320 od->instance = MIB_OBJECT_NONE;
2325 * Returns interfaces.ifnumber object value.
2327 * @param ident_len the address length (2)
2328 * @param ident points to objectname.0 (object id trailer)
2329 * @param len return value space (in bytes)
2330 * @param value points to (varbind) space to copy value into.
2333 interfaces_get_value(struct obj_def *od, u16_t len, void *value)
2335 LWIP_UNUSED_ARG(len);
2336 if (od->id_inst_ptr[0] == 1)
2338 s32_t *sint_ptr = (s32_t*)value;
2339 *sint_ptr = iflist_root.count;
2344 * Returns ifentry object definitions.
2346 * @param ident_len the address length (2)
2347 * @param ident points to objectname.index
2348 * @param od points to object definition.
2351 ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2355 /* return to object name, adding index depth (1) */
2360 od->id_inst_len = ident_len;
2361 od->id_inst_ptr = ident;
2363 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
2364 id = (u8_t)ident[0];
2365 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id));
2368 case 1: /* ifIndex */
2369 case 3: /* ifType */
2371 case 8: /* ifOperStatus */
2372 od->instance = MIB_OBJECT_TAB;
2373 od->access = MIB_OBJECT_READ_ONLY;
2374 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2375 od->v_len = sizeof(s32_t);
2377 case 2: /* ifDescr */
2378 od->instance = MIB_OBJECT_TAB;
2379 od->access = MIB_OBJECT_READ_ONLY;
2380 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2381 /** @todo this should be some sort of sizeof(struct netif.name) */
2384 case 5: /* ifSpeed */
2385 case 21: /* ifOutQLen */
2386 od->instance = MIB_OBJECT_TAB;
2387 od->access = MIB_OBJECT_READ_ONLY;
2388 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
2389 od->v_len = sizeof(u32_t);
2391 case 6: /* ifPhysAddress */
2393 struct netif *netif;
2395 snmp_ifindextonetif(ident[1], &netif);
2396 od->instance = MIB_OBJECT_TAB;
2397 od->access = MIB_OBJECT_READ_ONLY;
2398 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2399 od->v_len = netif->hwaddr_len;
2402 case 7: /* ifAdminStatus */
2403 od->instance = MIB_OBJECT_TAB;
2404 od->access = MIB_OBJECT_READ_WRITE;
2405 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2406 od->v_len = sizeof(s32_t);
2408 case 9: /* ifLastChange */
2409 od->instance = MIB_OBJECT_TAB;
2410 od->access = MIB_OBJECT_READ_ONLY;
2411 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
2412 od->v_len = sizeof(u32_t);
2414 case 10: /* ifInOctets */
2415 case 11: /* ifInUcastPkts */
2416 case 12: /* ifInNUcastPkts */
2417 case 13: /* ifInDiscarts */
2418 case 14: /* ifInErrors */
2419 case 15: /* ifInUnkownProtos */
2420 case 16: /* ifOutOctets */
2421 case 17: /* ifOutUcastPkts */
2422 case 18: /* ifOutNUcastPkts */
2423 case 19: /* ifOutDiscarts */
2424 case 20: /* ifOutErrors */
2425 od->instance = MIB_OBJECT_TAB;
2426 od->access = MIB_OBJECT_READ_ONLY;
2427 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
2428 od->v_len = sizeof(u32_t);
2430 case 22: /* ifSpecific */
2431 /** @note returning zeroDotZero (0.0) no media specific MIB support */
2432 od->instance = MIB_OBJECT_TAB;
2433 od->access = MIB_OBJECT_READ_ONLY;
2434 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
2435 od->v_len = ifspecific.len * sizeof(s32_t);
2438 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n"));
2439 od->instance = MIB_OBJECT_NONE;
2445 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n"));
2446 od->instance = MIB_OBJECT_NONE;
2451 * Returns ifentry object value.
2453 * @param ident_len the address length (2)
2454 * @param ident points to objectname.0 (object id trailer)
2455 * @param len return value space (in bytes)
2456 * @param value points to (varbind) space to copy value into.
2459 ifentry_get_value(struct obj_def *od, u16_t len, void *value)
2461 struct netif *netif;
2464 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2465 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2466 id = (u8_t)od->id_inst_ptr[0];
2469 case 1: /* ifIndex */
2471 s32_t *sint_ptr = (s32_t*)value;
2472 *sint_ptr = od->id_inst_ptr[1];
2475 case 2: /* ifDescr */
2476 ocstrncpy((u8_t*)value, (u8_t*)netif->name, len);
2478 case 3: /* ifType */
2480 s32_t *sint_ptr = (s32_t*)value;
2481 *sint_ptr = netif->link_type;
2486 s32_t *sint_ptr = (s32_t*)value;
2487 *sint_ptr = netif->mtu;
2490 case 5: /* ifSpeed */
2492 u32_t *uint_ptr = (u32_t*)value;
2493 *uint_ptr = netif->link_speed;
2496 case 6: /* ifPhysAddress */
2497 ocstrncpy((u8_t*)value, netif->hwaddr, len);
2499 case 7: /* ifAdminStatus */
2501 s32_t *sint_ptr = (s32_t*)value;
2502 if (netif_is_up(netif))
2504 if (netif_is_link_up(netif))
2506 *sint_ptr = 1; /* up */
2510 *sint_ptr = 7; /* lowerLayerDown */
2515 *sint_ptr = 2; /* down */
2519 case 8: /* ifOperStatus */
2521 s32_t *sint_ptr = (s32_t*)value;
2522 if (netif_is_up(netif))
2532 case 9: /* ifLastChange */
2534 u32_t *uint_ptr = (u32_t*)value;
2535 *uint_ptr = netif->ts;
2538 case 10: /* ifInOctets */
2540 u32_t *uint_ptr = (u32_t*)value;
2541 *uint_ptr = netif->ifinoctets;
2544 case 11: /* ifInUcastPkts */
2546 u32_t *uint_ptr = (u32_t*)value;
2547 *uint_ptr = netif->ifinucastpkts;
2550 case 12: /* ifInNUcastPkts */
2552 u32_t *uint_ptr = (u32_t*)value;
2553 *uint_ptr = netif->ifinnucastpkts;
2556 case 13: /* ifInDiscarts */
2558 u32_t *uint_ptr = (u32_t*)value;
2559 *uint_ptr = netif->ifindiscards;
2562 case 14: /* ifInErrors */
2563 case 15: /* ifInUnkownProtos */
2564 /** @todo add these counters! */
2566 u32_t *uint_ptr = (u32_t*)value;
2570 case 16: /* ifOutOctets */
2572 u32_t *uint_ptr = (u32_t*)value;
2573 *uint_ptr = netif->ifoutoctets;
2576 case 17: /* ifOutUcastPkts */
2578 u32_t *uint_ptr = (u32_t*)value;
2579 *uint_ptr = netif->ifoutucastpkts;
2582 case 18: /* ifOutNUcastPkts */
2584 u32_t *uint_ptr = (u32_t*)value;
2585 *uint_ptr = netif->ifoutnucastpkts;
2588 case 19: /* ifOutDiscarts */
2590 u32_t *uint_ptr = (u32_t*)value;
2591 *uint_ptr = netif->ifoutdiscards;
2594 case 20: /* ifOutErrors */
2595 /** @todo add this counter! */
2597 u32_t *uint_ptr = (u32_t*)value;
2601 case 21: /* ifOutQLen */
2602 /** @todo figure out if this must be 0 (no queue) or 1? */
2604 u32_t *uint_ptr = (u32_t*)value;
2608 case 22: /* ifSpecific */
2609 objectidncpy((s32_t*)value, (s32_t*)ifspecific.id, (u8_t)(len / sizeof(s32_t)));
2614 #if !SNMP_SAFE_REQUESTS
2616 ifentry_set_test(struct obj_def *od, u16_t len, void *value)
2618 struct netif *netif;
2620 LWIP_UNUSED_ARG(len);
2623 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2624 id = (u8_t)od->id_inst_ptr[0];
2627 case 7: /* ifAdminStatus */
2629 s32_t *sint_ptr = (s32_t*)value;
2630 if (*sint_ptr == 1 || *sint_ptr == 2)
2639 ifentry_set_value(struct obj_def *od, u16_t len, void *value)
2641 struct netif *netif;
2643 LWIP_UNUSED_ARG(len);
2645 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2646 id = (u8_t)od->id_inst_ptr[0];
2649 case 7: /* ifAdminStatus */
2651 s32_t *sint_ptr = (s32_t*)value;
2654 netif_set_up(netif);
2656 else if (*sint_ptr == 2)
2658 netif_set_down(netif);
2664 #endif /* SNMP_SAFE_REQUESTS */
2667 * Returns atentry object definitions.
2669 * @param ident_len the address length (6)
2670 * @param ident points to objectname.atifindex.atnetaddress
2671 * @param od points to object definition.
2674 atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2676 /* return to object name, adding index depth (5) */
2682 od->id_inst_len = ident_len;
2683 od->id_inst_ptr = ident;
2687 case 1: /* atIfIndex */
2688 od->instance = MIB_OBJECT_TAB;
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);
2693 case 2: /* atPhysAddress */
2694 od->instance = MIB_OBJECT_TAB;
2695 od->access = MIB_OBJECT_READ_WRITE;
2696 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2697 od->v_len = 6; /** @todo try to use netif::hwaddr_len */
2699 case 3: /* atNetAddress */
2700 od->instance = MIB_OBJECT_TAB;
2701 od->access = MIB_OBJECT_READ_WRITE;
2702 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
2706 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n"));
2707 od->instance = MIB_OBJECT_NONE;
2713 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n"));
2714 od->instance = MIB_OBJECT_NONE;
2719 atentry_get_value(struct obj_def *od, u16_t len, void *value)
2723 struct eth_addr* ethaddr_ret;
2724 ip_addr_t* ipaddr_ret;
2725 #endif /* LWIP_ARP */
2727 struct netif *netif;
2729 LWIP_UNUSED_ARG(len);
2730 LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
2732 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2733 snmp_oidtoip(&od->id_inst_ptr[2], &ip);
2735 #if LWIP_ARP /** @todo implement a netif_find_addr */
2736 if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
2738 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2739 id = (u8_t)od->id_inst_ptr[0];
2742 case 1: /* atIfIndex */
2744 s32_t *sint_ptr = (s32_t*)value;
2745 *sint_ptr = od->id_inst_ptr[1];
2748 case 2: /* atPhysAddress */
2750 struct eth_addr *dst = (struct eth_addr*)value;
2752 *dst = *ethaddr_ret;
2755 case 3: /* atNetAddress */
2757 ip_addr_t *dst = (ip_addr_t*)value;
2764 #endif /* LWIP_ARP */
2768 ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2772 /* return to object name, adding index depth (1) */
2777 od->id_inst_len = ident_len;
2778 od->id_inst_ptr = ident;
2780 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
2781 id = (u8_t)ident[0];
2782 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id));
2785 case 1: /* ipForwarding */
2786 case 2: /* ipDefaultTTL */
2787 od->instance = MIB_OBJECT_SCALAR;
2788 od->access = MIB_OBJECT_READ_WRITE;
2789 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2790 od->v_len = sizeof(s32_t);
2792 case 3: /* ipInReceives */
2793 case 4: /* ipInHdrErrors */
2794 case 5: /* ipInAddrErrors */
2795 case 6: /* ipForwDatagrams */
2796 case 7: /* ipInUnknownProtos */
2797 case 8: /* ipInDiscards */
2798 case 9: /* ipInDelivers */
2799 case 10: /* ipOutRequests */
2800 case 11: /* ipOutDiscards */
2801 case 12: /* ipOutNoRoutes */
2802 case 14: /* ipReasmReqds */
2803 case 15: /* ipReasmOKs */
2804 case 16: /* ipReasmFails */
2805 case 17: /* ipFragOKs */
2806 case 18: /* ipFragFails */
2807 case 19: /* ipFragCreates */
2808 case 23: /* ipRoutingDiscards */
2809 od->instance = MIB_OBJECT_SCALAR;
2810 od->access = MIB_OBJECT_READ_ONLY;
2811 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
2812 od->v_len = sizeof(u32_t);
2814 case 13: /* ipReasmTimeout */
2815 od->instance = MIB_OBJECT_SCALAR;
2816 od->access = MIB_OBJECT_READ_ONLY;
2817 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2818 od->v_len = sizeof(s32_t);
2821 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n"));
2822 od->instance = MIB_OBJECT_NONE;
2828 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n"));
2829 od->instance = MIB_OBJECT_NONE;
2834 ip_get_value(struct obj_def *od, u16_t len, void *value)
2838 LWIP_UNUSED_ARG(len);
2839 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2840 id = (u8_t)od->id_inst_ptr[0];
2843 case 1: /* ipForwarding */
2845 s32_t *sint_ptr = (s32_t*)value;
2850 /* not-forwarding */
2855 case 2: /* ipDefaultTTL */
2857 s32_t *sint_ptr = (s32_t*)value;
2858 *sint_ptr = IP_DEFAULT_TTL;
2861 case 3: /* ipInReceives */
2863 u32_t *uint_ptr = (u32_t*)value;
2864 *uint_ptr = ipinreceives;
2867 case 4: /* ipInHdrErrors */
2869 u32_t *uint_ptr = (u32_t*)value;
2870 *uint_ptr = ipinhdrerrors;
2873 case 5: /* ipInAddrErrors */
2875 u32_t *uint_ptr = (u32_t*)value;
2876 *uint_ptr = ipinaddrerrors;
2879 case 6: /* ipForwDatagrams */
2881 u32_t *uint_ptr = (u32_t*)value;
2882 *uint_ptr = ipforwdatagrams;
2885 case 7: /* ipInUnknownProtos */
2887 u32_t *uint_ptr = (u32_t*)value;
2888 *uint_ptr = ipinunknownprotos;
2891 case 8: /* ipInDiscards */
2893 u32_t *uint_ptr = (u32_t*)value;
2894 *uint_ptr = ipindiscards;
2897 case 9: /* ipInDelivers */
2899 u32_t *uint_ptr = (u32_t*)value;
2900 *uint_ptr = ipindelivers;
2903 case 10: /* ipOutRequests */
2905 u32_t *uint_ptr = (u32_t*)value;
2906 *uint_ptr = ipoutrequests;
2909 case 11: /* ipOutDiscards */
2911 u32_t *uint_ptr = (u32_t*)value;
2912 *uint_ptr = ipoutdiscards;
2915 case 12: /* ipOutNoRoutes */
2917 u32_t *uint_ptr = (u32_t*)value;
2918 *uint_ptr = ipoutnoroutes;
2921 case 13: /* ipReasmTimeout */
2923 s32_t *sint_ptr = (s32_t*)value;
2925 *sint_ptr = IP_REASS_MAXAGE;
2931 case 14: /* ipReasmReqds */
2933 u32_t *uint_ptr = (u32_t*)value;
2934 *uint_ptr = ipreasmreqds;
2937 case 15: /* ipReasmOKs */
2939 u32_t *uint_ptr = (u32_t*)value;
2940 *uint_ptr = ipreasmoks;
2943 case 16: /* ipReasmFails */
2945 u32_t *uint_ptr = (u32_t*)value;
2946 *uint_ptr = ipreasmfails;
2949 case 17: /* ipFragOKs */
2951 u32_t *uint_ptr = (u32_t*)value;
2952 *uint_ptr = ipfragoks;
2955 case 18: /* ipFragFails */
2957 u32_t *uint_ptr = (u32_t*)value;
2958 *uint_ptr = ipfragfails;
2961 case 19: /* ipFragCreates */
2963 u32_t *uint_ptr = (u32_t*)value;
2964 *uint_ptr = ipfragcreates;
2967 case 23: /* ipRoutingDiscards */
2968 /** @todo can lwIP discard routes at all?? hardwire this to 0?? */
2970 u32_t *uint_ptr = (u32_t*)value;
2971 *uint_ptr = iproutingdiscards;
2978 * Test ip object value before setting.
2980 * @param od is the object definition
2981 * @param len return value space (in bytes)
2982 * @param value points to (varbind) space to copy value from.
2984 * @note we allow set if the value matches the hardwired value,
2985 * otherwise return badvalue.
2988 ip_set_test(struct obj_def *od, u16_t len, void *value)
2991 s32_t *sint_ptr = (s32_t*)value;
2993 LWIP_UNUSED_ARG(len);
2995 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2996 id = (u8_t)od->id_inst_ptr[0];
2999 case 1: /* ipForwarding */
3004 /* not-forwarding */
3011 case 2: /* ipDefaultTTL */
3012 if (*sint_ptr == IP_DEFAULT_TTL)
3022 ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3024 /* return to object name, adding index depth (4) */
3032 od->id_inst_len = ident_len;
3033 od->id_inst_ptr = ident;
3035 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3036 id = (u8_t)ident[0];
3039 case 1: /* ipAdEntAddr */
3040 case 3: /* ipAdEntNetMask */
3041 od->instance = MIB_OBJECT_TAB;
3042 od->access = MIB_OBJECT_READ_ONLY;
3043 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3046 case 2: /* ipAdEntIfIndex */
3047 case 4: /* ipAdEntBcastAddr */
3048 case 5: /* ipAdEntReasmMaxSize */
3049 od->instance = MIB_OBJECT_TAB;
3050 od->access = MIB_OBJECT_READ_ONLY;
3051 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3052 od->v_len = sizeof(s32_t);
3055 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n"));
3056 od->instance = MIB_OBJECT_NONE;
3062 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n"));
3063 od->instance = MIB_OBJECT_NONE;
3068 ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
3073 struct netif *netif = netif_list;
3075 LWIP_UNUSED_ARG(len);
3076 snmp_oidtoip(&od->id_inst_ptr[1], &ip);
3078 while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
3080 netif = netif->next;
3086 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3087 id = (u8_t)od->id_inst_ptr[0];
3090 case 1: /* ipAdEntAddr */
3092 ip_addr_t *dst = (ip_addr_t*)value;
3093 *dst = netif->ip_addr;
3096 case 2: /* ipAdEntIfIndex */
3098 s32_t *sint_ptr = (s32_t*)value;
3099 *sint_ptr = ifidx + 1;
3102 case 3: /* ipAdEntNetMask */
3104 ip_addr_t *dst = (ip_addr_t*)value;
3105 *dst = netif->netmask;
3108 case 4: /* ipAdEntBcastAddr */
3110 s32_t *sint_ptr = (s32_t*)value;
3112 /* lwIP oddity, there's no broadcast
3113 address in the netif we can rely on */
3114 *sint_ptr = IPADDR_BROADCAST & 1;
3117 case 5: /* ipAdEntReasmMaxSize */
3119 s32_t *sint_ptr = (s32_t*)value;
3121 /* @todo The theoretical maximum is IP_REASS_MAX_PBUFS * size of the pbufs,
3122 * but only if receiving one fragmented packet at a time.
3123 * The current solution is to calculate for 2 simultaneous packets...
3125 *sint_ptr = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) *
3126 (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - IP_HLEN)));
3128 /** @todo returning MTU would be a bad thing and
3129 returning a wild guess like '576' isn't good either */
3140 * lwIP IP routing is currently using the network addresses in netif_list.
3141 * if no suitable network IP is found in netif_list, the default_netif is used.
3144 ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3148 /* return to object name, adding index depth (4) */
3154 od->id_inst_len = ident_len;
3155 od->id_inst_ptr = ident;
3157 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3158 id = (u8_t)ident[0];
3161 case 1: /* ipRouteDest */
3162 case 7: /* ipRouteNextHop */
3163 case 11: /* ipRouteMask */
3164 od->instance = MIB_OBJECT_TAB;
3165 od->access = MIB_OBJECT_READ_WRITE;
3166 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3169 case 2: /* ipRouteIfIndex */
3170 case 3: /* ipRouteMetric1 */
3171 case 4: /* ipRouteMetric2 */
3172 case 5: /* ipRouteMetric3 */
3173 case 6: /* ipRouteMetric4 */
3174 case 8: /* ipRouteType */
3175 case 10: /* ipRouteAge */
3176 case 12: /* ipRouteMetric5 */
3177 od->instance = MIB_OBJECT_TAB;
3178 od->access = MIB_OBJECT_READ_WRITE;
3179 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3180 od->v_len = sizeof(s32_t);
3182 case 9: /* ipRouteProto */
3183 od->instance = MIB_OBJECT_TAB;
3184 od->access = MIB_OBJECT_READ_ONLY;
3185 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3186 od->v_len = sizeof(s32_t);
3188 case 13: /* ipRouteInfo */
3189 /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */
3190 od->instance = MIB_OBJECT_TAB;
3191 od->access = MIB_OBJECT_READ_ONLY;
3192 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
3193 od->v_len = iprouteinfo.len * sizeof(s32_t);
3196 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n"));
3197 od->instance = MIB_OBJECT_NONE;
3203 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n"));
3204 od->instance = MIB_OBJECT_NONE;
3209 ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
3211 struct netif *netif;
3216 ident = od->id_inst_ptr;
3217 snmp_oidtoip(&ident[1], &dest);
3219 if (ip_addr_isany(&dest))
3221 /* ip_route() uses default netif for default route */
3222 netif = netif_default;
3226 /* not using ip_route(), need exact match! */
3228 while ((netif != NULL) &&
3229 !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
3231 netif = netif->next;
3236 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3237 id = (u8_t)ident[0];
3240 case 1: /* ipRouteDest */
3242 ip_addr_t *dst = (ip_addr_t*)value;
3244 if (ip_addr_isany(&dest))
3246 /* default rte has 0.0.0.0 dest */
3247 ip_addr_set_zero(dst);
3251 /* netifs have netaddress dest */
3252 ip_addr_get_network(dst, &netif->ip_addr, &netif->netmask);
3256 case 2: /* ipRouteIfIndex */
3258 s32_t *sint_ptr = (s32_t*)value;
3260 snmp_netiftoifindex(netif, sint_ptr);
3263 case 3: /* ipRouteMetric1 */
3265 s32_t *sint_ptr = (s32_t*)value;
3267 if (ip_addr_isany(&dest))
3269 /* default rte has metric 1 */
3274 /* other rtes have metric 0 */
3279 case 4: /* ipRouteMetric2 */
3280 case 5: /* ipRouteMetric3 */
3281 case 6: /* ipRouteMetric4 */
3282 case 12: /* ipRouteMetric5 */
3284 s32_t *sint_ptr = (s32_t*)value;
3289 case 7: /* ipRouteNextHop */
3291 ip_addr_t *dst = (ip_addr_t*)value;
3293 if (ip_addr_isany(&dest))
3295 /* default rte: gateway */
3300 /* other rtes: netif ip_addr */
3301 *dst = netif->ip_addr;
3305 case 8: /* ipRouteType */
3307 s32_t *sint_ptr = (s32_t*)value;
3309 if (ip_addr_isany(&dest))
3311 /* default rte is indirect */
3316 /* other rtes are direct */
3321 case 9: /* ipRouteProto */
3323 s32_t *sint_ptr = (s32_t*)value;
3324 /* locally defined routes */
3328 case 10: /* ipRouteAge */
3330 s32_t *sint_ptr = (s32_t*)value;
3331 /** @todo (sysuptime - timestamp last change) / 100
3332 @see snmp_insert_iprteidx_tree() */
3336 case 11: /* ipRouteMask */
3338 ip_addr_t *dst = (ip_addr_t*)value;
3340 if (ip_addr_isany(&dest))
3342 /* default rte use 0.0.0.0 mask */
3343 ip_addr_set_zero(dst);
3347 /* other rtes use netmask */
3348 *dst = netif->netmask;
3352 case 13: /* ipRouteInfo */
3353 objectidncpy((s32_t*)value, (s32_t*)iprouteinfo.id, (u8_t)(len / sizeof(s32_t)));
3360 ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3362 /* return to object name, adding index depth (5) */
3370 od->id_inst_len = ident_len;
3371 od->id_inst_ptr = ident;
3373 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3374 id = (u8_t)ident[0];
3377 case 1: /* ipNetToMediaIfIndex */
3378 case 4: /* ipNetToMediaType */
3379 od->instance = MIB_OBJECT_TAB;
3380 od->access = MIB_OBJECT_READ_WRITE;
3381 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3382 od->v_len = sizeof(s32_t);
3384 case 2: /* ipNetToMediaPhysAddress */
3385 od->instance = MIB_OBJECT_TAB;
3386 od->access = MIB_OBJECT_READ_WRITE;
3387 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
3388 od->v_len = 6; /** @todo try to use netif::hwaddr_len */
3390 case 3: /* ipNetToMediaNetAddress */
3391 od->instance = MIB_OBJECT_TAB;
3392 od->access = MIB_OBJECT_READ_WRITE;
3393 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3397 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n"));
3398 od->instance = MIB_OBJECT_NONE;
3404 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n"));
3405 od->instance = MIB_OBJECT_NONE;
3410 ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
3414 struct eth_addr* ethaddr_ret;
3415 ip_addr_t* ipaddr_ret;
3416 #endif /* LWIP_ARP */
3418 struct netif *netif;
3420 LWIP_UNUSED_ARG(len);
3421 LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
3423 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
3424 snmp_oidtoip(&od->id_inst_ptr[2], &ip);
3426 #if LWIP_ARP /** @todo implement a netif_find_addr */
3427 if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
3429 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3430 id = (u8_t)od->id_inst_ptr[0];
3433 case 1: /* ipNetToMediaIfIndex */
3435 s32_t *sint_ptr = (s32_t*)value;
3436 *sint_ptr = od->id_inst_ptr[1];
3439 case 2: /* ipNetToMediaPhysAddress */
3441 struct eth_addr *dst = (struct eth_addr*)value;
3443 *dst = *ethaddr_ret;
3446 case 3: /* ipNetToMediaNetAddress */
3448 ip_addr_t *dst = (ip_addr_t*)value;
3453 case 4: /* ipNetToMediaType */
3455 s32_t *sint_ptr = (s32_t*)value;
3462 #endif /* LWIP_ARP */
3466 icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3468 /* return to object name, adding index depth (1) */
3471 if ((ident_len == 2) &&
3472 (ident[0] > 0) && (ident[0] < 27))
3474 od->id_inst_len = ident_len;
3475 od->id_inst_ptr = ident;
3477 od->instance = MIB_OBJECT_SCALAR;
3478 od->access = MIB_OBJECT_READ_ONLY;
3479 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3480 od->v_len = sizeof(u32_t);
3484 LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n"));
3485 od->instance = MIB_OBJECT_NONE;
3490 icmp_get_value(struct obj_def *od, u16_t len, void *value)
3492 u32_t *uint_ptr = (u32_t*)value;
3495 LWIP_UNUSED_ARG(len);
3496 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3497 id = (u8_t)od->id_inst_ptr[0];
3500 case 1: /* icmpInMsgs */
3501 *uint_ptr = icmpinmsgs;
3503 case 2: /* icmpInErrors */
3504 *uint_ptr = icmpinerrors;
3506 case 3: /* icmpInDestUnreachs */
3507 *uint_ptr = icmpindestunreachs;
3509 case 4: /* icmpInTimeExcds */
3510 *uint_ptr = icmpintimeexcds;
3512 case 5: /* icmpInParmProbs */
3513 *uint_ptr = icmpinparmprobs;
3515 case 6: /* icmpInSrcQuenchs */
3516 *uint_ptr = icmpinsrcquenchs;
3518 case 7: /* icmpInRedirects */
3519 *uint_ptr = icmpinredirects;
3521 case 8: /* icmpInEchos */
3522 *uint_ptr = icmpinechos;
3524 case 9: /* icmpInEchoReps */
3525 *uint_ptr = icmpinechoreps;
3527 case 10: /* icmpInTimestamps */
3528 *uint_ptr = icmpintimestamps;
3530 case 11: /* icmpInTimestampReps */
3531 *uint_ptr = icmpintimestampreps;
3533 case 12: /* icmpInAddrMasks */
3534 *uint_ptr = icmpinaddrmasks;
3536 case 13: /* icmpInAddrMaskReps */
3537 *uint_ptr = icmpinaddrmaskreps;
3539 case 14: /* icmpOutMsgs */
3540 *uint_ptr = icmpoutmsgs;
3542 case 15: /* icmpOutErrors */
3543 *uint_ptr = icmpouterrors;
3545 case 16: /* icmpOutDestUnreachs */
3546 *uint_ptr = icmpoutdestunreachs;
3548 case 17: /* icmpOutTimeExcds */
3549 *uint_ptr = icmpouttimeexcds;
3551 case 18: /* icmpOutParmProbs */
3552 *uint_ptr = icmpoutparmprobs;
3554 case 19: /* icmpOutSrcQuenchs */
3555 *uint_ptr = icmpoutsrcquenchs;
3557 case 20: /* icmpOutRedirects */
3558 *uint_ptr = icmpoutredirects;
3560 case 21: /* icmpOutEchos */
3561 *uint_ptr = icmpoutechos;
3563 case 22: /* icmpOutEchoReps */
3564 *uint_ptr = icmpoutechoreps;
3566 case 23: /* icmpOutTimestamps */
3567 *uint_ptr = icmpouttimestamps;
3569 case 24: /* icmpOutTimestampReps */
3570 *uint_ptr = icmpouttimestampreps;
3572 case 25: /* icmpOutAddrMasks */
3573 *uint_ptr = icmpoutaddrmasks;
3575 case 26: /* icmpOutAddrMaskReps */
3576 *uint_ptr = icmpoutaddrmaskreps;
3582 /** @todo tcp grp */
3584 tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3588 /* return to object name, adding index depth (1) */
3593 od->id_inst_len = ident_len;
3594 od->id_inst_ptr = ident;
3596 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3597 id = (u8_t)ident[0];
3598 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
3602 case 1: /* tcpRtoAlgorithm */
3603 case 2: /* tcpRtoMin */
3604 case 3: /* tcpRtoMax */
3605 case 4: /* tcpMaxConn */
3606 od->instance = MIB_OBJECT_SCALAR;
3607 od->access = MIB_OBJECT_READ_ONLY;
3608 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3609 od->v_len = sizeof(s32_t);
3611 case 5: /* tcpActiveOpens */
3612 case 6: /* tcpPassiveOpens */
3613 case 7: /* tcpAttemptFails */
3614 case 8: /* tcpEstabResets */
3615 case 10: /* tcpInSegs */
3616 case 11: /* tcpOutSegs */
3617 case 12: /* tcpRetransSegs */
3618 case 14: /* tcpInErrs */
3619 case 15: /* tcpOutRsts */
3620 od->instance = MIB_OBJECT_SCALAR;
3621 od->access = MIB_OBJECT_READ_ONLY;
3622 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3623 od->v_len = sizeof(u32_t);
3625 case 9: /* tcpCurrEstab */
3626 od->instance = MIB_OBJECT_TAB;
3627 od->access = MIB_OBJECT_READ_ONLY;
3628 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
3629 od->v_len = sizeof(u32_t);
3632 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n"));
3633 od->instance = MIB_OBJECT_NONE;
3639 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n"));
3640 od->instance = MIB_OBJECT_NONE;
3645 tcp_get_value(struct obj_def *od, u16_t len, void *value)
3647 u32_t *uint_ptr = (u32_t*)value;
3648 s32_t *sint_ptr = (s32_t*)value;
3651 LWIP_UNUSED_ARG(len);
3652 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3653 id = (u8_t)od->id_inst_ptr[0];
3656 case 1: /* tcpRtoAlgorithm, vanj(4) */
3659 case 2: /* tcpRtoMin */
3660 /* @todo not the actual value, a guess,
3661 needs to be calculated */
3664 case 3: /* tcpRtoMax */
3665 /* @todo not the actual value, a guess,
3666 needs to be calculated */
3669 case 4: /* tcpMaxConn */
3670 *sint_ptr = MEMP_NUM_TCP_PCB;
3672 case 5: /* tcpActiveOpens */
3673 *uint_ptr = tcpactiveopens;
3675 case 6: /* tcpPassiveOpens */
3676 *uint_ptr = tcppassiveopens;
3678 case 7: /* tcpAttemptFails */
3679 *uint_ptr = tcpattemptfails;
3681 case 8: /* tcpEstabResets */
3682 *uint_ptr = tcpestabresets;
3684 case 9: /* tcpCurrEstab */
3686 u16_t tcpcurrestab = 0;
3687 struct tcp_pcb *pcb = tcp_active_pcbs;
3690 if ((pcb->state == ESTABLISHED) ||
3691 (pcb->state == CLOSE_WAIT))
3697 *uint_ptr = tcpcurrestab;
3700 case 10: /* tcpInSegs */
3701 *uint_ptr = tcpinsegs;
3703 case 11: /* tcpOutSegs */
3704 *uint_ptr = tcpoutsegs;
3706 case 12: /* tcpRetransSegs */
3707 *uint_ptr = tcpretranssegs;
3709 case 14: /* tcpInErrs */
3710 *uint_ptr = tcpinerrs;
3712 case 15: /* tcpOutRsts */
3713 *uint_ptr = tcpoutrsts;
3717 #ifdef THIS_SEEMS_UNUSED
3719 tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3721 /* return to object name, adding index depth (10) */
3725 if (ident_len == 11)
3729 od->id_inst_len = ident_len;
3730 od->id_inst_ptr = ident;
3733 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
3737 case 1: /* tcpConnState */
3738 od->instance = MIB_OBJECT_TAB;
3739 od->access = MIB_OBJECT_READ_WRITE;
3740 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3741 od->v_len = sizeof(s32_t);
3743 case 2: /* tcpConnLocalAddress */
3744 case 4: /* tcpConnRemAddress */
3745 od->instance = MIB_OBJECT_TAB;
3746 od->access = MIB_OBJECT_READ_ONLY;
3747 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3750 case 3: /* tcpConnLocalPort */
3751 case 5: /* tcpConnRemPort */
3752 od->instance = MIB_OBJECT_TAB;
3753 od->access = MIB_OBJECT_READ_ONLY;
3754 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3755 od->v_len = sizeof(s32_t);
3758 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
3759 od->instance = MIB_OBJECT_NONE;
3765 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
3766 od->instance = MIB_OBJECT_NONE;
3771 tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)
3777 ident = od->id_inst_ptr;
3778 snmp_oidtoip(&ident[1], &lip);
3780 snmp_oidtoip(&ident[6], &rip);
3783 /** @todo find matching PCB */
3789 udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3791 /* return to object name, adding index depth (1) */
3794 if ((ident_len == 2) &&
3795 (ident[0] > 0) && (ident[0] < 6))
3797 od->id_inst_len = ident_len;
3798 od->id_inst_ptr = ident;
3800 od->instance = MIB_OBJECT_SCALAR;
3801 od->access = MIB_OBJECT_READ_ONLY;
3802 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3803 od->v_len = sizeof(u32_t);
3807 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n"));
3808 od->instance = MIB_OBJECT_NONE;
3813 udp_get_value(struct obj_def *od, u16_t len, void *value)
3815 u32_t *uint_ptr = (u32_t*)value;
3818 LWIP_UNUSED_ARG(len);
3819 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3820 id = (u8_t)od->id_inst_ptr[0];
3823 case 1: /* udpInDatagrams */
3824 *uint_ptr = udpindatagrams;
3826 case 2: /* udpNoPorts */
3827 *uint_ptr = udpnoports;
3829 case 3: /* udpInErrors */
3830 *uint_ptr = udpinerrors;
3832 case 4: /* udpOutDatagrams */
3833 *uint_ptr = udpoutdatagrams;
3839 udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3841 /* return to object name, adding index depth (5) */
3847 od->id_inst_len = ident_len;
3848 od->id_inst_ptr = ident;
3852 case 1: /* udpLocalAddress */
3853 od->instance = MIB_OBJECT_TAB;
3854 od->access = MIB_OBJECT_READ_ONLY;
3855 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3858 case 2: /* udpLocalPort */
3859 od->instance = MIB_OBJECT_TAB;
3860 od->access = MIB_OBJECT_READ_ONLY;
3861 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3862 od->v_len = sizeof(s32_t);
3865 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n"));
3866 od->instance = MIB_OBJECT_NONE;
3872 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n"));
3873 od->instance = MIB_OBJECT_NONE;
3878 udpentry_get_value(struct obj_def *od, u16_t len, void *value)
3881 struct udp_pcb *pcb;
3885 LWIP_UNUSED_ARG(len);
3886 snmp_oidtoip(&od->id_inst_ptr[1], &ip);
3887 LWIP_ASSERT("invalid port", (od->id_inst_ptr[5] >= 0) && (od->id_inst_ptr[5] <= 0xffff));
3888 port = (u16_t)od->id_inst_ptr[5];
3891 while ((pcb != NULL) &&
3892 !(ip_addr_cmp(&pcb->local_ip, &ip) &&
3893 (pcb->local_port == port)))
3900 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3901 id = (u8_t)od->id_inst_ptr[0];
3904 case 1: /* udpLocalAddress */
3906 ip_addr_t *dst = (ip_addr_t*)value;
3907 *dst = pcb->local_ip;
3910 case 2: /* udpLocalPort */
3912 s32_t *sint_ptr = (s32_t*)value;
3913 *sint_ptr = pcb->local_port;
3921 snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3923 /* return to object name, adding index depth (1) */
3930 od->id_inst_len = ident_len;
3931 od->id_inst_ptr = ident;
3933 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3934 id = (u8_t)ident[0];
3937 case 1: /* snmpInPkts */
3938 case 2: /* snmpOutPkts */
3939 case 3: /* snmpInBadVersions */
3940 case 4: /* snmpInBadCommunityNames */
3941 case 5: /* snmpInBadCommunityUses */
3942 case 6: /* snmpInASNParseErrs */
3943 case 8: /* snmpInTooBigs */
3944 case 9: /* snmpInNoSuchNames */
3945 case 10: /* snmpInBadValues */
3946 case 11: /* snmpInReadOnlys */
3947 case 12: /* snmpInGenErrs */
3948 case 13: /* snmpInTotalReqVars */
3949 case 14: /* snmpInTotalSetVars */
3950 case 15: /* snmpInGetRequests */
3951 case 16: /* snmpInGetNexts */
3952 case 17: /* snmpInSetRequests */
3953 case 18: /* snmpInGetResponses */
3954 case 19: /* snmpInTraps */
3955 case 20: /* snmpOutTooBigs */
3956 case 21: /* snmpOutNoSuchNames */
3957 case 22: /* snmpOutBadValues */
3958 case 24: /* snmpOutGenErrs */
3959 case 25: /* snmpOutGetRequests */
3960 case 26: /* snmpOutGetNexts */
3961 case 27: /* snmpOutSetRequests */
3962 case 28: /* snmpOutGetResponses */
3963 case 29: /* snmpOutTraps */
3964 od->instance = MIB_OBJECT_SCALAR;
3965 od->access = MIB_OBJECT_READ_ONLY;
3966 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3967 od->v_len = sizeof(u32_t);
3969 case 30: /* snmpEnableAuthenTraps */
3970 od->instance = MIB_OBJECT_SCALAR;
3971 od->access = MIB_OBJECT_READ_WRITE;
3972 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3973 od->v_len = sizeof(s32_t);
3976 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n"));
3977 od->instance = MIB_OBJECT_NONE;
3983 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n"));
3984 od->instance = MIB_OBJECT_NONE;
3989 snmp_get_value(struct obj_def *od, u16_t len, void *value)
3991 u32_t *uint_ptr = (u32_t*)value;
3994 LWIP_UNUSED_ARG(len);
3995 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3996 id = (u8_t)od->id_inst_ptr[0];
3999 case 1: /* snmpInPkts */
4000 *uint_ptr = snmpinpkts;
4002 case 2: /* snmpOutPkts */
4003 *uint_ptr = snmpoutpkts;
4005 case 3: /* snmpInBadVersions */
4006 *uint_ptr = snmpinbadversions;
4008 case 4: /* snmpInBadCommunityNames */
4009 *uint_ptr = snmpinbadcommunitynames;
4011 case 5: /* snmpInBadCommunityUses */
4012 *uint_ptr = snmpinbadcommunityuses;
4014 case 6: /* snmpInASNParseErrs */
4015 *uint_ptr = snmpinasnparseerrs;
4017 case 8: /* snmpInTooBigs */
4018 *uint_ptr = snmpintoobigs;
4020 case 9: /* snmpInNoSuchNames */
4021 *uint_ptr = snmpinnosuchnames;
4023 case 10: /* snmpInBadValues */
4024 *uint_ptr = snmpinbadvalues;
4026 case 11: /* snmpInReadOnlys */
4027 *uint_ptr = snmpinreadonlys;
4029 case 12: /* snmpInGenErrs */
4030 *uint_ptr = snmpingenerrs;
4032 case 13: /* snmpInTotalReqVars */
4033 *uint_ptr = snmpintotalreqvars;
4035 case 14: /* snmpInTotalSetVars */
4036 *uint_ptr = snmpintotalsetvars;
4038 case 15: /* snmpInGetRequests */
4039 *uint_ptr = snmpingetrequests;
4041 case 16: /* snmpInGetNexts */
4042 *uint_ptr = snmpingetnexts;
4044 case 17: /* snmpInSetRequests */
4045 *uint_ptr = snmpinsetrequests;
4047 case 18: /* snmpInGetResponses */
4048 *uint_ptr = snmpingetresponses;
4050 case 19: /* snmpInTraps */
4051 *uint_ptr = snmpintraps;
4053 case 20: /* snmpOutTooBigs */
4054 *uint_ptr = snmpouttoobigs;
4056 case 21: /* snmpOutNoSuchNames */
4057 *uint_ptr = snmpoutnosuchnames;
4059 case 22: /* snmpOutBadValues */
4060 *uint_ptr = snmpoutbadvalues;
4062 case 24: /* snmpOutGenErrs */
4063 *uint_ptr = snmpoutgenerrs;
4065 case 25: /* snmpOutGetRequests */
4066 *uint_ptr = snmpoutgetrequests;
4068 case 26: /* snmpOutGetNexts */
4069 *uint_ptr = snmpoutgetnexts;
4071 case 27: /* snmpOutSetRequests */
4072 *uint_ptr = snmpoutsetrequests;
4074 case 28: /* snmpOutGetResponses */
4075 *uint_ptr = snmpoutgetresponses;
4077 case 29: /* snmpOutTraps */
4078 *uint_ptr = snmpouttraps;
4080 case 30: /* snmpEnableAuthenTraps */
4081 *uint_ptr = *snmpenableauthentraps_ptr;
4087 * Test snmp object value before setting.
4089 * @param od is the object definition
4090 * @param len return value space (in bytes)
4091 * @param value points to (varbind) space to copy value from.
4094 snmp_set_test(struct obj_def *od, u16_t len, void *value)
4098 LWIP_UNUSED_ARG(len);
4100 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
4101 id = (u8_t)od->id_inst_ptr[0];
4104 /* snmpEnableAuthenTraps */
4105 s32_t *sint_ptr = (s32_t*)value;
4107 if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default)
4109 /* we should have writable non-volatile mem here */
4110 if ((*sint_ptr == 1) || (*sint_ptr == 2))
4117 /* const or hardwired value */
4118 if (*sint_ptr == snmpenableauthentraps_default)
4128 snmp_set_value(struct obj_def *od, u16_t len, void *value)
4132 LWIP_UNUSED_ARG(len);
4133 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
4134 id = (u8_t)od->id_inst_ptr[0];
4137 /* snmpEnableAuthenTraps */
4138 /* @todo @fixme: which kind of pointer is 'value'? s32_t or u8_t??? */
4139 u8_t *ptr = (u8_t*)value;
4140 *snmpenableauthentraps_ptr = *ptr;
4144 #endif /* LWIP_SNMP */