NetServices Stack source

Dependents:   HelloWorld ServoInterfaceBoardExample1 4180_Lab4

Committer:
donatien
Date:
Fri Jun 11 16:05:15 2010 +0000
Revision:
0:632c9925f013
Child:
5:dd63a1e02b1b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:632c9925f013 1 /**
donatien 0:632c9925f013 2 * @file
donatien 0:632c9925f013 3 * Generic MIB tree structures.
donatien 0:632c9925f013 4 *
donatien 0:632c9925f013 5 * @todo namespace prefixes
donatien 0:632c9925f013 6 */
donatien 0:632c9925f013 7
donatien 0:632c9925f013 8 /*
donatien 0:632c9925f013 9 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
donatien 0:632c9925f013 10 * All rights reserved.
donatien 0:632c9925f013 11 *
donatien 0:632c9925f013 12 * Redistribution and use in source and binary forms, with or without modification,
donatien 0:632c9925f013 13 * are permitted provided that the following conditions are met:
donatien 0:632c9925f013 14 *
donatien 0:632c9925f013 15 * 1. Redistributions of source code must retain the above copyright notice,
donatien 0:632c9925f013 16 * this list of conditions and the following disclaimer.
donatien 0:632c9925f013 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
donatien 0:632c9925f013 18 * this list of conditions and the following disclaimer in the documentation
donatien 0:632c9925f013 19 * and/or other materials provided with the distribution.
donatien 0:632c9925f013 20 * 3. The name of the author may not be used to endorse or promote products
donatien 0:632c9925f013 21 * derived from this software without specific prior written permission.
donatien 0:632c9925f013 22 *
donatien 0:632c9925f013 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
donatien 0:632c9925f013 24 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
donatien 0:632c9925f013 25 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
donatien 0:632c9925f013 26 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
donatien 0:632c9925f013 27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
donatien 0:632c9925f013 28 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
donatien 0:632c9925f013 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
donatien 0:632c9925f013 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
donatien 0:632c9925f013 31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
donatien 0:632c9925f013 32 * OF SUCH DAMAGE.
donatien 0:632c9925f013 33 *
donatien 0:632c9925f013 34 * Author: Christiaan Simons <christiaan.simons@axon.tv>
donatien 0:632c9925f013 35 */
donatien 0:632c9925f013 36
donatien 0:632c9925f013 37 #ifndef __LWIP_SNMP_STRUCTS_H__
donatien 0:632c9925f013 38 #define __LWIP_SNMP_STRUCTS_H__
donatien 0:632c9925f013 39
donatien 0:632c9925f013 40 #include "lwip/opt.h"
donatien 0:632c9925f013 41
donatien 0:632c9925f013 42 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
donatien 0:632c9925f013 43
donatien 0:632c9925f013 44 #include "lwip/snmp.h"
donatien 0:632c9925f013 45
donatien 0:632c9925f013 46 #if SNMP_PRIVATE_MIB
donatien 0:632c9925f013 47 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
donatien 0:632c9925f013 48 * a 'struct mib_array_node mib_private' which contains your MIB. */
donatien 0:632c9925f013 49 #include "private_mib.h"
donatien 0:632c9925f013 50 #endif
donatien 0:632c9925f013 51
donatien 0:632c9925f013 52 #ifdef __cplusplus
donatien 0:632c9925f013 53 extern "C" {
donatien 0:632c9925f013 54 #endif
donatien 0:632c9925f013 55
donatien 0:632c9925f013 56 /* MIB object instance */
donatien 0:632c9925f013 57 #define MIB_OBJECT_NONE 0
donatien 0:632c9925f013 58 #define MIB_OBJECT_SCALAR 1
donatien 0:632c9925f013 59 #define MIB_OBJECT_TAB 2
donatien 0:632c9925f013 60
donatien 0:632c9925f013 61 /* MIB access types */
donatien 0:632c9925f013 62 #define MIB_ACCESS_READ 1
donatien 0:632c9925f013 63 #define MIB_ACCESS_WRITE 2
donatien 0:632c9925f013 64
donatien 0:632c9925f013 65 /* MIB object access */
donatien 0:632c9925f013 66 #define MIB_OBJECT_READ_ONLY MIB_ACCESS_READ
donatien 0:632c9925f013 67 #define MIB_OBJECT_READ_WRITE (MIB_ACCESS_READ | MIB_ACCESS_WRITE)
donatien 0:632c9925f013 68 #define MIB_OBJECT_WRITE_ONLY MIB_ACCESS_WRITE
donatien 0:632c9925f013 69 #define MIB_OBJECT_NOT_ACCESSIBLE 0
donatien 0:632c9925f013 70
donatien 0:632c9925f013 71 /** object definition returned by (get_object_def)() */
donatien 0:632c9925f013 72 struct obj_def
donatien 0:632c9925f013 73 {
donatien 0:632c9925f013 74 /* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */
donatien 0:632c9925f013 75 u8_t instance;
donatien 0:632c9925f013 76 /* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */
donatien 0:632c9925f013 77 u8_t access;
donatien 0:632c9925f013 78 /* ASN type for this object */
donatien 0:632c9925f013 79 u8_t asn_type;
donatien 0:632c9925f013 80 /* value length (host length) */
donatien 0:632c9925f013 81 u16_t v_len;
donatien 0:632c9925f013 82 /* length of instance part of supplied object identifier */
donatien 0:632c9925f013 83 u8_t id_inst_len;
donatien 0:632c9925f013 84 /* instance part of supplied object identifier */
donatien 0:632c9925f013 85 s32_t *id_inst_ptr;
donatien 0:632c9925f013 86 };
donatien 0:632c9925f013 87
donatien 0:632c9925f013 88 struct snmp_name_ptr
donatien 0:632c9925f013 89 {
donatien 0:632c9925f013 90 u8_t ident_len;
donatien 0:632c9925f013 91 s32_t *ident;
donatien 0:632c9925f013 92 };
donatien 0:632c9925f013 93
donatien 0:632c9925f013 94 /** MIB const scalar (.0) node */
donatien 0:632c9925f013 95 #define MIB_NODE_SC 0x01
donatien 0:632c9925f013 96 /** MIB const array node */
donatien 0:632c9925f013 97 #define MIB_NODE_AR 0x02
donatien 0:632c9925f013 98 /** MIB array node (mem_malloced from RAM) */
donatien 0:632c9925f013 99 #define MIB_NODE_RA 0x03
donatien 0:632c9925f013 100 /** MIB list root node (mem_malloced from RAM) */
donatien 0:632c9925f013 101 #define MIB_NODE_LR 0x04
donatien 0:632c9925f013 102 /** MIB node for external objects */
donatien 0:632c9925f013 103 #define MIB_NODE_EX 0x05
donatien 0:632c9925f013 104
donatien 0:632c9925f013 105 /** node "base class" layout, the mandatory fields for a node */
donatien 0:632c9925f013 106 struct mib_node
donatien 0:632c9925f013 107 {
donatien 0:632c9925f013 108 /** returns struct obj_def for the given object identifier */
donatien 0:632c9925f013 109 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 110 /** returns object value for the given object identifier,
donatien 0:632c9925f013 111 @note the caller must allocate at least len bytes for the value */
donatien 0:632c9925f013 112 void (*get_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 113 /** tests length and/or range BEFORE setting */
donatien 0:632c9925f013 114 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 115 /** sets object value, only to be called when set_test() */
donatien 0:632c9925f013 116 void (*set_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 117 /** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */
donatien 0:632c9925f013 118 u8_t node_type;
donatien 0:632c9925f013 119 /* array or max list length */
donatien 0:632c9925f013 120 u16_t maxlength;
donatien 0:632c9925f013 121 };
donatien 0:632c9925f013 122
donatien 0:632c9925f013 123 /** derived node for scalars .0 index */
donatien 0:632c9925f013 124 typedef struct mib_node mib_scalar_node;
donatien 0:632c9925f013 125
donatien 0:632c9925f013 126 /** derived node, points to a fixed size const array
donatien 0:632c9925f013 127 of sub-identifiers plus a 'child' pointer */
donatien 0:632c9925f013 128 struct mib_array_node
donatien 0:632c9925f013 129 {
donatien 0:632c9925f013 130 /* inherited "base class" members */
donatien 0:632c9925f013 131 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 132 void (*get_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 133 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 134 void (*set_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 135
donatien 0:632c9925f013 136 u8_t node_type;
donatien 0:632c9925f013 137 u16_t maxlength;
donatien 0:632c9925f013 138
donatien 0:632c9925f013 139 /* aditional struct members */
donatien 0:632c9925f013 140 const s32_t *objid;
donatien 0:632c9925f013 141 struct mib_node* const *nptr;
donatien 0:632c9925f013 142 };
donatien 0:632c9925f013 143
donatien 0:632c9925f013 144 /** derived node, points to a fixed size mem_malloced array
donatien 0:632c9925f013 145 of sub-identifiers plus a 'child' pointer */
donatien 0:632c9925f013 146 struct mib_ram_array_node
donatien 0:632c9925f013 147 {
donatien 0:632c9925f013 148 /* inherited "base class" members */
donatien 0:632c9925f013 149 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 150 void (*get_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 151 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 152 void (*set_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 153
donatien 0:632c9925f013 154 u8_t node_type;
donatien 0:632c9925f013 155 u16_t maxlength;
donatien 0:632c9925f013 156
donatien 0:632c9925f013 157 /* aditional struct members */
donatien 0:632c9925f013 158 s32_t *objid;
donatien 0:632c9925f013 159 struct mib_node **nptr;
donatien 0:632c9925f013 160 };
donatien 0:632c9925f013 161
donatien 0:632c9925f013 162 struct mib_list_node
donatien 0:632c9925f013 163 {
donatien 0:632c9925f013 164 struct mib_list_node *prev;
donatien 0:632c9925f013 165 struct mib_list_node *next;
donatien 0:632c9925f013 166 s32_t objid;
donatien 0:632c9925f013 167 struct mib_node *nptr;
donatien 0:632c9925f013 168 };
donatien 0:632c9925f013 169
donatien 0:632c9925f013 170 /** derived node, points to a doubly linked list
donatien 0:632c9925f013 171 of sub-identifiers plus a 'child' pointer */
donatien 0:632c9925f013 172 struct mib_list_rootnode
donatien 0:632c9925f013 173 {
donatien 0:632c9925f013 174 /* inherited "base class" members */
donatien 0:632c9925f013 175 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 176 void (*get_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 177 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 178 void (*set_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 179
donatien 0:632c9925f013 180 u8_t node_type;
donatien 0:632c9925f013 181 u16_t maxlength;
donatien 0:632c9925f013 182
donatien 0:632c9925f013 183 /* aditional struct members */
donatien 0:632c9925f013 184 struct mib_list_node *head;
donatien 0:632c9925f013 185 struct mib_list_node *tail;
donatien 0:632c9925f013 186 /* counts list nodes in list */
donatien 0:632c9925f013 187 u16_t count;
donatien 0:632c9925f013 188 };
donatien 0:632c9925f013 189
donatien 0:632c9925f013 190 /** derived node, has access functions for mib object in external memory or device
donatien 0:632c9925f013 191 using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */
donatien 0:632c9925f013 192 struct mib_external_node
donatien 0:632c9925f013 193 {
donatien 0:632c9925f013 194 /* inherited "base class" members */
donatien 0:632c9925f013 195 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 196 void (*get_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 197 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 198 void (*set_value)(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 199
donatien 0:632c9925f013 200 u8_t node_type;
donatien 0:632c9925f013 201 u16_t maxlength;
donatien 0:632c9925f013 202
donatien 0:632c9925f013 203 /* aditional struct members */
donatien 0:632c9925f013 204 /** points to an extenal (in memory) record of some sort of addressing
donatien 0:632c9925f013 205 information, passed to and interpreted by the funtions below */
donatien 0:632c9925f013 206 void* addr_inf;
donatien 0:632c9925f013 207 /** tree levels under this node */
donatien 0:632c9925f013 208 u8_t tree_levels;
donatien 0:632c9925f013 209 /** number of objects at this level */
donatien 0:632c9925f013 210 u16_t (*level_length)(void* addr_inf, u8_t level);
donatien 0:632c9925f013 211 /** compares object sub identifier with external id
donatien 0:632c9925f013 212 return zero when equal, nonzero when unequal */
donatien 0:632c9925f013 213 s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id);
donatien 0:632c9925f013 214 void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id);
donatien 0:632c9925f013 215
donatien 0:632c9925f013 216 /** async Questions */
donatien 0:632c9925f013 217 void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident);
donatien 0:632c9925f013 218 void (*get_value_q)(u8_t rid, struct obj_def *od);
donatien 0:632c9925f013 219 void (*set_test_q)(u8_t rid, struct obj_def *od);
donatien 0:632c9925f013 220 void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 221 /** async Answers */
donatien 0:632c9925f013 222 void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 223 void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 224 u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 225 void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 226 /** async Panic Close (agent returns error reply,
donatien 0:632c9925f013 227 e.g. used for external transaction cleanup) */
donatien 0:632c9925f013 228 void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident);
donatien 0:632c9925f013 229 void (*get_value_pc)(u8_t rid, struct obj_def *od);
donatien 0:632c9925f013 230 void (*set_test_pc)(u8_t rid, struct obj_def *od);
donatien 0:632c9925f013 231 void (*set_value_pc)(u8_t rid, struct obj_def *od);
donatien 0:632c9925f013 232 };
donatien 0:632c9925f013 233
donatien 0:632c9925f013 234 /** export MIB tree from mib2.c */
donatien 0:632c9925f013 235 extern const struct mib_array_node internet;
donatien 0:632c9925f013 236
donatien 0:632c9925f013 237 /** dummy function pointers for non-leaf MIB nodes from mib2.c */
donatien 0:632c9925f013 238 void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
donatien 0:632c9925f013 239 void noleafs_get_value(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 240 u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 241 void noleafs_set_value(struct obj_def *od, u16_t len, void *value);
donatien 0:632c9925f013 242
donatien 0:632c9925f013 243 void snmp_oidtoip(s32_t *ident, ip_addr_t *ip);
donatien 0:632c9925f013 244 void snmp_iptooid(ip_addr_t *ip, s32_t *ident);
donatien 0:632c9925f013 245 void snmp_ifindextonetif(s32_t ifindex, struct netif **netif);
donatien 0:632c9925f013 246 void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);
donatien 0:632c9925f013 247
donatien 0:632c9925f013 248 struct mib_list_node* snmp_mib_ln_alloc(s32_t id);
donatien 0:632c9925f013 249 void snmp_mib_ln_free(struct mib_list_node *ln);
donatien 0:632c9925f013 250 struct mib_list_rootnode* snmp_mib_lrn_alloc(void);
donatien 0:632c9925f013 251 void snmp_mib_lrn_free(struct mib_list_rootnode *lrn);
donatien 0:632c9925f013 252
donatien 0:632c9925f013 253 s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn);
donatien 0:632c9925f013 254 s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn);
donatien 0:632c9925f013 255 struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n);
donatien 0:632c9925f013 256
donatien 0:632c9925f013 257 struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np);
donatien 0:632c9925f013 258 struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
donatien 0:632c9925f013 259 u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident);
donatien 0:632c9925f013 260 u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
donatien 0:632c9925f013 261
donatien 0:632c9925f013 262 #ifdef __cplusplus
donatien 0:632c9925f013 263 }
donatien 0:632c9925f013 264 #endif
donatien 0:632c9925f013 265
donatien 0:632c9925f013 266 #endif /* LWIP_SNMP */
donatien 0:632c9925f013 267
donatien 0:632c9925f013 268 #endif /* __LWIP_SNMP_STRUCTS_H__ */