3 * [EXPERIMENTAL] Generic MIB tree access/construction functions.
7 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * Author: Christiaan Simons <christiaan.simons@axon.tv>
36 #include "lwip/snmp_structs.h"
41 * Searches tree for the supplied (scalar?) object identifier.
43 * @param node points to the root of the tree ('.internet')
44 * @param ident_len the length of the supplied object identifier
45 * @param ident points to the array of sub identifiers
46 * @param object_def points to the object definition to return
47 * @return pointer to the requested parent (!) node if success, NULL otherwise
50 snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct obj_def *object_def)
54 LWIP_DEBUGF(SNMP_MIB_DEBUG,("node==%p *ident==%"S32_F,(void*)node,*ident));
57 node_type = node->node_type;
58 if ((node_type == MIB_NODE_AR) || (node_type == MIB_NODE_RA))
60 struct mib_array_node *an;
63 /* array node (internal ROM or RAM, fixed length) */
64 an = (struct mib_array_node *)node;
66 while ((i < an->maxlength) && (an->objid[i] != *ident))
70 if (i < an->maxlength)
74 /* found it, if available proceed to child, otherwise inspect leaf */
75 LWIP_DEBUGF(SNMP_MIB_DEBUG,("an->objid[%"U16_F"]==%"S32_F" *ident==%"S32_F,i,an->objid[i],*ident));
76 if (an->nptr[i] == NULL)
78 /* a scalar leaf OR table,
79 inspect remaining instance number / table index */
80 /* retrieve object definition with get_object_def()
81 is it scalar, or a valid table item, or non-existent? */
82 an->get_object_def(ident_len, ident, object_def);
83 if (object_def->instance != MIB_OBJECT_NONE)
85 /** @todo return something more usefull ?? */
86 return (struct mib_node*)an;
90 /* search failed, object id points to unknown object (nosuchname) */
91 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, object not in this MIB"));
97 /* follow next child pointer */
105 /* search failed, short object identifier (nosuchname) */
106 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, short object identifier"));
112 /* search failed, identifier mismatch (nosuchname) */
113 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed *ident==%"S32_F,*ident));
117 else if(node_type == MIB_NODE_LR)
119 struct mib_list_rootnode *lrn;
120 struct mib_list_node *ln;
122 /* list root node (internal 'RAM', variable length) */
123 lrn = (struct mib_list_rootnode *)node;
125 /* iterate over list, head to tail */
126 while ((ln != NULL) && (ln->objid != *ident))
134 /* found it, proceed to child */;
135 LWIP_DEBUGF(SNMP_MIB_DEBUG,("ln->objid==%"S32_F" *ident==%"S32_F,ln->objid,*ident));
136 if (ln->nptr == NULL)
138 lrn->get_object_def(ident_len, ident, object_def);
139 if (object_def->instance != MIB_OBJECT_NONE)
141 /** @todo return something more usefull ?? */
142 return (struct mib_node*)lrn;
146 /* search failed, object id points to unknown object (nosuchname) */
147 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, object not in this MIB"));
153 /* follow next child pointer */
161 /* search failed, short object identifier (nosuchname) */
162 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, short object identifier"));
169 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed *ident==%"S32_F,*ident));
173 else if(node_type == MIB_NODE_EX)
175 struct mib_external_node *en;
178 /* external node (addressing and access via functions) */
179 en = (struct mib_external_node *)node;
181 while ((i < en->count) && en->ident_cmp(i,*ident))
189 if (en->get_nptr(i) == NULL)
191 /** @todo, this object is elsewhere, we can only start the request,
192 but can't return something usefull yet.*/
193 en->req_object_def(ident_len, ident);
194 return (struct mib_node*)en;
198 /* found it, proceed to child */
201 node = (struct mib_node*)en->get_nptr(i);
206 /* search failed, short object identifier (nosuchname) */
207 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed, short object identifier"));
214 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed *ident==%"S32_F,*ident));
219 /* done, found nothing */
220 LWIP_DEBUGF(SNMP_MIB_DEBUG,("search failed node==%p",(void*)node));
224 #endif /* LWIP_SNMP */