Dependents:   RTnoV3 RTnoV3_LED RTnoV3_Template RTnoV3_ADC ... more

Committer:
sherckuith
Date:
Sat Dec 31 11:25:27 2011 +0000
Revision:
0:479ce5546098
Ethernet

Who changed what in which revision?

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