Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.

Committer:
andrewbonney
Date:
Fri Apr 08 14:39:41 2011 +0000
Revision:
0:ec559500a63f

        

Who changed what in which revision?

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