1 | /*
|
---|
2 | * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without modification,
|
---|
6 | * are permitted provided that the following conditions are met:
|
---|
7 | *
|
---|
8 | * 1. Redistributions of source code must retain the above copyright notice,
|
---|
9 | * this list of conditions and the following disclaimer.
|
---|
10 | * 2. Redistributions in binary form must reproduce the above copyright notice,
|
---|
11 | * this list of conditions and the following disclaimer in the documentation
|
---|
12 | * and/or other materials provided with the distribution.
|
---|
13 | * 3. The name of the author may not be used to endorse or promote products
|
---|
14 | * derived from this software without specific prior written permission.
|
---|
15 | *
|
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
---|
17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
---|
18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
---|
19 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
20 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
---|
21 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
---|
22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
---|
23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
---|
24 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
25 | * OF SUCH DAMAGE.
|
---|
26 | *
|
---|
27 | * This file is part of the lwIP TCP/IP stack.
|
---|
28 | *
|
---|
29 | * Author: Martin Hentschel <info@cl-soft.de>
|
---|
30 | *
|
---|
31 | */
|
---|
32 |
|
---|
33 | using System;
|
---|
34 |
|
---|
35 | namespace LwipSnmpCodeGeneration
|
---|
36 | {
|
---|
37 | public static class LwipOpts
|
---|
38 | {
|
---|
39 | public static bool GenerateEmptyFolders = false;
|
---|
40 | /// <summary>
|
---|
41 | /// If a tree node only has scalar nodes as child nodes, it is replaced by
|
---|
42 | /// a single scalar array node in order to save memory and have only one single get/test/set method for all scalars.
|
---|
43 | /// </summary>
|
---|
44 | public static bool GenerateScalarArrays = true;
|
---|
45 | /// <summary>
|
---|
46 | /// If a tree node has multiple scalars as subnodes as well as other treenodes it
|
---|
47 | /// defines a single get/test/set method for all scalar child node.
|
---|
48 | /// (without other treenodes as child it would have been converted to scalar array node).
|
---|
49 | /// </summary>
|
---|
50 | public static bool GenerateSingleAccessMethodsForTreeNodeScalars = GenerateScalarArrays;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public static class LwipDefs
|
---|
54 | {
|
---|
55 | public const string Null = "NULL";
|
---|
56 | public const string Vt_U8 = "u8_t";
|
---|
57 | public const string Vt_U16 = "u16_t";
|
---|
58 | public const string Vt_U32 = "u32_t";
|
---|
59 | public const string Vt_S8 = "s8_t";
|
---|
60 | public const string Vt_S16 = "s16_t";
|
---|
61 | public const string Vt_S32 = "s32_t";
|
---|
62 | public const string Vt_Snmp_err = "snmp_err_t";
|
---|
63 |
|
---|
64 | public const string Incl_SnmpOpts = "lwip/apps/snmp_opts.h";
|
---|
65 | public const string Opt_SnmpEnabled = "LWIP_SNMP";
|
---|
66 |
|
---|
67 | public const string Vt_StMib = "struct snmp_mib";
|
---|
68 | public const string Vt_StObjectId = "struct snmp_obj_id";
|
---|
69 | public const string Vt_StNode = "struct snmp_node";
|
---|
70 | public const string Vt_StNodeInstance = "struct snmp_node_instance";
|
---|
71 | public const string Vt_StTreeNode = "struct snmp_tree_node";
|
---|
72 | public const string Vt_StScalarNode = "struct snmp_scalar_node";
|
---|
73 | public const string Vt_StScalarArrayNode = "struct snmp_scalar_array_node";
|
---|
74 | public const string Vt_StScalarArrayNodeDef = "struct snmp_scalar_array_node_def";
|
---|
75 | public const string Vt_StTableNode = "struct snmp_table_node";
|
---|
76 | public const string Vt_StTableColumnDef = "struct snmp_table_col_def";
|
---|
77 | public const string Vt_StNextOidState = "struct snmp_next_oid_state";
|
---|
78 |
|
---|
79 | public const string Def_NodeAccessReadOnly = "SNMP_NODE_INSTANCE_READ_ONLY";
|
---|
80 | public const string Def_NodeAccessReadWrite = "SNMP_NODE_INSTANCE_READ_WRITE";
|
---|
81 | public const string Def_NodeAccessWriteOnly = "SNMP_NODE_INSTANCE_WRITE_ONLY";
|
---|
82 | public const string Def_NodeAccessNotAccessible = "SNMP_NODE_INSTANCE_NOT_ACCESSIBLE";
|
---|
83 |
|
---|
84 | public const string Def_ErrorCode_Ok = "SNMP_ERR_NOERROR";
|
---|
85 | public const string Def_ErrorCode_WrongValue = "SNMP_ERR_WRONGVALUE";
|
---|
86 | public const string Def_ErrorCode_NoSuchInstance = "SNMP_ERR_NOSUCHINSTANCE";
|
---|
87 |
|
---|
88 | public const string FnctSuffix_GetValue = "_get_value";
|
---|
89 | public const string FnctSuffix_SetTest = "_set_test";
|
---|
90 | public const string FnctSuffix_SetValue = "_set_value";
|
---|
91 | public const string FnctSuffix_GetInstance = "_get_instance";
|
---|
92 | public const string FnctSuffix_GetNextInstance = "_get_next_instance";
|
---|
93 |
|
---|
94 | public const string FnctName_SetTest_Ok = "snmp_set_test_ok";
|
---|
95 |
|
---|
96 | public static string GetLwipDefForSnmpAccessMode(SnmpAccessMode am)
|
---|
97 | {
|
---|
98 | switch (am)
|
---|
99 | {
|
---|
100 | case SnmpAccessMode.ReadOnly: return Def_NodeAccessReadOnly;
|
---|
101 | case SnmpAccessMode.ReadWrite: return Def_NodeAccessReadWrite;
|
---|
102 | case SnmpAccessMode.NotAccessible: return Def_NodeAccessNotAccessible;
|
---|
103 | case SnmpAccessMode.WriteOnly: return Def_NodeAccessWriteOnly;
|
---|
104 | default: throw new NotSupportedException("Unknown SnmpAccessMode!");
|
---|
105 | }
|
---|
106 | }
|
---|
107 |
|
---|
108 | public static string GetAsn1DefForSnmpDataType(SnmpDataType dt)
|
---|
109 | {
|
---|
110 | switch (dt)
|
---|
111 | {
|
---|
112 | // primitive
|
---|
113 | case SnmpDataType.Null:
|
---|
114 | return "SNMP_ASN1_TYPE_NULL";
|
---|
115 | case SnmpDataType.Bits:
|
---|
116 | case SnmpDataType.OctetString:
|
---|
117 | return "SNMP_ASN1_TYPE_OCTET_STRING";
|
---|
118 | case SnmpDataType.ObjectIdentifier:
|
---|
119 | return "SNMP_ASN1_TYPE_OBJECT_ID";
|
---|
120 | case SnmpDataType.Integer:
|
---|
121 | return "SNMP_ASN1_TYPE_INTEGER";
|
---|
122 |
|
---|
123 | // application
|
---|
124 | case SnmpDataType.IpAddress:
|
---|
125 | return "SNMP_ASN1_TYPE_IPADDR";
|
---|
126 | case SnmpDataType.Counter:
|
---|
127 | return "SNMP_ASN1_TYPE_COUNTER";
|
---|
128 | case SnmpDataType.Gauge:
|
---|
129 | return "SNMP_ASN1_TYPE_GAUGE";
|
---|
130 | case SnmpDataType.TimeTicks:
|
---|
131 | return "SNMP_ASN1_TYPE_TIMETICKS";
|
---|
132 | case SnmpDataType.Opaque:
|
---|
133 | return "SNMP_ASN1_TYPE_OPAQUE";
|
---|
134 | case SnmpDataType.Counter64:
|
---|
135 | return "SNMP_ASN1_TYPE_COUNTER64";
|
---|
136 | default:
|
---|
137 | throw new NotSupportedException("Unknown SnmpDataType!");
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | public static string GetLengthForSnmpDataType(SnmpDataType dt)
|
---|
142 | {
|
---|
143 | switch (dt)
|
---|
144 | {
|
---|
145 | case SnmpDataType.Null:
|
---|
146 | return "0";
|
---|
147 |
|
---|
148 | case SnmpDataType.Integer:
|
---|
149 | case SnmpDataType.Counter:
|
---|
150 | case SnmpDataType.IpAddress:
|
---|
151 | case SnmpDataType.Gauge:
|
---|
152 | case SnmpDataType.TimeTicks:
|
---|
153 | return "4";
|
---|
154 |
|
---|
155 | case SnmpDataType.Counter64:
|
---|
156 | return "8";
|
---|
157 |
|
---|
158 | case SnmpDataType.OctetString:
|
---|
159 | case SnmpDataType.ObjectIdentifier:
|
---|
160 | case SnmpDataType.Bits:
|
---|
161 | case SnmpDataType.Opaque:
|
---|
162 | return null;
|
---|
163 |
|
---|
164 | default:
|
---|
165 | throw new NotSupportedException("Unknown SnmpDataType!");
|
---|
166 | }
|
---|
167 | }
|
---|
168 | }
|
---|
169 |
|
---|
170 | public enum SnmpDataType
|
---|
171 | {
|
---|
172 | Null,
|
---|
173 |
|
---|
174 | Integer, // INTEGER, Integer32
|
---|
175 |
|
---|
176 | Counter, // Counter, Counter32
|
---|
177 | Gauge, // Gauge, Gauge32, Unsigned32
|
---|
178 | TimeTicks,
|
---|
179 |
|
---|
180 | Counter64,
|
---|
181 |
|
---|
182 | OctetString,
|
---|
183 | Opaque,
|
---|
184 | Bits,
|
---|
185 |
|
---|
186 | ObjectIdentifier,
|
---|
187 |
|
---|
188 | IpAddress,
|
---|
189 | }
|
---|
190 |
|
---|
191 | public enum SnmpAccessMode
|
---|
192 | {
|
---|
193 | ReadOnly,
|
---|
194 | ReadWrite,
|
---|
195 | WriteOnly,
|
---|
196 | NotAccessible
|
---|
197 | }
|
---|
198 |
|
---|
199 | }
|
---|