Dependents:   TimeZoneDemo EthernetJackTestCode MMEx_Challenge ntp_mem ... more

Committer:
segundo
Date:
Tue Nov 09 20:54:15 2010 +0000
Revision:
0:ac1725ba162c

        

Who changed what in which revision?

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