Some quick code to use UDP-only (no TCP) with mBed. Echos received packets and sends packets when a button is pressed
snmp_structs.h
00001 /** 00002 * @file 00003 * Generic MIB tree structures. 00004 * 00005 * @todo namespace prefixes 00006 */ 00007 00008 /* 00009 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 00010 * All rights reserved. 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. The name of the author may not be used to endorse or promote products 00021 * derived from this software without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00024 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00025 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00026 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00027 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00028 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00029 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00030 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00031 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00032 * OF SUCH DAMAGE. 00033 * 00034 * Author: Christiaan Simons <christiaan.simons@axon.tv> 00035 */ 00036 00037 #ifndef __LWIP_SNMP_STRUCTS_H__ 00038 #define __LWIP_SNMP_STRUCTS_H__ 00039 00040 #include "lwip/opt.h" 00041 00042 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */ 00043 00044 #include "lwip/snmp.h" 00045 00046 #if SNMP_PRIVATE_MIB 00047 #include "private_mib.h" 00048 #endif 00049 00050 #ifdef __cplusplus 00051 extern "C" { 00052 #endif 00053 00054 /* MIB object instance */ 00055 #define MIB_OBJECT_NONE 0 00056 #define MIB_OBJECT_SCALAR 1 00057 #define MIB_OBJECT_TAB 2 00058 00059 /* MIB object access */ 00060 #define MIB_OBJECT_READ_ONLY 0 00061 #define MIB_OBJECT_READ_WRITE 1 00062 #define MIB_OBJECT_WRITE_ONLY 2 00063 #define MIB_OBJECT_NOT_ACCESSIBLE 3 00064 00065 /** object definition returned by (get_object_def)() */ 00066 struct obj_def 00067 { 00068 /* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */ 00069 u8_t instance; 00070 /* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */ 00071 u8_t access; 00072 /* ASN type for this object */ 00073 u8_t asn_type; 00074 /* value length (host length) */ 00075 u16_t v_len; 00076 /* length of instance part of supplied object identifier */ 00077 u8_t id_inst_len; 00078 /* instance part of supplied object identifier */ 00079 s32_t *id_inst_ptr; 00080 }; 00081 00082 struct snmp_name_ptr 00083 { 00084 u8_t ident_len; 00085 s32_t *ident; 00086 }; 00087 00088 /** MIB const scalar (.0) node */ 00089 #define MIB_NODE_SC 0x01 00090 /** MIB const array node */ 00091 #define MIB_NODE_AR 0x02 00092 /** MIB array node (mem_malloced from RAM) */ 00093 #define MIB_NODE_RA 0x03 00094 /** MIB list root node (mem_malloced from RAM) */ 00095 #define MIB_NODE_LR 0x04 00096 /** MIB node for external objects */ 00097 #define MIB_NODE_EX 0x05 00098 00099 /** node "base class" layout, the mandatory fields for a node */ 00100 struct mib_node 00101 { 00102 /** returns struct obj_def for the given object identifier */ 00103 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); 00104 /** returns object value for the given object identifier, 00105 @note the caller must allocate at least len bytes for the value */ 00106 void (*get_value)(struct obj_def *od, u16_t len, void *value); 00107 /** tests length and/or range BEFORE setting */ 00108 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); 00109 /** sets object value, only to be called when set_test() */ 00110 void (*set_value)(struct obj_def *od, u16_t len, void *value); 00111 /** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */ 00112 const u8_t node_type; 00113 /* array or max list length */ 00114 const u16_t maxlength; 00115 }; 00116 00117 /** derived node for scalars .0 index */ 00118 typedef struct mib_node mib_scalar_node; 00119 00120 /** derived node, points to a fixed size const array 00121 of sub-identifiers plus a 'child' pointer */ 00122 struct mib_array_node 00123 { 00124 /* inherited "base class" members */ 00125 void (* const get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); 00126 void (* const get_value)(struct obj_def *od, u16_t len, void *value); 00127 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); 00128 void (*set_value)(struct obj_def *od, u16_t len, void *value); 00129 00130 const u8_t node_type; 00131 const u16_t maxlength; 00132 00133 /* aditional struct members */ 00134 const s32_t *objid; 00135 struct mib_node* const *nptr; 00136 }; 00137 00138 /** derived node, points to a fixed size mem_malloced array 00139 of sub-identifiers plus a 'child' pointer */ 00140 struct mib_ram_array_node 00141 { 00142 /* inherited "base class" members */ 00143 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); 00144 void (*get_value)(struct obj_def *od, u16_t len, void *value); 00145 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); 00146 void (*set_value)(struct obj_def *od, u16_t len, void *value); 00147 00148 u8_t node_type; 00149 u16_t maxlength; 00150 00151 /* aditional struct members */ 00152 s32_t *objid; 00153 struct mib_node **nptr; 00154 }; 00155 00156 struct mib_list_node 00157 { 00158 struct mib_list_node *prev; 00159 struct mib_list_node *next; 00160 s32_t objid; 00161 struct mib_node *nptr; 00162 }; 00163 00164 /** derived node, points to a doubly linked list 00165 of sub-identifiers plus a 'child' pointer */ 00166 struct mib_list_rootnode 00167 { 00168 /* inherited "base class" members */ 00169 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); 00170 void (*get_value)(struct obj_def *od, u16_t len, void *value); 00171 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); 00172 void (*set_value)(struct obj_def *od, u16_t len, void *value); 00173 00174 u8_t node_type; 00175 u16_t maxlength; 00176 00177 /* aditional struct members */ 00178 struct mib_list_node *head; 00179 struct mib_list_node *tail; 00180 /* counts list nodes in list */ 00181 u16_t count; 00182 }; 00183 00184 /** derived node, has access functions for mib object in external memory or device 00185 using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */ 00186 struct mib_external_node 00187 { 00188 /* inherited "base class" members */ 00189 void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od); 00190 void (*get_value)(struct obj_def *od, u16_t len, void *value); 00191 u8_t (*set_test)(struct obj_def *od, u16_t len, void *value); 00192 void (*set_value)(struct obj_def *od, u16_t len, void *value); 00193 00194 u8_t node_type; 00195 u16_t maxlength; 00196 00197 /* aditional struct members */ 00198 /** points to an extenal (in memory) record of some sort of addressing 00199 information, passed to and interpreted by the funtions below */ 00200 void* addr_inf; 00201 /** tree levels under this node */ 00202 u8_t tree_levels; 00203 /** number of objects at this level */ 00204 u16_t (*level_length)(void* addr_inf, u8_t level); 00205 /** compares object sub identifier with external id 00206 return zero when equal, nonzero when unequal */ 00207 s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id); 00208 void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id); 00209 00210 /** async Questions */ 00211 void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident); 00212 void (*get_value_q)(u8_t rid, struct obj_def *od); 00213 void (*set_test_q)(u8_t rid, struct obj_def *od); 00214 void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value); 00215 /** async Answers */ 00216 void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od); 00217 void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value); 00218 u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value); 00219 void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value); 00220 /** async Panic Close (agent returns error reply, 00221 e.g. used for external transaction cleanup) */ 00222 void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident); 00223 void (*get_value_pc)(u8_t rid, struct obj_def *od); 00224 void (*set_test_pc)(u8_t rid, struct obj_def *od); 00225 void (*set_value_pc)(u8_t rid, struct obj_def *od); 00226 }; 00227 00228 /** export MIB tree from mib2.c */ 00229 extern const struct mib_array_node internet; 00230 00231 /** dummy function pointers for non-leaf MIB nodes from mib2.c */ 00232 void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od); 00233 void noleafs_get_value(struct obj_def *od, u16_t len, void *value); 00234 u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value); 00235 void noleafs_set_value(struct obj_def *od, u16_t len, void *value); 00236 00237 void snmp_oidtoip(s32_t *ident, struct ip_addr *ip); 00238 void snmp_iptooid(struct ip_addr *ip, s32_t *ident); 00239 void snmp_ifindextonetif(s32_t ifindex, struct netif **netif); 00240 void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx); 00241 00242 struct mib_list_node* snmp_mib_ln_alloc(s32_t id); 00243 void snmp_mib_ln_free(struct mib_list_node *ln); 00244 struct mib_list_rootnode* snmp_mib_lrn_alloc(void); 00245 void snmp_mib_lrn_free(struct mib_list_rootnode *lrn); 00246 00247 s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn); 00248 s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn); 00249 struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n); 00250 00251 struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np); 00252 struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret); 00253 u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident); 00254 u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret); 00255 00256 #ifdef __cplusplus 00257 } 00258 #endif 00259 00260 #endif /* LWIP_SNMP */ 00261 00262 #endif /* __LWIP_SNMP_STRUCTS_H__ */
Generated on Tue Jul 12 2022 19:17:24 by 1.7.2