![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Embedded C project:18/12/2014
Dependencies: DS1307 TextLCD mbed
NetServices/lwip/core/snmp/mib_structs.c@0:8d87bc453349, 2014-12-18 (annotated)
- Committer:
- ninoderkinderen
- Date:
- Thu Dec 18 09:35:49 2014 +0000
- Revision:
- 0:8d87bc453349
Programma embedded C
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ninoderkinderen | 0:8d87bc453349 | 1 | /** |
ninoderkinderen | 0:8d87bc453349 | 2 | * @file |
ninoderkinderen | 0:8d87bc453349 | 3 | * MIB tree access/construction functions. |
ninoderkinderen | 0:8d87bc453349 | 4 | */ |
ninoderkinderen | 0:8d87bc453349 | 5 | |
ninoderkinderen | 0:8d87bc453349 | 6 | /* |
ninoderkinderen | 0:8d87bc453349 | 7 | * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. |
ninoderkinderen | 0:8d87bc453349 | 8 | * All rights reserved. |
ninoderkinderen | 0:8d87bc453349 | 9 | * |
ninoderkinderen | 0:8d87bc453349 | 10 | * Redistribution and use in source and binary forms, with or without modification, |
ninoderkinderen | 0:8d87bc453349 | 11 | * are permitted provided that the following conditions are met: |
ninoderkinderen | 0:8d87bc453349 | 12 | * |
ninoderkinderen | 0:8d87bc453349 | 13 | * 1. Redistributions of source code must retain the above copyright notice, |
ninoderkinderen | 0:8d87bc453349 | 14 | * this list of conditions and the following disclaimer. |
ninoderkinderen | 0:8d87bc453349 | 15 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
ninoderkinderen | 0:8d87bc453349 | 16 | * this list of conditions and the following disclaimer in the documentation |
ninoderkinderen | 0:8d87bc453349 | 17 | * and/or other materials provided with the distribution. |
ninoderkinderen | 0:8d87bc453349 | 18 | * 3. The name of the author may not be used to endorse or promote products |
ninoderkinderen | 0:8d87bc453349 | 19 | * derived from this software without specific prior written permission. |
ninoderkinderen | 0:8d87bc453349 | 20 | * |
ninoderkinderen | 0:8d87bc453349 | 21 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
ninoderkinderen | 0:8d87bc453349 | 22 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
ninoderkinderen | 0:8d87bc453349 | 23 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
ninoderkinderen | 0:8d87bc453349 | 24 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
ninoderkinderen | 0:8d87bc453349 | 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
ninoderkinderen | 0:8d87bc453349 | 26 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
ninoderkinderen | 0:8d87bc453349 | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
ninoderkinderen | 0:8d87bc453349 | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
ninoderkinderen | 0:8d87bc453349 | 29 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
ninoderkinderen | 0:8d87bc453349 | 30 | * OF SUCH DAMAGE. |
ninoderkinderen | 0:8d87bc453349 | 31 | * |
ninoderkinderen | 0:8d87bc453349 | 32 | * Author: Christiaan Simons <christiaan.simons@axon.tv> |
ninoderkinderen | 0:8d87bc453349 | 33 | */ |
ninoderkinderen | 0:8d87bc453349 | 34 | |
ninoderkinderen | 0:8d87bc453349 | 35 | #include "lwip/opt.h" |
ninoderkinderen | 0:8d87bc453349 | 36 | |
ninoderkinderen | 0:8d87bc453349 | 37 | #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ |
ninoderkinderen | 0:8d87bc453349 | 38 | |
ninoderkinderen | 0:8d87bc453349 | 39 | #include "lwip/snmp_structs.h" |
ninoderkinderen | 0:8d87bc453349 | 40 | #include "lwip/memp.h" |
ninoderkinderen | 0:8d87bc453349 | 41 | #include "lwip/netif.h" |
ninoderkinderen | 0:8d87bc453349 | 42 | |
ninoderkinderen | 0:8d87bc453349 | 43 | /** .iso.org.dod.internet address prefix, @see snmp_iso_*() */ |
ninoderkinderen | 0:8d87bc453349 | 44 | const s32_t prefix[4] = {1, 3, 6, 1}; |
ninoderkinderen | 0:8d87bc453349 | 45 | |
ninoderkinderen | 0:8d87bc453349 | 46 | #define NODE_STACK_SIZE (LWIP_SNMP_OBJ_ID_LEN) |
ninoderkinderen | 0:8d87bc453349 | 47 | /** node stack entry (old news?) */ |
ninoderkinderen | 0:8d87bc453349 | 48 | struct nse |
ninoderkinderen | 0:8d87bc453349 | 49 | { |
ninoderkinderen | 0:8d87bc453349 | 50 | /** right child */ |
ninoderkinderen | 0:8d87bc453349 | 51 | struct mib_node* r_ptr; |
ninoderkinderen | 0:8d87bc453349 | 52 | /** right child identifier */ |
ninoderkinderen | 0:8d87bc453349 | 53 | s32_t r_id; |
ninoderkinderen | 0:8d87bc453349 | 54 | /** right child next level */ |
ninoderkinderen | 0:8d87bc453349 | 55 | u8_t r_nl; |
ninoderkinderen | 0:8d87bc453349 | 56 | }; |
ninoderkinderen | 0:8d87bc453349 | 57 | static u8_t node_stack_cnt; |
ninoderkinderen | 0:8d87bc453349 | 58 | static struct nse node_stack[NODE_STACK_SIZE]; |
ninoderkinderen | 0:8d87bc453349 | 59 | |
ninoderkinderen | 0:8d87bc453349 | 60 | /** |
ninoderkinderen | 0:8d87bc453349 | 61 | * Pushes nse struct onto stack. |
ninoderkinderen | 0:8d87bc453349 | 62 | */ |
ninoderkinderen | 0:8d87bc453349 | 63 | static void |
ninoderkinderen | 0:8d87bc453349 | 64 | push_node(struct nse* node) |
ninoderkinderen | 0:8d87bc453349 | 65 | { |
ninoderkinderen | 0:8d87bc453349 | 66 | LWIP_ASSERT("node_stack_cnt < NODE_STACK_SIZE",node_stack_cnt < NODE_STACK_SIZE); |
ninoderkinderen | 0:8d87bc453349 | 67 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("push_node() node=%p id=%"S32_F"\n",(void*)(node->r_ptr),node->r_id)); |
ninoderkinderen | 0:8d87bc453349 | 68 | if (node_stack_cnt < NODE_STACK_SIZE) |
ninoderkinderen | 0:8d87bc453349 | 69 | { |
ninoderkinderen | 0:8d87bc453349 | 70 | node_stack[node_stack_cnt] = *node; |
ninoderkinderen | 0:8d87bc453349 | 71 | node_stack_cnt++; |
ninoderkinderen | 0:8d87bc453349 | 72 | } |
ninoderkinderen | 0:8d87bc453349 | 73 | } |
ninoderkinderen | 0:8d87bc453349 | 74 | |
ninoderkinderen | 0:8d87bc453349 | 75 | /** |
ninoderkinderen | 0:8d87bc453349 | 76 | * Pops nse struct from stack. |
ninoderkinderen | 0:8d87bc453349 | 77 | */ |
ninoderkinderen | 0:8d87bc453349 | 78 | static void |
ninoderkinderen | 0:8d87bc453349 | 79 | pop_node(struct nse* node) |
ninoderkinderen | 0:8d87bc453349 | 80 | { |
ninoderkinderen | 0:8d87bc453349 | 81 | if (node_stack_cnt > 0) |
ninoderkinderen | 0:8d87bc453349 | 82 | { |
ninoderkinderen | 0:8d87bc453349 | 83 | node_stack_cnt--; |
ninoderkinderen | 0:8d87bc453349 | 84 | *node = node_stack[node_stack_cnt]; |
ninoderkinderen | 0:8d87bc453349 | 85 | } |
ninoderkinderen | 0:8d87bc453349 | 86 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("pop_node() node=%p id=%"S32_F"\n",(void *)(node->r_ptr),node->r_id)); |
ninoderkinderen | 0:8d87bc453349 | 87 | } |
ninoderkinderen | 0:8d87bc453349 | 88 | |
ninoderkinderen | 0:8d87bc453349 | 89 | /** |
ninoderkinderen | 0:8d87bc453349 | 90 | * Conversion from ifIndex to lwIP netif |
ninoderkinderen | 0:8d87bc453349 | 91 | * @param ifindex is a s32_t object sub-identifier |
ninoderkinderen | 0:8d87bc453349 | 92 | * @param netif points to returned netif struct pointer |
ninoderkinderen | 0:8d87bc453349 | 93 | */ |
ninoderkinderen | 0:8d87bc453349 | 94 | void |
ninoderkinderen | 0:8d87bc453349 | 95 | snmp_ifindextonetif(s32_t ifindex, struct netif **netif) |
ninoderkinderen | 0:8d87bc453349 | 96 | { |
ninoderkinderen | 0:8d87bc453349 | 97 | struct netif *nif = netif_list; |
ninoderkinderen | 0:8d87bc453349 | 98 | s32_t i, ifidx; |
ninoderkinderen | 0:8d87bc453349 | 99 | |
ninoderkinderen | 0:8d87bc453349 | 100 | ifidx = ifindex - 1; |
ninoderkinderen | 0:8d87bc453349 | 101 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 102 | while ((nif != NULL) && (i < ifidx)) |
ninoderkinderen | 0:8d87bc453349 | 103 | { |
ninoderkinderen | 0:8d87bc453349 | 104 | nif = nif->next; |
ninoderkinderen | 0:8d87bc453349 | 105 | i++; |
ninoderkinderen | 0:8d87bc453349 | 106 | } |
ninoderkinderen | 0:8d87bc453349 | 107 | *netif = nif; |
ninoderkinderen | 0:8d87bc453349 | 108 | } |
ninoderkinderen | 0:8d87bc453349 | 109 | |
ninoderkinderen | 0:8d87bc453349 | 110 | /** |
ninoderkinderen | 0:8d87bc453349 | 111 | * Conversion from lwIP netif to ifIndex |
ninoderkinderen | 0:8d87bc453349 | 112 | * @param netif points to a netif struct |
ninoderkinderen | 0:8d87bc453349 | 113 | * @param ifidx points to s32_t object sub-identifier |
ninoderkinderen | 0:8d87bc453349 | 114 | */ |
ninoderkinderen | 0:8d87bc453349 | 115 | void |
ninoderkinderen | 0:8d87bc453349 | 116 | snmp_netiftoifindex(struct netif *netif, s32_t *ifidx) |
ninoderkinderen | 0:8d87bc453349 | 117 | { |
ninoderkinderen | 0:8d87bc453349 | 118 | struct netif *nif = netif_list; |
ninoderkinderen | 0:8d87bc453349 | 119 | u16_t i; |
ninoderkinderen | 0:8d87bc453349 | 120 | |
ninoderkinderen | 0:8d87bc453349 | 121 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 122 | while ((nif != NULL) && (nif != netif)) |
ninoderkinderen | 0:8d87bc453349 | 123 | { |
ninoderkinderen | 0:8d87bc453349 | 124 | nif = nif->next; |
ninoderkinderen | 0:8d87bc453349 | 125 | i++; |
ninoderkinderen | 0:8d87bc453349 | 126 | } |
ninoderkinderen | 0:8d87bc453349 | 127 | *ifidx = i+1; |
ninoderkinderen | 0:8d87bc453349 | 128 | } |
ninoderkinderen | 0:8d87bc453349 | 129 | |
ninoderkinderen | 0:8d87bc453349 | 130 | /** |
ninoderkinderen | 0:8d87bc453349 | 131 | * Conversion from oid to lwIP ip_addr |
ninoderkinderen | 0:8d87bc453349 | 132 | * @param ident points to s32_t ident[4] input |
ninoderkinderen | 0:8d87bc453349 | 133 | * @param ip points to output struct |
ninoderkinderen | 0:8d87bc453349 | 134 | */ |
ninoderkinderen | 0:8d87bc453349 | 135 | void |
ninoderkinderen | 0:8d87bc453349 | 136 | snmp_oidtoip(s32_t *ident, ip_addr_t *ip) |
ninoderkinderen | 0:8d87bc453349 | 137 | { |
ninoderkinderen | 0:8d87bc453349 | 138 | IP4_ADDR(ip, ident[0], ident[1], ident[2], ident[3]); |
ninoderkinderen | 0:8d87bc453349 | 139 | } |
ninoderkinderen | 0:8d87bc453349 | 140 | |
ninoderkinderen | 0:8d87bc453349 | 141 | /** |
ninoderkinderen | 0:8d87bc453349 | 142 | * Conversion from lwIP ip_addr to oid |
ninoderkinderen | 0:8d87bc453349 | 143 | * @param ip points to input struct |
ninoderkinderen | 0:8d87bc453349 | 144 | * @param ident points to s32_t ident[4] output |
ninoderkinderen | 0:8d87bc453349 | 145 | */ |
ninoderkinderen | 0:8d87bc453349 | 146 | void |
ninoderkinderen | 0:8d87bc453349 | 147 | snmp_iptooid(ip_addr_t *ip, s32_t *ident) |
ninoderkinderen | 0:8d87bc453349 | 148 | { |
ninoderkinderen | 0:8d87bc453349 | 149 | ident[0] = ip4_addr1(ip); |
ninoderkinderen | 0:8d87bc453349 | 150 | ident[1] = ip4_addr2(ip); |
ninoderkinderen | 0:8d87bc453349 | 151 | ident[2] = ip4_addr3(ip); |
ninoderkinderen | 0:8d87bc453349 | 152 | ident[3] = ip4_addr4(ip); |
ninoderkinderen | 0:8d87bc453349 | 153 | } |
ninoderkinderen | 0:8d87bc453349 | 154 | |
ninoderkinderen | 0:8d87bc453349 | 155 | struct mib_list_node * |
ninoderkinderen | 0:8d87bc453349 | 156 | snmp_mib_ln_alloc(s32_t id) |
ninoderkinderen | 0:8d87bc453349 | 157 | { |
ninoderkinderen | 0:8d87bc453349 | 158 | struct mib_list_node *ln; |
ninoderkinderen | 0:8d87bc453349 | 159 | |
ninoderkinderen | 0:8d87bc453349 | 160 | ln = (struct mib_list_node *)memp_malloc(MEMP_SNMP_NODE); |
ninoderkinderen | 0:8d87bc453349 | 161 | if (ln != NULL) |
ninoderkinderen | 0:8d87bc453349 | 162 | { |
ninoderkinderen | 0:8d87bc453349 | 163 | ln->prev = NULL; |
ninoderkinderen | 0:8d87bc453349 | 164 | ln->next = NULL; |
ninoderkinderen | 0:8d87bc453349 | 165 | ln->objid = id; |
ninoderkinderen | 0:8d87bc453349 | 166 | ln->nptr = NULL; |
ninoderkinderen | 0:8d87bc453349 | 167 | } |
ninoderkinderen | 0:8d87bc453349 | 168 | return ln; |
ninoderkinderen | 0:8d87bc453349 | 169 | } |
ninoderkinderen | 0:8d87bc453349 | 170 | |
ninoderkinderen | 0:8d87bc453349 | 171 | void |
ninoderkinderen | 0:8d87bc453349 | 172 | snmp_mib_ln_free(struct mib_list_node *ln) |
ninoderkinderen | 0:8d87bc453349 | 173 | { |
ninoderkinderen | 0:8d87bc453349 | 174 | memp_free(MEMP_SNMP_NODE, ln); |
ninoderkinderen | 0:8d87bc453349 | 175 | } |
ninoderkinderen | 0:8d87bc453349 | 176 | |
ninoderkinderen | 0:8d87bc453349 | 177 | struct mib_list_rootnode * |
ninoderkinderen | 0:8d87bc453349 | 178 | snmp_mib_lrn_alloc(void) |
ninoderkinderen | 0:8d87bc453349 | 179 | { |
ninoderkinderen | 0:8d87bc453349 | 180 | struct mib_list_rootnode *lrn; |
ninoderkinderen | 0:8d87bc453349 | 181 | |
ninoderkinderen | 0:8d87bc453349 | 182 | lrn = (struct mib_list_rootnode*)memp_malloc(MEMP_SNMP_ROOTNODE); |
ninoderkinderen | 0:8d87bc453349 | 183 | if (lrn != NULL) |
ninoderkinderen | 0:8d87bc453349 | 184 | { |
ninoderkinderen | 0:8d87bc453349 | 185 | lrn->get_object_def = noleafs_get_object_def; |
ninoderkinderen | 0:8d87bc453349 | 186 | lrn->get_value = noleafs_get_value; |
ninoderkinderen | 0:8d87bc453349 | 187 | lrn->set_test = noleafs_set_test; |
ninoderkinderen | 0:8d87bc453349 | 188 | lrn->set_value = noleafs_set_value; |
ninoderkinderen | 0:8d87bc453349 | 189 | lrn->node_type = MIB_NODE_LR; |
ninoderkinderen | 0:8d87bc453349 | 190 | lrn->maxlength = 0; |
ninoderkinderen | 0:8d87bc453349 | 191 | lrn->head = NULL; |
ninoderkinderen | 0:8d87bc453349 | 192 | lrn->tail = NULL; |
ninoderkinderen | 0:8d87bc453349 | 193 | lrn->count = 0; |
ninoderkinderen | 0:8d87bc453349 | 194 | } |
ninoderkinderen | 0:8d87bc453349 | 195 | return lrn; |
ninoderkinderen | 0:8d87bc453349 | 196 | } |
ninoderkinderen | 0:8d87bc453349 | 197 | |
ninoderkinderen | 0:8d87bc453349 | 198 | void |
ninoderkinderen | 0:8d87bc453349 | 199 | snmp_mib_lrn_free(struct mib_list_rootnode *lrn) |
ninoderkinderen | 0:8d87bc453349 | 200 | { |
ninoderkinderen | 0:8d87bc453349 | 201 | memp_free(MEMP_SNMP_ROOTNODE, lrn); |
ninoderkinderen | 0:8d87bc453349 | 202 | } |
ninoderkinderen | 0:8d87bc453349 | 203 | |
ninoderkinderen | 0:8d87bc453349 | 204 | /** |
ninoderkinderen | 0:8d87bc453349 | 205 | * Inserts node in idx list in a sorted |
ninoderkinderen | 0:8d87bc453349 | 206 | * (ascending order) fashion and |
ninoderkinderen | 0:8d87bc453349 | 207 | * allocates the node if needed. |
ninoderkinderen | 0:8d87bc453349 | 208 | * |
ninoderkinderen | 0:8d87bc453349 | 209 | * @param rn points to the root node |
ninoderkinderen | 0:8d87bc453349 | 210 | * @param objid is the object sub identifier |
ninoderkinderen | 0:8d87bc453349 | 211 | * @param insn points to a pointer to the inserted node |
ninoderkinderen | 0:8d87bc453349 | 212 | * used for constructing the tree. |
ninoderkinderen | 0:8d87bc453349 | 213 | * @return -1 if failed, 1 if inserted, 2 if present. |
ninoderkinderen | 0:8d87bc453349 | 214 | */ |
ninoderkinderen | 0:8d87bc453349 | 215 | s8_t |
ninoderkinderen | 0:8d87bc453349 | 216 | snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn) |
ninoderkinderen | 0:8d87bc453349 | 217 | { |
ninoderkinderen | 0:8d87bc453349 | 218 | struct mib_list_node *nn; |
ninoderkinderen | 0:8d87bc453349 | 219 | s8_t insert; |
ninoderkinderen | 0:8d87bc453349 | 220 | |
ninoderkinderen | 0:8d87bc453349 | 221 | LWIP_ASSERT("rn != NULL",rn != NULL); |
ninoderkinderen | 0:8d87bc453349 | 222 | |
ninoderkinderen | 0:8d87bc453349 | 223 | /* -1 = malloc failure, 0 = not inserted, 1 = inserted, 2 = was present */ |
ninoderkinderen | 0:8d87bc453349 | 224 | insert = 0; |
ninoderkinderen | 0:8d87bc453349 | 225 | if (rn->head == NULL) |
ninoderkinderen | 0:8d87bc453349 | 226 | { |
ninoderkinderen | 0:8d87bc453349 | 227 | /* empty list, add first node */ |
ninoderkinderen | 0:8d87bc453349 | 228 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc empty list objid==%"S32_F"\n",objid)); |
ninoderkinderen | 0:8d87bc453349 | 229 | nn = snmp_mib_ln_alloc(objid); |
ninoderkinderen | 0:8d87bc453349 | 230 | if (nn != NULL) |
ninoderkinderen | 0:8d87bc453349 | 231 | { |
ninoderkinderen | 0:8d87bc453349 | 232 | rn->head = nn; |
ninoderkinderen | 0:8d87bc453349 | 233 | rn->tail = nn; |
ninoderkinderen | 0:8d87bc453349 | 234 | *insn = nn; |
ninoderkinderen | 0:8d87bc453349 | 235 | insert = 1; |
ninoderkinderen | 0:8d87bc453349 | 236 | } |
ninoderkinderen | 0:8d87bc453349 | 237 | else |
ninoderkinderen | 0:8d87bc453349 | 238 | { |
ninoderkinderen | 0:8d87bc453349 | 239 | insert = -1; |
ninoderkinderen | 0:8d87bc453349 | 240 | } |
ninoderkinderen | 0:8d87bc453349 | 241 | } |
ninoderkinderen | 0:8d87bc453349 | 242 | else |
ninoderkinderen | 0:8d87bc453349 | 243 | { |
ninoderkinderen | 0:8d87bc453349 | 244 | struct mib_list_node *n; |
ninoderkinderen | 0:8d87bc453349 | 245 | /* at least one node is present */ |
ninoderkinderen | 0:8d87bc453349 | 246 | n = rn->head; |
ninoderkinderen | 0:8d87bc453349 | 247 | while ((n != NULL) && (insert == 0)) |
ninoderkinderen | 0:8d87bc453349 | 248 | { |
ninoderkinderen | 0:8d87bc453349 | 249 | if (n->objid == objid) |
ninoderkinderen | 0:8d87bc453349 | 250 | { |
ninoderkinderen | 0:8d87bc453349 | 251 | /* node is already there */ |
ninoderkinderen | 0:8d87bc453349 | 252 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("node already there objid==%"S32_F"\n",objid)); |
ninoderkinderen | 0:8d87bc453349 | 253 | *insn = n; |
ninoderkinderen | 0:8d87bc453349 | 254 | insert = 2; |
ninoderkinderen | 0:8d87bc453349 | 255 | } |
ninoderkinderen | 0:8d87bc453349 | 256 | else if (n->objid < objid) |
ninoderkinderen | 0:8d87bc453349 | 257 | { |
ninoderkinderen | 0:8d87bc453349 | 258 | if (n->next == NULL) |
ninoderkinderen | 0:8d87bc453349 | 259 | { |
ninoderkinderen | 0:8d87bc453349 | 260 | /* alloc and insert at the tail */ |
ninoderkinderen | 0:8d87bc453349 | 261 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc ins tail objid==%"S32_F"\n",objid)); |
ninoderkinderen | 0:8d87bc453349 | 262 | nn = snmp_mib_ln_alloc(objid); |
ninoderkinderen | 0:8d87bc453349 | 263 | if (nn != NULL) |
ninoderkinderen | 0:8d87bc453349 | 264 | { |
ninoderkinderen | 0:8d87bc453349 | 265 | nn->next = NULL; |
ninoderkinderen | 0:8d87bc453349 | 266 | nn->prev = n; |
ninoderkinderen | 0:8d87bc453349 | 267 | n->next = nn; |
ninoderkinderen | 0:8d87bc453349 | 268 | rn->tail = nn; |
ninoderkinderen | 0:8d87bc453349 | 269 | *insn = nn; |
ninoderkinderen | 0:8d87bc453349 | 270 | insert = 1; |
ninoderkinderen | 0:8d87bc453349 | 271 | } |
ninoderkinderen | 0:8d87bc453349 | 272 | else |
ninoderkinderen | 0:8d87bc453349 | 273 | { |
ninoderkinderen | 0:8d87bc453349 | 274 | /* insertion failure */ |
ninoderkinderen | 0:8d87bc453349 | 275 | insert = -1; |
ninoderkinderen | 0:8d87bc453349 | 276 | } |
ninoderkinderen | 0:8d87bc453349 | 277 | } |
ninoderkinderen | 0:8d87bc453349 | 278 | else |
ninoderkinderen | 0:8d87bc453349 | 279 | { |
ninoderkinderen | 0:8d87bc453349 | 280 | /* there's more to explore: traverse list */ |
ninoderkinderen | 0:8d87bc453349 | 281 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("traverse list\n")); |
ninoderkinderen | 0:8d87bc453349 | 282 | n = n->next; |
ninoderkinderen | 0:8d87bc453349 | 283 | } |
ninoderkinderen | 0:8d87bc453349 | 284 | } |
ninoderkinderen | 0:8d87bc453349 | 285 | else |
ninoderkinderen | 0:8d87bc453349 | 286 | { |
ninoderkinderen | 0:8d87bc453349 | 287 | /* n->objid > objid */ |
ninoderkinderen | 0:8d87bc453349 | 288 | /* alloc and insert between n->prev and n */ |
ninoderkinderen | 0:8d87bc453349 | 289 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("alloc ins n->prev, objid==%"S32_F", n\n",objid)); |
ninoderkinderen | 0:8d87bc453349 | 290 | nn = snmp_mib_ln_alloc(objid); |
ninoderkinderen | 0:8d87bc453349 | 291 | if (nn != NULL) |
ninoderkinderen | 0:8d87bc453349 | 292 | { |
ninoderkinderen | 0:8d87bc453349 | 293 | if (n->prev == NULL) |
ninoderkinderen | 0:8d87bc453349 | 294 | { |
ninoderkinderen | 0:8d87bc453349 | 295 | /* insert at the head */ |
ninoderkinderen | 0:8d87bc453349 | 296 | nn->next = n; |
ninoderkinderen | 0:8d87bc453349 | 297 | nn->prev = NULL; |
ninoderkinderen | 0:8d87bc453349 | 298 | rn->head = nn; |
ninoderkinderen | 0:8d87bc453349 | 299 | n->prev = nn; |
ninoderkinderen | 0:8d87bc453349 | 300 | } |
ninoderkinderen | 0:8d87bc453349 | 301 | else |
ninoderkinderen | 0:8d87bc453349 | 302 | { |
ninoderkinderen | 0:8d87bc453349 | 303 | /* insert in the middle */ |
ninoderkinderen | 0:8d87bc453349 | 304 | nn->next = n; |
ninoderkinderen | 0:8d87bc453349 | 305 | nn->prev = n->prev; |
ninoderkinderen | 0:8d87bc453349 | 306 | n->prev->next = nn; |
ninoderkinderen | 0:8d87bc453349 | 307 | n->prev = nn; |
ninoderkinderen | 0:8d87bc453349 | 308 | } |
ninoderkinderen | 0:8d87bc453349 | 309 | *insn = nn; |
ninoderkinderen | 0:8d87bc453349 | 310 | insert = 1; |
ninoderkinderen | 0:8d87bc453349 | 311 | } |
ninoderkinderen | 0:8d87bc453349 | 312 | else |
ninoderkinderen | 0:8d87bc453349 | 313 | { |
ninoderkinderen | 0:8d87bc453349 | 314 | /* insertion failure */ |
ninoderkinderen | 0:8d87bc453349 | 315 | insert = -1; |
ninoderkinderen | 0:8d87bc453349 | 316 | } |
ninoderkinderen | 0:8d87bc453349 | 317 | } |
ninoderkinderen | 0:8d87bc453349 | 318 | } |
ninoderkinderen | 0:8d87bc453349 | 319 | } |
ninoderkinderen | 0:8d87bc453349 | 320 | if (insert == 1) |
ninoderkinderen | 0:8d87bc453349 | 321 | { |
ninoderkinderen | 0:8d87bc453349 | 322 | rn->count += 1; |
ninoderkinderen | 0:8d87bc453349 | 323 | } |
ninoderkinderen | 0:8d87bc453349 | 324 | LWIP_ASSERT("insert != 0",insert != 0); |
ninoderkinderen | 0:8d87bc453349 | 325 | return insert; |
ninoderkinderen | 0:8d87bc453349 | 326 | } |
ninoderkinderen | 0:8d87bc453349 | 327 | |
ninoderkinderen | 0:8d87bc453349 | 328 | /** |
ninoderkinderen | 0:8d87bc453349 | 329 | * Finds node in idx list and returns deletion mark. |
ninoderkinderen | 0:8d87bc453349 | 330 | * |
ninoderkinderen | 0:8d87bc453349 | 331 | * @param rn points to the root node |
ninoderkinderen | 0:8d87bc453349 | 332 | * @param objid is the object sub identifier |
ninoderkinderen | 0:8d87bc453349 | 333 | * @param fn returns pointer to found node |
ninoderkinderen | 0:8d87bc453349 | 334 | * @return 0 if not found, 1 if deletable, |
ninoderkinderen | 0:8d87bc453349 | 335 | * 2 can't delete (2 or more children), 3 not a list_node |
ninoderkinderen | 0:8d87bc453349 | 336 | */ |
ninoderkinderen | 0:8d87bc453349 | 337 | s8_t |
ninoderkinderen | 0:8d87bc453349 | 338 | snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn) |
ninoderkinderen | 0:8d87bc453349 | 339 | { |
ninoderkinderen | 0:8d87bc453349 | 340 | s8_t fc; |
ninoderkinderen | 0:8d87bc453349 | 341 | struct mib_list_node *n; |
ninoderkinderen | 0:8d87bc453349 | 342 | |
ninoderkinderen | 0:8d87bc453349 | 343 | LWIP_ASSERT("rn != NULL",rn != NULL); |
ninoderkinderen | 0:8d87bc453349 | 344 | n = rn->head; |
ninoderkinderen | 0:8d87bc453349 | 345 | while ((n != NULL) && (n->objid != objid)) |
ninoderkinderen | 0:8d87bc453349 | 346 | { |
ninoderkinderen | 0:8d87bc453349 | 347 | n = n->next; |
ninoderkinderen | 0:8d87bc453349 | 348 | } |
ninoderkinderen | 0:8d87bc453349 | 349 | if (n == NULL) |
ninoderkinderen | 0:8d87bc453349 | 350 | { |
ninoderkinderen | 0:8d87bc453349 | 351 | fc = 0; |
ninoderkinderen | 0:8d87bc453349 | 352 | } |
ninoderkinderen | 0:8d87bc453349 | 353 | else if (n->nptr == NULL) |
ninoderkinderen | 0:8d87bc453349 | 354 | { |
ninoderkinderen | 0:8d87bc453349 | 355 | /* leaf, can delete node */ |
ninoderkinderen | 0:8d87bc453349 | 356 | fc = 1; |
ninoderkinderen | 0:8d87bc453349 | 357 | } |
ninoderkinderen | 0:8d87bc453349 | 358 | else |
ninoderkinderen | 0:8d87bc453349 | 359 | { |
ninoderkinderen | 0:8d87bc453349 | 360 | struct mib_list_rootnode *r; |
ninoderkinderen | 0:8d87bc453349 | 361 | |
ninoderkinderen | 0:8d87bc453349 | 362 | if (n->nptr->node_type == MIB_NODE_LR) |
ninoderkinderen | 0:8d87bc453349 | 363 | { |
ninoderkinderen | 0:8d87bc453349 | 364 | r = (struct mib_list_rootnode *)n->nptr; |
ninoderkinderen | 0:8d87bc453349 | 365 | if (r->count > 1) |
ninoderkinderen | 0:8d87bc453349 | 366 | { |
ninoderkinderen | 0:8d87bc453349 | 367 | /* can't delete node */ |
ninoderkinderen | 0:8d87bc453349 | 368 | fc = 2; |
ninoderkinderen | 0:8d87bc453349 | 369 | } |
ninoderkinderen | 0:8d87bc453349 | 370 | else |
ninoderkinderen | 0:8d87bc453349 | 371 | { |
ninoderkinderen | 0:8d87bc453349 | 372 | /* count <= 1, can delete node */ |
ninoderkinderen | 0:8d87bc453349 | 373 | fc = 1; |
ninoderkinderen | 0:8d87bc453349 | 374 | } |
ninoderkinderen | 0:8d87bc453349 | 375 | } |
ninoderkinderen | 0:8d87bc453349 | 376 | else |
ninoderkinderen | 0:8d87bc453349 | 377 | { |
ninoderkinderen | 0:8d87bc453349 | 378 | /* other node type */ |
ninoderkinderen | 0:8d87bc453349 | 379 | fc = 3; |
ninoderkinderen | 0:8d87bc453349 | 380 | } |
ninoderkinderen | 0:8d87bc453349 | 381 | } |
ninoderkinderen | 0:8d87bc453349 | 382 | *fn = n; |
ninoderkinderen | 0:8d87bc453349 | 383 | return fc; |
ninoderkinderen | 0:8d87bc453349 | 384 | } |
ninoderkinderen | 0:8d87bc453349 | 385 | |
ninoderkinderen | 0:8d87bc453349 | 386 | /** |
ninoderkinderen | 0:8d87bc453349 | 387 | * Removes node from idx list |
ninoderkinderen | 0:8d87bc453349 | 388 | * if it has a single child left. |
ninoderkinderen | 0:8d87bc453349 | 389 | * |
ninoderkinderen | 0:8d87bc453349 | 390 | * @param rn points to the root node |
ninoderkinderen | 0:8d87bc453349 | 391 | * @param n points to the node to delete |
ninoderkinderen | 0:8d87bc453349 | 392 | * @return the nptr to be freed by caller |
ninoderkinderen | 0:8d87bc453349 | 393 | */ |
ninoderkinderen | 0:8d87bc453349 | 394 | struct mib_list_rootnode * |
ninoderkinderen | 0:8d87bc453349 | 395 | snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n) |
ninoderkinderen | 0:8d87bc453349 | 396 | { |
ninoderkinderen | 0:8d87bc453349 | 397 | struct mib_list_rootnode *next; |
ninoderkinderen | 0:8d87bc453349 | 398 | |
ninoderkinderen | 0:8d87bc453349 | 399 | LWIP_ASSERT("rn != NULL",rn != NULL); |
ninoderkinderen | 0:8d87bc453349 | 400 | LWIP_ASSERT("n != NULL",n != NULL); |
ninoderkinderen | 0:8d87bc453349 | 401 | |
ninoderkinderen | 0:8d87bc453349 | 402 | /* caller must remove this sub-tree */ |
ninoderkinderen | 0:8d87bc453349 | 403 | next = (struct mib_list_rootnode*)(n->nptr); |
ninoderkinderen | 0:8d87bc453349 | 404 | rn->count -= 1; |
ninoderkinderen | 0:8d87bc453349 | 405 | |
ninoderkinderen | 0:8d87bc453349 | 406 | if (n == rn->head) |
ninoderkinderen | 0:8d87bc453349 | 407 | { |
ninoderkinderen | 0:8d87bc453349 | 408 | rn->head = n->next; |
ninoderkinderen | 0:8d87bc453349 | 409 | if (n->next != NULL) |
ninoderkinderen | 0:8d87bc453349 | 410 | { |
ninoderkinderen | 0:8d87bc453349 | 411 | /* not last node, new list begin */ |
ninoderkinderen | 0:8d87bc453349 | 412 | n->next->prev = NULL; |
ninoderkinderen | 0:8d87bc453349 | 413 | } |
ninoderkinderen | 0:8d87bc453349 | 414 | } |
ninoderkinderen | 0:8d87bc453349 | 415 | else if (n == rn->tail) |
ninoderkinderen | 0:8d87bc453349 | 416 | { |
ninoderkinderen | 0:8d87bc453349 | 417 | rn->tail = n->prev; |
ninoderkinderen | 0:8d87bc453349 | 418 | if (n->prev != NULL) |
ninoderkinderen | 0:8d87bc453349 | 419 | { |
ninoderkinderen | 0:8d87bc453349 | 420 | /* not last node, new list end */ |
ninoderkinderen | 0:8d87bc453349 | 421 | n->prev->next = NULL; |
ninoderkinderen | 0:8d87bc453349 | 422 | } |
ninoderkinderen | 0:8d87bc453349 | 423 | } |
ninoderkinderen | 0:8d87bc453349 | 424 | else |
ninoderkinderen | 0:8d87bc453349 | 425 | { |
ninoderkinderen | 0:8d87bc453349 | 426 | /* node must be in the middle */ |
ninoderkinderen | 0:8d87bc453349 | 427 | n->prev->next = n->next; |
ninoderkinderen | 0:8d87bc453349 | 428 | n->next->prev = n->prev; |
ninoderkinderen | 0:8d87bc453349 | 429 | } |
ninoderkinderen | 0:8d87bc453349 | 430 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("free list objid==%"S32_F"\n",n->objid)); |
ninoderkinderen | 0:8d87bc453349 | 431 | snmp_mib_ln_free(n); |
ninoderkinderen | 0:8d87bc453349 | 432 | if (rn->count == 0) |
ninoderkinderen | 0:8d87bc453349 | 433 | { |
ninoderkinderen | 0:8d87bc453349 | 434 | rn->head = NULL; |
ninoderkinderen | 0:8d87bc453349 | 435 | rn->tail = NULL; |
ninoderkinderen | 0:8d87bc453349 | 436 | } |
ninoderkinderen | 0:8d87bc453349 | 437 | return next; |
ninoderkinderen | 0:8d87bc453349 | 438 | } |
ninoderkinderen | 0:8d87bc453349 | 439 | |
ninoderkinderen | 0:8d87bc453349 | 440 | |
ninoderkinderen | 0:8d87bc453349 | 441 | |
ninoderkinderen | 0:8d87bc453349 | 442 | /** |
ninoderkinderen | 0:8d87bc453349 | 443 | * Searches tree for the supplied (scalar?) object identifier. |
ninoderkinderen | 0:8d87bc453349 | 444 | * |
ninoderkinderen | 0:8d87bc453349 | 445 | * @param node points to the root of the tree ('.internet') |
ninoderkinderen | 0:8d87bc453349 | 446 | * @param ident_len the length of the supplied object identifier |
ninoderkinderen | 0:8d87bc453349 | 447 | * @param ident points to the array of sub identifiers |
ninoderkinderen | 0:8d87bc453349 | 448 | * @param np points to the found object instance (return) |
ninoderkinderen | 0:8d87bc453349 | 449 | * @return pointer to the requested parent (!) node if success, NULL otherwise |
ninoderkinderen | 0:8d87bc453349 | 450 | */ |
ninoderkinderen | 0:8d87bc453349 | 451 | struct mib_node * |
ninoderkinderen | 0:8d87bc453349 | 452 | snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np) |
ninoderkinderen | 0:8d87bc453349 | 453 | { |
ninoderkinderen | 0:8d87bc453349 | 454 | u8_t node_type, ext_level; |
ninoderkinderen | 0:8d87bc453349 | 455 | |
ninoderkinderen | 0:8d87bc453349 | 456 | ext_level = 0; |
ninoderkinderen | 0:8d87bc453349 | 457 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("node==%p *ident==%"S32_F"\n",(void*)node,*ident)); |
ninoderkinderen | 0:8d87bc453349 | 458 | while (node != NULL) |
ninoderkinderen | 0:8d87bc453349 | 459 | { |
ninoderkinderen | 0:8d87bc453349 | 460 | node_type = node->node_type; |
ninoderkinderen | 0:8d87bc453349 | 461 | if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA)) |
ninoderkinderen | 0:8d87bc453349 | 462 | { |
ninoderkinderen | 0:8d87bc453349 | 463 | struct mib_array_node *an; |
ninoderkinderen | 0:8d87bc453349 | 464 | u16_t i; |
ninoderkinderen | 0:8d87bc453349 | 465 | |
ninoderkinderen | 0:8d87bc453349 | 466 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 467 | { |
ninoderkinderen | 0:8d87bc453349 | 468 | /* array node (internal ROM or RAM, fixed length) */ |
ninoderkinderen | 0:8d87bc453349 | 469 | an = (struct mib_array_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 470 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 471 | while ((i < an->maxlength) && (an->objid[i] != *ident)) |
ninoderkinderen | 0:8d87bc453349 | 472 | { |
ninoderkinderen | 0:8d87bc453349 | 473 | i++; |
ninoderkinderen | 0:8d87bc453349 | 474 | } |
ninoderkinderen | 0:8d87bc453349 | 475 | if (i < an->maxlength) |
ninoderkinderen | 0:8d87bc453349 | 476 | { |
ninoderkinderen | 0:8d87bc453349 | 477 | /* found it, if available proceed to child, otherwise inspect leaf */ |
ninoderkinderen | 0:8d87bc453349 | 478 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->objid[i],*ident)); |
ninoderkinderen | 0:8d87bc453349 | 479 | if (an->nptr[i] == NULL) |
ninoderkinderen | 0:8d87bc453349 | 480 | { |
ninoderkinderen | 0:8d87bc453349 | 481 | /* a scalar leaf OR table, |
ninoderkinderen | 0:8d87bc453349 | 482 | inspect remaining instance number / table index */ |
ninoderkinderen | 0:8d87bc453349 | 483 | np->ident_len = ident_len; |
ninoderkinderen | 0:8d87bc453349 | 484 | np->ident = ident; |
ninoderkinderen | 0:8d87bc453349 | 485 | return (struct mib_node*)an; |
ninoderkinderen | 0:8d87bc453349 | 486 | } |
ninoderkinderen | 0:8d87bc453349 | 487 | else |
ninoderkinderen | 0:8d87bc453349 | 488 | { |
ninoderkinderen | 0:8d87bc453349 | 489 | /* follow next child pointer */ |
ninoderkinderen | 0:8d87bc453349 | 490 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 491 | ident_len--; |
ninoderkinderen | 0:8d87bc453349 | 492 | node = an->nptr[i]; |
ninoderkinderen | 0:8d87bc453349 | 493 | } |
ninoderkinderen | 0:8d87bc453349 | 494 | } |
ninoderkinderen | 0:8d87bc453349 | 495 | else |
ninoderkinderen | 0:8d87bc453349 | 496 | { |
ninoderkinderen | 0:8d87bc453349 | 497 | /* search failed, identifier mismatch (nosuchname) */ |
ninoderkinderen | 0:8d87bc453349 | 498 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("an search failed *ident==%"S32_F"\n",*ident)); |
ninoderkinderen | 0:8d87bc453349 | 499 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 500 | } |
ninoderkinderen | 0:8d87bc453349 | 501 | } |
ninoderkinderen | 0:8d87bc453349 | 502 | else |
ninoderkinderen | 0:8d87bc453349 | 503 | { |
ninoderkinderen | 0:8d87bc453349 | 504 | /* search failed, short object identifier (nosuchname) */ |
ninoderkinderen | 0:8d87bc453349 | 505 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("an search failed, short object identifier\n")); |
ninoderkinderen | 0:8d87bc453349 | 506 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 507 | } |
ninoderkinderen | 0:8d87bc453349 | 508 | } |
ninoderkinderen | 0:8d87bc453349 | 509 | else if(node_type == MIB_NODE_LR) |
ninoderkinderen | 0:8d87bc453349 | 510 | { |
ninoderkinderen | 0:8d87bc453349 | 511 | struct mib_list_rootnode *lrn; |
ninoderkinderen | 0:8d87bc453349 | 512 | struct mib_list_node *ln; |
ninoderkinderen | 0:8d87bc453349 | 513 | |
ninoderkinderen | 0:8d87bc453349 | 514 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 515 | { |
ninoderkinderen | 0:8d87bc453349 | 516 | /* list root node (internal 'RAM', variable length) */ |
ninoderkinderen | 0:8d87bc453349 | 517 | lrn = (struct mib_list_rootnode *)node; |
ninoderkinderen | 0:8d87bc453349 | 518 | ln = lrn->head; |
ninoderkinderen | 0:8d87bc453349 | 519 | /* iterate over list, head to tail */ |
ninoderkinderen | 0:8d87bc453349 | 520 | while ((ln != NULL) && (ln->objid != *ident)) |
ninoderkinderen | 0:8d87bc453349 | 521 | { |
ninoderkinderen | 0:8d87bc453349 | 522 | ln = ln->next; |
ninoderkinderen | 0:8d87bc453349 | 523 | } |
ninoderkinderen | 0:8d87bc453349 | 524 | if (ln != NULL) |
ninoderkinderen | 0:8d87bc453349 | 525 | { |
ninoderkinderen | 0:8d87bc453349 | 526 | /* found it, proceed to child */; |
ninoderkinderen | 0:8d87bc453349 | 527 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln->objid==%"S32_F" *ident==%"S32_F"\n",ln->objid,*ident)); |
ninoderkinderen | 0:8d87bc453349 | 528 | if (ln->nptr == NULL) |
ninoderkinderen | 0:8d87bc453349 | 529 | { |
ninoderkinderen | 0:8d87bc453349 | 530 | np->ident_len = ident_len; |
ninoderkinderen | 0:8d87bc453349 | 531 | np->ident = ident; |
ninoderkinderen | 0:8d87bc453349 | 532 | return (struct mib_node*)lrn; |
ninoderkinderen | 0:8d87bc453349 | 533 | } |
ninoderkinderen | 0:8d87bc453349 | 534 | else |
ninoderkinderen | 0:8d87bc453349 | 535 | { |
ninoderkinderen | 0:8d87bc453349 | 536 | /* follow next child pointer */ |
ninoderkinderen | 0:8d87bc453349 | 537 | ident_len--; |
ninoderkinderen | 0:8d87bc453349 | 538 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 539 | node = ln->nptr; |
ninoderkinderen | 0:8d87bc453349 | 540 | } |
ninoderkinderen | 0:8d87bc453349 | 541 | } |
ninoderkinderen | 0:8d87bc453349 | 542 | else |
ninoderkinderen | 0:8d87bc453349 | 543 | { |
ninoderkinderen | 0:8d87bc453349 | 544 | /* search failed */ |
ninoderkinderen | 0:8d87bc453349 | 545 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln search failed *ident==%"S32_F"\n",*ident)); |
ninoderkinderen | 0:8d87bc453349 | 546 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 547 | } |
ninoderkinderen | 0:8d87bc453349 | 548 | } |
ninoderkinderen | 0:8d87bc453349 | 549 | else |
ninoderkinderen | 0:8d87bc453349 | 550 | { |
ninoderkinderen | 0:8d87bc453349 | 551 | /* search failed, short object identifier (nosuchname) */ |
ninoderkinderen | 0:8d87bc453349 | 552 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln search failed, short object identifier\n")); |
ninoderkinderen | 0:8d87bc453349 | 553 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 554 | } |
ninoderkinderen | 0:8d87bc453349 | 555 | } |
ninoderkinderen | 0:8d87bc453349 | 556 | else if(node_type == MIB_NODE_EX) |
ninoderkinderen | 0:8d87bc453349 | 557 | { |
ninoderkinderen | 0:8d87bc453349 | 558 | struct mib_external_node *en; |
ninoderkinderen | 0:8d87bc453349 | 559 | u16_t i, len; |
ninoderkinderen | 0:8d87bc453349 | 560 | |
ninoderkinderen | 0:8d87bc453349 | 561 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 562 | { |
ninoderkinderen | 0:8d87bc453349 | 563 | /* external node (addressing and access via functions) */ |
ninoderkinderen | 0:8d87bc453349 | 564 | en = (struct mib_external_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 565 | |
ninoderkinderen | 0:8d87bc453349 | 566 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 567 | len = en->level_length(en->addr_inf,ext_level); |
ninoderkinderen | 0:8d87bc453349 | 568 | while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) != 0)) |
ninoderkinderen | 0:8d87bc453349 | 569 | { |
ninoderkinderen | 0:8d87bc453349 | 570 | i++; |
ninoderkinderen | 0:8d87bc453349 | 571 | } |
ninoderkinderen | 0:8d87bc453349 | 572 | if (i < len) |
ninoderkinderen | 0:8d87bc453349 | 573 | { |
ninoderkinderen | 0:8d87bc453349 | 574 | s32_t debug_id; |
ninoderkinderen | 0:8d87bc453349 | 575 | |
ninoderkinderen | 0:8d87bc453349 | 576 | en->get_objid(en->addr_inf,ext_level,i,&debug_id); |
ninoderkinderen | 0:8d87bc453349 | 577 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("en->objid==%"S32_F" *ident==%"S32_F"\n",debug_id,*ident)); |
ninoderkinderen | 0:8d87bc453349 | 578 | if ((ext_level + 1) == en->tree_levels) |
ninoderkinderen | 0:8d87bc453349 | 579 | { |
ninoderkinderen | 0:8d87bc453349 | 580 | np->ident_len = ident_len; |
ninoderkinderen | 0:8d87bc453349 | 581 | np->ident = ident; |
ninoderkinderen | 0:8d87bc453349 | 582 | return (struct mib_node*)en; |
ninoderkinderen | 0:8d87bc453349 | 583 | } |
ninoderkinderen | 0:8d87bc453349 | 584 | else |
ninoderkinderen | 0:8d87bc453349 | 585 | { |
ninoderkinderen | 0:8d87bc453349 | 586 | /* found it, proceed to child */ |
ninoderkinderen | 0:8d87bc453349 | 587 | ident_len--; |
ninoderkinderen | 0:8d87bc453349 | 588 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 589 | ext_level++; |
ninoderkinderen | 0:8d87bc453349 | 590 | } |
ninoderkinderen | 0:8d87bc453349 | 591 | } |
ninoderkinderen | 0:8d87bc453349 | 592 | else |
ninoderkinderen | 0:8d87bc453349 | 593 | { |
ninoderkinderen | 0:8d87bc453349 | 594 | /* search failed */ |
ninoderkinderen | 0:8d87bc453349 | 595 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("en search failed *ident==%"S32_F"\n",*ident)); |
ninoderkinderen | 0:8d87bc453349 | 596 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 597 | } |
ninoderkinderen | 0:8d87bc453349 | 598 | } |
ninoderkinderen | 0:8d87bc453349 | 599 | else |
ninoderkinderen | 0:8d87bc453349 | 600 | { |
ninoderkinderen | 0:8d87bc453349 | 601 | /* search failed, short object identifier (nosuchname) */ |
ninoderkinderen | 0:8d87bc453349 | 602 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("en search failed, short object identifier\n")); |
ninoderkinderen | 0:8d87bc453349 | 603 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 604 | } |
ninoderkinderen | 0:8d87bc453349 | 605 | } |
ninoderkinderen | 0:8d87bc453349 | 606 | else if (node_type == MIB_NODE_SC) |
ninoderkinderen | 0:8d87bc453349 | 607 | { |
ninoderkinderen | 0:8d87bc453349 | 608 | mib_scalar_node *sn; |
ninoderkinderen | 0:8d87bc453349 | 609 | |
ninoderkinderen | 0:8d87bc453349 | 610 | sn = (mib_scalar_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 611 | if ((ident_len == 1) && (*ident == 0)) |
ninoderkinderen | 0:8d87bc453349 | 612 | { |
ninoderkinderen | 0:8d87bc453349 | 613 | np->ident_len = ident_len; |
ninoderkinderen | 0:8d87bc453349 | 614 | np->ident = ident; |
ninoderkinderen | 0:8d87bc453349 | 615 | return (struct mib_node*)sn; |
ninoderkinderen | 0:8d87bc453349 | 616 | } |
ninoderkinderen | 0:8d87bc453349 | 617 | else |
ninoderkinderen | 0:8d87bc453349 | 618 | { |
ninoderkinderen | 0:8d87bc453349 | 619 | /* search failed, short object identifier (nosuchname) */ |
ninoderkinderen | 0:8d87bc453349 | 620 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, invalid object identifier length\n")); |
ninoderkinderen | 0:8d87bc453349 | 621 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 622 | } |
ninoderkinderen | 0:8d87bc453349 | 623 | } |
ninoderkinderen | 0:8d87bc453349 | 624 | else |
ninoderkinderen | 0:8d87bc453349 | 625 | { |
ninoderkinderen | 0:8d87bc453349 | 626 | /* unknown node_type */ |
ninoderkinderen | 0:8d87bc453349 | 627 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed node_type %"U16_F" unkown\n",(u16_t)node_type)); |
ninoderkinderen | 0:8d87bc453349 | 628 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 629 | } |
ninoderkinderen | 0:8d87bc453349 | 630 | } |
ninoderkinderen | 0:8d87bc453349 | 631 | /* done, found nothing */ |
ninoderkinderen | 0:8d87bc453349 | 632 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed node==%p\n",(void*)node)); |
ninoderkinderen | 0:8d87bc453349 | 633 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 634 | } |
ninoderkinderen | 0:8d87bc453349 | 635 | |
ninoderkinderen | 0:8d87bc453349 | 636 | /** |
ninoderkinderen | 0:8d87bc453349 | 637 | * Test table for presence of at least one table entry. |
ninoderkinderen | 0:8d87bc453349 | 638 | */ |
ninoderkinderen | 0:8d87bc453349 | 639 | static u8_t |
ninoderkinderen | 0:8d87bc453349 | 640 | empty_table(struct mib_node *node) |
ninoderkinderen | 0:8d87bc453349 | 641 | { |
ninoderkinderen | 0:8d87bc453349 | 642 | u8_t node_type; |
ninoderkinderen | 0:8d87bc453349 | 643 | u8_t empty = 0; |
ninoderkinderen | 0:8d87bc453349 | 644 | |
ninoderkinderen | 0:8d87bc453349 | 645 | if (node != NULL) |
ninoderkinderen | 0:8d87bc453349 | 646 | { |
ninoderkinderen | 0:8d87bc453349 | 647 | node_type = node->node_type; |
ninoderkinderen | 0:8d87bc453349 | 648 | if (node_type == MIB_NODE_LR) |
ninoderkinderen | 0:8d87bc453349 | 649 | { |
ninoderkinderen | 0:8d87bc453349 | 650 | struct mib_list_rootnode *lrn; |
ninoderkinderen | 0:8d87bc453349 | 651 | lrn = (struct mib_list_rootnode *)node; |
ninoderkinderen | 0:8d87bc453349 | 652 | if ((lrn->count == 0) || (lrn->head == NULL)) |
ninoderkinderen | 0:8d87bc453349 | 653 | { |
ninoderkinderen | 0:8d87bc453349 | 654 | empty = 1; |
ninoderkinderen | 0:8d87bc453349 | 655 | } |
ninoderkinderen | 0:8d87bc453349 | 656 | } |
ninoderkinderen | 0:8d87bc453349 | 657 | else if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA)) |
ninoderkinderen | 0:8d87bc453349 | 658 | { |
ninoderkinderen | 0:8d87bc453349 | 659 | struct mib_array_node *an; |
ninoderkinderen | 0:8d87bc453349 | 660 | an = (struct mib_array_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 661 | if ((an->maxlength == 0) || (an->nptr == NULL)) |
ninoderkinderen | 0:8d87bc453349 | 662 | { |
ninoderkinderen | 0:8d87bc453349 | 663 | empty = 1; |
ninoderkinderen | 0:8d87bc453349 | 664 | } |
ninoderkinderen | 0:8d87bc453349 | 665 | } |
ninoderkinderen | 0:8d87bc453349 | 666 | else if (node_type == MIB_NODE_EX) |
ninoderkinderen | 0:8d87bc453349 | 667 | { |
ninoderkinderen | 0:8d87bc453349 | 668 | struct mib_external_node *en; |
ninoderkinderen | 0:8d87bc453349 | 669 | en = (struct mib_external_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 670 | if (en->tree_levels == 0) |
ninoderkinderen | 0:8d87bc453349 | 671 | { |
ninoderkinderen | 0:8d87bc453349 | 672 | empty = 1; |
ninoderkinderen | 0:8d87bc453349 | 673 | } |
ninoderkinderen | 0:8d87bc453349 | 674 | } |
ninoderkinderen | 0:8d87bc453349 | 675 | } |
ninoderkinderen | 0:8d87bc453349 | 676 | return empty; |
ninoderkinderen | 0:8d87bc453349 | 677 | } |
ninoderkinderen | 0:8d87bc453349 | 678 | |
ninoderkinderen | 0:8d87bc453349 | 679 | /** |
ninoderkinderen | 0:8d87bc453349 | 680 | * Tree expansion. |
ninoderkinderen | 0:8d87bc453349 | 681 | */ |
ninoderkinderen | 0:8d87bc453349 | 682 | struct mib_node * |
ninoderkinderen | 0:8d87bc453349 | 683 | snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret) |
ninoderkinderen | 0:8d87bc453349 | 684 | { |
ninoderkinderen | 0:8d87bc453349 | 685 | u8_t node_type, ext_level, climb_tree; |
ninoderkinderen | 0:8d87bc453349 | 686 | |
ninoderkinderen | 0:8d87bc453349 | 687 | ext_level = 0; |
ninoderkinderen | 0:8d87bc453349 | 688 | /* reset node stack */ |
ninoderkinderen | 0:8d87bc453349 | 689 | node_stack_cnt = 0; |
ninoderkinderen | 0:8d87bc453349 | 690 | while (node != NULL) |
ninoderkinderen | 0:8d87bc453349 | 691 | { |
ninoderkinderen | 0:8d87bc453349 | 692 | climb_tree = 0; |
ninoderkinderen | 0:8d87bc453349 | 693 | node_type = node->node_type; |
ninoderkinderen | 0:8d87bc453349 | 694 | if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA)) |
ninoderkinderen | 0:8d87bc453349 | 695 | { |
ninoderkinderen | 0:8d87bc453349 | 696 | struct mib_array_node *an; |
ninoderkinderen | 0:8d87bc453349 | 697 | u16_t i; |
ninoderkinderen | 0:8d87bc453349 | 698 | |
ninoderkinderen | 0:8d87bc453349 | 699 | /* array node (internal ROM or RAM, fixed length) */ |
ninoderkinderen | 0:8d87bc453349 | 700 | an = (struct mib_array_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 701 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 702 | { |
ninoderkinderen | 0:8d87bc453349 | 703 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 704 | while ((i < an->maxlength) && (an->objid[i] < *ident)) |
ninoderkinderen | 0:8d87bc453349 | 705 | { |
ninoderkinderen | 0:8d87bc453349 | 706 | i++; |
ninoderkinderen | 0:8d87bc453349 | 707 | } |
ninoderkinderen | 0:8d87bc453349 | 708 | if (i < an->maxlength) |
ninoderkinderen | 0:8d87bc453349 | 709 | { |
ninoderkinderen | 0:8d87bc453349 | 710 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,an->objid[i],*ident)); |
ninoderkinderen | 0:8d87bc453349 | 711 | /* add identifier to oidret */ |
ninoderkinderen | 0:8d87bc453349 | 712 | oidret->id[oidret->len] = an->objid[i]; |
ninoderkinderen | 0:8d87bc453349 | 713 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 714 | |
ninoderkinderen | 0:8d87bc453349 | 715 | if (an->nptr[i] == NULL) |
ninoderkinderen | 0:8d87bc453349 | 716 | { |
ninoderkinderen | 0:8d87bc453349 | 717 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("leaf node\n")); |
ninoderkinderen | 0:8d87bc453349 | 718 | /* leaf node (e.g. in a fixed size table) */ |
ninoderkinderen | 0:8d87bc453349 | 719 | if (an->objid[i] > *ident) |
ninoderkinderen | 0:8d87bc453349 | 720 | { |
ninoderkinderen | 0:8d87bc453349 | 721 | return (struct mib_node*)an; |
ninoderkinderen | 0:8d87bc453349 | 722 | } |
ninoderkinderen | 0:8d87bc453349 | 723 | else if ((i + 1) < an->maxlength) |
ninoderkinderen | 0:8d87bc453349 | 724 | { |
ninoderkinderen | 0:8d87bc453349 | 725 | /* an->objid[i] == *ident */ |
ninoderkinderen | 0:8d87bc453349 | 726 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 727 | oidret->id[oidret->len] = an->objid[i + 1]; |
ninoderkinderen | 0:8d87bc453349 | 728 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 729 | return (struct mib_node*)an; |
ninoderkinderen | 0:8d87bc453349 | 730 | } |
ninoderkinderen | 0:8d87bc453349 | 731 | else |
ninoderkinderen | 0:8d87bc453349 | 732 | { |
ninoderkinderen | 0:8d87bc453349 | 733 | /* (i + 1) == an->maxlength */ |
ninoderkinderen | 0:8d87bc453349 | 734 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 735 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 736 | } |
ninoderkinderen | 0:8d87bc453349 | 737 | } |
ninoderkinderen | 0:8d87bc453349 | 738 | else |
ninoderkinderen | 0:8d87bc453349 | 739 | { |
ninoderkinderen | 0:8d87bc453349 | 740 | u8_t j; |
ninoderkinderen | 0:8d87bc453349 | 741 | struct nse cur_node; |
ninoderkinderen | 0:8d87bc453349 | 742 | |
ninoderkinderen | 0:8d87bc453349 | 743 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("non-leaf node\n")); |
ninoderkinderen | 0:8d87bc453349 | 744 | /* non-leaf, store right child ptr and id */ |
ninoderkinderen | 0:8d87bc453349 | 745 | LWIP_ASSERT("i < 0xff", i < 0xff); |
ninoderkinderen | 0:8d87bc453349 | 746 | j = (u8_t)i + 1; |
ninoderkinderen | 0:8d87bc453349 | 747 | while ((j < an->maxlength) && (empty_table(an->nptr[j]))) |
ninoderkinderen | 0:8d87bc453349 | 748 | { |
ninoderkinderen | 0:8d87bc453349 | 749 | j++; |
ninoderkinderen | 0:8d87bc453349 | 750 | } |
ninoderkinderen | 0:8d87bc453349 | 751 | if (j < an->maxlength) |
ninoderkinderen | 0:8d87bc453349 | 752 | { |
ninoderkinderen | 0:8d87bc453349 | 753 | cur_node.r_ptr = an->nptr[j]; |
ninoderkinderen | 0:8d87bc453349 | 754 | cur_node.r_id = an->objid[j]; |
ninoderkinderen | 0:8d87bc453349 | 755 | cur_node.r_nl = 0; |
ninoderkinderen | 0:8d87bc453349 | 756 | } |
ninoderkinderen | 0:8d87bc453349 | 757 | else |
ninoderkinderen | 0:8d87bc453349 | 758 | { |
ninoderkinderen | 0:8d87bc453349 | 759 | cur_node.r_ptr = NULL; |
ninoderkinderen | 0:8d87bc453349 | 760 | } |
ninoderkinderen | 0:8d87bc453349 | 761 | push_node(&cur_node); |
ninoderkinderen | 0:8d87bc453349 | 762 | if (an->objid[i] == *ident) |
ninoderkinderen | 0:8d87bc453349 | 763 | { |
ninoderkinderen | 0:8d87bc453349 | 764 | ident_len--; |
ninoderkinderen | 0:8d87bc453349 | 765 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 766 | } |
ninoderkinderen | 0:8d87bc453349 | 767 | else |
ninoderkinderen | 0:8d87bc453349 | 768 | { |
ninoderkinderen | 0:8d87bc453349 | 769 | /* an->objid[i] < *ident */ |
ninoderkinderen | 0:8d87bc453349 | 770 | ident_len = 0; |
ninoderkinderen | 0:8d87bc453349 | 771 | } |
ninoderkinderen | 0:8d87bc453349 | 772 | /* follow next child pointer */ |
ninoderkinderen | 0:8d87bc453349 | 773 | node = an->nptr[i]; |
ninoderkinderen | 0:8d87bc453349 | 774 | } |
ninoderkinderen | 0:8d87bc453349 | 775 | } |
ninoderkinderen | 0:8d87bc453349 | 776 | else |
ninoderkinderen | 0:8d87bc453349 | 777 | { |
ninoderkinderen | 0:8d87bc453349 | 778 | /* i == an->maxlength */ |
ninoderkinderen | 0:8d87bc453349 | 779 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 780 | } |
ninoderkinderen | 0:8d87bc453349 | 781 | } |
ninoderkinderen | 0:8d87bc453349 | 782 | else |
ninoderkinderen | 0:8d87bc453349 | 783 | { |
ninoderkinderen | 0:8d87bc453349 | 784 | u8_t j; |
ninoderkinderen | 0:8d87bc453349 | 785 | /* ident_len == 0, complete with leftmost '.thing' */ |
ninoderkinderen | 0:8d87bc453349 | 786 | j = 0; |
ninoderkinderen | 0:8d87bc453349 | 787 | while ((j < an->maxlength) && empty_table(an->nptr[j])) |
ninoderkinderen | 0:8d87bc453349 | 788 | { |
ninoderkinderen | 0:8d87bc453349 | 789 | j++; |
ninoderkinderen | 0:8d87bc453349 | 790 | } |
ninoderkinderen | 0:8d87bc453349 | 791 | if (j < an->maxlength) |
ninoderkinderen | 0:8d87bc453349 | 792 | { |
ninoderkinderen | 0:8d87bc453349 | 793 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("left an->objid[j]==%"S32_F"\n",an->objid[j])); |
ninoderkinderen | 0:8d87bc453349 | 794 | oidret->id[oidret->len] = an->objid[j]; |
ninoderkinderen | 0:8d87bc453349 | 795 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 796 | if (an->nptr[j] == NULL) |
ninoderkinderen | 0:8d87bc453349 | 797 | { |
ninoderkinderen | 0:8d87bc453349 | 798 | /* leaf node */ |
ninoderkinderen | 0:8d87bc453349 | 799 | return (struct mib_node*)an; |
ninoderkinderen | 0:8d87bc453349 | 800 | } |
ninoderkinderen | 0:8d87bc453349 | 801 | else |
ninoderkinderen | 0:8d87bc453349 | 802 | { |
ninoderkinderen | 0:8d87bc453349 | 803 | /* no leaf, continue */ |
ninoderkinderen | 0:8d87bc453349 | 804 | node = an->nptr[j]; |
ninoderkinderen | 0:8d87bc453349 | 805 | } |
ninoderkinderen | 0:8d87bc453349 | 806 | } |
ninoderkinderen | 0:8d87bc453349 | 807 | else |
ninoderkinderen | 0:8d87bc453349 | 808 | { |
ninoderkinderen | 0:8d87bc453349 | 809 | /* j == an->maxlength */ |
ninoderkinderen | 0:8d87bc453349 | 810 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 811 | } |
ninoderkinderen | 0:8d87bc453349 | 812 | } |
ninoderkinderen | 0:8d87bc453349 | 813 | } |
ninoderkinderen | 0:8d87bc453349 | 814 | else if(node_type == MIB_NODE_LR) |
ninoderkinderen | 0:8d87bc453349 | 815 | { |
ninoderkinderen | 0:8d87bc453349 | 816 | struct mib_list_rootnode *lrn; |
ninoderkinderen | 0:8d87bc453349 | 817 | struct mib_list_node *ln; |
ninoderkinderen | 0:8d87bc453349 | 818 | |
ninoderkinderen | 0:8d87bc453349 | 819 | /* list root node (internal 'RAM', variable length) */ |
ninoderkinderen | 0:8d87bc453349 | 820 | lrn = (struct mib_list_rootnode *)node; |
ninoderkinderen | 0:8d87bc453349 | 821 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 822 | { |
ninoderkinderen | 0:8d87bc453349 | 823 | ln = lrn->head; |
ninoderkinderen | 0:8d87bc453349 | 824 | /* iterate over list, head to tail */ |
ninoderkinderen | 0:8d87bc453349 | 825 | while ((ln != NULL) && (ln->objid < *ident)) |
ninoderkinderen | 0:8d87bc453349 | 826 | { |
ninoderkinderen | 0:8d87bc453349 | 827 | ln = ln->next; |
ninoderkinderen | 0:8d87bc453349 | 828 | } |
ninoderkinderen | 0:8d87bc453349 | 829 | if (ln != NULL) |
ninoderkinderen | 0:8d87bc453349 | 830 | { |
ninoderkinderen | 0:8d87bc453349 | 831 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln->objid==%"S32_F" *ident==%"S32_F"\n",ln->objid,*ident)); |
ninoderkinderen | 0:8d87bc453349 | 832 | oidret->id[oidret->len] = ln->objid; |
ninoderkinderen | 0:8d87bc453349 | 833 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 834 | if (ln->nptr == NULL) |
ninoderkinderen | 0:8d87bc453349 | 835 | { |
ninoderkinderen | 0:8d87bc453349 | 836 | /* leaf node */ |
ninoderkinderen | 0:8d87bc453349 | 837 | if (ln->objid > *ident) |
ninoderkinderen | 0:8d87bc453349 | 838 | { |
ninoderkinderen | 0:8d87bc453349 | 839 | return (struct mib_node*)lrn; |
ninoderkinderen | 0:8d87bc453349 | 840 | } |
ninoderkinderen | 0:8d87bc453349 | 841 | else if (ln->next != NULL) |
ninoderkinderen | 0:8d87bc453349 | 842 | { |
ninoderkinderen | 0:8d87bc453349 | 843 | /* ln->objid == *ident */ |
ninoderkinderen | 0:8d87bc453349 | 844 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 845 | oidret->id[oidret->len] = ln->next->objid; |
ninoderkinderen | 0:8d87bc453349 | 846 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 847 | return (struct mib_node*)lrn; |
ninoderkinderen | 0:8d87bc453349 | 848 | } |
ninoderkinderen | 0:8d87bc453349 | 849 | else |
ninoderkinderen | 0:8d87bc453349 | 850 | { |
ninoderkinderen | 0:8d87bc453349 | 851 | /* ln->next == NULL */ |
ninoderkinderen | 0:8d87bc453349 | 852 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 853 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 854 | } |
ninoderkinderen | 0:8d87bc453349 | 855 | } |
ninoderkinderen | 0:8d87bc453349 | 856 | else |
ninoderkinderen | 0:8d87bc453349 | 857 | { |
ninoderkinderen | 0:8d87bc453349 | 858 | struct mib_list_node *jn; |
ninoderkinderen | 0:8d87bc453349 | 859 | struct nse cur_node; |
ninoderkinderen | 0:8d87bc453349 | 860 | |
ninoderkinderen | 0:8d87bc453349 | 861 | /* non-leaf, store right child ptr and id */ |
ninoderkinderen | 0:8d87bc453349 | 862 | jn = ln->next; |
ninoderkinderen | 0:8d87bc453349 | 863 | while ((jn != NULL) && empty_table(jn->nptr)) |
ninoderkinderen | 0:8d87bc453349 | 864 | { |
ninoderkinderen | 0:8d87bc453349 | 865 | jn = jn->next; |
ninoderkinderen | 0:8d87bc453349 | 866 | } |
ninoderkinderen | 0:8d87bc453349 | 867 | if (jn != NULL) |
ninoderkinderen | 0:8d87bc453349 | 868 | { |
ninoderkinderen | 0:8d87bc453349 | 869 | cur_node.r_ptr = jn->nptr; |
ninoderkinderen | 0:8d87bc453349 | 870 | cur_node.r_id = jn->objid; |
ninoderkinderen | 0:8d87bc453349 | 871 | cur_node.r_nl = 0; |
ninoderkinderen | 0:8d87bc453349 | 872 | } |
ninoderkinderen | 0:8d87bc453349 | 873 | else |
ninoderkinderen | 0:8d87bc453349 | 874 | { |
ninoderkinderen | 0:8d87bc453349 | 875 | cur_node.r_ptr = NULL; |
ninoderkinderen | 0:8d87bc453349 | 876 | } |
ninoderkinderen | 0:8d87bc453349 | 877 | push_node(&cur_node); |
ninoderkinderen | 0:8d87bc453349 | 878 | if (ln->objid == *ident) |
ninoderkinderen | 0:8d87bc453349 | 879 | { |
ninoderkinderen | 0:8d87bc453349 | 880 | ident_len--; |
ninoderkinderen | 0:8d87bc453349 | 881 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 882 | } |
ninoderkinderen | 0:8d87bc453349 | 883 | else |
ninoderkinderen | 0:8d87bc453349 | 884 | { |
ninoderkinderen | 0:8d87bc453349 | 885 | /* ln->objid < *ident */ |
ninoderkinderen | 0:8d87bc453349 | 886 | ident_len = 0; |
ninoderkinderen | 0:8d87bc453349 | 887 | } |
ninoderkinderen | 0:8d87bc453349 | 888 | /* follow next child pointer */ |
ninoderkinderen | 0:8d87bc453349 | 889 | node = ln->nptr; |
ninoderkinderen | 0:8d87bc453349 | 890 | } |
ninoderkinderen | 0:8d87bc453349 | 891 | |
ninoderkinderen | 0:8d87bc453349 | 892 | } |
ninoderkinderen | 0:8d87bc453349 | 893 | else |
ninoderkinderen | 0:8d87bc453349 | 894 | { |
ninoderkinderen | 0:8d87bc453349 | 895 | /* ln == NULL */ |
ninoderkinderen | 0:8d87bc453349 | 896 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 897 | } |
ninoderkinderen | 0:8d87bc453349 | 898 | } |
ninoderkinderen | 0:8d87bc453349 | 899 | else |
ninoderkinderen | 0:8d87bc453349 | 900 | { |
ninoderkinderen | 0:8d87bc453349 | 901 | struct mib_list_node *jn; |
ninoderkinderen | 0:8d87bc453349 | 902 | /* ident_len == 0, complete with leftmost '.thing' */ |
ninoderkinderen | 0:8d87bc453349 | 903 | jn = lrn->head; |
ninoderkinderen | 0:8d87bc453349 | 904 | while ((jn != NULL) && empty_table(jn->nptr)) |
ninoderkinderen | 0:8d87bc453349 | 905 | { |
ninoderkinderen | 0:8d87bc453349 | 906 | jn = jn->next; |
ninoderkinderen | 0:8d87bc453349 | 907 | } |
ninoderkinderen | 0:8d87bc453349 | 908 | if (jn != NULL) |
ninoderkinderen | 0:8d87bc453349 | 909 | { |
ninoderkinderen | 0:8d87bc453349 | 910 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("left jn->objid==%"S32_F"\n",jn->objid)); |
ninoderkinderen | 0:8d87bc453349 | 911 | oidret->id[oidret->len] = jn->objid; |
ninoderkinderen | 0:8d87bc453349 | 912 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 913 | if (jn->nptr == NULL) |
ninoderkinderen | 0:8d87bc453349 | 914 | { |
ninoderkinderen | 0:8d87bc453349 | 915 | /* leaf node */ |
ninoderkinderen | 0:8d87bc453349 | 916 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("jn->nptr == NULL\n")); |
ninoderkinderen | 0:8d87bc453349 | 917 | return (struct mib_node*)lrn; |
ninoderkinderen | 0:8d87bc453349 | 918 | } |
ninoderkinderen | 0:8d87bc453349 | 919 | else |
ninoderkinderen | 0:8d87bc453349 | 920 | { |
ninoderkinderen | 0:8d87bc453349 | 921 | /* no leaf, continue */ |
ninoderkinderen | 0:8d87bc453349 | 922 | node = jn->nptr; |
ninoderkinderen | 0:8d87bc453349 | 923 | } |
ninoderkinderen | 0:8d87bc453349 | 924 | } |
ninoderkinderen | 0:8d87bc453349 | 925 | else |
ninoderkinderen | 0:8d87bc453349 | 926 | { |
ninoderkinderen | 0:8d87bc453349 | 927 | /* jn == NULL */ |
ninoderkinderen | 0:8d87bc453349 | 928 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 929 | } |
ninoderkinderen | 0:8d87bc453349 | 930 | } |
ninoderkinderen | 0:8d87bc453349 | 931 | } |
ninoderkinderen | 0:8d87bc453349 | 932 | else if(node_type == MIB_NODE_EX) |
ninoderkinderen | 0:8d87bc453349 | 933 | { |
ninoderkinderen | 0:8d87bc453349 | 934 | struct mib_external_node *en; |
ninoderkinderen | 0:8d87bc453349 | 935 | s32_t ex_id; |
ninoderkinderen | 0:8d87bc453349 | 936 | |
ninoderkinderen | 0:8d87bc453349 | 937 | /* external node (addressing and access via functions) */ |
ninoderkinderen | 0:8d87bc453349 | 938 | en = (struct mib_external_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 939 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 940 | { |
ninoderkinderen | 0:8d87bc453349 | 941 | u16_t i, len; |
ninoderkinderen | 0:8d87bc453349 | 942 | |
ninoderkinderen | 0:8d87bc453349 | 943 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 944 | len = en->level_length(en->addr_inf,ext_level); |
ninoderkinderen | 0:8d87bc453349 | 945 | while ((i < len) && (en->ident_cmp(en->addr_inf,ext_level,i,*ident) < 0)) |
ninoderkinderen | 0:8d87bc453349 | 946 | { |
ninoderkinderen | 0:8d87bc453349 | 947 | i++; |
ninoderkinderen | 0:8d87bc453349 | 948 | } |
ninoderkinderen | 0:8d87bc453349 | 949 | if (i < len) |
ninoderkinderen | 0:8d87bc453349 | 950 | { |
ninoderkinderen | 0:8d87bc453349 | 951 | /* add identifier to oidret */ |
ninoderkinderen | 0:8d87bc453349 | 952 | en->get_objid(en->addr_inf,ext_level,i,&ex_id); |
ninoderkinderen | 0:8d87bc453349 | 953 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("en->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F"\n",i,ex_id,*ident)); |
ninoderkinderen | 0:8d87bc453349 | 954 | oidret->id[oidret->len] = ex_id; |
ninoderkinderen | 0:8d87bc453349 | 955 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 956 | |
ninoderkinderen | 0:8d87bc453349 | 957 | if ((ext_level + 1) == en->tree_levels) |
ninoderkinderen | 0:8d87bc453349 | 958 | { |
ninoderkinderen | 0:8d87bc453349 | 959 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("leaf node\n")); |
ninoderkinderen | 0:8d87bc453349 | 960 | /* leaf node */ |
ninoderkinderen | 0:8d87bc453349 | 961 | if (ex_id > *ident) |
ninoderkinderen | 0:8d87bc453349 | 962 | { |
ninoderkinderen | 0:8d87bc453349 | 963 | return (struct mib_node*)en; |
ninoderkinderen | 0:8d87bc453349 | 964 | } |
ninoderkinderen | 0:8d87bc453349 | 965 | else if ((i + 1) < len) |
ninoderkinderen | 0:8d87bc453349 | 966 | { |
ninoderkinderen | 0:8d87bc453349 | 967 | /* ex_id == *ident */ |
ninoderkinderen | 0:8d87bc453349 | 968 | en->get_objid(en->addr_inf,ext_level,i + 1,&ex_id); |
ninoderkinderen | 0:8d87bc453349 | 969 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 970 | oidret->id[oidret->len] = ex_id; |
ninoderkinderen | 0:8d87bc453349 | 971 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 972 | return (struct mib_node*)en; |
ninoderkinderen | 0:8d87bc453349 | 973 | } |
ninoderkinderen | 0:8d87bc453349 | 974 | else |
ninoderkinderen | 0:8d87bc453349 | 975 | { |
ninoderkinderen | 0:8d87bc453349 | 976 | /* (i + 1) == len */ |
ninoderkinderen | 0:8d87bc453349 | 977 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 978 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 979 | } |
ninoderkinderen | 0:8d87bc453349 | 980 | } |
ninoderkinderen | 0:8d87bc453349 | 981 | else |
ninoderkinderen | 0:8d87bc453349 | 982 | { |
ninoderkinderen | 0:8d87bc453349 | 983 | u8_t j; |
ninoderkinderen | 0:8d87bc453349 | 984 | struct nse cur_node; |
ninoderkinderen | 0:8d87bc453349 | 985 | |
ninoderkinderen | 0:8d87bc453349 | 986 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("non-leaf node\n")); |
ninoderkinderen | 0:8d87bc453349 | 987 | /* non-leaf, store right child ptr and id */ |
ninoderkinderen | 0:8d87bc453349 | 988 | LWIP_ASSERT("i < 0xff", i < 0xff); |
ninoderkinderen | 0:8d87bc453349 | 989 | j = (u8_t)i + 1; |
ninoderkinderen | 0:8d87bc453349 | 990 | if (j < len) |
ninoderkinderen | 0:8d87bc453349 | 991 | { |
ninoderkinderen | 0:8d87bc453349 | 992 | /* right node is the current external node */ |
ninoderkinderen | 0:8d87bc453349 | 993 | cur_node.r_ptr = node; |
ninoderkinderen | 0:8d87bc453349 | 994 | en->get_objid(en->addr_inf,ext_level,j,&cur_node.r_id); |
ninoderkinderen | 0:8d87bc453349 | 995 | cur_node.r_nl = ext_level + 1; |
ninoderkinderen | 0:8d87bc453349 | 996 | } |
ninoderkinderen | 0:8d87bc453349 | 997 | else |
ninoderkinderen | 0:8d87bc453349 | 998 | { |
ninoderkinderen | 0:8d87bc453349 | 999 | cur_node.r_ptr = NULL; |
ninoderkinderen | 0:8d87bc453349 | 1000 | } |
ninoderkinderen | 0:8d87bc453349 | 1001 | push_node(&cur_node); |
ninoderkinderen | 0:8d87bc453349 | 1002 | if (en->ident_cmp(en->addr_inf,ext_level,i,*ident) == 0) |
ninoderkinderen | 0:8d87bc453349 | 1003 | { |
ninoderkinderen | 0:8d87bc453349 | 1004 | ident_len--; |
ninoderkinderen | 0:8d87bc453349 | 1005 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 1006 | } |
ninoderkinderen | 0:8d87bc453349 | 1007 | else |
ninoderkinderen | 0:8d87bc453349 | 1008 | { |
ninoderkinderen | 0:8d87bc453349 | 1009 | /* external id < *ident */ |
ninoderkinderen | 0:8d87bc453349 | 1010 | ident_len = 0; |
ninoderkinderen | 0:8d87bc453349 | 1011 | } |
ninoderkinderen | 0:8d87bc453349 | 1012 | /* proceed to child */ |
ninoderkinderen | 0:8d87bc453349 | 1013 | ext_level++; |
ninoderkinderen | 0:8d87bc453349 | 1014 | } |
ninoderkinderen | 0:8d87bc453349 | 1015 | } |
ninoderkinderen | 0:8d87bc453349 | 1016 | else |
ninoderkinderen | 0:8d87bc453349 | 1017 | { |
ninoderkinderen | 0:8d87bc453349 | 1018 | /* i == len (en->level_len()) */ |
ninoderkinderen | 0:8d87bc453349 | 1019 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 1020 | } |
ninoderkinderen | 0:8d87bc453349 | 1021 | } |
ninoderkinderen | 0:8d87bc453349 | 1022 | else |
ninoderkinderen | 0:8d87bc453349 | 1023 | { |
ninoderkinderen | 0:8d87bc453349 | 1024 | /* ident_len == 0, complete with leftmost '.thing' */ |
ninoderkinderen | 0:8d87bc453349 | 1025 | en->get_objid(en->addr_inf,ext_level,0,&ex_id); |
ninoderkinderen | 0:8d87bc453349 | 1026 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("left en->objid==%"S32_F"\n",ex_id)); |
ninoderkinderen | 0:8d87bc453349 | 1027 | oidret->id[oidret->len] = ex_id; |
ninoderkinderen | 0:8d87bc453349 | 1028 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 1029 | if ((ext_level + 1) == en->tree_levels) |
ninoderkinderen | 0:8d87bc453349 | 1030 | { |
ninoderkinderen | 0:8d87bc453349 | 1031 | /* leaf node */ |
ninoderkinderen | 0:8d87bc453349 | 1032 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("(ext_level + 1) == en->tree_levels\n")); |
ninoderkinderen | 0:8d87bc453349 | 1033 | return (struct mib_node*)en; |
ninoderkinderen | 0:8d87bc453349 | 1034 | } |
ninoderkinderen | 0:8d87bc453349 | 1035 | else |
ninoderkinderen | 0:8d87bc453349 | 1036 | { |
ninoderkinderen | 0:8d87bc453349 | 1037 | /* no leaf, proceed to child */ |
ninoderkinderen | 0:8d87bc453349 | 1038 | ext_level++; |
ninoderkinderen | 0:8d87bc453349 | 1039 | } |
ninoderkinderen | 0:8d87bc453349 | 1040 | } |
ninoderkinderen | 0:8d87bc453349 | 1041 | } |
ninoderkinderen | 0:8d87bc453349 | 1042 | else if(node_type == MIB_NODE_SC) |
ninoderkinderen | 0:8d87bc453349 | 1043 | { |
ninoderkinderen | 0:8d87bc453349 | 1044 | mib_scalar_node *sn; |
ninoderkinderen | 0:8d87bc453349 | 1045 | |
ninoderkinderen | 0:8d87bc453349 | 1046 | /* scalar node */ |
ninoderkinderen | 0:8d87bc453349 | 1047 | sn = (mib_scalar_node *)node; |
ninoderkinderen | 0:8d87bc453349 | 1048 | if (ident_len > 0) |
ninoderkinderen | 0:8d87bc453349 | 1049 | { |
ninoderkinderen | 0:8d87bc453349 | 1050 | /* at .0 */ |
ninoderkinderen | 0:8d87bc453349 | 1051 | climb_tree = 1; |
ninoderkinderen | 0:8d87bc453349 | 1052 | } |
ninoderkinderen | 0:8d87bc453349 | 1053 | else |
ninoderkinderen | 0:8d87bc453349 | 1054 | { |
ninoderkinderen | 0:8d87bc453349 | 1055 | /* ident_len == 0, complete object identifier */ |
ninoderkinderen | 0:8d87bc453349 | 1056 | oidret->id[oidret->len] = 0; |
ninoderkinderen | 0:8d87bc453349 | 1057 | (oidret->len)++; |
ninoderkinderen | 0:8d87bc453349 | 1058 | /* leaf node */ |
ninoderkinderen | 0:8d87bc453349 | 1059 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("completed scalar leaf\n")); |
ninoderkinderen | 0:8d87bc453349 | 1060 | return (struct mib_node*)sn; |
ninoderkinderen | 0:8d87bc453349 | 1061 | } |
ninoderkinderen | 0:8d87bc453349 | 1062 | } |
ninoderkinderen | 0:8d87bc453349 | 1063 | else |
ninoderkinderen | 0:8d87bc453349 | 1064 | { |
ninoderkinderen | 0:8d87bc453349 | 1065 | /* unknown/unhandled node_type */ |
ninoderkinderen | 0:8d87bc453349 | 1066 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("expand failed node_type %"U16_F" unkown\n",(u16_t)node_type)); |
ninoderkinderen | 0:8d87bc453349 | 1067 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 1068 | } |
ninoderkinderen | 0:8d87bc453349 | 1069 | |
ninoderkinderen | 0:8d87bc453349 | 1070 | if (climb_tree) |
ninoderkinderen | 0:8d87bc453349 | 1071 | { |
ninoderkinderen | 0:8d87bc453349 | 1072 | struct nse child; |
ninoderkinderen | 0:8d87bc453349 | 1073 | |
ninoderkinderen | 0:8d87bc453349 | 1074 | /* find right child ptr */ |
ninoderkinderen | 0:8d87bc453349 | 1075 | child.r_ptr = NULL; |
ninoderkinderen | 0:8d87bc453349 | 1076 | child.r_id = 0; |
ninoderkinderen | 0:8d87bc453349 | 1077 | child.r_nl = 0; |
ninoderkinderen | 0:8d87bc453349 | 1078 | while ((node_stack_cnt > 0) && (child.r_ptr == NULL)) |
ninoderkinderen | 0:8d87bc453349 | 1079 | { |
ninoderkinderen | 0:8d87bc453349 | 1080 | pop_node(&child); |
ninoderkinderen | 0:8d87bc453349 | 1081 | /* trim returned oid */ |
ninoderkinderen | 0:8d87bc453349 | 1082 | (oidret->len)--; |
ninoderkinderen | 0:8d87bc453349 | 1083 | } |
ninoderkinderen | 0:8d87bc453349 | 1084 | if (child.r_ptr != NULL) |
ninoderkinderen | 0:8d87bc453349 | 1085 | { |
ninoderkinderen | 0:8d87bc453349 | 1086 | /* incoming ident is useless beyond this point */ |
ninoderkinderen | 0:8d87bc453349 | 1087 | ident_len = 0; |
ninoderkinderen | 0:8d87bc453349 | 1088 | oidret->id[oidret->len] = child.r_id; |
ninoderkinderen | 0:8d87bc453349 | 1089 | oidret->len++; |
ninoderkinderen | 0:8d87bc453349 | 1090 | node = child.r_ptr; |
ninoderkinderen | 0:8d87bc453349 | 1091 | ext_level = child.r_nl; |
ninoderkinderen | 0:8d87bc453349 | 1092 | } |
ninoderkinderen | 0:8d87bc453349 | 1093 | else |
ninoderkinderen | 0:8d87bc453349 | 1094 | { |
ninoderkinderen | 0:8d87bc453349 | 1095 | /* tree ends here ... */ |
ninoderkinderen | 0:8d87bc453349 | 1096 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("expand failed, tree ends here\n")); |
ninoderkinderen | 0:8d87bc453349 | 1097 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 1098 | } |
ninoderkinderen | 0:8d87bc453349 | 1099 | } |
ninoderkinderen | 0:8d87bc453349 | 1100 | } |
ninoderkinderen | 0:8d87bc453349 | 1101 | /* done, found nothing */ |
ninoderkinderen | 0:8d87bc453349 | 1102 | LWIP_DEBUGF(SNMP_MIB_DEBUG,("expand failed node==%p\n",(void*)node)); |
ninoderkinderen | 0:8d87bc453349 | 1103 | return NULL; |
ninoderkinderen | 0:8d87bc453349 | 1104 | } |
ninoderkinderen | 0:8d87bc453349 | 1105 | |
ninoderkinderen | 0:8d87bc453349 | 1106 | /** |
ninoderkinderen | 0:8d87bc453349 | 1107 | * Test object identifier for the iso.org.dod.internet prefix. |
ninoderkinderen | 0:8d87bc453349 | 1108 | * |
ninoderkinderen | 0:8d87bc453349 | 1109 | * @param ident_len the length of the supplied object identifier |
ninoderkinderen | 0:8d87bc453349 | 1110 | * @param ident points to the array of sub identifiers |
ninoderkinderen | 0:8d87bc453349 | 1111 | * @return 1 if it matches, 0 otherwise |
ninoderkinderen | 0:8d87bc453349 | 1112 | */ |
ninoderkinderen | 0:8d87bc453349 | 1113 | u8_t |
ninoderkinderen | 0:8d87bc453349 | 1114 | snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident) |
ninoderkinderen | 0:8d87bc453349 | 1115 | { |
ninoderkinderen | 0:8d87bc453349 | 1116 | if ((ident_len > 3) && |
ninoderkinderen | 0:8d87bc453349 | 1117 | (ident[0] == 1) && (ident[1] == 3) && |
ninoderkinderen | 0:8d87bc453349 | 1118 | (ident[2] == 6) && (ident[3] == 1)) |
ninoderkinderen | 0:8d87bc453349 | 1119 | { |
ninoderkinderen | 0:8d87bc453349 | 1120 | return 1; |
ninoderkinderen | 0:8d87bc453349 | 1121 | } |
ninoderkinderen | 0:8d87bc453349 | 1122 | else |
ninoderkinderen | 0:8d87bc453349 | 1123 | { |
ninoderkinderen | 0:8d87bc453349 | 1124 | return 0; |
ninoderkinderen | 0:8d87bc453349 | 1125 | } |
ninoderkinderen | 0:8d87bc453349 | 1126 | } |
ninoderkinderen | 0:8d87bc453349 | 1127 | |
ninoderkinderen | 0:8d87bc453349 | 1128 | /** |
ninoderkinderen | 0:8d87bc453349 | 1129 | * Expands object identifier to the iso.org.dod.internet |
ninoderkinderen | 0:8d87bc453349 | 1130 | * prefix for use in getnext operation. |
ninoderkinderen | 0:8d87bc453349 | 1131 | * |
ninoderkinderen | 0:8d87bc453349 | 1132 | * @param ident_len the length of the supplied object identifier |
ninoderkinderen | 0:8d87bc453349 | 1133 | * @param ident points to the array of sub identifiers |
ninoderkinderen | 0:8d87bc453349 | 1134 | * @param oidret points to returned expanded object identifier |
ninoderkinderen | 0:8d87bc453349 | 1135 | * @return 1 if it matches, 0 otherwise |
ninoderkinderen | 0:8d87bc453349 | 1136 | * |
ninoderkinderen | 0:8d87bc453349 | 1137 | * @note ident_len 0 is allowed, expanding to the first known object id!! |
ninoderkinderen | 0:8d87bc453349 | 1138 | */ |
ninoderkinderen | 0:8d87bc453349 | 1139 | u8_t |
ninoderkinderen | 0:8d87bc453349 | 1140 | snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret) |
ninoderkinderen | 0:8d87bc453349 | 1141 | { |
ninoderkinderen | 0:8d87bc453349 | 1142 | const s32_t *prefix_ptr; |
ninoderkinderen | 0:8d87bc453349 | 1143 | s32_t *ret_ptr; |
ninoderkinderen | 0:8d87bc453349 | 1144 | u8_t i; |
ninoderkinderen | 0:8d87bc453349 | 1145 | |
ninoderkinderen | 0:8d87bc453349 | 1146 | i = 0; |
ninoderkinderen | 0:8d87bc453349 | 1147 | prefix_ptr = &prefix[0]; |
ninoderkinderen | 0:8d87bc453349 | 1148 | ret_ptr = &oidret->id[0]; |
ninoderkinderen | 0:8d87bc453349 | 1149 | ident_len = ((ident_len < 4)?ident_len:4); |
ninoderkinderen | 0:8d87bc453349 | 1150 | while ((i < ident_len) && ((*ident) <= (*prefix_ptr))) |
ninoderkinderen | 0:8d87bc453349 | 1151 | { |
ninoderkinderen | 0:8d87bc453349 | 1152 | *ret_ptr++ = *prefix_ptr++; |
ninoderkinderen | 0:8d87bc453349 | 1153 | ident++; |
ninoderkinderen | 0:8d87bc453349 | 1154 | i++; |
ninoderkinderen | 0:8d87bc453349 | 1155 | } |
ninoderkinderen | 0:8d87bc453349 | 1156 | if (i == ident_len) |
ninoderkinderen | 0:8d87bc453349 | 1157 | { |
ninoderkinderen | 0:8d87bc453349 | 1158 | /* match, complete missing bits */ |
ninoderkinderen | 0:8d87bc453349 | 1159 | while (i < 4) |
ninoderkinderen | 0:8d87bc453349 | 1160 | { |
ninoderkinderen | 0:8d87bc453349 | 1161 | *ret_ptr++ = *prefix_ptr++; |
ninoderkinderen | 0:8d87bc453349 | 1162 | i++; |
ninoderkinderen | 0:8d87bc453349 | 1163 | } |
ninoderkinderen | 0:8d87bc453349 | 1164 | oidret->len = i; |
ninoderkinderen | 0:8d87bc453349 | 1165 | return 1; |
ninoderkinderen | 0:8d87bc453349 | 1166 | } |
ninoderkinderen | 0:8d87bc453349 | 1167 | else |
ninoderkinderen | 0:8d87bc453349 | 1168 | { |
ninoderkinderen | 0:8d87bc453349 | 1169 | /* i != ident_len */ |
ninoderkinderen | 0:8d87bc453349 | 1170 | return 0; |
ninoderkinderen | 0:8d87bc453349 | 1171 | } |
ninoderkinderen | 0:8d87bc453349 | 1172 | } |
ninoderkinderen | 0:8d87bc453349 | 1173 | |
ninoderkinderen | 0:8d87bc453349 | 1174 | #endif /* LWIP_SNMP */ |