SNMP agent attached to SPI slave

Dependencies:   mbed

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