46 #define LOG_MODULE "SNMP [message]" 47 #define LOG_LEVEL LOG_LEVEL_SNMP 54 uint32_t original_out_len, last_out_len;
57 original_out_len = *out_len;
58 for(i = varbind_num - 1; i >= 0; i--) {
59 varbind = &varbinds[i];
61 last_out_len = *out_len;
64 case BER_DATA_TYPE_INTEGER:
67 case SNMP_DATA_TYPE_TIME_TICKS:
70 case BER_DATA_TYPE_OCTET_STRING:
73 case BER_DATA_TYPE_OID:
76 case BER_DATA_TYPE_NULL:
77 case SNMP_DATA_TYPE_NO_SUCH_INSTANCE:
78 case SNMP_DATA_TYPE_END_OF_MIB_VIEW:
93 if(header->
pdu_type == SNMP_DATA_TYPE_PDU_GET_BULK) {
122 LOG_DBG(
"Could not decode type\n");
126 if(type != BER_DATA_TYPE_SEQUENCE) {
127 LOG_DBG(
"Invalid type\n");
133 LOG_DBG(
"Could not decode length\n");
139 LOG_DBG(
"Could not decode version\n");
145 LOG_DBG(
"Could not decode community\n");
151 LOG_DBG(
"Invalid version\n");
157 LOG_DBG(
"Could not decode type\n");
162 if(header->
pdu_type != SNMP_DATA_TYPE_PDU_GET_REQUEST &&
163 header->
pdu_type != SNMP_DATA_TYPE_PDU_GET_NEXT_REQUEST &&
164 header->
pdu_type != SNMP_DATA_TYPE_PDU_GET_RESPONSE &&
165 header->
pdu_type != SNMP_DATA_TYPE_PDU_SET_REQUEST &&
166 header->
pdu_type != SNMP_DATA_TYPE_PDU_GET_BULK) {
167 LOG_DBG(
"Invalid pdu type\n");
173 LOG_DBG(
"Could not decode length\n");
179 LOG_DBG(
"Could not decode request id\n");
183 if(header->
pdu_type == SNMP_DATA_TYPE_PDU_GET_BULK) {
186 LOG_DBG(
"Could not decode error status\n");
192 LOG_DBG(
"Could not decode error index\n");
198 LOG_DBG(
"Could not decode error status\n");
204 LOG_DBG(
"Could not decode error index\n");
211 LOG_DBG(
"Could not decode type\n");
215 if(type != BER_DATA_TYPE_SEQUENCE) {
216 LOG_DBG(
"Invalid type\n");
222 LOG_DBG(
"Could not decode length\n");
226 for(i = 0; buf_len > 0; ++i) {
230 LOG_DBG(
"Could not decode type\n");
234 if(type != BER_DATA_TYPE_SEQUENCE) {
235 LOG_DBG(
"Invalid (%X) type\n", type);
241 LOG_DBG(
"Could not decode length\n");
247 LOG_DBG(
"Could not decode oid\n");
253 switch(varbinds[i].value_type) {
254 case BER_DATA_TYPE_INTEGER:
257 case SNMP_DATA_TYPE_TIME_TICKS:
260 case BER_DATA_TYPE_OCTET_STRING:
263 case BER_DATA_TYPE_NULL:
267 LOG_DBG(
"Invalid varbind type\n");
272 LOG_DBG(
"Could varbind type\n");
unsigned char * snmp_ber_encode_string_len(unsigned char *out, uint32_t *out_len, const char *str, uint32_t length)
Encodes a string.
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
uint8_t * snmp_oid_decode_oid(uint8_t *buf, uint32_t *buff_len, uint32_t *oid, uint32_t *oid_len)
Decodes a Oid.
unsigned char * snmp_ber_decode_type(unsigned char *buff, uint32_t *buff_len, uint8_t *type)
Decodes a type.
uint32_t length
The string length.
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
unsigned char * snmp_ber_encode_null(unsigned char *out, uint32_t *out_len, uint8_t type)
Encodes a null.
#define SNMP_VERSION_1
SNMP Version 1 code.
uint32_t oid[SNMP_MSG_OID_MAX_LEN]
The OID.
unsigned char * snmp_ber_decode_null(unsigned char *buf, uint32_t *buff_len)
Decodes a null.
An implementation of the Simple Network Management Protocol (RFC 3411-3418)
unsigned char * snmp_ber_encode_length(unsigned char *out, uint32_t *out_len, uint8_t length)
Encodes the length.
const char * string
A pointer to the string value from this varbind.
unsigned char * snmp_ber_decode_length(unsigned char *buff, uint32_t *buff_len, uint8_t *length)
Decodes a length.
unsigned char * snmp_ber_encode_integer(unsigned char *out, uint32_t *out_len, uint32_t number)
Encodes an integer.
uint8_t value_type
The type in this varbind.
uint32_t * oid
A pointer to the beggining of a oid array.
#define SNMP_VERSION_2C
SNMP Version 2c code.
unsigned char * snmp_ber_decode_unsigned_integer(unsigned char *buf, uint32_t *buff_len, uint8_t expected_type, uint32_t *num)
Decodes an unsigned number.
unsigned char * snmp_ber_encode_unsigned_integer(unsigned char *out, uint32_t *out_len, uint8_t type, uint32_t number)
Encodes an unsigned integer.
unsigned char * snmp_ber_decode_integer(unsigned char *buf, uint32_t *buff_len, uint32_t *num)
Decodes an integer.
unsigned char * snmp_message_encode(unsigned char *out, uint32_t *out_len, snmp_header_t *header, snmp_varbind_t *varbinds, uint32_t varbind_num)
Encodes a SNMP message.
uint32_t * oid
A array that represents the OID.
unsigned char * snmp_ber_decode_string_len_buffer(unsigned char *buf, uint32_t *buff_len, const char **str, uint32_t *length)
Decodes a string.
uint32_t integer
The integer value.
unsigned char * snmp_oid_encode_oid(unsigned char *out, uint32_t *out_len, uint32_t *oid)
Encodes a Oid.
uint8_t * snmp_message_decode(uint8_t *buf, uint32_t buf_len, snmp_header_t *header, snmp_varbind_t *varbinds, uint32_t *varbind_num)
unsigned char * snmp_ber_encode_type(unsigned char *out, uint32_t *out_len, uint8_t type)
Encodes a type.