Rtos API example

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers snmp_table.h Source File

snmp_table.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * SNMP server MIB API to implement table nodes
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Martin Hentschel <info@cl-soft.de>
00035  *
00036  */
00037 
00038 #ifndef LWIP_HDR_APPS_SNMP_TABLE_H
00039 #define LWIP_HDR_APPS_SNMP_TABLE_H
00040 
00041 #include "lwip/apps/snmp_opts.h"
00042 #include "lwip/apps/snmp_core.h"
00043 
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047 
00048 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
00049 
00050 /** default (customizable) read/write table */
00051 struct snmp_table_col_def
00052 {
00053   u32_t index;
00054   u8_t asn1_type;
00055   snmp_access_t access;
00056 };
00057 
00058 /** table node */
00059 struct snmp_table_node
00060 {
00061   /** inherited "base class" members */
00062   struct snmp_leaf_node node;
00063   u16_t column_count;
00064   const struct snmp_table_col_def* columns;
00065   snmp_err_t (*get_cell_instance)(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance);
00066   snmp_err_t (*get_next_cell_instance)(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance);
00067   /** returns object value for the given object identifier */
00068   node_instance_get_value_method get_value;
00069   /** tests length and/or range BEFORE setting */
00070   node_instance_set_test_method set_test;
00071   /** sets object value, only called when set_test() was successful */
00072   node_instance_set_value_method set_value;
00073 };
00074 
00075 snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
00076 snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
00077 
00078 #define SNMP_TABLE_CREATE(oid, columns, get_cell_instance_method, get_next_cell_instance_method, get_value_method, set_test_method, set_value_method) \
00079   {{{ SNMP_NODE_TABLE, (oid) }, \
00080   snmp_table_get_instance, \
00081   snmp_table_get_next_instance }, \
00082   (u16_t)LWIP_ARRAYSIZE(columns), (columns), \
00083   (get_cell_instance_method), (get_next_cell_instance_method), \
00084   (get_value_method), (set_test_method), (set_value_method)}
00085 
00086 #define SNMP_TABLE_GET_COLUMN_FROM_OID(oid) ((oid)[1]) /* first array value is (fixed) row entry (fixed to 1) and 2nd value is column, follow3ed by instance */
00087 
00088 
00089 /** simple read-only table */
00090 typedef enum {
00091   SNMP_VARIANT_VALUE_TYPE_U32,
00092   SNMP_VARIANT_VALUE_TYPE_S32,
00093   SNMP_VARIANT_VALUE_TYPE_PTR,
00094   SNMP_VARIANT_VALUE_TYPE_CONST_PTR
00095 } snmp_table_column_data_type_t;
00096 
00097 struct snmp_table_simple_col_def
00098 {
00099   u32_t index;
00100   u8_t asn1_type;
00101   snmp_table_column_data_type_t data_type; /* depending of what union member is used to store the value*/
00102 };
00103 
00104 /** simple read-only table node */
00105 struct snmp_table_simple_node
00106 {
00107   /* inherited "base class" members */
00108   struct snmp_leaf_node node;
00109   u16_t column_count;
00110   const struct snmp_table_simple_col_def* columns;
00111   snmp_err_t (*get_cell_value)(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len);
00112   snmp_err_t (*get_next_cell_instance_and_value)(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len);
00113 };
00114 
00115 snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
00116 snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
00117 
00118 #define SNMP_TABLE_CREATE_SIMPLE(oid, columns, get_cell_value_method, get_next_cell_instance_and_value_method) \
00119   {{{ SNMP_NODE_TABLE, (oid) }, \
00120   snmp_table_simple_get_instance, \
00121   snmp_table_simple_get_next_instance }, \
00122   (u16_t)LWIP_ARRAYSIZE(columns), (columns), (get_cell_value_method), (get_next_cell_instance_and_value_method) }
00123 
00124 s16_t snmp_table_extract_value_from_s32ref(struct snmp_node_instance* instance, void* value);
00125 s16_t snmp_table_extract_value_from_u32ref(struct snmp_node_instance* instance, void* value);
00126 s16_t snmp_table_extract_value_from_refconstptr(struct snmp_node_instance* instance, void* value);
00127 
00128 #endif /* LWIP_SNMP */
00129 
00130 #ifdef __cplusplus
00131 }
00132 #endif
00133 
00134 #endif /* LWIP_HDR_APPS_SNMP_TABLE_H */