LwipSnmp.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. using System;
  33. namespace LwipSnmpCodeGeneration
  34. {
  35. public static class LwipOpts
  36. {
  37. public static bool GenerateEmptyFolders = false;
  38. /// <summary>
  39. /// If a tree node only has scalar nodes as child nodes, it is replaced by
  40. /// a single scalar array node in order to save memory and have only one single get/test/set method for all scalars.
  41. /// </summary>
  42. public static bool GenerateScalarArrays = true;
  43. /// <summary>
  44. /// If a tree node has multiple scalars as subnodes as well as other treenodes it
  45. /// defines a single get/test/set method for all scalar child node.
  46. /// (without other treenodes as child it would have been converted to scalar array node).
  47. /// </summary>
  48. public static bool GenerateSingleAccessMethodsForTreeNodeScalars = GenerateScalarArrays;
  49. }
  50. public static class LwipDefs
  51. {
  52. public const string Null = "NULL";
  53. public const string Vt_U8 = "u8_t";
  54. public const string Vt_U16 = "u16_t";
  55. public const string Vt_U32 = "u32_t";
  56. public const string Vt_S8 = "s8_t";
  57. public const string Vt_S16 = "s16_t";
  58. public const string Vt_S32 = "s32_t";
  59. public const string Vt_Snmp_err = "snmp_err_t";
  60. public const string Incl_SnmpOpts = "lwip/apps/snmp_opts.h";
  61. public const string Opt_SnmpEnabled = "LWIP_SNMP";
  62. public const string Vt_StMib = "struct snmp_mib";
  63. public const string Vt_StObjectId = "struct snmp_obj_id";
  64. public const string Vt_StNode = "struct snmp_node";
  65. public const string Vt_StNodeInstance = "struct snmp_node_instance";
  66. public const string Vt_StTreeNode = "struct snmp_tree_node";
  67. public const string Vt_StScalarNode = "struct snmp_scalar_node";
  68. public const string Vt_StScalarArrayNode = "struct snmp_scalar_array_node";
  69. public const string Vt_StScalarArrayNodeDef = "struct snmp_scalar_array_node_def";
  70. public const string Vt_StTableNode = "struct snmp_table_node";
  71. public const string Vt_StTableColumnDef = "struct snmp_table_col_def";
  72. public const string Vt_StNextOidState = "struct snmp_next_oid_state";
  73. public const string Def_NodeAccessReadOnly = "SNMP_NODE_INSTANCE_READ_ONLY";
  74. public const string Def_NodeAccessReadWrite = "SNMP_NODE_INSTANCE_READ_WRITE";
  75. public const string Def_NodeAccessWriteOnly = "SNMP_NODE_INSTANCE_WRITE_ONLY";
  76. public const string Def_NodeAccessNotAccessible = "SNMP_NODE_INSTANCE_NOT_ACCESSIBLE";
  77. public const string Def_ErrorCode_Ok = "SNMP_ERR_NOERROR";
  78. public const string Def_ErrorCode_WrongValue = "SNMP_ERR_WRONGVALUE";
  79. public const string Def_ErrorCode_NoSuchInstance = "SNMP_ERR_NOSUCHINSTANCE";
  80. public const string FnctSuffix_GetValue = "_get_value";
  81. public const string FnctSuffix_SetTest = "_set_test";
  82. public const string FnctSuffix_SetValue = "_set_value";
  83. public const string FnctSuffix_GetInstance = "_get_instance";
  84. public const string FnctSuffix_GetNextInstance = "_get_next_instance";
  85. public const string FnctName_SetTest_Ok = "snmp_set_test_ok";
  86. public static string GetLwipDefForSnmpAccessMode(SnmpAccessMode am)
  87. {
  88. switch (am)
  89. {
  90. case SnmpAccessMode.ReadOnly: return Def_NodeAccessReadOnly;
  91. case SnmpAccessMode.ReadWrite: return Def_NodeAccessReadWrite;
  92. case SnmpAccessMode.NotAccessible: return Def_NodeAccessNotAccessible;
  93. case SnmpAccessMode.WriteOnly: return Def_NodeAccessWriteOnly;
  94. default: throw new NotSupportedException("Unknown SnmpAccessMode!");
  95. }
  96. }
  97. public static string GetAsn1DefForSnmpDataType(SnmpDataType dt)
  98. {
  99. switch (dt)
  100. {
  101. // primitive
  102. case SnmpDataType.Null:
  103. return "SNMP_ASN1_TYPE_NULL";
  104. case SnmpDataType.Bits:
  105. case SnmpDataType.OctetString:
  106. return "SNMP_ASN1_TYPE_OCTET_STRING";
  107. case SnmpDataType.ObjectIdentifier:
  108. return "SNMP_ASN1_TYPE_OBJECT_ID";
  109. case SnmpDataType.Integer:
  110. return "SNMP_ASN1_TYPE_INTEGER";
  111. // application
  112. case SnmpDataType.IpAddress:
  113. return "SNMP_ASN1_TYPE_IPADDR";
  114. case SnmpDataType.Counter:
  115. return "SNMP_ASN1_TYPE_COUNTER";
  116. case SnmpDataType.Gauge:
  117. return "SNMP_ASN1_TYPE_GAUGE";
  118. case SnmpDataType.TimeTicks:
  119. return "SNMP_ASN1_TYPE_TIMETICKS";
  120. case SnmpDataType.Opaque:
  121. return "SNMP_ASN1_TYPE_OPAQUE";
  122. case SnmpDataType.Counter64:
  123. return "SNMP_ASN1_TYPE_COUNTER64";
  124. default:
  125. throw new NotSupportedException("Unknown SnmpDataType!");
  126. }
  127. }
  128. public static string GetLengthForSnmpDataType(SnmpDataType dt)
  129. {
  130. switch (dt)
  131. {
  132. case SnmpDataType.Null:
  133. return "0";
  134. case SnmpDataType.Integer:
  135. case SnmpDataType.Counter:
  136. case SnmpDataType.IpAddress:
  137. case SnmpDataType.Gauge:
  138. case SnmpDataType.TimeTicks:
  139. return "4";
  140. case SnmpDataType.Counter64:
  141. return "8";
  142. case SnmpDataType.OctetString:
  143. case SnmpDataType.ObjectIdentifier:
  144. case SnmpDataType.Bits:
  145. case SnmpDataType.Opaque:
  146. return null;
  147. default:
  148. throw new NotSupportedException("Unknown SnmpDataType!");
  149. }
  150. }
  151. }
  152. public enum SnmpDataType
  153. {
  154. Null,
  155. Integer, // INTEGER, Integer32
  156. Counter, // Counter, Counter32
  157. Gauge, // Gauge, Gauge32, Unsigned32
  158. TimeTicks,
  159. Counter64,
  160. OctetString,
  161. Opaque,
  162. Bits,
  163. ObjectIdentifier,
  164. IpAddress,
  165. }
  166. public enum SnmpAccessMode
  167. {
  168. ReadOnly,
  169. ReadWrite,
  170. WriteOnly,
  171. NotAccessible
  172. }
  173. }