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