From 076f1ee89ea6565dd21e443d4aee1e26ad162335 Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 9 Jun 2016 14:28:04 +0200 Subject: [PATCH] minor: coding style cleanup in snmp code --- src/apps/snmp/snmp_asn1.c | 12 +-- src/apps/snmp/snmp_core.c | 173 +++++++++++--------------------- src/apps/snmp/snmp_msg.c | 12 ++- src/apps/snmp/snmp_scalar.c | 53 ++++------ src/apps/snmp/snmp_table.c | 129 ++++++++++-------------- src/apps/snmp/snmp_threadsync.c | 4 + src/apps/snmp/snmpv3.c | 3 +- 7 files changed, 146 insertions(+), 240 deletions(-) diff --git a/src/apps/snmp/snmp_asn1.c b/src/apps/snmp/snmp_asn1.c index 89071059..e2cb02c4 100644 --- a/src/apps/snmp/snmp_asn1.c +++ b/src/apps/snmp/snmp_asn1.c @@ -100,8 +100,7 @@ snmp_ans1_enc_tlv(struct snmp_pbuf_stream* pbuf_stream, struct snmp_asn1_tlv* tl PBUF_OP_EXEC(snmp_pbuf_stream_write(pbuf_stream, data)); - while (length_bytes_required > 1) - { + while (length_bytes_required > 1) { if (length_bytes_required == 2) { /* append high byte */ data = (u8_t)(tlv->value_len >> 8); @@ -344,8 +343,7 @@ void snmp_asn1_enc_u64t_cnt(const u32_t *value, u16_t *octets_needed) { /* check if high u32 is 0 */ - if (*value == 0x00) - { + if (*value == 0x00) { /* only low u32 is important */ value++; snmp_asn1_enc_u32t_cnt(*value, octets_needed); @@ -496,8 +494,7 @@ snmp_asn1_dec_u32t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value *value = data; len--; - while (len > 0) - { + while (len > 0) { PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data)); len--; @@ -544,8 +541,7 @@ snmp_asn1_dec_u64t(struct snmp_pbuf_stream *pbuf_stream, u16_t len, u32_t *value *value = data; len--; - while (len > 0) - { + while (len > 0) { PBUF_OP_EXEC(snmp_pbuf_stream_read(pbuf_stream, &data)); if (len == 4) { diff --git a/src/apps/snmp/snmp_core.c b/src/apps/snmp/snmp_core.c index 287fcf95..1351ef00 100644 --- a/src/apps/snmp/snmp_core.c +++ b/src/apps/snmp/snmp_core.c @@ -382,12 +382,10 @@ 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); - if (oid_len > 0) - { + if (oid_len > 0) { /* move existing OID to make room at the beginning for OID to insert */ 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]; } @@ -421,14 +419,11 @@ snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_ LWIP_ASSERT("'oid1' param must not be NULL or 'oid1_len' param be 0!", (oid1 != NULL) || (oid1_len == 0)); LWIP_ASSERT("'oid2' param must not be NULL or 'oid2_len' param be 0!", (oid2 != NULL) || (oid2_len == 0)); - while ((level < oid1_len) && (level < oid2_len)) - { - if (*oid1 < *oid2) - { + while ((level < oid1_len) && (level < oid2_len)) { + if (*oid1 < *oid2) { return -1; } - if (*oid1 > *oid2) - { + if (*oid1 > *oid2) { return 1; } @@ -438,12 +433,10 @@ snmp_oid_compare(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t oid2_ } /* common part of both OID's is equal, compare length */ - if (oid1_len < oid2_len) - { + if (oid1_len < oid2_len) { return -1; } - if (oid1_len > oid2_len) - { + if (oid1_len > oid2_len) { return 1; } @@ -493,21 +486,17 @@ snmp_get_mib_from_oid(const u32_t *oid, u8_t oid_len) return NULL; } - for (i=0; ibase_oid != NULL)); - if (oid_len >= snmp_mibs[i]->base_oid_len) - { + if (oid_len >= snmp_mibs[i]->base_oid_len) { l = snmp_mibs[i]->base_oid_len; list_oid = snmp_mibs[i]->base_oid; searched_oid = oid; - while (l > 0) - { - if (*list_oid != *searched_oid) - { + while (l > 0) { + if (*list_oid != *searched_oid) { break; } @@ -516,8 +505,7 @@ snmp_get_mib_from_oid(const u32_t *oid, u8_t oid_len) searched_oid++; } - if ((l == 0) && (snmp_mibs[i]->base_oid_len > max_match_len)) - { + if ((l == 0) && (snmp_mibs[i]->base_oid_len > max_match_len)) { max_match_len = snmp_mibs[i]->base_oid_len; matched_mib = snmp_mibs[i]; } @@ -539,15 +527,13 @@ snmp_get_next_mib(const u32_t *oid, u8_t oid_len) return NULL; } - for (i=0; ibase_oid != NULL) - { + for (i = 0; i < snmp_num_mibs; i++) { + if (snmp_mibs[i]->base_oid != NULL) { /* check if mib is located behind starting point */ - if (snmp_oid_compare(snmp_mibs[i]->base_oid, snmp_mibs[i]->base_oid_len, oid, oid_len) > 0) - { - if ((next_mib == NULL) || (snmp_oid_compare(snmp_mibs[i]->base_oid, snmp_mibs[i]->base_oid_len, next_mib->base_oid, next_mib->base_oid_len) < 0)) - { + if (snmp_oid_compare(snmp_mibs[i]->base_oid, snmp_mibs[i]->base_oid_len, oid, oid_len) > 0) { + if ((next_mib == NULL) || + (snmp_oid_compare(snmp_mibs[i]->base_oid, snmp_mibs[i]->base_oid_len, + next_mib->base_oid, next_mib->base_oid_len) < 0)) { next_mib = snmp_mibs[i]; } } @@ -565,10 +551,8 @@ snmp_get_mib_between(const u32_t *oid1, u8_t oid1_len, const u32_t *oid2, u8_t o LWIP_ASSERT("'oid2' param must not be NULL!", (oid2 != NULL)); LWIP_ASSERT("'oid2_len' param must be greater than 0!", (oid2_len > 0)); - if (next_mib != NULL) - { - if (snmp_oid_compare(next_mib->base_oid, next_mib->base_oid_len, oid2, oid2_len) < 0) - { + if (next_mib != NULL) { + if (snmp_oid_compare(next_mib->base_oid, next_mib->base_oid_len, oid2, oid2_len) < 0) { return next_mib; } } @@ -656,8 +640,7 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida /* validate the node; if the node has no further instance or the returned instance is invalid, search for the next in MIB and validate again */ node_instance->node = mn; - while (mn != NULL) - { + while (mn != NULL) { u8_t result; /* clear fields which may have values from previous loops */ @@ -675,8 +658,7 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida node_oid->len, node_instance); - if (result == SNMP_ERR_NOERROR) - { + if (result == SNMP_ERR_NOERROR) { #ifdef LWIP_DEBUG if(((node_instance->access & SNMP_NODE_INSTANCE_ACCESS_READ) != 0) && (node_instance->get_value == NULL)) { LWIP_DEBUGF(SNMP_DEBUG, ("SNMP inconsistent access: node is readable but no get_value function is specified\n")); @@ -687,8 +669,8 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida #endif /* validate node because the node may be not accessible for example (but let the caller decide what is valid */ - if ((validate_node_instance_method == NULL) || (validate_node_instance_method(node_instance, validate_node_instance_arg) == SNMP_ERR_NOERROR)) - { + if ((validate_node_instance_method == NULL) || + (validate_node_instance_method(node_instance, validate_node_instance_arg) == SNMP_ERR_NOERROR)) { /* node_oid "returns" the full result OID (including the instance part) */ snmp_oid_append(node_oid, node_instance->instance_oid.id, node_instance->instance_oid.len); break; @@ -702,17 +684,14 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida we don't have to change any variables because node_instance->instance_oid is used as input (starting point) as well as output (resulting next OID), so we have to simply call get_next_instance method again */ - } - else - { + } else { if (node_instance->release_instance != NULL) { node_instance->release_instance(node_instance); } /* the node has no further instance, skip to next node */ mn = snmp_mib_tree_resolve_next(mib, node_oid->id, node_oid->len, &node_instance->instance_oid); /* misuse node_instance->instance_oid as tmp buffer */ - if (mn != NULL) - { + if (mn != NULL) { /* prepare for next loop */ snmp_oid_assign(node_oid, node_instance->instance_oid.id, node_instance->instance_oid.len); node_instance->instance_oid.len = 0; @@ -781,8 +760,7 @@ snmp_get_next_node_instance_from_oid(const u32_t *oid, u8_t oid_len, snmp_valida } } - if (mib == NULL) - { + if (mib == NULL) { /* loop is only left when mib == null (error) or mib_node != NULL (success) */ return SNMP_ERR_ENDOFMIBVIEW; } @@ -800,21 +778,18 @@ snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t o const struct snmp_node* const* node = &mib->root_node; 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 */ u32_t subnode_oid = *(oid + oid_offset); u32_t i = (*(const struct snmp_tree_node* const*)node)->subnode_count; node = (*(const struct snmp_tree_node* const*)node)->subnodes; - while ((i > 0) && ((*node)->oid != subnode_oid)) - { + while ((i > 0) && ((*node)->oid != subnode_oid)) { node++; i--; } - if (i == 0) - { + if (i == 0) { /* no matching subnode found */ return NULL; } @@ -822,8 +797,7 @@ snmp_mib_tree_resolve_exact(const struct snmp_mib *mib, const u32_t *oid, u8_t o oid_offset++; } - if ((*node)->node_type != SNMP_NODE_TREE) - { + if ((*node)->node_type != SNMP_NODE_TREE) { /* we found a leaf node */ *oid_instance_len = oid_len - oid_offset; return (*node); @@ -841,30 +815,26 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi s32_t nsi = 0; /* NodeStackIndex */ u32_t subnode_oid; - if (mib->root_node->node_type != SNMP_NODE_TREE) - { + if (mib->root_node->node_type != SNMP_NODE_TREE) { /* a next operation on a mib with only a leaf node will always return NULL because there is no other node */ return NULL; } /* 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*)mib->root_node; - while (oid_offset < oid_len) - { + while (oid_offset < oid_len) { /* search for matching sub node */ u32_t i = node_stack[nsi]->subnode_count; node = node_stack[nsi]->subnodes; subnode_oid = *(oid + oid_offset); - while ((i > 0) && ((*node)->oid != subnode_oid)) - { + while ((i > 0) && ((*node)->oid != subnode_oid)) { node++; i--; } - if ((i == 0) || ((*node)->node_type != SNMP_NODE_TREE)) - { + if ((i == 0) || ((*node)->node_type != SNMP_NODE_TREE)) { /* no (matching) tree-subnode found */ break; } @@ -875,32 +845,24 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi } - if (oid_offset >= oid_len) - { + if (oid_offset >= oid_len) { /* passed oid references a tree node -> return first useable sub node of it */ subnode_oid = 0; - } - else - { + } else { subnode_oid = *(oid + oid_offset) + 1; } - while (nsi >= 0) - { + while (nsi >= 0) { const struct snmp_node* subnode = NULL; /* find next node on current level */ s32_t i = node_stack[nsi]->subnode_count; node = node_stack[nsi]->subnodes; - while (i > 0) - { - if ((*node)->oid == subnode_oid) - { + while (i > 0) { + if ((*node)->oid == subnode_oid) { subnode = *node; break; - } - else if (((*node)->oid > subnode_oid) && ((subnode == NULL) || ((*node)->oid < subnode->oid))) - { + } else if (((*node)->oid > subnode_oid) && ((subnode == NULL) || ((*node)->oid < subnode->oid))) { subnode = *node; } @@ -908,28 +870,21 @@ snmp_mib_tree_resolve_next(const struct snmp_mib *mib, const u32_t *oid, u8_t oi i--; } - if (subnode == NULL) - { + if (subnode == NULL) { /* no further node found on this level, go one level up and start searching with index of current node*/ subnode_oid = node_stack[nsi]->node.oid + 1; nsi--; - } - else - { - if (subnode->node_type == SNMP_NODE_TREE) - { + } else { + if (subnode->node_type == SNMP_NODE_TREE) { /* next is a tree node, go into it and start searching */ nsi++; node_stack[nsi] = (const struct snmp_tree_node*)subnode; subnode_oid = 0; - } - else - { + } else { /* we found a leaf node -> fill oidret and return it */ snmp_oid_assign(oidret, mib->base_oid, mib->base_oid_len); i = 1; - while (i <= nsi) - { + while (i <= nsi) { oidret->id[oidret->len] = node_stack[i]->node.oid; oidret->len++; i++; @@ -962,17 +917,14 @@ snmp_next_oid_init(struct snmp_next_oid_state *state, u8_t snmp_next_oid_precheck(struct snmp_next_oid_state *state, const u32_t *oid, const u8_t oid_len) { - if (state->status != SNMP_NEXT_OID_STATUS_BUF_TO_SMALL) - { + if (state->status != SNMP_NEXT_OID_STATUS_BUF_TO_SMALL) { u8_t start_oid_len = (oid_len < state->start_oid_len) ? oid_len : state->start_oid_len; /* check passed OID is located behind start offset */ - if (snmp_oid_compare(oid, oid_len, state->start_oid, start_oid_len) >= 0) - { + if (snmp_oid_compare(oid, oid_len, state->start_oid, start_oid_len) >= 0) { /* check if new oid is located closer to start oid than current closest oid */ if ((state->status == SNMP_NEXT_OID_STATUS_NO_MATCH) || - (snmp_oid_compare(oid, oid_len, state->next_oid, state->next_oid_len) < 0)) - { + (snmp_oid_compare(oid, oid_len, state->next_oid, state->next_oid_len) < 0)) { return 1; } } @@ -985,25 +937,19 @@ u8_t snmp_next_oid_check(struct snmp_next_oid_state *state, const u32_t *oid, const u8_t oid_len, void* reference) { /* 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) { /* check passed OID is located behind start offset */ - if (snmp_oid_compare(oid, oid_len, state->start_oid, state->start_oid_len) > 0) - { + if (snmp_oid_compare(oid, oid_len, state->start_oid, state->start_oid_len) > 0) { /* check if new oid is located closer to start oid than current closest oid */ if ((state->status == SNMP_NEXT_OID_STATUS_NO_MATCH) || - (snmp_oid_compare(oid, oid_len, state->next_oid, state->next_oid_len) < 0)) - { - if (oid_len <= state->next_oid_max_len) - { + (snmp_oid_compare(oid, oid_len, state->next_oid, state->next_oid_len) < 0)) { + if (oid_len <= state->next_oid_max_len) { MEMCPY(state->next_oid, oid, oid_len * sizeof(u32_t)); state->next_oid_len = oid_len; state->status = SNMP_NEXT_OID_STATUS_SUCCESS; state->reference = reference; return 1; - } - else - { + } else { state->status = SNMP_NEXT_OID_STATUS_BUF_TO_SMALL; } } @@ -1022,9 +968,8 @@ snmp_oid_in_range(const u32_t *oid_in, u8_t oid_len, const struct snmp_oid_range return 0; } - for(i=0; i oid_ranges[i].max)) { + for(i = 0; i < oid_ranges_len; i++) { + if ((oid_in[i] < oid_ranges[i].min) || (oid_in[i] > oid_ranges[i].max)) { return 0; } } @@ -1155,13 +1100,11 @@ snmp_encode_bits(u8_t *buf, u32_t buf_len, u32_t bit_value, u8_t bit_count) len++; } - if (len < min_bytes) - { + if (len < min_bytes) { buf += len; buf_len -= len; - while ((len < min_bytes) && (buf_len > 0)) - { + while ((len < min_bytes) && (buf_len > 0)) { *buf = 0x00; buf++; buf_len--; diff --git a/src/apps/snmp/snmp_msg.c b/src/apps/snmp/snmp_msg.c index fe4cb122..e2c7fa48 100644 --- a/src/apps/snmp/snmp_msg.c +++ b/src/apps/snmp/snmp_msg.c @@ -1308,25 +1308,29 @@ snmp_complete_outbound_frame(struct snmp_request *request) case SNMP_ERR_NOSUCHINSTANCE: case SNMP_ERR_NOSUCHOBJECT: case SNMP_ERR_ENDOFMIBVIEW: - request->error_status = SNMP_ERR_NOSUCHNAME; break; + request->error_status = SNMP_ERR_NOSUCHNAME; + break; /* mapping according to RFC */ case SNMP_ERR_WRONGVALUE: case SNMP_ERR_WRONGENCODING: case SNMP_ERR_WRONGTYPE: case SNMP_ERR_WRONGLENGTH: case SNMP_ERR_INCONSISTENTVALUE: - request->error_status = SNMP_ERR_BADVALUE; break; + request->error_status = SNMP_ERR_BADVALUE; + break; case SNMP_ERR_NOACCESS: case SNMP_ERR_NOTWRITABLE: case SNMP_ERR_NOCREATION: case SNMP_ERR_INCONSISTENTNAME: case SNMP_ERR_AUTHORIZATIONERROR: - request->error_status = SNMP_ERR_NOSUCHNAME; break; + request->error_status = SNMP_ERR_NOSUCHNAME; + break; case SNMP_ERR_RESOURCEUNAVAILABLE: case SNMP_ERR_COMMITFAILED: case SNMP_ERR_UNDOFAILED: default: - request->error_status = SNMP_ERR_GENERROR; break; + request->error_status = SNMP_ERR_GENERROR; + break; } } } else { diff --git a/src/apps/snmp/snmp_scalar.c b/src/apps/snmp/snmp_scalar.c index 9e583313..e7399986 100644 --- a/src/apps/snmp/snmp_scalar.c +++ b/src/apps/snmp/snmp_scalar.c @@ -55,8 +55,7 @@ snmp_scalar_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct snmp_n LWIP_UNUSED_ARG(root_oid_len); /* scalar only has one dedicated instance: .0 */ - if ((instance->instance_oid.len != 1) || (instance->instance_oid.id[0] != 0)) - { + if ((instance->instance_oid.len != 1) || (instance->instance_oid.id[0] != 0)) { return SNMP_ERR_NOSUCHINSTANCE; } @@ -72,8 +71,7 @@ snmp_err_t 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 */ - if (instance->instance_oid.len == 0) - { + if (instance->instance_oid.len == 0) { instance->instance_oid.len = 1; instance->instance_oid.id[0] = 0; @@ -90,16 +88,13 @@ snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct LWIP_UNUSED_ARG(root_oid); 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*)instance->node; const struct snmp_scalar_array_node_def* array_node_def = array_node->array_nodes; u32_t i = 0; - while (i < array_node->array_node_count) - { - if (array_node_def->oid == instance->instance_oid.id[0]) - { + while (i < array_node->array_node_count) { + if (array_node_def->oid == instance->instance_oid.id[0]) { break; } @@ -107,8 +102,7 @@ snmp_scalar_array_get_instance(const u32_t *root_oid, u8_t root_oid_len, struct i++; } - if (i < array_node->array_node_count) - { + if (i < array_node->array_node_count) { instance->access = array_node_def->access; instance->asn1_type = array_node_def->asn1_type; instance->get_value = snmp_scalar_array_get_value; @@ -133,33 +127,25 @@ snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, st LWIP_UNUSED_ARG(root_oid); LWIP_UNUSED_ARG(root_oid_len); - if ((instance->instance_oid.len == 0) && (array_node->array_node_count > 0)) - { + if ((instance->instance_oid.len == 0) && (array_node->array_node_count > 0)) { /* return node with lowest OID */ u16_t i = 0; result = array_node_def; array_node_def++; - for (i = 1; i < array_node->array_node_count; i++) - { - if (array_node_def->oid < result->oid) - { + for (i = 1; i < array_node->array_node_count; i++) { + if (array_node_def->oid < result->oid) { result = array_node_def; } array_node_def++; } - } - else if (instance->instance_oid.len >= 1) - { - if (instance->instance_oid.len == 1) - { + } else if (instance->instance_oid.len >= 1) { + if (instance->instance_oid.len == 1) { /* if we have the requested OID we return its instance, otherwise we search for the next available */ u16_t i = 0; - while (i < array_node->array_node_count) - { - if (array_node_def->oid == instance->instance_oid.id[0]) - { + while (i < array_node->array_node_count) { + if (array_node_def->oid == instance->instance_oid.id[0]) { result = array_node_def; break; } @@ -168,15 +154,13 @@ snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, st i++; } } - if (result == NULL) - { + if (result == NULL) { u32_t oid_dist = 0xFFFFFFFFUL; u16_t i = 0; array_node_def = array_node->array_nodes; /* may be already at the end when if case before was executed without result -> reinitialize to start */ - while (i < array_node->array_node_count) - { - if ((array_node_def->oid > instance->instance_oid.id[0]) && ((u32_t)(array_node_def->oid - instance->instance_oid.id[0]) < oid_dist)) - { + while (i < array_node->array_node_count) { + if ((array_node_def->oid > instance->instance_oid.id[0]) && + ((u32_t)(array_node_def->oid - instance->instance_oid.id[0]) < oid_dist)) { result = array_node_def; oid_dist = array_node_def->oid - instance->instance_oid.id[0]; } @@ -187,8 +171,7 @@ snmp_scalar_array_get_next_instance(const u32_t *root_oid, u8_t root_oid_len, st } } - if (result == NULL) - { + if (result == NULL) { /* nothing to return */ return SNMP_ERR_NOSUCHINSTANCE; } diff --git a/src/apps/snmp/snmp_table.c b/src/apps/snmp/snmp_table.c index 67108c19..fa14448d 100644 --- a/src/apps/snmp/snmp_table.c +++ b/src/apps/snmp/snmp_table.c @@ -53,15 +53,12 @@ snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, str /* check min. length (fixed row entry definition, column, row instance oid with at least one entry */ /* 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 */ const struct snmp_table_col_def* col_def = table_node->columns; u16_t i = table_node->column_count; - while (i > 0) - { - if (col_def->index == instance->instance_oid.id[1]) - { + while (i > 0) { + if (col_def->index == instance->instance_oid.id[1]) { break; } @@ -69,8 +66,7 @@ snmp_err_t snmp_table_get_instance(const u32_t *root_oid, u8_t root_oid_len, str i--; } - if (i > 0) - { + if (i > 0) { /* everything may be overwritten by get_cell_instance_method() in order to implement special handling for single columns/cells */ instance->asn1_type = col_def->asn1_type; instance->access = col_def->access; @@ -101,20 +97,15 @@ snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len LWIP_UNUSED_ARG(root_oid_len); /* check that first part of id is 0 or 1, referencing fixed row entry */ - if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) - { + if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) { return SNMP_ERR_NOSUCHINSTANCE; } - if (instance->instance_oid.len > 1) - { + if (instance->instance_oid.len > 1) { column = instance->instance_oid.id[1]; } - if (instance->instance_oid.len > 2) - { + if (instance->instance_oid.len > 2) { snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2); - } - else - { + } else { row_oid.len = 0; } @@ -123,28 +114,22 @@ snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len instance->set_value = table_node->set_value; /* resolve column and value */ - do - { + do { u16_t i; const struct snmp_table_col_def* next_col_def = NULL; col_def = table_node->columns; - for (i=0; icolumn_count; i++) - { - if (col_def->index == column) - { + for (i = 0; i < table_node->column_count; i++) { + if (col_def->index == column) { next_col_def = col_def; break; - } - else if ((col_def->index > column) && ((next_col_def == NULL) || (col_def->index < next_col_def->index))) - { + } else if ((col_def->index > column) && ((next_col_def == NULL) || (col_def->index < next_col_def->index))) { next_col_def = col_def; } col_def++; } - if (next_col_def == NULL) - { + if (next_col_def == NULL) { /* no further column found */ return SNMP_ERR_NOSUCHINSTANCE; } @@ -157,16 +142,14 @@ snmp_err_t snmp_table_get_next_instance(const u32_t *root_oid, u8_t root_oid_len &row_oid, instance); - if (result == SNMP_ERR_NOERROR) - { + if (result == SNMP_ERR_NOERROR) { col_def = next_col_def; break; } 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; - } - while (1); + } while (1); /* build resulting oid */ instance->instance_oid.len = 2; @@ -188,8 +171,7 @@ snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_l /* check min. length (fixed row entry definition, column, row instance oid with at least one entry */ /* 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)) { ret = table_node->get_cell_value( &(instance->instance_oid.id[1]), &(instance->instance_oid.id[2]), @@ -197,15 +179,12 @@ snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_l &instance->reference, &instance->reference_len); - if (ret == SNMP_ERR_NOERROR) - { + if (ret == SNMP_ERR_NOERROR) { /* search column */ const struct snmp_table_simple_col_def* col_def = table_node->columns; u32_t i = table_node->column_count; - while (i > 0) - { - if (col_def->index == instance->instance_oid.id[1]) - { + while (i > 0) { + if (col_def->index == instance->instance_oid.id[1]) { break; } @@ -213,28 +192,30 @@ snmp_err_t snmp_table_simple_get_instance(const u32_t *root_oid, u8_t root_oid_l i--; } - if (i > 0) - { + if (i > 0) { instance->asn1_type = col_def->asn1_type; instance->access = SNMP_NODE_INSTANCE_READ_ONLY; instance->set_test = NULL; instance->set_value = NULL; - switch (col_def->data_type) - { - case SNMP_VARIANT_VALUE_TYPE_U32: instance->get_value = snmp_table_extract_value_from_u32ref; break; - case SNMP_VARIANT_VALUE_TYPE_S32: instance->get_value = snmp_table_extract_value_from_s32ref; break; + switch (col_def->data_type) { + case SNMP_VARIANT_VALUE_TYPE_U32: + instance->get_value = snmp_table_extract_value_from_u32ref; + break; + case SNMP_VARIANT_VALUE_TYPE_S32: + instance->get_value = snmp_table_extract_value_from_s32ref; + break; case SNMP_VARIANT_VALUE_TYPE_PTR: /* fall through */ - case SNMP_VARIANT_VALUE_TYPE_CONST_PTR: instance->get_value = snmp_table_extract_value_from_refconstptr; break; + case SNMP_VARIANT_VALUE_TYPE_CONST_PTR: + instance->get_value = snmp_table_extract_value_from_refconstptr; + break; default: LWIP_DEBUGF(SNMP_DEBUG, ("snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type)); return SNMP_ERR_GENERROR; } ret = SNMP_ERR_NOERROR; - } - else - { + } else { ret = SNMP_ERR_NOSUCHINSTANCE; } } @@ -255,46 +236,36 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_ LWIP_UNUSED_ARG(root_oid_len); /* check that first part of id is 0 or 1, referencing fixed row entry */ - if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) - { + if ((instance->instance_oid.len > 0) && (instance->instance_oid.id[0] > 1)) { return SNMP_ERR_NOSUCHINSTANCE; } - if (instance->instance_oid.len > 1) - { + if (instance->instance_oid.len > 1) { column = instance->instance_oid.id[1]; } - if (instance->instance_oid.len > 2) - { + if (instance->instance_oid.len > 2) { snmp_oid_assign(&row_oid, &(instance->instance_oid.id[2]), instance->instance_oid.len - 2); - } - else - { + } else { row_oid.len = 0; } /* resolve column and value */ - do - { + do { u32_t i; const struct snmp_table_simple_col_def* next_col_def = NULL; col_def = table_node->columns; - for (i=0; icolumn_count; i++) - { - if (col_def->index == column) - { + for (i = 0; i < table_node->column_count; i++) { + if (col_def->index == column) { next_col_def = col_def; break; - } - else if ((col_def->index > column) && ((next_col_def == NULL) || (col_def->index < next_col_def->index))) - { + } else if ((col_def->index > column) && ((next_col_def == NULL) || + (col_def->index < next_col_def->index))) { next_col_def = col_def; } col_def++; } - if (next_col_def == NULL) - { + if (next_col_def == NULL) { /* no further column found */ return SNMP_ERR_NOSUCHINSTANCE; } @@ -305,8 +276,7 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_ &instance->reference, &instance->reference_len); - if (result == SNMP_ERR_NOERROR) - { + if (result == SNMP_ERR_NOERROR) { col_def = next_col_def; break; } @@ -321,12 +291,17 @@ snmp_err_t snmp_table_simple_get_next_instance(const u32_t *root_oid, u8_t root_ instance->set_test = NULL; instance->set_value = NULL; - switch (col_def->data_type) - { - case SNMP_VARIANT_VALUE_TYPE_U32: instance->get_value = snmp_table_extract_value_from_u32ref; break; - case SNMP_VARIANT_VALUE_TYPE_S32: instance->get_value = snmp_table_extract_value_from_s32ref; break; + switch (col_def->data_type) { + case SNMP_VARIANT_VALUE_TYPE_U32: + instance->get_value = snmp_table_extract_value_from_u32ref; + break; + case SNMP_VARIANT_VALUE_TYPE_S32: + instance->get_value = snmp_table_extract_value_from_s32ref; + break; case SNMP_VARIANT_VALUE_TYPE_PTR: /* fall through */ - case SNMP_VARIANT_VALUE_TYPE_CONST_PTR: instance->get_value = snmp_table_extract_value_from_refconstptr; break; + case SNMP_VARIANT_VALUE_TYPE_CONST_PTR: + instance->get_value = snmp_table_extract_value_from_refconstptr; + break; default: LWIP_DEBUGF(SNMP_DEBUG, ("snmp_table_simple_get_instance(): unknown column data_type: %d\n", col_def->data_type)); return SNMP_ERR_GENERROR; diff --git a/src/apps/snmp/snmp_threadsync.c b/src/apps/snmp/snmp_threadsync.c index d26bd276..00f4b472 100644 --- a/src/apps/snmp/snmp_threadsync.c +++ b/src/apps/snmp/snmp_threadsync.c @@ -59,6 +59,7 @@ threadsync_get_value_synced(void *ctx) sys_sem_signal(&call_data->threadsync_node->instance->sem); } + static u16_t threadsync_get_value(struct snmp_node_instance* instance, void* value) { @@ -79,6 +80,7 @@ threadsync_set_test_synced(void *ctx) sys_sem_signal(&call_data->threadsync_node->instance->sem); } + static snmp_err_t threadsync_set_test(struct snmp_node_instance* instance, u16_t len, void *value) { @@ -100,6 +102,7 @@ threadsync_set_value_synced(void *ctx) sys_sem_signal(&call_data->threadsync_node->instance->sem); } + static snmp_err_t threadsync_set_value(struct snmp_node_instance* instance, u16_t len, void *value) { @@ -121,6 +124,7 @@ threadsync_release_instance_synced(void* ctx) sys_sem_signal(&call_data->threadsync_node->instance->sem); } + static void threadsync_release_instance(struct snmp_node_instance *instance) { diff --git a/src/apps/snmp/snmpv3.c b/src/apps/snmp/snmpv3.c index 7790ac88..b33d6f78 100644 --- a/src/apps/snmp/snmpv3.c +++ b/src/apps/snmp/snmpv3.c @@ -119,8 +119,9 @@ snmpv3_build_priv_param(u8_t* priv_param) /* Emulate 64bit increment */ priv1++; - if (!priv1) /* Overflow */ + if (!priv1) { /* Overflow */ priv2++; + } #else /* Based on RFC3414 */ static u32_t ctr; u32_t boots = LWIP_SNMPV3_GET_ENGINE_BOOTS();