Debian Codegraph @

lwip/src/core/snmp/mib2.c

raw
1 /**
2 * @file
3 * Management Information Base II (RFC1213) objects and functions.
4 *
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 */
8
9 /*
10 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
11 * All rights reserved.
12 *
13 * Redistribution and use in source and binary forms, with or without modification,
14 * are permitted provided that the following conditions are met:
15 *
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.
23 *
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.
34 *
35 * Author: Christiaan Simons <[email protected]>
36 */
37
38 #include "lwip/opt.h"
39
40 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
41
42 #include "lwip/snmp.h"
43 #include "lwip/netif.h"
44 #include "lwip/ip.h"
45 #include "lwip/ip_frag.h"
46 #include "lwip/mem.h"
47 #include "lwip/tcp_impl.h"
48 #include "lwip/udp.h"
49 #include "lwip/snmp_asn1.h"
50 #include "lwip/snmp_structs.h"
51 #include "lwip/sys.h"
52 #include "netif/etharp.h"
53
54 #include <string.h>
55
56 /**
57 * IANA assigned enterprise ID for lwIP is 26381
58 * @see http://www.iana.org/assignments/enterprise-numbers
59 *
60 * @note this enterprise ID is assigned to the lwIP project,
61 * all object identifiers living under this ID are assigned
62 * by the lwIP maintainers (contact Christiaan Simons)!
63 * @note don't change this define, use snmp_set_sysobjid()
64 *
65 * If you need to create your own private MIB you'll need
66 * to apply for your own enterprise ID with IANA:
67 * http://www.iana.org/numbers.html
68 */
69 #define SNMP_ENTERPRISE_ID 26381
70 #define SNMP_SYSOBJID_LEN 7
71 #define SNMP_SYSOBJID {1, 3, 6, 1, 4, 1, SNMP_ENTERPRISE_ID}
72
73 #ifndef SNMP_SYSSERVICES
74 #define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2))
75 #endif
76
77 #ifndef SNMP_GET_SYSUPTIME
78 #define SNMP_GET_SYSUPTIME(sysuptime) (sysuptime = (sys_now() / 10))
79 #endif
80
81 static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
82 static void system_get_value(struct obj_def *od, u16_t len, void *value);
83 static u8_t system_set_test(struct obj_def *od, u16_t len, void *value);
84 static void system_set_value(struct obj_def *od, u16_t len, void *value);
85 static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
86 static void interfaces_get_value(struct obj_def *od, u16_t len, void *value);
87 static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
88 static void ifentry_get_value(struct obj_def *od, u16_t len, void *value);
89 #if !SNMP_SAFE_REQUESTS
90 static u8_t ifentry_set_test (struct obj_def *od, u16_t len, void *value);
91 static void ifentry_set_value (struct obj_def *od, u16_t len, void *value);
92 #endif /* SNMP_SAFE_REQUESTS */
93 static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
94 static void atentry_get_value(struct obj_def *od, u16_t len, void *value);
95 static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
96 static void ip_get_value(struct obj_def *od, u16_t len, void *value);
97 static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value);
98 static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
99 static void ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value);
100 static void ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
101 static void ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value);
102 static void ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
103 static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value);
104 static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
105 static void icmp_get_value(struct obj_def *od, u16_t len, void *value);
106 #if LWIP_TCP
107 static void tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
108 static void tcp_get_value(struct obj_def *od, u16_t len, void *value);
109 #ifdef THIS_SEEMS_UNUSED
110 static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
111 static void tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value);
112 #endif
113 #endif
114 static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
115 static void udp_get_value(struct obj_def *od, u16_t len, void *value);
116 static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
117 static void udpentry_get_value(struct obj_def *od, u16_t len, void *value);
118 static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
119 static void snmp_get_value(struct obj_def *od, u16_t len, void *value);
120 static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value);
121 static void snmp_set_value(struct obj_def *od, u16_t len, void *value);
122
123
124 /* snmp .1.3.6.1.2.1.11 */
125 const mib_scalar_node snmp_scalar = {
126 &snmp_get_object_def,
127 &snmp_get_value,
128 &snmp_set_test,
129 &snmp_set_value,
130 MIB_NODE_SC,
131 0
132 };
133 const s32_t snmp_ids[28] = {
134 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
135 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30
136 };
137 struct mib_node* const snmp_nodes[28] = {
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,
148 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
149 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
150 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
151 (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar
152 };
153 const struct mib_array_node snmp = {
154 &noleafs_get_object_def,
155 &noleafs_get_value,
156 &noleafs_set_test,
157 &noleafs_set_value,
158 MIB_NODE_AR,
159 28,
160 snmp_ids,
161 snmp_nodes
162 };
163
164 /* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */
165 /* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */
166 /* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */
167
168 /* udp .1.3.6.1.2.1.7 */
169 /** index root node for udpTable */
170 struct mib_list_rootnode udp_root = {
171 &noleafs_get_object_def,
172 &noleafs_get_value,
173 &noleafs_set_test,
174 &noleafs_set_value,
175 MIB_NODE_LR,
176 0,
177 NULL,
178 NULL,
179 0
180 };
181 const s32_t udpentry_ids[2] = { 1, 2 };
182 struct mib_node* const udpentry_nodes[2] = {
183 (struct mib_node*)&udp_root, (struct mib_node*)&udp_root,
184 };
185 const struct mib_array_node udpentry = {
186 &noleafs_get_object_def,
187 &noleafs_get_value,
188 &noleafs_set_test,
189 &noleafs_set_value,
190 MIB_NODE_AR,
191 2,
192 udpentry_ids,
193 udpentry_nodes
194 };
195
196 s32_t udptable_id = 1;
197 struct mib_node* udptable_node = (struct mib_node*)&udpentry;
198 struct mib_ram_array_node udptable = {
199 &noleafs_get_object_def,
200 &noleafs_get_value,
201 &noleafs_set_test,
202 &noleafs_set_value,
203 MIB_NODE_RA,
204 0,
205 &udptable_id,
206 &udptable_node
207 };
208
209 const mib_scalar_node udp_scalar = {
210 &udp_get_object_def,
211 &udp_get_value,
212 &noleafs_set_test,
213 &noleafs_set_value,
214 MIB_NODE_SC,
215 0
216 };
217 const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 };
218 struct mib_node* const udp_nodes[5] = {
219 (struct mib_node*)&udp_scalar, (struct mib_node*)&udp_scalar,
220 (struct mib_node*)&udp_scalar, (struct mib_node*)&udp_scalar,
221 (struct mib_node*)&udptable
222 };
223 const struct mib_array_node udp = {
224 &noleafs_get_object_def,
225 &noleafs_get_value,
226 &noleafs_set_test,
227 &noleafs_set_value,
228 MIB_NODE_AR,
229 5,
230 udp_ids,
231 udp_nodes
232 };
233
234 /* tcp .1.3.6.1.2.1.6 */
235 #if LWIP_TCP
236 /* only if the TCP protocol is available may implement this group */
237 /** index root node for tcpConnTable */
238 struct mib_list_rootnode tcpconntree_root = {
239 &noleafs_get_object_def,
240 &noleafs_get_value,
241 &noleafs_set_test,
242 &noleafs_set_value,
243 MIB_NODE_LR,
244 0,
245 NULL,
246 NULL,
247 0
248 };
249 const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 };
250 struct mib_node* const tcpconnentry_nodes[5] = {
251 (struct mib_node*)&tcpconntree_root, (struct mib_node*)&tcpconntree_root,
252 (struct mib_node*)&tcpconntree_root, (struct mib_node*)&tcpconntree_root,
253 (struct mib_node*)&tcpconntree_root
254 };
255 const struct mib_array_node tcpconnentry = {
256 &noleafs_get_object_def,
257 &noleafs_get_value,
258 &noleafs_set_test,
259 &noleafs_set_value,
260 MIB_NODE_AR,
261 5,
262 tcpconnentry_ids,
263 tcpconnentry_nodes
264 };
265
266 s32_t tcpconntable_id = 1;
267 struct mib_node* tcpconntable_node = (struct mib_node*)&tcpconnentry;
268 struct mib_ram_array_node tcpconntable = {
269 &noleafs_get_object_def,
270 &noleafs_get_value,
271 &noleafs_set_test,
272 &noleafs_set_value,
273 MIB_NODE_RA,
274 /** @todo update maxlength when inserting / deleting from table
275 0 when table is empty, 1 when more than one entry */
276 0,
277 &tcpconntable_id,
278 &tcpconntable_node
279 };
280
281 const mib_scalar_node tcp_scalar = {
282 &tcp_get_object_def,
283 &tcp_get_value,
284 &noleafs_set_test,
285 &noleafs_set_value,
286 MIB_NODE_SC,
287 0
288 };
289 const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
290 struct mib_node* const tcp_nodes[15] = {
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*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
294 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
295 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
296 (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
297 (struct mib_node*)&tcpconntable, (struct mib_node*)&tcp_scalar,
298 (struct mib_node*)&tcp_scalar
299 };
300 const struct mib_array_node tcp = {
301 &noleafs_get_object_def,
302 &noleafs_get_value,
303 &noleafs_set_test,
304 &noleafs_set_value,
305 MIB_NODE_AR,
306 15,
307 tcp_ids,
308 tcp_nodes
309 };
310 #endif
311
312 /* icmp .1.3.6.1.2.1.5 */
313 const mib_scalar_node icmp_scalar = {
314 &icmp_get_object_def,
315 &icmp_get_value,
316 &noleafs_set_test,
317 &noleafs_set_value,
318 MIB_NODE_SC,
319 0
320 };
321 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 };
322 struct mib_node* const icmp_nodes[26] = {
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,
332 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
333 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
334 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
335 (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar
336 };
337 const struct mib_array_node icmp = {
338 &noleafs_get_object_def,
339 &noleafs_get_value,
340 &noleafs_set_test,
341 &noleafs_set_value,
342 MIB_NODE_AR,
343 26,
344 icmp_ids,
345 icmp_nodes
346 };
347
348 /** index root node for ipNetToMediaTable */
349 struct mib_list_rootnode ipntomtree_root = {
350 &noleafs_get_object_def,
351 &noleafs_get_value,
352 &noleafs_set_test,
353 &noleafs_set_value,
354 MIB_NODE_LR,
355 0,
356 NULL,
357 NULL,
358 0
359 };
360 const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 };
361 struct mib_node* const ipntomentry_nodes[4] = {
362 (struct mib_node*)&ipntomtree_root, (struct mib_node*)&ipntomtree_root,
363 (struct mib_node*)&ipntomtree_root, (struct mib_node*)&ipntomtree_root
364 };
365 const struct mib_array_node ipntomentry = {
366 &noleafs_get_object_def,
367 &noleafs_get_value,
368 &noleafs_set_test,
369 &noleafs_set_value,
370 MIB_NODE_AR,
371 4,
372 ipntomentry_ids,
373 ipntomentry_nodes
374 };
375
376 s32_t ipntomtable_id = 1;
377 struct mib_node* ipntomtable_node = (struct mib_node*)&ipntomentry;
378 struct mib_ram_array_node ipntomtable = {
379 &noleafs_get_object_def,
380 &noleafs_get_value,
381 &noleafs_set_test,
382 &noleafs_set_value,
383 MIB_NODE_RA,
384 0,
385 &ipntomtable_id,
386 &ipntomtable_node
387 };
388
389 /** index root node for ipRouteTable */
390 struct mib_list_rootnode iprtetree_root = {
391 &noleafs_get_object_def,
392 &noleafs_get_value,
393 &noleafs_set_test,
394 &noleafs_set_value,
395 MIB_NODE_LR,
396 0,
397 NULL,
398 NULL,
399 0
400 };
401 const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
402 struct mib_node* const iprteentry_nodes[13] = {
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, (struct mib_node*)&iprtetree_root,
406 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
407 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
408 (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
409 (struct mib_node*)&iprtetree_root
410 };
411 const struct mib_array_node iprteentry = {
412 &noleafs_get_object_def,
413 &noleafs_get_value,
414 &noleafs_set_test,
415 &noleafs_set_value,
416 MIB_NODE_AR,
417 13,
418 iprteentry_ids,
419 iprteentry_nodes
420 };
421
422 s32_t iprtetable_id = 1;
423 struct mib_node* iprtetable_node = (struct mib_node*)&iprteentry;
424 struct mib_ram_array_node iprtetable = {
425 &noleafs_get_object_def,
426 &noleafs_get_value,
427 &noleafs_set_test,
428 &noleafs_set_value,
429 MIB_NODE_RA,
430 0,
431 &iprtetable_id,
432 &iprtetable_node
433 };
434
435 /** index root node for ipAddrTable */
436 struct mib_list_rootnode ipaddrtree_root = {
437 &noleafs_get_object_def,
438 &noleafs_get_value,
439 &noleafs_set_test,
440 &noleafs_set_value,
441 MIB_NODE_LR,
442 0,
443 NULL,
444 NULL,
445 0
446 };
447 const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 };
448 struct mib_node* const ipaddrentry_nodes[5] = {
449 (struct mib_node*)&ipaddrtree_root,
450 (struct mib_node*)&ipaddrtree_root,
451 (struct mib_node*)&ipaddrtree_root,
452 (struct mib_node*)&ipaddrtree_root,
453 (struct mib_node*)&ipaddrtree_root
454 };
455 const struct mib_array_node ipaddrentry = {
456 &noleafs_get_object_def,
457 &noleafs_get_value,
458 &noleafs_set_test,
459 &noleafs_set_value,
460 MIB_NODE_AR,
461 5,
462 ipaddrentry_ids,
463 ipaddrentry_nodes
464 };
465
466 s32_t ipaddrtable_id = 1;
467 struct mib_node* ipaddrtable_node = (struct mib_node*)&ipaddrentry;
468 struct mib_ram_array_node ipaddrtable = {
469 &noleafs_get_object_def,
470 &noleafs_get_value,
471 &noleafs_set_test,
472 &noleafs_set_value,
473 MIB_NODE_RA,
474 0,
475 &ipaddrtable_id,
476 &ipaddrtable_node
477 };
478
479 /* ip .1.3.6.1.2.1.4 */
480 const mib_scalar_node ip_scalar = {
481 &ip_get_object_def,
482 &ip_get_value,
483 &ip_set_test,
484 &noleafs_set_value,
485 MIB_NODE_SC,
486 0
487 };
488 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 };
489 struct mib_node* const ip_nodes[23] = {
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*)&ip_scalar,
496 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
497 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
498 (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
499 (struct mib_node*)&ip_scalar, (struct mib_node*)&ipaddrtable,
500 (struct mib_node*)&iprtetable, (struct mib_node*)&ipntomtable,
501 (struct mib_node*)&ip_scalar
502 };
503 const struct mib_array_node mib2_ip = {
504 &noleafs_get_object_def,
505 &noleafs_get_value,
506 &noleafs_set_test,
507 &noleafs_set_value,
508 MIB_NODE_AR,
509 23,
510 ip_ids,
511 ip_nodes
512 };
513
514 /** index root node for atTable */
515 struct mib_list_rootnode arptree_root = {
516 &noleafs_get_object_def,
517 &noleafs_get_value,
518 &noleafs_set_test,
519 &noleafs_set_value,
520 MIB_NODE_LR,
521 0,
522 NULL,
523 NULL,
524 0
525 };
526 const s32_t atentry_ids[3] = { 1, 2, 3 };
527 struct mib_node* const atentry_nodes[3] = {
528 (struct mib_node*)&arptree_root,
529 (struct mib_node*)&arptree_root,
530 (struct mib_node*)&arptree_root
531 };
532 const struct mib_array_node atentry = {
533 &noleafs_get_object_def,
534 &noleafs_get_value,
535 &noleafs_set_test,
536 &noleafs_set_value,
537 MIB_NODE_AR,
538 3,
539 atentry_ids,
540 atentry_nodes
541 };
542
543 const s32_t attable_id = 1;
544 struct mib_node* const attable_node = (struct mib_node*)&atentry;
545 const struct mib_array_node attable = {
546 &noleafs_get_object_def,
547 &noleafs_get_value,
548 &noleafs_set_test,
549 &noleafs_set_value,
550 MIB_NODE_AR,
551 1,
552 &attable_id,
553 &attable_node
554 };
555
556 /* at .1.3.6.1.2.1.3 */
557 s32_t at_id = 1;
558 struct mib_node* mib2_at_node = (struct mib_node*)&attable;
559 struct mib_ram_array_node at = {
560 &noleafs_get_object_def,
561 &noleafs_get_value,
562 &noleafs_set_test,
563 &noleafs_set_value,
564 MIB_NODE_RA,
565 0,
566 &at_id,
567 &mib2_at_node
568 };
569
570 /** index root node for ifTable */
571 struct mib_list_rootnode iflist_root = {
572 &ifentry_get_object_def,
573 &ifentry_get_value,
574 #if SNMP_SAFE_REQUESTS
575 &noleafs_set_test,
576 &noleafs_set_value,
577 #else /* SNMP_SAFE_REQUESTS */
578 &ifentry_set_test,
579 &ifentry_set_value,
580 #endif /* SNMP_SAFE_REQUESTS */
581 MIB_NODE_LR,
582 0,
583 NULL,
584 NULL,
585 0
586 };
587 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 };
588 struct mib_node* const ifentry_nodes[22] = {
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,
596 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
597 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
598 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
599 (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root
600 };
601 const struct mib_array_node ifentry = {
602 &noleafs_get_object_def,
603 &noleafs_get_value,
604 &noleafs_set_test,
605 &noleafs_set_value,
606 MIB_NODE_AR,
607 22,
608 ifentry_ids,
609 ifentry_nodes
610 };
611
612 s32_t iftable_id = 1;
613 struct mib_node* iftable_node = (struct mib_node*)&ifentry;
614 struct mib_ram_array_node iftable = {
615 &noleafs_get_object_def,
616 &noleafs_get_value,
617 &noleafs_set_test,
618 &noleafs_set_value,
619 MIB_NODE_RA,
620 0,
621 &iftable_id,
622 &iftable_node
623 };
624
625 /* interfaces .1.3.6.1.2.1.2 */
626 const mib_scalar_node interfaces_scalar = {
627 &interfaces_get_object_def,
628 &interfaces_get_value,
629 &noleafs_set_test,
630 &noleafs_set_value,
631 MIB_NODE_SC,
632 0
633 };
634 const s32_t interfaces_ids[2] = { 1, 2 };
635 struct mib_node* const interfaces_nodes[2] = {
636 (struct mib_node*)&interfaces_scalar, (struct mib_node*)&iftable
637 };
638 const struct mib_array_node interfaces = {
639 &noleafs_get_object_def,
640 &noleafs_get_value,
641 &noleafs_set_test,
642 &noleafs_set_value,
643 MIB_NODE_AR,
644 2,
645 interfaces_ids,
646 interfaces_nodes
647 };
648
649
650 /* 0 1 2 3 4 5 6 */
651 /* system .1.3.6.1.2.1.1 */
652 const mib_scalar_node sys_tem_scalar = {
653 &system_get_object_def,
654 &system_get_value,
655 &system_set_test,
656 &system_set_value,
657 MIB_NODE_SC,
658 0
659 };
660 const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };
661 struct mib_node* const sys_tem_nodes[7] = {
662 (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
663 (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
664 (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
665 (struct mib_node*)&sys_tem_scalar
666 };
667 /* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */
668 const struct mib_array_node sys_tem = {
669 &noleafs_get_object_def,
670 &noleafs_get_value,
671 &noleafs_set_test,
672 &noleafs_set_value,
673 MIB_NODE_AR,
674 7,
675 sys_tem_ids,
676 sys_tem_nodes
677 };
678
679 /* mib-2 .1.3.6.1.2.1 */
680 #if LWIP_TCP
681 #define MIB2_GROUPS 8
682 #else
683 #define MIB2_GROUPS 7
684 #endif
685 const s32_t mib2_ids[MIB2_GROUPS] =
686 {
687 1,
688 2,
689 3,
690 4,
691 5,
692 #if LWIP_TCP
693 6,
694 #endif
695 7,
696 11
697 };
698 struct mib_node* const mib2_nodes[MIB2_GROUPS] = {
699 (struct mib_node*)&sys_tem,
700 (struct mib_node*)&interfaces,
701 (struct mib_node*)&at,
702 (struct mib_node*)&mib2_ip,
703 (struct mib_node*)&icmp,
704 #if LWIP_TCP
705 (struct mib_node*)&tcp,
706 #endif
707 (struct mib_node*)&udp,
708 (struct mib_node*)&snmp
709 };
710
711 const struct mib_array_node mib2 = {
712 &noleafs_get_object_def,
713 &noleafs_get_value,
714 &noleafs_set_test,
715 &noleafs_set_value,
716 MIB_NODE_AR,
717 MIB2_GROUPS,
718 mib2_ids,
719 mib2_nodes
720 };
721
722 /* mgmt .1.3.6.1.2 */
723 const s32_t mgmt_ids[1] = { 1 };
724 struct mib_node* const mgmt_nodes[1] = { (struct mib_node*)&mib2 };
725 const struct mib_array_node mgmt = {
726 &noleafs_get_object_def,
727 &noleafs_get_value,
728 &noleafs_set_test,
729 &noleafs_set_value,
730 MIB_NODE_AR,
731 1,
732 mgmt_ids,
733 mgmt_nodes
734 };
735
736 /* internet .1.3.6.1 */
737 #if SNMP_PRIVATE_MIB
738 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
739 * a 'struct mib_array_node mib_private' which contains your MIB. */
740 s32_t internet_ids[2] = { 2, 4 };
741 struct mib_node* const internet_nodes[2] = { (struct mib_node*)&mgmt, (struct mib_node*)&mib_private };
742 const struct mib_array_node internet = {
743 &noleafs_get_object_def,
744 &noleafs_get_value,
745 &noleafs_set_test,
746 &noleafs_set_value,
747 MIB_NODE_AR,
748 2,
749 internet_ids,
750 internet_nodes
751 };
752 #else
753 const s32_t internet_ids[1] = { 2 };
754 struct mib_node* const internet_nodes[1] = { (struct mib_node*)&mgmt };
755 const struct mib_array_node internet = {
756 &noleafs_get_object_def,
757 &noleafs_get_value,
758 &noleafs_set_test,
759 &noleafs_set_value,
760 MIB_NODE_AR,
761 1,
762 internet_ids,
763 internet_nodes
764 };
765 #endif
766
767 /** mib-2.system.sysObjectID */
768 static const struct snmp_obj_id sysobjid_default = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID};
769 static const struct snmp_obj_id* sysobjid_ptr = &sysobjid_default;
770 /** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */
771 static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}};
772 /** mib-2.system.sysServices */
773 static const s32_t sysservices = SNMP_SYSSERVICES;
774
775 /** mib-2.system.sysDescr */
776 static const u8_t sysdescr_len_default = 4;
777 static const u8_t sysdescr_default[] = "lwIP";
778 static const u8_t* sysdescr_len_ptr = &sysdescr_len_default;
779 static const u8_t* sysdescr_ptr = &sysdescr_default[0];
780 /** mib-2.system.sysContact */
781 static const u8_t syscontact_len_default = 0;
782 static const u8_t syscontact_default[] = "";
783 static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default;
784 static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0];
785 /** mib-2.system.sysName */
786 static const u8_t sysname_len_default = 8;
787 static const u8_t sysname_default[] = "FQDN-unk";
788 static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default;
789 static u8_t* sysname_ptr = (u8_t*)&sysname_default[0];
790 /** mib-2.system.sysLocation */
791 static const u8_t syslocation_len_default = 0;
792 static const u8_t syslocation_default[] = "";
793 static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default;
794 static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0];
795 /** mib-2.snmp.snmpEnableAuthenTraps */
796 static const u8_t snmpenableauthentraps_default = 2; /* disabled */
797 static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default;
798
799 /** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */
800 static const struct snmp_obj_id ifspecific = {2, {0, 0}};
801 /** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */
802 static const struct snmp_obj_id iprouteinfo = {2, {0, 0}};
803
804
805
806 /* mib-2.system counter(s) */
807 static u32_t sysuptime = 0;
808
809 /* mib-2.ip counter(s) */
810 static u32_t ipinreceives = 0,
811 ipinhdrerrors = 0,
812 ipinaddrerrors = 0,
813 ipforwdatagrams = 0,
814 ipinunknownprotos = 0,
815 ipindiscards = 0,
816 ipindelivers = 0,
817 ipoutrequests = 0,
818 ipoutdiscards = 0,
819 ipoutnoroutes = 0,
820 ipreasmreqds = 0,
821 ipreasmoks = 0,
822 ipreasmfails = 0,
823 ipfragoks = 0,
824 ipfragfails = 0,
825 ipfragcreates = 0,
826 iproutingdiscards = 0;
827 /* mib-2.icmp counter(s) */
828 static u32_t icmpinmsgs = 0,
829 icmpinerrors = 0,
830 icmpindestunreachs = 0,
831 icmpintimeexcds = 0,
832 icmpinparmprobs = 0,
833 icmpinsrcquenchs = 0,
834 icmpinredirects = 0,
835 icmpinechos = 0,
836 icmpinechoreps = 0,
837 icmpintimestamps = 0,
838 icmpintimestampreps = 0,
839 icmpinaddrmasks = 0,
840 icmpinaddrmaskreps = 0,
841 icmpoutmsgs = 0,
842 icmpouterrors = 0,
843 icmpoutdestunreachs = 0,
844 icmpouttimeexcds = 0,
845 icmpoutparmprobs = 0,
846 icmpoutsrcquenchs = 0,
847 icmpoutredirects = 0,
848 icmpoutechos = 0,
849 icmpoutechoreps = 0,
850 icmpouttimestamps = 0,
851 icmpouttimestampreps = 0,
852 icmpoutaddrmasks = 0,
853 icmpoutaddrmaskreps = 0;
854 /* mib-2.tcp counter(s) */
855 static u32_t tcpactiveopens = 0,
856 tcppassiveopens = 0,
857 tcpattemptfails = 0,
858 tcpestabresets = 0,
859 tcpinsegs = 0,
860 tcpoutsegs = 0,
861 tcpretranssegs = 0,
862 tcpinerrs = 0,
863 tcpoutrsts = 0;
864 /* mib-2.udp counter(s) */
865 static u32_t udpindatagrams = 0,
866 udpnoports = 0,
867 udpinerrors = 0,
868 udpoutdatagrams = 0;
869 /* mib-2.snmp counter(s) */
870 static u32_t snmpinpkts = 0,
871 snmpoutpkts = 0,
872 snmpinbadversions = 0,
873 snmpinbadcommunitynames = 0,
874 snmpinbadcommunityuses = 0,
875 snmpinasnparseerrs = 0,
876 snmpintoobigs = 0,
877 snmpinnosuchnames = 0,
878 snmpinbadvalues = 0,
879 snmpinreadonlys = 0,
880 snmpingenerrs = 0,
881 snmpintotalreqvars = 0,
882 snmpintotalsetvars = 0,
883 snmpingetrequests = 0,
884 snmpingetnexts = 0,
885 snmpinsetrequests = 0,
886 snmpingetresponses = 0,
887 snmpintraps = 0,
888 snmpouttoobigs = 0,
889 snmpoutnosuchnames = 0,
890 snmpoutbadvalues = 0,
891 snmpoutgenerrs = 0,
892 snmpoutgetrequests = 0,
893 snmpoutgetnexts = 0,
894 snmpoutsetrequests = 0,
895 snmpoutgetresponses = 0,
896 snmpouttraps = 0;
897
898
899 /**
900 * Initializes sysDescr pointers.
901 *
902 * @param str if non-NULL then copy str pointer
903 * @param len points to string length, excluding zero terminator
904 */
905 void snmp_set_sysdescr(const u8_t *str, const u8_t *len)
906 {
907 if (str != NULL)
908 {
909 sysdescr_ptr = str;
910 sysdescr_len_ptr = len;
911 }
912 }
913
914 void snmp_get_sysobjid_ptr(const struct snmp_obj_id **oid)
915 {
916 *oid = sysobjid_ptr;
917 }
918
919 /**
920 * Initializes sysObjectID value.
921 *
922 * @param oid points to stuct snmp_obj_id to copy
923 */
924 void snmp_set_sysobjid(const struct snmp_obj_id *oid)
925 {
926 sysobjid_ptr = oid;
927 }
928
929 /**
930 * Must be called at regular 10 msec interval from a timer interrupt
931 * or signal handler depending on your runtime environment.
932 */
933 void snmp_inc_sysuptime(void)
934 {
935 sysuptime++;
936 }
937
938 void snmp_add_sysuptime(u32_t value)
939 {
940 sysuptime+=value;
941 }
942
943 void snmp_get_sysuptime(u32_t *value)
944 {
945 SNMP_GET_SYSUPTIME(sysuptime);
946 *value = sysuptime;
947 }
948
949 /**
950 * Initializes sysContact pointers,
951 * e.g. ptrs to non-volatile memory external to lwIP.
952 *
953 * @param ocstr if non-NULL then copy str pointer
954 * @param ocstrlen points to string length, excluding zero terminator
955 */
956 void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen)
957 {
958 if (ocstr != NULL)
959 {
960 syscontact_ptr = ocstr;
961 syscontact_len_ptr = ocstrlen;
962 }
963 }
964
965 /**
966 * Initializes sysName pointers,
967 * e.g. ptrs to non-volatile memory external to lwIP.
968 *
969 * @param ocstr if non-NULL then copy str pointer
970 * @param ocstrlen points to string length, excluding zero terminator
971 */
972 void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen)
973 {
974 if (ocstr != NULL)
975 {
976 sysname_ptr = ocstr;
977 sysname_len_ptr = ocstrlen;
978 }
979 }
980
981 /**
982 * Initializes sysLocation pointers,
983 * e.g. ptrs to non-volatile memory external to lwIP.
984 *
985 * @param ocstr if non-NULL then copy str pointer
986 * @param ocstrlen points to string length, excluding zero terminator
987 */
988 void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen)
989 {
990 if (ocstr != NULL)
991 {
992 syslocation_ptr = ocstr;
993 syslocation_len_ptr = ocstrlen;
994 }
995 }
996
997
998 void snmp_add_ifinoctets(struct netif *ni, u32_t value)
999 {
1000 ni->ifinoctets += value;
1001 }
1002
1003 void snmp_inc_ifinucastpkts(struct netif *ni)
1004 {
1005 (ni->ifinucastpkts)++;
1006 }
1007
1008 void snmp_inc_ifinnucastpkts(struct netif *ni)
1009 {
1010 (ni->ifinnucastpkts)++;
1011 }
1012
1013 void snmp_inc_ifindiscards(struct netif *ni)
1014 {
1015 (ni->ifindiscards)++;
1016 }
1017
1018 void snmp_add_ifoutoctets(struct netif *ni, u32_t value)
1019 {
1020 ni->ifoutoctets += value;
1021 }
1022
1023 void snmp_inc_ifoutucastpkts(struct netif *ni)
1024 {
1025 (ni->ifoutucastpkts)++;
1026 }
1027
1028 void snmp_inc_ifoutnucastpkts(struct netif *ni)
1029 {
1030 (ni->ifoutnucastpkts)++;
1031 }
1032
1033 void snmp_inc_ifoutdiscards(struct netif *ni)
1034 {
1035 (ni->ifoutdiscards)++;
1036 }
1037
1038 void snmp_inc_iflist(void)
1039 {
1040 struct mib_list_node *if_node = NULL;
1041
1042 snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node);
1043 /* enable getnext traversal on filled table */
1044 iftable.maxlength = 1;
1045 }
1046
1047 void snmp_dec_iflist(void)
1048 {
1049 snmp_mib_node_delete(&iflist_root, iflist_root.tail);
1050 /* disable getnext traversal on empty table */
1051 if(iflist_root.count == 0) iftable.maxlength = 0;
1052 }
1053
1054 /**
1055 * Inserts ARP table indexes (.xIfIndex.xNetAddress)
1056 * into arp table index trees (both atTable and ipNetToMediaTable).
1057 */
1058 void snmp_insert_arpidx_tree(struct netif *ni, ip_addr_t *ip)
1059 {
1060 struct mib_list_rootnode *at_rn;
1061 struct mib_list_node *at_node;
1062 s32_t arpidx[5];
1063 u8_t level, tree;
1064
1065 LWIP_ASSERT("ni != NULL", ni != NULL);
1066 snmp_netiftoifindex(ni, &arpidx[0]);
1067 snmp_iptooid(ip, &arpidx[1]);
1068
1069 for (tree = 0; tree < 2; tree++)
1070 {
1071 if (tree == 0)
1072 {
1073 at_rn = &arptree_root;
1074 }
1075 else
1076 {
1077 at_rn = &ipntomtree_root;
1078 }
1079 for (level = 0; level < 5; level++)
1080 {
1081 at_node = NULL;
1082 snmp_mib_node_insert(at_rn, arpidx[level], &at_node);
1083 if ((level != 4) && (at_node != NULL))
1084 {
1085 if (at_node->nptr == NULL)
1086 {
1087 at_rn = snmp_mib_lrn_alloc();
1088 at_node->nptr = (struct mib_node*)at_rn;
1089 if (at_rn != NULL)
1090 {
1091 if (level == 3)
1092 {
1093 if (tree == 0)
1094 {
1095 at_rn->get_object_def = atentry_get_object_def;
1096 at_rn->get_value = atentry_get_value;
1097 }
1098 else
1099 {
1100 at_rn->get_object_def = ip_ntomentry_get_object_def;
1101 at_rn->get_value = ip_ntomentry_get_value;
1102 }
1103 at_rn->set_test = noleafs_set_test;
1104 at_rn->set_value = noleafs_set_value;
1105 }
1106 }
1107 else
1108 {
1109 /* at_rn == NULL, malloc failure */
1110 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full"));
1111 break;
1112 }
1113 }
1114 else
1115 {
1116 at_rn = (struct mib_list_rootnode*)at_node->nptr;
1117 }
1118 }
1119 }
1120 }
1121 /* enable getnext traversal on filled tables */
1122 at.maxlength = 1;
1123 ipntomtable.maxlength = 1;
1124 }
1125
1126 /**
1127 * Removes ARP table indexes (.xIfIndex.xNetAddress)
1128 * from arp table index trees.
1129 */
1130 void snmp_delete_arpidx_tree(struct netif *ni, ip_addr_t *ip)
1131 {
1132 struct mib_list_rootnode *at_rn, *next, *del_rn[5];
1133 struct mib_list_node *at_n, *del_n[5];
1134 s32_t arpidx[5];
1135 u8_t fc, tree, level, del_cnt;
1136
1137 snmp_netiftoifindex(ni, &arpidx[0]);
1138 snmp_iptooid(ip, &arpidx[1]);
1139
1140 for (tree = 0; tree < 2; tree++)
1141 {
1142 /* mark nodes for deletion */
1143 if (tree == 0)
1144 {
1145 at_rn = &arptree_root;
1146 }
1147 else
1148 {
1149 at_rn = &ipntomtree_root;
1150 }
1151 level = 0;
1152 del_cnt = 0;
1153 while ((level < 5) && (at_rn != NULL))
1154 {
1155 fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n);
1156 if (fc == 0)
1157 {
1158 /* arpidx[level] does not exist */
1159 del_cnt = 0;
1160 at_rn = NULL;
1161 }
1162 else if (fc == 1)
1163 {
1164 del_rn[del_cnt] = at_rn;
1165 del_n[del_cnt] = at_n;
1166 del_cnt++;
1167 at_rn = (struct mib_list_rootnode*)(at_n->nptr);
1168 }
1169 else if (fc == 2)
1170 {
1171 /* reset delete (2 or more childs) */
1172 del_cnt = 0;
1173 at_rn = (struct mib_list_rootnode*)(at_n->nptr);
1174 }
1175 level++;
1176 }
1177 /* delete marked index nodes */
1178 while (del_cnt > 0)
1179 {
1180 del_cnt--;
1181
1182 at_rn = del_rn[del_cnt];
1183 at_n = del_n[del_cnt];
1184
1185 next = snmp_mib_node_delete(at_rn, at_n);
1186 if (next != NULL)
1187 {
1188 LWIP_ASSERT("next_count == 0",next->count == 0);
1189 snmp_mib_lrn_free(next);
1190 }
1191 }
1192 }
1193 /* disable getnext traversal on empty tables */
1194 if(arptree_root.count == 0) at.maxlength = 0;
1195 if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0;
1196 }
1197
1198 void snmp_inc_ipinreceives(void)
1199 {
1200 ipinreceives++;
1201 }
1202
1203 void snmp_inc_ipinhdrerrors(void)
1204 {
1205 ipinhdrerrors++;
1206 }
1207
1208 void snmp_inc_ipinaddrerrors(void)
1209 {
1210 ipinaddrerrors++;
1211 }
1212
1213 void snmp_inc_ipforwdatagrams(void)
1214 {
1215 ipforwdatagrams++;
1216 }
1217
1218 void snmp_inc_ipinunknownprotos(void)
1219 {
1220 ipinunknownprotos++;
1221 }
1222
1223 void snmp_inc_ipindiscards(void)
1224 {
1225 ipindiscards++;
1226 }
1227
1228 void snmp_inc_ipindelivers(void)
1229 {
1230 ipindelivers++;
1231 }
1232
1233 void snmp_inc_ipoutrequests(void)
1234 {
1235 ipoutrequests++;
1236 }
1237
1238 void snmp_inc_ipoutdiscards(void)
1239 {
1240 ipoutdiscards++;
1241 }
1242
1243 void snmp_inc_ipoutnoroutes(void)
1244 {
1245 ipoutnoroutes++;
1246 }
1247
1248 void snmp_inc_ipreasmreqds(void)
1249 {
1250 ipreasmreqds++;
1251 }
1252
1253 void snmp_inc_ipreasmoks(void)
1254 {
1255 ipreasmoks++;
1256 }
1257
1258 void snmp_inc_ipreasmfails(void)
1259 {
1260 ipreasmfails++;
1261 }
1262
1263 void snmp_inc_ipfragoks(void)
1264 {
1265 ipfragoks++;
1266 }
1267
1268 void snmp_inc_ipfragfails(void)
1269 {
1270 ipfragfails++;
1271 }
1272
1273 void snmp_inc_ipfragcreates(void)
1274 {
1275 ipfragcreates++;
1276 }
1277
1278 void snmp_inc_iproutingdiscards(void)
1279 {
1280 iproutingdiscards++;
1281 }
1282
1283 /**
1284 * Inserts ipAddrTable indexes (.ipAdEntAddr)
1285 * into index tree.
1286 */
1287 void snmp_insert_ipaddridx_tree(struct netif *ni)
1288 {
1289 struct mib_list_rootnode *ipa_rn;
1290 struct mib_list_node *ipa_node;
1291 s32_t ipaddridx[4];
1292 u8_t level;
1293
1294 LWIP_ASSERT("ni != NULL", ni != NULL);
1295 snmp_iptooid(&ni->ip_addr, &ipaddridx[0]);
1296
1297 level = 0;
1298 ipa_rn = &ipaddrtree_root;
1299 while (level < 4)
1300 {
1301 ipa_node = NULL;
1302 snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node);
1303 if ((level != 3) && (ipa_node != NULL))
1304 {
1305 if (ipa_node->nptr == NULL)
1306 {
1307 ipa_rn = snmp_mib_lrn_alloc();
1308 ipa_node->nptr = (struct mib_node*)ipa_rn;
1309 if (ipa_rn != NULL)
1310 {
1311 if (level == 2)
1312 {
1313 ipa_rn->get_object_def = ip_addrentry_get_object_def;
1314 ipa_rn->get_value = ip_addrentry_get_value;
1315 ipa_rn->set_test = noleafs_set_test;
1316 ipa_rn->set_value = noleafs_set_value;
1317 }
1318 }
1319 else
1320 {
1321 /* ipa_rn == NULL, malloc failure */
1322 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full"));
1323 break;
1324 }
1325 }
1326 else
1327 {
1328 ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr;
1329 }
1330 }
1331 level++;
1332 }
1333 /* enable getnext traversal on filled table */
1334 ipaddrtable.maxlength = 1;
1335 }
1336
1337 /**
1338 * Removes ipAddrTable indexes (.ipAdEntAddr)
1339 * from index tree.
1340 */
1341 void snmp_delete_ipaddridx_tree(struct netif *ni)
1342 {
1343 struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];
1344 struct mib_list_node *ipa_n, *del_n[4];
1345 s32_t ipaddridx[4];
1346 u8_t fc, level, del_cnt;
1347
1348 LWIP_ASSERT("ni != NULL", ni != NULL);
1349 snmp_iptooid(&ni->ip_addr, &ipaddridx[0]);
1350
1351 /* mark nodes for deletion */
1352 level = 0;
1353 del_cnt = 0;
1354 ipa_rn = &ipaddrtree_root;
1355 while ((level < 4) && (ipa_rn != NULL))
1356 {
1357 fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n);
1358 if (fc == 0)
1359 {
1360 /* ipaddridx[level] does not exist */
1361 del_cnt = 0;
1362 ipa_rn = NULL;
1363 }
1364 else if (fc == 1)
1365 {
1366 del_rn[del_cnt] = ipa_rn;
1367 del_n[del_cnt] = ipa_n;
1368 del_cnt++;
1369 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
1370 }
1371 else if (fc == 2)
1372 {
1373 /* reset delete (2 or more childs) */
1374 del_cnt = 0;
1375 ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
1376 }
1377 level++;
1378 }
1379 /* delete marked index nodes */
1380 while (del_cnt > 0)
1381 {
1382 del_cnt--;
1383
1384 ipa_rn = del_rn[del_cnt];
1385 ipa_n = del_n[del_cnt];
1386
1387 next = snmp_mib_node_delete(ipa_rn, ipa_n);
1388 if (next != NULL)
1389 {
1390 LWIP_ASSERT("next_count == 0",next->count == 0);
1391 snmp_mib_lrn_free(next);
1392 }
1393 }
1394 /* disable getnext traversal on empty table */
1395 if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0;
1396 }
1397
1398 /**
1399 * Inserts ipRouteTable indexes (.ipRouteDest)
1400 * into index tree.
1401 *
1402 * @param dflt non-zero for the default rte, zero for network rte
1403 * @param ni points to network interface for this rte
1404 *
1405 * @todo record sysuptime for _this_ route when it is installed
1406 * (needed for ipRouteAge) in the netif.
1407 */
1408 void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
1409 {
1410 u8_t insert = 0;
1411 ip_addr_t dst;
1412
1413 if (dflt != 0)
1414 {
1415 /* the default route 0.0.0.0 */
1416 ip_addr_set_any(&dst);
1417 insert = 1;
1418 }
1419 else
1420 {
1421 /* route to the network address */
1422 ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
1423 /* exclude 0.0.0.0 network (reserved for default rte) */
1424 if (!ip_addr_isany(&dst)) {
1425 insert = 1;
1426 }
1427 }
1428 if (insert)
1429 {
1430 struct mib_list_rootnode *iprte_rn;
1431 struct mib_list_node *iprte_node;
1432 s32_t iprteidx[4];
1433 u8_t level;
1434
1435 snmp_iptooid(&dst, &iprteidx[0]);
1436 level = 0;
1437 iprte_rn = &iprtetree_root;
1438 while (level < 4)
1439 {
1440 iprte_node = NULL;
1441 snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node);
1442 if ((level != 3) && (iprte_node != NULL))
1443 {
1444 if (iprte_node->nptr == NULL)
1445 {
1446 iprte_rn = snmp_mib_lrn_alloc();
1447 iprte_node->nptr = (struct mib_node*)iprte_rn;
1448 if (iprte_rn != NULL)
1449 {
1450 if (level == 2)
1451 {
1452 iprte_rn->get_object_def = ip_rteentry_get_object_def;
1453 iprte_rn->get_value = ip_rteentry_get_value;
1454 iprte_rn->set_test = noleafs_set_test;
1455 iprte_rn->set_value = noleafs_set_value;
1456 }
1457 }
1458 else
1459 {
1460 /* iprte_rn == NULL, malloc failure */
1461 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full"));
1462 break;
1463 }
1464 }
1465 else
1466 {
1467 iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr;
1468 }
1469 }
1470 level++;
1471 }
1472 }
1473 /* enable getnext traversal on filled table */
1474 iprtetable.maxlength = 1;
1475 }
1476
1477 /**
1478 * Removes ipRouteTable indexes (.ipRouteDest)
1479 * from index tree.
1480 *
1481 * @param dflt non-zero for the default rte, zero for network rte
1482 * @param ni points to network interface for this rte or NULL
1483 * for default route to be removed.
1484 */
1485 void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
1486 {
1487 u8_t del = 0;
1488 ip_addr_t dst;
1489
1490 if (dflt != 0)
1491 {
1492 /* the default route 0.0.0.0 */
1493 ip_addr_set_any(&dst);
1494 del = 1;
1495 }
1496 else
1497 {
1498 /* route to the network address */
1499 ip_addr_get_network(&dst, &ni->ip_addr, &ni->netmask);
1500 /* exclude 0.0.0.0 network (reserved for default rte) */
1501 if (!ip_addr_isany(&dst)) {
1502 del = 1;
1503 }
1504 }
1505 if (del)
1506 {
1507 struct mib_list_rootnode *iprte_rn, *next, *del_rn[4];
1508 struct mib_list_node *iprte_n, *del_n[4];
1509 s32_t iprteidx[4];
1510 u8_t fc, level, del_cnt;
1511
1512 snmp_iptooid(&dst, &iprteidx[0]);
1513 /* mark nodes for deletion */
1514 level = 0;
1515 del_cnt = 0;
1516 iprte_rn = &iprtetree_root;
1517 while ((level < 4) && (iprte_rn != NULL))
1518 {
1519 fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n);
1520 if (fc == 0)
1521 {
1522 /* iprteidx[level] does not exist */
1523 del_cnt = 0;
1524 iprte_rn = NULL;
1525 }
1526 else if (fc == 1)
1527 {
1528 del_rn[del_cnt] = iprte_rn;
1529 del_n[del_cnt] = iprte_n;
1530 del_cnt++;
1531 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
1532 }
1533 else if (fc == 2)
1534 {
1535 /* reset delete (2 or more childs) */
1536 del_cnt = 0;
1537 iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
1538 }
1539 level++;
1540 }
1541 /* delete marked index nodes */
1542 while (del_cnt > 0)
1543 {
1544 del_cnt--;
1545
1546 iprte_rn = del_rn[del_cnt];
1547 iprte_n = del_n[del_cnt];
1548
1549 next = snmp_mib_node_delete(iprte_rn, iprte_n);
1550 if (next != NULL)
1551 {
1552 LWIP_ASSERT("next_count == 0",next->count == 0);
1553 snmp_mib_lrn_free(next);
1554 }
1555 }
1556 }
1557 /* disable getnext traversal on empty table */
1558 if (iprtetree_root.count == 0) iprtetable.maxlength = 0;
1559 }
1560
1561
1562 void snmp_inc_icmpinmsgs(void)
1563 {
1564 icmpinmsgs++;
1565 }
1566
1567 void snmp_inc_icmpinerrors(void)
1568 {
1569 icmpinerrors++;
1570 }
1571
1572 void snmp_inc_icmpindestunreachs(void)
1573 {
1574 icmpindestunreachs++;
1575 }
1576
1577 void snmp_inc_icmpintimeexcds(void)
1578 {
1579 icmpintimeexcds++;
1580 }
1581
1582 void snmp_inc_icmpinparmprobs(void)
1583 {
1584 icmpinparmprobs++;
1585 }
1586
1587 void snmp_inc_icmpinsrcquenchs(void)
1588 {
1589 icmpinsrcquenchs++;
1590 }
1591
1592 void snmp_inc_icmpinredirects(void)
1593 {
1594 icmpinredirects++;
1595 }
1596
1597 void snmp_inc_icmpinechos(void)
1598 {
1599 icmpinechos++;
1600 }
1601
1602 void snmp_inc_icmpinechoreps(void)
1603 {
1604 icmpinechoreps++;
1605 }
1606
1607 void snmp_inc_icmpintimestamps(void)
1608 {
1609 icmpintimestamps++;
1610 }
1611
1612 void snmp_inc_icmpintimestampreps(void)
1613 {
1614 icmpintimestampreps++;
1615 }
1616
1617 void snmp_inc_icmpinaddrmasks(void)
1618 {
1619 icmpinaddrmasks++;
1620 }
1621
1622 void snmp_inc_icmpinaddrmaskreps(void)
1623 {
1624 icmpinaddrmaskreps++;
1625 }
1626
1627 void snmp_inc_icmpoutmsgs(void)
1628 {
1629 icmpoutmsgs++;
1630 }
1631
1632 void snmp_inc_icmpouterrors(void)
1633 {
1634 icmpouterrors++;
1635 }
1636
1637 void snmp_inc_icmpoutdestunreachs(void)
1638 {
1639 icmpoutdestunreachs++;
1640 }
1641
1642 void snmp_inc_icmpouttimeexcds(void)
1643 {
1644 icmpouttimeexcds++;
1645 }
1646
1647 void snmp_inc_icmpoutparmprobs(void)
1648 {
1649 icmpoutparmprobs++;
1650 }
1651
1652 void snmp_inc_icmpoutsrcquenchs(void)
1653 {
1654 icmpoutsrcquenchs++;
1655 }
1656
1657 void snmp_inc_icmpoutredirects(void)
1658 {
1659 icmpoutredirects++;
1660 }
1661
1662 void snmp_inc_icmpoutechos(void)
1663 {
1664 icmpoutechos++;
1665 }
1666
1667 void snmp_inc_icmpoutechoreps(void)
1668 {
1669 icmpoutechoreps++;
1670 }
1671
1672 void snmp_inc_icmpouttimestamps(void)
1673 {
1674 icmpouttimestamps++;
1675 }
1676
1677 void snmp_inc_icmpouttimestampreps(void)
1678 {
1679 icmpouttimestampreps++;
1680 }
1681
1682 void snmp_inc_icmpoutaddrmasks(void)
1683 {
1684 icmpoutaddrmasks++;
1685 }
1686
1687 void snmp_inc_icmpoutaddrmaskreps(void)
1688 {
1689 icmpoutaddrmaskreps++;
1690 }
1691
1692 void snmp_inc_tcpactiveopens(void)
1693 {
1694 tcpactiveopens++;
1695 }
1696
1697 void snmp_inc_tcppassiveopens(void)
1698 {
1699 tcppassiveopens++;
1700 }
1701
1702 void snmp_inc_tcpattemptfails(void)
1703 {
1704 tcpattemptfails++;
1705 }
1706
1707 void snmp_inc_tcpestabresets(void)
1708 {
1709 tcpestabresets++;
1710 }
1711
1712 void snmp_inc_tcpinsegs(void)
1713 {
1714 tcpinsegs++;
1715 }
1716
1717 void snmp_inc_tcpoutsegs(void)
1718 {
1719 tcpoutsegs++;
1720 }
1721
1722 void snmp_inc_tcpretranssegs(void)
1723 {
1724 tcpretranssegs++;
1725 }
1726
1727 void snmp_inc_tcpinerrs(void)
1728 {
1729 tcpinerrs++;
1730 }
1731
1732 void snmp_inc_tcpoutrsts(void)
1733 {
1734 tcpoutrsts++;
1735 }
1736
1737 void snmp_inc_udpindatagrams(void)
1738 {
1739 udpindatagrams++;
1740 }
1741
1742 void snmp_inc_udpnoports(void)
1743 {
1744 udpnoports++;
1745 }
1746
1747 void snmp_inc_udpinerrors(void)
1748 {
1749 udpinerrors++;
1750 }
1751
1752 void snmp_inc_udpoutdatagrams(void)
1753 {
1754 udpoutdatagrams++;
1755 }
1756
1757 /**
1758 * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort)
1759 * into index tree.
1760 */
1761 void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
1762 {
1763 struct mib_list_rootnode *udp_rn;
1764 struct mib_list_node *udp_node;
1765 s32_t udpidx[5];
1766 u8_t level;
1767
1768 LWIP_ASSERT("pcb != NULL", pcb != NULL);
1769 snmp_iptooid(ipX_2_ip(&pcb->local_ip), &udpidx[0]);
1770 udpidx[4] = pcb->local_port;
1771
1772 udp_rn = &udp_root;
1773 for (level = 0; level < 5; level++)
1774 {
1775 udp_node = NULL;
1776 snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node);
1777 if ((level != 4) && (udp_node != NULL))
1778 {
1779 if (udp_node->nptr == NULL)
1780 {
1781 udp_rn = snmp_mib_lrn_alloc();
1782 udp_node->nptr = (struct mib_node*)udp_rn;
1783 if (udp_rn != NULL)
1784 {
1785 if (level == 3)
1786 {
1787 udp_rn->get_object_def = udpentry_get_object_def;
1788 udp_rn->get_value = udpentry_get_value;
1789 udp_rn->set_test = noleafs_set_test;
1790 udp_rn->set_value = noleafs_set_value;
1791 }
1792 }
1793 else
1794 {
1795 /* udp_rn == NULL, malloc failure */
1796 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full"));
1797 break;
1798 }
1799 }
1800 else
1801 {
1802 udp_rn = (struct mib_list_rootnode*)udp_node->nptr;
1803 }
1804 }
1805 }
1806 udptable.maxlength = 1;
1807 }
1808
1809 /**
1810 * Removes udpTable indexes (.udpLocalAddress.udpLocalPort)
1811 * from index tree.
1812 */
1813 void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
1814 {
1815 struct udp_pcb *npcb;
1816 struct mib_list_rootnode *udp_rn, *next, *del_rn[5];
1817 struct mib_list_node *udp_n, *del_n[5];
1818 s32_t udpidx[5];
1819 u8_t bindings, fc, level, del_cnt;
1820
1821 LWIP_ASSERT("pcb != NULL", pcb != NULL);
1822 snmp_iptooid(ipX_2_ip(&pcb->local_ip), &udpidx[0]);
1823 udpidx[4] = pcb->local_port;
1824
1825 /* count PCBs for a given binding
1826 (e.g. when reusing ports or for temp output PCBs) */
1827 bindings = 0;
1828 npcb = udp_pcbs;
1829 while ((npcb != NULL))
1830 {
1831 if (ipX_addr_cmp(0, &npcb->local_ip, &pcb->local_ip) &&
1832 (npcb->local_port == udpidx[4]))
1833 {
1834 bindings++;
1835 }
1836 npcb = npcb->next;
1837 }
1838 if (bindings == 1)
1839 {
1840 /* selectively remove */
1841 /* mark nodes for deletion */
1842 level = 0;
1843 del_cnt = 0;
1844 udp_rn = &udp_root;
1845 while ((level < 5) && (udp_rn != NULL))
1846 {
1847 fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n);
1848 if (fc == 0)
1849 {
1850 /* udpidx[level] does not exist */
1851 del_cnt = 0;
1852 udp_rn = NULL;
1853 }
1854 else if (fc == 1)
1855 {
1856 del_rn[del_cnt] = udp_rn;
1857 del_n[del_cnt] = udp_n;
1858 del_cnt++;
1859 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
1860 }
1861 else if (fc == 2)
1862 {
1863 /* reset delete (2 or more childs) */
1864 del_cnt = 0;
1865 udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
1866 }
1867 level++;
1868 }
1869 /* delete marked index nodes */
1870 while (del_cnt > 0)
1871 {
1872 del_cnt--;
1873
1874 udp_rn = del_rn[del_cnt];
1875 udp_n = del_n[del_cnt];
1876
1877 next = snmp_mib_node_delete(udp_rn, udp_n);
1878 if (next != NULL)
1879 {
1880 LWIP_ASSERT("next_count == 0",next->count == 0);
1881 snmp_mib_lrn_free(next);
1882 }
1883 }
1884 }
1885 /* disable getnext traversal on empty table */
1886 if (udp_root.count == 0) udptable.maxlength = 0;
1887 }
1888
1889
1890 void snmp_inc_snmpinpkts(void)
1891 {
1892 snmpinpkts++;
1893 }
1894
1895 void snmp_inc_snmpoutpkts(void)
1896 {
1897 snmpoutpkts++;
1898 }
1899
1900 void snmp_inc_snmpinbadversions(void)
1901 {
1902 snmpinbadversions++;
1903 }
1904
1905 void snmp_inc_snmpinbadcommunitynames(void)
1906 {
1907 snmpinbadcommunitynames++;
1908 }
1909
1910 void snmp_inc_snmpinbadcommunityuses(void)
1911 {
1912 snmpinbadcommunityuses++;
1913 }
1914
1915 void snmp_inc_snmpinasnparseerrs(void)
1916 {
1917 snmpinasnparseerrs++;
1918 }
1919
1920 void snmp_inc_snmpintoobigs(void)
1921 {
1922 snmpintoobigs++;
1923 }
1924
1925 void snmp_inc_snmpinnosuchnames(void)
1926 {
1927 snmpinnosuchnames++;
1928 }
1929
1930 void snmp_inc_snmpinbadvalues(void)
1931 {
1932 snmpinbadvalues++;
1933 }
1934
1935 void snmp_inc_snmpinreadonlys(void)
1936 {
1937 snmpinreadonlys++;
1938 }
1939
1940 void snmp_inc_snmpingenerrs(void)
1941 {
1942 snmpingenerrs++;
1943 }
1944
1945 void snmp_add_snmpintotalreqvars(u8_t value)
1946 {
1947 snmpintotalreqvars += value;
1948 }
1949
1950 void snmp_add_snmpintotalsetvars(u8_t value)
1951 {
1952 snmpintotalsetvars += value;
1953 }
1954
1955 void snmp_inc_snmpingetrequests(void)
1956 {
1957 snmpingetrequests++;
1958 }
1959
1960 void snmp_inc_snmpingetnexts(void)
1961 {
1962 snmpingetnexts++;
1963 }
1964
1965 void snmp_inc_snmpinsetrequests(void)
1966 {
1967 snmpinsetrequests++;
1968 }
1969
1970 void snmp_inc_snmpingetresponses(void)
1971 {
1972 snmpingetresponses++;
1973 }
1974
1975 void snmp_inc_snmpintraps(void)
1976 {
1977 snmpintraps++;
1978 }
1979
1980 void snmp_inc_snmpouttoobigs(void)
1981 {
1982 snmpouttoobigs++;
1983 }
1984
1985 void snmp_inc_snmpoutnosuchnames(void)
1986 {
1987 snmpoutnosuchnames++;
1988 }
1989
1990 void snmp_inc_snmpoutbadvalues(void)
1991 {
1992 snmpoutbadvalues++;
1993 }
1994
1995 void snmp_inc_snmpoutgenerrs(void)
1996 {
1997 snmpoutgenerrs++;
1998 }
1999
2000 void snmp_inc_snmpoutgetrequests(void)
2001 {
2002 snmpoutgetrequests++;
2003 }
2004
2005 void snmp_inc_snmpoutgetnexts(void)
2006 {
2007 snmpoutgetnexts++;
2008 }
2009
2010 void snmp_inc_snmpoutsetrequests(void)
2011 {
2012 snmpoutsetrequests++;
2013 }
2014
2015 void snmp_inc_snmpoutgetresponses(void)
2016 {
2017 snmpoutgetresponses++;
2018 }
2019
2020 void snmp_inc_snmpouttraps(void)
2021 {
2022 snmpouttraps++;
2023 }
2024
2025 void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)
2026 {
2027 *oid = &snmpgrp_id;
2028 }
2029
2030 void snmp_set_snmpenableauthentraps(u8_t *value)
2031 {
2032 if (value != NULL)
2033 {
2034 snmpenableauthentraps_ptr = value;
2035 }
2036 }
2037
2038 void snmp_get_snmpenableauthentraps(u8_t *value)
2039 {
2040 *value = *snmpenableauthentraps_ptr;
2041 }
2042
2043 void
2044 noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2045 {
2046 LWIP_UNUSED_ARG(ident_len);
2047 LWIP_UNUSED_ARG(ident);
2048 od->instance = MIB_OBJECT_NONE;
2049 }
2050
2051 void
2052 noleafs_get_value(struct obj_def *od, u16_t len, void *value)
2053 {
2054 LWIP_UNUSED_ARG(od);
2055 LWIP_UNUSED_ARG(len);
2056 LWIP_UNUSED_ARG(value);
2057 }
2058
2059 u8_t
2060 noleafs_set_test(struct obj_def *od, u16_t len, void *value)
2061 {
2062 LWIP_UNUSED_ARG(od);
2063 LWIP_UNUSED_ARG(len);
2064 LWIP_UNUSED_ARG(value);
2065 /* can't set */
2066 return 0;
2067 }
2068
2069 void
2070 noleafs_set_value(struct obj_def *od, u16_t len, void *value)
2071 {
2072 LWIP_UNUSED_ARG(od);
2073 LWIP_UNUSED_ARG(len);
2074 LWIP_UNUSED_ARG(value);
2075 }
2076
2077
2078 /**
2079 * Returns systems object definitions.
2080 *
2081 * @param ident_len the address length (2)
2082 * @param ident points to objectname.0 (object id trailer)
2083 * @param od points to object definition.
2084 */
2085 static void
2086 system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2087 {
2088 u8_t id;
2089
2090 /* return to object name, adding index depth (1) */
2091 ident_len += 1;
2092 ident -= 1;
2093 if (ident_len == 2)
2094 {
2095 od->id_inst_len = ident_len;
2096 od->id_inst_ptr = ident;
2097
2098 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
2099 id = (u8_t)ident[0];
2100 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id));
2101 switch (id)
2102 {
2103 case 1: /* sysDescr */
2104 od->instance = MIB_OBJECT_SCALAR;
2105 od->access = MIB_OBJECT_READ_ONLY;
2106 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2107 od->v_len = *sysdescr_len_ptr;
2108 break;
2109 case 2: /* sysObjectID */
2110 od->instance = MIB_OBJECT_SCALAR;
2111 od->access = MIB_OBJECT_READ_ONLY;
2112 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
2113 od->v_len = sysobjid_ptr->len * sizeof(s32_t);
2114 break;
2115 case 3: /* sysUpTime */
2116 od->instance = MIB_OBJECT_SCALAR;
2117 od->access = MIB_OBJECT_READ_ONLY;
2118 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
2119 od->v_len = sizeof(u32_t);
2120 break;
2121 case 4: /* sysContact */
2122 od->instance = MIB_OBJECT_SCALAR;
2123 od->access = MIB_OBJECT_READ_WRITE;
2124 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2125 od->v_len = *syscontact_len_ptr;
2126 break;
2127 case 5: /* sysName */
2128 od->instance = MIB_OBJECT_SCALAR;
2129 od->access = MIB_OBJECT_READ_WRITE;
2130 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2131 od->v_len = *sysname_len_ptr;
2132 break;
2133 case 6: /* sysLocation */
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 = *syslocation_len_ptr;
2138 break;
2139 case 7: /* sysServices */
2140 od->instance = MIB_OBJECT_SCALAR;
2141 od->access = MIB_OBJECT_READ_ONLY;
2142 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2143 od->v_len = sizeof(s32_t);
2144 break;
2145 default:
2146 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n"));
2147 od->instance = MIB_OBJECT_NONE;
2148 break;
2149 };
2150 }
2151 else
2152 {
2153 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n"));
2154 od->instance = MIB_OBJECT_NONE;
2155 }
2156 }
2157
2158 /**
2159 * Returns system object value.
2160 *
2161 * @param ident_len the address length (2)
2162 * @param ident points to objectname.0 (object id trailer)
2163 * @param len return value space (in bytes)
2164 * @param value points to (varbind) space to copy value into.
2165 */
2166 static void
2167 system_get_value(struct obj_def *od, u16_t len, void *value)
2168 {
2169 u8_t id;
2170
2171 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2172 id = (u8_t)od->id_inst_ptr[0];
2173 switch (id)
2174 {
2175 case 1: /* sysDescr */
2176 MEMCPY(value, sysdescr_ptr, len);
2177 break;
2178 case 2: /* sysObjectID */
2179 MEMCPY(value, sysobjid_ptr->id, len);
2180 break;
2181 case 3: /* sysUpTime */
2182 {
2183 snmp_get_sysuptime((u32_t*)value);
2184 }
2185 break;
2186 case 4: /* sysContact */
2187 MEMCPY(value, syscontact_ptr, len);
2188 break;
2189 case 5: /* sysName */
2190 MEMCPY(value, sysname_ptr, len);
2191 break;
2192 case 6: /* sysLocation */
2193 MEMCPY(value, syslocation_ptr, len);
2194 break;
2195 case 7: /* sysServices */
2196 {
2197 s32_t *sint_ptr = (s32_t*)value;
2198 *sint_ptr = sysservices;
2199 }
2200 break;
2201 default:
2202 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_value(): unknown id: %d\n", id));
2203 break;
2204 };
2205 }
2206
2207 static u8_t
2208 system_set_test(struct obj_def *od, u16_t len, void *value)
2209 {
2210 u8_t id, set_ok;
2211
2212 LWIP_UNUSED_ARG(value);
2213 set_ok = 0;
2214 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2215 id = (u8_t)od->id_inst_ptr[0];
2216 switch (id)
2217 {
2218 case 4: /* sysContact */
2219 if ((syscontact_ptr != syscontact_default) &&
2220 (len <= 255))
2221 {
2222 set_ok = 1;
2223 }
2224 break;
2225 case 5: /* sysName */
2226 if ((sysname_ptr != sysname_default) &&
2227 (len <= 255))
2228 {
2229 set_ok = 1;
2230 }
2231 break;
2232 case 6: /* sysLocation */
2233 if ((syslocation_ptr != syslocation_default) &&
2234 (len <= 255))
2235 {
2236 set_ok = 1;
2237 }
2238 break;
2239 default:
2240 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_test(): unknown id: %d\n", id));
2241 break;
2242 };
2243 return set_ok;
2244 }
2245
2246 static void
2247 system_set_value(struct obj_def *od, u16_t len, void *value)
2248 {
2249 u8_t id;
2250
2251 LWIP_ASSERT("invalid len", len <= 0xff);
2252 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2253 id = (u8_t)od->id_inst_ptr[0];
2254 switch (id)
2255 {
2256 case 4: /* sysContact */
2257 MEMCPY(syscontact_ptr, value, len);
2258 *syscontact_len_ptr = (u8_t)len;
2259 break;
2260 case 5: /* sysName */
2261 MEMCPY(sysname_ptr, value, len);
2262 *sysname_len_ptr = (u8_t)len;
2263 break;
2264 case 6: /* sysLocation */
2265 MEMCPY(syslocation_ptr, value, len);
2266 *syslocation_len_ptr = (u8_t)len;
2267 break;
2268 default:
2269 LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_value(): unknown id: %d\n", id));
2270 break;
2271 };
2272 }
2273
2274 /**
2275 * Returns interfaces.ifnumber object definition.
2276 *
2277 * @param ident_len the address length (2)
2278 * @param ident points to objectname.index
2279 * @param od points to object definition.
2280 */
2281 static void
2282 interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2283 {
2284 /* return to object name, adding index depth (1) */
2285 ident_len += 1;
2286 ident -= 1;
2287 if (ident_len == 2)
2288 {
2289 od->id_inst_len = ident_len;
2290 od->id_inst_ptr = ident;
2291
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);
2296 }
2297 else
2298 {
2299 LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n"));
2300 od->instance = MIB_OBJECT_NONE;
2301 }
2302 }
2303
2304 /**
2305 * Returns interfaces.ifnumber object value.
2306 *
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.
2311 */
2312 static void
2313 interfaces_get_value(struct obj_def *od, u16_t len, void *value)
2314 {
2315 LWIP_UNUSED_ARG(len);
2316 if (od->id_inst_ptr[0] == 1)
2317 {
2318 s32_t *sint_ptr = (s32_t*)value;
2319 *sint_ptr = iflist_root.count;
2320 }
2321 }
2322
2323 /**
2324 * Returns ifentry object definitions.
2325 *
2326 * @param ident_len the address length (2)
2327 * @param ident points to objectname.index
2328 * @param od points to object definition.
2329 */
2330 static void
2331 ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2332 {
2333 u8_t id;
2334
2335 /* return to object name, adding index depth (1) */
2336 ident_len += 1;
2337 ident -= 1;
2338 if (ident_len == 2)
2339 {
2340 od->id_inst_len = ident_len;
2341 od->id_inst_ptr = ident;
2342
2343 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
2344 id = (u8_t)ident[0];
2345 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id));
2346 switch (id)
2347 {
2348 case 1: /* ifIndex */
2349 case 3: /* ifType */
2350 case 4: /* ifMtu */
2351 case 8: /* ifOperStatus */
2352 od->instance = MIB_OBJECT_TAB;
2353 od->access = MIB_OBJECT_READ_ONLY;
2354 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2355 od->v_len = sizeof(s32_t);
2356 break;
2357 case 2: /* ifDescr */
2358 od->instance = MIB_OBJECT_TAB;
2359 od->access = MIB_OBJECT_READ_ONLY;
2360 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2361 /** @todo this should be some sort of sizeof(struct netif.name) */
2362 od->v_len = 2;
2363 break;
2364 case 5: /* ifSpeed */
2365 case 21: /* ifOutQLen */
2366 od->instance = MIB_OBJECT_TAB;
2367 od->access = MIB_OBJECT_READ_ONLY;
2368 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
2369 od->v_len = sizeof(u32_t);
2370 break;
2371 case 6: /* ifPhysAddress */
2372 {
2373 struct netif *netif;
2374
2375 snmp_ifindextonetif(ident[1], &netif);
2376 od->instance = MIB_OBJECT_TAB;
2377 od->access = MIB_OBJECT_READ_ONLY;
2378 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2379 od->v_len = netif->hwaddr_len;
2380 }
2381 break;
2382 case 7: /* ifAdminStatus */
2383 od->instance = MIB_OBJECT_TAB;
2384 od->access = MIB_OBJECT_READ_WRITE;
2385 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2386 od->v_len = sizeof(s32_t);
2387 break;
2388 case 9: /* ifLastChange */
2389 od->instance = MIB_OBJECT_TAB;
2390 od->access = MIB_OBJECT_READ_ONLY;
2391 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
2392 od->v_len = sizeof(u32_t);
2393 break;
2394 case 10: /* ifInOctets */
2395 case 11: /* ifInUcastPkts */
2396 case 12: /* ifInNUcastPkts */
2397 case 13: /* ifInDiscarts */
2398 case 14: /* ifInErrors */
2399 case 15: /* ifInUnkownProtos */
2400 case 16: /* ifOutOctets */
2401 case 17: /* ifOutUcastPkts */
2402 case 18: /* ifOutNUcastPkts */
2403 case 19: /* ifOutDiscarts */
2404 case 20: /* ifOutErrors */
2405 od->instance = MIB_OBJECT_TAB;
2406 od->access = MIB_OBJECT_READ_ONLY;
2407 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
2408 od->v_len = sizeof(u32_t);
2409 break;
2410 case 22: /* ifSpecific */
2411 /** @note returning zeroDotZero (0.0) no media specific MIB support */
2412 od->instance = MIB_OBJECT_TAB;
2413 od->access = MIB_OBJECT_READ_ONLY;
2414 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
2415 od->v_len = ifspecific.len * sizeof(s32_t);
2416 break;
2417 default:
2418 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n"));
2419 od->instance = MIB_OBJECT_NONE;
2420 break;
2421 };
2422 }
2423 else
2424 {
2425 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n"));
2426 od->instance = MIB_OBJECT_NONE;
2427 }
2428 }
2429
2430 /**
2431 * Returns ifentry object value.
2432 *
2433 * @param ident_len the address length (2)
2434 * @param ident points to objectname.0 (object id trailer)
2435 * @param len return value space (in bytes)
2436 * @param value points to (varbind) space to copy value into.
2437 */
2438 static void
2439 ifentry_get_value(struct obj_def *od, u16_t len, void *value)
2440 {
2441 struct netif *netif;
2442 u8_t id;
2443
2444 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2445 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2446 id = (u8_t)od->id_inst_ptr[0];
2447 switch (id)
2448 {
2449 case 1: /* ifIndex */
2450 {
2451 s32_t *sint_ptr = (s32_t*)value;
2452 *sint_ptr = od->id_inst_ptr[1];
2453 }
2454 break;
2455 case 2: /* ifDescr */
2456 MEMCPY(value, netif->name, len);
2457 break;
2458 case 3: /* ifType */
2459 {
2460 s32_t *sint_ptr = (s32_t*)value;
2461 *sint_ptr = netif->link_type;
2462 }
2463 break;
2464 case 4: /* ifMtu */
2465 {
2466 s32_t *sint_ptr = (s32_t*)value;
2467 *sint_ptr = netif->mtu;
2468 }
2469 break;
2470 case 5: /* ifSpeed */
2471 {
2472 u32_t *uint_ptr = (u32_t*)value;
2473 *uint_ptr = netif->link_speed;
2474 }
2475 break;
2476 case 6: /* ifPhysAddress */
2477 MEMCPY(value, netif->hwaddr, len);
2478 break;
2479 case 7: /* ifAdminStatus */
2480 {
2481 s32_t *sint_ptr = (s32_t*)value;
2482 if (netif_is_up(netif))
2483 {
2484 if (netif_is_link_up(netif))
2485 {
2486 *sint_ptr = 1; /* up */
2487 }
2488 else
2489 {
2490 *sint_ptr = 7; /* lowerLayerDown */
2491 }
2492 }
2493 else
2494 {
2495 *sint_ptr = 2; /* down */
2496 }
2497 }
2498 break;
2499 case 8: /* ifOperStatus */
2500 {
2501 s32_t *sint_ptr = (s32_t*)value;
2502 if (netif_is_up(netif))
2503 {
2504 *sint_ptr = 1;
2505 }
2506 else
2507 {
2508 *sint_ptr = 2;
2509 }
2510 }
2511 break;
2512 case 9: /* ifLastChange */
2513 {
2514 u32_t *uint_ptr = (u32_t*)value;
2515 *uint_ptr = netif->ts;
2516 }
2517 break;
2518 case 10: /* ifInOctets */
2519 {
2520 u32_t *uint_ptr = (u32_t*)value;
2521 *uint_ptr = netif->ifinoctets;
2522 }
2523 break;
2524 case 11: /* ifInUcastPkts */
2525 {
2526 u32_t *uint_ptr = (u32_t*)value;
2527 *uint_ptr = netif->ifinucastpkts;
2528 }
2529 break;
2530 case 12: /* ifInNUcastPkts */
2531 {
2532 u32_t *uint_ptr = (u32_t*)value;
2533 *uint_ptr = netif->ifinnucastpkts;
2534 }
2535 break;
2536 case 13: /* ifInDiscarts */
2537 {
2538 u32_t *uint_ptr = (u32_t*)value;
2539 *uint_ptr = netif->ifindiscards;
2540 }
2541 break;
2542 case 14: /* ifInErrors */
2543 case 15: /* ifInUnkownProtos */
2544 /** @todo add these counters! */
2545 {
2546 u32_t *uint_ptr = (u32_t*)value;
2547 *uint_ptr = 0;
2548 }
2549 break;
2550 case 16: /* ifOutOctets */
2551 {
2552 u32_t *uint_ptr = (u32_t*)value;
2553 *uint_ptr = netif->ifoutoctets;
2554 }
2555 break;
2556 case 17: /* ifOutUcastPkts */
2557 {
2558 u32_t *uint_ptr = (u32_t*)value;
2559 *uint_ptr = netif->ifoutucastpkts;
2560 }
2561 break;
2562 case 18: /* ifOutNUcastPkts */
2563 {
2564 u32_t *uint_ptr = (u32_t*)value;
2565 *uint_ptr = netif->ifoutnucastpkts;
2566 }
2567 break;
2568 case 19: /* ifOutDiscarts */
2569 {
2570 u32_t *uint_ptr = (u32_t*)value;
2571 *uint_ptr = netif->ifoutdiscards;
2572 }
2573 break;
2574 case 20: /* ifOutErrors */
2575 /** @todo add this counter! */
2576 {
2577 u32_t *uint_ptr = (u32_t*)value;
2578 *uint_ptr = 0;
2579 }
2580 break;
2581 case 21: /* ifOutQLen */
2582 /** @todo figure out if this must be 0 (no queue) or 1? */
2583 {
2584 u32_t *uint_ptr = (u32_t*)value;
2585 *uint_ptr = 0;
2586 }
2587 break;
2588 case 22: /* ifSpecific */
2589 MEMCPY(value, ifspecific.id, len);
2590 break;
2591 default:
2592 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_value(): unknown id: %d\n", id));
2593 break;
2594 };
2595 }
2596
2597 #if !SNMP_SAFE_REQUESTS
2598 static u8_t
2599 ifentry_set_test(struct obj_def *od, u16_t len, void *value)
2600 {
2601 struct netif *netif;
2602 u8_t id, set_ok;
2603 LWIP_UNUSED_ARG(len);
2604
2605 set_ok = 0;
2606 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2607 id = (u8_t)od->id_inst_ptr[0];
2608 switch (id)
2609 {
2610 case 7: /* ifAdminStatus */
2611 {
2612 s32_t *sint_ptr = (s32_t*)value;
2613 if (*sint_ptr == 1 || *sint_ptr == 2)
2614 set_ok = 1;
2615 }
2616 break;
2617 }
2618 return set_ok;
2619 }
2620
2621 static void
2622 ifentry_set_value(struct obj_def *od, u16_t len, void *value)
2623 {
2624 struct netif *netif;
2625 u8_t id;
2626 LWIP_UNUSED_ARG(len);
2627
2628 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2629 id = (u8_t)od->id_inst_ptr[0];
2630 switch (id)
2631 {
2632 case 7: /* ifAdminStatus */
2633 {
2634 s32_t *sint_ptr = (s32_t*)value;
2635 if (*sint_ptr == 1)
2636 {
2637 netif_set_up(netif);
2638 }
2639 else if (*sint_ptr == 2)
2640 {
2641 netif_set_down(netif);
2642 }
2643 }
2644 break;
2645 }
2646 }
2647 #endif /* SNMP_SAFE_REQUESTS */
2648
2649 /**
2650 * Returns atentry object definitions.
2651 *
2652 * @param ident_len the address length (6)
2653 * @param ident points to objectname.atifindex.atnetaddress
2654 * @param od points to object definition.
2655 */
2656 static void
2657 atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2658 {
2659 /* return to object name, adding index depth (5) */
2660 ident_len += 5;
2661 ident -= 5;
2662
2663 if (ident_len == 6)
2664 {
2665 od->id_inst_len = ident_len;
2666 od->id_inst_ptr = ident;
2667
2668 switch (ident[0])
2669 {
2670 case 1: /* atIfIndex */
2671 od->instance = MIB_OBJECT_TAB;
2672 od->access = MIB_OBJECT_READ_WRITE;
2673 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2674 od->v_len = sizeof(s32_t);
2675 break;
2676 case 2: /* atPhysAddress */
2677 od->instance = MIB_OBJECT_TAB;
2678 od->access = MIB_OBJECT_READ_WRITE;
2679 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
2680 od->v_len = 6; /** @todo try to use netif::hwaddr_len */
2681 break;
2682 case 3: /* atNetAddress */
2683 od->instance = MIB_OBJECT_TAB;
2684 od->access = MIB_OBJECT_READ_WRITE;
2685 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
2686 od->v_len = 4;
2687 break;
2688 default:
2689 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n"));
2690 od->instance = MIB_OBJECT_NONE;
2691 break;
2692 }
2693 }
2694 else
2695 {
2696 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n"));
2697 od->instance = MIB_OBJECT_NONE;
2698 }
2699 }
2700
2701 static void
2702 atentry_get_value(struct obj_def *od, u16_t len, void *value)
2703 {
2704 #if LWIP_ARP
2705 u8_t id;
2706 struct eth_addr* ethaddr_ret;
2707 ip_addr_t* ipaddr_ret;
2708 #endif /* LWIP_ARP */
2709 ip_addr_t ip;
2710 struct netif *netif;
2711
2712 LWIP_UNUSED_ARG(len);
2713 LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
2714
2715 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
2716 snmp_oidtoip(&od->id_inst_ptr[2], &ip);
2717
2718 #if LWIP_ARP /** @todo implement a netif_find_addr */
2719 if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
2720 {
2721 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2722 id = (u8_t)od->id_inst_ptr[0];
2723 switch (id)
2724 {
2725 case 1: /* atIfIndex */
2726 {
2727 s32_t *sint_ptr = (s32_t*)value;
2728 *sint_ptr = od->id_inst_ptr[1];
2729 }
2730 break;
2731 case 2: /* atPhysAddress */
2732 {
2733 struct eth_addr *dst = (struct eth_addr*)value;
2734
2735 *dst = *ethaddr_ret;
2736 }
2737 break;
2738 case 3: /* atNetAddress */
2739 {
2740 ip_addr_t *dst = (ip_addr_t*)value;
2741
2742 *dst = *ipaddr_ret;
2743 }
2744 break;
2745 default:
2746 LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_value(): unknown id: %d\n", id));
2747 break;
2748 }
2749 }
2750 #endif /* LWIP_ARP */
2751 }
2752
2753 static void
2754 ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
2755 {
2756 u8_t id;
2757
2758 /* return to object name, adding index depth (1) */
2759 ident_len += 1;
2760 ident -= 1;
2761 if (ident_len == 2)
2762 {
2763 od->id_inst_len = ident_len;
2764 od->id_inst_ptr = ident;
2765
2766 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
2767 id = (u8_t)ident[0];
2768 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id));
2769 switch (id)
2770 {
2771 case 1: /* ipForwarding */
2772 case 2: /* ipDefaultTTL */
2773 od->instance = MIB_OBJECT_SCALAR;
2774 od->access = MIB_OBJECT_READ_WRITE;
2775 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2776 od->v_len = sizeof(s32_t);
2777 break;
2778 case 3: /* ipInReceives */
2779 case 4: /* ipInHdrErrors */
2780 case 5: /* ipInAddrErrors */
2781 case 6: /* ipForwDatagrams */
2782 case 7: /* ipInUnknownProtos */
2783 case 8: /* ipInDiscards */
2784 case 9: /* ipInDelivers */
2785 case 10: /* ipOutRequests */
2786 case 11: /* ipOutDiscards */
2787 case 12: /* ipOutNoRoutes */
2788 case 14: /* ipReasmReqds */
2789 case 15: /* ipReasmOKs */
2790 case 16: /* ipReasmFails */
2791 case 17: /* ipFragOKs */
2792 case 18: /* ipFragFails */
2793 case 19: /* ipFragCreates */
2794 case 23: /* ipRoutingDiscards */
2795 od->instance = MIB_OBJECT_SCALAR;
2796 od->access = MIB_OBJECT_READ_ONLY;
2797 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
2798 od->v_len = sizeof(u32_t);
2799 break;
2800 case 13: /* ipReasmTimeout */
2801 od->instance = MIB_OBJECT_SCALAR;
2802 od->access = MIB_OBJECT_READ_ONLY;
2803 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
2804 od->v_len = sizeof(s32_t);
2805 break;
2806 default:
2807 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n"));
2808 od->instance = MIB_OBJECT_NONE;
2809 break;
2810 };
2811 }
2812 else
2813 {
2814 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n"));
2815 od->instance = MIB_OBJECT_NONE;
2816 }
2817 }
2818
2819 static void
2820 ip_get_value(struct obj_def *od, u16_t len, void *value)
2821 {
2822 u8_t id;
2823
2824 LWIP_UNUSED_ARG(len);
2825 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2826 id = (u8_t)od->id_inst_ptr[0];
2827 switch (id)
2828 {
2829 case 1: /* ipForwarding */
2830 {
2831 s32_t *sint_ptr = (s32_t*)value;
2832 #if IP_FORWARD
2833 /* forwarding */
2834 *sint_ptr = 1;
2835 #else
2836 /* not-forwarding */
2837 *sint_ptr = 2;
2838 #endif
2839 }
2840 break;
2841 case 2: /* ipDefaultTTL */
2842 {
2843 s32_t *sint_ptr = (s32_t*)value;
2844 *sint_ptr = IP_DEFAULT_TTL;
2845 }
2846 break;
2847 case 3: /* ipInReceives */
2848 {
2849 u32_t *uint_ptr = (u32_t*)value;
2850 *uint_ptr = ipinreceives;
2851 }
2852 break;
2853 case 4: /* ipInHdrErrors */
2854 {
2855 u32_t *uint_ptr = (u32_t*)value;
2856 *uint_ptr = ipinhdrerrors;
2857 }
2858 break;
2859 case 5: /* ipInAddrErrors */
2860 {
2861 u32_t *uint_ptr = (u32_t*)value;
2862 *uint_ptr = ipinaddrerrors;
2863 }
2864 break;
2865 case 6: /* ipForwDatagrams */
2866 {
2867 u32_t *uint_ptr = (u32_t*)value;
2868 *uint_ptr = ipforwdatagrams;
2869 }
2870 break;
2871 case 7: /* ipInUnknownProtos */
2872 {
2873 u32_t *uint_ptr = (u32_t*)value;
2874 *uint_ptr = ipinunknownprotos;
2875 }
2876 break;
2877 case 8: /* ipInDiscards */
2878 {
2879 u32_t *uint_ptr = (u32_t*)value;
2880 *uint_ptr = ipindiscards;
2881 }
2882 break;
2883 case 9: /* ipInDelivers */
2884 {
2885 u32_t *uint_ptr = (u32_t*)value;
2886 *uint_ptr = ipindelivers;
2887 }
2888 break;
2889 case 10: /* ipOutRequests */
2890 {
2891 u32_t *uint_ptr = (u32_t*)value;
2892 *uint_ptr = ipoutrequests;
2893 }
2894 break;
2895 case 11: /* ipOutDiscards */
2896 {
2897 u32_t *uint_ptr = (u32_t*)value;
2898 *uint_ptr = ipoutdiscards;
2899 }
2900 break;
2901 case 12: /* ipOutNoRoutes */
2902 {
2903 u32_t *uint_ptr = (u32_t*)value;
2904 *uint_ptr = ipoutnoroutes;
2905 }
2906 break;
2907 case 13: /* ipReasmTimeout */
2908 {
2909 s32_t *sint_ptr = (s32_t*)value;
2910 #if IP_REASSEMBLY
2911 *sint_ptr = IP_REASS_MAXAGE;
2912 #else
2913 *sint_ptr = 0;
2914 #endif
2915 }
2916 break;
2917 case 14: /* ipReasmReqds */
2918 {
2919 u32_t *uint_ptr = (u32_t*)value;
2920 *uint_ptr = ipreasmreqds;
2921 }
2922 break;
2923 case 15: /* ipReasmOKs */
2924 {
2925 u32_t *uint_ptr = (u32_t*)value;
2926 *uint_ptr = ipreasmoks;
2927 }
2928 break;
2929 case 16: /* ipReasmFails */
2930 {
2931 u32_t *uint_ptr = (u32_t*)value;
2932 *uint_ptr = ipreasmfails;
2933 }
2934 break;
2935 case 17: /* ipFragOKs */
2936 {
2937 u32_t *uint_ptr = (u32_t*)value;
2938 *uint_ptr = ipfragoks;
2939 }
2940 break;
2941 case 18: /* ipFragFails */
2942 {
2943 u32_t *uint_ptr = (u32_t*)value;
2944 *uint_ptr = ipfragfails;
2945 }
2946 break;
2947 case 19: /* ipFragCreates */
2948 {
2949 u32_t *uint_ptr = (u32_t*)value;
2950 *uint_ptr = ipfragcreates;
2951 }
2952 break;
2953 case 23: /* ipRoutingDiscards */
2954 /** @todo can lwIP discard routes at all?? hardwire this to 0?? */
2955 {
2956 u32_t *uint_ptr = (u32_t*)value;
2957 *uint_ptr = iproutingdiscards;
2958 }
2959 break;
2960 default:
2961 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_value(): unknown id: %d\n", id));
2962 break;
2963 };
2964 }
2965
2966 /**
2967 * Test ip object value before setting.
2968 *
2969 * @param od is the object definition
2970 * @param len return value space (in bytes)
2971 * @param value points to (varbind) space to copy value from.
2972 *
2973 * @note we allow set if the value matches the hardwired value,
2974 * otherwise return badvalue.
2975 */
2976 static u8_t
2977 ip_set_test(struct obj_def *od, u16_t len, void *value)
2978 {
2979 u8_t id, set_ok;
2980 s32_t *sint_ptr = (s32_t*)value;
2981
2982 LWIP_UNUSED_ARG(len);
2983 set_ok = 0;
2984 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
2985 id = (u8_t)od->id_inst_ptr[0];
2986 switch (id)
2987 {
2988 case 1: /* ipForwarding */
2989 #if IP_FORWARD
2990 /* forwarding */
2991 if (*sint_ptr == 1)
2992 #else
2993 /* not-forwarding */
2994 if (*sint_ptr == 2)
2995 #endif
2996 {
2997 set_ok = 1;
2998 }
2999 break;
3000 case 2: /* ipDefaultTTL */
3001 if (*sint_ptr == IP_DEFAULT_TTL)
3002 {
3003 set_ok = 1;
3004 }
3005 break;
3006 default:
3007 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_set_test(): unknown id: %d\n", id));
3008 break;
3009 };
3010 return set_ok;
3011 }
3012
3013 static void
3014 ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3015 {
3016 /* return to object name, adding index depth (4) */
3017 ident_len += 4;
3018 ident -= 4;
3019
3020 if (ident_len == 5)
3021 {
3022 u8_t id;
3023
3024 od->id_inst_len = ident_len;
3025 od->id_inst_ptr = ident;
3026
3027 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3028 id = (u8_t)ident[0];
3029 switch (id)
3030 {
3031 case 1: /* ipAdEntAddr */
3032 case 3: /* ipAdEntNetMask */
3033 od->instance = MIB_OBJECT_TAB;
3034 od->access = MIB_OBJECT_READ_ONLY;
3035 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3036 od->v_len = 4;
3037 break;
3038 case 2: /* ipAdEntIfIndex */
3039 case 4: /* ipAdEntBcastAddr */
3040 case 5: /* ipAdEntReasmMaxSize */
3041 od->instance = MIB_OBJECT_TAB;
3042 od->access = MIB_OBJECT_READ_ONLY;
3043 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3044 od->v_len = sizeof(s32_t);
3045 break;
3046 default:
3047 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n"));
3048 od->instance = MIB_OBJECT_NONE;
3049 break;
3050 }
3051 }
3052 else
3053 {
3054 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n"));
3055 od->instance = MIB_OBJECT_NONE;
3056 }
3057 }
3058
3059 static void
3060 ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
3061 {
3062 u8_t id;
3063 u16_t ifidx;
3064 ip_addr_t ip;
3065 struct netif *netif = netif_list;
3066
3067 LWIP_UNUSED_ARG(len);
3068 snmp_oidtoip(&od->id_inst_ptr[1], &ip);
3069 ifidx = 0;
3070 while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
3071 {
3072 netif = netif->next;
3073 ifidx++;
3074 }
3075
3076 if (netif != NULL)
3077 {
3078 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3079 id = (u8_t)od->id_inst_ptr[0];
3080 switch (id)
3081 {
3082 case 1: /* ipAdEntAddr */
3083 {
3084 ip_addr_t *dst = (ip_addr_t*)value;
3085 *dst = netif->ip_addr;
3086 }
3087 break;
3088 case 2: /* ipAdEntIfIndex */
3089 {
3090 s32_t *sint_ptr = (s32_t*)value;
3091 *sint_ptr = ifidx + 1;
3092 }
3093 break;
3094 case 3: /* ipAdEntNetMask */
3095 {
3096 ip_addr_t *dst = (ip_addr_t*)value;
3097 *dst = netif->netmask;
3098 }
3099 break;
3100 case 4: /* ipAdEntBcastAddr */
3101 {
3102 s32_t *sint_ptr = (s32_t*)value;
3103
3104 /* lwIP oddity, there's no broadcast
3105 address in the netif we can rely on */
3106 *sint_ptr = IPADDR_BROADCAST & 1;
3107 }
3108 break;
3109 case 5: /* ipAdEntReasmMaxSize */
3110 {
3111 s32_t *sint_ptr = (s32_t*)value;
3112 #if IP_REASSEMBLY
3113 /* @todo The theoretical maximum is IP_REASS_MAX_PBUFS * size of the pbufs,
3114 * but only if receiving one fragmented packet at a time.
3115 * The current solution is to calculate for 2 simultaneous packets...
3116 */
3117 *sint_ptr = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) *
3118 (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - IP_HLEN)));
3119 #else
3120 /** @todo returning MTU would be a bad thing and
3121 returning a wild guess like '576' isn't good either */
3122 *sint_ptr = 0;
3123 #endif
3124 }
3125 break;
3126 default:
3127 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_value(): unknown id: %d\n", id));
3128 break;
3129 }
3130 }
3131 }
3132
3133 /**
3134 * @note
3135 * lwIP IP routing is currently using the network addresses in netif_list.
3136 * if no suitable network IP is found in netif_list, the default_netif is used.
3137 */
3138 static void
3139 ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3140 {
3141 u8_t id;
3142
3143 /* return to object name, adding index depth (4) */
3144 ident_len += 4;
3145 ident -= 4;
3146
3147 if (ident_len == 5)
3148 {
3149 od->id_inst_len = ident_len;
3150 od->id_inst_ptr = ident;
3151
3152 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3153 id = (u8_t)ident[0];
3154 switch (id)
3155 {
3156 case 1: /* ipRouteDest */
3157 case 7: /* ipRouteNextHop */
3158 case 11: /* ipRouteMask */
3159 od->instance = MIB_OBJECT_TAB;
3160 od->access = MIB_OBJECT_READ_WRITE;
3161 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3162 od->v_len = 4;
3163 break;
3164 case 2: /* ipRouteIfIndex */
3165 case 3: /* ipRouteMetric1 */
3166 case 4: /* ipRouteMetric2 */
3167 case 5: /* ipRouteMetric3 */
3168 case 6: /* ipRouteMetric4 */
3169 case 8: /* ipRouteType */
3170 case 10: /* ipRouteAge */
3171 case 12: /* ipRouteMetric5 */
3172 od->instance = MIB_OBJECT_TAB;
3173 od->access = MIB_OBJECT_READ_WRITE;
3174 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3175 od->v_len = sizeof(s32_t);
3176 break;
3177 case 9: /* ipRouteProto */
3178 od->instance = MIB_OBJECT_TAB;
3179 od->access = MIB_OBJECT_READ_ONLY;
3180 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3181 od->v_len = sizeof(s32_t);
3182 break;
3183 case 13: /* ipRouteInfo */
3184 /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */
3185 od->instance = MIB_OBJECT_TAB;
3186 od->access = MIB_OBJECT_READ_ONLY;
3187 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
3188 od->v_len = iprouteinfo.len * sizeof(s32_t);
3189 break;
3190 default:
3191 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n"));
3192 od->instance = MIB_OBJECT_NONE;
3193 break;
3194 }
3195 }
3196 else
3197 {
3198 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n"));
3199 od->instance = MIB_OBJECT_NONE;
3200 }
3201 }
3202
3203 static void
3204 ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
3205 {
3206 struct netif *netif;
3207 ip_addr_t dest;
3208 s32_t *ident;
3209 u8_t id;
3210
3211 ident = od->id_inst_ptr;
3212 snmp_oidtoip(&ident[1], &dest);
3213
3214 if (ip_addr_isany(&dest))
3215 {
3216 /* ip_route() uses default netif for default route */
3217 netif = netif_default;
3218 }
3219 else
3220 {
3221 /* not using ip_route(), need exact match! */
3222 netif = netif_list;
3223 while ((netif != NULL) &&
3224 !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
3225 {
3226 netif = netif->next;
3227 }
3228 }
3229 if (netif != NULL)
3230 {
3231 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3232 id = (u8_t)ident[0];
3233 switch (id)
3234 {
3235 case 1: /* ipRouteDest */
3236 {
3237 ip_addr_t *dst = (ip_addr_t*)value;
3238
3239 if (ip_addr_isany(&dest))
3240 {
3241 /* default rte has 0.0.0.0 dest */
3242 ip_addr_set_zero(dst);
3243 }
3244 else
3245 {
3246 /* netifs have netaddress dest */
3247 ip_addr_get_network(dst, &netif->ip_addr, &netif->netmask);
3248 }
3249 }
3250 break;
3251 case 2: /* ipRouteIfIndex */
3252 {
3253 s32_t *sint_ptr = (s32_t*)value;
3254
3255 snmp_netiftoifindex(netif, sint_ptr);
3256 }
3257 break;
3258 case 3: /* ipRouteMetric1 */
3259 {
3260 s32_t *sint_ptr = (s32_t*)value;
3261
3262 if (ip_addr_isany(&dest))
3263 {
3264 /* default rte has metric 1 */
3265 *sint_ptr = 1;
3266 }
3267 else
3268 {
3269 /* other rtes have metric 0 */
3270 *sint_ptr = 0;
3271 }
3272 }
3273 break;
3274 case 4: /* ipRouteMetric2 */
3275 case 5: /* ipRouteMetric3 */
3276 case 6: /* ipRouteMetric4 */
3277 case 12: /* ipRouteMetric5 */
3278 {
3279 s32_t *sint_ptr = (s32_t*)value;
3280 /* not used */
3281 *sint_ptr = -1;
3282 }
3283 break;
3284 case 7: /* ipRouteNextHop */
3285 {
3286 ip_addr_t *dst = (ip_addr_t*)value;
3287
3288 if (ip_addr_isany(&dest))
3289 {
3290 /* default rte: gateway */
3291 *dst = netif->gw;
3292 }
3293 else
3294 {
3295 /* other rtes: netif ip_addr */
3296 *dst = netif->ip_addr;
3297 }
3298 }
3299 break;
3300 case 8: /* ipRouteType */
3301 {
3302 s32_t *sint_ptr = (s32_t*)value;
3303
3304 if (ip_addr_isany(&dest))
3305 {
3306 /* default rte is indirect */
3307 *sint_ptr = 4;
3308 }
3309 else
3310 {
3311 /* other rtes are direct */
3312 *sint_ptr = 3;
3313 }
3314 }
3315 break;
3316 case 9: /* ipRouteProto */
3317 {
3318 s32_t *sint_ptr = (s32_t*)value;
3319 /* locally defined routes */
3320 *sint_ptr = 2;
3321 }
3322 break;
3323 case 10: /* ipRouteAge */
3324 {
3325 s32_t *sint_ptr = (s32_t*)value;
3326 /** @todo (sysuptime - timestamp last change) / 100
3327 @see snmp_insert_iprteidx_tree() */
3328 *sint_ptr = 0;
3329 }
3330 break;
3331 case 11: /* ipRouteMask */
3332 {
3333 ip_addr_t *dst = (ip_addr_t*)value;
3334
3335 if (ip_addr_isany(&dest))
3336 {
3337 /* default rte use 0.0.0.0 mask */
3338 ip_addr_set_zero(dst);
3339 }
3340 else
3341 {
3342 /* other rtes use netmask */
3343 *dst = netif->netmask;
3344 }
3345 }
3346 break;
3347 case 13: /* ipRouteInfo */
3348 MEMCPY(value, iprouteinfo.id, len);
3349 break;
3350 default:
3351 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_value(): unknown id: %d\n", id));
3352 break;
3353 }
3354 }
3355 }
3356
3357 static void
3358 ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3359 {
3360 /* return to object name, adding index depth (5) */
3361 ident_len += 5;
3362 ident -= 5;
3363
3364 if (ident_len == 6)
3365 {
3366 u8_t id;
3367
3368 od->id_inst_len = ident_len;
3369 od->id_inst_ptr = ident;
3370
3371 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3372 id = (u8_t)ident[0];
3373 switch (id)
3374 {
3375 case 1: /* ipNetToMediaIfIndex */
3376 case 4: /* ipNetToMediaType */
3377 od->instance = MIB_OBJECT_TAB;
3378 od->access = MIB_OBJECT_READ_WRITE;
3379 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3380 od->v_len = sizeof(s32_t);
3381 break;
3382 case 2: /* ipNetToMediaPhysAddress */
3383 od->instance = MIB_OBJECT_TAB;
3384 od->access = MIB_OBJECT_READ_WRITE;
3385 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
3386 od->v_len = 6; /** @todo try to use netif::hwaddr_len */
3387 break;
3388 case 3: /* ipNetToMediaNetAddress */
3389 od->instance = MIB_OBJECT_TAB;
3390 od->access = MIB_OBJECT_READ_WRITE;
3391 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3392 od->v_len = 4;
3393 break;
3394 default:
3395 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n"));
3396 od->instance = MIB_OBJECT_NONE;
3397 break;
3398 }
3399 }
3400 else
3401 {
3402 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n"));
3403 od->instance = MIB_OBJECT_NONE;
3404 }
3405 }
3406
3407 static void
3408 ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
3409 {
3410 #if LWIP_ARP
3411 u8_t id;
3412 struct eth_addr* ethaddr_ret;
3413 ip_addr_t* ipaddr_ret;
3414 #endif /* LWIP_ARP */
3415 ip_addr_t ip;
3416 struct netif *netif;
3417
3418 LWIP_UNUSED_ARG(len);
3419 LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
3420
3421 snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
3422 snmp_oidtoip(&od->id_inst_ptr[2], &ip);
3423
3424 #if LWIP_ARP /** @todo implement a netif_find_addr */
3425 if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
3426 {
3427 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3428 id = (u8_t)od->id_inst_ptr[0];
3429 switch (id)
3430 {
3431 case 1: /* ipNetToMediaIfIndex */
3432 {
3433 s32_t *sint_ptr = (s32_t*)value;
3434 *sint_ptr = od->id_inst_ptr[1];
3435 }
3436 break;
3437 case 2: /* ipNetToMediaPhysAddress */
3438 {
3439 struct eth_addr *dst = (struct eth_addr*)value;
3440
3441 *dst = *ethaddr_ret;
3442 }
3443 break;
3444 case 3: /* ipNetToMediaNetAddress */
3445 {
3446 ip_addr_t *dst = (ip_addr_t*)value;
3447
3448 *dst = *ipaddr_ret;
3449 }
3450 break;
3451 case 4: /* ipNetToMediaType */
3452 {
3453 s32_t *sint_ptr = (s32_t*)value;
3454 /* dynamic (?) */
3455 *sint_ptr = 3;
3456 }
3457 break;
3458 default:
3459 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_value(): unknown id: %d\n", id));
3460 break;
3461 }
3462 }
3463 #endif /* LWIP_ARP */
3464 }
3465
3466 static void
3467 icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3468 {
3469 /* return to object name, adding index depth (1) */
3470 ident_len += 1;
3471 ident -= 1;
3472 if ((ident_len == 2) &&
3473 (ident[0] > 0) && (ident[0] < 27))
3474 {
3475 od->id_inst_len = ident_len;
3476 od->id_inst_ptr = ident;
3477
3478 od->instance = MIB_OBJECT_SCALAR;
3479 od->access = MIB_OBJECT_READ_ONLY;
3480 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3481 od->v_len = sizeof(u32_t);
3482 }
3483 else
3484 {
3485 LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n"));
3486 od->instance = MIB_OBJECT_NONE;
3487 }
3488 }
3489
3490 static void
3491 icmp_get_value(struct obj_def *od, u16_t len, void *value)
3492 {
3493 u32_t *uint_ptr = (u32_t*)value;
3494 u8_t id;
3495
3496 LWIP_UNUSED_ARG(len);
3497 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3498 id = (u8_t)od->id_inst_ptr[0];
3499 switch (id)
3500 {
3501 case 1: /* icmpInMsgs */
3502 *uint_ptr = icmpinmsgs;
3503 break;
3504 case 2: /* icmpInErrors */
3505 *uint_ptr = icmpinerrors;
3506 break;
3507 case 3: /* icmpInDestUnreachs */
3508 *uint_ptr = icmpindestunreachs;
3509 break;
3510 case 4: /* icmpInTimeExcds */
3511 *uint_ptr = icmpintimeexcds;
3512 break;
3513 case 5: /* icmpInParmProbs */
3514 *uint_ptr = icmpinparmprobs;
3515 break;
3516 case 6: /* icmpInSrcQuenchs */
3517 *uint_ptr = icmpinsrcquenchs;
3518 break;
3519 case 7: /* icmpInRedirects */
3520 *uint_ptr = icmpinredirects;
3521 break;
3522 case 8: /* icmpInEchos */
3523 *uint_ptr = icmpinechos;
3524 break;
3525 case 9: /* icmpInEchoReps */
3526 *uint_ptr = icmpinechoreps;
3527 break;
3528 case 10: /* icmpInTimestamps */
3529 *uint_ptr = icmpintimestamps;
3530 break;
3531 case 11: /* icmpInTimestampReps */
3532 *uint_ptr = icmpintimestampreps;
3533 break;
3534 case 12: /* icmpInAddrMasks */
3535 *uint_ptr = icmpinaddrmasks;
3536 break;
3537 case 13: /* icmpInAddrMaskReps */
3538 *uint_ptr = icmpinaddrmaskreps;
3539 break;
3540 case 14: /* icmpOutMsgs */
3541 *uint_ptr = icmpoutmsgs;
3542 break;
3543 case 15: /* icmpOutErrors */
3544 *uint_ptr = icmpouterrors;
3545 break;
3546 case 16: /* icmpOutDestUnreachs */
3547 *uint_ptr = icmpoutdestunreachs;
3548 break;
3549 case 17: /* icmpOutTimeExcds */
3550 *uint_ptr = icmpouttimeexcds;
3551 break;
3552 case 18: /* icmpOutParmProbs */
3553 *uint_ptr = icmpoutparmprobs;
3554 break;
3555 case 19: /* icmpOutSrcQuenchs */
3556 *uint_ptr = icmpoutsrcquenchs;
3557 break;
3558 case 20: /* icmpOutRedirects */
3559 *uint_ptr = icmpoutredirects;
3560 break;
3561 case 21: /* icmpOutEchos */
3562 *uint_ptr = icmpoutechos;
3563 break;
3564 case 22: /* icmpOutEchoReps */
3565 *uint_ptr = icmpoutechoreps;
3566 break;
3567 case 23: /* icmpOutTimestamps */
3568 *uint_ptr = icmpouttimestamps;
3569 break;
3570 case 24: /* icmpOutTimestampReps */
3571 *uint_ptr = icmpouttimestampreps;
3572 break;
3573 case 25: /* icmpOutAddrMasks */
3574 *uint_ptr = icmpoutaddrmasks;
3575 break;
3576 case 26: /* icmpOutAddrMaskReps */
3577 *uint_ptr = icmpoutaddrmaskreps;
3578 break;
3579 default:
3580 LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_value(): unknown id: %d\n", id));
3581 break;
3582 }
3583 }
3584
3585 #if LWIP_TCP
3586 /** @todo tcp grp */
3587 static void
3588 tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3589 {
3590 u8_t id;
3591
3592 /* return to object name, adding index depth (1) */
3593 ident_len += 1;
3594 ident -= 1;
3595 if (ident_len == 2)
3596 {
3597 od->id_inst_len = ident_len;
3598 od->id_inst_ptr = ident;
3599
3600 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3601 id = (u8_t)ident[0];
3602 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
3603
3604 switch (id)
3605 {
3606 case 1: /* tcpRtoAlgorithm */
3607 case 2: /* tcpRtoMin */
3608 case 3: /* tcpRtoMax */
3609 case 4: /* tcpMaxConn */
3610 od->instance = MIB_OBJECT_SCALAR;
3611 od->access = MIB_OBJECT_READ_ONLY;
3612 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3613 od->v_len = sizeof(s32_t);
3614 break;
3615 case 5: /* tcpActiveOpens */
3616 case 6: /* tcpPassiveOpens */
3617 case 7: /* tcpAttemptFails */
3618 case 8: /* tcpEstabResets */
3619 case 10: /* tcpInSegs */
3620 case 11: /* tcpOutSegs */
3621 case 12: /* tcpRetransSegs */
3622 case 14: /* tcpInErrs */
3623 case 15: /* tcpOutRsts */
3624 od->instance = MIB_OBJECT_SCALAR;
3625 od->access = MIB_OBJECT_READ_ONLY;
3626 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3627 od->v_len = sizeof(u32_t);
3628 break;
3629 case 9: /* tcpCurrEstab */
3630 od->instance = MIB_OBJECT_TAB;
3631 od->access = MIB_OBJECT_READ_ONLY;
3632 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
3633 od->v_len = sizeof(u32_t);
3634 break;
3635 default:
3636 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n"));
3637 od->instance = MIB_OBJECT_NONE;
3638 break;
3639 };
3640 }
3641 else
3642 {
3643 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n"));
3644 od->instance = MIB_OBJECT_NONE;
3645 }
3646 }
3647
3648 static void
3649 tcp_get_value(struct obj_def *od, u16_t len, void *value)
3650 {
3651 u32_t *uint_ptr = (u32_t*)value;
3652 s32_t *sint_ptr = (s32_t*)value;
3653 u8_t id;
3654
3655 LWIP_UNUSED_ARG(len);
3656 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3657 id = (u8_t)od->id_inst_ptr[0];
3658 switch (id)
3659 {
3660 case 1: /* tcpRtoAlgorithm, vanj(4) */
3661 *sint_ptr = 4;
3662 break;
3663 case 2: /* tcpRtoMin */
3664 /* @todo not the actual value, a guess,
3665 needs to be calculated */
3666 *sint_ptr = 1000;
3667 break;
3668 case 3: /* tcpRtoMax */
3669 /* @todo not the actual value, a guess,
3670 needs to be calculated */
3671 *sint_ptr = 60000;
3672 break;
3673 case 4: /* tcpMaxConn */
3674 *sint_ptr = MEMP_NUM_TCP_PCB;
3675 break;
3676 case 5: /* tcpActiveOpens */
3677 *uint_ptr = tcpactiveopens;
3678 break;
3679 case 6: /* tcpPassiveOpens */
3680 *uint_ptr = tcppassiveopens;
3681 break;
3682 case 7: /* tcpAttemptFails */
3683 *uint_ptr = tcpattemptfails;
3684 break;
3685 case 8: /* tcpEstabResets */
3686 *uint_ptr = tcpestabresets;
3687 break;
3688 case 9: /* tcpCurrEstab */
3689 {
3690 u16_t tcpcurrestab = 0;
3691 struct tcp_pcb *pcb = tcp_active_pcbs;
3692 while (pcb != NULL)
3693 {
3694 if ((pcb->state == ESTABLISHED) ||
3695 (pcb->state == CLOSE_WAIT))
3696 {
3697 tcpcurrestab++;
3698 }
3699 pcb = pcb->next;
3700 }
3701 *uint_ptr = tcpcurrestab;
3702 }
3703 break;
3704 case 10: /* tcpInSegs */
3705 *uint_ptr = tcpinsegs;
3706 break;
3707 case 11: /* tcpOutSegs */
3708 *uint_ptr = tcpoutsegs;
3709 break;
3710 case 12: /* tcpRetransSegs */
3711 *uint_ptr = tcpretranssegs;
3712 break;
3713 case 14: /* tcpInErrs */
3714 *uint_ptr = tcpinerrs;
3715 break;
3716 case 15: /* tcpOutRsts */
3717 *uint_ptr = tcpoutrsts;
3718 break;
3719 default:
3720 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_value(): unknown id: %d\n", id));
3721 break;
3722 }
3723 }
3724 #ifdef THIS_SEEMS_UNUSED
3725 static void
3726 tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3727 {
3728 /* return to object name, adding index depth (10) */
3729 ident_len += 10;
3730 ident -= 10;
3731
3732 if (ident_len == 11)
3733 {
3734 u8_t id;
3735
3736 od->id_inst_len = ident_len;
3737 od->id_inst_ptr = ident;
3738
3739 id = ident[0];
3740 LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
3741
3742 switch (id)
3743 {
3744 case 1: /* tcpConnState */
3745 od->instance = MIB_OBJECT_TAB;
3746 od->access = MIB_OBJECT_READ_WRITE;
3747 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3748 od->v_len = sizeof(s32_t);
3749 break;
3750 case 2: /* tcpConnLocalAddress */
3751 case 4: /* tcpConnRemAddress */
3752 od->instance = MIB_OBJECT_TAB;
3753 od->access = MIB_OBJECT_READ_ONLY;
3754 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3755 od->v_len = 4;
3756 break;
3757 case 3: /* tcpConnLocalPort */
3758 case 5: /* tcpConnRemPort */
3759 od->instance = MIB_OBJECT_TAB;
3760 od->access = MIB_OBJECT_READ_ONLY;
3761 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3762 od->v_len = sizeof(s32_t);
3763 break;
3764 default:
3765 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
3766 od->instance = MIB_OBJECT_NONE;
3767 break;
3768 };
3769 }
3770 else
3771 {
3772 LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
3773 od->instance = MIB_OBJECT_NONE;
3774 }
3775 }
3776
3777 static void
3778 tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)
3779 {
3780 ip_addr_t lip, rip;
3781 u16_t lport, rport;
3782 s32_t *ident;
3783
3784 ident = od->id_inst_ptr;
3785 snmp_oidtoip(&ident[1], &lip);
3786 lport = ident[5];
3787 snmp_oidtoip(&ident[6], &rip);
3788 rport = ident[10];
3789
3790 /** @todo find matching PCB */
3791 }
3792 #endif /* if 0 */
3793 #endif
3794
3795 static void
3796 udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3797 {
3798 /* return to object name, adding index depth (1) */
3799 ident_len += 1;
3800 ident -= 1;
3801 if ((ident_len == 2) &&
3802 (ident[0] > 0) && (ident[0] < 6))
3803 {
3804 od->id_inst_len = ident_len;
3805 od->id_inst_ptr = ident;
3806
3807 od->instance = MIB_OBJECT_SCALAR;
3808 od->access = MIB_OBJECT_READ_ONLY;
3809 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3810 od->v_len = sizeof(u32_t);
3811 }
3812 else
3813 {
3814 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n"));
3815 od->instance = MIB_OBJECT_NONE;
3816 }
3817 }
3818
3819 static void
3820 udp_get_value(struct obj_def *od, u16_t len, void *value)
3821 {
3822 u32_t *uint_ptr = (u32_t*)value;
3823 u8_t id;
3824
3825 LWIP_UNUSED_ARG(len);
3826 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3827 id = (u8_t)od->id_inst_ptr[0];
3828 switch (id)
3829 {
3830 case 1: /* udpInDatagrams */
3831 *uint_ptr = udpindatagrams;
3832 break;
3833 case 2: /* udpNoPorts */
3834 *uint_ptr = udpnoports;
3835 break;
3836 case 3: /* udpInErrors */
3837 *uint_ptr = udpinerrors;
3838 break;
3839 case 4: /* udpOutDatagrams */
3840 *uint_ptr = udpoutdatagrams;
3841 break;
3842 default:
3843 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_value(): unknown id: %d\n", id));
3844 break;
3845 }
3846 }
3847
3848 static void
3849 udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3850 {
3851 /* return to object name, adding index depth (5) */
3852 ident_len += 5;
3853 ident -= 5;
3854
3855 if (ident_len == 6)
3856 {
3857 od->id_inst_len = ident_len;
3858 od->id_inst_ptr = ident;
3859
3860 switch (ident[0])
3861 {
3862 case 1: /* udpLocalAddress */
3863 od->instance = MIB_OBJECT_TAB;
3864 od->access = MIB_OBJECT_READ_ONLY;
3865 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
3866 od->v_len = 4;
3867 break;
3868 case 2: /* udpLocalPort */
3869 od->instance = MIB_OBJECT_TAB;
3870 od->access = MIB_OBJECT_READ_ONLY;
3871 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3872 od->v_len = sizeof(s32_t);
3873 break;
3874 default:
3875 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n"));
3876 od->instance = MIB_OBJECT_NONE;
3877 break;
3878 }
3879 }
3880 else
3881 {
3882 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n"));
3883 od->instance = MIB_OBJECT_NONE;
3884 }
3885 }
3886
3887 static void
3888 udpentry_get_value(struct obj_def *od, u16_t len, void *value)
3889 {
3890 u8_t id;
3891 struct udp_pcb *pcb;
3892 ipX_addr_t ip;
3893 u16_t port;
3894
3895 LWIP_UNUSED_ARG(len);
3896 snmp_oidtoip(&od->id_inst_ptr[1], (ip_addr_t*)&ip);
3897 LWIP_ASSERT("invalid port", (od->id_inst_ptr[5] >= 0) && (od->id_inst_ptr[5] <= 0xffff));
3898 port = (u16_t)od->id_inst_ptr[5];
3899
3900 pcb = udp_pcbs;
3901 while ((pcb != NULL) &&
3902 !(ipX_addr_cmp(0, &pcb->local_ip, &ip) &&
3903 (pcb->local_port == port)))
3904 {
3905 pcb = pcb->next;
3906 }
3907
3908 if (pcb != NULL)
3909 {
3910 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
3911 id = (u8_t)od->id_inst_ptr[0];
3912 switch (id)
3913 {
3914 case 1: /* udpLocalAddress */
3915 {
3916 ipX_addr_t *dst = (ipX_addr_t*)value;
3917 ipX_addr_copy(0, *dst, pcb->local_ip);
3918 }
3919 break;
3920 case 2: /* udpLocalPort */
3921 {
3922 s32_t *sint_ptr = (s32_t*)value;
3923 *sint_ptr = pcb->local_port;
3924 }
3925 break;
3926 default:
3927 LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_value(): unknown id: %d\n", id));
3928 break;
3929 }
3930 }
3931 }
3932
3933 static void
3934 snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
3935 {
3936 /* return to object name, adding index depth (1) */
3937 ident_len += 1;
3938 ident -= 1;
3939 if (ident_len == 2)
3940 {
3941 u8_t id;
3942
3943 od->id_inst_len = ident_len;
3944 od->id_inst_ptr = ident;
3945
3946 LWIP_ASSERT("invalid id", (ident[0] >= 0) && (ident[0] <= 0xff));
3947 id = (u8_t)ident[0];
3948 switch (id)
3949 {
3950 case 1: /* snmpInPkts */
3951 case 2: /* snmpOutPkts */
3952 case 3: /* snmpInBadVersions */
3953 case 4: /* snmpInBadCommunityNames */
3954 case 5: /* snmpInBadCommunityUses */
3955 case 6: /* snmpInASNParseErrs */
3956 case 8: /* snmpInTooBigs */
3957 case 9: /* snmpInNoSuchNames */
3958 case 10: /* snmpInBadValues */
3959 case 11: /* snmpInReadOnlys */
3960 case 12: /* snmpInGenErrs */
3961 case 13: /* snmpInTotalReqVars */
3962 case 14: /* snmpInTotalSetVars */
3963 case 15: /* snmpInGetRequests */
3964 case 16: /* snmpInGetNexts */
3965 case 17: /* snmpInSetRequests */
3966 case 18: /* snmpInGetResponses */
3967 case 19: /* snmpInTraps */
3968 case 20: /* snmpOutTooBigs */
3969 case 21: /* snmpOutNoSuchNames */
3970 case 22: /* snmpOutBadValues */
3971 case 24: /* snmpOutGenErrs */
3972 case 25: /* snmpOutGetRequests */
3973 case 26: /* snmpOutGetNexts */
3974 case 27: /* snmpOutSetRequests */
3975 case 28: /* snmpOutGetResponses */
3976 case 29: /* snmpOutTraps */
3977 od->instance = MIB_OBJECT_SCALAR;
3978 od->access = MIB_OBJECT_READ_ONLY;
3979 od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
3980 od->v_len = sizeof(u32_t);
3981 break;
3982 case 30: /* snmpEnableAuthenTraps */
3983 od->instance = MIB_OBJECT_SCALAR;
3984 od->access = MIB_OBJECT_READ_WRITE;
3985 od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
3986 od->v_len = sizeof(s32_t);
3987 break;
3988 default:
3989 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n"));
3990 od->instance = MIB_OBJECT_NONE;
3991 break;
3992 };
3993 }
3994 else
3995 {
3996 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n"));
3997 od->instance = MIB_OBJECT_NONE;
3998 }
3999 }
4000
4001 static void
4002 snmp_get_value(struct obj_def *od, u16_t len, void *value)
4003 {
4004 u32_t *uint_ptr = (u32_t*)value;
4005 u8_t id;
4006
4007 LWIP_UNUSED_ARG(len);
4008 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
4009 id = (u8_t)od->id_inst_ptr[0];
4010 switch (id)
4011 {
4012 case 1: /* snmpInPkts */
4013 *uint_ptr = snmpinpkts;
4014 break;
4015 case 2: /* snmpOutPkts */
4016 *uint_ptr = snmpoutpkts;
4017 break;
4018 case 3: /* snmpInBadVersions */
4019 *uint_ptr = snmpinbadversions;
4020 break;
4021 case 4: /* snmpInBadCommunityNames */
4022 *uint_ptr = snmpinbadcommunitynames;
4023 break;
4024 case 5: /* snmpInBadCommunityUses */
4025 *uint_ptr = snmpinbadcommunityuses;
4026 break;
4027 case 6: /* snmpInASNParseErrs */
4028 *uint_ptr = snmpinasnparseerrs;
4029 break;
4030 case 8: /* snmpInTooBigs */
4031 *uint_ptr = snmpintoobigs;
4032 break;
4033 case 9: /* snmpInNoSuchNames */
4034 *uint_ptr = snmpinnosuchnames;
4035 break;
4036 case 10: /* snmpInBadValues */
4037 *uint_ptr = snmpinbadvalues;
4038 break;
4039 case 11: /* snmpInReadOnlys */
4040 *uint_ptr = snmpinreadonlys;
4041 break;
4042 case 12: /* snmpInGenErrs */
4043 *uint_ptr = snmpingenerrs;
4044 break;
4045 case 13: /* snmpInTotalReqVars */
4046 *uint_ptr = snmpintotalreqvars;
4047 break;
4048 case 14: /* snmpInTotalSetVars */
4049 *uint_ptr = snmpintotalsetvars;
4050 break;
4051 case 15: /* snmpInGetRequests */
4052 *uint_ptr = snmpingetrequests;
4053 break;
4054 case 16: /* snmpInGetNexts */
4055 *uint_ptr = snmpingetnexts;
4056 break;
4057 case 17: /* snmpInSetRequests */
4058 *uint_ptr = snmpinsetrequests;
4059 break;
4060 case 18: /* snmpInGetResponses */
4061 *uint_ptr = snmpingetresponses;
4062 break;
4063 case 19: /* snmpInTraps */
4064 *uint_ptr = snmpintraps;
4065 break;
4066 case 20: /* snmpOutTooBigs */
4067 *uint_ptr = snmpouttoobigs;
4068 break;
4069 case 21: /* snmpOutNoSuchNames */
4070 *uint_ptr = snmpoutnosuchnames;
4071 break;
4072 case 22: /* snmpOutBadValues */
4073 *uint_ptr = snmpoutbadvalues;
4074 break;
4075 case 24: /* snmpOutGenErrs */
4076 *uint_ptr = snmpoutgenerrs;
4077 break;
4078 case 25: /* snmpOutGetRequests */
4079 *uint_ptr = snmpoutgetrequests;
4080 break;
4081 case 26: /* snmpOutGetNexts */
4082 *uint_ptr = snmpoutgetnexts;
4083 break;
4084 case 27: /* snmpOutSetRequests */
4085 *uint_ptr = snmpoutsetrequests;
4086 break;
4087 case 28: /* snmpOutGetResponses */
4088 *uint_ptr = snmpoutgetresponses;
4089 break;
4090 case 29: /* snmpOutTraps */
4091 *uint_ptr = snmpouttraps;
4092 break;
4093 case 30: /* snmpEnableAuthenTraps */
4094 *uint_ptr = *snmpenableauthentraps_ptr;
4095 break;
4096 default:
4097 LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_value(): unknown id: %d\n", id));
4098 break;
4099 };
4100 }
4101
4102 /**
4103 * Test snmp object value before setting.
4104 *
4105 * @param od is the object definition
4106 * @param len return value space (in bytes)
4107 * @param value points to (varbind) space to copy value from.
4108 */
4109 static u8_t
4110 snmp_set_test(struct obj_def *od, u16_t len, void *value)
4111 {
4112 u8_t id, set_ok;
4113
4114 LWIP_UNUSED_ARG(len);
4115 set_ok = 0;
4116 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
4117 id = (u8_t)od->id_inst_ptr[0];
4118 if (id == 30)
4119 {
4120 /* snmpEnableAuthenTraps */
4121 s32_t *sint_ptr = (s32_t*)value;
4122
4123 if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default)
4124 {
4125 /* we should have writable non-volatile mem here */
4126 if ((*sint_ptr == 1) || (*sint_ptr == 2))
4127 {
4128 set_ok = 1;
4129 }
4130 }
4131 else
4132 {
4133 /* const or hardwired value */
4134 if (*sint_ptr == snmpenableauthentraps_default)
4135 {
4136 set_ok = 1;
4137 }
4138 }
4139 }
4140 return set_ok;
4141 }
4142
4143 static void
4144 snmp_set_value(struct obj_def *od, u16_t len, void *value)
4145 {
4146 u8_t id;
4147
4148 LWIP_UNUSED_ARG(len);
4149 LWIP_ASSERT("invalid id", (od->id_inst_ptr[0] >= 0) && (od->id_inst_ptr[0] <= 0xff));
4150 id = (u8_t)od->id_inst_ptr[0];
4151 if (id == 30)
4152 {
4153 /* snmpEnableAuthenTraps */
4154 /* @todo @fixme: which kind of pointer is 'value'? s32_t or u8_t??? */
4155 u8_t *ptr = (u8_t*)value;
4156 *snmpenableauthentraps_ptr = *ptr;
4157 }
4158 }
4159
4160 #endif /* LWIP_SNMP */