Netservices modded to read fragmented HTTP respsonse/payload from special purpose server - 180 bytes only

Committer:
RodColeman
Date:
Thu Sep 08 10:48:09 2011 +0000
Revision:
0:850eacf3e945
revised fixed length to 178 bytes

Who changed what in which revision?

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