STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
snmp_asn1.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
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  * Author: Christiaan Simons <christiaan.simons@axon.tv>
33  * Martin Hentschel <info@cl-soft.de>
34  */
35 
36 #ifndef LWIP_HDR_APPS_SNMP_ASN1_H
37 #define LWIP_HDR_APPS_SNMP_ASN1_H
38 
39 #include "lwip/apps/snmp_opts.h"
40 
41 #if LWIP_SNMP
42 
43 #include "lwip/err.h"
44 #include "lwip/apps/snmp_core.h"
45 #include "snmp_pbuf_stream.h"
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #define SNMP_ASN1_TLV_INDEFINITE_LENGTH 0x80
52 
53 #define SNMP_ASN1_CLASS_MASK 0xC0
54 #define SNMP_ASN1_CONTENTTYPE_MASK 0x20
55 #define SNMP_ASN1_DATATYPE_MASK 0x1F
56 #define SNMP_ASN1_DATATYPE_EXTENDED 0x1F /* DataType indicating that datatype is encoded in following bytes */
57 
58 /* context specific (SNMP) tags (from SNMP spec. RFC1157) */
59 #define SNMP_ASN1_CONTEXT_PDU_GET_REQ 0
60 #define SNMP_ASN1_CONTEXT_PDU_GET_NEXT_REQ 1
61 #define SNMP_ASN1_CONTEXT_PDU_GET_RESP 2
62 #define SNMP_ASN1_CONTEXT_PDU_SET_REQ 3
63 #define SNMP_ASN1_CONTEXT_PDU_TRAP 4
64 #define SNMP_ASN1_CONTEXT_PDU_GET_BULK_REQ 5
65 
66 #define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0
67 #define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2
68 
69 struct snmp_asn1_tlv
70 {
71  u8_t type; /* only U8 because extended types are not specified by SNMP */
72  u8_t type_len; /* encoded length of 'type' field (normally 1) */
73  u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */
74  u16_t value_len; /* encoded length of the value */
75 };
76 #define SNMP_ASN1_TLV_LENGTH(tlv) ((tlv).type_len + (tlv).length_len + (tlv).value_len)
77 #define SNMP_ASN1_SET_TLV_PARAMS(tlv, type_, length_len_, value_len_) do { (tlv).type = (type_); (tlv).type_len = 0; (tlv).length_len = (length_len_); (tlv).value_len = (value_len_); } while (0);
78 
79 err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv);
80 err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value);
81 err_t snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value);
82 err_t snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value);
83 err_t snmp_asn1_dec_oid(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t* oid, u8_t* oid_len, u8_t oid_max_len);
84 err_t snmp_asn1_dec_raw(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u8_t *buf, u16_t* buf_len, u16_t buf_max_len);
85 
86 err_t snmp_ans1_enc_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv);
87 
88 void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed);
89 void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed);
90 void snmp_asn1_enc_u64t_cnt(const u32_t *value, u16_t *octets_needed);
91 void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed);
92 void snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed);
93 err_t snmp_asn1_enc_oid(struct snmp_pbuf_stream* pbuf_stream, const u32_t *oid, u16_t oid_len);
94 err_t snmp_asn1_enc_s32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, s32_t value);
95 err_t snmp_asn1_enc_u32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u32_t value);
96 err_t snmp_asn1_enc_u64t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, const u32_t* value);
97 err_t snmp_asn1_enc_raw(struct snmp_pbuf_stream* pbuf_stream, const u8_t *raw, u16_t raw_len);
98 
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #endif /* LWIP_SNMP */
104 
105 #endif /* LWIP_HDR_APPS_SNMP_ASN1_H */
unsigned long u32_t
Definition: cc.h:42
s8_t err_t
Definition: err.h:47
unsigned char u8_t
Definition: cc.h:38
signed long s32_t
Definition: cc.h:43
unsigned short u16_t
Definition: cc.h:40