snmp.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #ifndef PRO_SNMP_H
  2. #define PRO_SNMP_H
  3. /*
  4. * Copyright 1998-2007 by egnite Software GmbH
  5. * Copyright 1988, 1989, 1991, 1992 by Carnegie Mellon University
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. * 3. Neither the name of the copyright holders nor the names of
  17. * contributors may be used to endorse or promote products derived
  18. * from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  23. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  24. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  25. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  26. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  27. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  28. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  30. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * For additional information see http://www.ethernut.de/
  34. */
  35. /*!
  36. * \file pro/snmp.h
  37. * \brief Definitions for Simple Network Management Protocol.
  38. *
  39. * \verbatim
  40. * $Id: snmp.h 4473 2012-08-20 15:12:45Z haraldkipp $
  41. * \endverbatim
  42. */
  43. #include <pro/asn1.h>
  44. /*!
  45. * \addtogroup xgSNMP
  46. */
  47. /*@{*/
  48. #ifndef SNMP_PORT
  49. /*! \brief Standard UDP port for SNMP agents to receive requests messages.
  50. */
  51. #define SNMP_PORT 161
  52. #endif
  53. #ifndef SNMP_TRAP_PORT
  54. /*! \brief Standard UDP port for SNMP managers to receive notificaion messages.
  55. */
  56. #define SNMP_TRAP_PORT 162
  57. #endif
  58. #ifndef SNMP_MAX_LEN
  59. /*! \brief Default maximum message size.
  60. */
  61. #define SNMP_MAX_LEN 500
  62. #endif
  63. /*! \brief SNMPv1.
  64. *
  65. * The original version, defined by RFC 1157.
  66. */
  67. #define SNMP_VERSION_1 0
  68. /*! \brief SNMPv2c.
  69. *
  70. * Community string-based SNMPv2, which was an attempt to combine the
  71. * protocol operations of SNMPv2 with the security of SNMPv1, defined
  72. * by RFCs 1901, 1905, and 1906.
  73. *
  74. * Partly supplied by this code, work is in progress.
  75. */
  76. #define SNMP_VERSION_2C 1
  77. /*! \brief SNMPv3.
  78. *
  79. * An attempt by the IETF working group to merge the SNMPv2u and SNMPv2*
  80. * proposals into a more widely accepted SNMPv3. The original version,
  81. * defined by RFC 1157.
  82. *
  83. * Not yet supported by this code.
  84. */
  85. #define SNMP_VERSION_3 3
  86. /*
  87. * PDU types in SNMPv1, SNMPv2c and SNMPv3.
  88. */
  89. #define SNMP_MSG_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)
  90. #define SNMP_MSG_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)
  91. #define SNMP_MSG_RESPONSE (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)
  92. #define SNMP_MSG_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)
  93. /*
  94. * PDU types in SNMPv1.
  95. */
  96. #define SNMP_MSG_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
  97. /*
  98. * PDU types in SNMPv2c and SNMPv3
  99. */
  100. #define SNMP_MSG_GETBULK (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)
  101. #define SNMP_MSG_INFORM (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)
  102. #define SNMP_MSG_TRAP2 (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)
  103. /*
  104. * PDU types in SNMPv3
  105. */
  106. #define SNMP_MSG_REPORT (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)
  107. /*
  108. * Exception values for SNMPv2c and SNMPv3
  109. */
  110. #define SNMP_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)
  111. #define SNMP_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)
  112. #define SNMP_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)
  113. /*
  114. * Error codes in SNMPv1, SNMPv2c and SNMPv3 PDUs.
  115. */
  116. #define SNMP_ERR_NOERROR 0
  117. #define SNMP_ERR_TOOBIG 1
  118. #define SNMP_ERR_NOSUCHNAME 2
  119. #define SNMP_ERR_BADVALUE 3
  120. #define SNMP_ERR_READONLY 4
  121. #define SNMP_ERR_GENERR 5
  122. /*
  123. * Error codes in SNMPv2c and SNMPv3 PDUs.
  124. */
  125. #define SNMP_ERR_NOACCESS 6
  126. #define SNMP_ERR_WRONGTYPE 7
  127. #define SNMP_ERR_WRONGLENGTH 8
  128. #define SNMP_ERR_WRONGENCODING 9
  129. #define SNMP_ERR_WRONGVALUE 10
  130. #define SNMP_ERR_NOCREATION 11
  131. #define SNMP_ERR_INCONSISTENTVALUE 12
  132. #define SNMP_ERR_RESOURCEUNAVAILABLE 13
  133. #define SNMP_ERR_COMMITFAILED 14
  134. #define SNMP_ERR_UNDOFAILED 15
  135. #define SNMP_ERR_AUTHORIZATIONERROR 16
  136. #define SNMP_ERR_NOTWRITABLE 17
  137. #define SNMP_ERR_INCONSISTENTNAME 18
  138. /*
  139. * Values of the generic-trap field in trap PDUs.
  140. */
  141. #define SNMP_TRAP_COLDSTART 0
  142. #define SNMP_TRAP_WARMSTART 1
  143. #define SNMP_TRAP_LINKDOWN 2
  144. #define SNMP_TRAP_LINKUP 3
  145. #define SNMP_TRAP_AUTHFAIL 4
  146. #define SNMP_TRAP_EGPNEIGHBORLOSS 5
  147. #define SNMP_TRAP_ENTERPRISESPECIFIC 6
  148. /*
  149. * Basic OID values
  150. */
  151. #define SNMP_OID_INTERNET 1, 3, 6, 1
  152. #define SNMP_OID_ENTERPRISES SNMP_OID_INTERNET, 4, 1
  153. #define SNMP_OID_MIB2 SNMP_OID_INTERNET, 2, 1
  154. #define SNMP_OID_SNMPV2 SNMP_OID_INTERNET, 6
  155. #define SNMP_OID_SNMPMODULES SNMP_OID_SNMPV2, 3
  156. #define SNMP_PARSE_ERROR -1
  157. #define SNMP_BUILD_ERROR -2
  158. /*! \brief Maximum length of a community name. */
  159. #define MAX_SID_LEN 32
  160. /*! \brief Maximum number of sub IDs in an OID. */
  161. #define MAX_NAME_LEN 128
  162. #define SNMP_ACT_RESERVE1 0
  163. #define SNMP_ACT_RESERVE2 1
  164. #define SNMP_ACT_COMMIT 2
  165. #define SNMP_ACT_ACTION 3
  166. #define SNMP_ACT_FREE 4
  167. /*@}*/
  168. extern const uint8_t *SnmpVarParse(const uint8_t *, size_t *, OID *, size_t *, uint8_t *, uint8_t **, size_t *);
  169. extern uint8_t *SnmpVarBuild(uint8_t *, size_t *, const OID *, size_t, uint8_t , const uint8_t *, size_t);
  170. #endif