snmp_asn1.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file
  3. * Abstract Syntax Notation One (ISO 8824, 8825) codec.
  4. */
  5. /*
  6. * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. The name of the author may not be used to endorse or promote products
  18. * derived from this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  21. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  22. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  23. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  25. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  28. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. * OF SUCH DAMAGE.
  30. *
  31. * Author: Christiaan Simons <christiaan.simons@axon.tv>
  32. */
  33. #ifndef __LWIP_SNMP_ASN1_H__
  34. #define __LWIP_SNMP_ASN1_H__
  35. #include "lwip/opt.h"
  36. #include "lwip/err.h"
  37. #include "lwip/pbuf.h"
  38. #include "lwip/snmp.h"
  39. #if LWIP_SNMP
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. #define SNMP_ASN1_UNIV (0) /* (!0x80 | !0x40) */
  44. #define SNMP_ASN1_APPLIC (0x40) /* (!0x80 | 0x40) */
  45. #define SNMP_ASN1_CONTXT (0x80) /* ( 0x80 | !0x40) */
  46. #define SNMP_ASN1_CONSTR (0x20) /* ( 0x20) */
  47. #define SNMP_ASN1_PRIMIT (0) /* (!0x20) */
  48. /* universal tags */
  49. #define SNMP_ASN1_INTEG 2
  50. #define SNMP_ASN1_OC_STR 4
  51. #define SNMP_ASN1_NUL 5
  52. #define SNMP_ASN1_OBJ_ID 6
  53. #define SNMP_ASN1_SEQ 16
  54. /* application specific (SNMP) tags */
  55. #define SNMP_ASN1_IPADDR 0 /* octet string size(4) */
  56. #define SNMP_ASN1_COUNTER 1 /* u32_t */
  57. #define SNMP_ASN1_GAUGE 2 /* u32_t */
  58. #define SNMP_ASN1_TIMETICKS 3 /* u32_t */
  59. #define SNMP_ASN1_OPAQUE 4 /* octet string */
  60. /* context specific (SNMP) tags */
  61. #define SNMP_ASN1_PDU_GET_REQ 0
  62. #define SNMP_ASN1_PDU_GET_NEXT_REQ 1
  63. #define SNMP_ASN1_PDU_GET_RESP 2
  64. #define SNMP_ASN1_PDU_SET_REQ 3
  65. #define SNMP_ASN1_PDU_TRAP 4
  66. err_t snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type);
  67. err_t snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length);
  68. err_t snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value);
  69. err_t snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value);
  70. err_t snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid);
  71. err_t snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw);
  72. void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed);
  73. void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed);
  74. void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed);
  75. void snmp_asn1_enc_oid_cnt(u8_t ident_len, s32_t *ident, u16_t *octets_needed);
  76. err_t snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type);
  77. err_t snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length);
  78. err_t snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value);
  79. err_t snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value);
  80. err_t snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u8_t ident_len, s32_t *ident);
  81. err_t snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, u8_t *raw);
  82. #ifdef __cplusplus
  83. }
  84. #endif
  85. #endif /* LWIP_SNMP */
  86. #endif /* __LWIP_SNMP_ASN1_H__ */