Onenet

Dependents:   K64F_eCompass_OneNET_JW

Committer:
robert_jw
Date:
Mon Jun 20 01:40:20 2016 +0000
Revision:
0:b2805b6888dc
ADS

Who changed what in which revision?

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