-/**
- * @file
- * Management Information Base II (RFC1213) objects and functions.
- *
- * @note the object identifiers for this MIB-2 and private MIB tree
- * must be kept in sorted ascending order. This to ensure correct getnext operation.
- */
-
-/*
- * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without modification,
- * are permitted provided that the following conditions are met:
- *
- * 1. Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- * derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
- * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
- * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
- * OF SUCH DAMAGE.
- *
- * Author: Christiaan Simons <christiaan.simons@axon.tv>
- */
-
-#include "arch/cc.h"
-#include "lwip/opt.h"
-
-#if LWIP_SNMP
-#include "lwip/snmp.h"
-#include "lwip/netif.h"
-#include "netif/etharp.h"
-#include "lwip/ip.h"
-#include "lwip/ip_frag.h"
-#include "lwip/tcp.h"
-#include "lwip/udp.h"
-#include "lwip/snmp_asn1.h"
-#include "lwip/snmp_structs.h"
-
-/**
- * IANA assigned enterprise ID for lwIP is 26381
- * @see http://www.iana.org/assignments/enterprise-numbers
- *
- * @note this enterprise ID is assigned to the lwIP project,
- * all object identifiers living under this ID are assigned
- * by the lwIP maintainers (contact Christiaan Simons)!
- * @note don't change this define, use snmp_set_sysobjid()
- *
- * If you need to create your own private MIB you'll need
- * to apply for your own enterprise ID with IANA:
- * http://www.iana.org/numbers.html
- */
-#define SNMP_ENTERPRISE_ID 26381
-#define SNMP_SYSOBJID_LEN 7
-#define SNMP_SYSOBJID {1, 3, 6, 1, 4, 1, SNMP_ENTERPRISE_ID}
-
-#ifndef SNMP_SYSSERVICES
-#define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2))
-#endif
-
-static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void system_get_value(struct obj_def *od, u16_t len, void *value);
-static u8_t system_set_test(struct obj_def *od, u16_t len, void *value);
-static void system_set_value(struct obj_def *od, u16_t len, void *value);
-static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void interfaces_get_value(struct obj_def *od, u16_t len, void *value);
-static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void ifentry_get_value(struct obj_def *od, u16_t len, void *value);
-static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void atentry_get_value(struct obj_def *od, u16_t len, void *value);
-static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void ip_get_value(struct obj_def *od, u16_t len, void *value);
-static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value);
-static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value);
-static void ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value);
-static void ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value);
-static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void icmp_get_value(struct obj_def *od, u16_t len, void *value);
-#if LWIP_TCP
-static void tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void tcp_get_value(struct obj_def *od, u16_t len, void *value);
-static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value);
-#endif
-static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void udp_get_value(struct obj_def *od, u16_t len, void *value);
-static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void udpentry_get_value(struct obj_def *od, u16_t len, void *value);
-static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
-static void snmp_get_value(struct obj_def *od, u16_t len, void *value);
-static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value);
-static void snmp_set_value(struct obj_def *od, u16_t len, void *value);
-
-
-/* snmp .1.3.6.1.2.1.11 */
-const mib_scalar_node snmp_scalar = {
- &snmp_get_object_def,
- &snmp_get_value,
- &snmp_set_test,
- &snmp_set_value,
- MIB_NODE_SC,
- 0
-};
-const s32_t snmp_ids[28] = {
- 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30
-};
-struct mib_node* const snmp_nodes[28] = {
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,
- (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar
-};
-const struct mib_array_node snmp = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 28,
- snmp_ids,
- snmp_nodes
-};
-
-/* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */
-/* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */
-/* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */
-
-/* udp .1.3.6.1.2.1.7 */
-/** index root node for udpTable */
-struct mib_list_rootnode udp_root = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-const s32_t udpentry_ids[2] = { 1, 2 };
-struct mib_node* const udpentry_nodes[2] = {
- (struct mib_node* const)&udp_root, (struct mib_node* const)&udp_root,
-};
-const struct mib_array_node udpentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 2,
- udpentry_ids,
- udpentry_nodes
-};
-
-s32_t udptable_id = 1;
-struct mib_node* udptable_node = (struct mib_node* const)&udpentry;
-struct mib_ram_array_node udptable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
- 0,
- &udptable_id,
- &udptable_node
-};
-
-const mib_scalar_node udp_scalar = {
- &udp_get_object_def,
- &udp_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_SC,
- 0
-};
-const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 };
-struct mib_node* const udp_nodes[5] = {
- (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar,
- (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar,
- (struct mib_node* const)&udptable
-};
-const struct mib_array_node udp = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 5,
- udp_ids,
- udp_nodes
-};
-
-/* tcp .1.3.6.1.2.1.6 */
-#if LWIP_TCP
-/* only if the TCP protocol is available may implement this group */
-/** index root node for tcpConnTable */
-struct mib_list_rootnode tcpconntree_root = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 };
-struct mib_node* const tcpconnentry_nodes[5] = {
- (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root,
- (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root,
- (struct mib_node* const)&tcpconntree_root
-};
-const struct mib_array_node tcpconnentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 5,
- tcpconnentry_ids,
- tcpconnentry_nodes
-};
-
-s32_t tcpconntable_id = 1;
-struct mib_node* tcpconntable_node = (struct mib_node* const)&tcpconnentry;
-struct mib_ram_array_node tcpconntable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
-/** @todo update maxlength when inserting / deleting from table
- 0 when table is empty, 1 when more than one entry */
- 0,
- &tcpconntable_id,
- &tcpconntable_node
-};
-
-const mib_scalar_node tcp_scalar = {
- &tcp_get_object_def,
- &tcp_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_SC,
- 0
-};
-const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
-struct mib_node* const tcp_nodes[15] = {
- (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcpconntable, (struct mib_node* const)&tcp_scalar,
- (struct mib_node* const)&tcp_scalar
-};
-const struct mib_array_node tcp = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 15,
- tcp_ids,
- tcp_nodes
-};
-#endif
-
-/* icmp .1.3.6.1.2.1.5 */
-const mib_scalar_node icmp_scalar = {
- &icmp_get_object_def,
- &icmp_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_SC,
- 0
-};
-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 };
-struct mib_node* const icmp_nodes[26] = {
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,
- (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar
-};
-const struct mib_array_node icmp = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 26,
- icmp_ids,
- icmp_nodes
-};
-
-/** index root node for ipNetToMediaTable */
-struct mib_list_rootnode ipntomtree_root = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 };
-struct mib_node* const ipntomentry_nodes[4] = {
- (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root,
- (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root
-};
-const struct mib_array_node ipntomentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 4,
- ipntomentry_ids,
- ipntomentry_nodes
-};
-
-s32_t ipntomtable_id = 1;
-struct mib_node* ipntomtable_node = (struct mib_node* const)&ipntomentry;
-struct mib_ram_array_node ipntomtable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
- 0,
- &ipntomtable_id,
- &ipntomtable_node
-};
-
-/** index root node for ipRouteTable */
-struct mib_list_rootnode iprtetree_root = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
-struct mib_node* const iprteentry_nodes[13] = {
- (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
- (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
- (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
- (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
- (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
- (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,
- (struct mib_node* const)&iprtetree_root
-};
-const struct mib_array_node iprteentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 13,
- iprteentry_ids,
- iprteentry_nodes
-};
-
-s32_t iprtetable_id = 1;
-struct mib_node* iprtetable_node = (struct mib_node* const)&iprteentry;
-struct mib_ram_array_node iprtetable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
- 0,
- &iprtetable_id,
- &iprtetable_node
-};
-
-/** index root node for ipAddrTable */
-struct mib_list_rootnode ipaddrtree_root = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 };
-struct mib_node* const ipaddrentry_nodes[5] = {
- (struct mib_node* const)&ipaddrtree_root,
- (struct mib_node* const)&ipaddrtree_root,
- (struct mib_node* const)&ipaddrtree_root,
- (struct mib_node* const)&ipaddrtree_root,
- (struct mib_node* const)&ipaddrtree_root
-};
-const struct mib_array_node ipaddrentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 5,
- ipaddrentry_ids,
- ipaddrentry_nodes
-};
-
-s32_t ipaddrtable_id = 1;
-struct mib_node* ipaddrtable_node = (struct mib_node* const)&ipaddrentry;
-struct mib_ram_array_node ipaddrtable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
- 0,
- &ipaddrtable_id,
- &ipaddrtable_node
-};
-
-/* ip .1.3.6.1.2.1.4 */
-const mib_scalar_node ip_scalar = {
- &ip_get_object_def,
- &ip_get_value,
- &ip_set_test,
- &noleafs_set_value,
- MIB_NODE_SC,
- 0
-};
-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 };
-struct mib_node* const ip_nodes[23] = {
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,
- (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ipaddrtable,
- (struct mib_node* const)&iprtetable, (struct mib_node* const)&ipntomtable,
- (struct mib_node* const)&ip_scalar
-};
-const struct mib_array_node ip = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 23,
- ip_ids,
- ip_nodes
-};
-
-/** index root node for atTable */
-struct mib_list_rootnode arptree_root = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-const s32_t atentry_ids[3] = { 1, 2, 3 };
-struct mib_node* const atentry_nodes[3] = {
- (struct mib_node* const)&arptree_root,
- (struct mib_node* const)&arptree_root,
- (struct mib_node* const)&arptree_root
-};
-const struct mib_array_node atentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 3,
- atentry_ids,
- atentry_nodes
-};
-
-const s32_t attable_id = 1;
-struct mib_node* const attable_node = (struct mib_node* const)&atentry;
-const struct mib_array_node attable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 1,
- &attable_id,
- &attable_node
-};
-
-/* at .1.3.6.1.2.1.3 */
-s32_t at_id = 1;
-struct mib_node* at_node = (struct mib_node* const)&attable;
-struct mib_ram_array_node at = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
- 0,
- &at_id,
- &at_node
-};
-
-/** index root node for ifTable */
-struct mib_list_rootnode iflist_root = {
- &ifentry_get_object_def,
- &ifentry_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_LR,
- 0,
- NULL,
- NULL,
- 0
-};
-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 };
-struct mib_node* const ifentry_nodes[22] = {
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,
- (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root
-};
-const struct mib_array_node ifentry = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 22,
- ifentry_ids,
- ifentry_nodes
-};
-
-s32_t iftable_id = 1;
-struct mib_node* iftable_node = (struct mib_node* const)&ifentry;
-struct mib_ram_array_node iftable = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_RA,
- 0,
- &iftable_id,
- &iftable_node
-};
-
-/* interfaces .1.3.6.1.2.1.2 */
-const mib_scalar_node interfaces_scalar = {
- &interfaces_get_object_def,
- &interfaces_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_SC,
- 0
-};
-const s32_t interfaces_ids[2] = { 1, 2 };
-struct mib_node* const interfaces_nodes[2] = {
- (struct mib_node* const)&interfaces_scalar, (struct mib_node* const)&iftable
-};
-const struct mib_array_node interfaces = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 2,
- interfaces_ids,
- interfaces_nodes
-};
-
-
-/* 0 1 2 3 4 5 6 */
-/* system .1.3.6.1.2.1.1 */
-const mib_scalar_node sys_tem_scalar = {
- &system_get_object_def,
- &system_get_value,
- &system_set_test,
- &system_set_value,
- MIB_NODE_SC,
- 0
-};
-const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };
-struct mib_node* const sys_tem_nodes[7] = {
- (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,
- (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,
- (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,
- (struct mib_node* const)&sys_tem_scalar
-};
-/* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */
-const struct mib_array_node sys_tem = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 7,
- sys_tem_ids,
- sys_tem_nodes
-};
-
-/* mib-2 .1.3.6.1.2.1 */
-#if LWIP_TCP
-#define MIB2_GROUPS 8
-#else
-#define MIB2_GROUPS 7
-#endif
-const s32_t mib2_ids[MIB2_GROUPS] =
-{
- 1,
- 2,
- 3,
- 4,
- 5,
-#if LWIP_TCP
- 6,
-#endif
- 7,
- 11
-};
-struct mib_node* const mib2_nodes[MIB2_GROUPS] = {
- (struct mib_node* const)&sys_tem,
- (struct mib_node* const)&interfaces,
- (struct mib_node* const)&at,
- (struct mib_node* const)&ip,
- (struct mib_node* const)&icmp,
-#if LWIP_TCP
- (struct mib_node* const)&tcp,
-#endif
- (struct mib_node* const)&udp,
- (struct mib_node* const)&snmp
-};
-
-const struct mib_array_node mib2 = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- MIB2_GROUPS,
- mib2_ids,
- mib2_nodes
-};
-
-/* mgmt .1.3.6.1.2 */
-const s32_t mgmt_ids[1] = { 1 };
-struct mib_node* const mgmt_nodes[1] = { (struct mib_node* const)&mib2 };
-const struct mib_array_node mgmt = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 1,
- mgmt_ids,
- mgmt_nodes
-};
-
-/* internet .1.3.6.1 */
-#if SNMP_PRIVATE_MIB
-s32_t internet_ids[2] = { 2, 4 };
-struct mib_node* const internet_nodes[2] = { (struct mib_node* const)&mgmt, (struct mib_node* const)&private };
-const struct mib_array_node internet = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 2,
- internet_ids,
- internet_nodes
-};
-#else
-const s32_t internet_ids[1] = { 2 };
-struct mib_node* const internet_nodes[1] = { (struct mib_node* const)&mgmt };
-const struct mib_array_node internet = {
- &noleafs_get_object_def,
- &noleafs_get_value,
- &noleafs_set_test,
- &noleafs_set_value,
- MIB_NODE_AR,
- 1,
- internet_ids,
- internet_nodes
-};
-#endif
-
-/** mib-2.system.sysObjectID */
-static struct snmp_obj_id sysobjid = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID};
-/** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */
-static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}};
-/** mib-2.system.sysServices */
-static const s32_t sysservices = SNMP_SYSSERVICES;
-
-/** mib-2.system.sysDescr */
-static const u8_t sysdescr_len_default = 4;
-static const u8_t sysdescr_default[] = "lwIP";
-static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default;
-static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0];
-/** mib-2.system.sysContact */
-static const u8_t syscontact_len_default = 0;
-static const u8_t syscontact_default[] = "";
-static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default;
-static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0];
-/** mib-2.system.sysName */
-static const u8_t sysname_len_default = 8;
-static const u8_t sysname_default[] = "FQDN-unk";
-static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default;
-static u8_t* sysname_ptr = (u8_t*)&sysname_default[0];
-/** mib-2.system.sysLocation */
-static const u8_t syslocation_len_default = 0;
-static const u8_t syslocation_default[] = "";
-static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default;
-static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0];
-/** mib-2.snmp.snmpEnableAuthenTraps */
-static const u8_t snmpenableauthentraps_default = 2; /* disabled */
-static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default;
-
-/** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */
-static const struct snmp_obj_id ifspecific = {2, {0, 0}};
-/** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */
-static const struct snmp_obj_id iprouteinfo = {2, {0, 0}};
-
-
-
-/* mib-2.system counter(s) */
-static u32_t sysuptime = 0;
-
-/* mib-2.ip counter(s) */
-static u32_t ipinreceives = 0,
- ipinhdrerrors = 0,
- ipinaddrerrors = 0,
- ipforwdatagrams = 0,
- ipinunknownprotos = 0,
- ipindiscards = 0,
- ipindelivers = 0,
- ipoutrequests = 0,
- ipoutdiscards = 0,
- ipoutnoroutes = 0,
- ipreasmreqds = 0,
- ipreasmoks = 0,
- ipreasmfails = 0,
- ipfragoks = 0,
- ipfragfails = 0,
- ipfragcreates = 0,
- iproutingdiscards = 0;
-/* mib-2.icmp counter(s) */
-static u32_t icmpinmsgs = 0,
- icmpinerrors = 0,
- icmpindestunreachs = 0,
- icmpintimeexcds = 0,
- icmpinparmprobs = 0,
- icmpinsrcquenchs = 0,
- icmpinredirects = 0,
- icmpinechos = 0,
- icmpinechoreps = 0,
- icmpintimestamps = 0,
- icmpintimestampreps = 0,
- icmpinaddrmasks = 0,
- icmpinaddrmaskreps = 0,
- icmpoutmsgs = 0,
- icmpouterrors = 0,
- icmpoutdestunreachs = 0,
- icmpouttimeexcds = 0,
- icmpoutparmprobs = 0,
- icmpoutsrcquenchs = 0,
- icmpoutredirects = 0,
- icmpoutechos = 0,
- icmpoutechoreps = 0,
- icmpouttimestamps = 0,
- icmpouttimestampreps = 0,
- icmpoutaddrmasks = 0,
- icmpoutaddrmaskreps = 0;
-/* mib-2.tcp counter(s) */
-static u32_t tcpactiveopens = 0,
- tcppassiveopens = 0,
- tcpattemptfails = 0,
- tcpestabresets = 0,
- tcpinsegs = 0,
- tcpoutsegs = 0,
- tcpretranssegs = 0,
- tcpinerrs = 0,
- tcpoutrsts = 0;
-/* mib-2.udp counter(s) */
-static u32_t udpindatagrams = 0,
- udpnoports = 0,
- udpinerrors = 0,
- udpoutdatagrams = 0;
-/* mib-2.snmp counter(s) */
-static u32_t snmpinpkts = 0,
- snmpoutpkts = 0,
- snmpinbadversions = 0,
- snmpinbadcommunitynames = 0,
- snmpinbadcommunityuses = 0,
- snmpinasnparseerrs = 0,
- snmpintoobigs = 0,
- snmpinnosuchnames = 0,
- snmpinbadvalues = 0,
- snmpinreadonlys = 0,
- snmpingenerrs = 0,
- snmpintotalreqvars = 0,
- snmpintotalsetvars = 0,
- snmpingetrequests = 0,
- snmpingetnexts = 0,
- snmpinsetrequests = 0,
- snmpingetresponses = 0,
- snmpintraps = 0,
- snmpouttoobigs = 0,
- snmpoutnosuchnames = 0,
- snmpoutbadvalues = 0,
- snmpoutgenerrs = 0,
- snmpoutgetrequests = 0,
- snmpoutgetnexts = 0,
- snmpoutsetrequests = 0,
- snmpoutgetresponses = 0,
- snmpouttraps = 0;
-
-
-
-/* prototypes of the following functions are in lwip/src/include/lwip/snmp.h */
-/**
- * Copy octet string.
- *
- * @param dst points to destination
- * @param src points to source
- * @param n number of octets to copy.
- */
-void ocstrncpy(u8_t *dst, u8_t *src, u8_t n)
-{
- while (n > 0)
- {
- n--;
- *dst++ = *src++;
- }
-}
-
-/**
- * Copy object identifier (s32_t) array.
- *
- * @param dst points to destination
- * @param src points to source
- * @param n number of sub identifiers to copy.
- */
-void objectidncpy(s32_t *dst, s32_t *src, u8_t n)
-{
- while(n > 0)
- {
- n--;
- *dst++ = *src++;
- }
-}
-
-/**
- * Initializes sysDescr pointers.
- *
- * @param str if non-NULL then copy str pointer
- * @param strlen points to string length, excluding zero terminator
- */
-void snmp_set_sysdesr(u8_t *str, u8_t *strlen)
-{
- if (str != NULL)
- {
- sysdescr_ptr = str;
- sysdescr_len_ptr = strlen;
- }
-}
-
-void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid)
-{
- *oid = &sysobjid;
-}
-
-/**
- * Initializes sysObjectID value.
- *
- * @param oid points to stuct snmp_obj_id to copy
- */
-void snmp_set_sysobjid(struct snmp_obj_id *oid)
-{
- sysobjid = *oid;
-}
-
-/**
- * Must be called at regular 10 msec interval from a timer interrupt
- * or signal handler depending on your runtime environment.
- */
-void snmp_inc_sysuptime(void)
-{
- sysuptime++;
-}
-
-void snmp_get_sysuptime(u32_t *value)
-{
- *value = sysuptime;
-}
-
-/**
- * Initializes sysContact pointers,
- * e.g. ptrs to non-volatile memory external to lwIP.
- *
- * @param str if non-NULL then copy str pointer
- * @param strlen points to string length, excluding zero terminator
- */
-void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen)
-{
- if (ocstr != NULL)
- {
- syscontact_ptr = ocstr;
- syscontact_len_ptr = ocstrlen;
- }
-}
-
-/**
- * Initializes sysName pointers,
- * e.g. ptrs to non-volatile memory external to lwIP.
- *
- * @param str if non-NULL then copy str pointer
- * @param strlen points to string length, excluding zero terminator
- */
-void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen)
-{
- if (ocstr != NULL)
- {
- sysname_ptr = ocstr;
- sysname_len_ptr = ocstrlen;
- }
-}
-
-/**
- * Initializes sysLocation pointers,
- * e.g. ptrs to non-volatile memory external to lwIP.
- *
- * @param str if non-NULL then copy str pointer
- * @param strlen points to string length, excluding zero terminator
- */
-void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen)
-{
- if (ocstr != NULL)
- {
- syslocation_ptr = ocstr;
- syslocation_len_ptr = ocstrlen;
- }
-}
-
-
-void snmp_add_ifinoctets(struct netif *ni, u32_t value)
-{
- ni->ifinoctets += value;
-}
-
-void snmp_inc_ifinucastpkts(struct netif *ni)
-{
- (ni->ifinucastpkts)++;
-}
-
-void snmp_inc_ifinnucastpkts(struct netif *ni)
-{
- (ni->ifinnucastpkts)++;
-}
-
-void snmp_inc_ifindiscards(struct netif *ni)
-{
- (ni->ifindiscards)++;
-}
-
-void snmp_add_ifoutoctets(struct netif *ni, u32_t value)
-{
- ni->ifoutoctets += value;
-}
-
-void snmp_inc_ifoutucastpkts(struct netif *ni)
-{
- (ni->ifoutucastpkts)++;
-}
-
-void snmp_inc_ifoutnucastpkts(struct netif *ni)
-{
- (ni->ifoutnucastpkts)++;
-}
-
-void snmp_inc_ifoutdiscards(struct netif *ni)
-{
- (ni->ifoutdiscards)++;
-}
-
-void snmp_inc_iflist(void)
-{
- struct mib_list_node *if_node = NULL;
-
- snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node);
- /* enable getnext traversal on filled table */
- iftable.maxlength = 1;
-}
-
-void snmp_dec_iflist(void)
-{
- snmp_mib_node_delete(&iflist_root, iflist_root.tail);
- /* disable getnext traversal on empty table */
- if(iflist_root.count == 0) iftable.maxlength = 0;
-}
-
-/**
- * Inserts ARP table indexes (.xIfIndex.xNetAddress)
- * into arp table index trees (both atTable and ipNetToMediaTable).
- */
-void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip)
-{
- struct mib_list_rootnode *at_rn;
- struct mib_list_node *at_node;
- struct ip_addr hip;
- s32_t arpidx[5];
- u8_t level, tree;
-
- LWIP_ASSERT("ni != NULL", ni != NULL);
- snmp_netiftoifindex(ni, &arpidx[0]);
- hip.addr = ntohl(ip->addr);
- snmp_iptooid(&hip, &arpidx[1]);
-
- for (tree = 0; tree < 2; tree++)
- {
- if (tree == 0)
- {
- at_rn = &arptree_root;
- }
- else
- {
- at_rn = &ipntomtree_root;
- }
- for (level = 0; level < 5; level++)
- {
- at_node = NULL;
- snmp_mib_node_insert(at_rn, arpidx[level], &at_node);
- if ((level != 4) && (at_node != NULL))
- {
- if (at_node->nptr == NULL)
- {
- at_rn = snmp_mib_lrn_alloc();
- at_node->nptr = (struct mib_node*)at_rn;
- if (at_rn != NULL)
- {
- if (level == 3)
- {
- if (tree == 0)
- {
- at_rn->get_object_def = atentry_get_object_def;
- at_rn->get_value = atentry_get_value;
- }
- else
- {
- at_rn->get_object_def = ip_ntomentry_get_object_def;
- at_rn->get_value = ip_ntomentry_get_value;
- }
- at_rn->set_test = noleafs_set_test;
- at_rn->set_value = noleafs_set_value;
- }
- }
- else
- {
- /* at_rn == NULL, malloc failure */
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full"));
- break;
- }
- }
- else
- {
- at_rn = (struct mib_list_rootnode*)at_node->nptr;
- }
- }
- }
- }
- /* enable getnext traversal on filled tables */
- at.maxlength = 1;
- ipntomtable.maxlength = 1;
-}
-
-/**
- * Removes ARP table indexes (.xIfIndex.xNetAddress)
- * from arp table index trees.
- */
-void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip)
-{
- struct mib_list_rootnode *at_rn, *next, *del_rn[5];
- struct mib_list_node *at_n, *del_n[5];
- struct ip_addr hip;
- s32_t arpidx[5];
- u8_t fc, tree, level, del_cnt;
-
- snmp_netiftoifindex(ni, &arpidx[0]);
- hip.addr = ntohl(ip->addr);
- snmp_iptooid(&hip, &arpidx[1]);
-
- for (tree = 0; tree < 2; tree++)
- {
- /* mark nodes for deletion */
- if (tree == 0)
- {
- at_rn = &arptree_root;
- }
- else
- {
- at_rn = &ipntomtree_root;
- }
- level = 0;
- del_cnt = 0;
- while ((level < 5) && (at_rn != NULL))
- {
- fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n);
- if (fc == 0)
- {
- /* arpidx[level] does not exist */
- del_cnt = 0;
- at_rn = NULL;
- }
- else if (fc == 1)
- {
- del_rn[del_cnt] = at_rn;
- del_n[del_cnt] = at_n;
- del_cnt++;
- at_rn = (struct mib_list_rootnode*)(at_n->nptr);
- }
- else if (fc == 2)
- {
- /* reset delete (2 or more childs) */
- del_cnt = 0;
- at_rn = (struct mib_list_rootnode*)(at_n->nptr);
- }
- level++;
- }
- /* delete marked index nodes */
- while (del_cnt > 0)
- {
- del_cnt--;
-
- at_rn = del_rn[del_cnt];
- at_n = del_n[del_cnt];
-
- next = snmp_mib_node_delete(at_rn, at_n);
- if (next != NULL)
- {
- LWIP_ASSERT("next_count == 0",next->count == 0);
- snmp_mib_lrn_free(next);
- }
- }
- }
- /* disable getnext traversal on empty tables */
- if(arptree_root.count == 0) at.maxlength = 0;
- if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0;
-}
-
-void snmp_inc_ipinreceives(void)
-{
- ipinreceives++;
-}
-
-void snmp_inc_ipinhdrerrors(void)
-{
- ipinhdrerrors++;
-}
-
-void snmp_inc_ipinaddrerrors(void)
-{
- ipinaddrerrors++;
-}
-
-void snmp_inc_ipforwdatagrams(void)
-{
- ipforwdatagrams++;
-}
-
-void snmp_inc_ipinunknownprotos(void)
-{
- ipinunknownprotos++;
-}
-
-void snmp_inc_ipindiscards(void)
-{
- ipindiscards++;
-}
-
-void snmp_inc_ipindelivers(void)
-{
- ipindelivers++;
-}
-
-void snmp_inc_ipoutrequests(void)
-{
- ipoutrequests++;
-}
-
-void snmp_inc_ipoutdiscards(void)
-{
- ipoutdiscards++;
-}
-
-void snmp_inc_ipoutnoroutes(void)
-{
- ipoutnoroutes++;
-}
-
-void snmp_inc_ipreasmreqds(void)
-{
- ipreasmreqds++;
-}
-
-void snmp_inc_ipreasmoks(void)
-{
- ipreasmoks++;
-}
-
-void snmp_inc_ipreasmfails(void)
-{
- ipreasmfails++;
-}
-
-void snmp_inc_ipfragoks(void)
-{
- ipfragoks++;
-}
-
-void snmp_inc_ipfragfails(void)
-{
- ipfragfails++;
-}
-
-void snmp_inc_ipfragcreates(void)
-{
- ipfragcreates++;
-}
-
-void snmp_inc_iproutingdiscards(void)
-{
- iproutingdiscards++;
-}
-
-/**
- * Inserts ipAddrTable indexes (.ipAdEntAddr)
- * into index tree.
- */
-void snmp_insert_ipaddridx_tree(struct netif *ni)
-{
- struct mib_list_rootnode *ipa_rn;
- struct mib_list_node *ipa_node;
- struct ip_addr ip;
- s32_t ipaddridx[4];
- u8_t level;
-
- LWIP_ASSERT("ni != NULL", ni != NULL);
- ip.addr = ntohl(ni->ip_addr.addr);
- snmp_iptooid(&ip, &ipaddridx[0]);
-
- level = 0;
- ipa_rn = &ipaddrtree_root;
- while (level < 4)
- {
- ipa_node = NULL;
- snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node);
- if ((level != 3) && (ipa_node != NULL))
- {
- if (ipa_node->nptr == NULL)
- {
- ipa_rn = snmp_mib_lrn_alloc();
- ipa_node->nptr = (struct mib_node*)ipa_rn;
- if (ipa_rn != NULL)
- {
- if (level == 2)
- {
- ipa_rn->get_object_def = ip_addrentry_get_object_def;
- ipa_rn->get_value = ip_addrentry_get_value;
- ipa_rn->set_test = noleafs_set_test;
- ipa_rn->set_value = noleafs_set_value;
- }
- }
- else
- {
- /* ipa_rn == NULL, malloc failure */
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full"));
- break;
- }
- }
- else
- {
- ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr;
- }
- }
- level++;
- }
- /* enable getnext traversal on filled table */
- ipaddrtable.maxlength = 1;
-}
-
-/**
- * Removes ipAddrTable indexes (.ipAdEntAddr)
- * from index tree.
- */
-void snmp_delete_ipaddridx_tree(struct netif *ni)
-{
- struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];
- struct mib_list_node *ipa_n, *del_n[4];
- struct ip_addr ip;
- s32_t ipaddridx[4];
- u8_t fc, level, del_cnt;
-
- LWIP_ASSERT("ni != NULL", ni != NULL);
- ip.addr = ntohl(ni->ip_addr.addr);
- snmp_iptooid(&ip, &ipaddridx[0]);
-
- /* mark nodes for deletion */
- level = 0;
- del_cnt = 0;
- ipa_rn = &ipaddrtree_root;
- while ((level < 4) && (ipa_rn != NULL))
- {
- fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n);
- if (fc == 0)
- {
- /* ipaddridx[level] does not exist */
- del_cnt = 0;
- ipa_rn = NULL;
- }
- else if (fc == 1)
- {
- del_rn[del_cnt] = ipa_rn;
- del_n[del_cnt] = ipa_n;
- del_cnt++;
- ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
- }
- else if (fc == 2)
- {
- /* reset delete (2 or more childs) */
- del_cnt = 0;
- ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
- }
- level++;
- }
- /* delete marked index nodes */
- while (del_cnt > 0)
- {
- del_cnt--;
-
- ipa_rn = del_rn[del_cnt];
- ipa_n = del_n[del_cnt];
-
- next = snmp_mib_node_delete(ipa_rn, ipa_n);
- if (next != NULL)
- {
- LWIP_ASSERT("next_count == 0",next->count == 0);
- snmp_mib_lrn_free(next);
- }
- }
- /* disable getnext traversal on empty table */
- if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0;
-}
-
-/**
- * Inserts ipRouteTable indexes (.ipRouteDest)
- * into index tree.
- *
- * @param dflt non-zero for the default rte, zero for network rte
- * @param netif points to network interface for this rte
- *
- * @todo record sysuptime for _this_ route when it is installed
- * (needed for ipRouteAge) in the netif.
- */
-void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
-{
- u8_t insert = 0;
- struct ip_addr dst;
-
- if (dflt != 0)
- {
- /* the default route 0.0.0.0 */
- dst.addr = 0;
- insert = 1;
- }
- else
- {
- /* route to the network address */
- dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
- /* exclude 0.0.0.0 network (reserved for default rte) */
- if (dst.addr != 0) insert = 1;
- }
- if (insert)
- {
- struct mib_list_rootnode *iprte_rn;
- struct mib_list_node *iprte_node;
- s32_t iprteidx[4];
- u8_t level;
-
- snmp_iptooid(&dst, &iprteidx[0]);
- level = 0;
- iprte_rn = &iprtetree_root;
- while (level < 4)
- {
- iprte_node = NULL;
- snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node);
- if ((level != 3) && (iprte_node != NULL))
- {
- if (iprte_node->nptr == NULL)
- {
- iprte_rn = snmp_mib_lrn_alloc();
- iprte_node->nptr = (struct mib_node*)iprte_rn;
- if (iprte_rn != NULL)
- {
- if (level == 2)
- {
- iprte_rn->get_object_def = ip_rteentry_get_object_def;
- iprte_rn->get_value = ip_rteentry_get_value;
- iprte_rn->set_test = noleafs_set_test;
- iprte_rn->set_value = noleafs_set_value;
- }
- }
- else
- {
- /* iprte_rn == NULL, malloc failure */
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full"));
- break;
- }
- }
- else
- {
- iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr;
- }
- }
- level++;
- }
- }
- /* enable getnext traversal on filled table */
- iprtetable.maxlength = 1;
-}
-
-/**
- * Removes ipRouteTable indexes (.ipRouteDest)
- * from index tree.
- *
- * @param dflt non-zero for the default rte, zero for network rte
- * @param netif points to network interface for this rte or NULL
- * for default route to be removed.
- */
-void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
-{
- u8_t delete = 0;
- struct ip_addr dst;
-
- if (dflt != 0)
- {
- /* the default route 0.0.0.0 */
- dst.addr = 0;
- delete = 1;
- }
- else
- {
- /* route to the network address */
- dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
- /* exclude 0.0.0.0 network (reserved for default rte) */
- if (dst.addr != 0) delete = 1;
- }
- if (delete)
- {
- struct mib_list_rootnode *iprte_rn, *next, *del_rn[4];
- struct mib_list_node *iprte_n, *del_n[4];
- s32_t iprteidx[4];
- u8_t fc, level, del_cnt;
-
- snmp_iptooid(&dst, &iprteidx[0]);
- /* mark nodes for deletion */
- level = 0;
- del_cnt = 0;
- iprte_rn = &iprtetree_root;
- while ((level < 4) && (iprte_rn != NULL))
- {
- fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n);
- if (fc == 0)
- {
- /* iprteidx[level] does not exist */
- del_cnt = 0;
- iprte_rn = NULL;
- }
- else if (fc == 1)
- {
- del_rn[del_cnt] = iprte_rn;
- del_n[del_cnt] = iprte_n;
- del_cnt++;
- iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
- }
- else if (fc == 2)
- {
- /* reset delete (2 or more childs) */
- del_cnt = 0;
- iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
- }
- level++;
- }
- /* delete marked index nodes */
- while (del_cnt > 0)
- {
- del_cnt--;
-
- iprte_rn = del_rn[del_cnt];
- iprte_n = del_n[del_cnt];
-
- next = snmp_mib_node_delete(iprte_rn, iprte_n);
- if (next != NULL)
- {
- LWIP_ASSERT("next_count == 0",next->count == 0);
- snmp_mib_lrn_free(next);
- }
- }
- }
- /* disable getnext traversal on empty table */
- if (iprtetree_root.count == 0) iprtetable.maxlength = 0;
-}
-
-
-void snmp_inc_icmpinmsgs(void)
-{
- icmpinmsgs++;
-}
-
-void snmp_inc_icmpinerrors(void)
-{
- icmpinerrors++;
-}
-
-void snmp_inc_icmpindestunreachs(void)
-{
- icmpindestunreachs++;
-}
-
-void snmp_inc_icmpintimeexcds(void)
-{
- icmpintimeexcds++;
-}
-
-void snmp_inc_icmpinparmprobs(void)
-{
- icmpinparmprobs++;
-}
-
-void snmp_inc_icmpinsrcquenchs(void)
-{
- icmpinsrcquenchs++;
-}
-
-void snmp_inc_icmpinredirects(void)
-{
- icmpinredirects++;
-}
-
-void snmp_inc_icmpinechos(void)
-{
- icmpinechos++;
-}
-
-void snmp_inc_icmpinechoreps(void)
-{
- icmpinechoreps++;
-}
-
-void snmp_inc_icmpintimestamps(void)
-{
- icmpintimestamps++;
-}
-
-void snmp_inc_icmpintimestampreps(void)
-{
- icmpintimestampreps++;
-}
-
-void snmp_inc_icmpinaddrmasks(void)
-{
- icmpinaddrmasks++;
-}
-
-void snmp_inc_icmpinaddrmaskreps(void)
-{
- icmpinaddrmaskreps++;
-}
-
-void snmp_inc_icmpoutmsgs(void)
-{
- icmpoutmsgs++;
-}
-
-void snmp_inc_icmpouterrors(void)
-{
- icmpouterrors++;
-}
-
-void snmp_inc_icmpoutdestunreachs(void)
-{
- icmpoutdestunreachs++;
-}
-
-void snmp_inc_icmpouttimeexcds(void)
-{
- icmpouttimeexcds++;
-}
-
-void snmp_inc_icmpoutparmprobs(void)
-{
- icmpoutparmprobs++;
-}
-
-void snmp_inc_icmpoutsrcquenchs(void)
-{
- icmpoutsrcquenchs++;
-}
-
-void snmp_inc_icmpoutredirects(void)
-{
- icmpoutredirects++;
-}
-
-void snmp_inc_icmpoutechos(void)
-{
- icmpoutechos++;
-}
-
-void snmp_inc_icmpoutechoreps(void)
-{
- icmpoutechoreps++;
-}
-
-void snmp_inc_icmpouttimestamps(void)
-{
- icmpouttimestamps++;
-}
-
-void snmp_inc_icmpouttimestampreps(void)
-{
- icmpouttimestampreps++;
-}
-
-void snmp_inc_icmpoutaddrmasks(void)
-{
- icmpoutaddrmasks++;
-}
-
-void snmp_inc_icmpoutaddrmaskreps(void)
-{
- icmpoutaddrmaskreps++;
-}
-
-void snmp_inc_tcpactiveopens(void)
-{
- tcpactiveopens++;
-}
-
-void snmp_inc_tcppassiveopens(void)
-{
- tcppassiveopens++;
-}
-
-void snmp_inc_tcpattemptfails(void)
-{
- tcpattemptfails++;
-}
-
-void snmp_inc_tcpestabresets(void)
-{
- tcpestabresets++;
-}
-
-void snmp_inc_tcpinsegs(void)
-{
- tcpinsegs++;
-}
-
-void snmp_inc_tcpoutsegs(void)
-{
- tcpoutsegs++;
-}
-
-void snmp_inc_tcpretranssegs(void)
-{
- tcpretranssegs++;
-}
-
-void snmp_inc_tcpinerrs(void)
-{
- tcpinerrs++;
-}
-
-void snmp_inc_tcpoutrsts(void)
-{
- tcpoutrsts++;
-}
-
-void snmp_inc_udpindatagrams(void)
-{
- udpindatagrams++;
-}
-
-void snmp_inc_udpnoports(void)
-{
- udpnoports++;
-}
-
-void snmp_inc_udpinerrors(void)
-{
- udpinerrors++;
-}
-
-void snmp_inc_udpoutdatagrams(void)
-{
- udpoutdatagrams++;
-}
-
-/**
- * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort)
- * into index tree.
- */
-void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
-{
- struct mib_list_rootnode *udp_rn;
- struct mib_list_node *udp_node;
- struct ip_addr ip;
- s32_t udpidx[5];
- u8_t level;
-
- LWIP_ASSERT("pcb != NULL", pcb != NULL);
- ip.addr = ntohl(pcb->local_ip.addr);
- snmp_iptooid(&ip, &udpidx[0]);
- udpidx[4] = pcb->local_port;
-
- udp_rn = &udp_root;
- for (level = 0; level < 5; level++)
- {
- udp_node = NULL;
- snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node);
- if ((level != 4) && (udp_node != NULL))
- {
- if (udp_node->nptr == NULL)
- {
- udp_rn = snmp_mib_lrn_alloc();
- udp_node->nptr = (struct mib_node*)udp_rn;
- if (udp_rn != NULL)
- {
- if (level == 3)
- {
- udp_rn->get_object_def = udpentry_get_object_def;
- udp_rn->get_value = udpentry_get_value;
- udp_rn->set_test = noleafs_set_test;
- udp_rn->set_value = noleafs_set_value;
- }
- }
- else
- {
- /* udp_rn == NULL, malloc failure */
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full"));
- break;
- }
- }
- else
- {
- udp_rn = (struct mib_list_rootnode*)udp_node->nptr;
- }
- }
- }
- udptable.maxlength = 1;
-}
-
-/**
- * Removes udpTable indexes (.udpLocalAddress.udpLocalPort)
- * from index tree.
- */
-void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
-{
- struct mib_list_rootnode *udp_rn, *next, *del_rn[5];
- struct mib_list_node *udp_n, *del_n[5];
- struct ip_addr ip;
- s32_t udpidx[5];
- u8_t bindings, fc, level, del_cnt;
-
- LWIP_ASSERT("pcb != NULL", pcb != NULL);
- ip.addr = ntohl(pcb->local_ip.addr);
- snmp_iptooid(&ip, &udpidx[0]);
- udpidx[4] = pcb->local_port;
-
- /* count PCBs for a given binding
- (e.g. when reusing ports or for temp output PCBs) */
- bindings = 0;
- pcb = udp_pcbs;
- while ((pcb != NULL))
- {
- if ((pcb->local_ip.addr == ip.addr) &&
- (pcb->local_port == udpidx[4]))
- {
- bindings++;
- }
- pcb = pcb->next;
- }
- if (bindings == 1)
- {
- /* selectively remove */
- /* mark nodes for deletion */
- level = 0;
- del_cnt = 0;
- udp_rn = &udp_root;
- while ((level < 5) && (udp_rn != NULL))
- {
- fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n);
- if (fc == 0)
- {
- /* udpidx[level] does not exist */
- del_cnt = 0;
- udp_rn = NULL;
- }
- else if (fc == 1)
- {
- del_rn[del_cnt] = udp_rn;
- del_n[del_cnt] = udp_n;
- del_cnt++;
- udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
- }
- else if (fc == 2)
- {
- /* reset delete (2 or more childs) */
- del_cnt = 0;
- udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
- }
- level++;
- }
- /* delete marked index nodes */
- while (del_cnt > 0)
- {
- del_cnt--;
-
- udp_rn = del_rn[del_cnt];
- udp_n = del_n[del_cnt];
-
- next = snmp_mib_node_delete(udp_rn, udp_n);
- if (next != NULL)
- {
- LWIP_ASSERT("next_count == 0",next->count == 0);
- snmp_mib_lrn_free(next);
- }
- }
- }
- /* disable getnext traversal on empty table */
- if (udp_root.count == 0) udptable.maxlength = 0;
-}
-
-
-void snmp_inc_snmpinpkts(void)
-{
- snmpinpkts++;
-}
-
-void snmp_inc_snmpoutpkts(void)
-{
- snmpoutpkts++;
-}
-
-void snmp_inc_snmpinbadversions(void)
-{
- snmpinbadversions++;
-}
-
-void snmp_inc_snmpinbadcommunitynames(void)
-{
- snmpinbadcommunitynames++;
-}
-
-void snmp_inc_snmpinbadcommunityuses(void)
-{
- snmpinbadcommunityuses++;
-}
-
-void snmp_inc_snmpinasnparseerrs(void)
-{
- snmpinasnparseerrs++;
-}
-
-void snmp_inc_snmpintoobigs(void)
-{
- snmpintoobigs++;
-}
-
-void snmp_inc_snmpinnosuchnames(void)
-{
- snmpinnosuchnames++;
-}
-
-void snmp_inc_snmpinbadvalues(void)
-{
- snmpinbadvalues++;
-}
-
-void snmp_inc_snmpinreadonlys(void)
-{
- snmpinreadonlys++;
-}
-
-void snmp_inc_snmpingenerrs(void)
-{
- snmpingenerrs++;
-}
-
-void snmp_add_snmpintotalreqvars(u8_t value)
-{
- snmpintotalreqvars += value;
-}
-
-void snmp_add_snmpintotalsetvars(u8_t value)
-{
- snmpintotalsetvars += value;
-}
-
-void snmp_inc_snmpingetrequests(void)
-{
- snmpingetrequests++;
-}
-
-void snmp_inc_snmpingetnexts(void)
-{
- snmpingetnexts++;
-}
-
-void snmp_inc_snmpinsetrequests(void)
-{
- snmpinsetrequests++;
-}
-
-void snmp_inc_snmpingetresponses(void)
-{
- snmpingetresponses++;
-}
-
-void snmp_inc_snmpintraps(void)
-{
- snmpintraps++;
-}
-
-void snmp_inc_snmpouttoobigs(void)
-{
- snmpouttoobigs++;
-}
-
-void snmp_inc_snmpoutnosuchnames(void)
-{
- snmpoutnosuchnames++;
-}
-
-void snmp_inc_snmpoutbadvalues(void)
-{
- snmpoutbadvalues++;
-}
-
-void snmp_inc_snmpoutgenerrs(void)
-{
- snmpoutgenerrs++;
-}
-
-void snmp_inc_snmpoutgetrequests(void)
-{
- snmpoutgetrequests++;
-}
-
-void snmp_inc_snmpoutgetnexts(void)
-{
- snmpoutgetnexts++;
-}
-
-void snmp_inc_snmpoutsetrequests(void)
-{
- snmpoutsetrequests++;
-}
-
-void snmp_inc_snmpoutgetresponses(void)
-{
- snmpoutgetresponses++;
-}
-
-void snmp_inc_snmpouttraps(void)
-{
- snmpouttraps++;
-}
-
-void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)
-{
- *oid = &snmpgrp_id;
-}
-
-void snmp_set_snmpenableauthentraps(u8_t *value)
-{
- if (value != NULL)
- {
- snmpenableauthentraps_ptr = value;
- }
-}
-
-void snmp_get_snmpenableauthentraps(u8_t *value)
-{
- *value = *snmpenableauthentraps_ptr;
-}
-
-void
-noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- if (ident_len){}
- if (ident){}
- od->instance = MIB_OBJECT_NONE;
-}
-
-void
-noleafs_get_value(struct obj_def *od, u16_t len, void *value)
-{
- if (od){}
- if (len){}
- if (value){}
-}
-
-u8_t
-noleafs_set_test(struct obj_def *od, u16_t len, void *value)
-{
- if (od){}
- if (len){}
- if (value){}
- /* can't set */
- return 0;
-}
-
-void
-noleafs_set_value(struct obj_def *od, u16_t len, void *value)
-{
- if (od){}
- if (len){}
- if (value){}
-}
-
-
-/**
- * Returns systems object definitions.
- *
- * @param ident_len the address length (2)
- * @param ident points to objectname.0 (object id trailer)
- * @param od points to object definition.
- */
-static void
-system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- u8_t id;
-
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if (ident_len == 2)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id));
- switch (id)
- {
- case 1: /* sysDescr */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = *sysdescr_len_ptr;
- break;
- case 2: /* sysObjectID */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
- od->v_len = sysobjid.len * sizeof(s32_t);
- break;
- case 3: /* sysUpTime */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
- od->v_len = sizeof(u32_t);
- break;
- case 4: /* sysContact */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = *syscontact_len_ptr;
- break;
- case 5: /* sysName */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = *sysname_len_ptr;
- break;
- case 6: /* sysLocation */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = *syslocation_len_ptr;
- break;
- case 7: /* sysServices */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- };
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-/**
- * Returns system object value.
- *
- * @param ident_len the address length (2)
- * @param ident points to objectname.0 (object id trailer)
- * @param len return value space (in bytes)
- * @param value points to (varbind) space to copy value into.
- */
-static void
-system_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
-
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* sysDescr */
- ocstrncpy(value,sysdescr_ptr,len);
- break;
- case 2: /* sysObjectID */
- objectidncpy((s32_t*)value,(s32_t*)sysobjid.id,len / sizeof(s32_t));
- break;
- case 3: /* sysUpTime */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = sysuptime;
- }
- break;
- case 4: /* sysContact */
- ocstrncpy(value,syscontact_ptr,len);
- break;
- case 5: /* sysName */
- ocstrncpy(value,sysname_ptr,len);
- break;
- case 6: /* sysLocation */
- ocstrncpy(value,syslocation_ptr,len);
- break;
- case 7: /* sysServices */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = sysservices;
- }
- break;
- };
-}
-
-static u8_t
-system_set_test(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id, set_ok;
-
- if (value) {}
- set_ok = 0;
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 4: /* sysContact */
- if ((syscontact_ptr != syscontact_default) &&
- (len <= 255))
- {
- set_ok = 1;
- }
- break;
- case 5: /* sysName */
- if ((sysname_ptr != sysname_default) &&
- (len <= 255))
- {
- set_ok = 1;
- }
- break;
- case 6: /* sysLocation */
- if ((syslocation_ptr != syslocation_default) &&
- (len <= 255))
- {
- set_ok = 1;
- }
- break;
- };
- return set_ok;
-}
-
-static void
-system_set_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
-
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 4: /* sysContact */
- ocstrncpy(syscontact_ptr,value,len);
- *syscontact_len_ptr = len;
- break;
- case 5: /* sysName */
- ocstrncpy(sysname_ptr,value,len);
- *sysname_len_ptr = len;
- break;
- case 6: /* sysLocation */
- ocstrncpy(syslocation_ptr,value,len);
- *syslocation_len_ptr = len;
- break;
- };
-}
-
-/**
- * Returns interfaces.ifnumber object definition.
- *
- * @param ident_len the address length (2)
- * @param ident points to objectname.index
- * @param od points to object definition.
- */
-static void
-interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if (ident_len == 2)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-/**
- * Returns interfaces.ifnumber object value.
- *
- * @param ident_len the address length (2)
- * @param ident points to objectname.0 (object id trailer)
- * @param len return value space (in bytes)
- * @param value points to (varbind) space to copy value into.
- */
-static void
-interfaces_get_value(struct obj_def *od, u16_t len, void *value)
-{
- if (len){}
- if (od->id_inst_ptr[0] == 1)
- {
- s32_t *sint_ptr = value;
- *sint_ptr = iflist_root.count;
- }
-}
-
-/**
- * Returns ifentry object definitions.
- *
- * @param ident_len the address length (2)
- * @param ident points to objectname.index
- * @param od points to object definition.
- */
-static void
-ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- u8_t id;
-
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if (ident_len == 2)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id));
- switch (id)
- {
- case 1: /* ifIndex */
- case 3: /* ifType */
- case 4: /* ifMtu */
- case 8: /* ifOperStatus */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 2: /* ifDescr */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- /** @todo this should be some sort of sizeof(struct netif.name) */
- od->v_len = 2;
- break;
- case 5: /* ifSpeed */
- case 21: /* ifOutQLen */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
- od->v_len = sizeof(u32_t);
- break;
- case 6: /* ifPhysAddress */
- {
- struct netif *netif;
-
- snmp_ifindextonetif(ident[1], &netif);
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = netif->hwaddr_len;
- }
- break;
- case 7: /* ifAdminStatus */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 9: /* ifLastChange */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
- od->v_len = sizeof(u32_t);
- break;
- case 10: /* ifInOctets */
- case 11: /* ifInUcastPkts */
- case 12: /* ifInNUcastPkts */
- case 13: /* ifInDiscarts */
- case 14: /* ifInErrors */
- case 15: /* ifInUnkownProtos */
- case 16: /* ifOutOctets */
- case 17: /* ifOutUcastPkts */
- case 18: /* ifOutNUcastPkts */
- case 19: /* ifOutDiscarts */
- case 20: /* ifOutErrors */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
- od->v_len = sizeof(u32_t);
- break;
- case 22: /* ifSpecific */
- /** @note returning zeroDotZero (0.0) no media specific MIB support */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
- od->v_len = ifspecific.len * sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- };
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-/**
- * Returns ifentry object value.
- *
- * @param ident_len the address length (2)
- * @param ident points to objectname.0 (object id trailer)
- * @param len return value space (in bytes)
- * @param value points to (varbind) space to copy value into.
- */
-static void
-ifentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- struct netif *netif;
- u8_t id;
-
- snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* ifIndex */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = od->id_inst_ptr[1];
- }
- break;
- case 2: /* ifDescr */
- ocstrncpy(value,(u8_t*)netif->name,len);
- break;
- case 3: /* ifType */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = netif->link_type;
- }
- break;
- case 4: /* ifMtu */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = netif->mtu;
- }
- break;
- case 5: /* ifSpeed */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->link_speed;
- }
- break;
- case 6: /* ifPhysAddress */
- ocstrncpy(value,netif->hwaddr,len);
- break;
- case 7: /* ifAdminStatus */
- case 8: /* ifOperStatus */
- {
- s32_t *sint_ptr = value;
- if (netif_is_up(netif))
- {
- *sint_ptr = 1;
- }
- else
- {
- *sint_ptr = 2;
- }
- }
- break;
- case 9: /* ifLastChange */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ts;
- }
- break;
- case 10: /* ifInOctets */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifinoctets;
- }
- break;
- case 11: /* ifInUcastPkts */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifinucastpkts;
- }
- break;
- case 12: /* ifInNUcastPkts */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifinnucastpkts;
- }
- break;
- case 13: /* ifInDiscarts */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifindiscards;
- }
- break;
- case 14: /* ifInErrors */
- case 15: /* ifInUnkownProtos */
- /** @todo add these counters! */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = 0;
- }
- break;
- case 16: /* ifOutOctets */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifoutoctets;
- }
- break;
- case 17: /* ifOutUcastPkts */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifoutucastpkts;
- }
- break;
- case 18: /* ifOutNUcastPkts */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifoutnucastpkts;
- }
- break;
- case 19: /* ifOutDiscarts */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = netif->ifoutdiscards;
- }
- break;
- case 20: /* ifOutErrors */
- /** @todo add this counter! */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = 0;
- }
- break;
- case 21: /* ifOutQLen */
- /** @todo figure out if this must be 0 (no queue) or 1? */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = 0;
- }
- break;
- case 22: /* ifSpecific */
- objectidncpy((s32_t*)value,(s32_t*)ifspecific.id,len / sizeof(s32_t));
- break;
- };
-}
-
-/**
- * Returns atentry object definitions.
- *
- * @param ident_len the address length (6)
- * @param ident points to objectname.atifindex.atnetaddress
- * @param od points to object definition.
- */
-static void
-atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (5) */
- ident_len += 5;
- ident -= 5;
-
- if (ident_len == 6)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- switch (ident[0])
- {
- case 1: /* atIfIndex */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 2: /* atPhysAddress */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = sizeof(struct eth_addr);
- break;
- case 3: /* atNetAddress */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
- od->v_len = 4;
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- }
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-atentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
- struct eth_addr* ethaddr_ret;
- struct ip_addr* ipaddr_ret;
- struct ip_addr ip;
- struct netif *netif;
-
- if (len) {}
-
- snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
- snmp_oidtoip(&od->id_inst_ptr[2], &ip);
- ip.addr = htonl(ip.addr);
-
- if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
- {
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* atIfIndex */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = od->id_inst_ptr[1];
- }
- break;
- case 2: /* atPhysAddress */
- {
- struct eth_addr *dst = value;
-
- *dst = *ethaddr_ret;
- }
- break;
- case 3: /* atNetAddress */
- {
- struct ip_addr *dst = value;
-
- *dst = *ipaddr_ret;
- }
- break;
- }
- }
-}
-
-static void
-ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- u8_t id;
-
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if (ident_len == 2)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id));
- switch (id)
- {
- case 1: /* ipForwarding */
- case 2: /* ipDefaultTTL */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 3: /* ipInReceives */
- case 4: /* ipInHdrErrors */
- case 5: /* ipInAddrErrors */
- case 6: /* ipForwDatagrams */
- case 7: /* ipInUnknownProtos */
- case 8: /* ipInDiscards */
- case 9: /* ipInDelivers */
- case 10: /* ipOutRequests */
- case 11: /* ipOutDiscards */
- case 12: /* ipOutNoRoutes */
- case 14: /* ipReasmReqds */
- case 15: /* ipReasmOKs */
- case 16: /* ipReasmFails */
- case 17: /* ipFragOKs */
- case 18: /* ipFragFails */
- case 19: /* ipFragCreates */
- case 23: /* ipRoutingDiscards */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
- od->v_len = sizeof(u32_t);
- break;
- case 13: /* ipReasmTimeout */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- };
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-ip_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
-
- if (len) {}
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* ipForwarding */
- {
- s32_t *sint_ptr = value;
-#if IP_FORWARD
- /* forwarding */
- *sint_ptr = 1;
-#else
- /* not-forwarding */
- *sint_ptr = 2;
-#endif
- }
- break;
- case 2: /* ipDefaultTTL */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = IP_DEFAULT_TTL;
- }
- break;
- case 3: /* ipInReceives */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipinreceives;
- }
- break;
- case 4: /* ipInHdrErrors */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipinhdrerrors;
- }
- break;
- case 5: /* ipInAddrErrors */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipinaddrerrors;
- }
- break;
- case 6: /* ipForwDatagrams */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipforwdatagrams;
- }
- break;
- case 7: /* ipInUnknownProtos */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipinunknownprotos;
- }
- break;
- case 8: /* ipInDiscards */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipindiscards;
- }
- break;
- case 9: /* ipInDelivers */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipindelivers;
- }
- break;
- case 10: /* ipOutRequests */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipoutrequests;
- }
- break;
- case 11: /* ipOutDiscards */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipoutdiscards;
- }
- break;
- case 12: /* ipOutNoRoutes */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipoutnoroutes;
- }
- break;
- case 13: /* ipReasmTimeout */
- {
- s32_t *sint_ptr = value;
-#if IP_REASSEMBLY
- *sint_ptr = IP_REASS_MAXAGE;
-#else
- *sint_ptr = 0;
-#endif
- }
- break;
- case 14: /* ipReasmReqds */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipreasmreqds;
- }
- break;
- case 15: /* ipReasmOKs */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipreasmoks;
- }
- break;
- case 16: /* ipReasmFails */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipreasmfails;
- }
- break;
- case 17: /* ipFragOKs */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipfragoks;
- }
- break;
- case 18: /* ipFragFails */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipfragfails;
- }
- break;
- case 19: /* ipFragCreates */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = ipfragcreates;
- }
- break;
- case 23: /* ipRoutingDiscards */
- /** @todo can lwIP discard routes at all?? hardwire this to 0?? */
- {
- u32_t *uint_ptr = value;
- *uint_ptr = iproutingdiscards;
- }
- break;
- };
-}
-
-/**
- * Test ip object value before setting.
- *
- * @param od is the object definition
- * @param len return value space (in bytes)
- * @param value points to (varbind) space to copy value from.
- *
- * @note we allow set if the value matches the hardwired value,
- * otherwise return badvalue.
- */
-static u8_t
-ip_set_test(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id, set_ok;
- s32_t *sint_ptr = value;
-
- if (len) {}
- set_ok = 0;
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* ipForwarding */
-#if IP_FORWARD
- /* forwarding */
- if (*sint_ptr == 1)
-#else
- /* not-forwarding */
- if (*sint_ptr == 2)
-#endif
- {
- set_ok = 1;
- }
- break;
- case 2: /* ipDefaultTTL */
- if (*sint_ptr == IP_DEFAULT_TTL)
- {
- set_ok = 1;
- }
- break;
- };
- return set_ok;
-}
-
-static void
-ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (4) */
- ident_len += 4;
- ident -= 4;
-
- if (ident_len == 5)
- {
- u8_t id;
-
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- switch (id)
- {
- case 1: /* ipAdEntAddr */
- case 3: /* ipAdEntNetMask */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
- od->v_len = 4;
- break;
- case 2: /* ipAdEntIfIndex */
- case 4: /* ipAdEntBcastAddr */
- case 5: /* ipAdEntReasmMaxSize */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- }
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
- u16_t ifidx;
- struct ip_addr ip;
- struct netif *netif = netif_list;
-
- if (len) {}
- snmp_oidtoip(&od->id_inst_ptr[1], &ip);
- ip.addr = htonl(ip.addr);
- ifidx = 0;
- while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
- {
- netif = netif->next;
- ifidx++;
- }
-
- if (netif != NULL)
- {
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* ipAdEntAddr */
- {
- struct ip_addr *dst = value;
- *dst = netif->ip_addr;
- }
- break;
- case 2: /* ipAdEntIfIndex */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = ifidx + 1;
- }
- break;
- case 3: /* ipAdEntNetMask */
- {
- struct ip_addr *dst = value;
- *dst = netif->netmask;
- }
- break;
- case 4: /* ipAdEntBcastAddr */
- {
- s32_t *sint_ptr = value;
-
- /* lwIP oddity, there's no broadcast
- address in the netif we can rely on */
- *sint_ptr = ip_addr_broadcast.addr & 1;
- }
- break;
- case 5: /* ipAdEntReasmMaxSize */
- {
- s32_t *sint_ptr = value;
-#if IP_REASSEMBLY
- *sint_ptr = (IP_HLEN + IP_REASS_BUFSIZE);
-#else
- /** @todo returning MTU would be a bad thing and
- returning a wild guess like '576' isn't good either */
- *sint_ptr = 0;
-#endif
- }
- break;
- }
- }
-}
-
-/**
- * @note
- * lwIP IP routing is currently using the network addresses in netif_list.
- * if no suitable network IP is found in netif_list, the default_netif is used.
- */
-static void
-ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- u8_t id;
-
- /* return to object name, adding index depth (4) */
- ident_len += 4;
- ident -= 4;
-
- if (ident_len == 5)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- switch (id)
- {
- case 1: /* ipRouteDest */
- case 7: /* ipRouteNextHop */
- case 11: /* ipRouteMask */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
- od->v_len = 4;
- break;
- case 2: /* ipRouteIfIndex */
- case 3: /* ipRouteMetric1 */
- case 4: /* ipRouteMetric2 */
- case 5: /* ipRouteMetric3 */
- case 6: /* ipRouteMetric4 */
- case 8: /* ipRouteType */
- case 10: /* ipRouteAge */
- case 12: /* ipRouteMetric5 */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 9: /* ipRouteProto */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 13: /* ipRouteInfo */
- /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
- od->v_len = iprouteinfo.len * sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- }
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- struct netif *netif;
- struct ip_addr dest;
- s32_t *ident;
- u8_t id;
-
- ident = od->id_inst_ptr;
- snmp_oidtoip(&ident[1], &dest);
- dest.addr = htonl(dest.addr);
-
- if (dest.addr == 0)
- {
- /* ip_route() uses default netif for default route */
- netif = netif_default;
- }
- else
- {
- /* not using ip_route(), need exact match! */
- netif = netif_list;
- while ((netif != NULL) &&
- !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
- {
- netif = netif->next;
- }
- }
- if (netif != NULL)
- {
- id = ident[0];
- switch (id)
- {
- case 1: /* ipRouteDest */
- {
- struct ip_addr *dst = value;
-
- if (dest.addr == 0)
- {
- /* default rte has 0.0.0.0 dest */
- dst->addr = 0;
- }
- else
- {
- /* netifs have netaddress dest */
- dst->addr = netif->ip_addr.addr & netif->netmask.addr;
- }
- }
- break;
- case 2: /* ipRouteIfIndex */
- {
- s32_t *sint_ptr = value;
-
- snmp_netiftoifindex(netif, sint_ptr);
- }
- break;
- case 3: /* ipRouteMetric1 */
- {
- s32_t *sint_ptr = value;
-
- if (dest.addr == 0)
- {
- /* default rte has metric 1 */
- *sint_ptr = 1;
- }
- else
- {
- /* other rtes have metric 0 */
- *sint_ptr = 0;
- }
- }
- break;
- case 4: /* ipRouteMetric2 */
- case 5: /* ipRouteMetric3 */
- case 6: /* ipRouteMetric4 */
- case 12: /* ipRouteMetric5 */
- {
- s32_t *sint_ptr = value;
- /* not used */
- *sint_ptr = -1;
- }
- break;
- case 7: /* ipRouteNextHop */
- {
- struct ip_addr *dst = value;
-
- if (dest.addr == 0)
- {
- /* default rte: gateway */
- *dst = netif->gw;
- }
- else
- {
- /* other rtes: netif ip_addr */
- *dst = netif->ip_addr;
- }
- }
- break;
- case 8: /* ipRouteType */
- {
- s32_t *sint_ptr = value;
-
- if (dest.addr == 0)
- {
- /* default rte is indirect */
- *sint_ptr = 4;
- }
- else
- {
- /* other rtes are direct */
- *sint_ptr = 3;
- }
- }
- break;
- case 9: /* ipRouteProto */
- {
- s32_t *sint_ptr = value;
- /* locally defined routes */
- *sint_ptr = 2;
- }
- break;
- case 10: /* ipRouteAge */
- {
- s32_t *sint_ptr = value;
- /** @todo (sysuptime - timestamp last change) / 100
- @see snmp_insert_iprteidx_tree() */
- *sint_ptr = 0;
- }
- break;
- case 11: /* ipRouteMask */
- {
- struct ip_addr *dst = value;
-
- if (dest.addr == 0)
- {
- /* default rte use 0.0.0.0 mask */
- dst->addr = 0;
- }
- else
- {
- /* other rtes use netmask */
- *dst = netif->netmask;
- }
- }
- break;
- case 13: /* ipRouteInfo */
- objectidncpy((s32_t*)value,(s32_t*)iprouteinfo.id,len / sizeof(s32_t));
- break;
- }
- }
-}
-
-static void
-ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (5) */
- ident_len += 5;
- ident -= 5;
-
- if (ident_len == 6)
- {
- u8_t id;
-
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- switch (id)
- {
- case 1: /* ipNetToMediaIfIndex */
- case 4: /* ipNetToMediaType */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 2: /* ipNetToMediaPhysAddress */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
- od->v_len = sizeof(struct eth_addr);
- break;
- case 3: /* ipNetToMediaNetAddress */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
- od->v_len = 4;
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- }
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
- struct eth_addr* ethaddr_ret;
- struct ip_addr* ipaddr_ret;
- struct ip_addr ip;
- struct netif *netif;
-
- if (len) {}
-
- snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
- snmp_oidtoip(&od->id_inst_ptr[2], &ip);
- ip.addr = htonl(ip.addr);
-
- if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)
- {
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* ipNetToMediaIfIndex */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = od->id_inst_ptr[1];
- }
- break;
- case 2: /* ipNetToMediaPhysAddress */
- {
- struct eth_addr *dst = value;
-
- *dst = *ethaddr_ret;
- }
- break;
- case 3: /* ipNetToMediaNetAddress */
- {
- struct ip_addr *dst = value;
-
- *dst = *ipaddr_ret;
- }
- break;
- case 4: /* ipNetToMediaType */
- {
- s32_t *sint_ptr = value;
- /* dynamic (?) */
- *sint_ptr = 3;
- }
- break;
- }
- }
-}
-
-static void
-icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if ((ident_len == 2) &&
- (ident[0] > 0) && (ident[0] < 27))
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
- od->v_len = sizeof(u32_t);
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-icmp_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u32_t *uint_ptr = value;
- u8_t id;
-
- if (len){}
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* icmpInMsgs */
- *uint_ptr = icmpinmsgs;
- break;
- case 2: /* icmpInErrors */
- *uint_ptr = icmpinerrors;
- break;
- case 3: /* icmpInDestUnreachs */
- *uint_ptr = icmpindestunreachs;
- break;
- case 4: /* icmpInTimeExcds */
- *uint_ptr = icmpintimeexcds;
- break;
- case 5: /* icmpInParmProbs */
- *uint_ptr = icmpinparmprobs;
- break;
- case 6: /* icmpInSrcQuenchs */
- *uint_ptr = icmpinsrcquenchs;
- break;
- case 7: /* icmpInRedirects */
- *uint_ptr = icmpinredirects;
- break;
- case 8: /* icmpInEchos */
- *uint_ptr = icmpinechos;
- break;
- case 9: /* icmpInEchoReps */
- *uint_ptr = icmpinechoreps;
- break;
- case 10: /* icmpInTimestamps */
- *uint_ptr = icmpintimestamps;
- break;
- case 11: /* icmpInTimestampReps */
- *uint_ptr = icmpintimestampreps;
- break;
- case 12: /* icmpInAddrMasks */
- *uint_ptr = icmpinaddrmasks;
- break;
- case 13: /* icmpInAddrMaskReps */
- *uint_ptr = icmpinaddrmaskreps;
- break;
- case 14: /* icmpOutMsgs */
- *uint_ptr = icmpoutmsgs;
- break;
- case 15: /* icmpOutErrors */
- *uint_ptr = icmpouterrors;
- break;
- case 16: /* icmpOutDestUnreachs */
- *uint_ptr = icmpoutdestunreachs;
- break;
- case 17: /* icmpOutTimeExcds */
- *uint_ptr = icmpouttimeexcds;
- break;
- case 18: /* icmpOutParmProbs */
- *uint_ptr = icmpoutparmprobs;
- break;
- case 19: /* icmpOutSrcQuenchs */
- *uint_ptr = icmpoutsrcquenchs;
- break;
- case 20: /* icmpOutRedirects */
- *uint_ptr = icmpoutredirects;
- break;
- case 21: /* icmpOutEchos */
- *uint_ptr = icmpoutechos;
- break;
- case 22: /* icmpOutEchoReps */
- *uint_ptr = icmpoutechoreps;
- break;
- case 23: /* icmpOutTimestamps */
- *uint_ptr = icmpouttimestamps;
- break;
- case 24: /* icmpOutTimestampReps */
- *uint_ptr = icmpouttimestampreps;
- break;
- case 25: /* icmpOutAddrMasks */
- *uint_ptr = icmpoutaddrmasks;
- break;
- case 26: /* icmpOutAddrMaskReps */
- *uint_ptr = icmpoutaddrmaskreps;
- break;
- }
-}
-
-#if LWIP_TCP
-/** @todo tcp grp */
-static void
-tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- u8_t id;
-
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if (ident_len == 2)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
-
- switch (id)
- {
- case 1: /* tcpRtoAlgorithm */
- case 2: /* tcpRtoMin */
- case 3: /* tcpRtoMax */
- case 4: /* tcpMaxConn */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 5: /* tcpActiveOpens */
- case 6: /* tcpPassiveOpens */
- case 7: /* tcpAttemptFails */
- case 8: /* tcpEstabResets */
- case 10: /* tcpInSegs */
- case 11: /* tcpOutSegs */
- case 12: /* tcpRetransSegs */
- case 14: /* tcpInErrs */
- case 15: /* tcpOutRsts */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
- od->v_len = sizeof(u32_t);
- break;
- case 9: /* tcpCurrEstab */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
- od->v_len = sizeof(u32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- };
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-tcp_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u32_t *uint_ptr = value;
- s32_t *sint_ptr = value;
- u8_t id;
-
- if (len){}
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* tcpRtoAlgorithm, vanj(4) */
- *sint_ptr = 4;
- break;
- case 2: /* tcpRtoMin */
- /* @todo not the actual value, a guess,
- needs to be calculated */
- *sint_ptr = 1000;
- break;
- case 3: /* tcpRtoMax */
- /* @todo not the actual value, a guess,
- needs to be calculated */
- *sint_ptr = 60000;
- break;
- case 4: /* tcpMaxConn */
- *sint_ptr = MEMP_NUM_TCP_PCB;
- break;
- case 5: /* tcpActiveOpens */
- *uint_ptr = tcpactiveopens;
- break;
- case 6: /* tcpPassiveOpens */
- *uint_ptr = tcppassiveopens;
- break;
- case 7: /* tcpAttemptFails */
- *uint_ptr = tcpattemptfails;
- break;
- case 8: /* tcpEstabResets */
- *uint_ptr = tcpestabresets;
- break;
- case 9: /* tcpCurrEstab */
- {
- u16_t tcpcurrestab = 0;
- struct tcp_pcb *pcb = tcp_active_pcbs;
- while (pcb != NULL)
- {
- if ((pcb->state == ESTABLISHED) ||
- (pcb->state == CLOSE_WAIT))
- {
- tcpcurrestab++;
- }
- pcb = pcb->next;
- }
- *uint_ptr = tcpcurrestab;
- }
- break;
- case 10: /* tcpInSegs */
- *uint_ptr = tcpinsegs;
- break;
- case 11: /* tcpOutSegs */
- *uint_ptr = tcpoutsegs;
- break;
- case 12: /* tcpRetransSegs */
- *uint_ptr = tcpretranssegs;
- break;
- case 14: /* tcpInErrs */
- *uint_ptr = tcpinerrs;
- break;
- case 15: /* tcpOutRsts */
- *uint_ptr = tcpoutrsts;
- break;
- }
-}
-
-static void
-tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (10) */
- ident_len += 10;
- ident -= 10;
-
- if (ident_len == 11)
- {
- u8_t id;
-
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
-
- switch (id)
- {
- case 1: /* tcpConnState */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- case 2: /* tcpConnLocalAddress */
- case 4: /* tcpConnRemAddress */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
- od->v_len = 4;
- break;
- case 3: /* tcpConnLocalPort */
- case 5: /* tcpConnRemPort */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- };
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- struct ip_addr lip, rip;
- u16_t lport, rport;
- s32_t *ident;
-
- ident = od->id_inst_ptr;
- snmp_oidtoip(&ident[1], &lip);
- lip.addr = htonl(lip.addr);
- lport = ident[5];
- snmp_oidtoip(&ident[6], &rip);
- rip.addr = htonl(rip.addr);
- rport = ident[10];
-
- /** @todo find matching PCB */
-}
-#endif
-
-static void
-udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if ((ident_len == 2) &&
- (ident[0] > 0) && (ident[0] < 6))
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
- od->v_len = sizeof(u32_t);
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-udp_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u32_t *uint_ptr = value;
- u8_t id;
-
- if (len){}
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* udpInDatagrams */
- *uint_ptr = udpindatagrams;
- break;
- case 2: /* udpNoPorts */
- *uint_ptr = udpnoports;
- break;
- case 3: /* udpInErrors */
- *uint_ptr = udpinerrors;
- break;
- case 4: /* udpOutDatagrams */
- *uint_ptr = udpoutdatagrams;
- break;
- }
-}
-
-static void
-udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (5) */
- ident_len += 5;
- ident -= 5;
-
- if (ident_len == 6)
- {
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- switch (ident[0])
- {
- case 1: /* udpLocalAddress */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
- od->v_len = 4;
- break;
- case 2: /* udpLocalPort */
- od->instance = MIB_OBJECT_TAB;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- }
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-udpentry_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
- struct udp_pcb *pcb;
- struct ip_addr ip;
- u16_t port;
-
- if (len){}
- snmp_oidtoip(&od->id_inst_ptr[1], &ip);
- ip.addr = htonl(ip.addr);
- port = od->id_inst_ptr[5];
-
- pcb = udp_pcbs;
- while ((pcb != NULL) &&
- !((pcb->local_ip.addr == ip.addr) &&
- (pcb->local_port == port)))
- {
- pcb = pcb->next;
- }
-
- if (pcb != NULL)
- {
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* udpLocalAddress */
- {
- struct ip_addr *dst = value;
- *dst = pcb->local_ip;
- }
- break;
- case 2: /* udpLocalPort */
- {
- s32_t *sint_ptr = value;
- *sint_ptr = pcb->local_port;
- }
- break;
- }
- }
-}
-
-static void
-snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
-{
- /* return to object name, adding index depth (1) */
- ident_len += 1;
- ident -= 1;
- if (ident_len == 2)
- {
- u8_t id;
-
- od->id_inst_len = ident_len;
- od->id_inst_ptr = ident;
-
- id = ident[0];
- switch (id)
- {
- case 1: /* snmpInPkts */
- case 2: /* snmpOutPkts */
- case 3: /* snmpInBadVersions */
- case 4: /* snmpInBadCommunityNames */
- case 5: /* snmpInBadCommunityUses */
- case 6: /* snmpInASNParseErrs */
- case 8: /* snmpInTooBigs */
- case 9: /* snmpInNoSuchNames */
- case 10: /* snmpInBadValues */
- case 11: /* snmpInReadOnlys */
- case 12: /* snmpInGenErrs */
- case 13: /* snmpInTotalReqVars */
- case 14: /* snmpInTotalSetVars */
- case 15: /* snmpInGetRequests */
- case 16: /* snmpInGetNexts */
- case 17: /* snmpInSetRequests */
- case 18: /* snmpInGetResponses */
- case 19: /* snmpInTraps */
- case 20: /* snmpOutTooBigs */
- case 21: /* snmpOutNoSuchNames */
- case 22: /* snmpOutBadValues */
- case 24: /* snmpOutGenErrs */
- case 25: /* snmpOutGetRequests */
- case 26: /* snmpOutGetNexts */
- case 27: /* snmpOutSetRequests */
- case 28: /* snmpOutGetResponses */
- case 29: /* snmpOutTraps */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_ONLY;
- od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
- od->v_len = sizeof(u32_t);
- break;
- case 30: /* snmpEnableAuthenTraps */
- od->instance = MIB_OBJECT_SCALAR;
- od->access = MIB_OBJECT_READ_WRITE;
- od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
- od->v_len = sizeof(s32_t);
- break;
- default:
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n"));
- od->instance = MIB_OBJECT_NONE;
- break;
- };
- }
- else
- {
- LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n"));
- od->instance = MIB_OBJECT_NONE;
- }
-}
-
-static void
-snmp_get_value(struct obj_def *od, u16_t len, void *value)
-{
- u32_t *uint_ptr = value;
- u8_t id;
-
- if (len){}
- id = od->id_inst_ptr[0];
- switch (id)
- {
- case 1: /* snmpInPkts */
- *uint_ptr = snmpinpkts;
- break;
- case 2: /* snmpOutPkts */
- *uint_ptr = snmpoutpkts;
- break;
- case 3: /* snmpInBadVersions */
- *uint_ptr = snmpinbadversions;
- break;
- case 4: /* snmpInBadCommunityNames */
- *uint_ptr = snmpinbadcommunitynames;
- break;
- case 5: /* snmpInBadCommunityUses */
- *uint_ptr = snmpinbadcommunityuses;
- break;
- case 6: /* snmpInASNParseErrs */
- *uint_ptr = snmpinasnparseerrs;
- break;
- case 8: /* snmpInTooBigs */
- *uint_ptr = snmpintoobigs;
- break;
- case 9: /* snmpInNoSuchNames */
- *uint_ptr = snmpinnosuchnames;
- break;
- case 10: /* snmpInBadValues */
- *uint_ptr = snmpinbadvalues;
- break;
- case 11: /* snmpInReadOnlys */
- *uint_ptr = snmpinreadonlys;
- break;
- case 12: /* snmpInGenErrs */
- *uint_ptr = snmpingenerrs;
- break;
- case 13: /* snmpInTotalReqVars */
- *uint_ptr = snmpintotalreqvars;
- break;
- case 14: /* snmpInTotalSetVars */
- *uint_ptr = snmpintotalsetvars;
- break;
- case 15: /* snmpInGetRequests */
- *uint_ptr = snmpingetrequests;
- break;
- case 16: /* snmpInGetNexts */
- *uint_ptr = snmpingetnexts;
- break;
- case 17: /* snmpInSetRequests */
- *uint_ptr = snmpinsetrequests;
- break;
- case 18: /* snmpInGetResponses */
- *uint_ptr = snmpingetresponses;
- break;
- case 19: /* snmpInTraps */
- *uint_ptr = snmpintraps;
- break;
- case 20: /* snmpOutTooBigs */
- *uint_ptr = snmpouttoobigs;
- break;
- case 21: /* snmpOutNoSuchNames */
- *uint_ptr = snmpoutnosuchnames;
- break;
- case 22: /* snmpOutBadValues */
- *uint_ptr = snmpoutbadvalues;
- break;
- case 24: /* snmpOutGenErrs */
- *uint_ptr = snmpoutgenerrs;
- break;
- case 25: /* snmpOutGetRequests */
- *uint_ptr = snmpoutgetrequests;
- break;
- case 26: /* snmpOutGetNexts */
- *uint_ptr = snmpoutgetnexts;
- break;
- case 27: /* snmpOutSetRequests */
- *uint_ptr = snmpoutsetrequests;
- break;
- case 28: /* snmpOutGetResponses */
- *uint_ptr = snmpoutgetresponses;
- break;
- case 29: /* snmpOutTraps */
- *uint_ptr = snmpouttraps;
- break;
- case 30: /* snmpEnableAuthenTraps */
- *uint_ptr = *snmpenableauthentraps_ptr;
- break;
- };
-}
-
-/**
- * Test snmp object value before setting.
- *
- * @param od is the object definition
- * @param len return value space (in bytes)
- * @param value points to (varbind) space to copy value from.
- */
-static u8_t
-snmp_set_test(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id, set_ok;
-
- if (len) {}
- set_ok = 0;
- id = od->id_inst_ptr[0];
- if (id == 30)
- {
- /* snmpEnableAuthenTraps */
- s32_t *sint_ptr = value;
-
- if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default)
- {
- /* we should have writable non-volatile mem here */
- if ((*sint_ptr == 1) || (*sint_ptr == 2))
- {
- set_ok = 1;
- }
- }
- else
- {
- /* const or hardwired value */
- if (*sint_ptr == snmpenableauthentraps_default)
- {
- set_ok = 1;
- }
- }
- }
- return set_ok;
-}
-
-static void
-snmp_set_value(struct obj_def *od, u16_t len, void *value)
-{
- u8_t id;
-
- if (len) {}
- id = od->id_inst_ptr[0];
- if (id == 30)
- {
- /* snmpEnableAuthenTraps */
- s32_t *sint_ptr = value;
- *snmpenableauthentraps_ptr = *sint_ptr;
- }
-}
-
-#endif /* LWIP_SNMP */
+/**\r
+ * @file\r
+ * Management Information Base II (RFC1213) objects and functions.\r
+ *\r
+ * @note the object identifiers for this MIB-2 and private MIB tree\r
+ * must be kept in sorted ascending order. This to ensure correct getnext operation.\r
+ */\r
+\r
+/*\r
+ * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without modification,\r
+ * are permitted provided that the following conditions are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright notice,\r
+ * this list of conditions and the following disclaimer in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ * derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT\r
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\r
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY\r
+ * OF SUCH DAMAGE.\r
+ *\r
+ * Author: Christiaan Simons <christiaan.simons@axon.tv>\r
+ */\r
+\r
+#include "arch/cc.h"\r
+#include "lwip/opt.h"\r
+\r
+#if LWIP_SNMP\r
+#include "lwip/snmp.h"\r
+#include "lwip/netif.h"\r
+#include "netif/etharp.h"\r
+#include "lwip/ip.h"\r
+#include "lwip/ip_frag.h"\r
+#include "lwip/tcp.h"\r
+#include "lwip/udp.h"\r
+#include "lwip/snmp_asn1.h"\r
+#include "lwip/snmp_structs.h"\r
+\r
+/**\r
+ * IANA assigned enterprise ID for lwIP is 26381\r
+ * @see http://www.iana.org/assignments/enterprise-numbers\r
+ *\r
+ * @note this enterprise ID is assigned to the lwIP project,\r
+ * all object identifiers living under this ID are assigned\r
+ * by the lwIP maintainers (contact Christiaan Simons)!\r
+ * @note don't change this define, use snmp_set_sysobjid()\r
+ *\r
+ * If you need to create your own private MIB you'll need\r
+ * to apply for your own enterprise ID with IANA:\r
+ * http://www.iana.org/numbers.html\r
+ */\r
+#define SNMP_ENTERPRISE_ID 26381\r
+#define SNMP_SYSOBJID_LEN 7\r
+#define SNMP_SYSOBJID {1, 3, 6, 1, 4, 1, SNMP_ENTERPRISE_ID}\r
+\r
+#ifndef SNMP_SYSSERVICES\r
+#define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2))\r
+#endif\r
+\r
+static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void system_get_value(struct obj_def *od, u16_t len, void *value);\r
+static u8_t system_set_test(struct obj_def *od, u16_t len, void *value);\r
+static void system_set_value(struct obj_def *od, u16_t len, void *value);\r
+static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void interfaces_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void ifentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void atentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void ip_get_value(struct obj_def *od, u16_t len, void *value);\r
+static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value);\r
+static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void icmp_get_value(struct obj_def *od, u16_t len, void *value);\r
+#if LWIP_TCP\r
+static void tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void tcp_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+#endif\r
+static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void udp_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void udpentry_get_value(struct obj_def *od, u16_t len, void *value);\r
+static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);\r
+static void snmp_get_value(struct obj_def *od, u16_t len, void *value);\r
+static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value);\r
+static void snmp_set_value(struct obj_def *od, u16_t len, void *value);\r
+\r
+\r
+/* snmp .1.3.6.1.2.1.11 */\r
+const mib_scalar_node snmp_scalar = {\r
+ &snmp_get_object_def,\r
+ &snmp_get_value,\r
+ &snmp_set_test,\r
+ &snmp_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+const s32_t snmp_ids[28] = {\r
+ 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,\r
+ 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30\r
+};\r
+struct mib_node* const snmp_nodes[28] = {\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar,\r
+ (struct mib_node* const)&snmp_scalar, (struct mib_node* const)&snmp_scalar\r
+};\r
+const struct mib_array_node snmp = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 28,\r
+ snmp_ids,\r
+ snmp_nodes\r
+};\r
+\r
+/* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */\r
+/* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */\r
+/* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */\r
+\r
+/* udp .1.3.6.1.2.1.7 */\r
+/** index root node for udpTable */\r
+struct mib_list_rootnode udp_root = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+const s32_t udpentry_ids[2] = { 1, 2 };\r
+struct mib_node* const udpentry_nodes[2] = {\r
+ (struct mib_node* const)&udp_root, (struct mib_node* const)&udp_root,\r
+};\r
+const struct mib_array_node udpentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 2,\r
+ udpentry_ids,\r
+ udpentry_nodes\r
+};\r
+\r
+s32_t udptable_id = 1;\r
+struct mib_node* udptable_node = (struct mib_node* const)&udpentry;\r
+struct mib_ram_array_node udptable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+ 0,\r
+ &udptable_id,\r
+ &udptable_node\r
+};\r
+\r
+const mib_scalar_node udp_scalar = {\r
+ &udp_get_object_def,\r
+ &udp_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 };\r
+struct mib_node* const udp_nodes[5] = {\r
+ (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar,\r
+ (struct mib_node* const)&udp_scalar, (struct mib_node* const)&udp_scalar,\r
+ (struct mib_node* const)&udptable\r
+};\r
+const struct mib_array_node udp = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 5,\r
+ udp_ids,\r
+ udp_nodes\r
+};\r
+\r
+/* tcp .1.3.6.1.2.1.6 */\r
+#if LWIP_TCP\r
+/* only if the TCP protocol is available may implement this group */\r
+/** index root node for tcpConnTable */\r
+struct mib_list_rootnode tcpconntree_root = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 };\r
+struct mib_node* const tcpconnentry_nodes[5] = {\r
+ (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root,\r
+ (struct mib_node* const)&tcpconntree_root, (struct mib_node* const)&tcpconntree_root,\r
+ (struct mib_node* const)&tcpconntree_root\r
+};\r
+const struct mib_array_node tcpconnentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 5,\r
+ tcpconnentry_ids,\r
+ tcpconnentry_nodes\r
+};\r
+\r
+s32_t tcpconntable_id = 1;\r
+struct mib_node* tcpconntable_node = (struct mib_node* const)&tcpconnentry;\r
+struct mib_ram_array_node tcpconntable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+/** @todo update maxlength when inserting / deleting from table\r
+ 0 when table is empty, 1 when more than one entry */\r
+ 0,\r
+ &tcpconntable_id,\r
+ &tcpconntable_node\r
+};\r
+\r
+const mib_scalar_node tcp_scalar = {\r
+ &tcp_get_object_def,\r
+ &tcp_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };\r
+struct mib_node* const tcp_nodes[15] = {\r
+ (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcp_scalar, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcpconntable, (struct mib_node* const)&tcp_scalar,\r
+ (struct mib_node* const)&tcp_scalar\r
+};\r
+const struct mib_array_node tcp = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 15,\r
+ tcp_ids,\r
+ tcp_nodes\r
+};\r
+#endif\r
+\r
+/* icmp .1.3.6.1.2.1.5 */\r
+const mib_scalar_node icmp_scalar = {\r
+ &icmp_get_object_def,\r
+ &icmp_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+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 };\r
+struct mib_node* const icmp_nodes[26] = {\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar,\r
+ (struct mib_node* const)&icmp_scalar, (struct mib_node* const)&icmp_scalar\r
+};\r
+const struct mib_array_node icmp = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 26,\r
+ icmp_ids,\r
+ icmp_nodes\r
+};\r
+\r
+/** index root node for ipNetToMediaTable */\r
+struct mib_list_rootnode ipntomtree_root = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 };\r
+struct mib_node* const ipntomentry_nodes[4] = {\r
+ (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root,\r
+ (struct mib_node* const)&ipntomtree_root, (struct mib_node* const)&ipntomtree_root\r
+};\r
+const struct mib_array_node ipntomentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 4,\r
+ ipntomentry_ids,\r
+ ipntomentry_nodes\r
+};\r
+\r
+s32_t ipntomtable_id = 1;\r
+struct mib_node* ipntomtable_node = (struct mib_node* const)&ipntomentry;\r
+struct mib_ram_array_node ipntomtable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+ 0,\r
+ &ipntomtable_id,\r
+ &ipntomtable_node\r
+};\r
+\r
+/** index root node for ipRouteTable */\r
+struct mib_list_rootnode iprtetree_root = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };\r
+struct mib_node* const iprteentry_nodes[13] = {\r
+ (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,\r
+ (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,\r
+ (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,\r
+ (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,\r
+ (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,\r
+ (struct mib_node* const)&iprtetree_root, (struct mib_node* const)&iprtetree_root,\r
+ (struct mib_node* const)&iprtetree_root\r
+};\r
+const struct mib_array_node iprteentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 13,\r
+ iprteentry_ids,\r
+ iprteentry_nodes\r
+};\r
+\r
+s32_t iprtetable_id = 1;\r
+struct mib_node* iprtetable_node = (struct mib_node* const)&iprteentry;\r
+struct mib_ram_array_node iprtetable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+ 0,\r
+ &iprtetable_id,\r
+ &iprtetable_node\r
+};\r
+\r
+/** index root node for ipAddrTable */\r
+struct mib_list_rootnode ipaddrtree_root = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 };\r
+struct mib_node* const ipaddrentry_nodes[5] = {\r
+ (struct mib_node* const)&ipaddrtree_root,\r
+ (struct mib_node* const)&ipaddrtree_root,\r
+ (struct mib_node* const)&ipaddrtree_root,\r
+ (struct mib_node* const)&ipaddrtree_root,\r
+ (struct mib_node* const)&ipaddrtree_root\r
+};\r
+const struct mib_array_node ipaddrentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 5,\r
+ ipaddrentry_ids,\r
+ ipaddrentry_nodes\r
+};\r
+\r
+s32_t ipaddrtable_id = 1;\r
+struct mib_node* ipaddrtable_node = (struct mib_node* const)&ipaddrentry;\r
+struct mib_ram_array_node ipaddrtable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+ 0,\r
+ &ipaddrtable_id,\r
+ &ipaddrtable_node\r
+};\r
+\r
+/* ip .1.3.6.1.2.1.4 */\r
+const mib_scalar_node ip_scalar = {\r
+ &ip_get_object_def,\r
+ &ip_get_value,\r
+ &ip_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+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 };\r
+struct mib_node* const ip_nodes[23] = {\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ip_scalar,\r
+ (struct mib_node* const)&ip_scalar, (struct mib_node* const)&ipaddrtable,\r
+ (struct mib_node* const)&iprtetable, (struct mib_node* const)&ipntomtable,\r
+ (struct mib_node* const)&ip_scalar\r
+};\r
+const struct mib_array_node ip = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 23,\r
+ ip_ids,\r
+ ip_nodes\r
+};\r
+\r
+/** index root node for atTable */\r
+struct mib_list_rootnode arptree_root = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+const s32_t atentry_ids[3] = { 1, 2, 3 };\r
+struct mib_node* const atentry_nodes[3] = {\r
+ (struct mib_node* const)&arptree_root,\r
+ (struct mib_node* const)&arptree_root,\r
+ (struct mib_node* const)&arptree_root\r
+};\r
+const struct mib_array_node atentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 3,\r
+ atentry_ids,\r
+ atentry_nodes\r
+};\r
+\r
+const s32_t attable_id = 1;\r
+struct mib_node* const attable_node = (struct mib_node* const)&atentry;\r
+const struct mib_array_node attable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 1,\r
+ &attable_id,\r
+ &attable_node\r
+};\r
+\r
+/* at .1.3.6.1.2.1.3 */\r
+s32_t at_id = 1;\r
+struct mib_node* at_node = (struct mib_node* const)&attable;\r
+struct mib_ram_array_node at = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+ 0,\r
+ &at_id,\r
+ &at_node\r
+};\r
+\r
+/** index root node for ifTable */\r
+struct mib_list_rootnode iflist_root = {\r
+ &ifentry_get_object_def,\r
+ &ifentry_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_LR,\r
+ 0,\r
+ NULL,\r
+ NULL,\r
+ 0\r
+};\r
+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 };\r
+struct mib_node* const ifentry_nodes[22] = {\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root,\r
+ (struct mib_node* const)&iflist_root, (struct mib_node* const)&iflist_root\r
+};\r
+const struct mib_array_node ifentry = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 22,\r
+ ifentry_ids,\r
+ ifentry_nodes\r
+};\r
+\r
+s32_t iftable_id = 1;\r
+struct mib_node* iftable_node = (struct mib_node* const)&ifentry;\r
+struct mib_ram_array_node iftable = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_RA,\r
+ 0,\r
+ &iftable_id,\r
+ &iftable_node\r
+};\r
+\r
+/* interfaces .1.3.6.1.2.1.2 */\r
+const mib_scalar_node interfaces_scalar = {\r
+ &interfaces_get_object_def,\r
+ &interfaces_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+const s32_t interfaces_ids[2] = { 1, 2 };\r
+struct mib_node* const interfaces_nodes[2] = {\r
+ (struct mib_node* const)&interfaces_scalar, (struct mib_node* const)&iftable\r
+};\r
+const struct mib_array_node interfaces = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 2,\r
+ interfaces_ids,\r
+ interfaces_nodes\r
+};\r
+\r
+\r
+/* 0 1 2 3 4 5 6 */\r
+/* system .1.3.6.1.2.1.1 */\r
+const mib_scalar_node sys_tem_scalar = {\r
+ &system_get_object_def,\r
+ &system_get_value,\r
+ &system_set_test,\r
+ &system_set_value,\r
+ MIB_NODE_SC,\r
+ 0\r
+};\r
+const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };\r
+struct mib_node* const sys_tem_nodes[7] = {\r
+ (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,\r
+ (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,\r
+ (struct mib_node* const)&sys_tem_scalar, (struct mib_node* const)&sys_tem_scalar,\r
+ (struct mib_node* const)&sys_tem_scalar\r
+};\r
+/* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */\r
+const struct mib_array_node sys_tem = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 7,\r
+ sys_tem_ids,\r
+ sys_tem_nodes\r
+};\r
+\r
+/* mib-2 .1.3.6.1.2.1 */\r
+#if LWIP_TCP\r
+#define MIB2_GROUPS 8\r
+#else\r
+#define MIB2_GROUPS 7\r
+#endif\r
+const s32_t mib2_ids[MIB2_GROUPS] =\r
+{\r
+ 1,\r
+ 2,\r
+ 3,\r
+ 4,\r
+ 5,\r
+#if LWIP_TCP\r
+ 6,\r
+#endif\r
+ 7,\r
+ 11\r
+};\r
+struct mib_node* const mib2_nodes[MIB2_GROUPS] = {\r
+ (struct mib_node* const)&sys_tem,\r
+ (struct mib_node* const)&interfaces,\r
+ (struct mib_node* const)&at,\r
+ (struct mib_node* const)&ip,\r
+ (struct mib_node* const)&icmp,\r
+#if LWIP_TCP\r
+ (struct mib_node* const)&tcp,\r
+#endif\r
+ (struct mib_node* const)&udp,\r
+ (struct mib_node* const)&snmp\r
+};\r
+\r
+const struct mib_array_node mib2 = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ MIB2_GROUPS,\r
+ mib2_ids,\r
+ mib2_nodes\r
+};\r
+\r
+/* mgmt .1.3.6.1.2 */\r
+const s32_t mgmt_ids[1] = { 1 };\r
+struct mib_node* const mgmt_nodes[1] = { (struct mib_node* const)&mib2 };\r
+const struct mib_array_node mgmt = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 1,\r
+ mgmt_ids,\r
+ mgmt_nodes\r
+};\r
+\r
+/* internet .1.3.6.1 */\r
+#if SNMP_PRIVATE_MIB\r
+s32_t internet_ids[2] = { 2, 4 };\r
+struct mib_node* const internet_nodes[2] = { (struct mib_node* const)&mgmt, (struct mib_node* const)&private };\r
+const struct mib_array_node internet = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 2,\r
+ internet_ids,\r
+ internet_nodes\r
+};\r
+#else\r
+const s32_t internet_ids[1] = { 2 };\r
+struct mib_node* const internet_nodes[1] = { (struct mib_node* const)&mgmt };\r
+const struct mib_array_node internet = {\r
+ &noleafs_get_object_def,\r
+ &noleafs_get_value,\r
+ &noleafs_set_test,\r
+ &noleafs_set_value,\r
+ MIB_NODE_AR,\r
+ 1,\r
+ internet_ids,\r
+ internet_nodes\r
+};\r
+#endif\r
+\r
+/** mib-2.system.sysObjectID */\r
+static struct snmp_obj_id sysobjid = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID};\r
+/** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */\r
+static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}};\r
+/** mib-2.system.sysServices */\r
+static const s32_t sysservices = SNMP_SYSSERVICES;\r
+\r
+/** mib-2.system.sysDescr */\r
+static const u8_t sysdescr_len_default = 4;\r
+static const u8_t sysdescr_default[] = "lwIP";\r
+static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default;\r
+static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0];\r
+/** mib-2.system.sysContact */\r
+static const u8_t syscontact_len_default = 0;\r
+static const u8_t syscontact_default[] = "";\r
+static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default;\r
+static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0];\r
+/** mib-2.system.sysName */\r
+static const u8_t sysname_len_default = 8;\r
+static const u8_t sysname_default[] = "FQDN-unk";\r
+static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default;\r
+static u8_t* sysname_ptr = (u8_t*)&sysname_default[0];\r
+/** mib-2.system.sysLocation */\r
+static const u8_t syslocation_len_default = 0;\r
+static const u8_t syslocation_default[] = "";\r
+static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default;\r
+static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0];\r
+/** mib-2.snmp.snmpEnableAuthenTraps */\r
+static const u8_t snmpenableauthentraps_default = 2; /* disabled */\r
+static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default;\r
+\r
+/** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */\r
+static const struct snmp_obj_id ifspecific = {2, {0, 0}};\r
+/** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */\r
+static const struct snmp_obj_id iprouteinfo = {2, {0, 0}};\r
+\r
+\r
+\r
+/* mib-2.system counter(s) */\r
+static u32_t sysuptime = 0;\r
+\r
+/* mib-2.ip counter(s) */\r
+static u32_t ipinreceives = 0,\r
+ ipinhdrerrors = 0,\r
+ ipinaddrerrors = 0,\r
+ ipforwdatagrams = 0,\r
+ ipinunknownprotos = 0,\r
+ ipindiscards = 0,\r
+ ipindelivers = 0,\r
+ ipoutrequests = 0,\r
+ ipoutdiscards = 0,\r
+ ipoutnoroutes = 0,\r
+ ipreasmreqds = 0,\r
+ ipreasmoks = 0,\r
+ ipreasmfails = 0,\r
+ ipfragoks = 0,\r
+ ipfragfails = 0,\r
+ ipfragcreates = 0,\r
+ iproutingdiscards = 0;\r
+/* mib-2.icmp counter(s) */\r
+static u32_t icmpinmsgs = 0,\r
+ icmpinerrors = 0,\r
+ icmpindestunreachs = 0,\r
+ icmpintimeexcds = 0,\r
+ icmpinparmprobs = 0,\r
+ icmpinsrcquenchs = 0,\r
+ icmpinredirects = 0,\r
+ icmpinechos = 0,\r
+ icmpinechoreps = 0,\r
+ icmpintimestamps = 0,\r
+ icmpintimestampreps = 0,\r
+ icmpinaddrmasks = 0,\r
+ icmpinaddrmaskreps = 0,\r
+ icmpoutmsgs = 0,\r
+ icmpouterrors = 0,\r
+ icmpoutdestunreachs = 0,\r
+ icmpouttimeexcds = 0,\r
+ icmpoutparmprobs = 0,\r
+ icmpoutsrcquenchs = 0,\r
+ icmpoutredirects = 0,\r
+ icmpoutechos = 0,\r
+ icmpoutechoreps = 0,\r
+ icmpouttimestamps = 0,\r
+ icmpouttimestampreps = 0,\r
+ icmpoutaddrmasks = 0,\r
+ icmpoutaddrmaskreps = 0;\r
+/* mib-2.tcp counter(s) */\r
+static u32_t tcpactiveopens = 0,\r
+ tcppassiveopens = 0,\r
+ tcpattemptfails = 0,\r
+ tcpestabresets = 0,\r
+ tcpinsegs = 0,\r
+ tcpoutsegs = 0,\r
+ tcpretranssegs = 0,\r
+ tcpinerrs = 0,\r
+ tcpoutrsts = 0;\r
+/* mib-2.udp counter(s) */\r
+static u32_t udpindatagrams = 0,\r
+ udpnoports = 0,\r
+ udpinerrors = 0,\r
+ udpoutdatagrams = 0;\r
+/* mib-2.snmp counter(s) */\r
+static u32_t snmpinpkts = 0,\r
+ snmpoutpkts = 0,\r
+ snmpinbadversions = 0,\r
+ snmpinbadcommunitynames = 0,\r
+ snmpinbadcommunityuses = 0,\r
+ snmpinasnparseerrs = 0,\r
+ snmpintoobigs = 0,\r
+ snmpinnosuchnames = 0,\r
+ snmpinbadvalues = 0,\r
+ snmpinreadonlys = 0,\r
+ snmpingenerrs = 0,\r
+ snmpintotalreqvars = 0,\r
+ snmpintotalsetvars = 0,\r
+ snmpingetrequests = 0,\r
+ snmpingetnexts = 0,\r
+ snmpinsetrequests = 0,\r
+ snmpingetresponses = 0,\r
+ snmpintraps = 0,\r
+ snmpouttoobigs = 0,\r
+ snmpoutnosuchnames = 0,\r
+ snmpoutbadvalues = 0,\r
+ snmpoutgenerrs = 0,\r
+ snmpoutgetrequests = 0,\r
+ snmpoutgetnexts = 0,\r
+ snmpoutsetrequests = 0,\r
+ snmpoutgetresponses = 0,\r
+ snmpouttraps = 0;\r
+\r
+\r
+\r
+/* prototypes of the following functions are in lwip/src/include/lwip/snmp.h */\r
+/**\r
+ * Copy octet string.\r
+ *\r
+ * @param dst points to destination\r
+ * @param src points to source\r
+ * @param n number of octets to copy.\r
+ */\r
+void ocstrncpy(u8_t *dst, u8_t *src, u8_t n)\r
+{\r
+ while (n > 0)\r
+ {\r
+ n--;\r
+ *dst++ = *src++;\r
+ }\r
+}\r
+\r
+/**\r
+ * Copy object identifier (s32_t) array.\r
+ *\r
+ * @param dst points to destination\r
+ * @param src points to source\r
+ * @param n number of sub identifiers to copy.\r
+ */\r
+void objectidncpy(s32_t *dst, s32_t *src, u8_t n)\r
+{\r
+ while(n > 0)\r
+ {\r
+ n--;\r
+ *dst++ = *src++;\r
+ }\r
+}\r
+\r
+/**\r
+ * Initializes sysDescr pointers.\r
+ *\r
+ * @param str if non-NULL then copy str pointer\r
+ * @param strlen points to string length, excluding zero terminator\r
+ */\r
+void snmp_set_sysdesr(u8_t *str, u8_t *strlen)\r
+{\r
+ if (str != NULL)\r
+ {\r
+ sysdescr_ptr = str;\r
+ sysdescr_len_ptr = strlen;\r
+ }\r
+}\r
+\r
+void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid)\r
+{\r
+ *oid = &sysobjid;\r
+}\r
+\r
+/**\r
+ * Initializes sysObjectID value.\r
+ *\r
+ * @param oid points to stuct snmp_obj_id to copy\r
+ */\r
+void snmp_set_sysobjid(struct snmp_obj_id *oid)\r
+{\r
+ sysobjid = *oid;\r
+}\r
+\r
+/**\r
+ * Must be called at regular 10 msec interval from a timer interrupt\r
+ * or signal handler depending on your runtime environment.\r
+ */\r
+void snmp_inc_sysuptime(void)\r
+{\r
+ sysuptime++;\r
+}\r
+\r
+void snmp_get_sysuptime(u32_t *value)\r
+{\r
+ *value = sysuptime;\r
+}\r
+\r
+/**\r
+ * Initializes sysContact pointers,\r
+ * e.g. ptrs to non-volatile memory external to lwIP.\r
+ *\r
+ * @param str if non-NULL then copy str pointer\r
+ * @param strlen points to string length, excluding zero terminator\r
+ */\r
+void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen)\r
+{\r
+ if (ocstr != NULL)\r
+ {\r
+ syscontact_ptr = ocstr;\r
+ syscontact_len_ptr = ocstrlen;\r
+ }\r
+}\r
+\r
+/**\r
+ * Initializes sysName pointers,\r
+ * e.g. ptrs to non-volatile memory external to lwIP.\r
+ *\r
+ * @param str if non-NULL then copy str pointer\r
+ * @param strlen points to string length, excluding zero terminator\r
+ */\r
+void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen)\r
+{\r
+ if (ocstr != NULL)\r
+ {\r
+ sysname_ptr = ocstr;\r
+ sysname_len_ptr = ocstrlen;\r
+ }\r
+}\r
+\r
+/**\r
+ * Initializes sysLocation pointers,\r
+ * e.g. ptrs to non-volatile memory external to lwIP.\r
+ *\r
+ * @param str if non-NULL then copy str pointer\r
+ * @param strlen points to string length, excluding zero terminator\r
+ */\r
+void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen)\r
+{\r
+ if (ocstr != NULL)\r
+ {\r
+ syslocation_ptr = ocstr;\r
+ syslocation_len_ptr = ocstrlen;\r
+ }\r
+}\r
+\r
+\r
+void snmp_add_ifinoctets(struct netif *ni, u32_t value)\r
+{\r
+ ni->ifinoctets += value;\r
+}\r
+\r
+void snmp_inc_ifinucastpkts(struct netif *ni)\r
+{\r
+ (ni->ifinucastpkts)++;\r
+}\r
+\r
+void snmp_inc_ifinnucastpkts(struct netif *ni)\r
+{\r
+ (ni->ifinnucastpkts)++;\r
+}\r
+\r
+void snmp_inc_ifindiscards(struct netif *ni)\r
+{\r
+ (ni->ifindiscards)++;\r
+}\r
+\r
+void snmp_add_ifoutoctets(struct netif *ni, u32_t value)\r
+{\r
+ ni->ifoutoctets += value;\r
+}\r
+\r
+void snmp_inc_ifoutucastpkts(struct netif *ni)\r
+{\r
+ (ni->ifoutucastpkts)++;\r
+}\r
+\r
+void snmp_inc_ifoutnucastpkts(struct netif *ni)\r
+{\r
+ (ni->ifoutnucastpkts)++;\r
+}\r
+\r
+void snmp_inc_ifoutdiscards(struct netif *ni)\r
+{\r
+ (ni->ifoutdiscards)++;\r
+}\r
+\r
+void snmp_inc_iflist(void)\r
+{\r
+ struct mib_list_node *if_node = NULL;\r
+\r
+ snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node);\r
+ /* enable getnext traversal on filled table */\r
+ iftable.maxlength = 1;\r
+}\r
+\r
+void snmp_dec_iflist(void)\r
+{\r
+ snmp_mib_node_delete(&iflist_root, iflist_root.tail);\r
+ /* disable getnext traversal on empty table */\r
+ if(iflist_root.count == 0) iftable.maxlength = 0;\r
+}\r
+\r
+/**\r
+ * Inserts ARP table indexes (.xIfIndex.xNetAddress)\r
+ * into arp table index trees (both atTable and ipNetToMediaTable).\r
+ */\r
+void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip)\r
+{\r
+ struct mib_list_rootnode *at_rn;\r
+ struct mib_list_node *at_node;\r
+ struct ip_addr hip;\r
+ s32_t arpidx[5];\r
+ u8_t level, tree;\r
+\r
+ LWIP_ASSERT("ni != NULL", ni != NULL);\r
+ snmp_netiftoifindex(ni, &arpidx[0]);\r
+ hip.addr = ntohl(ip->addr);\r
+ snmp_iptooid(&hip, &arpidx[1]);\r
+\r
+ for (tree = 0; tree < 2; tree++)\r
+ {\r
+ if (tree == 0)\r
+ {\r
+ at_rn = &arptree_root;\r
+ }\r
+ else\r
+ {\r
+ at_rn = &ipntomtree_root;\r
+ }\r
+ for (level = 0; level < 5; level++)\r
+ {\r
+ at_node = NULL;\r
+ snmp_mib_node_insert(at_rn, arpidx[level], &at_node);\r
+ if ((level != 4) && (at_node != NULL))\r
+ {\r
+ if (at_node->nptr == NULL)\r
+ {\r
+ at_rn = snmp_mib_lrn_alloc();\r
+ at_node->nptr = (struct mib_node*)at_rn;\r
+ if (at_rn != NULL)\r
+ {\r
+ if (level == 3)\r
+ {\r
+ if (tree == 0)\r
+ {\r
+ at_rn->get_object_def = atentry_get_object_def;\r
+ at_rn->get_value = atentry_get_value;\r
+ }\r
+ else\r
+ {\r
+ at_rn->get_object_def = ip_ntomentry_get_object_def;\r
+ at_rn->get_value = ip_ntomentry_get_value;\r
+ }\r
+ at_rn->set_test = noleafs_set_test;\r
+ at_rn->set_value = noleafs_set_value;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* at_rn == NULL, malloc failure */\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full"));\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ at_rn = (struct mib_list_rootnode*)at_node->nptr;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ /* enable getnext traversal on filled tables */\r
+ at.maxlength = 1;\r
+ ipntomtable.maxlength = 1;\r
+}\r
+\r
+/**\r
+ * Removes ARP table indexes (.xIfIndex.xNetAddress)\r
+ * from arp table index trees.\r
+ */\r
+void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip)\r
+{\r
+ struct mib_list_rootnode *at_rn, *next, *del_rn[5];\r
+ struct mib_list_node *at_n, *del_n[5];\r
+ struct ip_addr hip;\r
+ s32_t arpidx[5];\r
+ u8_t fc, tree, level, del_cnt;\r
+\r
+ snmp_netiftoifindex(ni, &arpidx[0]);\r
+ hip.addr = ntohl(ip->addr);\r
+ snmp_iptooid(&hip, &arpidx[1]);\r
+\r
+ for (tree = 0; tree < 2; tree++)\r
+ {\r
+ /* mark nodes for deletion */\r
+ if (tree == 0)\r
+ {\r
+ at_rn = &arptree_root;\r
+ }\r
+ else\r
+ {\r
+ at_rn = &ipntomtree_root;\r
+ }\r
+ level = 0;\r
+ del_cnt = 0;\r
+ while ((level < 5) && (at_rn != NULL))\r
+ {\r
+ fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n);\r
+ if (fc == 0)\r
+ {\r
+ /* arpidx[level] does not exist */\r
+ del_cnt = 0;\r
+ at_rn = NULL;\r
+ }\r
+ else if (fc == 1)\r
+ {\r
+ del_rn[del_cnt] = at_rn;\r
+ del_n[del_cnt] = at_n;\r
+ del_cnt++;\r
+ at_rn = (struct mib_list_rootnode*)(at_n->nptr);\r
+ }\r
+ else if (fc == 2)\r
+ {\r
+ /* reset delete (2 or more childs) */\r
+ del_cnt = 0;\r
+ at_rn = (struct mib_list_rootnode*)(at_n->nptr);\r
+ }\r
+ level++;\r
+ }\r
+ /* delete marked index nodes */\r
+ while (del_cnt > 0)\r
+ {\r
+ del_cnt--;\r
+\r
+ at_rn = del_rn[del_cnt];\r
+ at_n = del_n[del_cnt];\r
+\r
+ next = snmp_mib_node_delete(at_rn, at_n);\r
+ if (next != NULL)\r
+ {\r
+ LWIP_ASSERT("next_count == 0",next->count == 0);\r
+ snmp_mib_lrn_free(next);\r
+ }\r
+ }\r
+ }\r
+ /* disable getnext traversal on empty tables */\r
+ if(arptree_root.count == 0) at.maxlength = 0;\r
+ if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0;\r
+}\r
+\r
+void snmp_inc_ipinreceives(void)\r
+{\r
+ ipinreceives++;\r
+}\r
+\r
+void snmp_inc_ipinhdrerrors(void)\r
+{\r
+ ipinhdrerrors++;\r
+}\r
+\r
+void snmp_inc_ipinaddrerrors(void)\r
+{\r
+ ipinaddrerrors++;\r
+}\r
+\r
+void snmp_inc_ipforwdatagrams(void)\r
+{\r
+ ipforwdatagrams++;\r
+}\r
+\r
+void snmp_inc_ipinunknownprotos(void)\r
+{\r
+ ipinunknownprotos++;\r
+}\r
+\r
+void snmp_inc_ipindiscards(void)\r
+{\r
+ ipindiscards++;\r
+}\r
+\r
+void snmp_inc_ipindelivers(void)\r
+{\r
+ ipindelivers++;\r
+}\r
+\r
+void snmp_inc_ipoutrequests(void)\r
+{\r
+ ipoutrequests++;\r
+}\r
+\r
+void snmp_inc_ipoutdiscards(void)\r
+{\r
+ ipoutdiscards++;\r
+}\r
+\r
+void snmp_inc_ipoutnoroutes(void)\r
+{\r
+ ipoutnoroutes++;\r
+}\r
+\r
+void snmp_inc_ipreasmreqds(void)\r
+{\r
+ ipreasmreqds++;\r
+}\r
+\r
+void snmp_inc_ipreasmoks(void)\r
+{\r
+ ipreasmoks++;\r
+}\r
+\r
+void snmp_inc_ipreasmfails(void)\r
+{\r
+ ipreasmfails++;\r
+}\r
+\r
+void snmp_inc_ipfragoks(void)\r
+{\r
+ ipfragoks++;\r
+}\r
+\r
+void snmp_inc_ipfragfails(void)\r
+{\r
+ ipfragfails++;\r
+}\r
+\r
+void snmp_inc_ipfragcreates(void)\r
+{\r
+ ipfragcreates++;\r
+}\r
+\r
+void snmp_inc_iproutingdiscards(void)\r
+{\r
+ iproutingdiscards++;\r
+}\r
+\r
+/**\r
+ * Inserts ipAddrTable indexes (.ipAdEntAddr)\r
+ * into index tree.\r
+ */\r
+void snmp_insert_ipaddridx_tree(struct netif *ni)\r
+{\r
+ struct mib_list_rootnode *ipa_rn;\r
+ struct mib_list_node *ipa_node;\r
+ struct ip_addr ip;\r
+ s32_t ipaddridx[4];\r
+ u8_t level;\r
+\r
+ LWIP_ASSERT("ni != NULL", ni != NULL);\r
+ ip.addr = ntohl(ni->ip_addr.addr);\r
+ snmp_iptooid(&ip, &ipaddridx[0]);\r
+\r
+ level = 0;\r
+ ipa_rn = &ipaddrtree_root;\r
+ while (level < 4)\r
+ {\r
+ ipa_node = NULL;\r
+ snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node);\r
+ if ((level != 3) && (ipa_node != NULL))\r
+ {\r
+ if (ipa_node->nptr == NULL)\r
+ {\r
+ ipa_rn = snmp_mib_lrn_alloc();\r
+ ipa_node->nptr = (struct mib_node*)ipa_rn;\r
+ if (ipa_rn != NULL)\r
+ {\r
+ if (level == 2)\r
+ {\r
+ ipa_rn->get_object_def = ip_addrentry_get_object_def;\r
+ ipa_rn->get_value = ip_addrentry_get_value;\r
+ ipa_rn->set_test = noleafs_set_test;\r
+ ipa_rn->set_value = noleafs_set_value;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* ipa_rn == NULL, malloc failure */\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full"));\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr;\r
+ }\r
+ }\r
+ level++;\r
+ }\r
+ /* enable getnext traversal on filled table */\r
+ ipaddrtable.maxlength = 1;\r
+}\r
+\r
+/**\r
+ * Removes ipAddrTable indexes (.ipAdEntAddr)\r
+ * from index tree.\r
+ */\r
+void snmp_delete_ipaddridx_tree(struct netif *ni)\r
+{\r
+ struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];\r
+ struct mib_list_node *ipa_n, *del_n[4];\r
+ struct ip_addr ip;\r
+ s32_t ipaddridx[4];\r
+ u8_t fc, level, del_cnt;\r
+\r
+ LWIP_ASSERT("ni != NULL", ni != NULL);\r
+ ip.addr = ntohl(ni->ip_addr.addr);\r
+ snmp_iptooid(&ip, &ipaddridx[0]);\r
+\r
+ /* mark nodes for deletion */\r
+ level = 0;\r
+ del_cnt = 0;\r
+ ipa_rn = &ipaddrtree_root;\r
+ while ((level < 4) && (ipa_rn != NULL))\r
+ {\r
+ fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n);\r
+ if (fc == 0)\r
+ {\r
+ /* ipaddridx[level] does not exist */\r
+ del_cnt = 0;\r
+ ipa_rn = NULL;\r
+ }\r
+ else if (fc == 1)\r
+ {\r
+ del_rn[del_cnt] = ipa_rn;\r
+ del_n[del_cnt] = ipa_n;\r
+ del_cnt++;\r
+ ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);\r
+ }\r
+ else if (fc == 2)\r
+ {\r
+ /* reset delete (2 or more childs) */\r
+ del_cnt = 0;\r
+ ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);\r
+ }\r
+ level++;\r
+ }\r
+ /* delete marked index nodes */\r
+ while (del_cnt > 0)\r
+ {\r
+ del_cnt--;\r
+\r
+ ipa_rn = del_rn[del_cnt];\r
+ ipa_n = del_n[del_cnt];\r
+\r
+ next = snmp_mib_node_delete(ipa_rn, ipa_n);\r
+ if (next != NULL)\r
+ {\r
+ LWIP_ASSERT("next_count == 0",next->count == 0);\r
+ snmp_mib_lrn_free(next);\r
+ }\r
+ }\r
+ /* disable getnext traversal on empty table */\r
+ if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0;\r
+}\r
+\r
+/**\r
+ * Inserts ipRouteTable indexes (.ipRouteDest)\r
+ * into index tree.\r
+ *\r
+ * @param dflt non-zero for the default rte, zero for network rte\r
+ * @param netif points to network interface for this rte\r
+ *\r
+ * @todo record sysuptime for _this_ route when it is installed\r
+ * (needed for ipRouteAge) in the netif.\r
+ */\r
+void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)\r
+{\r
+ u8_t insert = 0;\r
+ struct ip_addr dst;\r
+\r
+ if (dflt != 0)\r
+ {\r
+ /* the default route 0.0.0.0 */\r
+ dst.addr = 0;\r
+ insert = 1;\r
+ }\r
+ else\r
+ {\r
+ /* route to the network address */\r
+ dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);\r
+ /* exclude 0.0.0.0 network (reserved for default rte) */\r
+ if (dst.addr != 0) insert = 1;\r
+ }\r
+ if (insert)\r
+ {\r
+ struct mib_list_rootnode *iprte_rn;\r
+ struct mib_list_node *iprte_node;\r
+ s32_t iprteidx[4];\r
+ u8_t level;\r
+\r
+ snmp_iptooid(&dst, &iprteidx[0]);\r
+ level = 0;\r
+ iprte_rn = &iprtetree_root;\r
+ while (level < 4)\r
+ {\r
+ iprte_node = NULL;\r
+ snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node);\r
+ if ((level != 3) && (iprte_node != NULL))\r
+ {\r
+ if (iprte_node->nptr == NULL)\r
+ {\r
+ iprte_rn = snmp_mib_lrn_alloc();\r
+ iprte_node->nptr = (struct mib_node*)iprte_rn;\r
+ if (iprte_rn != NULL)\r
+ {\r
+ if (level == 2)\r
+ {\r
+ iprte_rn->get_object_def = ip_rteentry_get_object_def;\r
+ iprte_rn->get_value = ip_rteentry_get_value;\r
+ iprte_rn->set_test = noleafs_set_test;\r
+ iprte_rn->set_value = noleafs_set_value;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* iprte_rn == NULL, malloc failure */\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full"));\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr;\r
+ }\r
+ }\r
+ level++;\r
+ }\r
+ }\r
+ /* enable getnext traversal on filled table */\r
+ iprtetable.maxlength = 1;\r
+}\r
+\r
+/**\r
+ * Removes ipRouteTable indexes (.ipRouteDest)\r
+ * from index tree.\r
+ *\r
+ * @param dflt non-zero for the default rte, zero for network rte\r
+ * @param netif points to network interface for this rte or NULL\r
+ * for default route to be removed.\r
+ */\r
+void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)\r
+{\r
+ u8_t delete = 0;\r
+ struct ip_addr dst;\r
+\r
+ if (dflt != 0)\r
+ {\r
+ /* the default route 0.0.0.0 */\r
+ dst.addr = 0;\r
+ delete = 1;\r
+ }\r
+ else\r
+ {\r
+ /* route to the network address */\r
+ dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);\r
+ /* exclude 0.0.0.0 network (reserved for default rte) */\r
+ if (dst.addr != 0) delete = 1;\r
+ }\r
+ if (delete)\r
+ {\r
+ struct mib_list_rootnode *iprte_rn, *next, *del_rn[4];\r
+ struct mib_list_node *iprte_n, *del_n[4];\r
+ s32_t iprteidx[4];\r
+ u8_t fc, level, del_cnt;\r
+\r
+ snmp_iptooid(&dst, &iprteidx[0]);\r
+ /* mark nodes for deletion */\r
+ level = 0;\r
+ del_cnt = 0;\r
+ iprte_rn = &iprtetree_root;\r
+ while ((level < 4) && (iprte_rn != NULL))\r
+ {\r
+ fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n);\r
+ if (fc == 0)\r
+ {\r
+ /* iprteidx[level] does not exist */\r
+ del_cnt = 0;\r
+ iprte_rn = NULL;\r
+ }\r
+ else if (fc == 1)\r
+ {\r
+ del_rn[del_cnt] = iprte_rn;\r
+ del_n[del_cnt] = iprte_n;\r
+ del_cnt++;\r
+ iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);\r
+ }\r
+ else if (fc == 2)\r
+ {\r
+ /* reset delete (2 or more childs) */\r
+ del_cnt = 0;\r
+ iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);\r
+ }\r
+ level++;\r
+ }\r
+ /* delete marked index nodes */\r
+ while (del_cnt > 0)\r
+ {\r
+ del_cnt--;\r
+\r
+ iprte_rn = del_rn[del_cnt];\r
+ iprte_n = del_n[del_cnt];\r
+\r
+ next = snmp_mib_node_delete(iprte_rn, iprte_n);\r
+ if (next != NULL)\r
+ {\r
+ LWIP_ASSERT("next_count == 0",next->count == 0);\r
+ snmp_mib_lrn_free(next);\r
+ }\r
+ }\r
+ }\r
+ /* disable getnext traversal on empty table */\r
+ if (iprtetree_root.count == 0) iprtetable.maxlength = 0;\r
+}\r
+\r
+\r
+void snmp_inc_icmpinmsgs(void)\r
+{\r
+ icmpinmsgs++;\r
+}\r
+\r
+void snmp_inc_icmpinerrors(void)\r
+{\r
+ icmpinerrors++;\r
+}\r
+\r
+void snmp_inc_icmpindestunreachs(void)\r
+{\r
+ icmpindestunreachs++;\r
+}\r
+\r
+void snmp_inc_icmpintimeexcds(void)\r
+{\r
+ icmpintimeexcds++;\r
+}\r
+\r
+void snmp_inc_icmpinparmprobs(void)\r
+{\r
+ icmpinparmprobs++;\r
+}\r
+\r
+void snmp_inc_icmpinsrcquenchs(void)\r
+{\r
+ icmpinsrcquenchs++;\r
+}\r
+\r
+void snmp_inc_icmpinredirects(void)\r
+{\r
+ icmpinredirects++;\r
+}\r
+\r
+void snmp_inc_icmpinechos(void)\r
+{\r
+ icmpinechos++;\r
+}\r
+\r
+void snmp_inc_icmpinechoreps(void)\r
+{\r
+ icmpinechoreps++;\r
+}\r
+\r
+void snmp_inc_icmpintimestamps(void)\r
+{\r
+ icmpintimestamps++;\r
+}\r
+\r
+void snmp_inc_icmpintimestampreps(void)\r
+{\r
+ icmpintimestampreps++;\r
+}\r
+\r
+void snmp_inc_icmpinaddrmasks(void)\r
+{\r
+ icmpinaddrmasks++;\r
+}\r
+\r
+void snmp_inc_icmpinaddrmaskreps(void)\r
+{\r
+ icmpinaddrmaskreps++;\r
+}\r
+\r
+void snmp_inc_icmpoutmsgs(void)\r
+{\r
+ icmpoutmsgs++;\r
+}\r
+\r
+void snmp_inc_icmpouterrors(void)\r
+{\r
+ icmpouterrors++;\r
+}\r
+\r
+void snmp_inc_icmpoutdestunreachs(void)\r
+{\r
+ icmpoutdestunreachs++;\r
+}\r
+\r
+void snmp_inc_icmpouttimeexcds(void)\r
+{\r
+ icmpouttimeexcds++;\r
+}\r
+\r
+void snmp_inc_icmpoutparmprobs(void)\r
+{\r
+ icmpoutparmprobs++;\r
+}\r
+\r
+void snmp_inc_icmpoutsrcquenchs(void)\r
+{\r
+ icmpoutsrcquenchs++;\r
+}\r
+\r
+void snmp_inc_icmpoutredirects(void)\r
+{\r
+ icmpoutredirects++;\r
+}\r
+\r
+void snmp_inc_icmpoutechos(void)\r
+{\r
+ icmpoutechos++;\r
+}\r
+\r
+void snmp_inc_icmpoutechoreps(void)\r
+{\r
+ icmpoutechoreps++;\r
+}\r
+\r
+void snmp_inc_icmpouttimestamps(void)\r
+{\r
+ icmpouttimestamps++;\r
+}\r
+\r
+void snmp_inc_icmpouttimestampreps(void)\r
+{\r
+ icmpouttimestampreps++;\r
+}\r
+\r
+void snmp_inc_icmpoutaddrmasks(void)\r
+{\r
+ icmpoutaddrmasks++;\r
+}\r
+\r
+void snmp_inc_icmpoutaddrmaskreps(void)\r
+{\r
+ icmpoutaddrmaskreps++;\r
+}\r
+\r
+void snmp_inc_tcpactiveopens(void)\r
+{\r
+ tcpactiveopens++;\r
+}\r
+\r
+void snmp_inc_tcppassiveopens(void)\r
+{\r
+ tcppassiveopens++;\r
+}\r
+\r
+void snmp_inc_tcpattemptfails(void)\r
+{\r
+ tcpattemptfails++;\r
+}\r
+\r
+void snmp_inc_tcpestabresets(void)\r
+{\r
+ tcpestabresets++;\r
+}\r
+\r
+void snmp_inc_tcpinsegs(void)\r
+{\r
+ tcpinsegs++;\r
+}\r
+\r
+void snmp_inc_tcpoutsegs(void)\r
+{\r
+ tcpoutsegs++;\r
+}\r
+\r
+void snmp_inc_tcpretranssegs(void)\r
+{\r
+ tcpretranssegs++;\r
+}\r
+\r
+void snmp_inc_tcpinerrs(void)\r
+{\r
+ tcpinerrs++;\r
+}\r
+\r
+void snmp_inc_tcpoutrsts(void)\r
+{\r
+ tcpoutrsts++;\r
+}\r
+\r
+void snmp_inc_udpindatagrams(void)\r
+{\r
+ udpindatagrams++;\r
+}\r
+\r
+void snmp_inc_udpnoports(void)\r
+{\r
+ udpnoports++;\r
+}\r
+\r
+void snmp_inc_udpinerrors(void)\r
+{\r
+ udpinerrors++;\r
+}\r
+\r
+void snmp_inc_udpoutdatagrams(void)\r
+{\r
+ udpoutdatagrams++;\r
+}\r
+\r
+/**\r
+ * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort)\r
+ * into index tree.\r
+ */\r
+void snmp_insert_udpidx_tree(struct udp_pcb *pcb)\r
+{\r
+ struct mib_list_rootnode *udp_rn;\r
+ struct mib_list_node *udp_node;\r
+ struct ip_addr ip;\r
+ s32_t udpidx[5];\r
+ u8_t level;\r
+\r
+ LWIP_ASSERT("pcb != NULL", pcb != NULL);\r
+ ip.addr = ntohl(pcb->local_ip.addr);\r
+ snmp_iptooid(&ip, &udpidx[0]);\r
+ udpidx[4] = pcb->local_port;\r
+\r
+ udp_rn = &udp_root;\r
+ for (level = 0; level < 5; level++)\r
+ {\r
+ udp_node = NULL;\r
+ snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node);\r
+ if ((level != 4) && (udp_node != NULL))\r
+ {\r
+ if (udp_node->nptr == NULL)\r
+ {\r
+ udp_rn = snmp_mib_lrn_alloc();\r
+ udp_node->nptr = (struct mib_node*)udp_rn;\r
+ if (udp_rn != NULL)\r
+ {\r
+ if (level == 3)\r
+ {\r
+ udp_rn->get_object_def = udpentry_get_object_def;\r
+ udp_rn->get_value = udpentry_get_value;\r
+ udp_rn->set_test = noleafs_set_test;\r
+ udp_rn->set_value = noleafs_set_value;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* udp_rn == NULL, malloc failure */\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full"));\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ udp_rn = (struct mib_list_rootnode*)udp_node->nptr;\r
+ }\r
+ }\r
+ }\r
+ udptable.maxlength = 1;\r
+}\r
+\r
+/**\r
+ * Removes udpTable indexes (.udpLocalAddress.udpLocalPort)\r
+ * from index tree.\r
+ */\r
+void snmp_delete_udpidx_tree(struct udp_pcb *pcb)\r
+{\r
+ struct mib_list_rootnode *udp_rn, *next, *del_rn[5];\r
+ struct mib_list_node *udp_n, *del_n[5];\r
+ struct ip_addr ip;\r
+ s32_t udpidx[5];\r
+ u8_t bindings, fc, level, del_cnt;\r
+\r
+ LWIP_ASSERT("pcb != NULL", pcb != NULL);\r
+ ip.addr = ntohl(pcb->local_ip.addr);\r
+ snmp_iptooid(&ip, &udpidx[0]);\r
+ udpidx[4] = pcb->local_port;\r
+\r
+ /* count PCBs for a given binding\r
+ (e.g. when reusing ports or for temp output PCBs) */\r
+ bindings = 0;\r
+ pcb = udp_pcbs;\r
+ while ((pcb != NULL))\r
+ {\r
+ if ((pcb->local_ip.addr == ip.addr) &&\r
+ (pcb->local_port == udpidx[4]))\r
+ {\r
+ bindings++;\r
+ }\r
+ pcb = pcb->next;\r
+ }\r
+ if (bindings == 1)\r
+ {\r
+ /* selectively remove */\r
+ /* mark nodes for deletion */\r
+ level = 0;\r
+ del_cnt = 0;\r
+ udp_rn = &udp_root;\r
+ while ((level < 5) && (udp_rn != NULL))\r
+ {\r
+ fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n);\r
+ if (fc == 0)\r
+ {\r
+ /* udpidx[level] does not exist */\r
+ del_cnt = 0;\r
+ udp_rn = NULL;\r
+ }\r
+ else if (fc == 1)\r
+ {\r
+ del_rn[del_cnt] = udp_rn;\r
+ del_n[del_cnt] = udp_n;\r
+ del_cnt++;\r
+ udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);\r
+ }\r
+ else if (fc == 2)\r
+ {\r
+ /* reset delete (2 or more childs) */\r
+ del_cnt = 0;\r
+ udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);\r
+ }\r
+ level++;\r
+ }\r
+ /* delete marked index nodes */\r
+ while (del_cnt > 0)\r
+ {\r
+ del_cnt--;\r
+\r
+ udp_rn = del_rn[del_cnt];\r
+ udp_n = del_n[del_cnt];\r
+\r
+ next = snmp_mib_node_delete(udp_rn, udp_n);\r
+ if (next != NULL)\r
+ {\r
+ LWIP_ASSERT("next_count == 0",next->count == 0);\r
+ snmp_mib_lrn_free(next);\r
+ }\r
+ }\r
+ }\r
+ /* disable getnext traversal on empty table */\r
+ if (udp_root.count == 0) udptable.maxlength = 0;\r
+}\r
+\r
+\r
+void snmp_inc_snmpinpkts(void)\r
+{\r
+ snmpinpkts++;\r
+}\r
+\r
+void snmp_inc_snmpoutpkts(void)\r
+{\r
+ snmpoutpkts++;\r
+}\r
+\r
+void snmp_inc_snmpinbadversions(void)\r
+{\r
+ snmpinbadversions++;\r
+}\r
+\r
+void snmp_inc_snmpinbadcommunitynames(void)\r
+{\r
+ snmpinbadcommunitynames++;\r
+}\r
+\r
+void snmp_inc_snmpinbadcommunityuses(void)\r
+{\r
+ snmpinbadcommunityuses++;\r
+}\r
+\r
+void snmp_inc_snmpinasnparseerrs(void)\r
+{\r
+ snmpinasnparseerrs++;\r
+}\r
+\r
+void snmp_inc_snmpintoobigs(void)\r
+{\r
+ snmpintoobigs++;\r
+}\r
+\r
+void snmp_inc_snmpinnosuchnames(void)\r
+{\r
+ snmpinnosuchnames++;\r
+}\r
+\r
+void snmp_inc_snmpinbadvalues(void)\r
+{\r
+ snmpinbadvalues++;\r
+}\r
+\r
+void snmp_inc_snmpinreadonlys(void)\r
+{\r
+ snmpinreadonlys++;\r
+}\r
+\r
+void snmp_inc_snmpingenerrs(void)\r
+{\r
+ snmpingenerrs++;\r
+}\r
+\r
+void snmp_add_snmpintotalreqvars(u8_t value)\r
+{\r
+ snmpintotalreqvars += value;\r
+}\r
+\r
+void snmp_add_snmpintotalsetvars(u8_t value)\r
+{\r
+ snmpintotalsetvars += value;\r
+}\r
+\r
+void snmp_inc_snmpingetrequests(void)\r
+{\r
+ snmpingetrequests++;\r
+}\r
+\r
+void snmp_inc_snmpingetnexts(void)\r
+{\r
+ snmpingetnexts++;\r
+}\r
+\r
+void snmp_inc_snmpinsetrequests(void)\r
+{\r
+ snmpinsetrequests++;\r
+}\r
+\r
+void snmp_inc_snmpingetresponses(void)\r
+{\r
+ snmpingetresponses++;\r
+}\r
+\r
+void snmp_inc_snmpintraps(void)\r
+{\r
+ snmpintraps++;\r
+}\r
+\r
+void snmp_inc_snmpouttoobigs(void)\r
+{\r
+ snmpouttoobigs++;\r
+}\r
+\r
+void snmp_inc_snmpoutnosuchnames(void)\r
+{\r
+ snmpoutnosuchnames++;\r
+}\r
+\r
+void snmp_inc_snmpoutbadvalues(void)\r
+{\r
+ snmpoutbadvalues++;\r
+}\r
+\r
+void snmp_inc_snmpoutgenerrs(void)\r
+{\r
+ snmpoutgenerrs++;\r
+}\r
+\r
+void snmp_inc_snmpoutgetrequests(void)\r
+{\r
+ snmpoutgetrequests++;\r
+}\r
+\r
+void snmp_inc_snmpoutgetnexts(void)\r
+{\r
+ snmpoutgetnexts++;\r
+}\r
+\r
+void snmp_inc_snmpoutsetrequests(void)\r
+{\r
+ snmpoutsetrequests++;\r
+}\r
+\r
+void snmp_inc_snmpoutgetresponses(void)\r
+{\r
+ snmpoutgetresponses++;\r
+}\r
+\r
+void snmp_inc_snmpouttraps(void)\r
+{\r
+ snmpouttraps++;\r
+}\r
+\r
+void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)\r
+{\r
+ *oid = &snmpgrp_id;\r
+}\r
+\r
+void snmp_set_snmpenableauthentraps(u8_t *value)\r
+{\r
+ if (value != NULL)\r
+ {\r
+ snmpenableauthentraps_ptr = value;\r
+ }\r
+}\r
+\r
+void snmp_get_snmpenableauthentraps(u8_t *value)\r
+{\r
+ *value = *snmpenableauthentraps_ptr;\r
+}\r
+\r
+void\r
+noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ if (ident_len){}\r
+ if (ident){}\r
+ od->instance = MIB_OBJECT_NONE;\r
+}\r
+\r
+void\r
+noleafs_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ if (od){}\r
+ if (len){}\r
+ if (value){}\r
+}\r
+\r
+u8_t\r
+noleafs_set_test(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ if (od){}\r
+ if (len){}\r
+ if (value){}\r
+ /* can't set */\r
+ return 0;\r
+}\r
+\r
+void\r
+noleafs_set_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ if (od){}\r
+ if (len){}\r
+ if (value){}\r
+}\r
+\r
+\r
+/**\r
+ * Returns systems object definitions.\r
+ *\r
+ * @param ident_len the address length (2)\r
+ * @param ident points to objectname.0 (object id trailer)\r
+ * @param od points to object definition.\r
+ */\r
+static void\r
+system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ u8_t id;\r
+\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if (ident_len == 2)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id));\r
+ switch (id)\r
+ {\r
+ case 1: /* sysDescr */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = *sysdescr_len_ptr;\r
+ break;\r
+ case 2: /* sysObjectID */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);\r
+ od->v_len = sysobjid.len * sizeof(s32_t);\r
+ break;\r
+ case 3: /* sysUpTime */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 4: /* sysContact */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = *syscontact_len_ptr;\r
+ break;\r
+ case 5: /* sysName */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = *sysname_len_ptr;\r
+ break;\r
+ case 6: /* sysLocation */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = *syslocation_len_ptr;\r
+ break;\r
+ case 7: /* sysServices */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ };\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+/**\r
+ * Returns system object value.\r
+ *\r
+ * @param ident_len the address length (2)\r
+ * @param ident points to objectname.0 (object id trailer)\r
+ * @param len return value space (in bytes)\r
+ * @param value points to (varbind) space to copy value into.\r
+ */\r
+static void\r
+system_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* sysDescr */\r
+ ocstrncpy(value,sysdescr_ptr,len);\r
+ break;\r
+ case 2: /* sysObjectID */\r
+ objectidncpy((s32_t*)value,(s32_t*)sysobjid.id,len / sizeof(s32_t));\r
+ break;\r
+ case 3: /* sysUpTime */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = sysuptime;\r
+ }\r
+ break;\r
+ case 4: /* sysContact */\r
+ ocstrncpy(value,syscontact_ptr,len);\r
+ break;\r
+ case 5: /* sysName */\r
+ ocstrncpy(value,sysname_ptr,len);\r
+ break;\r
+ case 6: /* sysLocation */\r
+ ocstrncpy(value,syslocation_ptr,len);\r
+ break;\r
+ case 7: /* sysServices */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = sysservices;\r
+ }\r
+ break;\r
+ };\r
+}\r
+\r
+static u8_t\r
+system_set_test(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id, set_ok;\r
+\r
+ if (value) {}\r
+ set_ok = 0;\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 4: /* sysContact */\r
+ if ((syscontact_ptr != syscontact_default) &&\r
+ (len <= 255))\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ break;\r
+ case 5: /* sysName */\r
+ if ((sysname_ptr != sysname_default) &&\r
+ (len <= 255))\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ break;\r
+ case 6: /* sysLocation */\r
+ if ((syslocation_ptr != syslocation_default) &&\r
+ (len <= 255))\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ break;\r
+ };\r
+ return set_ok;\r
+}\r
+\r
+static void\r
+system_set_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 4: /* sysContact */\r
+ ocstrncpy(syscontact_ptr,value,len);\r
+ *syscontact_len_ptr = len;\r
+ break;\r
+ case 5: /* sysName */\r
+ ocstrncpy(sysname_ptr,value,len);\r
+ *sysname_len_ptr = len;\r
+ break;\r
+ case 6: /* sysLocation */\r
+ ocstrncpy(syslocation_ptr,value,len);\r
+ *syslocation_len_ptr = len;\r
+ break;\r
+ };\r
+}\r
+\r
+/**\r
+ * Returns interfaces.ifnumber object definition.\r
+ *\r
+ * @param ident_len the address length (2)\r
+ * @param ident points to objectname.index\r
+ * @param od points to object definition.\r
+ */\r
+static void\r
+interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if (ident_len == 2)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+/**\r
+ * Returns interfaces.ifnumber object value.\r
+ *\r
+ * @param ident_len the address length (2)\r
+ * @param ident points to objectname.0 (object id trailer)\r
+ * @param len return value space (in bytes)\r
+ * @param value points to (varbind) space to copy value into.\r
+ */\r
+static void\r
+interfaces_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ if (len){}\r
+ if (od->id_inst_ptr[0] == 1)\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = iflist_root.count;\r
+ }\r
+}\r
+\r
+/**\r
+ * Returns ifentry object definitions.\r
+ *\r
+ * @param ident_len the address length (2)\r
+ * @param ident points to objectname.index\r
+ * @param od points to object definition.\r
+ */\r
+static void\r
+ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ u8_t id;\r
+\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if (ident_len == 2)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id));\r
+ switch (id)\r
+ {\r
+ case 1: /* ifIndex */\r
+ case 3: /* ifType */\r
+ case 4: /* ifMtu */\r
+ case 8: /* ifOperStatus */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 2: /* ifDescr */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ /** @todo this should be some sort of sizeof(struct netif.name) */\r
+ od->v_len = 2;\r
+ break;\r
+ case 5: /* ifSpeed */\r
+ case 21: /* ifOutQLen */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 6: /* ifPhysAddress */\r
+ {\r
+ struct netif *netif;\r
+\r
+ snmp_ifindextonetif(ident[1], &netif);\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = netif->hwaddr_len;\r
+ }\r
+ break;\r
+ case 7: /* ifAdminStatus */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 9: /* ifLastChange */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 10: /* ifInOctets */\r
+ case 11: /* ifInUcastPkts */\r
+ case 12: /* ifInNUcastPkts */\r
+ case 13: /* ifInDiscarts */\r
+ case 14: /* ifInErrors */\r
+ case 15: /* ifInUnkownProtos */\r
+ case 16: /* ifOutOctets */\r
+ case 17: /* ifOutUcastPkts */\r
+ case 18: /* ifOutNUcastPkts */\r
+ case 19: /* ifOutDiscarts */\r
+ case 20: /* ifOutErrors */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 22: /* ifSpecific */\r
+ /** @note returning zeroDotZero (0.0) no media specific MIB support */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);\r
+ od->v_len = ifspecific.len * sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ };\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+/**\r
+ * Returns ifentry object value.\r
+ *\r
+ * @param ident_len the address length (2)\r
+ * @param ident points to objectname.0 (object id trailer)\r
+ * @param len return value space (in bytes)\r
+ * @param value points to (varbind) space to copy value into.\r
+ */\r
+static void\r
+ifentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ struct netif *netif;\r
+ u8_t id;\r
+\r
+ snmp_ifindextonetif(od->id_inst_ptr[1], &netif);\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ifIndex */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = od->id_inst_ptr[1];\r
+ }\r
+ break;\r
+ case 2: /* ifDescr */\r
+ ocstrncpy(value,(u8_t*)netif->name,len);\r
+ break;\r
+ case 3: /* ifType */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = netif->link_type;\r
+ }\r
+ break;\r
+ case 4: /* ifMtu */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = netif->mtu;\r
+ }\r
+ break;\r
+ case 5: /* ifSpeed */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->link_speed;\r
+ }\r
+ break;\r
+ case 6: /* ifPhysAddress */\r
+ ocstrncpy(value,netif->hwaddr,len);\r
+ break;\r
+ case 7: /* ifAdminStatus */\r
+ case 8: /* ifOperStatus */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ if (netif_is_up(netif))\r
+ {\r
+ *sint_ptr = 1;\r
+ }\r
+ else\r
+ {\r
+ *sint_ptr = 2;\r
+ }\r
+ }\r
+ break;\r
+ case 9: /* ifLastChange */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ts;\r
+ }\r
+ break;\r
+ case 10: /* ifInOctets */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifinoctets;\r
+ }\r
+ break;\r
+ case 11: /* ifInUcastPkts */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifinucastpkts;\r
+ }\r
+ break;\r
+ case 12: /* ifInNUcastPkts */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifinnucastpkts;\r
+ }\r
+ break;\r
+ case 13: /* ifInDiscarts */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifindiscards;\r
+ }\r
+ break;\r
+ case 14: /* ifInErrors */\r
+ case 15: /* ifInUnkownProtos */\r
+ /** @todo add these counters! */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = 0;\r
+ }\r
+ break;\r
+ case 16: /* ifOutOctets */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifoutoctets;\r
+ }\r
+ break;\r
+ case 17: /* ifOutUcastPkts */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifoutucastpkts;\r
+ }\r
+ break;\r
+ case 18: /* ifOutNUcastPkts */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifoutnucastpkts;\r
+ }\r
+ break;\r
+ case 19: /* ifOutDiscarts */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = netif->ifoutdiscards;\r
+ }\r
+ break;\r
+ case 20: /* ifOutErrors */\r
+ /** @todo add this counter! */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = 0;\r
+ }\r
+ break;\r
+ case 21: /* ifOutQLen */\r
+ /** @todo figure out if this must be 0 (no queue) or 1? */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = 0;\r
+ }\r
+ break;\r
+ case 22: /* ifSpecific */\r
+ objectidncpy((s32_t*)value,(s32_t*)ifspecific.id,len / sizeof(s32_t));\r
+ break;\r
+ };\r
+}\r
+\r
+/**\r
+ * Returns atentry object definitions.\r
+ *\r
+ * @param ident_len the address length (6)\r
+ * @param ident points to objectname.atifindex.atnetaddress\r
+ * @param od points to object definition.\r
+ */\r
+static void\r
+atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (5) */\r
+ ident_len += 5;\r
+ ident -= 5;\r
+\r
+ if (ident_len == 6)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ switch (ident[0])\r
+ {\r
+ case 1: /* atIfIndex */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 2: /* atPhysAddress */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = sizeof(struct eth_addr);\r
+ break;\r
+ case 3: /* atNetAddress */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);\r
+ od->v_len = 4;\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+atentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+ struct eth_addr* ethaddr_ret;\r
+ struct ip_addr* ipaddr_ret;\r
+ struct ip_addr ip;\r
+ struct netif *netif;\r
+\r
+ if (len) {}\r
+\r
+ snmp_ifindextonetif(od->id_inst_ptr[1], &netif);\r
+ snmp_oidtoip(&od->id_inst_ptr[2], &ip);\r
+ ip.addr = htonl(ip.addr);\r
+\r
+ if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)\r
+ {\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* atIfIndex */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = od->id_inst_ptr[1];\r
+ }\r
+ break;\r
+ case 2: /* atPhysAddress */\r
+ {\r
+ struct eth_addr *dst = value;\r
+\r
+ *dst = *ethaddr_ret;\r
+ }\r
+ break;\r
+ case 3: /* atNetAddress */\r
+ {\r
+ struct ip_addr *dst = value;\r
+\r
+ *dst = *ipaddr_ret;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+static void\r
+ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ u8_t id;\r
+\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if (ident_len == 2)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id));\r
+ switch (id)\r
+ {\r
+ case 1: /* ipForwarding */\r
+ case 2: /* ipDefaultTTL */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 3: /* ipInReceives */\r
+ case 4: /* ipInHdrErrors */\r
+ case 5: /* ipInAddrErrors */\r
+ case 6: /* ipForwDatagrams */\r
+ case 7: /* ipInUnknownProtos */\r
+ case 8: /* ipInDiscards */\r
+ case 9: /* ipInDelivers */\r
+ case 10: /* ipOutRequests */\r
+ case 11: /* ipOutDiscards */\r
+ case 12: /* ipOutNoRoutes */\r
+ case 14: /* ipReasmReqds */\r
+ case 15: /* ipReasmOKs */\r
+ case 16: /* ipReasmFails */\r
+ case 17: /* ipFragOKs */\r
+ case 18: /* ipFragFails */\r
+ case 19: /* ipFragCreates */\r
+ case 23: /* ipRoutingDiscards */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 13: /* ipReasmTimeout */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ };\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+ip_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+\r
+ if (len) {}\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipForwarding */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+#if IP_FORWARD\r
+ /* forwarding */\r
+ *sint_ptr = 1;\r
+#else\r
+ /* not-forwarding */\r
+ *sint_ptr = 2;\r
+#endif\r
+ }\r
+ break;\r
+ case 2: /* ipDefaultTTL */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = IP_DEFAULT_TTL;\r
+ }\r
+ break;\r
+ case 3: /* ipInReceives */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipinreceives;\r
+ }\r
+ break;\r
+ case 4: /* ipInHdrErrors */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipinhdrerrors;\r
+ }\r
+ break;\r
+ case 5: /* ipInAddrErrors */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipinaddrerrors;\r
+ }\r
+ break;\r
+ case 6: /* ipForwDatagrams */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipforwdatagrams;\r
+ }\r
+ break;\r
+ case 7: /* ipInUnknownProtos */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipinunknownprotos;\r
+ }\r
+ break;\r
+ case 8: /* ipInDiscards */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipindiscards;\r
+ }\r
+ break;\r
+ case 9: /* ipInDelivers */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipindelivers;\r
+ }\r
+ break;\r
+ case 10: /* ipOutRequests */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipoutrequests;\r
+ }\r
+ break;\r
+ case 11: /* ipOutDiscards */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipoutdiscards;\r
+ }\r
+ break;\r
+ case 12: /* ipOutNoRoutes */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipoutnoroutes;\r
+ }\r
+ break;\r
+ case 13: /* ipReasmTimeout */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+#if IP_REASSEMBLY\r
+ *sint_ptr = IP_REASS_MAXAGE;\r
+#else\r
+ *sint_ptr = 0;\r
+#endif\r
+ }\r
+ break;\r
+ case 14: /* ipReasmReqds */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipreasmreqds;\r
+ }\r
+ break;\r
+ case 15: /* ipReasmOKs */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipreasmoks;\r
+ }\r
+ break;\r
+ case 16: /* ipReasmFails */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipreasmfails;\r
+ }\r
+ break;\r
+ case 17: /* ipFragOKs */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipfragoks;\r
+ }\r
+ break;\r
+ case 18: /* ipFragFails */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipfragfails;\r
+ }\r
+ break;\r
+ case 19: /* ipFragCreates */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = ipfragcreates;\r
+ }\r
+ break;\r
+ case 23: /* ipRoutingDiscards */\r
+ /** @todo can lwIP discard routes at all?? hardwire this to 0?? */\r
+ {\r
+ u32_t *uint_ptr = value;\r
+ *uint_ptr = iproutingdiscards;\r
+ }\r
+ break;\r
+ };\r
+}\r
+\r
+/**\r
+ * Test ip object value before setting.\r
+ *\r
+ * @param od is the object definition\r
+ * @param len return value space (in bytes)\r
+ * @param value points to (varbind) space to copy value from.\r
+ *\r
+ * @note we allow set if the value matches the hardwired value,\r
+ * otherwise return badvalue.\r
+ */\r
+static u8_t\r
+ip_set_test(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id, set_ok;\r
+ s32_t *sint_ptr = value;\r
+\r
+ if (len) {}\r
+ set_ok = 0;\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipForwarding */\r
+#if IP_FORWARD\r
+ /* forwarding */\r
+ if (*sint_ptr == 1)\r
+#else\r
+ /* not-forwarding */\r
+ if (*sint_ptr == 2)\r
+#endif\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ break;\r
+ case 2: /* ipDefaultTTL */\r
+ if (*sint_ptr == IP_DEFAULT_TTL)\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ break;\r
+ };\r
+ return set_ok;\r
+}\r
+\r
+static void\r
+ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (4) */\r
+ ident_len += 4;\r
+ ident -= 4;\r
+\r
+ if (ident_len == 5)\r
+ {\r
+ u8_t id;\r
+\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipAdEntAddr */\r
+ case 3: /* ipAdEntNetMask */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);\r
+ od->v_len = 4;\r
+ break;\r
+ case 2: /* ipAdEntIfIndex */\r
+ case 4: /* ipAdEntBcastAddr */\r
+ case 5: /* ipAdEntReasmMaxSize */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+ u16_t ifidx;\r
+ struct ip_addr ip;\r
+ struct netif *netif = netif_list;\r
+\r
+ if (len) {}\r
+ snmp_oidtoip(&od->id_inst_ptr[1], &ip);\r
+ ip.addr = htonl(ip.addr);\r
+ ifidx = 0;\r
+ while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))\r
+ {\r
+ netif = netif->next;\r
+ ifidx++;\r
+ }\r
+\r
+ if (netif != NULL)\r
+ {\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipAdEntAddr */\r
+ {\r
+ struct ip_addr *dst = value;\r
+ *dst = netif->ip_addr;\r
+ }\r
+ break;\r
+ case 2: /* ipAdEntIfIndex */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = ifidx + 1;\r
+ }\r
+ break;\r
+ case 3: /* ipAdEntNetMask */\r
+ {\r
+ struct ip_addr *dst = value;\r
+ *dst = netif->netmask;\r
+ }\r
+ break;\r
+ case 4: /* ipAdEntBcastAddr */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+\r
+ /* lwIP oddity, there's no broadcast\r
+ address in the netif we can rely on */\r
+ *sint_ptr = ip_addr_broadcast.addr & 1;\r
+ }\r
+ break;\r
+ case 5: /* ipAdEntReasmMaxSize */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+#if IP_REASSEMBLY\r
+ *sint_ptr = (IP_HLEN + IP_REASS_BUFSIZE);\r
+#else\r
+ /** @todo returning MTU would be a bad thing and\r
+ returning a wild guess like '576' isn't good either */\r
+ *sint_ptr = 0;\r
+#endif\r
+ }\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+/**\r
+ * @note\r
+ * lwIP IP routing is currently using the network addresses in netif_list.\r
+ * if no suitable network IP is found in netif_list, the default_netif is used.\r
+ */\r
+static void\r
+ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ u8_t id;\r
+\r
+ /* return to object name, adding index depth (4) */\r
+ ident_len += 4;\r
+ ident -= 4;\r
+\r
+ if (ident_len == 5)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipRouteDest */\r
+ case 7: /* ipRouteNextHop */\r
+ case 11: /* ipRouteMask */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);\r
+ od->v_len = 4;\r
+ break;\r
+ case 2: /* ipRouteIfIndex */\r
+ case 3: /* ipRouteMetric1 */\r
+ case 4: /* ipRouteMetric2 */\r
+ case 5: /* ipRouteMetric3 */\r
+ case 6: /* ipRouteMetric4 */\r
+ case 8: /* ipRouteType */\r
+ case 10: /* ipRouteAge */\r
+ case 12: /* ipRouteMetric5 */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 9: /* ipRouteProto */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 13: /* ipRouteInfo */\r
+ /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);\r
+ od->v_len = iprouteinfo.len * sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ struct netif *netif;\r
+ struct ip_addr dest;\r
+ s32_t *ident;\r
+ u8_t id;\r
+\r
+ ident = od->id_inst_ptr;\r
+ snmp_oidtoip(&ident[1], &dest);\r
+ dest.addr = htonl(dest.addr);\r
+\r
+ if (dest.addr == 0)\r
+ {\r
+ /* ip_route() uses default netif for default route */\r
+ netif = netif_default;\r
+ }\r
+ else\r
+ {\r
+ /* not using ip_route(), need exact match! */\r
+ netif = netif_list;\r
+ while ((netif != NULL) &&\r
+ !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )\r
+ {\r
+ netif = netif->next;\r
+ }\r
+ }\r
+ if (netif != NULL)\r
+ {\r
+ id = ident[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipRouteDest */\r
+ {\r
+ struct ip_addr *dst = value;\r
+\r
+ if (dest.addr == 0)\r
+ {\r
+ /* default rte has 0.0.0.0 dest */\r
+ dst->addr = 0;\r
+ }\r
+ else\r
+ {\r
+ /* netifs have netaddress dest */\r
+ dst->addr = netif->ip_addr.addr & netif->netmask.addr;\r
+ }\r
+ }\r
+ break;\r
+ case 2: /* ipRouteIfIndex */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+\r
+ snmp_netiftoifindex(netif, sint_ptr);\r
+ }\r
+ break;\r
+ case 3: /* ipRouteMetric1 */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+\r
+ if (dest.addr == 0)\r
+ {\r
+ /* default rte has metric 1 */\r
+ *sint_ptr = 1;\r
+ }\r
+ else\r
+ {\r
+ /* other rtes have metric 0 */\r
+ *sint_ptr = 0;\r
+ }\r
+ }\r
+ break;\r
+ case 4: /* ipRouteMetric2 */\r
+ case 5: /* ipRouteMetric3 */\r
+ case 6: /* ipRouteMetric4 */\r
+ case 12: /* ipRouteMetric5 */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ /* not used */\r
+ *sint_ptr = -1;\r
+ }\r
+ break;\r
+ case 7: /* ipRouteNextHop */\r
+ {\r
+ struct ip_addr *dst = value;\r
+\r
+ if (dest.addr == 0)\r
+ {\r
+ /* default rte: gateway */\r
+ *dst = netif->gw;\r
+ }\r
+ else\r
+ {\r
+ /* other rtes: netif ip_addr */\r
+ *dst = netif->ip_addr;\r
+ }\r
+ }\r
+ break;\r
+ case 8: /* ipRouteType */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+\r
+ if (dest.addr == 0)\r
+ {\r
+ /* default rte is indirect */\r
+ *sint_ptr = 4;\r
+ }\r
+ else\r
+ {\r
+ /* other rtes are direct */\r
+ *sint_ptr = 3;\r
+ }\r
+ }\r
+ break;\r
+ case 9: /* ipRouteProto */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ /* locally defined routes */\r
+ *sint_ptr = 2;\r
+ }\r
+ break;\r
+ case 10: /* ipRouteAge */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ /** @todo (sysuptime - timestamp last change) / 100\r
+ @see snmp_insert_iprteidx_tree() */\r
+ *sint_ptr = 0;\r
+ }\r
+ break;\r
+ case 11: /* ipRouteMask */\r
+ {\r
+ struct ip_addr *dst = value;\r
+\r
+ if (dest.addr == 0)\r
+ {\r
+ /* default rte use 0.0.0.0 mask */\r
+ dst->addr = 0;\r
+ }\r
+ else\r
+ {\r
+ /* other rtes use netmask */\r
+ *dst = netif->netmask;\r
+ }\r
+ }\r
+ break;\r
+ case 13: /* ipRouteInfo */\r
+ objectidncpy((s32_t*)value,(s32_t*)iprouteinfo.id,len / sizeof(s32_t));\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+static void\r
+ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (5) */\r
+ ident_len += 5;\r
+ ident -= 5;\r
+\r
+ if (ident_len == 6)\r
+ {\r
+ u8_t id;\r
+\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipNetToMediaIfIndex */\r
+ case 4: /* ipNetToMediaType */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 2: /* ipNetToMediaPhysAddress */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);\r
+ od->v_len = sizeof(struct eth_addr);\r
+ break;\r
+ case 3: /* ipNetToMediaNetAddress */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);\r
+ od->v_len = 4;\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+ struct eth_addr* ethaddr_ret;\r
+ struct ip_addr* ipaddr_ret;\r
+ struct ip_addr ip;\r
+ struct netif *netif;\r
+\r
+ if (len) {}\r
+\r
+ snmp_ifindextonetif(od->id_inst_ptr[1], &netif);\r
+ snmp_oidtoip(&od->id_inst_ptr[2], &ip);\r
+ ip.addr = htonl(ip.addr);\r
+\r
+ if (etharp_find_addr(netif, &ip, ðaddr_ret, &ipaddr_ret) > -1)\r
+ {\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* ipNetToMediaIfIndex */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = od->id_inst_ptr[1];\r
+ }\r
+ break;\r
+ case 2: /* ipNetToMediaPhysAddress */\r
+ {\r
+ struct eth_addr *dst = value;\r
+\r
+ *dst = *ethaddr_ret;\r
+ }\r
+ break;\r
+ case 3: /* ipNetToMediaNetAddress */\r
+ {\r
+ struct ip_addr *dst = value;\r
+\r
+ *dst = *ipaddr_ret;\r
+ }\r
+ break;\r
+ case 4: /* ipNetToMediaType */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ /* dynamic (?) */\r
+ *sint_ptr = 3;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+static void\r
+icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if ((ident_len == 2) &&\r
+ (ident[0] > 0) && (ident[0] < 27))\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);\r
+ od->v_len = sizeof(u32_t);\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+icmp_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u32_t *uint_ptr = value;\r
+ u8_t id;\r
+\r
+ if (len){}\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* icmpInMsgs */\r
+ *uint_ptr = icmpinmsgs;\r
+ break;\r
+ case 2: /* icmpInErrors */\r
+ *uint_ptr = icmpinerrors;\r
+ break;\r
+ case 3: /* icmpInDestUnreachs */\r
+ *uint_ptr = icmpindestunreachs;\r
+ break;\r
+ case 4: /* icmpInTimeExcds */\r
+ *uint_ptr = icmpintimeexcds;\r
+ break;\r
+ case 5: /* icmpInParmProbs */\r
+ *uint_ptr = icmpinparmprobs;\r
+ break;\r
+ case 6: /* icmpInSrcQuenchs */\r
+ *uint_ptr = icmpinsrcquenchs;\r
+ break;\r
+ case 7: /* icmpInRedirects */\r
+ *uint_ptr = icmpinredirects;\r
+ break;\r
+ case 8: /* icmpInEchos */\r
+ *uint_ptr = icmpinechos;\r
+ break;\r
+ case 9: /* icmpInEchoReps */\r
+ *uint_ptr = icmpinechoreps;\r
+ break;\r
+ case 10: /* icmpInTimestamps */\r
+ *uint_ptr = icmpintimestamps;\r
+ break;\r
+ case 11: /* icmpInTimestampReps */\r
+ *uint_ptr = icmpintimestampreps;\r
+ break;\r
+ case 12: /* icmpInAddrMasks */\r
+ *uint_ptr = icmpinaddrmasks;\r
+ break;\r
+ case 13: /* icmpInAddrMaskReps */\r
+ *uint_ptr = icmpinaddrmaskreps;\r
+ break;\r
+ case 14: /* icmpOutMsgs */\r
+ *uint_ptr = icmpoutmsgs;\r
+ break;\r
+ case 15: /* icmpOutErrors */\r
+ *uint_ptr = icmpouterrors;\r
+ break;\r
+ case 16: /* icmpOutDestUnreachs */\r
+ *uint_ptr = icmpoutdestunreachs;\r
+ break;\r
+ case 17: /* icmpOutTimeExcds */\r
+ *uint_ptr = icmpouttimeexcds;\r
+ break;\r
+ case 18: /* icmpOutParmProbs */\r
+ *uint_ptr = icmpoutparmprobs;\r
+ break;\r
+ case 19: /* icmpOutSrcQuenchs */\r
+ *uint_ptr = icmpoutsrcquenchs;\r
+ break;\r
+ case 20: /* icmpOutRedirects */\r
+ *uint_ptr = icmpoutredirects;\r
+ break;\r
+ case 21: /* icmpOutEchos */\r
+ *uint_ptr = icmpoutechos;\r
+ break;\r
+ case 22: /* icmpOutEchoReps */\r
+ *uint_ptr = icmpoutechoreps;\r
+ break;\r
+ case 23: /* icmpOutTimestamps */\r
+ *uint_ptr = icmpouttimestamps;\r
+ break;\r
+ case 24: /* icmpOutTimestampReps */\r
+ *uint_ptr = icmpouttimestampreps;\r
+ break;\r
+ case 25: /* icmpOutAddrMasks */\r
+ *uint_ptr = icmpoutaddrmasks;\r
+ break;\r
+ case 26: /* icmpOutAddrMaskReps */\r
+ *uint_ptr = icmpoutaddrmaskreps;\r
+ break;\r
+ }\r
+}\r
+\r
+#if LWIP_TCP\r
+/** @todo tcp grp */\r
+static void\r
+tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ u8_t id;\r
+\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if (ident_len == 2)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));\r
+\r
+ switch (id)\r
+ {\r
+ case 1: /* tcpRtoAlgorithm */\r
+ case 2: /* tcpRtoMin */\r
+ case 3: /* tcpRtoMax */\r
+ case 4: /* tcpMaxConn */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 5: /* tcpActiveOpens */\r
+ case 6: /* tcpPassiveOpens */\r
+ case 7: /* tcpAttemptFails */\r
+ case 8: /* tcpEstabResets */\r
+ case 10: /* tcpInSegs */\r
+ case 11: /* tcpOutSegs */\r
+ case 12: /* tcpRetransSegs */\r
+ case 14: /* tcpInErrs */\r
+ case 15: /* tcpOutRsts */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 9: /* tcpCurrEstab */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ };\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+tcp_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u32_t *uint_ptr = value;\r
+ s32_t *sint_ptr = value;\r
+ u8_t id;\r
+\r
+ if (len){}\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* tcpRtoAlgorithm, vanj(4) */\r
+ *sint_ptr = 4;\r
+ break;\r
+ case 2: /* tcpRtoMin */\r
+ /* @todo not the actual value, a guess,\r
+ needs to be calculated */\r
+ *sint_ptr = 1000;\r
+ break;\r
+ case 3: /* tcpRtoMax */\r
+ /* @todo not the actual value, a guess,\r
+ needs to be calculated */\r
+ *sint_ptr = 60000;\r
+ break;\r
+ case 4: /* tcpMaxConn */\r
+ *sint_ptr = MEMP_NUM_TCP_PCB;\r
+ break;\r
+ case 5: /* tcpActiveOpens */\r
+ *uint_ptr = tcpactiveopens;\r
+ break;\r
+ case 6: /* tcpPassiveOpens */\r
+ *uint_ptr = tcppassiveopens;\r
+ break;\r
+ case 7: /* tcpAttemptFails */\r
+ *uint_ptr = tcpattemptfails;\r
+ break;\r
+ case 8: /* tcpEstabResets */\r
+ *uint_ptr = tcpestabresets;\r
+ break;\r
+ case 9: /* tcpCurrEstab */\r
+ {\r
+ u16_t tcpcurrestab = 0;\r
+ struct tcp_pcb *pcb = tcp_active_pcbs;\r
+ while (pcb != NULL)\r
+ {\r
+ if ((pcb->state == ESTABLISHED) ||\r
+ (pcb->state == CLOSE_WAIT))\r
+ {\r
+ tcpcurrestab++;\r
+ }\r
+ pcb = pcb->next;\r
+ }\r
+ *uint_ptr = tcpcurrestab;\r
+ }\r
+ break;\r
+ case 10: /* tcpInSegs */\r
+ *uint_ptr = tcpinsegs;\r
+ break;\r
+ case 11: /* tcpOutSegs */\r
+ *uint_ptr = tcpoutsegs;\r
+ break;\r
+ case 12: /* tcpRetransSegs */\r
+ *uint_ptr = tcpretranssegs;\r
+ break;\r
+ case 14: /* tcpInErrs */\r
+ *uint_ptr = tcpinerrs;\r
+ break;\r
+ case 15: /* tcpOutRsts */\r
+ *uint_ptr = tcpoutrsts;\r
+ break;\r
+ }\r
+}\r
+\r
+static void\r
+tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (10) */\r
+ ident_len += 10;\r
+ ident -= 10;\r
+\r
+ if (ident_len == 11)\r
+ {\r
+ u8_t id;\r
+\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));\r
+\r
+ switch (id)\r
+ {\r
+ case 1: /* tcpConnState */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ case 2: /* tcpConnLocalAddress */\r
+ case 4: /* tcpConnRemAddress */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);\r
+ od->v_len = 4;\r
+ break;\r
+ case 3: /* tcpConnLocalPort */\r
+ case 5: /* tcpConnRemPort */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ };\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ struct ip_addr lip, rip;\r
+ u16_t lport, rport;\r
+ s32_t *ident;\r
+\r
+ ident = od->id_inst_ptr;\r
+ snmp_oidtoip(&ident[1], &lip);\r
+ lip.addr = htonl(lip.addr);\r
+ lport = ident[5];\r
+ snmp_oidtoip(&ident[6], &rip);\r
+ rip.addr = htonl(rip.addr);\r
+ rport = ident[10];\r
+\r
+ /** @todo find matching PCB */\r
+}\r
+#endif\r
+\r
+static void\r
+udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if ((ident_len == 2) &&\r
+ (ident[0] > 0) && (ident[0] < 6))\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);\r
+ od->v_len = sizeof(u32_t);\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+udp_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u32_t *uint_ptr = value;\r
+ u8_t id;\r
+\r
+ if (len){}\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* udpInDatagrams */\r
+ *uint_ptr = udpindatagrams;\r
+ break;\r
+ case 2: /* udpNoPorts */\r
+ *uint_ptr = udpnoports;\r
+ break;\r
+ case 3: /* udpInErrors */\r
+ *uint_ptr = udpinerrors;\r
+ break;\r
+ case 4: /* udpOutDatagrams */\r
+ *uint_ptr = udpoutdatagrams;\r
+ break;\r
+ }\r
+}\r
+\r
+static void\r
+udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (5) */\r
+ ident_len += 5;\r
+ ident -= 5;\r
+\r
+ if (ident_len == 6)\r
+ {\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ switch (ident[0])\r
+ {\r
+ case 1: /* udpLocalAddress */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);\r
+ od->v_len = 4;\r
+ break;\r
+ case 2: /* udpLocalPort */\r
+ od->instance = MIB_OBJECT_TAB;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+udpentry_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+ struct udp_pcb *pcb;\r
+ struct ip_addr ip;\r
+ u16_t port;\r
+\r
+ if (len){}\r
+ snmp_oidtoip(&od->id_inst_ptr[1], &ip);\r
+ ip.addr = htonl(ip.addr);\r
+ port = od->id_inst_ptr[5];\r
+\r
+ pcb = udp_pcbs;\r
+ while ((pcb != NULL) &&\r
+ !((pcb->local_ip.addr == ip.addr) &&\r
+ (pcb->local_port == port)))\r
+ {\r
+ pcb = pcb->next;\r
+ }\r
+\r
+ if (pcb != NULL)\r
+ {\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* udpLocalAddress */\r
+ {\r
+ struct ip_addr *dst = value;\r
+ *dst = pcb->local_ip;\r
+ }\r
+ break;\r
+ case 2: /* udpLocalPort */\r
+ {\r
+ s32_t *sint_ptr = value;\r
+ *sint_ptr = pcb->local_port;\r
+ }\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+static void\r
+snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)\r
+{\r
+ /* return to object name, adding index depth (1) */\r
+ ident_len += 1;\r
+ ident -= 1;\r
+ if (ident_len == 2)\r
+ {\r
+ u8_t id;\r
+\r
+ od->id_inst_len = ident_len;\r
+ od->id_inst_ptr = ident;\r
+\r
+ id = ident[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* snmpInPkts */\r
+ case 2: /* snmpOutPkts */\r
+ case 3: /* snmpInBadVersions */\r
+ case 4: /* snmpInBadCommunityNames */\r
+ case 5: /* snmpInBadCommunityUses */\r
+ case 6: /* snmpInASNParseErrs */\r
+ case 8: /* snmpInTooBigs */\r
+ case 9: /* snmpInNoSuchNames */\r
+ case 10: /* snmpInBadValues */\r
+ case 11: /* snmpInReadOnlys */\r
+ case 12: /* snmpInGenErrs */\r
+ case 13: /* snmpInTotalReqVars */\r
+ case 14: /* snmpInTotalSetVars */\r
+ case 15: /* snmpInGetRequests */\r
+ case 16: /* snmpInGetNexts */\r
+ case 17: /* snmpInSetRequests */\r
+ case 18: /* snmpInGetResponses */\r
+ case 19: /* snmpInTraps */\r
+ case 20: /* snmpOutTooBigs */\r
+ case 21: /* snmpOutNoSuchNames */\r
+ case 22: /* snmpOutBadValues */\r
+ case 24: /* snmpOutGenErrs */\r
+ case 25: /* snmpOutGetRequests */\r
+ case 26: /* snmpOutGetNexts */\r
+ case 27: /* snmpOutSetRequests */\r
+ case 28: /* snmpOutGetResponses */\r
+ case 29: /* snmpOutTraps */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_ONLY;\r
+ od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);\r
+ od->v_len = sizeof(u32_t);\r
+ break;\r
+ case 30: /* snmpEnableAuthenTraps */\r
+ od->instance = MIB_OBJECT_SCALAR;\r
+ od->access = MIB_OBJECT_READ_WRITE;\r
+ od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);\r
+ od->v_len = sizeof(s32_t);\r
+ break;\r
+ default:\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ break;\r
+ };\r
+ }\r
+ else\r
+ {\r
+ LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n"));\r
+ od->instance = MIB_OBJECT_NONE;\r
+ }\r
+}\r
+\r
+static void\r
+snmp_get_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u32_t *uint_ptr = value;\r
+ u8_t id;\r
+\r
+ if (len){}\r
+ id = od->id_inst_ptr[0];\r
+ switch (id)\r
+ {\r
+ case 1: /* snmpInPkts */\r
+ *uint_ptr = snmpinpkts;\r
+ break;\r
+ case 2: /* snmpOutPkts */\r
+ *uint_ptr = snmpoutpkts;\r
+ break;\r
+ case 3: /* snmpInBadVersions */\r
+ *uint_ptr = snmpinbadversions;\r
+ break;\r
+ case 4: /* snmpInBadCommunityNames */\r
+ *uint_ptr = snmpinbadcommunitynames;\r
+ break;\r
+ case 5: /* snmpInBadCommunityUses */\r
+ *uint_ptr = snmpinbadcommunityuses;\r
+ break;\r
+ case 6: /* snmpInASNParseErrs */\r
+ *uint_ptr = snmpinasnparseerrs;\r
+ break;\r
+ case 8: /* snmpInTooBigs */\r
+ *uint_ptr = snmpintoobigs;\r
+ break;\r
+ case 9: /* snmpInNoSuchNames */\r
+ *uint_ptr = snmpinnosuchnames;\r
+ break;\r
+ case 10: /* snmpInBadValues */\r
+ *uint_ptr = snmpinbadvalues;\r
+ break;\r
+ case 11: /* snmpInReadOnlys */\r
+ *uint_ptr = snmpinreadonlys;\r
+ break;\r
+ case 12: /* snmpInGenErrs */\r
+ *uint_ptr = snmpingenerrs;\r
+ break;\r
+ case 13: /* snmpInTotalReqVars */\r
+ *uint_ptr = snmpintotalreqvars;\r
+ break;\r
+ case 14: /* snmpInTotalSetVars */\r
+ *uint_ptr = snmpintotalsetvars;\r
+ break;\r
+ case 15: /* snmpInGetRequests */\r
+ *uint_ptr = snmpingetrequests;\r
+ break;\r
+ case 16: /* snmpInGetNexts */\r
+ *uint_ptr = snmpingetnexts;\r
+ break;\r
+ case 17: /* snmpInSetRequests */\r
+ *uint_ptr = snmpinsetrequests;\r
+ break;\r
+ case 18: /* snmpInGetResponses */\r
+ *uint_ptr = snmpingetresponses;\r
+ break;\r
+ case 19: /* snmpInTraps */\r
+ *uint_ptr = snmpintraps;\r
+ break;\r
+ case 20: /* snmpOutTooBigs */\r
+ *uint_ptr = snmpouttoobigs;\r
+ break;\r
+ case 21: /* snmpOutNoSuchNames */\r
+ *uint_ptr = snmpoutnosuchnames;\r
+ break;\r
+ case 22: /* snmpOutBadValues */\r
+ *uint_ptr = snmpoutbadvalues;\r
+ break;\r
+ case 24: /* snmpOutGenErrs */\r
+ *uint_ptr = snmpoutgenerrs;\r
+ break;\r
+ case 25: /* snmpOutGetRequests */\r
+ *uint_ptr = snmpoutgetrequests;\r
+ break;\r
+ case 26: /* snmpOutGetNexts */\r
+ *uint_ptr = snmpoutgetnexts;\r
+ break;\r
+ case 27: /* snmpOutSetRequests */\r
+ *uint_ptr = snmpoutsetrequests;\r
+ break;\r
+ case 28: /* snmpOutGetResponses */\r
+ *uint_ptr = snmpoutgetresponses;\r
+ break;\r
+ case 29: /* snmpOutTraps */\r
+ *uint_ptr = snmpouttraps;\r
+ break;\r
+ case 30: /* snmpEnableAuthenTraps */\r
+ *uint_ptr = *snmpenableauthentraps_ptr;\r
+ break;\r
+ };\r
+}\r
+\r
+/**\r
+ * Test snmp object value before setting.\r
+ *\r
+ * @param od is the object definition\r
+ * @param len return value space (in bytes)\r
+ * @param value points to (varbind) space to copy value from.\r
+ */\r
+static u8_t\r
+snmp_set_test(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id, set_ok;\r
+\r
+ if (len) {}\r
+ set_ok = 0;\r
+ id = od->id_inst_ptr[0];\r
+ if (id == 30)\r
+ {\r
+ /* snmpEnableAuthenTraps */\r
+ s32_t *sint_ptr = value;\r
+\r
+ if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default)\r
+ {\r
+ /* we should have writable non-volatile mem here */\r
+ if ((*sint_ptr == 1) || (*sint_ptr == 2))\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ /* const or hardwired value */\r
+ if (*sint_ptr == snmpenableauthentraps_default)\r
+ {\r
+ set_ok = 1;\r
+ }\r
+ }\r
+ }\r
+ return set_ok;\r
+}\r
+\r
+static void\r
+snmp_set_value(struct obj_def *od, u16_t len, void *value)\r
+{\r
+ u8_t id;\r
+\r
+ if (len) {}\r
+ id = od->id_inst_ptr[0];\r
+ if (id == 30)\r
+ {\r
+ /* snmpEnableAuthenTraps */\r
+ s32_t *sint_ptr = value;\r
+ *snmpenableauthentraps_ptr = *sint_ptr;\r
+ }\r
+}\r
+\r
+#endif /* LWIP_SNMP */\r