Ethernet for Nucleo and Disco board STM32F746 works with gcc and arm. IAC is untested

Dependents:   STM32F746_iothub_client_sample_mqtt DISCO-F746NG_Ethernet Nucleo_F746ZG_Ethernet thethingsiO-DISCO_F746NG-mqtt ... more

Committer:
DieterGraef
Date:
Thu Jun 23 09:04:23 2016 +0000
Revision:
1:28ba13dd96f7
Parent:
0:d26c1b55cfca
corrected MAC issue. The MAC is now 02:00:00:xx:xx:xx where xx is the sum over the unique device register

Who changed what in which revision?

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