ConOpSys V2970  P004.07
ANVILEX control operating system
snmp_table.h
Go to the documentation of this file.
1 /**
2  * @file
3  * SNMP server MIB API to implement table nodes
4  */
5 
6 /*
7  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright notice,
14  * this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  * 3. The name of the author may not be used to endorse or promote products
19  * derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Martin Hentschel <info@cl-soft.de>
35  *
36  */
37 
38 #ifndef LWIP_HDR_APPS_SNMP_TABLE_H
39 #define LWIP_HDR_APPS_SNMP_TABLE_H
40 
41 #include "lwip/apps/snmp_opts.h"
42 #include "lwip/apps/snmp_core.h"
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
49 
50 /** default (customizable) read/write table */
51 struct snmp_table_col_def
52 {
53  u32_t index;
54  u8_t asn1_type;
55  snmp_access_t access;
56 };
57 
58 /** table node */
59 struct snmp_table_node
60 {
61  /** inherited "base class" members */
62  struct snmp_leaf_node node;
63  u16_t column_count;
64  const struct snmp_table_col_def* columns;
65  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);
66  snmp_err_t (*get_next_cell_instance)(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance);
67  /** returns object value for the given object identifier */
68  node_instance_get_value_method get_value;
69  /** tests length and/or range BEFORE setting */
70  node_instance_set_test_method set_test;
71  /** sets object value, only called when set_test() was successful */
72  node_instance_set_value_method set_value;
73 };
74 
75 snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
76 snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
77 
78 #define SNMP_TABLE_CREATE(oid, columns, get_cell_instance_method, get_next_cell_instance_method, get_value_method, set_test_method, set_value_method) \
79  {{{ SNMP_NODE_TABLE, (oid) }, \
80  snmp_table_get_instance, \
81  snmp_table_get_next_instance }, \
82  (u16_t)LWIP_ARRAYSIZE(columns), (columns), \
83  (get_cell_instance_method), (get_next_cell_instance_method), \
84  (get_value_method), (set_test_method), (set_value_method)}
85 
86 #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 */
87 
88 
89 /** simple read-only table */
90 typedef enum {
91  SNMP_VARIANT_VALUE_TYPE_U32,
92  SNMP_VARIANT_VALUE_TYPE_S32,
93  SNMP_VARIANT_VALUE_TYPE_PTR,
94  SNMP_VARIANT_VALUE_TYPE_CONST_PTR
95 } snmp_table_column_data_type_t;
96 
97 struct snmp_table_simple_col_def
98 {
99  u32_t index;
100  u8_t asn1_type;
101  snmp_table_column_data_type_t data_type; /* depending of what union member is used to store the value*/
102 };
103 
104 /** simple read-only table node */
105 struct snmp_table_simple_node
106 {
107  /* inherited "base class" members */
108  struct snmp_leaf_node node;
109  u16_t column_count;
110  const struct snmp_table_simple_col_def* columns;
111  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);
112  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);
113 };
114 
115 snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
116 snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance);
117 
118 #define SNMP_TABLE_CREATE_SIMPLE(oid, columns, get_cell_value_method, get_next_cell_instance_and_value_method) \
119  {{{ SNMP_NODE_TABLE, (oid) }, \
120  snmp_table_simple_get_instance, \
121  snmp_table_simple_get_next_instance }, \
122  (u16_t)LWIP_ARRAYSIZE(columns), (columns), (get_cell_value_method), (get_next_cell_instance_and_value_method) }
123 
124 s16_t snmp_table_extract_value_from_s32ref(struct snmp_node_instance* instance, void* value);
125 s16_t snmp_table_extract_value_from_u32ref(struct snmp_node_instance* instance, void* value);
126 s16_t snmp_table_extract_value_from_refconstptr(struct snmp_node_instance* instance, void* value);
127 
128 #endif /* LWIP_SNMP */
129 
130 #ifdef __cplusplus
131 }
132 #endif
133 
134 #endif /* LWIP_HDR_APPS_SNMP_TABLE_H */
uint32_t u32_t
Definition: arch.h:129
uint8_t u8_t
Definition: arch.h:125
uint16_t u16_t
Definition: arch.h:127
int16_t s16_t
Definition: arch.h:128