Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/include/lwip/snmp_structs.h need to be fixed.

0001 /**
0002  * @file
0003  * Generic MIB tree structures.
0004  *
0005  * @todo namespace prefixes
0006  */
0007 
0008 /*
0009  * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
0010  * All rights reserved.
0011  *
0012  * Redistribution and use in source and binary forms, with or without modification,
0013  * are permitted provided that the following conditions are met:
0014  *
0015  * 1. Redistributions of source code must retain the above copyright notice,
0016  *    this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright notice,
0018  *    this list of conditions and the following disclaimer in the documentation
0019  *    and/or other materials provided with the distribution.
0020  * 3. The name of the author may not be used to endorse or promote products
0021  *    derived from this software without specific prior written permission.
0022  *
0023  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
0024  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
0025  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
0026  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0027  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
0028  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
0031  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
0032  * OF SUCH DAMAGE.
0033  *
0034  * Author: Christiaan Simons <christiaan.simons@axon.tv>
0035  */
0036 
0037 #ifndef __LWIP_SNMP_STRUCTS_H__
0038 #define __LWIP_SNMP_STRUCTS_H__
0039 
0040 #include "lwip/opt.h"
0041 
0042 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
0043 
0044 #include "lwip/snmp.h"
0045 
0046 #if SNMP_PRIVATE_MIB
0047 #include "private_mib.h"
0048 #endif
0049 
0050 #ifdef __cplusplus
0051 extern "C" {
0052 #endif
0053 
0054 /* MIB object instance */
0055 #define MIB_OBJECT_NONE 0 
0056 #define MIB_OBJECT_SCALAR 1
0057 #define MIB_OBJECT_TAB 2
0058 
0059 /* MIB object access */
0060 #define MIB_OBJECT_READ_ONLY 0
0061 #define MIB_OBJECT_READ_WRITE 1
0062 #define MIB_OBJECT_WRITE_ONLY 2
0063 #define MIB_OBJECT_NOT_ACCESSIBLE 3
0064 
0065 /** object definition returned by (get_object_def)() */
0066 struct obj_def
0067 {
0068   /* MIB_OBJECT_NONE (0), MIB_OBJECT_SCALAR (1), MIB_OBJECT_TAB (2) */
0069   u8_t instance;
0070   /* 0 read-only, 1 read-write, 2 write-only, 3 not-accessible */
0071   u8_t access;
0072   /* ASN type for this object */
0073   u8_t asn_type;
0074   /* value length (host length) */
0075   u16_t v_len;
0076   /* length of instance part of supplied object identifier */
0077   u8_t  id_inst_len;
0078   /* instance part of supplied object identifier */
0079   s32_t *id_inst_ptr;
0080 };
0081 
0082 struct snmp_name_ptr
0083 {
0084   u8_t ident_len;
0085   s32_t *ident;
0086 };
0087 
0088 /** MIB const scalar (.0) node */
0089 #define MIB_NODE_SC 0x01
0090 /** MIB const array node */
0091 #define MIB_NODE_AR 0x02
0092 /** MIB array node (mem_malloced from RAM) */
0093 #define MIB_NODE_RA 0x03
0094 /** MIB list root node (mem_malloced from RAM) */
0095 #define MIB_NODE_LR 0x04
0096 /** MIB node for external objects */
0097 #define MIB_NODE_EX 0x05
0098 
0099 /** node "base class" layout, the mandatory fields for a node  */
0100 struct mib_node
0101 {
0102   /** returns struct obj_def for the given object identifier */
0103   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
0104   /** returns object value for the given object identifier,
0105      @note the caller must allocate at least len bytes for the value */
0106   void (*get_value)(struct obj_def *od, u16_t len, void *value);
0107   /** tests length and/or range BEFORE setting */
0108   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
0109   /** sets object value, only to be called when set_test()  */
0110   void (*set_value)(struct obj_def *od, u16_t len, void *value);  
0111   /** One out of MIB_NODE_AR, MIB_NODE_LR or MIB_NODE_EX */
0112   const u8_t node_type;
0113   /* array or max list length */
0114   const u16_t maxlength;
0115 };
0116 
0117 /** derived node for scalars .0 index */
0118 typedef struct mib_node mib_scalar_node;
0119 
0120 /** derived node, points to a fixed size const array
0121     of sub-identifiers plus a 'child' pointer */
0122 struct mib_array_node
0123 {
0124   /* inherited "base class" members */
0125   void (* const get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
0126   void (* const get_value)(struct obj_def *od, u16_t len, void *value);
0127   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
0128   void (*set_value)(struct obj_def *od, u16_t len, void *value);
0129 
0130   const u8_t node_type;
0131   const u16_t maxlength;
0132 
0133   /* aditional struct members */
0134   const s32_t *objid;
0135   struct mib_node* const *nptr;
0136 };
0137 
0138 /** derived node, points to a fixed size mem_malloced array
0139     of sub-identifiers plus a 'child' pointer */
0140 struct mib_ram_array_node
0141 {
0142   /* inherited "base class" members */
0143   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
0144   void (*get_value)(struct obj_def *od, u16_t len, void *value);
0145   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
0146   void (*set_value)(struct obj_def *od, u16_t len, void *value);
0147 
0148   u8_t node_type;
0149   u16_t maxlength;
0150 
0151   /* aditional struct members */
0152   s32_t *objid;
0153   struct mib_node **nptr;
0154 };
0155 
0156 struct mib_list_node
0157 {
0158   struct mib_list_node *prev;  
0159   struct mib_list_node *next;
0160   s32_t objid;
0161   struct mib_node *nptr;
0162 };
0163 
0164 /** derived node, points to a doubly linked list
0165     of sub-identifiers plus a 'child' pointer */
0166 struct mib_list_rootnode
0167 {
0168   /* inherited "base class" members */
0169   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
0170   void (*get_value)(struct obj_def *od, u16_t len, void *value);
0171   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
0172   void (*set_value)(struct obj_def *od, u16_t len, void *value);
0173 
0174   u8_t node_type;
0175   u16_t maxlength;
0176 
0177   /* aditional struct members */
0178   struct mib_list_node *head;
0179   struct mib_list_node *tail;
0180   /* counts list nodes in list  */
0181   u16_t count;
0182 };
0183 
0184 /** derived node, has access functions for mib object in external memory or device
0185     using 'tree_level' and 'idx', with a range 0 .. (level_length() - 1) */
0186 struct mib_external_node
0187 {
0188   /* inherited "base class" members */
0189   void (*get_object_def)(u8_t ident_len, s32_t *ident, struct obj_def *od);
0190   void (*get_value)(struct obj_def *od, u16_t len, void *value);
0191   u8_t (*set_test)(struct obj_def *od, u16_t len, void *value);
0192   void (*set_value)(struct obj_def *od, u16_t len, void *value);
0193 
0194   u8_t node_type;
0195   u16_t maxlength;
0196 
0197   /* aditional struct members */
0198   /** points to an extenal (in memory) record of some sort of addressing
0199       information, passed to and interpreted by the funtions below */
0200   void* addr_inf;
0201   /** tree levels under this node */
0202   u8_t tree_levels;
0203   /** number of objects at this level */
0204   u16_t (*level_length)(void* addr_inf, u8_t level);
0205   /** compares object sub identifier with external id
0206       return zero when equal, nonzero when unequal */
0207   s32_t (*ident_cmp)(void* addr_inf, u8_t level, u16_t idx, s32_t sub_id);
0208   void (*get_objid)(void* addr_inf, u8_t level, u16_t idx, s32_t *sub_id);
0209 
0210   /** async Questions */
0211   void (*get_object_def_q)(void* addr_inf, u8_t rid, u8_t ident_len, s32_t *ident);
0212   void (*get_value_q)(u8_t rid, struct obj_def *od);
0213   void (*set_test_q)(u8_t rid, struct obj_def *od);
0214   void (*set_value_q)(u8_t rid, struct obj_def *od, u16_t len, void *value);
0215   /** async Answers */
0216   void (*get_object_def_a)(u8_t rid, u8_t ident_len, s32_t *ident, struct obj_def *od);
0217   void (*get_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
0218   u8_t (*set_test_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
0219   void (*set_value_a)(u8_t rid, struct obj_def *od, u16_t len, void *value);
0220   /** async Panic Close (agent returns error reply, 
0221       e.g. used for external transaction cleanup) */
0222   void (*get_object_def_pc)(u8_t rid, u8_t ident_len, s32_t *ident);
0223   void (*get_value_pc)(u8_t rid, struct obj_def *od);
0224   void (*set_test_pc)(u8_t rid, struct obj_def *od);
0225   void (*set_value_pc)(u8_t rid, struct obj_def *od);
0226 };
0227 
0228 /** export MIB tree from mib2.c */
0229 extern const struct mib_array_node internet;
0230 
0231 /** dummy function pointers for non-leaf MIB nodes from mib2.c */
0232 void noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
0233 void noleafs_get_value(struct obj_def *od, u16_t len, void *value);
0234 u8_t noleafs_set_test(struct obj_def *od, u16_t len, void *value);
0235 void noleafs_set_value(struct obj_def *od, u16_t len, void *value);
0236 
0237 void snmp_oidtoip(s32_t *ident, struct ip_addr *ip);
0238 void snmp_iptooid(struct ip_addr *ip, s32_t *ident);
0239 void snmp_ifindextonetif(s32_t ifindex, struct netif **netif);
0240 void snmp_netiftoifindex(struct netif *netif, s32_t *ifidx);
0241 
0242 struct mib_list_node* snmp_mib_ln_alloc(s32_t id);
0243 void snmp_mib_ln_free(struct mib_list_node *ln);
0244 struct mib_list_rootnode* snmp_mib_lrn_alloc(void);
0245 void snmp_mib_lrn_free(struct mib_list_rootnode *lrn);
0246 
0247 s8_t snmp_mib_node_insert(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **insn);
0248 s8_t snmp_mib_node_find(struct mib_list_rootnode *rn, s32_t objid, struct mib_list_node **fn);
0249 struct mib_list_rootnode *snmp_mib_node_delete(struct mib_list_rootnode *rn, struct mib_list_node *n);
0250 
0251 struct mib_node* snmp_search_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_name_ptr *np);
0252 struct mib_node* snmp_expand_tree(struct mib_node *node, u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
0253 u8_t snmp_iso_prefix_tst(u8_t ident_len, s32_t *ident);
0254 u8_t snmp_iso_prefix_expand(u8_t ident_len, s32_t *ident, struct snmp_obj_id *oidret);
0255 
0256 #ifdef __cplusplus
0257 }
0258 #endif
0259 
0260 #endif /* LWIP_SNMP */
0261 
0262 #endif /* __LWIP_SNMP_STRUCTS_H__ */