PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/FreeRTOS/Demo/Common/ethernet/lwIP/include/lwip/snmp_structs.h

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