code that uses Watchdog to reset Mbed every 30seconds. After 30-60mins, the ethernet interface fails to setup() after WatchDog reset.

Dependencies:   mbed

Committer:
eqon
Date:
Thu Jun 07 05:44:29 2012 +0000
Revision:
0:0ce833f21e63

        

Who changed what in which revision?

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