minor: SNMP: fixed coding style (lwip style)

This commit is contained in:
goldsimon 2015-10-07 10:01:23 +02:00
parent 2b971400fa
commit 2949449e25
6 changed files with 1998 additions and 2800 deletions

View File

@ -55,12 +55,10 @@ snmp_asn1_dec_type(struct pbuf *p, u16_t ofs, u8_t *type)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
*type = *msg_ptr;
@ -88,128 +86,104 @@ snmp_asn1_dec_length(struct pbuf *p, u16_t ofs, u8_t *octets_used, u16_t *length
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if (*msg_ptr < 0x80)
{
if (*msg_ptr < 0x80) {
/* primitive definite length format */
*octets_used = 1;
*length = *msg_ptr;
return ERR_OK;
}
else if (*msg_ptr == 0x80)
{
} else if (*msg_ptr == 0x80) {
/* constructed indefinite length format, termination with two zero octets */
u8_t zeros;
u8_t i;
*length = 0;
zeros = 0;
while (zeros != 2)
{
while (zeros != 2) {
i = 2;
while (i > 0)
{
while (i > 0) {
i--;
(*length) += 1;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
if (*msg_ptr == 0)
{
if (*msg_ptr == 0) {
zeros++;
if (zeros == 2)
{
if (zeros == 2) {
/* stop while (i > 0) */
i = 0;
}
}
else
{
} else {
zeros = 0;
}
}
}
*octets_used = 1;
return ERR_OK;
}
else if (*msg_ptr == 0x81)
{
} else if (*msg_ptr == 0x81) {
/* constructed definite length format, one octet */
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
*length = *msg_ptr;
*octets_used = 2;
return ERR_OK;
}
else if (*msg_ptr == 0x82)
{
} else if (*msg_ptr == 0x82) {
u8_t i;
/* constructed definite length format, two octets */
i = 2;
while (i > 0)
{
while (i > 0) {
i--;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
if (i == 0)
{
if (i == 0) {
/* least significant length octet */
*length |= *msg_ptr;
}
else
{
} else {
/* most significant length octet */
*length = (*msg_ptr) << 8;
}
}
*octets_used = 3;
return ERR_OK;
}
else
{
} else {
/* constructed definite length format 3..127 octets, this is too big (>64k) */
/** @todo: do we need to accept inefficient codings with many leading zero's? */
*octets_used = 1 + ((*msg_ptr) & 0x7f);
@ -243,72 +217,60 @@ snmp_asn1_dec_u32t(struct pbuf *p, u16_t ofs, u16_t len, u32_t *value)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if ((len > 0) && (len < 6))
{
if ((len > 0) && (len < 6)) {
/* start from zero */
*value = 0;
if (*msg_ptr & 0x80)
{
if (*msg_ptr & 0x80) {
/* negative, expecting zero sign bit! */
return ERR_ARG;
}
else
{
} else {
/* positive */
if ((len > 1) && (*msg_ptr == 0))
{
if ((len > 1) && (*msg_ptr == 0)) {
/* skip leading "sign byte" octet 0x00 */
len--;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
}
/* OR octets with value */
while (len > 1)
{
while (len > 1) {
len--;
*value |= *msg_ptr;
*value <<= 8;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
*value |= *msg_ptr;
return ERR_OK;
}
else
{
} else {
return ERR_ARG;
}
}
@ -343,70 +305,54 @@ snmp_asn1_dec_s32t(struct pbuf *p, u16_t ofs, u16_t len, s32_t *value)
u8_t sign;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if ((len > 0) && (len < 5))
{
if (*msg_ptr & 0x80)
{
if ((len > 0) && (len < 5)) {
if (*msg_ptr & 0x80) {
/* negative, start from -1 */
*value = -1;
sign = 1;
}
else
{
} else {
/* positive, start from 0 */
*value = 0;
sign = 0;
}
/* OR/AND octets with value */
while (len > 1)
{
while (len > 1) {
len--;
if (sign)
{
if (sign) {
*lsb_ptr &= *msg_ptr;
*value <<= 8;
*lsb_ptr |= 255;
}
else
{
} else {
*lsb_ptr |= *msg_ptr;
*value <<= 8;
}
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
if (sign)
{
if (sign) {
*lsb_ptr &= *msg_ptr;
}
else
{
} else {
*lsb_ptr |= *msg_ptr;
}
return ERR_OK;
}
else
{
} else {
return ERR_ARG;
}
}
@ -433,129 +379,106 @@ snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid)
s32_t *oid_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
oid->len = 0;
oid_ptr = &oid->id[0];
if (len > 0)
{
if (len > 0) {
/* first compressed octet */
if (*msg_ptr == 0x2B)
{
if (*msg_ptr == 0x2B) {
/* (most) common case 1.3 (iso.org) */
*oid_ptr = 1;
oid_ptr++;
*oid_ptr = 3;
oid_ptr++;
}
else if (*msg_ptr < 40)
{
} else if (*msg_ptr < 40) {
*oid_ptr = 0;
oid_ptr++;
*oid_ptr = *msg_ptr;
oid_ptr++;
}
else if (*msg_ptr < 80)
{
} else if (*msg_ptr < 80) {
*oid_ptr = 1;
oid_ptr++;
*oid_ptr = (*msg_ptr) - 40;
oid_ptr++;
}
else
{
} else {
*oid_ptr = 2;
oid_ptr++;
*oid_ptr = (*msg_ptr) - 80;
oid_ptr++;
}
oid->len = 2;
}
else
{
} else {
/* accepting zero length identifiers e.g. for
getnext operation. uncommon but valid */
return ERR_OK;
}
len--;
if (len > 0)
{
if (len > 0) {
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
while ((len > 0) && (oid->len < LWIP_SNMP_OBJ_ID_LEN))
{
while ((len > 0) && (oid->len < LWIP_SNMP_OBJ_ID_LEN)) {
/* sub-identifier uses multiple octets */
if (*msg_ptr & 0x80)
{
if (*msg_ptr & 0x80) {
s32_t sub_id = 0;
while ((*msg_ptr & 0x80) && (len > 1))
{
while ((*msg_ptr & 0x80) && (len > 1)) {
len--;
sub_id = (sub_id << 7) + (*msg_ptr & ~0x80);
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
if (!(*msg_ptr & 0x80) && (len > 0))
{
if (!(*msg_ptr & 0x80) && (len > 0)) {
/* last octet sub-identifier */
len--;
sub_id = (sub_id << 7) + *msg_ptr;
*oid_ptr = sub_id;
}
}
else
{
} else {
/* !(*msg_ptr & 0x80) sub-identifier uses single octet */
len--;
*oid_ptr = *msg_ptr;
}
if (len > 0)
{
if (len > 0) {
/* remaining oid bytes available ... */
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
@ -563,13 +486,10 @@ snmp_asn1_dec_oid(struct pbuf *p, u16_t ofs, u16_t len, struct snmp_obj_id *oid)
oid_ptr++;
oid->len++;
}
if (len == 0)
{
if (len == 0) {
/* len == 0, end of oid */
return ERR_OK;
}
else
{
} else {
/* len > 0, oid->len == LWIP_SNMP_OBJ_ID_LEN or malformed encoding */
return ERR_ARG;
}
@ -598,36 +518,30 @@ snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw
u16_t plen, base;
u8_t *msg_ptr;
if (len > 0)
{
if (len > 0) {
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if (raw_len >= len)
{
while (len > 1)
{
if (raw_len >= len) {
while (len > 1) {
/* copy len - 1 octets */
len--;
*raw = *msg_ptr;
raw++;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
@ -635,9 +549,7 @@ snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw
/* copy last octet */
*raw = *msg_ptr;
return ERR_OK;
}
else
{
} else {
/* raw_len < len, not enough dst space */
return ERR_ARG;
}
@ -646,9 +558,7 @@ snmp_asn1_dec_raw(struct pbuf *p, u16_t ofs, u16_t len, u16_t raw_len, u8_t *raw
}
/* p == NULL, ofs >= plen */
return ERR_ARG;
}
else
{
} else {
/* len == 0, empty string */
return ERR_OK;
}

View File

@ -49,16 +49,11 @@
void
snmp_asn1_enc_length_cnt(u16_t length, u8_t *octets_needed)
{
if (length < 0x80U)
{
if (length < 0x80U) {
*octets_needed = 1;
}
else if (length < 0x100U)
{
} else if (length < 0x100U) {
*octets_needed = 2;
}
else
{
} else {
*octets_needed = 3;
}
}
@ -76,24 +71,15 @@ 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)
{
if (value < 0x80UL)
{
if (value < 0x80UL) {
*octets_needed = 1;
}
else if (value < 0x8000UL)
{
} else if (value < 0x8000UL) {
*octets_needed = 2;
}
else if (value < 0x800000UL)
{
} else if (value < 0x800000UL) {
*octets_needed = 3;
}
else if (value < 0x80000000UL)
{
} else if (value < 0x80000000UL) {
*octets_needed = 4;
}
else
{
} else {
*octets_needed = 5;
}
}
@ -109,24 +95,15 @@ 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)
{
if (value < 0)
{
if (value < 0) {
value = ~value;
}
if (value < 0x80L)
{
} if (value < 0x80L) {
*octets_needed = 1;
}
else if (value < 0x8000L)
{
} else if (value < 0x8000L) {
*octets_needed = 2;
}
else if (value < 0x800000L)
{
} else if (value < 0x800000L) {
*octets_needed = 3;
}
else
{
} else {
*octets_needed = 4;
}
}
@ -145,22 +122,19 @@ snmp_asn1_enc_oid_cnt(u16_t ident_len, const s32_t *ident, u16_t *octets_needed)
u8_t cnt;
cnt = 0;
if (ident_len > 1)
{
if (ident_len > 1) {
/* compressed prefix in one octet */
cnt++;
ident_len -= 2;
ident += 2;
}
while(ident_len > 0)
{
while (ident_len > 0) {
ident_len--;
sub_id = *ident;
sub_id >>= 7;
cnt++;
while(sub_id > 0)
{
while (sub_id > 0) {
sub_id >>= 7;
cnt++;
}
@ -184,12 +158,10 @@ snmp_asn1_enc_type(struct pbuf *p, u16_t ofs, u8_t type)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
*msg_ptr = type;
@ -216,70 +188,57 @@ snmp_asn1_enc_length(struct pbuf *p, u16_t ofs, u16_t length)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if (length < 0x80)
{
if (length < 0x80) {
*msg_ptr = (u8_t)length;
return ERR_OK;
}
else if (length < 0x100)
{
} else if (length < 0x100) {
*msg_ptr = 0x81;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
*msg_ptr = (u8_t)length;
return ERR_OK;
}
else
{
} else {
u8_t i;
/* length >= 0x100 && length <= 0xFFFF */
*msg_ptr = 0x82;
i = 2;
while (i > 0)
{
while (i > 0) {
i--;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
if (i == 0)
{
if (i == 0) {
/* least significant length octet */
*msg_ptr = (u8_t)length;
}
else
{
} else {
/* most significant length octet */
*msg_ptr = (u8_t)(length >> 8);
}
@ -311,50 +270,44 @@ snmp_asn1_enc_u32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, u32_t value)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if (octets_needed == 5)
{
if (octets_needed == 5) {
/* not enough bits in 'value' add leading 0x00 */
octets_needed--;
*msg_ptr = 0x00;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
while (octets_needed > 1)
{
while (octets_needed > 1) {
octets_needed--;
*msg_ptr = (u8_t)(value >> (octets_needed << 3));
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
@ -387,30 +340,26 @@ snmp_asn1_enc_s32t(struct pbuf *p, u16_t ofs, u16_t octets_needed, s32_t value)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
while (octets_needed > 1)
{
while (octets_needed > 1) {
octets_needed--;
*msg_ptr = (u8_t)(value >> (octets_needed << 3));
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
@ -441,52 +390,42 @@ snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u16_t ident_len, const s32_t *ident
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
if (ident_len > 1)
{
if ((ident[0] == 1) && (ident[1] == 3))
{
if (ident_len > 1) {
if ((ident[0] == 1) && (ident[1] == 3)) {
/* compressed (most common) prefix .iso.org */
*msg_ptr = 0x2b;
}
else
{
} else {
/* calculate prefix */
*msg_ptr = (u8_t)((ident[0] * 40) + ident[1]);
}
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
ident_len -= 2;
ident += 2;
}
else
{
/* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */
} else {
/* @bug: allow empty varbinds for symmetry (we must decode them for getnext), allow partial compression?? */
/* ident_len <= 1, at least we need zeroDotZero (0.0) (ident_len == 2) */
return ERR_ARG;
}
while (ident_len > 0)
{
while (ident_len > 0) {
s32_t sub_id;
u8_t shift, tail;
@ -494,26 +433,23 @@ snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u16_t ident_len, const s32_t *ident
sub_id = *ident;
tail = 0;
shift = 28;
while(shift > 0)
{
while (shift > 0) {
u8_t code;
code = (u8_t)(sub_id >> shift);
if ((code != 0) || (tail != 0))
{
if ((code != 0) || (tail != 0)) {
tail = 1;
*msg_ptr = code | 0x80;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
@ -521,19 +457,17 @@ snmp_asn1_enc_oid(struct pbuf *p, u16_t ofs, u16_t ident_len, const s32_t *ident
shift -= 7;
}
*msg_ptr = (u8_t)sub_id & 0x7F;
if (ident_len > 0)
{
if (ident_len > 0) {
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
@ -565,38 +499,33 @@ snmp_asn1_enc_raw(struct pbuf *p, u16_t ofs, u16_t raw_len, const u8_t *raw)
u8_t *msg_ptr;
plen = 0;
while (p != NULL)
{
while (p != NULL) {
base = plen;
plen += p->len;
if (ofs < plen)
{
if (ofs < plen) {
msg_ptr = (u8_t*)p->payload;
msg_ptr += ofs - base;
while (raw_len > 1)
{
while (raw_len > 1) {
/* copy raw_len - 1 octets */
raw_len--;
*msg_ptr = *raw;
raw++;
ofs += 1;
if (ofs >= plen)
{
if (ofs >= plen) {
/* next octet in next pbuf */
p = p->next;
if (p == NULL) { return ERR_ARG; }
if (p == NULL) {
return ERR_ARG;
}
msg_ptr = (u8_t*)p->payload;
plen += p->len;
}
else
{
} else {
/* next octet in same pbuf */
msg_ptr++;
}
}
if (raw_len > 0)
{
if (raw_len > 0) {
/* copy last or single octet */
*msg_ptr = *raw;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -88,8 +88,7 @@ static u16_t snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *
void
snmp_trap_dst_enable(u8_t dst_idx, u8_t enable)
{
if (dst_idx < SNMP_TRAP_DESTINATIONS)
{
if (dst_idx < SNMP_TRAP_DESTINATIONS) {
trap_dst[dst_idx].enable = enable;
}
}
@ -102,8 +101,7 @@ snmp_trap_dst_enable(u8_t dst_idx, u8_t enable)
void
snmp_trap_dst_ip_set(u8_t dst_idx, const ip_addr_t *dst)
{
if (dst_idx < SNMP_TRAP_DESTINATIONS)
{
if (dst_idx < SNMP_TRAP_DESTINATIONS) {
ip_addr_set(&trap_dst[dst_idx].dip, dst);
}
}
@ -131,8 +129,7 @@ snmp_send_response(struct snmp_msg_pstat *m_stat)
/* try allocating pbuf(s) for complete response */
p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
if (p == NULL)
{
if (p == NULL) {
LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() tooBig\n"));
/* can't construct reply, return error-status tooBig */
@ -144,8 +141,7 @@ snmp_send_response(struct snmp_msg_pstat *m_stat)
/* retry allocation once for header and empty varbind-list */
p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
}
if (p != NULL)
{
if (p != NULL) {
/* first pbuf alloc try or retry alloc success */
u16_t ofs;
@ -155,26 +151,25 @@ snmp_send_response(struct snmp_msg_pstat *m_stat)
ofs = snmp_resp_header_enc(m_stat, p);
snmp_varbind_list_enc(&m_stat->outvb, p, ofs);
switch (m_stat->error_status)
{
case SNMP_ES_NOERROR:
/* nothing to do */
break;
case SNMP_ES_TOOBIG:
mib2_inc_snmpouttoobigs();
break;
case SNMP_ES_NOSUCHNAME:
mib2_inc_snmpoutnosuchnames();
break;
case SNMP_ES_BADVALUE:
mib2_inc_snmpoutbadvalues();
break;
case SNMP_ES_GENERROR:
mib2_inc_snmpoutgenerrs();
break;
default:
LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_send_response(): unknown error_status: %d\n", (int)m_stat->error_status));
break;
switch (m_stat->error_status) {
case SNMP_ES_NOERROR:
/* nothing to do */
break;
case SNMP_ES_TOOBIG:
mib2_inc_snmpouttoobigs();
break;
case SNMP_ES_NOSUCHNAME:
mib2_inc_snmpoutnosuchnames();
break;
case SNMP_ES_BADVALUE:
mib2_inc_snmpoutbadvalues();
break;
case SNMP_ES_GENERROR:
mib2_inc_snmpoutgenerrs();
break;
default:
LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_send_response(): unknown error_status: %d\n", (int)m_stat->error_status));
break;
}
mib2_inc_snmpoutgetresponses();
mib2_inc_snmpoutpkts();
@ -183,13 +178,10 @@ snmp_send_response(struct snmp_msg_pstat *m_stat)
/** connect to the originating source */
udp_connect(m_stat->pcb, &m_stat->sip, m_stat->sp);
err = udp_send(m_stat->pcb, p);
if (err == ERR_MEM)
{
if (err == ERR_MEM) {
/** @todo release some memory, retry and return tooBig? tooMuchHassle? */
err = ERR_MEM;
}
else
{
} else {
err = ERR_OK;
}
/** disassociate remote address and port with this pcb */
@ -198,9 +190,7 @@ snmp_send_response(struct snmp_msg_pstat *m_stat)
pbuf_free(p);
LWIP_DEBUGF(SNMP_MSG_DEBUG, ("snmp_snd_response() done\n"));
return err;
}
else
{
} else {
/* first pbuf alloc try or retry alloc failed
very low on memory, couldn't return tooBig */
return ERR_MEM;
@ -233,10 +223,8 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
u16_t i,tot_len;
err_t err = ERR_OK;
for (i=0, td = &trap_dst[0]; i<SNMP_TRAP_DESTINATIONS; i++, td++)
{
if ((td->enable != 0) && !ip_addr_isany(&td->dip))
{
for (i = 0, td = &trap_dst[0]; i < SNMP_TRAP_DESTINATIONS; i++, td++) {
if ((td->enable != 0) && !ip_addr_isany(&td->dip)) {
/* network order trap destination */
ip_addr_copy(trap_msg.dip, td->dip);
/* lookup current source address for this dst */
@ -247,13 +235,10 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
memcpy(trap_msg.sip_raw, dst_ip, trap_msg.sip_raw_len);
trap_msg.gen_trap = generic_trap;
trap_msg.spc_trap = specific_trap;
if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC)
{
if (generic_trap == SNMP_GENTRAP_ENTERPRISESPC) {
/* enterprise-Specific trap */
trap_msg.enterprise = eoid;
}
else
{
} else {
/* generic (MIB-II) trap */
mib2_get_snmpgrpid_ptr(&trap_msg.enterprise);
}
@ -266,8 +251,7 @@ snmp_send_trap(s8_t generic_trap, const struct snmp_obj_id *eoid, s32_t specific
/* allocate pbuf(s) */
p = pbuf_alloc(PBUF_TRANSPORT, tot_len, PBUF_POOL);
if (p != NULL)
{
if (p != NULL) {
u16_t ofs;
/* pass 1, encode packet ino the pbuf(s) */
@ -307,8 +291,7 @@ snmp_authfail_trap(void)
{
u8_t enable;
mib2_get_snmpenableauthentraps(&enable);
if (enable == 1)
{
if (enable == 1) {
trap_msg.outvb.head = NULL;
trap_msg.outvb.tail = NULL;
trap_msg.outvb.count = 0;
@ -438,35 +421,33 @@ snmp_varbind_list_sum(struct snmp_varbind_root *root)
tot_len = 0;
vb = root->tail;
while ( vb != NULL )
{
while (vb != NULL) {
/* encoded value lenght depends on type */
switch (vb->value_type)
{
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_s32t_cnt(*sint_ptr, &vb->vlen);
break;
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
uint_ptr = (u32_t*)vb->value;
snmp_asn1_enc_u32t_cnt(*uint_ptr, &vb->vlen);
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
vb->vlen = vb->value_len;
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_oid_cnt(vb->value_len / sizeof(s32_t), sint_ptr, &vb->vlen);
break;
default:
/* unsupported type */
vb->vlen = 0;
break;
switch (vb->value_type) {
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_s32t_cnt(*sint_ptr, &vb->vlen);
break;
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
uint_ptr = (u32_t*)vb->value;
snmp_asn1_enc_u32t_cnt(*uint_ptr, &vb->vlen);
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
vb->vlen = vb->value_len;
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_oid_cnt(vb->value_len / sizeof(s32_t), sint_ptr, &vb->vlen);
break;
default:
/* unsupported type */
vb->vlen = 0;
break;
}
/* encoding length of value length field */
snmp_asn1_enc_length_cnt(vb->vlen, &vb->vlenlen);
@ -638,8 +619,7 @@ snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *p, u16_t ofs)
ofs += root->seqlenlen;
vb = root->head;
while ( vb != NULL )
{
while (vb != NULL) {
snmp_asn1_enc_type(p, ofs, (SNMP_ASN1_UNIV | SNMP_ASN1_CONSTR | SNMP_ASN1_SEQ));
ofs += 1;
snmp_asn1_enc_length(p, ofs, vb->seqlen);
@ -657,33 +637,32 @@ snmp_varbind_list_enc(struct snmp_varbind_root *root, struct pbuf *p, u16_t ofs)
snmp_asn1_enc_length(p, ofs, vb->vlen);
ofs += vb->vlenlen;
switch (vb->value_type)
{
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_s32t(p, ofs, vb->vlen, *sint_ptr);
break;
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
uint_ptr = (u32_t*)vb->value;
snmp_asn1_enc_u32t(p, ofs, vb->vlen, *uint_ptr);
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
raw_ptr = (u8_t*)vb->value;
snmp_asn1_enc_raw(p, ofs, vb->vlen, raw_ptr);
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_oid(p, ofs, vb->value_len / sizeof(s32_t), sint_ptr);
break;
default:
/* unsupported type */
break;
switch (vb->value_type) {
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_s32t(p, ofs, vb->vlen, *sint_ptr);
break;
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS):
uint_ptr = (u32_t*)vb->value;
snmp_asn1_enc_u32t(p, ofs, vb->vlen, *uint_ptr);
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR):
case (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_OPAQUE):
raw_ptr = (u8_t*)vb->value;
snmp_asn1_enc_raw(p, ofs, vb->vlen, raw_ptr);
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_NUL):
break;
case (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID):
sint_ptr = (s32_t*)vb->value;
snmp_asn1_enc_oid(p, ofs, vb->value_len / sizeof(s32_t), sint_ptr);
break;
default:
/* unsupported type */
break;
}
ofs += vb->vlen;
vb = vb->next;