Marco Zecchini
/
Example_RTOS
Rtos API example
Embed:
(wiki syntax)
Show/hide line numbers
snmp_asn1.h
Go to the documentation of this file.
00001 /** 00002 * @file 00003 * Abstract Syntax Notation One (ISO 8824, 8825) codec. 00004 */ 00005 00006 /* 00007 * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands. 00008 * Copyright (c) 2016 Elias Oenal. 00009 * All rights reserved. 00010 * 00011 * Redistribution and use in source and binary forms, with or without modification, 00012 * are permitted provided that the following conditions are met: 00013 * 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. The name of the author may not be used to endorse or promote products 00020 * derived from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 00023 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 00025 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 00027 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00028 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00029 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 00030 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 00031 * OF SUCH DAMAGE. 00032 * 00033 * Author: Christiaan Simons <christiaan.simons@axon.tv> 00034 * Martin Hentschel <info@cl-soft.de> 00035 * Elias Oenal <lwip@eliasoenal.com> 00036 */ 00037 00038 #ifndef LWIP_HDR_APPS_SNMP_ASN1_H 00039 #define LWIP_HDR_APPS_SNMP_ASN1_H 00040 00041 #include "lwip/apps/snmp_opts.h" 00042 00043 #if LWIP_SNMP 00044 00045 #include "lwip/err.h" 00046 #include "lwip/apps/snmp_core.h" 00047 #include "snmp_pbuf_stream.h" 00048 00049 #ifdef __cplusplus 00050 extern "C" { 00051 #endif 00052 00053 #define SNMP_ASN1_TLV_INDEFINITE_LENGTH 0x80 00054 00055 #define SNMP_ASN1_CLASS_MASK 0xC0 00056 #define SNMP_ASN1_CONTENTTYPE_MASK 0x20 00057 #define SNMP_ASN1_DATATYPE_MASK 0x1F 00058 #define SNMP_ASN1_DATATYPE_EXTENDED 0x1F /* DataType indicating that datatype is encoded in following bytes */ 00059 00060 /* context specific (SNMP) tags (from SNMP spec. RFC1157) */ 00061 #define SNMP_ASN1_CONTEXT_PDU_GET_REQ 0 00062 #define SNMP_ASN1_CONTEXT_PDU_GET_NEXT_REQ 1 00063 #define SNMP_ASN1_CONTEXT_PDU_GET_RESP 2 00064 #define SNMP_ASN1_CONTEXT_PDU_SET_REQ 3 00065 #define SNMP_ASN1_CONTEXT_PDU_TRAP 4 00066 #define SNMP_ASN1_CONTEXT_PDU_GET_BULK_REQ 5 00067 00068 #define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0 00069 #define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2 00070 00071 struct snmp_asn1_tlv 00072 { 00073 u8_t type; /* only U8 because extended types are not specified by SNMP */ 00074 u8_t type_len; /* encoded length of 'type' field (normally 1) */ 00075 u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */ 00076 u16_t value_len; /* encoded length of the value */ 00077 }; 00078 #define SNMP_ASN1_TLV_HDR_LENGTH(tlv) ((tlv).type_len + (tlv).length_len) 00079 #define SNMP_ASN1_TLV_LENGTH(tlv) ((tlv).type_len + (tlv).length_len + (tlv).value_len) 00080 #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); 00081 00082 err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv); 00083 err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value); 00084 err_t snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value); 00085 err_t snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value); 00086 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); 00087 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); 00088 00089 err_t snmp_ans1_enc_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv); 00090 00091 void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed); 00092 void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed); 00093 void snmp_asn1_enc_u64t_cnt(const u32_t *value, u16_t *octets_needed); 00094 void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed); 00095 void snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed); 00096 err_t snmp_asn1_enc_oid(struct snmp_pbuf_stream* pbuf_stream, const u32_t *oid, u16_t oid_len); 00097 err_t snmp_asn1_enc_s32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, s32_t value); 00098 err_t snmp_asn1_enc_u32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u32_t value); 00099 err_t snmp_asn1_enc_u64t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, const u32_t* value); 00100 err_t snmp_asn1_enc_raw(struct snmp_pbuf_stream* pbuf_stream, const u8_t *raw, u16_t raw_len); 00101 00102 #ifdef __cplusplus 00103 } 00104 #endif 00105 00106 #endif /* LWIP_SNMP */ 00107 00108 #endif /* LWIP_HDR_APPS_SNMP_ASN1_H */
Generated on Sun Jul 17 2022 08:25:30 by 1.7.2