I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

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