delta param

Dependents:   EthernetInterface

Fork of lwip by mbed official

Committer:
klauss
Date:
Thu Jan 08 23:42:30 2015 +0000
Revision:
29:da6f39d13880
Parent:
0:51ac1d130fd4
wip

Who changed what in which revision?

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