Dependents:   SNMPAgent HTTPServer think_speak_a cyassl-client ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers snmp_structs.h Source File

snmp_structs.h

Go to the documentation of this file.
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 /* When using a private MIB, you have to create a file 'private_mib.h' that contains
00048  * a 'struct mib_array_node mib_private' which contains your MIB. */
00049 #include "private_mib.h"
00050 #endif
00051 
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 
00056 /* MIB object instance */
00057 #define MIB_OBJECT_NONE 0 
00058 #define MIB_OBJECT_SCALAR 1
00059 #define MIB_OBJECT_TAB 2
00060 
00061 /* MIB access types */
00062 #define MIB_ACCESS_READ   1
00063 #define MIB_ACCESS_WRITE  2
00064 
00065 /* MIB object access */
00066 #define MIB_OBJECT_READ_ONLY      MIB_ACCESS_READ
00067 #define MIB_OBJECT_READ_WRITE     (MIB_ACCESS_READ | MIB_ACCESS_WRITE)
00068 #define MIB_OBJECT_WRITE_ONLY     MIB_ACCESS_WRITE
00069 #define MIB_OBJECT_NOT_ACCESSIBLE 0
00070 
00071 /** object definition returned by (get_object_def)() */
00072 struct obj_def
00073 {
00074   /* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */
00075   u8_t instance;
00076   /* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */
00077   u8_t access;
00078   /* ASN type for this object */
00079   u8_t asn_type;
00080   /* value length (host length) */
00081   u16_t v_len;
00082   /* length of instance part of supplied object identifier */
00083   u8_t  id_inst_len;
00084   /* instance part of supplied object identifier */
00085   s32_t *id_inst_ptr;
00086 };
00087 
00088 struct snmp_name_ptr
00089 {
00090   u8_t ident_len;
00091   s32_t *ident;
00092 };
00093 
00094 /** MIB const scalar (.0) node */
00095 #define MIB_NODE_SC 0x01
00096 /** MIB const array node */
00097 #define MIB_NODE_AR 0x02
00098 /** MIB array node (mem_malloced from RAM) */
00099 #define MIB_NODE_RA 0x03
00100 /** MIB list root node (mem_malloced from RAM) */
00101 #define MIB_NODE_LR 0x04
00102 /** MIB node for external objects */
00103 #define MIB_NODE_EX 0x05
00104 
00105 /** node "base class" layout, the mandatory fields for a node  */
00106 struct mib_node
00107 {
00108   /** returns struct obj_def for the given object identifier */
00109   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
00110   /** returns object value for the given object identifier,
00111      @note the caller must allocate at least len bytes for the value */
00112   void (*get_value)(struct obj_def *od, u16_t len, void *value);
00113   /** tests length and/or range BEFORE setting */
00114   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
00115   /** sets object value, only to be called when set_test()  */
00116   void (*set_value)(struct obj_def *od, u16_t len, void *value);  
00117   /** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */
00118   u8_t node_type;
00119   /* array or max list length */
00120   u16_t maxlength;
00121 };
00122 
00123 /** derived node for scalars .0 index */
00124 typedef struct mib_node mib_scalar_node;
00125 
00126 /** derived node, points to a fixed size const array
00127     of sub-identifiers plus a 'child' pointer */
00128 struct mib_array_node
00129 {
00130   /* inherited "base class" members */
00131   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
00132   void (*get_value)(struct obj_def *od, u16_t len, void *value);
00133   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
00134   void (*set_value)(struct obj_def *od, u16_t len, void *value);
00135 
00136   u8_t node_type;
00137   u16_t maxlength;
00138 
00139   /* additional struct members */
00140   const s32_t *objid;
00141   struct mib_node* const *nptr;
00142 };
00143 
00144 /** derived node, points to a fixed size mem_malloced array
00145     of sub-identifiers plus a 'child' pointer */
00146 struct mib_ram_array_node
00147 {
00148   /* inherited "base class" members */
00149   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
00150   void (*get_value)(struct obj_def *od, u16_t len, void *value);
00151   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
00152   void (*set_value)(struct obj_def *od, u16_t len, void *value);
00153 
00154   u8_t node_type;
00155   u16_t maxlength;
00156 
00157   /* aditional struct members */
00158   s32_t *objid;
00159   struct mib_node **nptr;
00160 };
00161 
00162 struct mib_list_node
00163 {
00164   struct mib_list_node *prev;  
00165   struct mib_list_node *next;
00166   s32_t objid;
00167   struct mib_node *nptr;
00168 };
00169 
00170 /** derived node, points to a doubly linked list
00171     of sub-identifiers plus a 'child' pointer */
00172 struct mib_list_rootnode
00173 {
00174   /* inherited "base class" members */
00175   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
00176   void (*get_value)(struct obj_def *od, u16_t len, void *value);
00177   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
00178   void (*set_value)(struct obj_def *od, u16_t len, void *value);
00179 
00180   u8_t node_type;
00181   u16_t maxlength;
00182 
00183   /* additional struct members */
00184   struct mib_list_node *head;
00185   struct mib_list_node *tail;
00186   /* counts list nodes in list  */
00187   u16_t count;
00188 };
00189 
00190 /** derived node, has access functions for mib object in external memory or device
00191     using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */
00192 struct mib_external_node
00193 {
00194   /* inherited "base class" members */
00195   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
00196   void (*get_value)(struct obj_def *od, u16_t len, void *value);
00197   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
00198   void (*set_value)(struct obj_def *od, u16_t len, void *value);
00199 
00200   u8_t node_type;
00201   u16_t maxlength;
00202 
00203   /* additional struct members */
00204   /** points to an external (in memory) record of some sort of addressing
00205       information, passed to and interpreted by the funtions below */
00206   void* addr_inf;
00207   /** tree levels under this node */
00208   u8_t tree_levels;
00209   /** number of objects at this level */
00210   u16_t (*level_length)(void* addr_inf, u8_t level);
00211   /** compares object sub identifier with external id
00212       return zero when equal, nonzero when unequal */
00213   s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id);
00214   void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id);
00215 
00216   /** async Questions */
00217   void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident);
00218   void (*get_value_q)(u8_t rid, struct obj_def *od);
00219   void (*set_test_q)(u8_t rid, struct obj_def *od);
00220   void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value);
00221   /** async Answers */
00222   void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od);
00223   void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
00224   u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
00225   void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
00226   /** async Panic Close (agent returns error reply, 
00227       e.g. used for external transaction cleanup) */
00228   void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident);
00229   void (*get_value_pc)(u8_t rid, struct obj_def *od);
00230   void (*set_test_pc)(u8_t rid, struct obj_def *od);
00231   void (*set_value_pc)(u8_t rid, struct obj_def *od);
00232 };
00233 
00234 /** export MIB tree from mib2.c */
00235 extern const struct mib_array_node internet;
00236 
00237 /** dummy function pointers for non-leaf MIB nodes from mib2.c */
00238 void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
00239 void noleafs_get_value(struct obj_def *od, u16_t len, void *value);
00240 u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value);
00241 void noleafs_set_value(struct obj_def *od, u16_t len, void *value);
00242 
00243 void snmp_oidtoip(s32_t *ident, ip_addr_t *ip);
00244 void snmp_iptooid(ip_addr_t *ip, s32_t *ident);
00245 void snmp_ifindextonetif(s32_t ifindex, struct netif **netif);
00246 void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);
00247 
00248 struct mib_list_node* snmp_mib_ln_alloc(s32_t id);
00249 void snmp_mib_ln_free(struct mib_list_node *ln);
00250 struct mib_list_rootnode* snmp_mib_lrn_alloc(void);
00251 void snmp_mib_lrn_free(struct mib_list_rootnode *lrn);
00252 
00253 s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn);
00254 s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn);
00255 struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n);
00256 
00257 struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np);
00258 struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
00259 u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident);
00260 u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
00261 
00262 #ifdef __cplusplus
00263 }
00264 #endif
00265 
00266 #endif /* LWIP_SNMP */
00267 
00268 #endif /* __LWIP_SNMP_STRUCTS_H__ */