Reformat SNMP code using astylerc

This commit is contained in:
Dirk Ziegelmeier 2017-09-17 20:29:18 +02:00
parent 6e7fe4520a
commit 3ed24085fa
27 changed files with 1291 additions and 1325 deletions

View File

@ -54,7 +54,7 @@
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode * @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode
*/ */
err_t err_t
snmp_ans1_enc_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv) snmp_ans1_enc_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv)
{ {
u8_t data; u8_t data;
u8_t length_bytes_required; u8_t length_bytes_required;
@ -130,7 +130,7 @@ snmp_ans1_enc_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tl
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode * @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode
*/ */
err_t err_t
snmp_asn1_enc_raw(struct snmp_pbuf_stream* pbuf_stream, const u8_t *raw, u16_t raw_len) snmp_asn1_enc_raw(struct snmp_pbuf_stream *pbuf_stream, const u8_t *raw, u16_t raw_len)
{ {
PBUF_OP_EXEC(snmp_pbuf_stream_writebuf(pbuf_stream, raw, raw_len)); PBUF_OP_EXEC(snmp_pbuf_stream_writebuf(pbuf_stream, raw, raw_len));
@ -148,7 +148,7 @@ snmp_asn1_enc_raw(struct snmp_pbuf_stream* pbuf_stream, const u8_t *raw, u16_t r
* @see snmp_asn1_enc_u32t_cnt() * @see snmp_asn1_enc_u32t_cnt()
*/ */
err_t err_t
snmp_asn1_enc_u32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u32_t value) snmp_asn1_enc_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u32_t value)
{ {
if (octets_needed > 5) { if (octets_needed > 5) {
return ERR_ARG; return ERR_ARG;
@ -180,7 +180,7 @@ snmp_asn1_enc_u32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u3
* @see snmp_asn1_enc_s32t_cnt() * @see snmp_asn1_enc_s32t_cnt()
*/ */
err_t err_t
snmp_asn1_enc_s32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, s32_t value) snmp_asn1_enc_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, s32_t value)
{ {
while (octets_needed > 1) { while (octets_needed > 1) {
octets_needed--; octets_needed--;
@ -203,7 +203,7 @@ snmp_asn1_enc_s32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, s3
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode * @return ERR_OK if successful, ERR_ARG if we can't (or won't) encode
*/ */
err_t err_t
snmp_asn1_enc_oid(struct snmp_pbuf_stream* pbuf_stream, const u32_t *oid, u16_t oid_len) snmp_asn1_enc_oid(struct snmp_pbuf_stream *pbuf_stream, const u32_t *oid, u16_t oid_len)
{ {
if (oid_len > 1) { if (oid_len > 1) {
/* write compressed first two sub id's */ /* write compressed first two sub id's */
@ -353,7 +353,7 @@ snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed)
* @return ERR_OK if successful, ERR_VAL if we can't decode * @return ERR_OK if successful, ERR_VAL if we can't decode
*/ */
err_t err_t
snmp_asn1_dec_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv) snmp_asn1_dec_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv)
{ {
u8_t data; u8_t data;
@ -495,7 +495,7 @@ snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) decode * @return ERR_OK if successful, ERR_ARG if we can't (or won't) decode
*/ */
err_t 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) 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)
{ {
u32_t *oid_ptr; u32_t *oid_ptr;
u8_t data; u8_t data;
@ -586,7 +586,7 @@ snmp_asn1_dec_oid(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t* oid, u
* @return ERR_OK if successful, ERR_ARG if we can't (or won't) decode * @return ERR_OK if successful, ERR_ARG if we can't (or won't) decode
*/ */
err_t 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) 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)
{ {
if (len > buf_max_len) { if (len > buf_max_len) {
/* not enough dst space */ /* not enough dst space */
@ -678,7 +678,7 @@ snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u64_t *value
* @see snmp_asn1_enc_u64t_cnt() * @see snmp_asn1_enc_u64t_cnt()
*/ */
err_t err_t
snmp_asn1_enc_u64t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u64_t value) snmp_asn1_enc_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u64_t value)
{ {
if (octets_needed > 9) { if (octets_needed > 9) {
return ERR_ARG; return ERR_ARG;

View File

@ -71,8 +71,7 @@ extern "C" {
#define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0 #define SNMP_ASN1_CONTEXT_VARBIND_NO_SUCH_OBJECT 0
#define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2 #define SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW 2
struct snmp_asn1_tlv struct snmp_asn1_tlv {
{
u8_t type; /* only U8 because extended types are not specified by SNMP */ u8_t type; /* only U8 because extended types are not specified by SNMP */
u8_t type_len; /* encoded length of 'type' field (normally 1) */ u8_t type_len; /* encoded length of 'type' field (normally 1) */
u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */ u8_t length_len; /* indicates how many bytes are required to encode the 'value_len' field */
@ -82,27 +81,27 @@ struct snmp_asn1_tlv
#define SNMP_ASN1_TLV_LENGTH(tlv) ((tlv).type_len + (tlv).length_len + (tlv).value_len) #define SNMP_ASN1_TLV_LENGTH(tlv) ((tlv).type_len + (tlv).length_len + (tlv).value_len)
#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); #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);
err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv); err_t snmp_asn1_dec_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv);
err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value); err_t snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value);
err_t snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value); err_t snmp_asn1_dec_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, s32_t *value);
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); 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);
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); 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);
err_t snmp_ans1_enc_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tlv); err_t snmp_ans1_enc_tlv(struct snmp_pbuf_stream *pbuf_stream, struct snmp_asn1_tlv *tlv);
void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed); void snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed);
void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed); void snmp_asn1_enc_u32t_cnt(u32_t value, u16_t *octets_needed);
void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed); void snmp_asn1_enc_s32t_cnt(s32_t value, u16_t *octets_needed);
void snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed); void snmp_asn1_enc_oid_cnt(const u32_t *oid, u16_t oid_len, u16_t *octets_needed);
err_t snmp_asn1_enc_oid(struct snmp_pbuf_stream* pbuf_stream, const u32_t *oid, u16_t oid_len); err_t snmp_asn1_enc_oid(struct snmp_pbuf_stream *pbuf_stream, const u32_t *oid, u16_t oid_len);
err_t snmp_asn1_enc_s32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, s32_t value); err_t snmp_asn1_enc_s32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, s32_t value);
err_t snmp_asn1_enc_u32t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u32_t value); err_t snmp_asn1_enc_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u32_t value);
err_t snmp_asn1_enc_raw(struct snmp_pbuf_stream* pbuf_stream, const u8_t *raw, u16_t raw_len); err_t snmp_asn1_enc_raw(struct snmp_pbuf_stream *pbuf_stream, const u8_t *raw, u16_t raw_len);
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
err_t snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u64_t *value); err_t snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u64_t *value);
void snmp_asn1_enc_u64t_cnt(u64_t value, u16_t *octets_needed); void snmp_asn1_enc_u64t_cnt(u64_t value, u16_t *octets_needed);
err_t snmp_asn1_enc_u64t(struct snmp_pbuf_stream* pbuf_stream, u16_t octets_needed, u64_t value); err_t snmp_asn1_enc_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t octets_needed, u64_t value);
#endif #endif
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -188,18 +188,18 @@
#if (LWIP_SNMP && (SNMP_TRAP_DESTINATIONS<=0)) #if (LWIP_SNMP && (SNMP_TRAP_DESTINATIONS<=0))
#error "If you want to use SNMP, you have to define SNMP_TRAP_DESTINATIONS>=1 in your lwipopts.h" #error "If you want to use SNMP, you have to define SNMP_TRAP_DESTINATIONS>=1 in your lwipopts.h"
#endif #endif
#if (!LWIP_UDP && LWIP_SNMP) #if (!LWIP_UDP && LWIP_SNMP)
#error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h" #error "If you want to use SNMP, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif #endif
#if SNMP_MAX_OBJ_ID_LEN > 255 #if SNMP_MAX_OBJ_ID_LEN > 255
#error "SNMP_MAX_OBJ_ID_LEN must fit into an u8_t" #error "SNMP_MAX_OBJ_ID_LEN must fit into an u8_t"
#endif #endif
struct snmp_statistics snmp_stats; struct snmp_statistics snmp_stats;
static const struct snmp_obj_id snmp_device_enterprise_oid_default = {SNMP_DEVICE_ENTERPRISE_OID_LEN, SNMP_DEVICE_ENTERPRISE_OID}; static const struct snmp_obj_id snmp_device_enterprise_oid_default = {SNMP_DEVICE_ENTERPRISE_OID_LEN, SNMP_DEVICE_ENTERPRISE_OID};
static const struct snmp_obj_id* snmp_device_enterprise_oid = &snmp_device_enterprise_oid_default; static const struct snmp_obj_id *snmp_device_enterprise_oid = &snmp_device_enterprise_oid_default;
const u32_t snmp_zero_dot_zero_values[] = { 0, 0 }; const u32_t snmp_zero_dot_zero_values[] = { 0, 0 };
const struct snmp_obj_id_const_ref snmp_zero_dot_zero = { LWIP_ARRAYSIZE(snmp_zero_dot_zero_values), snmp_zero_dot_zero_values }; const struct snmp_obj_id_const_ref snmp_zero_dot_zero = { LWIP_ARRAYSIZE(snmp_zero_dot_zero_values), snmp_zero_dot_zero_values };
@ -208,19 +208,19 @@ const struct snmp_obj_id_const_ref snmp_zero_dot_zero = { LWIP_ARRAYSIZE(snmp_ze
#include "lwip/apps/snmp_mib2.h" #include "lwip/apps/snmp_mib2.h"
#include "lwip/apps/snmp_snmpv2_framework.h" #include "lwip/apps/snmp_snmpv2_framework.h"
#include "lwip/apps/snmp_snmpv2_usm.h" #include "lwip/apps/snmp_snmpv2_usm.h"
static const struct snmp_mib* const default_mibs[] = { &mib2, &snmpframeworkmib, &snmpusmmib }; static const struct snmp_mib *const default_mibs[] = { &mib2, &snmpframeworkmib, &snmpusmmib };
static u8_t snmp_num_mibs = LWIP_ARRAYSIZE(default_mibs); static u8_t snmp_num_mibs = LWIP_ARRAYSIZE(default_mibs);
#elif SNMP_LWIP_MIB2 #elif SNMP_LWIP_MIB2
#include "lwip/apps/snmp_mib2.h" #include "lwip/apps/snmp_mib2.h"
static const struct snmp_mib* const default_mibs[] = { &mib2 }; static const struct snmp_mib *const default_mibs[] = { &mib2 };
static u8_t snmp_num_mibs = LWIP_ARRAYSIZE(default_mibs); static u8_t snmp_num_mibs = LWIP_ARRAYSIZE(default_mibs);
#else #else
static const struct snmp_mib* const default_mibs[] = { NULL }; static const struct snmp_mib *const default_mibs[] = { NULL };
static u8_t snmp_num_mibs = 0; static u8_t snmp_num_mibs = 0;
#endif #endif
/* List of known mibs */ /* List of known mibs */
static struct snmp_mib const * const *snmp_mibs = default_mibs; static struct snmp_mib const *const *snmp_mibs = default_mibs;
/** /**
* @ingroup snmp_core * @ingroup snmp_core
@ -255,7 +255,7 @@ snmp_set_mibs(const struct snmp_mib **mibs, u8_t num_mibs)
* device b > 1.3.6.1.4.1.XXX(ent-oid).1(devices).2(device b) * device b > 1.3.6.1.4.1.XXX(ent-oid).1(devices).2(device b)
* for more details see description of 'sysObjectID' field in RFC1213-MIB * for more details see description of 'sysObjectID' field in RFC1213-MIB
*/ */
void snmp_set_device_enterprise_oid(const struct snmp_obj_id* device_enterprise_oid) void snmp_set_device_enterprise_oid(const struct snmp_obj_id *device_enterprise_oid)
{ {
if (device_enterprise_oid == NULL) { if (device_enterprise_oid == NULL) {
snmp_device_enterprise_oid = &snmp_device_enterprise_oid_default; snmp_device_enterprise_oid = &snmp_device_enterprise_oid_default;
@ -268,7 +268,7 @@ void snmp_set_device_enterprise_oid(const struct snmp_obj_id* device_enterprise_
* @ingroup snmp_core * @ingroup snmp_core
* Get 'device enterprise oid' * Get 'device enterprise oid'
*/ */
const struct snmp_obj_id* snmp_get_device_enterprise_oid(void) const struct snmp_obj_id *snmp_get_device_enterprise_oid(void)
{ {
return snmp_device_enterprise_oid; return snmp_device_enterprise_oid;
} }
@ -521,7 +521,7 @@ snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port)
} }
/* InetPortNumber */ /* InetPortNumber */
if (oid_len < (idx+1)) { if (oid_len < (idx + 1)) {
return 0; return 0;
} }
if (oid[idx] > 0xffff) { if (oid[idx] > 0xffff) {
@ -542,7 +542,7 @@ snmp_oid_to_ip_port(const u32_t *oid, u8_t oid_len, ip_addr_t *ip, u16_t *port)
* @param oid_len OID length * @param oid_len OID length
*/ */
void void
snmp_oid_assign(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) snmp_oid_assign(struct snmp_obj_id *target, const u32_t *oid, u8_t oid_len)
{ {
LWIP_ASSERT("oid_len <= LWIP_SNMP_OBJ_ID_LEN", oid_len <= SNMP_MAX_OBJ_ID_LEN); LWIP_ASSERT("oid_len <= LWIP_SNMP_OBJ_ID_LEN", oid_len <= SNMP_MAX_OBJ_ID_LEN);
@ -560,14 +560,14 @@ snmp_oid_assign(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len)
* @param oid_len OID length * @param oid_len OID length
*/ */
void void
snmp_oid_prefix(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) snmp_oid_prefix(struct snmp_obj_id *target, const u32_t *oid, u8_t oid_len)
{ {
LWIP_ASSERT("target->len + oid_len <= LWIP_SNMP_OBJ_ID_LEN", (target->len + oid_len) <= SNMP_MAX_OBJ_ID_LEN); LWIP_ASSERT("target->len + oid_len <= LWIP_SNMP_OBJ_ID_LEN", (target->len + oid_len) <= SNMP_MAX_OBJ_ID_LEN);
if (oid_len > 0) { if (oid_len > 0) {
/* move existing OID to make room at the beginning for OID to insert */ /* move existing OID to make room at the beginning for OID to insert */
int i; int i;
for (i = target->len-1; i>=0; i--) { for (i = target->len - 1; i >= 0; i--) {
target->id[i + oid_len] = target->id[i]; target->id[i + oid_len] = target->id[i];
} }
@ -585,7 +585,7 @@ snmp_oid_prefix(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len)
* @param oid2_len OID 2 length * @param oid2_len OID 2 length
*/ */
void void
snmp_oid_combine(struct snmp_obj_id* target, const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len) snmp_oid_combine(struct snmp_obj_id *target, const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len)
{ {
snmp_oid_assign(target, oid1, oid1_len); snmp_oid_assign(target, oid1, oid1_len);
snmp_oid_append(target, oid2, oid2_len); snmp_oid_append(target, oid2, oid2_len);
@ -598,7 +598,7 @@ snmp_oid_combine(struct snmp_obj_id* target, const u32_t *oid1, u8_t oid1_len, c
* @param oid_len OID length * @param oid_len OID length
*/ */
void void
snmp_oid_append(struct snmp_obj_id* target, const u32_t *oid, u8_t oid_len) snmp_oid_append(struct snmp_obj_id *target, const u32_t *oid, u8_t oid_len)
{ {
LWIP_ASSERT("offset + oid_len <= LWIP_SNMP_OBJ_ID_LEN", (target->len + oid_len) <= SNMP_MAX_OBJ_ID_LEN); LWIP_ASSERT("offset + oid_len <= LWIP_SNMP_OBJ_ID_LEN", (target->len + oid_len) <= SNMP_MAX_OBJ_ID_LEN);
@ -660,7 +660,7 @@ snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_
u8_t u8_t
snmp_oid_equal(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len) snmp_oid_equal(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len)
{ {
return (snmp_oid_compare(oid1, oid1_len, oid2, oid2_len) == 0)? 1 : 0; return (snmp_oid_compare(oid1, oid1_len, oid2, oid2_len) == 0) ? 1 : 0;
} }
/** /**
@ -674,15 +674,15 @@ netif_to_num(const struct netif *netif)
return netif_get_index(netif); return netif_get_index(netif);
} }
static const struct snmp_mib* static const struct snmp_mib *
snmp_get_mib_from_oid(const u32_t *oid, u8_t oid_len) snmp_get_mib_from_oid(const u32_t *oid, u8_t oid_len)
{ {
const u32_t* list_oid; const u32_t *list_oid;
const u32_t* searched_oid; const u32_t *searched_oid;
u8_t i, l; u8_t i, l;
u8_t max_match_len = 0; u8_t max_match_len = 0;
const struct snmp_mib* matched_mib = NULL; const struct snmp_mib *matched_mib = NULL;
LWIP_ASSERT("'oid' param must not be NULL!", (oid != NULL)); LWIP_ASSERT("'oid' param must not be NULL!", (oid != NULL));
@ -719,11 +719,11 @@ snmp_get_mib_from_oid(const u32_t *oid, u8_t oid_len)
return matched_mib; return matched_mib;
} }
static const struct snmp_mib* static const struct snmp_mib *
snmp_get_next_mib(const u32_t *oid, u8_t oid_len) snmp_get_next_mib(const u32_t *oid, u8_t oid_len)
{ {
u8_t i; u8_t i;
const struct snmp_mib* next_mib = NULL; const struct snmp_mib *next_mib = NULL;
LWIP_ASSERT("'oid' param must not be NULL!", (oid != NULL)); LWIP_ASSERT("'oid' param must not be NULL!", (oid != NULL));
@ -747,10 +747,10 @@ snmp_get_next_mib(const u32_t *oid, u8_t oid_len)
return next_mib; return next_mib;
} }
static const struct snmp_mib* static const struct snmp_mib *
snmp_get_mib_between(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len) snmp_get_mib_between(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_len)
{ {
const struct snmp_mib* next_mib = snmp_get_next_mib(oid1, oid1_len); const struct snmp_mib *next_mib = snmp_get_next_mib(oid1, oid1_len);
LWIP_ASSERT("'oid2' param must not be NULL!", (oid2 != NULL)); LWIP_ASSERT("'oid2' param must not be NULL!", (oid2 != NULL));
LWIP_ASSERT("'oid2_len' param must be greater than 0!", (oid2_len > 0)); LWIP_ASSERT("'oid2_len' param must be greater than 0!", (oid2_len > 0));
@ -765,7 +765,7 @@ snmp_get_mib_between(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t o
} }
u8_t u8_t
snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node_instance* node_instance) snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node_instance *node_instance)
{ {
u8_t result = SNMP_ERR_NOSUCHOBJECT; u8_t result = SNMP_ERR_NOSUCHOBJECT;
const struct snmp_mib *mib; const struct snmp_mib *mib;
@ -778,7 +778,7 @@ snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node
mn = snmp_mib_tree_resolve_exact(mib, oid, oid_len, &oid_instance_len); mn = snmp_mib_tree_resolve_exact(mib, oid, oid_len, &oid_instance_len);
if ((mn != NULL) && (mn->node_type != SNMP_NODE_TREE)) { if ((mn != NULL) && (mn->node_type != SNMP_NODE_TREE)) {
/* get instance */ /* get instance */
const struct snmp_leaf_node* leaf_node = (const struct snmp_leaf_node*)(const void*)mn; const struct snmp_leaf_node *leaf_node = (const struct snmp_leaf_node *)(const void *)mn;
node_instance->node = mn; node_instance->node = mn;
snmp_oid_assign(&node_instance->instance_oid, oid + (oid_len - oid_instance_len), oid_instance_len); snmp_oid_assign(&node_instance->instance_oid, oid + (oid_len - oid_instance_len), oid_instance_len);
@ -805,11 +805,11 @@ snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node
} }
u8_t u8_t
snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_validate_node_instance_method validate_node_instance_method, void* validate_node_instance_arg, struct snmp_obj_id* node_oid, struct snmp_node_instance* node_instance) snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_validate_node_instance_method validate_node_instance_method, void *validate_node_instance_arg, struct snmp_obj_id *node_oid, struct snmp_node_instance *node_instance)
{ {
const struct snmp_mib *mib; const struct snmp_mib *mib;
const struct snmp_node *mn = NULL; const struct snmp_node *mn = NULL;
const u32_t* start_oid = NULL; const u32_t *start_oid = NULL;
u8_t start_oid_len = 0; u8_t start_oid_len = 0;
/* resolve target MIB from passed OID */ /* resolve target MIB from passed OID */
@ -857,7 +857,7 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida
node_instance->reference.ptr = NULL; node_instance->reference.ptr = NULL;
node_instance->reference_len = 0; node_instance->reference_len = 0;
result = ((const struct snmp_leaf_node*)(const void*)mn)->get_next_instance( result = ((const struct snmp_leaf_node *)(const void *)mn)->get_next_instance(
node_oid->id, node_oid->id,
node_oid->len, node_oid->len,
node_instance); node_instance);
@ -977,17 +977,17 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida
* *
*/ */
const struct snmp_node * const struct snmp_node *
snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, u8_t* oid_instance_len) snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, u8_t *oid_instance_len)
{ {
const struct snmp_node* const* node = &mib->root_node; const struct snmp_node *const *node = &mib->root_node;
u8_t oid_offset = mib->base_oid_len; u8_t oid_offset = mib->base_oid_len;
while ((oid_offset < oid_len) && ((*node)->node_type == SNMP_NODE_TREE)) { while ((oid_offset < oid_len) && ((*node)->node_type == SNMP_NODE_TREE)) {
/* search for matching sub node */ /* search for matching sub node */
u32_t subnode_oid = *(oid + oid_offset); u32_t subnode_oid = *(oid + oid_offset);
u32_t i = (*(const struct snmp_tree_node* const*)node)->subnode_count; u32_t i = (*(const struct snmp_tree_node * const *)node)->subnode_count;
node = (*(const struct snmp_tree_node* const*)node)->subnodes; node = (*(const struct snmp_tree_node * const *)node)->subnodes;
while ((i > 0) && ((*node)->oid != subnode_oid)) { while ((i > 0) && ((*node)->oid != subnode_oid)) {
node++; node++;
i--; i--;
@ -1010,12 +1010,12 @@ snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t o
return NULL; return NULL;
} }
const struct snmp_node* const struct snmp_node *
snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, struct snmp_obj_id* oidret) snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, struct snmp_obj_id *oidret)
{ {
u8_t oid_offset = mib->base_oid_len; u8_t oid_offset = mib->base_oid_len;
const struct snmp_node* const* node; const struct snmp_node *const *node;
const struct snmp_tree_node* node_stack[SNMP_MAX_OBJ_ID_LEN]; const struct snmp_tree_node *node_stack[SNMP_MAX_OBJ_ID_LEN];
s32_t nsi = 0; /* NodeStackIndex */ s32_t nsi = 0; /* NodeStackIndex */
u32_t subnode_oid; u32_t subnode_oid;
@ -1025,7 +1025,7 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi
} }
/* first build node stack related to passed oid (as far as possible), then go backwards to determine the next node */ /* first build node stack related to passed oid (as far as possible), then go backwards to determine the next node */
node_stack[nsi] = (const struct snmp_tree_node*)(const void*)mib->root_node; node_stack[nsi] = (const struct snmp_tree_node *)(const void *)mib->root_node;
while (oid_offset < oid_len) { while (oid_offset < oid_len) {
/* search for matching sub node */ /* search for matching sub node */
u32_t i = node_stack[nsi]->subnode_count; u32_t i = node_stack[nsi]->subnode_count;
@ -1043,7 +1043,7 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi
break; break;
} }
nsi++; nsi++;
node_stack[nsi] = (const struct snmp_tree_node*)(const void*)(*node); node_stack[nsi] = (const struct snmp_tree_node *)(const void *)(*node);
oid_offset++; oid_offset++;
} }
@ -1057,7 +1057,7 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi
} }
while (nsi >= 0) { while (nsi >= 0) {
const struct snmp_node* subnode = NULL; const struct snmp_node *subnode = NULL;
/* find next node on current level */ /* find next node on current level */
s32_t i = node_stack[nsi]->subnode_count; s32_t i = node_stack[nsi]->subnode_count;
@ -1082,7 +1082,7 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi
if (subnode->node_type == SNMP_NODE_TREE) { if (subnode->node_type == SNMP_NODE_TREE) {
/* next is a tree node, go into it and start searching */ /* next is a tree node, go into it and start searching */
nsi++; nsi++;
node_stack[nsi] = (const struct snmp_tree_node*)(const void*)subnode; node_stack[nsi] = (const struct snmp_tree_node *)(const void *)subnode;
subnode_oid = 0; subnode_oid = 0;
} else { } else {
/* we found a leaf node -> fill oidret and return it */ /* we found a leaf node -> fill oidret and return it */
@ -1143,7 +1143,7 @@ snmp_next_oid_precheck(struct snmp_next_oid_state *state, const u32_t *oid, u8_t
/** checks the passed OID if it is a candidate to be the next one (get_next); returns !=0 if passed oid is currently closest, otherwise 0 */ /** checks the passed OID if it is a candidate to be the next one (get_next); returns !=0 if passed oid is currently closest, otherwise 0 */
u8_t u8_t
snmp_next_oid_check(struct snmp_next_oid_state *state, const u32_t *oid, u8_t oid_len, void* reference) snmp_next_oid_check(struct snmp_next_oid_state *state, const u32_t *oid, u8_t oid_len, void *reference)
{ {
/* do not overwrite a fail result */ /* do not overwrite a fail result */
if (state->status != SNMP_NEXT_OID_STATUS_BUF_TO_SMALL) { if (state->status != SNMP_NEXT_OID_STATUS_BUF_TO_SMALL) {
@ -1187,7 +1187,7 @@ snmp_oid_in_range(const u32_t *oid_in, u8_t oid_len, const struct snmp_oid_range
} }
snmp_err_t snmp_err_t
snmp_set_test_ok(struct snmp_node_instance* instance, u16_t value_len, void* value) snmp_set_test_ok(struct snmp_node_instance *instance, u16_t value_len, void *value)
{ {
LWIP_UNUSED_ARG(instance); LWIP_UNUSED_ARG(instance);
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
@ -1230,8 +1230,7 @@ snmp_decode_bits(const u8_t *buf, u32_t buf_len, u32_t *bit_value)
} }
bits_processed++; bits_processed++;
b <<= 1; b <<= 1;
} } while ((bits_processed & 0x07) != 0); /* &0x07 -> % 8 */
while ((bits_processed & 0x07) != 0); /* &0x07 -> % 8 */
} else { } else {
bits_processed += 8; bits_processed += 8;
} }

View File

@ -66,13 +66,13 @@ extern "C" {
#define SNMP_ERR_ENDOFMIBVIEW SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW #define SNMP_ERR_ENDOFMIBVIEW SNMP_VARBIND_EXCEPTION_OFFSET + SNMP_ASN1_CONTEXT_VARBIND_END_OF_MIB_VIEW
const struct snmp_node* snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, u8_t* oid_instance_len); const struct snmp_node *snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, u8_t *oid_instance_len);
const struct snmp_node* snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, struct snmp_obj_id* oidret); const struct snmp_node *snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oid_len, struct snmp_obj_id *oidret);
typedef u8_t (*snmp_validate_node_instance_method)(struct snmp_node_instance*, void*); typedef u8_t (*snmp_validate_node_instance_method)(struct snmp_node_instance *, void *);
u8_t snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node_instance* node_instance); u8_t snmp_get_node_instance_from_oid(const u32_t *oid, u8_t oid_len, struct snmp_node_instance *node_instance);
u8_t snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_validate_node_instance_method validate_node_instance_method, void* validate_node_instance_arg, struct snmp_obj_id* node_oid, struct snmp_node_instance* node_instance); u8_t snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_validate_node_instance_method validate_node_instance_method, void *validate_node_instance_arg, struct snmp_obj_id *node_oid, struct snmp_node_instance *node_instance);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -59,7 +59,7 @@
#include "lwip/tcpip.h" #include "lwip/tcpip.h"
#include "lwip/priv/tcpip_priv.h" #include "lwip/priv/tcpip_priv.h"
void void
snmp_mib2_lwip_synchronizer(snmp_threadsync_called_fn fn, void* arg) snmp_mib2_lwip_synchronizer(snmp_threadsync_called_fn fn, void *arg)
{ {
#if LWIP_TCPIP_CORE_LOCKING #if LWIP_TCPIP_CORE_LOCKING
LOCK_TCPIP_CORE(); LOCK_TCPIP_CORE();
@ -87,7 +87,7 @@ extern const struct snmp_scalar_array_node snmp_mib2_system_node;
extern const struct snmp_tree_node snmp_mib2_at_root; extern const struct snmp_tree_node snmp_mib2_at_root;
extern const struct snmp_tree_node snmp_mib2_ip_root; extern const struct snmp_tree_node snmp_mib2_ip_root;
static const struct snmp_node* const mib2_nodes[] = { static const struct snmp_node *const mib2_nodes[] = {
&snmp_mib2_system_node.node.node, &snmp_mib2_system_node.node.node,
&snmp_mib2_interface_root.node, &snmp_mib2_interface_root.node,
#if LWIP_ARP && LWIP_IPV4 #if LWIP_ARP && LWIP_IPV4
@ -110,7 +110,7 @@ static const struct snmp_node* const mib2_nodes[] = {
static const struct snmp_tree_node mib2_root = SNMP_CREATE_TREE_NODE(1, mib2_nodes); static const struct snmp_tree_node mib2_root = SNMP_CREATE_TREE_NODE(1, mib2_nodes);
static const u32_t mib2_base_oid_arr[] = { 1,3,6,1,2,1 }; static const u32_t mib2_base_oid_arr[] = { 1, 3, 6, 1, 2, 1 };
const struct snmp_mib mib2 = SNMP_MIB_CREATE(mib2_base_oid_arr, &mib2_root.node); const struct snmp_mib mib2 = SNMP_MIB_CREATE(mib2_base_oid_arr, &mib2_root.node);
#endif /* LWIP_SNMP && SNMP_LWIP_MIB2 */ #endif /* LWIP_SNMP && SNMP_LWIP_MIB2 */

View File

@ -58,7 +58,7 @@
static s16_t static s16_t
icmp_get_value(const struct snmp_scalar_array_node_def *node, void *value) icmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t *)value;
switch (node->oid) { switch (node->oid) {
case 1: /* icmpInMsgs */ case 1: /* icmpInMsgs */
@ -140,7 +140,7 @@ icmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
*uint_ptr = 0; *uint_ptr = 0;
return sizeof(*uint_ptr); return sizeof(*uint_ptr);
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_value(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("icmp_get_value(): unknown id: %"S32_F"\n", node->oid));
break; break;
} }

View File

@ -59,10 +59,10 @@
/* --- interfaces .1.3.6.1.2.1.2 ----------------------------------------------------- */ /* --- interfaces .1.3.6.1.2.1.2 ----------------------------------------------------- */
static s16_t static s16_t
interfaces_get_value(struct snmp_node_instance* instance, void* value) interfaces_get_value(struct snmp_node_instance *instance, void *value)
{ {
if (instance->node->oid == 1) { if (instance->node->oid == 1) {
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
s32_t num_netifs = 0; s32_t num_netifs = 0;
struct netif *netif; struct netif *netif;
@ -92,7 +92,7 @@ static const u8_t iftable_ifAdminStatus_lowerLayerDown = 7;
static const u8_t iftable_ifAdminStatus_down = 2; static const u8_t iftable_ifAdminStatus_down = 2;
static snmp_err_t static snmp_err_t
interfaces_Table_get_cell_instance(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, struct snmp_node_instance* cell_instance) interfaces_Table_get_cell_instance(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, struct snmp_node_instance *cell_instance)
{ {
u32_t ifIndex; u32_t ifIndex;
struct netif *netif; struct netif *netif;
@ -121,7 +121,7 @@ interfaces_Table_get_cell_instance(const u32_t* column, const u32_t* row_oid, u8
} }
static snmp_err_t static snmp_err_t
interfaces_Table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id* row_oid, struct snmp_node_instance* cell_instance) interfaces_Table_get_next_cell_instance(const u32_t *column, struct snmp_obj_id *row_oid, struct snmp_node_instance *cell_instance)
{ {
struct netif *netif; struct netif *netif;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -154,15 +154,14 @@ interfaces_Table_get_next_cell_instance(const u32_t* column, struct snmp_obj_id*
} }
static s16_t static s16_t
interfaces_Table_get_value(struct snmp_node_instance* instance, void* value) interfaces_Table_get_value(struct snmp_node_instance *instance, void *value)
{ {
struct netif *netif = (struct netif*)instance->reference.ptr; struct netif *netif = (struct netif *)instance->reference.ptr;
u32_t* value_u32 = (u32_t*)value; u32_t *value_u32 = (u32_t *)value;
s32_t* value_s32 = (s32_t*)value; s32_t *value_s32 = (s32_t *)value;
u16_t value_len; u16_t value_len;
switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id)) switch (SNMP_TABLE_GET_COLUMN_FROM_OID(instance->instance_oid.id)) {
{
case 1: /* ifIndex */ case 1: /* ifIndex */
*value_s32 = netif_to_num(netif); *value_s32 = netif_to_num(netif);
value_len = sizeof(*value_s32); value_len = sizeof(*value_s32);
@ -274,9 +273,9 @@ interfaces_Table_get_value(struct snmp_node_instance* instance, void* value)
#if !SNMP_SAFE_REQUESTS #if !SNMP_SAFE_REQUESTS
static snmp_err_t static snmp_err_t
interfaces_Table_set_test(struct snmp_node_instance* instance, u16_t len, void *value) interfaces_Table_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
{ {
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
/* stack should never call this method for another column, /* stack should never call this method for another column,
because all other columns are set to readonly */ because all other columns are set to readonly */
@ -291,10 +290,10 @@ interfaces_Table_set_test(struct snmp_node_instance* instance, u16_t len, void *
} }
static snmp_err_t static snmp_err_t
interfaces_Table_set_value(struct snmp_node_instance* instance, u16_t len, void *value) interfaces_Table_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
{ {
struct netif *netif = (struct netif*)instance->reference.ptr; struct netif *netif = (struct netif *)instance->reference.ptr;
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
/* stack should never call this method for another column, /* stack should never call this method for another column,
because all other columns are set to readonly */ because all other columns are set to readonly */
@ -359,7 +358,7 @@ static const struct snmp_table_node interfaces_Table = SNMP_TABLE_CREATE(
CREATE_LWIP_SYNC_NODE(1, interfaces_Number) CREATE_LWIP_SYNC_NODE(1, interfaces_Number)
CREATE_LWIP_SYNC_NODE(2, interfaces_Table) CREATE_LWIP_SYNC_NODE(2, interfaces_Table)
static const struct snmp_node* const interface_nodes[] = { static const struct snmp_node *const interface_nodes[] = {
&SYNC_NODE_NAME(interfaces_Number).node.node, &SYNC_NODE_NAME(interfaces_Number).node.node,
&SYNC_NODE_NAME(interfaces_Table).node.node &SYNC_NODE_NAME(interfaces_Table).node.node
}; };

View File

@ -59,10 +59,10 @@
/* --- ip .1.3.6.1.2.1.4 ----------------------------------------------------- */ /* --- ip .1.3.6.1.2.1.4 ----------------------------------------------------- */
static s16_t static s16_t
ip_get_value(struct snmp_node_instance* instance, void* value) ip_get_value(struct snmp_node_instance *instance, void *value)
{ {
s32_t* sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
u32_t* uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t *)value;
switch (instance->node->oid) { switch (instance->node->oid) {
case 1: /* ipForwarding */ case 1: /* ipForwarding */
@ -136,7 +136,7 @@ ip_get_value(struct snmp_node_instance* instance, void* value)
*uint_ptr = 0; *uint_ptr = 0;
return sizeof(*uint_ptr); return sizeof(*uint_ptr);
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_value(): unknown id: %"S32_F"\n", instance->node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("ip_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
break; break;
} }
@ -154,10 +154,10 @@ ip_get_value(struct snmp_node_instance* instance, void* value)
* otherwise return badvalue. * otherwise return badvalue.
*/ */
static snmp_err_t static snmp_err_t
ip_set_test(struct snmp_node_instance* instance, u16_t len, void *value) ip_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
{ {
snmp_err_t ret = SNMP_ERR_WRONGVALUE; snmp_err_t ret = SNMP_ERR_WRONGVALUE;
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
LWIP_UNUSED_ARG(len); LWIP_UNUSED_ARG(len);
switch (instance->node->oid) { switch (instance->node->oid) {
@ -179,7 +179,7 @@ ip_set_test(struct snmp_node_instance* instance, u16_t len, void *value)
} }
break; break;
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_set_test(): unknown id: %"S32_F"\n", instance->node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("ip_set_test(): unknown id: %"S32_F"\n", instance->node->oid));
break; break;
} }
@ -187,7 +187,7 @@ ip_set_test(struct snmp_node_instance* instance, u16_t len, void *value)
} }
static snmp_err_t static snmp_err_t
ip_set_value(struct snmp_node_instance* instance, u16_t len, void *value) ip_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
{ {
LWIP_UNUSED_ARG(instance); LWIP_UNUSED_ARG(instance);
LWIP_UNUSED_ARG(len); LWIP_UNUSED_ARG(len);
@ -207,7 +207,7 @@ static const struct snmp_oid_range ip_AddrTable_oid_ranges[] = {
}; };
static snmp_err_t static snmp_err_t
ip_AddrTable_get_cell_value_core(struct netif *netif, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) ip_AddrTable_get_cell_value_core(struct netif *netif, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
{ {
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
@ -232,7 +232,7 @@ ip_AddrTable_get_cell_value_core(struct netif *netif, const u32_t* column, union
* but only if receiving one fragmented packet at a time. * but only if receiving one fragmented packet at a time.
* The current solution is to calculate for 2 simultaneous packets... * The current solution is to calculate for 2 simultaneous packets...
*/ */
value->u32 = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) * value->u32 = (IP_HLEN + ((IP_REASS_MAX_PBUFS / 2) *
(PBUF_POOL_BUFSIZE - PBUF_LINK_ENCAPSULATION_HLEN - PBUF_LINK_HLEN - IP_HLEN))); (PBUF_POOL_BUFSIZE - PBUF_LINK_ENCAPSULATION_HLEN - PBUF_LINK_HLEN - IP_HLEN)));
#else #else
/** @todo returning MTU would be a bad thing and /** @todo returning MTU would be a bad thing and
@ -248,7 +248,7 @@ ip_AddrTable_get_cell_value_core(struct netif *netif, const u32_t* column, union
} }
static snmp_err_t static snmp_err_t
ip_AddrTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) ip_AddrTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip4_addr_t ip; ip4_addr_t ip;
struct netif *netif; struct netif *netif;
@ -274,7 +274,7 @@ ip_AddrTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_
} }
static snmp_err_t static snmp_err_t
ip_AddrTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) ip_AddrTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
struct netif *netif; struct netif *netif;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -296,7 +296,7 @@ ip_AddrTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_o
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
/* fill in object properties */ /* fill in object properties */
return ip_AddrTable_get_cell_value_core((struct netif*)state.reference, column, value, value_len); return ip_AddrTable_get_cell_value_core((struct netif *)state.reference, column, value, value_len);
} }
/* not found */ /* not found */
@ -314,7 +314,7 @@ static const struct snmp_oid_range ip_RouteTable_oid_ranges[] = {
}; };
static snmp_err_t static snmp_err_t
ip_RouteTable_get_cell_value_core(struct netif *netif, u8_t default_route, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) ip_RouteTable_get_cell_value_core(struct netif *netif, u8_t default_route, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
{ {
switch (*column) { switch (*column) {
case 1: /* ipRouteDest */ case 1: /* ipRouteDest */
@ -393,7 +393,7 @@ ip_RouteTable_get_cell_value_core(struct netif *netif, u8_t default_route, const
} }
static snmp_err_t static snmp_err_t
ip_RouteTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) ip_RouteTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip4_addr_t test_ip; ip4_addr_t test_ip;
struct netif *netif; struct netif *netif;
@ -428,7 +428,7 @@ ip_RouteTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row
} }
static snmp_err_t static snmp_err_t
ip_RouteTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) ip_RouteTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
struct netif *netif; struct netif *netif;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -462,7 +462,7 @@ ip_RouteTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_
snmp_oid_to_ip4(&result_temp[0], &dst); snmp_oid_to_ip4(&result_temp[0], &dst);
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
/* fill in object properties */ /* fill in object properties */
return ip_RouteTable_get_cell_value_core((struct netif*)state.reference, ip4_addr_isany_val(dst), column, value, value_len); return ip_RouteTable_get_cell_value_core((struct netif *)state.reference, ip4_addr_isany_val(dst), column, value, value_len);
} else { } else {
/* not found */ /* not found */
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
@ -482,7 +482,7 @@ static const struct snmp_oid_range ip_NetToMediaTable_oid_ranges[] = {
}; };
static snmp_err_t static snmp_err_t
ip_NetToMediaTable_get_cell_value_core(u8_t arp_table_index, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) ip_NetToMediaTable_get_cell_value_core(u8_t arp_table_index, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
{ {
ip4_addr_t *ip; ip4_addr_t *ip;
struct netif *netif; struct netif *netif;
@ -513,7 +513,7 @@ ip_NetToMediaTable_get_cell_value_core(u8_t arp_table_index, const u32_t* column
} }
static snmp_err_t static snmp_err_t
ip_NetToMediaTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) ip_NetToMediaTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip4_addr_t ip_in; ip4_addr_t ip_in;
u8_t netif_index; u8_t netif_index;
@ -529,7 +529,7 @@ ip_NetToMediaTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_
snmp_oid_to_ip4(&row_oid[1], &ip_in); /* we know it succeeds because of oid_in_range check above */ snmp_oid_to_ip4(&row_oid[1], &ip_in); /* we know it succeeds because of oid_in_range check above */
/* find requested entry */ /* find requested entry */
for (i=0; i<ARP_TABLE_SIZE; i++) { for (i = 0; i < ARP_TABLE_SIZE; i++) {
ip4_addr_t *ip; ip4_addr_t *ip;
struct netif *netif; struct netif *netif;
struct eth_addr *ethaddr; struct eth_addr *ethaddr;
@ -547,7 +547,7 @@ ip_NetToMediaTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_
} }
static snmp_err_t static snmp_err_t
ip_NetToMediaTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) ip_NetToMediaTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
u8_t i; u8_t i;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -557,7 +557,7 @@ ip_NetToMediaTable_get_next_cell_instance_and_value(const u32_t* column, struct
snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges)); snmp_next_oid_init(&state, row_oid->id, row_oid->len, result_temp, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges));
/* iterate over all possible OIDs to find the next one */ /* iterate over all possible OIDs to find the next one */
for (i=0; i<ARP_TABLE_SIZE; i++) { for (i = 0; i < ARP_TABLE_SIZE; i++) {
ip4_addr_t *ip; ip4_addr_t *ip;
struct netif *netif; struct netif *netif;
struct eth_addr *ethaddr; struct eth_addr *ethaddr;
@ -569,7 +569,7 @@ ip_NetToMediaTable_get_next_cell_instance_and_value(const u32_t* column, struct
snmp_ip4_to_oid(ip, &test_oid[1]); snmp_ip4_to_oid(ip, &test_oid[1]);
/* check generated OID: is it a candidate for the next one? */ /* check generated OID: is it a candidate for the next one? */
snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges), LWIP_PTR_NUMERIC_CAST(void*, i)); snmp_next_oid_check(&state, test_oid, LWIP_ARRAYSIZE(ip_NetToMediaTable_oid_ranges), LWIP_PTR_NUMERIC_CAST(void *, i));
} }
} }
@ -675,7 +675,7 @@ CREATE_LWIP_SYNC_NODE(22, ip_NetToMediaTable)
#endif /* LWIP_ARP */ #endif /* LWIP_ARP */
CREATE_LWIP_SYNC_NODE(23, ip_RoutingDiscards) CREATE_LWIP_SYNC_NODE(23, ip_RoutingDiscards)
static const struct snmp_node* const ip_nodes[] = { static const struct snmp_node *const ip_nodes[] = {
&SYNC_NODE_NAME(ip_Forwarding).node.node, &SYNC_NODE_NAME(ip_Forwarding).node.node,
&SYNC_NODE_NAME(ip_DefaultTTL).node.node, &SYNC_NODE_NAME(ip_DefaultTTL).node.node,
&SYNC_NODE_NAME(ip_InReceives).node.node, &SYNC_NODE_NAME(ip_InReceives).node.node,
@ -721,7 +721,7 @@ static const struct snmp_table_simple_node at_Table = SNMP_TABLE_CREATE_SIMPLE(1
/* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */ /* the following nodes access variables in LWIP stack from SNMP worker thread and must therefore be synced to LWIP (TCPIP) thread */
CREATE_LWIP_SYNC_NODE(1, at_Table) CREATE_LWIP_SYNC_NODE(1, at_Table)
static const struct snmp_node* const at_nodes[] = { static const struct snmp_node *const at_nodes[] = {
&SYNC_NODE_NAME(at_Table).node.node &SYNC_NODE_NAME(at_Table).node.node
}; };

View File

@ -48,7 +48,7 @@
static s16_t static s16_t
snmp_get_value(const struct snmp_scalar_array_node_def *node, void *value) snmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t *)value;
switch (node->oid) { switch (node->oid) {
case 1: /* snmpInPkts */ case 1: /* snmpInPkts */
*uint_ptr = snmp_stats.inpkts; *uint_ptr = snmp_stats.inpkts;
@ -145,7 +145,7 @@ snmp_get_value(const struct snmp_scalar_array_node_def *node, void *value)
*uint_ptr = 0; /* not supported */ *uint_ptr = 0; /* not supported */
break; break;
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_value(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmp_get_value(): unknown id: %"S32_F"\n", node->oid));
return 0; return 0;
} }
@ -160,7 +160,7 @@ snmp_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *va
if (node->oid == 30) { if (node->oid == 30) {
/* snmpEnableAuthenTraps */ /* snmpEnableAuthenTraps */
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
/* we should have writable non-volatile mem here */ /* we should have writable non-volatile mem here */
if ((*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) || (*sint_ptr == MIB2_AUTH_TRAPS_ENABLED)) { if ((*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) || (*sint_ptr == MIB2_AUTH_TRAPS_ENABLED)) {
@ -177,7 +177,7 @@ snmp_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *v
if (node->oid == 30) { if (node->oid == 30) {
/* snmpEnableAuthenTraps */ /* snmpEnableAuthenTraps */
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
if (*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) { if (*sint_ptr == MIB2_AUTH_TRAPS_DISABLED) {
snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_DISABLED); snmp_set_auth_traps_enabled(SNMP_AUTH_TRAPS_DISABLED);
} else { } else {

View File

@ -58,31 +58,31 @@
/** mib-2.system.sysDescr */ /** mib-2.system.sysDescr */
static const u8_t sysdescr_default[] = SNMP_LWIP_MIB2_SYSDESC; static const u8_t sysdescr_default[] = SNMP_LWIP_MIB2_SYSDESC;
static const u8_t* sysdescr = sysdescr_default; static const u8_t *sysdescr = sysdescr_default;
static const u16_t* sysdescr_len = NULL; /* use strlen for determining len */ static const u16_t *sysdescr_len = NULL; /* use strlen for determining len */
/** mib-2.system.sysContact */ /** mib-2.system.sysContact */
static const u8_t syscontact_default[] = SNMP_LWIP_MIB2_SYSCONTACT; static const u8_t syscontact_default[] = SNMP_LWIP_MIB2_SYSCONTACT;
static const u8_t* syscontact = syscontact_default; static const u8_t *syscontact = syscontact_default;
static const u16_t* syscontact_len = NULL; /* use strlen for determining len */ static const u16_t *syscontact_len = NULL; /* use strlen for determining len */
static u8_t* syscontact_wr = NULL; /* if writable, points to the same buffer as syscontact (required for correct constness) */ static u8_t *syscontact_wr = NULL; /* if writable, points to the same buffer as syscontact (required for correct constness) */
static u16_t* syscontact_wr_len = NULL; /* if writable, points to the same buffer as syscontact_len (required for correct constness) */ static u16_t *syscontact_wr_len = NULL; /* if writable, points to the same buffer as syscontact_len (required for correct constness) */
static u16_t syscontact_bufsize = 0; /* 0=not writable */ static u16_t syscontact_bufsize = 0; /* 0=not writable */
/** mib-2.system.sysName */ /** mib-2.system.sysName */
static const u8_t sysname_default[] = SNMP_LWIP_MIB2_SYSNAME; static const u8_t sysname_default[] = SNMP_LWIP_MIB2_SYSNAME;
static const u8_t* sysname = sysname_default; static const u8_t *sysname = sysname_default;
static const u16_t* sysname_len = NULL; /* use strlen for determining len */ static const u16_t *sysname_len = NULL; /* use strlen for determining len */
static u8_t* sysname_wr = NULL; /* if writable, points to the same buffer as sysname (required for correct constness) */ static u8_t *sysname_wr = NULL; /* if writable, points to the same buffer as sysname (required for correct constness) */
static u16_t* sysname_wr_len = NULL; /* if writable, points to the same buffer as sysname_len (required for correct constness) */ static u16_t *sysname_wr_len = NULL; /* if writable, points to the same buffer as sysname_len (required for correct constness) */
static u16_t sysname_bufsize = 0; /* 0=not writable */ static u16_t sysname_bufsize = 0; /* 0=not writable */
/** mib-2.system.sysLocation */ /** mib-2.system.sysLocation */
static const u8_t syslocation_default[] = SNMP_LWIP_MIB2_SYSLOCATION; static const u8_t syslocation_default[] = SNMP_LWIP_MIB2_SYSLOCATION;
static const u8_t* syslocation = syslocation_default; static const u8_t *syslocation = syslocation_default;
static const u16_t* syslocation_len = NULL; /* use strlen for determining len */ static const u16_t *syslocation_len = NULL; /* use strlen for determining len */
static u8_t* syslocation_wr = NULL; /* if writable, points to the same buffer as syslocation (required for correct constness) */ static u8_t *syslocation_wr = NULL; /* if writable, points to the same buffer as syslocation (required for correct constness) */
static u16_t* syslocation_wr_len = NULL; /* if writable, points to the same buffer as syslocation_len (required for correct constness) */ static u16_t *syslocation_wr_len = NULL; /* if writable, points to the same buffer as syslocation_len (required for correct constness) */
static u16_t syslocation_bufsize = 0; /* 0=not writable */ static u16_t syslocation_bufsize = 0; /* 0=not writable */
/** /**
@ -229,48 +229,47 @@ snmp_mib2_set_syslocation_readonly(const u8_t *ocstr, const u16_t *ocstrlen)
static s16_t static s16_t
system_get_value(const struct snmp_scalar_array_node_def *node, void *value) system_get_value(const struct snmp_scalar_array_node_def *node, void *value)
{ {
const u8_t* var = NULL; const u8_t *var = NULL;
const s16_t* var_len; const s16_t *var_len;
u16_t result; u16_t result;
switch (node->oid) { switch (node->oid) {
case 1: /* sysDescr */ case 1: /* sysDescr */
var = sysdescr; var = sysdescr;
var_len = (const s16_t*)sysdescr_len; var_len = (const s16_t *)sysdescr_len;
break; break;
case 2: /* sysObjectID */ case 2: { /* sysObjectID */
{ const struct snmp_obj_id *dev_enterprise_oid = snmp_get_device_enterprise_oid();
const struct snmp_obj_id* dev_enterprise_oid = snmp_get_device_enterprise_oid();
MEMCPY(value, dev_enterprise_oid->id, dev_enterprise_oid->len * sizeof(u32_t)); MEMCPY(value, dev_enterprise_oid->id, dev_enterprise_oid->len * sizeof(u32_t));
return dev_enterprise_oid->len * sizeof(u32_t); return dev_enterprise_oid->len * sizeof(u32_t);
} }
case 3: /* sysUpTime */ case 3: /* sysUpTime */
MIB2_COPY_SYSUPTIME_TO((u32_t*)value); MIB2_COPY_SYSUPTIME_TO((u32_t *)value);
return sizeof(u32_t); return sizeof(u32_t);
case 4: /* sysContact */ case 4: /* sysContact */
var = syscontact; var = syscontact;
var_len = (const s16_t*)syscontact_len; var_len = (const s16_t *)syscontact_len;
break; break;
case 5: /* sysName */ case 5: /* sysName */
var = sysname; var = sysname;
var_len = (const s16_t*)sysname_len; var_len = (const s16_t *)sysname_len;
break; break;
case 6: /* sysLocation */ case 6: /* sysLocation */
var = syslocation; var = syslocation;
var_len = (const s16_t*)syslocation_len; var_len = (const s16_t *)syslocation_len;
break; break;
case 7: /* sysServices */ case 7: /* sysServices */
*(s32_t*)value = SNMP_SYSSERVICES; *(s32_t *)value = SNMP_SYSSERVICES;
return sizeof(s32_t); return sizeof(s32_t);
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_value(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_get_value(): unknown id: %"S32_F"\n", node->oid));
return 0; return 0;
} }
/* handle string values (OID 1,4,5 and 6) */ /* handle string values (OID 1,4,5 and 6) */
LWIP_ASSERT("", (value != NULL)); LWIP_ASSERT("", (value != NULL));
if (var_len == NULL) { if (var_len == NULL) {
result = (s16_t)strlen((const char*)var); result = (s16_t)strlen((const char *)var);
} else { } else {
result = *var_len; result = *var_len;
} }
@ -282,8 +281,8 @@ static snmp_err_t
system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value) system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
{ {
snmp_err_t ret = SNMP_ERR_WRONGVALUE; snmp_err_t ret = SNMP_ERR_WRONGVALUE;
const u16_t* var_bufsize = NULL; const u16_t *var_bufsize = NULL;
const u16_t* var_wr_len; const u16_t *var_wr_len;
LWIP_UNUSED_ARG(value); LWIP_UNUSED_ARG(value);
@ -301,7 +300,7 @@ system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *
var_wr_len = syslocation_wr_len; var_wr_len = syslocation_wr_len;
break; break;
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_test(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_test(): unknown id: %"S32_F"\n", node->oid));
return ret; return ret;
} }
@ -327,8 +326,8 @@ system_set_test(const struct snmp_scalar_array_node_def *node, u16_t len, void *
static snmp_err_t static snmp_err_t
system_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value) system_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void *value)
{ {
u8_t* var_wr = NULL; u8_t *var_wr = NULL;
u16_t* var_wr_len; u16_t *var_wr_len;
switch (node->oid) { switch (node->oid) {
case 4: /* sysContact */ case 4: /* sysContact */
@ -344,7 +343,7 @@ system_set_value(const struct snmp_scalar_array_node_def *node, u16_t len, void
var_wr_len = syslocation_wr_len; var_wr_len = syslocation_wr_len;
break; break;
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_set_value(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("system_set_value(): unknown id: %"S32_F"\n", node->oid));
return SNMP_ERR_GENERROR; return SNMP_ERR_GENERROR;
} }

View File

@ -59,10 +59,10 @@
/* --- tcp .1.3.6.1.2.1.6 ----------------------------------------------------- */ /* --- tcp .1.3.6.1.2.1.6 ----------------------------------------------------- */
static s16_t static s16_t
tcp_get_value(struct snmp_node_instance* instance, void* value) tcp_get_value(struct snmp_node_instance *instance, void *value)
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t *)value;
s32_t *sint_ptr = (s32_t*)value; s32_t *sint_ptr = (s32_t *)value;
switch (instance->node->oid) { switch (instance->node->oid) {
case 1: /* tcpRtoAlgorithm, vanj(4) */ case 1: /* tcpRtoAlgorithm, vanj(4) */
@ -93,8 +93,7 @@ tcp_get_value(struct snmp_node_instance* instance, void* value)
case 8: /* tcpEstabResets */ case 8: /* tcpEstabResets */
*uint_ptr = STATS_GET(mib2.tcpestabresets); *uint_ptr = STATS_GET(mib2.tcpestabresets);
return sizeof(*uint_ptr); return sizeof(*uint_ptr);
case 9: /* tcpCurrEstab */ case 9: { /* tcpCurrEstab */
{
u16_t tcpcurrestab = 0; u16_t tcpcurrestab = 0;
struct tcp_pcb *pcb = tcp_active_pcbs; struct tcp_pcb *pcb = tcp_active_pcbs;
while (pcb != NULL) { while (pcb != NULL) {
@ -123,23 +122,21 @@ tcp_get_value(struct snmp_node_instance* instance, void* value)
*uint_ptr = STATS_GET(mib2.tcpoutrsts); *uint_ptr = STATS_GET(mib2.tcpoutrsts);
return sizeof(*uint_ptr); return sizeof(*uint_ptr);
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
case 17: /* tcpHCInSegs */ case 17: { /* tcpHCInSegs */
{
/* use the 32 bit counter for now... */ /* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.tcpinsegs); u64_t val64 = STATS_GET(mib2.tcpinsegs);
*((u64_t*)value) = val64; *((u64_t *)value) = val64;
} }
return sizeof(u64_t); return sizeof(u64_t);
case 18: /* tcpHCOutSegs */ case 18: { /* tcpHCOutSegs */
{
/* use the 32 bit counter for now... */ /* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.tcpoutsegs); u64_t val64 = STATS_GET(mib2.tcpoutsegs);
*((u64_t*)value) = val64; *((u64_t *)value) = val64;
} }
return sizeof(u64_t); return sizeof(u64_t);
#endif #endif
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_value(): unknown id: %"S32_F"\n", instance->node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("tcp_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
break; break;
} }
@ -165,7 +162,7 @@ static const struct snmp_oid_range tcp_ConnTable_oid_ranges[] = {
}; };
static snmp_err_t static snmp_err_t
tcp_ConnTable_get_cell_value_core(struct tcp_pcb *pcb, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) tcp_ConnTable_get_cell_value_core(struct tcp_pcb *pcb, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
{ {
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
@ -203,7 +200,7 @@ tcp_ConnTable_get_cell_value_core(struct tcp_pcb *pcb, const u32_t* column, unio
} }
static snmp_err_t static snmp_err_t
tcp_ConnTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) tcp_ConnTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
u8_t i; u8_t i;
ip4_addr_t local_ip; ip4_addr_t local_ip;
@ -256,7 +253,7 @@ tcp_ConnTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row
} }
static snmp_err_t static snmp_err_t
tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) tcp_ConnTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
u8_t i; u8_t i;
struct tcp_pcb *pcb; struct tcp_pcb *pcb;
@ -300,7 +297,7 @@ tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
/* fill in object properties */ /* fill in object properties */
return tcp_ConnTable_get_cell_value_core((struct tcp_pcb*)state.reference, column, value, value_len); return tcp_ConnTable_get_cell_value_core((struct tcp_pcb *)state.reference, column, value, value_len);
} }
/* not found */ /* not found */
@ -312,7 +309,7 @@ tcp_ConnTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_
/* --- tcpConnectionTable --- */ /* --- tcpConnectionTable --- */
static snmp_err_t static snmp_err_t
tcp_ConnectionTable_get_cell_value_core(const u32_t* column, struct tcp_pcb *pcb, union snmp_variant_value* value) tcp_ConnectionTable_get_cell_value_core(const u32_t *column, struct tcp_pcb *pcb, union snmp_variant_value *value)
{ {
/* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */ /* all items except tcpConnectionState and tcpConnectionProcess are declared as not-accessible */
switch (*column) { switch (*column) {
@ -330,25 +327,25 @@ tcp_ConnectionTable_get_cell_value_core(const u32_t* column, struct tcp_pcb *pcb
} }
static snmp_err_t static snmp_err_t
tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) tcp_ConnectionTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip_addr_t local_ip, remote_ip; ip_addr_t local_ip, remote_ip;
u16_t local_port, remote_port; u16_t local_port, remote_port;
struct tcp_pcb *pcb; struct tcp_pcb *pcb;
u8_t idx = 0; u8_t idx = 0;
u8_t i; u8_t i;
struct tcp_pcb ** const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs}; struct tcp_pcb **const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs};
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
/* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */ /* tcpConnectionLocalAddressType + tcpConnectionLocalAddress + tcpConnectionLocalPort */
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port); idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
if (idx == 0) { if (idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
/* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */ /* tcpConnectionRemAddressType + tcpConnectionRemAddress + tcpConnectionRemPort */
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &remote_ip, &remote_port); idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &remote_ip, &remote_port);
if (idx == 0) { if (idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
@ -374,7 +371,7 @@ tcp_ConnectionTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8
} }
static snmp_err_t static snmp_err_t
tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
struct tcp_pcb *pcb; struct tcp_pcb *pcb;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -382,7 +379,7 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct
* 1x tcpConnectionRemAddressType + 1x OID len + 16x tcpConnectionRemAddress + 1x tcpConnectionRemPort */ * 1x tcpConnectionRemAddressType + 1x OID len + 16x tcpConnectionRemAddress + 1x tcpConnectionRemPort */
u32_t result_temp[38]; u32_t result_temp[38];
u8_t i; u8_t i;
struct tcp_pcb ** const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs}; struct tcp_pcb **const tcp_pcb_nonlisten_lists[] = {&tcp_bound_pcbs, &tcp_active_pcbs, &tcp_tw_pcbs};
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
@ -414,7 +411,7 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
/* fill in object properties */ /* fill in object properties */
return tcp_ConnectionTable_get_cell_value_core(column, (struct tcp_pcb*)state.reference, value); return tcp_ConnectionTable_get_cell_value_core(column, (struct tcp_pcb *)state.reference, value);
} else { } else {
/* not found */ /* not found */
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
@ -424,7 +421,7 @@ tcp_ConnectionTable_get_next_cell_instance_and_value(const u32_t* column, struct
/* --- tcpListenerTable --- */ /* --- tcpListenerTable --- */
static snmp_err_t static snmp_err_t
tcp_ListenerTable_get_cell_value_core(const u32_t* column, union snmp_variant_value* value) tcp_ListenerTable_get_cell_value_core(const u32_t *column, union snmp_variant_value *value)
{ {
/* all items except tcpListenerProcess are declared as not-accessible */ /* all items except tcpListenerProcess are declared as not-accessible */
switch (*column) { switch (*column) {
@ -439,7 +436,7 @@ tcp_ListenerTable_get_cell_value_core(const u32_t* column, union snmp_variant_va
} }
static snmp_err_t static snmp_err_t
tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) tcp_ListenerTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip_addr_t local_ip; ip_addr_t local_ip;
u16_t local_port; u16_t local_port;
@ -449,7 +446,7 @@ tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
/* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */ /* tcpListenerLocalAddressType + tcpListenerLocalAddress + tcpListenerLocalPort */
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port); idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
if (idx == 0) { if (idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
@ -470,7 +467,7 @@ tcp_ListenerTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
} }
static snmp_err_t static snmp_err_t
tcp_ListenerTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) tcp_ListenerTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
struct tcp_pcb_listen *pcb; struct tcp_pcb_listen *pcb;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -580,7 +577,7 @@ CREATE_LWIP_SYNC_NODE(18, tcp_HCOutSegs)
CREATE_LWIP_SYNC_NODE(19, tcp_ConnectionTable) CREATE_LWIP_SYNC_NODE(19, tcp_ConnectionTable)
CREATE_LWIP_SYNC_NODE(20, tcp_ListenerTable) CREATE_LWIP_SYNC_NODE(20, tcp_ListenerTable)
static const struct snmp_node* const tcp_nodes[] = { static const struct snmp_node *const tcp_nodes[] = {
&SYNC_NODE_NAME(tcp_RtoAlgorithm).node.node, &SYNC_NODE_NAME(tcp_RtoAlgorithm).node.node,
&SYNC_NODE_NAME(tcp_RtoMin).node.node, &SYNC_NODE_NAME(tcp_RtoMin).node.node,
&SYNC_NODE_NAME(tcp_RtoMax).node.node, &SYNC_NODE_NAME(tcp_RtoMax).node.node,

View File

@ -58,9 +58,9 @@
/* --- udp .1.3.6.1.2.1.7 ----------------------------------------------------- */ /* --- udp .1.3.6.1.2.1.7 ----------------------------------------------------- */
static s16_t static s16_t
udp_get_value(struct snmp_node_instance* instance, void* value) udp_get_value(struct snmp_node_instance *instance, void *value)
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t *)value;
switch (instance->node->oid) { switch (instance->node->oid) {
case 1: /* udpInDatagrams */ case 1: /* udpInDatagrams */
@ -76,23 +76,21 @@ udp_get_value(struct snmp_node_instance* instance, void* value)
*uint_ptr = STATS_GET(mib2.udpoutdatagrams); *uint_ptr = STATS_GET(mib2.udpoutdatagrams);
return sizeof(*uint_ptr); return sizeof(*uint_ptr);
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
case 8: /* udpHCInDatagrams */ case 8: { /* udpHCInDatagrams */
{
/* use the 32 bit counter for now... */ /* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.udpindatagrams); u64_t val64 = STATS_GET(mib2.udpindatagrams);
*((u64_t*)value) = val64; *((u64_t *)value) = val64;
} }
return sizeof(u64_t); return sizeof(u64_t);
case 9: /* udpHCOutDatagrams */ case 9: { /* udpHCOutDatagrams */
{
/* use the 32 bit counter for now... */ /* use the 32 bit counter for now... */
u64_t val64 = STATS_GET(mib2.udpoutdatagrams); u64_t val64 = STATS_GET(mib2.udpoutdatagrams);
*((u64_t*)value) = val64; *((u64_t *)value) = val64;
} }
return sizeof(u64_t); return sizeof(u64_t);
#endif #endif
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_value(): unknown id: %"S32_F"\n", instance->node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("udp_get_value(): unknown id: %"S32_F"\n", instance->node->oid));
break; break;
} }
@ -102,7 +100,7 @@ udp_get_value(struct snmp_node_instance* instance, void* value)
/* --- udpEndpointTable --- */ /* --- udpEndpointTable --- */
static snmp_err_t static snmp_err_t
udp_endpointTable_get_cell_value_core(const u32_t* column, union snmp_variant_value* value) udp_endpointTable_get_cell_value_core(const u32_t *column, union snmp_variant_value *value)
{ {
/* all items except udpEndpointProcess are declared as not-accessible */ /* all items except udpEndpointProcess are declared as not-accessible */
switch (*column) { switch (*column) {
@ -117,7 +115,7 @@ udp_endpointTable_get_cell_value_core(const u32_t* column, union snmp_variant_va
} }
static snmp_err_t static snmp_err_t
udp_endpointTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) udp_endpointTable_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip_addr_t local_ip, remote_ip; ip_addr_t local_ip, remote_ip;
u16_t local_port, remote_port; u16_t local_port, remote_port;
@ -127,19 +125,19 @@ udp_endpointTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
/* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */ /* udpEndpointLocalAddressType + udpEndpointLocalAddress + udpEndpointLocalPort */
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &local_ip, &local_port); idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &local_ip, &local_port);
if (idx == 0) { if (idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
/* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */ /* udpEndpointRemoteAddressType + udpEndpointRemoteAddress + udpEndpointRemotePort */
idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len-idx, &remote_ip, &remote_port); idx += snmp_oid_to_ip_port(&row_oid[idx], row_oid_len - idx, &remote_ip, &remote_port);
if (idx == 0) { if (idx == 0) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
/* udpEndpointInstance */ /* udpEndpointInstance */
if (row_oid_len < (idx+1)) { if (row_oid_len < (idx + 1)) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
if (row_oid[idx] != 0) { if (row_oid[idx] != 0) {
@ -164,7 +162,7 @@ udp_endpointTable_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t
} }
static snmp_err_t static snmp_err_t
udp_endpointTable_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) udp_endpointTable_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
struct udp_pcb *pcb; struct udp_pcb *pcb;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -225,7 +223,7 @@ static const struct snmp_oid_range udp_Table_oid_ranges[] = {
}; };
static snmp_err_t static snmp_err_t
udp_Table_get_cell_value_core(struct udp_pcb *pcb, const u32_t* column, union snmp_variant_value* value, u32_t* value_len) udp_Table_get_cell_value_core(struct udp_pcb *pcb, const u32_t *column, union snmp_variant_value *value, u32_t *value_len)
{ {
LWIP_UNUSED_ARG(value_len); LWIP_UNUSED_ARG(value_len);
@ -246,7 +244,7 @@ udp_Table_get_cell_value_core(struct udp_pcb *pcb, const u32_t* column, union sn
} }
static snmp_err_t static snmp_err_t
udp_Table_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid_len, union snmp_variant_value* value, u32_t* value_len) udp_Table_get_cell_value(const u32_t *column, const u32_t *row_oid, u8_t row_oid_len, union snmp_variant_value *value, u32_t *value_len)
{ {
ip4_addr_t ip; ip4_addr_t ip;
u16_t port; u16_t port;
@ -278,7 +276,7 @@ udp_Table_get_cell_value(const u32_t* column, const u32_t* row_oid, u8_t row_oid
} }
static snmp_err_t static snmp_err_t
udp_Table_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_id* row_oid, union snmp_variant_value* value, u32_t* value_len) udp_Table_get_next_cell_instance_and_value(const u32_t *column, struct snmp_obj_id *row_oid, union snmp_variant_value *value, u32_t *value_len)
{ {
struct udp_pcb *pcb; struct udp_pcb *pcb;
struct snmp_next_oid_state state; struct snmp_next_oid_state state;
@ -307,7 +305,7 @@ udp_Table_get_next_cell_instance_and_value(const u32_t* column, struct snmp_obj_
if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) { if (state.status == SNMP_NEXT_OID_STATUS_SUCCESS) {
snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len); snmp_oid_assign(row_oid, state.next_oid, state.next_oid_len);
/* fill in object properties */ /* fill in object properties */
return udp_Table_get_cell_value_core((struct udp_pcb*)state.reference, column, value, value_len); return udp_Table_get_cell_value_core((struct udp_pcb *)state.reference, column, value, value_len);
} else { } else {
/* not found */ /* not found */
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
@ -354,7 +352,7 @@ CREATE_LWIP_SYNC_NODE(8, udp_HCInDatagrams)
CREATE_LWIP_SYNC_NODE(9, udp_HCOutDatagrams) CREATE_LWIP_SYNC_NODE(9, udp_HCOutDatagrams)
#endif #endif
static const struct snmp_node* const udp_nodes[] = { static const struct snmp_node *const udp_nodes[] = {
&SYNC_NODE_NAME(udp_inDatagrams).node.node, &SYNC_NODE_NAME(udp_inDatagrams).node.node,
&SYNC_NODE_NAME(udp_noPorts).node.node, &SYNC_NODE_NAME(udp_noPorts).node.node,
&SYNC_NODE_NAME(udp_inErrors).node.node, &SYNC_NODE_NAME(udp_inErrors).node.node,

View File

@ -72,7 +72,7 @@ const char *snmp_community_write = SNMP_COMMUNITY_WRITE;
const char *snmp_community_trap = SNMP_COMMUNITY_TRAP; const char *snmp_community_trap = SNMP_COMMUNITY_TRAP;
snmp_write_callback_fct snmp_write_callback = NULL; snmp_write_callback_fct snmp_write_callback = NULL;
void* snmp_write_callback_arg = NULL; void *snmp_write_callback_arg = NULL;
#if LWIP_SNMP_CONFIGURE_VERSIONS #if LWIP_SNMP_CONFIGURE_VERSIONS
@ -91,8 +91,7 @@ snmp_version_enabled(u8_t version)
if (version == SNMP_VERSION_1) { if (version == SNMP_VERSION_1) {
return v1_enabled; return v1_enabled;
} } else if (version == SNMP_VERSION_2c) {
else if (version == SNMP_VERSION_2c) {
return v2c_enabled; return v2c_enabled;
} }
#if LWIP_SNMP_V3 #if LWIP_SNMP_V3
@ -131,8 +130,7 @@ snmp_version_enable(u8_t version, u8_t enable)
if (version == SNMP_VERSION_1) { if (version == SNMP_VERSION_1) {
v1_enabled = enable; v1_enabled = enable;
} } else if (version == SNMP_VERSION_2c) {
else if (version == SNMP_VERSION_2c) {
v2c_enabled = enable; v2c_enabled = enable;
} }
#if LWIP_SNMP_V3 #if LWIP_SNMP_V3
@ -182,7 +180,7 @@ snmp_get_community(void)
* @param community is a pointer to new community string * @param community is a pointer to new community string
*/ */
void void
snmp_set_community(const char * const community) snmp_set_community(const char *const community)
{ {
LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN); LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN);
snmp_community = community; snmp_community = community;
@ -219,7 +217,7 @@ snmp_get_community_trap(void)
* @param community is a pointer to new write-access community string * @param community is a pointer to new write-access community string
*/ */
void void
snmp_set_community_write(const char * const community) snmp_set_community_write(const char *const community)
{ {
LWIP_ASSERT("community string must not be NULL", community != NULL); LWIP_ASSERT("community string must not be NULL", community != NULL);
LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN); LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN);
@ -235,7 +233,7 @@ snmp_set_community_write(const char * const community)
* @param community is a pointer to new trap community string * @param community is a pointer to new trap community string
*/ */
void void
snmp_set_community_trap(const char * const community) snmp_set_community_trap(const char *const community)
{ {
LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN); LWIP_ASSERT("community string is too long!", strlen(community) <= SNMP_MAX_COMMUNITY_STR_LEN);
snmp_community_trap = community; snmp_community_trap = community;
@ -246,7 +244,7 @@ snmp_set_community_trap(const char * const community)
* Callback fired on every successful write access * Callback fired on every successful write access
*/ */
void void
snmp_set_write_callback(snmp_write_callback_fct write_callback, void* callback_arg) snmp_set_write_callback(snmp_write_callback_fct write_callback, void *callback_arg)
{ {
snmp_write_callback = write_callback; snmp_write_callback = write_callback;
snmp_write_callback_arg = callback_arg; snmp_write_callback_arg = callback_arg;
@ -312,43 +310,37 @@ snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t por
vb.value_len = sizeof(u32_t); vb.value_len = sizeof(u32_t);
switch (request.error_status) { switch (request.error_status) {
case SNMP_ERR_AUTHORIZATIONERROR: case SNMP_ERR_AUTHORIZATIONERROR: {
{
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 5, 0 }; static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 5, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid)); snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.wrongdigests; vb.value = &snmp_stats.wrongdigests;
} }
break; break;
case SNMP_ERR_UNKNOWN_ENGINEID: case SNMP_ERR_UNKNOWN_ENGINEID: {
{
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 4, 0 }; static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 4, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid)); snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.unknownengineids; vb.value = &snmp_stats.unknownengineids;
} }
break; break;
case SNMP_ERR_UNKNOWN_SECURITYNAME: case SNMP_ERR_UNKNOWN_SECURITYNAME: {
{
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0 }; static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 3, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid)); snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.unknownusernames; vb.value = &snmp_stats.unknownusernames;
} }
break; break;
case SNMP_ERR_UNSUPPORTED_SECLEVEL: case SNMP_ERR_UNSUPPORTED_SECLEVEL: {
{
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 1, 0 }; static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 1, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid)); snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.unsupportedseclevels; vb.value = &snmp_stats.unsupportedseclevels;
} }
break; break;
case SNMP_ERR_NOTINTIMEWINDOW: case SNMP_ERR_NOTINTIMEWINDOW: {
{
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 2, 0 }; static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 2, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid)); snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.notintimewindows; vb.value = &snmp_stats.notintimewindows;
} }
break; break;
case SNMP_ERR_DECRYIPTION_ERROR: case SNMP_ERR_DECRYIPTION_ERROR: {
{
static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 6, 0 }; static const u32_t oid[] = { 1, 3, 6, 1, 6, 3, 15, 1, 1, 6, 0 };
snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid)); snmp_oid_assign(&vb.oid, oid, LWIP_ARRAYSIZE(oid));
vb.value = &snmp_stats.decryptionerrors; vb.value = &snmp_stats.decryptionerrors;
@ -392,14 +384,14 @@ snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t por
} }
static u8_t static u8_t
snmp_msg_getnext_validate_node_inst(struct snmp_node_instance* node_instance, void* validate_arg) snmp_msg_getnext_validate_node_inst(struct snmp_node_instance *node_instance, void *validate_arg)
{ {
if (((node_instance->access & SNMP_NODE_INSTANCE_ACCESS_READ) != SNMP_NODE_INSTANCE_ACCESS_READ) || (node_instance->get_value == NULL)) { if (((node_instance->access & SNMP_NODE_INSTANCE_ACCESS_READ) != SNMP_NODE_INSTANCE_ACCESS_READ) || (node_instance->get_value == NULL)) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
if ((node_instance->asn1_type == SNMP_ASN1_TYPE_COUNTER64) && (((struct snmp_request*)validate_arg)->version == SNMP_VERSION_1)) { if ((node_instance->asn1_type == SNMP_ASN1_TYPE_COUNTER64) && (((struct snmp_request *)validate_arg)->version == SNMP_VERSION_1)) {
/* according to RFC 2089 skip Counter64 objects in GetNext requests from v1 clients */ /* according to RFC 2089 skip Counter64 objects in GetNext requests from v1 clients */
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
@ -462,7 +454,7 @@ snmp_process_varbind(struct snmp_request *request, struct snmp_varbind *vb, u8_t
s16_t len = node_instance.get_value(&node_instance, vb->value); s16_t len = node_instance.get_value(&node_instance, vb->value);
vb->type = node_instance.asn1_type; vb->type = node_instance.asn1_type;
if(len >= 0) { if (len >= 0) {
vb->value_len = (u16_t)len; /* cast is OK because we checked >= 0 above */ vb->value_len = (u16_t)len; /* cast is OK because we checked >= 0 above */
LWIP_ASSERT("SNMP_MAX_VALUE_SIZE is configured too low", (vb->value_len & ~SNMP_GET_VALUE_RAW_DATA) <= SNMP_MAX_VALUE_SIZE); LWIP_ASSERT("SNMP_MAX_VALUE_SIZE is configured too low", (vb->value_len & ~SNMP_GET_VALUE_RAW_DATA) <= SNMP_MAX_VALUE_SIZE);
@ -808,8 +800,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
#if LWIP_SNMP_CONFIGURE_VERSIONS #if LWIP_SNMP_CONFIGURE_VERSIONS
|| (!snmp_version_enabled(s32_value)) || (!snmp_version_enabled(s32_value))
#endif #endif
) ) {
{
/* unsupported SNMP version */ /* unsupported SNMP version */
snmp_stats.inbadversions++; snmp_stats.inbadversions++;
return ERR_ARG; return ERR_ARG;
@ -823,9 +814,9 @@ snmp_parse_inbound_frame(struct snmp_request *request)
/* SNMPv3 doesn't use communities */ /* SNMPv3 doesn't use communities */
/* @todo: Differentiate read/write access */ /* @todo: Differentiate read/write access */
strncpy((char*)request->community, snmp_community, SNMP_MAX_COMMUNITY_STR_LEN); strncpy((char *)request->community, snmp_community, SNMP_MAX_COMMUNITY_STR_LEN);
request->community[SNMP_MAX_COMMUNITY_STR_LEN] = 0; /* ensure NULL termination (strncpy does NOT guarantee it!) */ request->community[SNMP_MAX_COMMUNITY_STR_LEN] = 0; /* ensure NULL termination (strncpy does NOT guarantee it!) */
request->community_strlen = (u16_t)strnlen((char*)request->community, SNMP_MAX_COMMUNITY_STR_LEN); request->community_strlen = (u16_t)strnlen((char *)request->community, SNMP_MAX_COMMUNITY_STR_LEN);
/* RFC3414 globalData */ /* RFC3414 globalData */
IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv)); IF_PARSE_EXEC(snmp_asn1_dec_tlv(&pbuf_stream, &tlv));
@ -970,7 +961,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
} }
/* 4) verify username */ /* 4) verify username */
if(snmpv3_get_user((char*)request->msg_user_name, &auth, NULL, &priv, NULL)) { if (snmpv3_get_user((char *)request->msg_user_name, &auth, NULL, &priv, NULL)) {
snmp_stats.unknownusernames++; snmp_stats.unknownusernames++;
request->msg_flags = 0; /* noauthnopriv */ request->msg_flags = 0; /* noauthnopriv */
request->error_status = SNMP_ERR_UNKNOWN_SECURITYNAME; request->error_status = SNMP_ERR_UNKNOWN_SECURITYNAME;
@ -978,7 +969,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
} }
/* 5) verify security level */ /* 5) verify security level */
switch(request->msg_flags & (SNMP_V3_AUTH_FLAG | SNMP_V3_PRIV_FLAG)) { switch (request->msg_flags & (SNMP_V3_AUTH_FLAG | SNMP_V3_PRIV_FLAG)) {
case SNMP_V3_NOAUTHNOPRIV: case SNMP_V3_NOAUTHNOPRIV:
if ((auth != SNMP_V3_AUTH_ALGO_INVAL) || (priv != SNMP_V3_PRIV_ALGO_INVAL)) { if ((auth != SNMP_V3_AUTH_ALGO_INVAL) || (priv != SNMP_V3_PRIV_ALGO_INVAL)) {
/* Invalid security level for user */ /* Invalid security level for user */
@ -1039,10 +1030,10 @@ snmp_parse_inbound_frame(struct snmp_request *request)
/* Verify authentication */ /* Verify authentication */
IF_PARSE_EXEC(snmp_pbuf_stream_init(&auth_stream, request->inbound_pbuf, 0, request->inbound_pbuf->tot_len)); IF_PARSE_EXEC(snmp_pbuf_stream_init(&auth_stream, request->inbound_pbuf, 0, request->inbound_pbuf->tot_len));
IF_PARSE_EXEC(snmpv3_get_user((char*)request->msg_user_name, &auth, key, NULL, NULL)); IF_PARSE_EXEC(snmpv3_get_user((char *)request->msg_user_name, &auth, key, NULL, NULL));
IF_PARSE_EXEC(snmpv3_auth(&auth_stream, request->inbound_pbuf->tot_len, key, auth, hmac)); IF_PARSE_EXEC(snmpv3_auth(&auth_stream, request->inbound_pbuf->tot_len, key, auth, hmac));
if(memcmp(request->msg_authentication_parameters, hmac, SNMP_V3_MAX_AUTH_PARAM_LENGTH)) { if (memcmp(request->msg_authentication_parameters, hmac, SNMP_V3_MAX_AUTH_PARAM_LENGTH)) {
snmp_stats.wrongdigests++; snmp_stats.wrongdigests++;
request->msg_flags = SNMP_V3_NOAUTHNOPRIV; request->msg_flags = SNMP_V3_NOAUTHNOPRIV;
request->error_status = SNMP_ERR_AUTHORIZATIONERROR; request->error_status = SNMP_ERR_AUTHORIZATIONERROR;
@ -1066,8 +1057,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
request->msg_flags = SNMP_V3_AUTHNOPRIV; request->msg_flags = SNMP_V3_AUTHNOPRIV;
request->error_status = SNMP_ERR_NOTINTIMEWINDOW; request->error_status = SNMP_ERR_NOTINTIMEWINDOW;
return ERR_OK; return ERR_OK;
} } else if (time > 150) {
else if (time > 150) {
if (request->msg_authoritative_engine_time < time - 150) { if (request->msg_authoritative_engine_time < time - 150) {
snmp_stats.notintimewindows++; snmp_stats.notintimewindows++;
request->msg_flags = SNMP_V3_AUTHNOPRIV; request->msg_flags = SNMP_V3_AUTHNOPRIV;
@ -1091,8 +1081,8 @@ snmp_parse_inbound_frame(struct snmp_request *request)
parent_tlv_value_len -= SNMP_ASN1_TLV_HDR_LENGTH(tlv); parent_tlv_value_len -= SNMP_ASN1_TLV_HDR_LENGTH(tlv);
IF_PARSE_ASSERT(parent_tlv_value_len > 0); IF_PARSE_ASSERT(parent_tlv_value_len > 0);
IF_PARSE_EXEC(snmpv3_get_user((char*)request->msg_user_name, NULL, NULL, &priv, key)); IF_PARSE_EXEC(snmpv3_get_user((char *)request->msg_user_name, NULL, NULL, &priv, key));
if(snmpv3_crypt(&pbuf_stream, tlv.value_len, key, if (snmpv3_crypt(&pbuf_stream, tlv.value_len, key,
request->msg_privacy_parameters, request->msg_authoritative_engine_boots, request->msg_privacy_parameters, request->msg_authoritative_engine_boots,
request->msg_authoritative_engine_time, priv, SNMP_V3_PRIV_MODE_DECRYPT) != ERR_OK) { request->msg_authoritative_engine_time, priv, SNMP_V3_PRIV_MODE_DECRYPT) != ERR_OK) {
snmp_stats.decryptionerrors++; snmp_stats.decryptionerrors++;
@ -1165,7 +1155,7 @@ snmp_parse_inbound_frame(struct snmp_request *request)
parent_tlv_value_len = tlv.value_len; parent_tlv_value_len = tlv.value_len;
/* validate PDU type */ /* validate PDU type */
switch(tlv.type) { switch (tlv.type) {
case (SNMP_ASN1_CLASS_CONTEXT | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_CONTEXT_PDU_GET_REQ): case (SNMP_ASN1_CLASS_CONTEXT | SNMP_ASN1_CONTENTTYPE_CONSTRUCTED | SNMP_ASN1_CONTEXT_PDU_GET_REQ):
/* GetRequest PDU */ /* GetRequest PDU */
snmp_stats.ingetrequests++; snmp_stats.ingetrequests++;
@ -1204,14 +1194,14 @@ snmp_parse_inbound_frame(struct snmp_request *request)
/* our write community is empty, that means all our objects are readonly */ /* our write community is empty, that means all our objects are readonly */
request->error_status = SNMP_ERR_NOTWRITABLE; request->error_status = SNMP_ERR_NOTWRITABLE;
request->error_index = 1; request->error_index = 1;
} else if (strncmp(snmp_community_write, (const char*)request->community, SNMP_MAX_COMMUNITY_STR_LEN) != 0) { } else if (strncmp(snmp_community_write, (const char *)request->community, SNMP_MAX_COMMUNITY_STR_LEN) != 0) {
/* community name does not match */ /* community name does not match */
snmp_stats.inbadcommunitynames++; snmp_stats.inbadcommunitynames++;
snmp_authfail_trap(); snmp_authfail_trap();
return ERR_ARG; return ERR_ARG;
} }
} else { } else {
if (strncmp(snmp_community, (const char*)request->community, SNMP_MAX_COMMUNITY_STR_LEN) != 0) { if (strncmp(snmp_community, (const char *)request->community, SNMP_MAX_COMMUNITY_STR_LEN) != 0) {
/* community name does not match */ /* community name does not match */
snmp_stats.inbadcommunitynames++; snmp_stats.inbadcommunitynames++;
snmp_authfail_trap(); snmp_authfail_trap();
@ -1279,7 +1269,7 @@ static err_t
snmp_prepare_outbound_frame(struct snmp_request *request) snmp_prepare_outbound_frame(struct snmp_request *request)
{ {
struct snmp_asn1_tlv tlv; struct snmp_asn1_tlv tlv;
struct snmp_pbuf_stream* pbuf_stream = &(request->outbound_pbuf_stream); struct snmp_pbuf_stream *pbuf_stream = &(request->outbound_pbuf_stream);
/* try allocating pbuf(s) for maximum response size */ /* try allocating pbuf(s) for maximum response size */
request->outbound_pbuf = pbuf_alloc(PBUF_TRANSPORT, 1472, PBUF_RAM); request->outbound_pbuf = pbuf_alloc(PBUF_TRANSPORT, 1472, PBUF_RAM);
@ -1308,7 +1298,7 @@ snmp_prepare_outbound_frame(struct snmp_request *request)
OF_BUILD_EXEC( snmp_asn1_enc_raw(pbuf_stream, request->community, request->community_strlen) ); OF_BUILD_EXEC( snmp_asn1_enc_raw(pbuf_stream, request->community, request->community_strlen) );
#if LWIP_SNMP_V3 #if LWIP_SNMP_V3
} else { } else {
const char* id; const char *id;
/* globalData */ /* globalData */
request->outbound_msg_global_data_offset = pbuf_stream->offset; request->outbound_msg_global_data_offset = pbuf_stream->offset;
@ -1489,7 +1479,7 @@ snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len)
if (varbind->value_len != sizeof (s32_t)) { if (varbind->value_len != sizeof (s32_t)) {
return ERR_VAL; return ERR_VAL;
} }
snmp_asn1_enc_s32t_cnt(*((s32_t*) varbind->value), &len->value_value_len); snmp_asn1_enc_s32t_cnt(*((s32_t *) varbind->value), &len->value_value_len);
break; break;
case SNMP_ASN1_TYPE_COUNTER: case SNMP_ASN1_TYPE_COUNTER:
case SNMP_ASN1_TYPE_GAUGE: case SNMP_ASN1_TYPE_GAUGE:
@ -1497,7 +1487,7 @@ snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len)
if (varbind->value_len != sizeof (u32_t)) { if (varbind->value_len != sizeof (u32_t)) {
return ERR_VAL; return ERR_VAL;
} }
snmp_asn1_enc_u32t_cnt(*((u32_t*) varbind->value), &len->value_value_len); snmp_asn1_enc_u32t_cnt(*((u32_t *) varbind->value), &len->value_value_len);
break; break;
case SNMP_ASN1_TYPE_OCTET_STRING: case SNMP_ASN1_TYPE_OCTET_STRING:
case SNMP_ASN1_TYPE_IPADDR: case SNMP_ASN1_TYPE_IPADDR:
@ -1514,14 +1504,14 @@ snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len)
if ((varbind->value_len & 0x03) != 0) { if ((varbind->value_len & 0x03) != 0) {
return ERR_VAL; return ERR_VAL;
} }
snmp_asn1_enc_oid_cnt((u32_t*) varbind->value, varbind->value_len >> 2, &len->value_value_len); snmp_asn1_enc_oid_cnt((u32_t *) varbind->value, varbind->value_len >> 2, &len->value_value_len);
break; break;
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
case SNMP_ASN1_TYPE_COUNTER64: case SNMP_ASN1_TYPE_COUNTER64:
if (varbind->value_len != sizeof(u64_t)) { if (varbind->value_len != sizeof(u64_t)) {
return ERR_VAL; return ERR_VAL;
} }
snmp_asn1_enc_u64t_cnt(*(u64_t*)varbind->value, &len->value_value_len); snmp_asn1_enc_u64t_cnt(*(u64_t *)varbind->value, &len->value_value_len);
break; break;
#endif #endif
default: default:
@ -1540,7 +1530,7 @@ snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len)
#define OVB_BUILD_EXEC(code) BUILD_EXEC(code, ERR_ARG) #define OVB_BUILD_EXEC(code) BUILD_EXEC(code, ERR_ARG)
err_t err_t
snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind* varbind) snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind *varbind)
{ {
struct snmp_asn1_tlv tlv; struct snmp_asn1_tlv tlv;
struct snmp_varbind_len len; struct snmp_varbind_len len;
@ -1574,29 +1564,29 @@ snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_v
if (len.value_value_len > 0) { if (len.value_value_len > 0) {
if (varbind->value_len & SNMP_GET_VALUE_RAW_DATA) { if (varbind->value_len & SNMP_GET_VALUE_RAW_DATA) {
OVB_BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (u8_t*) varbind->value, len.value_value_len)); OVB_BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (u8_t *) varbind->value, len.value_value_len));
} else { } else {
switch (varbind->type) { switch (varbind->type) {
case SNMP_ASN1_TYPE_INTEGER: case SNMP_ASN1_TYPE_INTEGER:
OVB_BUILD_EXEC(snmp_asn1_enc_s32t(pbuf_stream, len.value_value_len, *((s32_t*) varbind->value))); OVB_BUILD_EXEC(snmp_asn1_enc_s32t(pbuf_stream, len.value_value_len, *((s32_t *) varbind->value)));
break; break;
case SNMP_ASN1_TYPE_COUNTER: case SNMP_ASN1_TYPE_COUNTER:
case SNMP_ASN1_TYPE_GAUGE: case SNMP_ASN1_TYPE_GAUGE:
case SNMP_ASN1_TYPE_TIMETICKS: case SNMP_ASN1_TYPE_TIMETICKS:
OVB_BUILD_EXEC(snmp_asn1_enc_u32t(pbuf_stream, len.value_value_len, *((u32_t*) varbind->value))); OVB_BUILD_EXEC(snmp_asn1_enc_u32t(pbuf_stream, len.value_value_len, *((u32_t *) varbind->value)));
break; break;
case SNMP_ASN1_TYPE_OCTET_STRING: case SNMP_ASN1_TYPE_OCTET_STRING:
case SNMP_ASN1_TYPE_IPADDR: case SNMP_ASN1_TYPE_IPADDR:
case SNMP_ASN1_TYPE_OPAQUE: case SNMP_ASN1_TYPE_OPAQUE:
OVB_BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (u8_t*) varbind->value, len.value_value_len)); OVB_BUILD_EXEC(snmp_asn1_enc_raw(pbuf_stream, (u8_t *) varbind->value, len.value_value_len));
len.value_value_len = varbind->value_len; len.value_value_len = varbind->value_len;
break; break;
case SNMP_ASN1_TYPE_OBJECT_ID: case SNMP_ASN1_TYPE_OBJECT_ID:
OVB_BUILD_EXEC(snmp_asn1_enc_oid(pbuf_stream, (u32_t*) varbind->value, varbind->value_len / sizeof (u32_t))); OVB_BUILD_EXEC(snmp_asn1_enc_oid(pbuf_stream, (u32_t *) varbind->value, varbind->value_len / sizeof (u32_t)));
break; break;
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
case SNMP_ASN1_TYPE_COUNTER64: case SNMP_ASN1_TYPE_COUNTER64:
OVB_BUILD_EXEC(snmp_asn1_enc_u64t(pbuf_stream, len.value_value_len, *(u64_t*) varbind->value)); OVB_BUILD_EXEC(snmp_asn1_enc_u64t(pbuf_stream, len.value_value_len, *(u64_t *) varbind->value));
break; break;
#endif #endif
default: default:
@ -1804,7 +1794,7 @@ snmp_complete_outbound_frame(struct snmp_request *request)
- request->outbound_scoped_pdu_string_offset - 1 - 3); - request->outbound_scoped_pdu_string_offset - 1 - 3);
OF_BUILD_EXEC(snmp_ans1_enc_tlv(&(request->outbound_pbuf_stream), &tlv)); OF_BUILD_EXEC(snmp_ans1_enc_tlv(&(request->outbound_pbuf_stream), &tlv));
OF_BUILD_EXEC(snmpv3_get_user((char*)request->msg_user_name, NULL, NULL, &algo, key)); OF_BUILD_EXEC(snmpv3_get_user((char *)request->msg_user_name, NULL, NULL, &algo, key));
OF_BUILD_EXEC(snmpv3_crypt(&request->outbound_pbuf_stream, tlv.value_len, key, OF_BUILD_EXEC(snmpv3_crypt(&request->outbound_pbuf_stream, tlv.value_len, key,
request->msg_privacy_parameters, request->msg_authoritative_engine_boots, request->msg_privacy_parameters, request->msg_authoritative_engine_boots,
@ -1816,7 +1806,7 @@ snmp_complete_outbound_frame(struct snmp_request *request)
snmpv3_auth_algo_t algo; snmpv3_auth_algo_t algo;
u8_t hmac[20]; u8_t hmac[20];
OF_BUILD_EXEC(snmpv3_get_user((char*)request->msg_user_name, &algo, key, NULL, NULL)); OF_BUILD_EXEC(snmpv3_get_user((char *)request->msg_user_name, &algo, key, NULL, NULL));
OF_BUILD_EXEC(snmp_pbuf_stream_init(&(request->outbound_pbuf_stream), OF_BUILD_EXEC(snmp_pbuf_stream_init(&(request->outbound_pbuf_stream),
request->outbound_pbuf, 0, request->outbound_pbuf->tot_len)); request->outbound_pbuf, 0, request->outbound_pbuf->tot_len));
OF_BUILD_EXEC(snmpv3_auth(&request->outbound_pbuf_stream, frame_size + outbound_padding, key, algo, hmac)); OF_BUILD_EXEC(snmpv3_auth(&request->outbound_pbuf_stream, frame_size + outbound_padding, key, algo, hmac));
@ -1862,7 +1852,7 @@ snmp_execute_write_callbacks(struct snmp_request *request)
/* ----------------------------------------------------------------------- */ /* ----------------------------------------------------------------------- */
void void
snmp_vb_enumerator_init(struct snmp_varbind_enumerator* enumerator, struct pbuf* p, u16_t offset, u16_t length) snmp_vb_enumerator_init(struct snmp_varbind_enumerator *enumerator, struct pbuf *p, u16_t offset, u16_t length)
{ {
snmp_pbuf_stream_init(&(enumerator->pbuf_stream), p, offset, length); snmp_pbuf_stream_init(&(enumerator->pbuf_stream), p, offset, length);
enumerator->varbind_count = 0; enumerator->varbind_count = 0;
@ -1872,14 +1862,13 @@ snmp_vb_enumerator_init(struct snmp_varbind_enumerator* enumerator, struct pbuf*
#define VB_PARSE_ASSERT(code) PARSE_ASSERT(code, SNMP_VB_ENUMERATOR_ERR_ASN1ERROR) #define VB_PARSE_ASSERT(code) PARSE_ASSERT(code, SNMP_VB_ENUMERATOR_ERR_ASN1ERROR)
snmp_vb_enumerator_err_t snmp_vb_enumerator_err_t
snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct snmp_varbind* varbind) snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator *enumerator, struct snmp_varbind *varbind)
{ {
struct snmp_asn1_tlv tlv; struct snmp_asn1_tlv tlv;
u16_t varbind_len; u16_t varbind_len;
err_t err; err_t err;
if (enumerator->pbuf_stream.length == 0) if (enumerator->pbuf_stream.length == 0) {
{
return SNMP_VB_ENUMERATOR_ERR_EOVB; return SNMP_VB_ENUMERATOR_ERR_EOVB;
} }
enumerator->varbind_count++; enumerator->varbind_count++;
@ -1905,18 +1894,18 @@ snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct s
if (varbind->value != NULL) { if (varbind->value != NULL) {
switch (varbind->type) { switch (varbind->type) {
case SNMP_ASN1_TYPE_INTEGER: case SNMP_ASN1_TYPE_INTEGER:
VB_PARSE_EXEC(snmp_asn1_dec_s32t(&(enumerator->pbuf_stream), tlv.value_len, (s32_t*)varbind->value)); VB_PARSE_EXEC(snmp_asn1_dec_s32t(&(enumerator->pbuf_stream), tlv.value_len, (s32_t *)varbind->value));
varbind->value_len = sizeof(s32_t); varbind->value_len = sizeof(s32_t);
break; break;
case SNMP_ASN1_TYPE_COUNTER: case SNMP_ASN1_TYPE_COUNTER:
case SNMP_ASN1_TYPE_GAUGE: case SNMP_ASN1_TYPE_GAUGE:
case SNMP_ASN1_TYPE_TIMETICKS: case SNMP_ASN1_TYPE_TIMETICKS:
VB_PARSE_EXEC(snmp_asn1_dec_u32t(&(enumerator->pbuf_stream), tlv.value_len, (u32_t*)varbind->value)); VB_PARSE_EXEC(snmp_asn1_dec_u32t(&(enumerator->pbuf_stream), tlv.value_len, (u32_t *)varbind->value));
varbind->value_len = sizeof(u32_t); varbind->value_len = sizeof(u32_t);
break; break;
case SNMP_ASN1_TYPE_OCTET_STRING: case SNMP_ASN1_TYPE_OCTET_STRING:
case SNMP_ASN1_TYPE_OPAQUE: case SNMP_ASN1_TYPE_OPAQUE:
err = snmp_asn1_dec_raw(&(enumerator->pbuf_stream), tlv.value_len, (u8_t*)varbind->value, &varbind->value_len, SNMP_MAX_VALUE_SIZE); err = snmp_asn1_dec_raw(&(enumerator->pbuf_stream), tlv.value_len, (u8_t *)varbind->value, &varbind->value_len, SNMP_MAX_VALUE_SIZE);
if (err == ERR_MEM) { if (err == ERR_MEM) {
return SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH; return SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH;
} }
@ -1927,7 +1916,7 @@ snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct s
break; break;
case SNMP_ASN1_TYPE_OBJECT_ID: case SNMP_ASN1_TYPE_OBJECT_ID:
/* misuse tlv.length_len as OID_length transporter */ /* misuse tlv.length_len as OID_length transporter */
err = snmp_asn1_dec_oid(&(enumerator->pbuf_stream), tlv.value_len, (u32_t*)varbind->value, &tlv.length_len, SNMP_MAX_OBJ_ID_LEN); err = snmp_asn1_dec_oid(&(enumerator->pbuf_stream), tlv.value_len, (u32_t *)varbind->value, &tlv.length_len, SNMP_MAX_OBJ_ID_LEN);
if (err == ERR_MEM) { if (err == ERR_MEM) {
return SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH; return SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH;
} }
@ -1937,14 +1926,14 @@ snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct s
case SNMP_ASN1_TYPE_IPADDR: case SNMP_ASN1_TYPE_IPADDR:
if (tlv.value_len == 4) { if (tlv.value_len == 4) {
/* must be exactly 4 octets! */ /* must be exactly 4 octets! */
VB_PARSE_EXEC(snmp_asn1_dec_raw(&(enumerator->pbuf_stream), tlv.value_len, (u8_t*)varbind->value, &varbind->value_len, SNMP_MAX_VALUE_SIZE)); VB_PARSE_EXEC(snmp_asn1_dec_raw(&(enumerator->pbuf_stream), tlv.value_len, (u8_t *)varbind->value, &varbind->value_len, SNMP_MAX_VALUE_SIZE));
} else { } else {
VB_PARSE_ASSERT(0); VB_PARSE_ASSERT(0);
} }
break; break;
#if LWIP_HAVE_INT64 #if LWIP_HAVE_INT64
case SNMP_ASN1_TYPE_COUNTER64: case SNMP_ASN1_TYPE_COUNTER64:
VB_PARSE_EXEC(snmp_asn1_dec_u64t(&(enumerator->pbuf_stream), tlv.value_len, (u64_t*)varbind->value)); VB_PARSE_EXEC(snmp_asn1_dec_u64t(&(enumerator->pbuf_stream), tlv.value_len, (u64_t *)varbind->value));
varbind->value_len = sizeof(u64_t); varbind->value_len = sizeof(u64_t);
break; break;
#endif #endif

View File

@ -62,8 +62,7 @@ extern "C" {
#define SNMP_VERSION_2c 1 #define SNMP_VERSION_2c 1
#define SNMP_VERSION_3 3 #define SNMP_VERSION_3 3
struct snmp_varbind_enumerator struct snmp_varbind_enumerator {
{
struct snmp_pbuf_stream pbuf_stream; struct snmp_pbuf_stream pbuf_stream;
u16_t varbind_count; u16_t varbind_count;
}; };
@ -75,11 +74,10 @@ typedef enum {
SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH = 3 SNMP_VB_ENUMERATOR_ERR_INVALIDLENGTH = 3
} snmp_vb_enumerator_err_t; } snmp_vb_enumerator_err_t;
void snmp_vb_enumerator_init(struct snmp_varbind_enumerator* enumerator, struct pbuf* p, u16_t offset, u16_t length); void snmp_vb_enumerator_init(struct snmp_varbind_enumerator *enumerator, struct pbuf *p, u16_t offset, u16_t length);
snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator* enumerator, struct snmp_varbind* varbind); snmp_vb_enumerator_err_t snmp_vb_enumerator_get_next(struct snmp_varbind_enumerator *enumerator, struct snmp_varbind *varbind);
struct snmp_request struct snmp_request {
{
/* Communication handle */ /* Communication handle */
void *handle; void *handle;
/* source IP address */ /* source IP address */
@ -156,8 +154,7 @@ struct snmp_request
}; };
/** A helper struct keeping length information about varbinds */ /** A helper struct keeping length information about varbinds */
struct snmp_varbind_len struct snmp_varbind_len {
{
u8_t vb_len_len; u8_t vb_len_len;
u16_t vb_value_len; u16_t vb_value_len;
u8_t oid_len_len; u8_t oid_len_len;
@ -171,13 +168,13 @@ extern const char *snmp_community;
/** Agent community string for write access */ /** Agent community string for write access */
extern const char *snmp_community_write; extern const char *snmp_community_write;
/** handle for sending traps */ /** handle for sending traps */
extern void* snmp_traps_handle; extern void *snmp_traps_handle;
void snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t port); void snmp_receive(void *handle, struct pbuf *p, const ip_addr_t *source_ip, u16_t port);
err_t snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port); err_t snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port);
u8_t snmp_get_local_ip_for_dst(void* handle, const ip_addr_t *dst, ip_addr_t *result); u8_t snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result);
err_t snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len); err_t snmp_varbind_length(struct snmp_varbind *varbind, struct snmp_varbind_len *len);
err_t snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind* varbind); err_t snmp_append_outbound_varbind(struct snmp_pbuf_stream *pbuf_stream, struct snmp_varbind *varbind);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -75,7 +75,7 @@ snmp_netconn_thread(void *arg)
if (buf != NULL) { if (buf != NULL) {
netbuf_delete(buf); netbuf_delete(buf);
} }
} while(1); } while (1);
} }
err_t err_t
@ -86,17 +86,17 @@ snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
memset(&buf, 0, sizeof(buf)); memset(&buf, 0, sizeof(buf));
buf.p = p; buf.p = p;
result = netconn_sendto((struct netconn*)handle, &buf, dst, port); result = netconn_sendto((struct netconn *)handle, &buf, dst, port);
return result; return result;
} }
u8_t u8_t
snmp_get_local_ip_for_dst(void* handle, const ip_addr_t *dst, ip_addr_t *result) snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
{ {
struct netconn* conn = (struct netconn*)handle; struct netconn *conn = (struct netconn *)handle;
struct netif *dst_if; struct netif *dst_if;
const ip_addr_t* dst_ip; const ip_addr_t *dst_ip;
LWIP_UNUSED_ARG(conn); /* unused in case of IPV4 only configuration */ LWIP_UNUSED_ARG(conn); /* unused in case of IPV4 only configuration */

View File

@ -44,7 +44,7 @@
#include <string.h> #include <string.h>
err_t err_t
snmp_pbuf_stream_init(struct snmp_pbuf_stream* pbuf_stream, struct pbuf* p, u16_t offset, u16_t length) snmp_pbuf_stream_init(struct snmp_pbuf_stream *pbuf_stream, struct pbuf *p, u16_t offset, u16_t length)
{ {
pbuf_stream->offset = offset; pbuf_stream->offset = offset;
pbuf_stream->length = length; pbuf_stream->length = length;
@ -54,7 +54,7 @@ snmp_pbuf_stream_init(struct snmp_pbuf_stream* pbuf_stream, struct pbuf* p, u16_
} }
err_t err_t
snmp_pbuf_stream_read(struct snmp_pbuf_stream* pbuf_stream, u8_t* data) snmp_pbuf_stream_read(struct snmp_pbuf_stream *pbuf_stream, u8_t *data)
{ {
if (pbuf_stream->length == 0) { if (pbuf_stream->length == 0) {
return ERR_BUF; return ERR_BUF;
@ -71,13 +71,13 @@ snmp_pbuf_stream_read(struct snmp_pbuf_stream* pbuf_stream, u8_t* data)
} }
err_t err_t
snmp_pbuf_stream_write(struct snmp_pbuf_stream* pbuf_stream, u8_t data) snmp_pbuf_stream_write(struct snmp_pbuf_stream *pbuf_stream, u8_t data)
{ {
return snmp_pbuf_stream_writebuf(pbuf_stream, &data, 1); return snmp_pbuf_stream_writebuf(pbuf_stream, &data, 1);
} }
err_t err_t
snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream* pbuf_stream, const void* buf, u16_t buf_len) snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream *pbuf_stream, const void *buf, u16_t buf_len)
{ {
if (pbuf_stream->length < buf_len) { if (pbuf_stream->length < buf_len) {
return ERR_BUF; return ERR_BUF;
@ -94,7 +94,7 @@ snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream* pbuf_stream, const void* buf,
} }
err_t err_t
snmp_pbuf_stream_writeto(struct snmp_pbuf_stream* pbuf_stream, struct snmp_pbuf_stream* target_pbuf_stream, u16_t len) snmp_pbuf_stream_writeto(struct snmp_pbuf_stream *pbuf_stream, struct snmp_pbuf_stream *target_pbuf_stream, u16_t len)
{ {
if ((pbuf_stream == NULL) || (target_pbuf_stream == NULL)) { if ((pbuf_stream == NULL) || (target_pbuf_stream == NULL)) {
@ -112,14 +112,14 @@ snmp_pbuf_stream_writeto(struct snmp_pbuf_stream* pbuf_stream, struct snmp_pbuf_
u16_t chunk_len; u16_t chunk_len;
err_t err; err_t err;
u16_t target_offset; u16_t target_offset;
struct pbuf* pbuf = pbuf_skip(pbuf_stream->pbuf, pbuf_stream->offset, &target_offset); struct pbuf *pbuf = pbuf_skip(pbuf_stream->pbuf, pbuf_stream->offset, &target_offset);
if ((pbuf == NULL) || (pbuf->len == 0)) { if ((pbuf == NULL) || (pbuf->len == 0)) {
return ERR_BUF; return ERR_BUF;
} }
chunk_len = LWIP_MIN(len, pbuf->len); chunk_len = LWIP_MIN(len, pbuf->len);
err = snmp_pbuf_stream_writebuf(target_pbuf_stream, &((u8_t*)pbuf->payload)[target_offset], chunk_len); err = snmp_pbuf_stream_writebuf(target_pbuf_stream, &((u8_t *)pbuf->payload)[target_offset], chunk_len);
if (err != ERR_OK) { if (err != ERR_OK) {
return err; return err;
} }
@ -133,7 +133,7 @@ snmp_pbuf_stream_writeto(struct snmp_pbuf_stream* pbuf_stream, struct snmp_pbuf_
} }
err_t err_t
snmp_pbuf_stream_seek(struct snmp_pbuf_stream* pbuf_stream, s32_t offset) snmp_pbuf_stream_seek(struct snmp_pbuf_stream *pbuf_stream, s32_t offset)
{ {
if ((offset < 0) || (offset > pbuf_stream->length)) { if ((offset < 0) || (offset > pbuf_stream->length)) {
/* we cannot seek backwards or forward behind stream end */ /* we cannot seek backwards or forward behind stream end */
@ -147,7 +147,7 @@ snmp_pbuf_stream_seek(struct snmp_pbuf_stream* pbuf_stream, s32_t offset)
} }
err_t err_t
snmp_pbuf_stream_seek_abs(struct snmp_pbuf_stream* pbuf_stream, u32_t offset) snmp_pbuf_stream_seek_abs(struct snmp_pbuf_stream *pbuf_stream, u32_t offset)
{ {
s32_t rel_offset = offset - pbuf_stream->offset; s32_t rel_offset = offset - pbuf_stream->offset;
return snmp_pbuf_stream_seek(pbuf_stream, rel_offset); return snmp_pbuf_stream_seek(pbuf_stream, rel_offset);

View File

@ -49,20 +49,19 @@
extern "C" { extern "C" {
#endif #endif
struct snmp_pbuf_stream struct snmp_pbuf_stream {
{ struct pbuf *pbuf;
struct pbuf* pbuf;
u16_t offset; u16_t offset;
u16_t length; u16_t length;
}; };
err_t snmp_pbuf_stream_init(struct snmp_pbuf_stream* pbuf_stream, struct pbuf* p, u16_t offset, u16_t length); err_t snmp_pbuf_stream_init(struct snmp_pbuf_stream *pbuf_stream, struct pbuf *p, u16_t offset, u16_t length);
err_t snmp_pbuf_stream_read(struct snmp_pbuf_stream* pbuf_stream, u8_t* data); err_t snmp_pbuf_stream_read(struct snmp_pbuf_stream *pbuf_stream, u8_t *data);
err_t snmp_pbuf_stream_write(struct snmp_pbuf_stream* pbuf_stream, u8_t data); err_t snmp_pbuf_stream_write(struct snmp_pbuf_stream *pbuf_stream, u8_t data);
err_t snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream* pbuf_stream, const void* buf, u16_t buf_len); err_t snmp_pbuf_stream_writebuf(struct snmp_pbuf_stream *pbuf_stream, const void *buf, u16_t buf_len);
err_t snmp_pbuf_stream_writeto(struct snmp_pbuf_stream* pbuf_stream, struct snmp_pbuf_stream* target_pbuf_stream, u16_t len); err_t snmp_pbuf_stream_writeto(struct snmp_pbuf_stream *pbuf_stream, struct snmp_pbuf_stream *target_pbuf_stream, u16_t len);
err_t snmp_pbuf_stream_seek(struct snmp_pbuf_stream* pbuf_stream, s32_t offset); err_t snmp_pbuf_stream_seek(struct snmp_pbuf_stream *pbuf_stream, s32_t offset);
err_t snmp_pbuf_stream_seek_abs(struct snmp_pbuf_stream* pbuf_stream, u32_t offset); err_t snmp_pbuf_stream_seek_abs(struct snmp_pbuf_stream *pbuf_stream, u32_t offset);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -56,15 +56,15 @@ snmp_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr,
err_t err_t
snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port) snmp_sendto(void *handle, struct pbuf *p, const ip_addr_t *dst, u16_t port)
{ {
return udp_sendto((struct udp_pcb*)handle, p, dst, port); return udp_sendto((struct udp_pcb *)handle, p, dst, port);
} }
u8_t u8_t
snmp_get_local_ip_for_dst(void* handle, const ip_addr_t *dst, ip_addr_t *result) snmp_get_local_ip_for_dst(void *handle, const ip_addr_t *dst, ip_addr_t *result)
{ {
struct udp_pcb* udp_pcb = (struct udp_pcb*)handle; struct udp_pcb *udp_pcb = (struct udp_pcb *)handle;
struct netif *dst_if; struct netif *dst_if;
const ip_addr_t* dst_ip; const ip_addr_t *dst_ip;
LWIP_UNUSED_ARG(udp_pcb); /* unused in case of IPV4 only configuration */ LWIP_UNUSED_ARG(udp_pcb); /* unused in case of IPV4 only configuration */

View File

@ -42,14 +42,14 @@
#include "lwip/apps/snmp_scalar.h" #include "lwip/apps/snmp_scalar.h"
#include "lwip/apps/snmp_core.h" #include "lwip/apps/snmp_core.h"
static s16_t snmp_scalar_array_get_value(struct snmp_node_instance* instance, void* value); static s16_t snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value);
static snmp_err_t snmp_scalar_array_set_test(struct snmp_node_instance* instance, u16_t value_len, void* value); static snmp_err_t snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value);
static snmp_err_t snmp_scalar_array_set_value(struct snmp_node_instance* instance, u16_t value_len, void* value); static snmp_err_t snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value);
snmp_err_t snmp_err_t
snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
const struct snmp_scalar_node* scalar_node = (const struct snmp_scalar_node*)(const void*)instance->node; const struct snmp_scalar_node *scalar_node = (const struct snmp_scalar_node *)(const void *)instance->node;
LWIP_UNUSED_ARG(root_oid); LWIP_UNUSED_ARG(root_oid);
LWIP_UNUSED_ARG(root_oid_len); LWIP_UNUSED_ARG(root_oid_len);
@ -68,7 +68,7 @@ snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_n
} }
snmp_err_t snmp_err_t
snmp_scalar_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_scalar_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
/* because our only instance is .0 we can only return a next instance if no instance oid is passed */ /* because our only instance is .0 we can only return a next instance if no instance oid is passed */
if (instance->instance_oid.len == 0) { if (instance->instance_oid.len == 0) {
@ -83,14 +83,14 @@ snmp_scalar_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct s
snmp_err_t snmp_err_t
snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
LWIP_UNUSED_ARG(root_oid); LWIP_UNUSED_ARG(root_oid);
LWIP_UNUSED_ARG(root_oid_len); LWIP_UNUSED_ARG(root_oid_len);
if ((instance->instance_oid.len == 2) && (instance->instance_oid.id[1] == 0)) { if ((instance->instance_oid.len == 2) && (instance->instance_oid.id[1] == 0)) {
const struct snmp_scalar_array_node* array_node = (const struct snmp_scalar_array_node*)(const void*)instance->node; const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def* array_node_def = array_node->array_nodes; const struct snmp_scalar_array_node_def *array_node_def = array_node->array_nodes;
u32_t i = 0; u32_t i = 0;
while (i < array_node->array_node_count) { while (i < array_node->array_node_count) {
@ -118,11 +118,11 @@ snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct
} }
snmp_err_t snmp_err_t
snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
const struct snmp_scalar_array_node* array_node = (const struct snmp_scalar_array_node*)(const void*)instance->node; const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def* array_node_def = array_node->array_nodes; const struct snmp_scalar_array_node_def *array_node_def = array_node->array_nodes;
const struct snmp_scalar_array_node_def* result = NULL; const struct snmp_scalar_array_node_def *result = NULL;
LWIP_UNUSED_ARG(root_oid); LWIP_UNUSED_ARG(root_oid);
LWIP_UNUSED_ARG(root_oid_len); LWIP_UNUSED_ARG(root_oid_len);
@ -191,28 +191,28 @@ snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, st
} }
static s16_t static s16_t
snmp_scalar_array_get_value(struct snmp_node_instance* instance, void* value) snmp_scalar_array_get_value(struct snmp_node_instance *instance, void *value)
{ {
const struct snmp_scalar_array_node* array_node = (const struct snmp_scalar_array_node*)(const void*)instance->node; const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def* array_node_def = (const struct snmp_scalar_array_node_def*)instance->reference.const_ptr; const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
return array_node->get_value(array_node_def, value); return array_node->get_value(array_node_def, value);
} }
static snmp_err_t static snmp_err_t
snmp_scalar_array_set_test(struct snmp_node_instance* instance, u16_t value_len, void* value) snmp_scalar_array_set_test(struct snmp_node_instance *instance, u16_t value_len, void *value)
{ {
const struct snmp_scalar_array_node* array_node = (const struct snmp_scalar_array_node*)(const void*)instance->node; const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def* array_node_def = (const struct snmp_scalar_array_node_def*)instance->reference.const_ptr; const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
return array_node->set_test(array_node_def, value_len, value); return array_node->set_test(array_node_def, value_len, value);
} }
static snmp_err_t static snmp_err_t
snmp_scalar_array_set_value(struct snmp_node_instance* instance, u16_t value_len, void* value) snmp_scalar_array_set_value(struct snmp_node_instance *instance, u16_t value_len, void *value)
{ {
const struct snmp_scalar_array_node* array_node = (const struct snmp_scalar_array_node*)(const void*)instance->node; const struct snmp_scalar_array_node *array_node = (const struct snmp_scalar_array_node *)(const void *)instance->node;
const struct snmp_scalar_array_node_def* array_node_def = (const struct snmp_scalar_array_node_def*)instance->reference.const_ptr; const struct snmp_scalar_array_node_def *array_node_def = (const struct snmp_scalar_array_node_def *)instance->reference.const_ptr;
return array_node->set_value(array_node_def, value_len, value); return array_node->set_value(array_node_def, value_len, value);
} }

View File

@ -60,7 +60,7 @@ static s16_t snmpengine_scalars_get_value(const struct snmp_scalar_array_node_de
*(s32_t *)value = SNMP_FRAMEWORKMIB_SNMPENGINEMAXMESSAGESIZE; *(s32_t *)value = SNMP_FRAMEWORKMIB_SNMPENGINEMAXMESSAGESIZE;
return sizeof(s32_t); return sizeof(s32_t);
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmpengine_scalars_get_value(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("snmpengine_scalars_get_value(): unknown id: %"S32_F"\n", node->oid));
return 0; return 0;
} }
} }
@ -83,7 +83,7 @@ static const struct snmp_node *const snmpframeworkmib_subnodes[] = {
&snmpframeworkmibobjects_treenode.node &snmpframeworkmibobjects_treenode.node
}; };
static const struct snmp_tree_node snmpframeworkmib_root = SNMP_CREATE_TREE_NODE(10, snmpframeworkmib_subnodes); static const struct snmp_tree_node snmpframeworkmib_root = SNMP_CREATE_TREE_NODE(10, snmpframeworkmib_subnodes);
static const u32_t snmpframeworkmib_base_oid[] = {1,3,6,1,6,3,10}; static const u32_t snmpframeworkmib_base_oid[] = {1, 3, 6, 1, 6, 3, 10};
const struct snmp_mib snmpframeworkmib = {snmpframeworkmib_base_oid, LWIP_ARRAYSIZE(snmpframeworkmib_base_oid), &snmpframeworkmib_root.node}; const struct snmp_mib snmpframeworkmib = {snmpframeworkmib_base_oid, LWIP_ARRAYSIZE(snmpframeworkmib_base_oid), &snmpframeworkmib_root.node};
/* --- snmpFrameworkMIB ----------------------------------------------------- */ /* --- snmpFrameworkMIB ----------------------------------------------------- */

View File

@ -61,8 +61,7 @@ static const struct snmp_obj_id *snmp_auth_algo_to_oid(snmpv3_auth_algo_t algo)
{ {
if (algo == SNMP_V3_AUTH_ALGO_MD5) { if (algo == SNMP_V3_AUTH_ALGO_MD5) {
return &usmHMACMD5AuthProtocol; return &usmHMACMD5AuthProtocol;
} } else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
else if (algo == SNMP_V3_AUTH_ALGO_SHA) {
return &usmHMACMD5AuthProtocol; return &usmHMACMD5AuthProtocol;
} }
@ -73,8 +72,7 @@ static const struct snmp_obj_id *snmp_priv_algo_to_oid(snmpv3_priv_algo_t algo)
{ {
if (algo == SNMP_V3_PRIV_ALGO_DES) { if (algo == SNMP_V3_PRIV_ALGO_DES) {
return &usmDESPrivProtocol; return &usmDESPrivProtocol;
} } else if (algo == SNMP_V3_PRIV_ALGO_AES) {
else if (algo == SNMP_V3_PRIV_ALGO_AES) {
return &usmAESPrivProtocol; return &usmAESPrivProtocol;
} }
@ -207,8 +205,7 @@ static snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snm
if (!snmp_oid_equal(&row_oid->id[engineid_start], row_oid->len - 1, engineid_oid, row_oid->len - 1)) { if (!snmp_oid_equal(&row_oid->id[engineid_start], row_oid->len - 1, engineid_oid, row_oid->len - 1)) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
} } else {
else {
/* Verify complete EngineID */ /* Verify complete EngineID */
snmp_engineid_to_oid(engineid, engineid_oid, engineid_len); snmp_engineid_to_oid(engineid, engineid_oid, engineid_len);
if (!snmp_oid_equal(&row_oid->id[engineid_start], engineid_len, engineid_oid, engineid_len)) { if (!snmp_oid_equal(&row_oid->id[engineid_start], engineid_len, engineid_oid, engineid_len)) {
@ -234,8 +231,7 @@ static snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snm
if (!snmp_oid_in_range(&row_oid->id[name_start], tmplen, usmUserTable_oid_ranges, tmplen)) { if (!snmp_oid_in_range(&row_oid->id[name_start], tmplen, usmUserTable_oid_ranges, tmplen)) {
return SNMP_ERR_NOSUCHINSTANCE; return SNMP_ERR_NOSUCHINSTANCE;
} }
} } else {
else {
/* Full name given according to oid. Also test for too much data.*/ /* Full name given according to oid. Also test for too much data.*/
u8_t tmplen = row_oid->len - engineid_len - 2; u8_t tmplen = row_oid->len - engineid_len - 2;
if (!snmp_oid_in_range(&row_oid->id[name_start], name_len, usmUserTable_oid_ranges, tmplen)) { if (!snmp_oid_in_range(&row_oid->id[name_start], name_len, usmUserTable_oid_ranges, tmplen)) {
@ -262,7 +258,7 @@ static snmp_err_t usmusertable_get_next_instance(const u32_t *column, struct snm
snmp_name_to_oid(username, &test_oid[2 + eid_len], strlen(username)); snmp_name_to_oid(username, &test_oid[2 + eid_len], strlen(username));
/* check generated OID: is it a candidate for the next one? */ /* check generated OID: is it a candidate for the next one? */
snmp_next_oid_check(&state, test_oid, (u8_t)(1 + eid_len + 1 + strlen(username)), LWIP_PTR_NUMERIC_CAST(void*, i)); snmp_next_oid_check(&state, test_oid, (u8_t)(1 + eid_len + 1 + strlen(username)), LWIP_PTR_NUMERIC_CAST(void *, i));
} }
/* did we find a next one? */ /* did we find a next one? */
@ -291,11 +287,10 @@ static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, vo
case 4: /* usmUserCloneFrom */ case 4: /* usmUserCloneFrom */
MEMCPY(value, snmp_zero_dot_zero.id, snmp_zero_dot_zero.len * sizeof(u32_t)); MEMCPY(value, snmp_zero_dot_zero.id, snmp_zero_dot_zero.len * sizeof(u32_t));
return snmp_zero_dot_zero.len * sizeof(u32_t); return snmp_zero_dot_zero.len * sizeof(u32_t);
case 5: /* usmUserAuthProtocol */ case 5: { /* usmUserAuthProtocol */
{
const struct snmp_obj_id *auth_algo; const struct snmp_obj_id *auth_algo;
snmpv3_auth_algo_t auth_algo_val; snmpv3_auth_algo_t auth_algo_val;
snmpv3_get_user((const char*)cell_instance->reference.ptr, &auth_algo_val, NULL, NULL, NULL); snmpv3_get_user((const char *)cell_instance->reference.ptr, &auth_algo_val, NULL, NULL, NULL);
auth_algo = snmp_auth_algo_to_oid(auth_algo_val); auth_algo = snmp_auth_algo_to_oid(auth_algo_val);
MEMCPY(value, auth_algo->id, auth_algo->len * sizeof(u32_t)); MEMCPY(value, auth_algo->id, auth_algo->len * sizeof(u32_t));
return auth_algo->len * sizeof(u32_t); return auth_algo->len * sizeof(u32_t);
@ -304,11 +299,10 @@ static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, vo
return 0; return 0;
case 7: /* usmUserOwnAuthKeyChange */ case 7: /* usmUserOwnAuthKeyChange */
return 0; return 0;
case 8: /* usmUserPrivProtocol */ case 8: { /* usmUserPrivProtocol */
{
const struct snmp_obj_id *priv_algo; const struct snmp_obj_id *priv_algo;
snmpv3_priv_algo_t priv_algo_val; snmpv3_priv_algo_t priv_algo_val;
snmpv3_get_user((const char*)cell_instance->reference.ptr, NULL, NULL, &priv_algo_val, NULL); snmpv3_get_user((const char *)cell_instance->reference.ptr, NULL, NULL, &priv_algo_val, NULL);
priv_algo = snmp_priv_algo_to_oid(priv_algo_val); priv_algo = snmp_priv_algo_to_oid(priv_algo_val);
MEMCPY(value, priv_algo->id, priv_algo->len * sizeof(u32_t)); MEMCPY(value, priv_algo->id, priv_algo->len * sizeof(u32_t));
return priv_algo->len * sizeof(u32_t); return priv_algo->len * sizeof(u32_t);
@ -321,14 +315,14 @@ static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, vo
/* TODO: Implement usmUserPublic */ /* TODO: Implement usmUserPublic */
return 0; return 0;
case 12: /* usmUserStorageType */ case 12: /* usmUserStorageType */
snmpv3_get_user_storagetype((const char*)cell_instance->reference.ptr, &storage_type); snmpv3_get_user_storagetype((const char *)cell_instance->reference.ptr, &storage_type);
*(s32_t*)value = storage_type; *(s32_t *)value = storage_type;
return sizeof(s32_t); return sizeof(s32_t);
case 13: /* usmUserStatus */ case 13: /* usmUserStatus */
*(s32_t*)value = 1; /* active */ *(s32_t *)value = 1; /* active */
return sizeof(s32_t); return sizeof(s32_t);
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("usmusertable_get_value(): unknown id: %"S32_F"\n", SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id))); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmusertable_get_value(): unknown id: %"S32_F"\n", SNMP_TABLE_GET_COLUMN_FROM_OID(cell_instance->instance_oid.id)));
return 0; return 0;
} }
} }
@ -336,7 +330,7 @@ static s16_t usmusertable_get_value(struct snmp_node_instance *cell_instance, vo
/* --- usmMIBObjects 1.3.6.1.6.3.15.1 ----------------------------------------------------- */ /* --- usmMIBObjects 1.3.6.1.6.3.15.1 ----------------------------------------------------- */
static s16_t usmstats_scalars_get_value(const struct snmp_scalar_array_node_def *node, void *value) static s16_t usmstats_scalars_get_value(const struct snmp_scalar_array_node_def *node, void *value)
{ {
u32_t *uint_ptr = (u32_t*)value; u32_t *uint_ptr = (u32_t *)value;
switch (node->oid) { switch (node->oid) {
case 1: /* usmStatsUnsupportedSecLevels */ case 1: /* usmStatsUnsupportedSecLevels */
*uint_ptr = snmp_stats.unsupportedseclevels; *uint_ptr = snmp_stats.unsupportedseclevels;
@ -357,7 +351,7 @@ static s16_t usmstats_scalars_get_value(const struct snmp_scalar_array_node_def
*uint_ptr = snmp_stats.decryptionerrors; *uint_ptr = snmp_stats.decryptionerrors;
break; break;
default: default:
LWIP_DEBUGF(SNMP_MIB_DEBUG,("usmstats_scalars_get_value(): unknown id: %"S32_F"\n", node->oid)); LWIP_DEBUGF(SNMP_MIB_DEBUG, ("usmstats_scalars_get_value(): unknown id: %"S32_F"\n", node->oid));
return 0; return 0;
} }
@ -410,7 +404,7 @@ static const struct snmp_node *const snmpusmmib_subnodes[] = {
&usmmibobjects_treenode.node &usmmibobjects_treenode.node
}; };
static const struct snmp_tree_node snmpusmmib_root = SNMP_CREATE_TREE_NODE(15, snmpusmmib_subnodes); static const struct snmp_tree_node snmpusmmib_root = SNMP_CREATE_TREE_NODE(15, snmpusmmib_subnodes);
static const u32_t snmpusmmib_base_oid[] = {1,3,6,1,6,3,15}; static const u32_t snmpusmmib_base_oid[] = {1, 3, 6, 1, 6, 3, 15};
const struct snmp_mib snmpusmmib = {snmpusmmib_base_oid, LWIP_ARRAYSIZE(snmpusmmib_base_oid), &snmpusmmib_root.node}; const struct snmp_mib snmpusmmib = {snmpusmmib_base_oid, LWIP_ARRAYSIZE(snmpusmmib_base_oid), &snmpusmmib_root.node};
#endif /* LWIP_SNMP */ #endif /* LWIP_SNMP */

View File

@ -43,10 +43,10 @@
#include "lwip/apps/snmp_table.h" #include "lwip/apps/snmp_table.h"
#include <string.h> #include <string.h>
snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE; snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
const struct snmp_table_node* table_node = (const struct snmp_table_node*)(const void*)instance->node; const struct snmp_table_node *table_node = (const struct snmp_table_node *)(const void *)instance->node;
LWIP_UNUSED_ARG(root_oid); LWIP_UNUSED_ARG(root_oid);
LWIP_UNUSED_ARG(root_oid_len); LWIP_UNUSED_ARG(root_oid_len);
@ -55,7 +55,7 @@ snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, str
/* fixed row entry always has oid 1 */ /* fixed row entry always has oid 1 */
if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1)) { if ((instance->instance_oid.len >= 3) && (instance->instance_oid.id[0] == 1)) {
/* search column */ /* search column */
const struct snmp_table_col_def* col_def = table_node->columns; const struct snmp_table_col_def *col_def = table_node->columns;
u16_t i = table_node->column_count; u16_t i = table_node->column_count;
while (i > 0) { while (i > 0) {
if (col_def->index == instance->instance_oid.id[1]) { if (col_def->index == instance->instance_oid.id[1]) {
@ -77,7 +77,7 @@ snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, str
ret = table_node->get_cell_instance( ret = table_node->get_cell_instance(
&(instance->instance_oid.id[1]), &(instance->instance_oid.id[1]),
&(instance->instance_oid.id[2]), &(instance->instance_oid.id[2]),
instance->instance_oid.len-2, instance->instance_oid.len - 2,
instance); instance);
} }
} }
@ -85,10 +85,10 @@ snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, str
return ret; return ret;
} }
snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
const struct snmp_table_node* table_node = (const struct snmp_table_node*)(const void*)instance->node; const struct snmp_table_node *table_node = (const struct snmp_table_node *)(const void *)instance->node;
const struct snmp_table_col_def* col_def; const struct snmp_table_col_def *col_def;
struct snmp_obj_id row_oid; struct snmp_obj_id row_oid;
u32_t column = 0; u32_t column = 0;
snmp_err_t result; snmp_err_t result;
@ -116,7 +116,7 @@ snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len
/* resolve column and value */ /* resolve column and value */
do { do {
u16_t i; u16_t i;
const struct snmp_table_col_def* next_col_def = NULL; const struct snmp_table_col_def *next_col_def = NULL;
col_def = table_node->columns; col_def = table_node->columns;
for (i = 0; i < table_node->column_count; i++) { for (i = 0; i < table_node->column_count; i++) {
@ -161,10 +161,10 @@ snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len
} }
snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE; snmp_err_t ret = SNMP_ERR_NOSUCHINSTANCE;
const struct snmp_table_simple_node* table_node = (const struct snmp_table_simple_node*)(const void*)instance->node; const struct snmp_table_simple_node *table_node = (const struct snmp_table_simple_node *)(const void *)instance->node;
LWIP_UNUSED_ARG(root_oid); LWIP_UNUSED_ARG(root_oid);
LWIP_UNUSED_ARG(root_oid_len); LWIP_UNUSED_ARG(root_oid_len);
@ -175,13 +175,13 @@ snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_l
ret = table_node->get_cell_value( ret = table_node->get_cell_value(
&(instance->instance_oid.id[1]), &(instance->instance_oid.id[1]),
&(instance->instance_oid.id[2]), &(instance->instance_oid.id[2]),
instance->instance_oid.len-2, instance->instance_oid.len - 2,
&instance->reference, &instance->reference,
&instance->reference_len); &instance->reference_len);
if (ret == SNMP_ERR_NOERROR) { if (ret == SNMP_ERR_NOERROR) {
/* search column */ /* search column */
const struct snmp_table_simple_col_def* col_def = table_node->columns; const struct snmp_table_simple_col_def *col_def = table_node->columns;
u32_t i = table_node->column_count; u32_t i = table_node->column_count;
while (i > 0) { while (i > 0) {
if (col_def->index == instance->instance_oid.id[1]) { if (col_def->index == instance->instance_oid.id[1]) {
@ -224,10 +224,10 @@ snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_l
return ret; return ret;
} }
snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
const struct snmp_table_simple_node* table_node = (const struct snmp_table_simple_node*)(const void*)instance->node; const struct snmp_table_simple_node *table_node = (const struct snmp_table_simple_node *)(const void *)instance->node;
const struct snmp_table_simple_col_def* col_def; const struct snmp_table_simple_col_def *col_def;
struct snmp_obj_id row_oid; struct snmp_obj_id row_oid;
u32_t column = 0; u32_t column = 0;
snmp_err_t result; snmp_err_t result;
@ -251,7 +251,7 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_
/* resolve column and value */ /* resolve column and value */
do { do {
u32_t i; u32_t i;
const struct snmp_table_simple_col_def* next_col_def = NULL; const struct snmp_table_simple_col_def *next_col_def = NULL;
col_def = table_node->columns; col_def = table_node->columns;
for (i = 0; i < table_node->column_count; i++) { for (i = 0; i < table_node->column_count; i++) {
@ -283,8 +283,7 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_
row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */ row_oid.len = 0; /* reset row_oid because we switch to next column and start with the first entry there */
column = next_col_def->index + 1; column = next_col_def->index + 1;
} } while (1);
while (1);
instance->asn1_type = col_def->asn1_type; instance->asn1_type = col_def->asn1_type;
instance->access = SNMP_NODE_INSTANCE_READ_ONLY; instance->access = SNMP_NODE_INSTANCE_READ_ONLY;
@ -318,23 +317,23 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_
s16_t s16_t
snmp_table_extract_value_from_s32ref(struct snmp_node_instance* instance, void* value) snmp_table_extract_value_from_s32ref(struct snmp_node_instance *instance, void *value)
{ {
s32_t *dst = (s32_t*)value; s32_t *dst = (s32_t *)value;
*dst = instance->reference.s32; *dst = instance->reference.s32;
return sizeof(*dst); return sizeof(*dst);
} }
s16_t s16_t
snmp_table_extract_value_from_u32ref(struct snmp_node_instance* instance, void* value) snmp_table_extract_value_from_u32ref(struct snmp_node_instance *instance, void *value)
{ {
u32_t *dst = (u32_t*)value; u32_t *dst = (u32_t *)value;
*dst = instance->reference.u32; *dst = instance->reference.u32;
return sizeof(*dst); return sizeof(*dst);
} }
s16_t s16_t
snmp_table_extract_value_from_refconstptr(struct snmp_node_instance* instance, void* value) snmp_table_extract_value_from_refconstptr(struct snmp_node_instance *instance, void *value)
{ {
MEMCPY(value, instance->reference.const_ptr, instance->reference_len); MEMCPY(value, instance->reference.const_ptr, instance->reference_len);
return (u16_t)instance->reference_len; return (u16_t)instance->reference_len;

View File

@ -53,7 +53,7 @@ call_synced_function(struct threadsync_data *call_data, snmp_threadsync_called_f
static void static void
threadsync_get_value_synced(void *ctx) threadsync_get_value_synced(void *ctx)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)ctx; struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->retval.s16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value); call_data->retval.s16 = call_data->proxy_instance.get_value(&call_data->proxy_instance, call_data->arg1.value);
@ -61,9 +61,9 @@ threadsync_get_value_synced(void *ctx)
} }
static s16_t static s16_t
threadsync_get_value(struct snmp_node_instance* instance, void* value) threadsync_get_value(struct snmp_node_instance *instance, void *value)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)instance->reference.ptr; struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
call_data->arg1.value = value; call_data->arg1.value = value;
call_synced_function(call_data, threadsync_get_value_synced); call_synced_function(call_data, threadsync_get_value_synced);
@ -74,7 +74,7 @@ threadsync_get_value(struct snmp_node_instance* instance, void* value)
static void static void
threadsync_set_test_synced(void *ctx) threadsync_set_test_synced(void *ctx)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)ctx; struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->retval.err = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value); call_data->retval.err = call_data->proxy_instance.set_test(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
@ -82,9 +82,9 @@ threadsync_set_test_synced(void *ctx)
} }
static snmp_err_t static snmp_err_t
threadsync_set_test(struct snmp_node_instance* instance, u16_t len, void *value) threadsync_set_test(struct snmp_node_instance *instance, u16_t len, void *value)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)instance->reference.ptr; struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
call_data->arg1.value = value; call_data->arg1.value = value;
call_data->arg2.len = len; call_data->arg2.len = len;
@ -96,7 +96,7 @@ threadsync_set_test(struct snmp_node_instance* instance, u16_t len, void *value)
static void static void
threadsync_set_value_synced(void *ctx) threadsync_set_value_synced(void *ctx)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)ctx; struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->retval.err = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value); call_data->retval.err = call_data->proxy_instance.set_value(&call_data->proxy_instance, call_data->arg2.len, call_data->arg1.value);
@ -104,9 +104,9 @@ threadsync_set_value_synced(void *ctx)
} }
static snmp_err_t static snmp_err_t
threadsync_set_value(struct snmp_node_instance* instance, u16_t len, void *value) threadsync_set_value(struct snmp_node_instance *instance, u16_t len, void *value)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)instance->reference.ptr; struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
call_data->arg1.value = value; call_data->arg1.value = value;
call_data->arg2.len = len; call_data->arg2.len = len;
@ -116,9 +116,9 @@ threadsync_set_value(struct snmp_node_instance* instance, u16_t len, void *value
} }
static void static void
threadsync_release_instance_synced(void* ctx) threadsync_release_instance_synced(void *ctx)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)ctx; struct threadsync_data *call_data = (struct threadsync_data *)ctx;
call_data->proxy_instance.release_instance(&call_data->proxy_instance); call_data->proxy_instance.release_instance(&call_data->proxy_instance);
@ -128,7 +128,7 @@ threadsync_release_instance_synced(void* ctx)
static void static void
threadsync_release_instance(struct snmp_node_instance *instance) threadsync_release_instance(struct snmp_node_instance *instance)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)instance->reference.ptr; struct threadsync_data *call_data = (struct threadsync_data *)instance->reference.ptr;
if (call_data->proxy_instance.release_instance != NULL) { if (call_data->proxy_instance.release_instance != NULL) {
call_synced_function(call_data, threadsync_release_instance_synced); call_synced_function(call_data, threadsync_release_instance_synced);
@ -136,10 +136,10 @@ threadsync_release_instance(struct snmp_node_instance *instance)
} }
static void static void
get_instance_synced(void* ctx) get_instance_synced(void *ctx)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)ctx; struct threadsync_data *call_data = (struct threadsync_data *)ctx;
const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node*)(const void*)call_data->proxy_instance.node; const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node *)(const void *)call_data->proxy_instance.node;
call_data->retval.err = leaf->get_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance); call_data->retval.err = leaf->get_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
@ -147,10 +147,10 @@ get_instance_synced(void* ctx)
} }
static void static void
get_next_instance_synced(void* ctx) get_next_instance_synced(void *ctx)
{ {
struct threadsync_data *call_data = (struct threadsync_data*)ctx; struct threadsync_data *call_data = (struct threadsync_data *)ctx;
const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node*)(const void*)call_data->proxy_instance.node; const struct snmp_leaf_node *leaf = (const struct snmp_leaf_node *)(const void *)call_data->proxy_instance.node;
call_data->retval.err = leaf->get_next_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance); call_data->retval.err = leaf->get_next_instance(call_data->arg1.root_oid, call_data->arg2.root_oid_len, &call_data->proxy_instance);
@ -158,9 +158,9 @@ get_next_instance_synced(void* ctx)
} }
static snmp_err_t static snmp_err_t
do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance, snmp_threadsync_called_fn fn) do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance, snmp_threadsync_called_fn fn)
{ {
const struct snmp_threadsync_node *threadsync_node = (const struct snmp_threadsync_node*)(const void*)instance->node; const struct snmp_threadsync_node *threadsync_node = (const struct snmp_threadsync_node *)(const void *)instance->node;
struct threadsync_data *call_data = &threadsync_node->instance->data; struct threadsync_data *call_data = &threadsync_node->instance->data;
if (threadsync_node->node.node.oid != threadsync_node->target->node.oid) { if (threadsync_node->node.node.oid != threadsync_node->target->node.oid) {
@ -184,9 +184,9 @@ do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* ins
instance->access = call_data->proxy_instance.access; instance->access = call_data->proxy_instance.access;
instance->asn1_type = call_data->proxy_instance.asn1_type; instance->asn1_type = call_data->proxy_instance.asn1_type;
instance->release_instance = threadsync_release_instance; instance->release_instance = threadsync_release_instance;
instance->get_value = (call_data->proxy_instance.get_value != NULL)? threadsync_get_value : NULL; instance->get_value = (call_data->proxy_instance.get_value != NULL) ? threadsync_get_value : NULL;
instance->set_value = (call_data->proxy_instance.set_value != NULL)? threadsync_set_value : NULL; instance->set_value = (call_data->proxy_instance.set_value != NULL) ? threadsync_set_value : NULL;
instance->set_test = (call_data->proxy_instance.set_test != NULL)? threadsync_set_test : NULL; instance->set_test = (call_data->proxy_instance.set_test != NULL) ? threadsync_set_test : NULL;
snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len); snmp_oid_assign(&instance->instance_oid, call_data->proxy_instance.instance_oid.id, call_data->proxy_instance.instance_oid.len);
} }
@ -194,13 +194,13 @@ do_sync(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* ins
} }
snmp_err_t snmp_err_t
snmp_threadsync_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_threadsync_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
return do_sync(root_oid, root_oid_len, instance, get_instance_synced); return do_sync(root_oid, root_oid_len, instance, get_instance_synced);
} }
snmp_err_t snmp_err_t
snmp_threadsync_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance* instance) snmp_threadsync_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_node_instance *instance)
{ {
return do_sync(root_oid, root_oid_len, instance, get_next_instance_synced); return do_sync(root_oid, root_oid_len, instance, get_next_instance_synced);
} }

View File

@ -51,8 +51,7 @@
#include "snmp_asn1.h" #include "snmp_asn1.h"
#include "snmp_core_priv.h" #include "snmp_core_priv.h"
struct snmp_msg_trap struct snmp_msg_trap {
{
/* source enterprise ID (sysObjectID) */ /* source enterprise ID (sysObjectID) */
const struct snmp_obj_id *enterprise; const struct snmp_obj_id *enterprise;
/* source IP address, raw network order format */ /* source IP address, raw network order format */
@ -91,10 +90,9 @@ static err_t snmp_trap_varbind_enc(struct snmp_msg_trap *trap, struct snmp_pbuf_
/** Agent community string for sending traps */ /** Agent community string for sending traps */
extern const char *snmp_community_trap; extern const char *snmp_community_trap;
void* snmp_traps_handle; void *snmp_traps_handle;
struct snmp_trap_dst struct snmp_trap_dst {
{
/* destination IP address in network order */ /* destination IP address in network order */
ip_addr_t dip; ip_addr_t dip;
/* set to 0 when disabled, >0 when enabled */ /* set to 0 when disabled, >0 when enabled */
@ -170,7 +168,7 @@ snmp_get_auth_traps_enabled(void)
* (sysObjectID) for specific traps. * (sysObjectID) for specific traps.
*/ */
err_t err_t
snmp_send_trap(const struct snmp_obj_id* eoid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds) snmp_send_trap(const struct snmp_obj_id *eoid, s32_t generic_trap, s32_t specific_trap, struct snmp_varbind *varbinds)
{ {
struct snmp_msg_trap trap_msg; struct snmp_msg_trap trap_msg;
struct snmp_trap_dst *td; struct snmp_trap_dst *td;

View File

@ -101,7 +101,7 @@ snmpv3_get_engine_time_internal(void)
* @todo: This is a potential thread safety issue. * @todo: This is a potential thread safety issue.
*/ */
err_t err_t
snmpv3_build_priv_param(u8_t* priv_param) snmpv3_build_priv_param(u8_t *priv_param)
{ {
#ifdef LWIP_RAND /* Based on RFC3826 */ #ifdef LWIP_RAND /* Based on RFC3826 */
static u8_t init; static u8_t init;

View File

@ -49,8 +49,8 @@
#include "mbedtls/sha1.h" #include "mbedtls/sha1.h"
err_t err_t
snmpv3_auth(struct snmp_pbuf_stream* stream, u16_t length, snmpv3_auth(struct snmp_pbuf_stream *stream, u16_t length,
const u8_t* key, snmpv3_auth_algo_t algo, u8_t* hmac_out) const u8_t *key, snmpv3_auth_algo_t algo, u8_t *hmac_out)
{ {
u32_t i; u32_t i;
u8_t key_len; u8_t key_len;
@ -70,7 +70,7 @@ snmpv3_auth(struct snmp_pbuf_stream* stream, u16_t length,
} }
mbedtls_md_init(&ctx); mbedtls_md_init(&ctx);
if(mbedtls_md_setup(&ctx, md_info, 1) != 0) { if (mbedtls_md_setup(&ctx, md_info, 1) != 0) {
return ERR_ARG; return ERR_ARG;
} }
@ -105,8 +105,8 @@ free_md:
#if LWIP_SNMP_V3_CRYPTO #if LWIP_SNMP_V3_CRYPTO
err_t err_t
snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length, snmpv3_crypt(struct snmp_pbuf_stream *stream, u16_t length,
const u8_t* key, const u8_t* priv_param, const u32_t engine_boots, const u8_t *key, const u8_t *priv_param, const u32_t engine_boots,
const u32_t engine_time, snmpv3_priv_algo_t algo, snmpv3_priv_mode_t mode) const u32_t engine_time, snmpv3_priv_algo_t algo, snmpv3_priv_mode_t mode)
{ {
size_t i; size_t i;
@ -130,13 +130,13 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length,
} }
cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_DES_CBC); cipher_info = mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_DES_CBC);
if(mbedtls_cipher_setup(&ctx, cipher_info) != 0) { if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) {
return ERR_ARG; return ERR_ARG;
} }
if(mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_NONE) != 0) { if (mbedtls_cipher_set_padding_mode(&ctx, MBEDTLS_PADDING_NONE) != 0) {
return ERR_ARG; return ERR_ARG;
} }
if(mbedtls_cipher_setkey(&ctx, key, 8*8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT)? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) { if (mbedtls_cipher_setkey(&ctx, key, 8 * 8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) {
goto error; goto error;
} }
@ -144,7 +144,7 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length,
for (i = 0; i < LWIP_ARRAYSIZE(iv_local); i++) { for (i = 0; i < LWIP_ARRAYSIZE(iv_local); i++) {
iv_local[i] = priv_param[i] ^ key[i + 8]; iv_local[i] = priv_param[i] ^ key[i + 8];
} }
if(mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) { if (mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) {
goto error; goto error;
} }
@ -183,7 +183,7 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length,
if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) { if (mbedtls_cipher_setup(&ctx, cipher_info) != 0) {
return ERR_ARG; return ERR_ARG;
} }
if (mbedtls_cipher_setkey(&ctx, key, 16*8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT)? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) { if (mbedtls_cipher_setkey(&ctx, key, 16 * 8, (mode == SNMP_V3_PRIV_MODE_ENCRYPT) ? MBEDTLS_ENCRYPT : MBEDTLS_DECRYPT) != 0) {
goto error; goto error;
} }
@ -200,7 +200,7 @@ snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length,
iv_local[4 + 2] = (engine_time >> 8) & 0xFF; iv_local[4 + 2] = (engine_time >> 8) & 0xFF;
iv_local[4 + 3] = (engine_time >> 0) & 0xFF; iv_local[4 + 3] = (engine_time >> 0) & 0xFF;
SMEMCPY(iv_local + 8, priv_param, 8); SMEMCPY(iv_local + 8, priv_param, 8);
if(mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) { if (mbedtls_cipher_set_iv(&ctx, iv_local, LWIP_ARRAYSIZE(iv_local)) != 0) {
goto error; goto error;
} }

View File

@ -52,17 +52,16 @@
#define SNMP_V3_MD5_LEN 16 #define SNMP_V3_MD5_LEN 16
#define SNMP_V3_SHA_LEN 20 #define SNMP_V3_SHA_LEN 20
typedef enum typedef enum {
{
SNMP_V3_PRIV_MODE_DECRYPT = 0, SNMP_V3_PRIV_MODE_DECRYPT = 0,
SNMP_V3_PRIV_MODE_ENCRYPT = 1 SNMP_V3_PRIV_MODE_ENCRYPT = 1
} snmpv3_priv_mode_t; } snmpv3_priv_mode_t;
s32_t snmpv3_get_engine_boots_internal(void); s32_t snmpv3_get_engine_boots_internal(void);
err_t snmpv3_auth(struct snmp_pbuf_stream* stream, u16_t length, const u8_t* key, snmpv3_auth_algo_t algo, u8_t* hmac_out); err_t snmpv3_auth(struct snmp_pbuf_stream *stream, u16_t length, const u8_t *key, snmpv3_auth_algo_t algo, u8_t *hmac_out);
err_t snmpv3_crypt(struct snmp_pbuf_stream* stream, u16_t length, const u8_t* key, err_t snmpv3_crypt(struct snmp_pbuf_stream *stream, u16_t length, const u8_t *key,
const u8_t* priv_param, const u32_t engine_boots, const u32_t engine_time, snmpv3_priv_algo_t algo, snmpv3_priv_mode_t mode); const u8_t *priv_param, const u32_t engine_boots, const u32_t engine_time, snmpv3_priv_algo_t algo, snmpv3_priv_mode_t mode);
err_t snmpv3_build_priv_param(u8_t* priv_param); err_t snmpv3_build_priv_param(u8_t *priv_param);
void snmpv3_enginetime_timer(void *arg); void snmpv3_enginetime_timer(void *arg);
#endif #endif