diff --git a/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_interface.c b/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_interface.c index 854f11b0017a..478d86ecafbe 100644 --- a/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_interface.c +++ b/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan_interface.c @@ -87,7 +87,10 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur) #endif } } - uint16_t pan_id = cur->mac_parameters->pan_id; + if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION) { + pana_reset_values(cur->mac_parameters->pan_id); + } + if (cur->interface_mode == INTERFACE_UP) { if (cur->mac_api) { mlme_reset_t reset; @@ -105,9 +108,6 @@ static int8_t set_6lowpan_nwk_down(protocol_interface_info_entry_t *cur) reassembly_interface_reset(cur->id); icmp_nd_routers_init(); - if (cur->lowpan_info & INTERFACE_NWK_BOOTSRAP_PANA_AUTHENTICATION) { - pana_reset_values(pan_id); - } if (cur->pana_sec_info_temp) { ns_dyn_mem_free(cur->pana_sec_info_temp); diff --git a/source/6LoWPAN/MAC/mac_helper.c b/source/6LoWPAN/MAC/mac_helper.c index bf3e6c311514..faf954010d1b 100644 --- a/source/6LoWPAN/MAC/mac_helper.c +++ b/source/6LoWPAN/MAC/mac_helper.c @@ -768,8 +768,10 @@ static uint8_t mac_helper_header_security_aux_header_length(uint8_t keyIdmode) { switch (keyIdmode) { case MAC_KEY_ID_MODE_SRC8_IDX: header_length += 4; //64-bit key source first part + /* fall through */ case MAC_KEY_ID_MODE_SRC4_IDX: header_length += 4; //32-bit key source inline + /* fall through */ case MAC_KEY_ID_MODE_IDX: header_length += 1; break; diff --git a/source/Common_Protocols/icmpv6.c b/source/Common_Protocols/icmpv6.c index cf11bb8c893a..6c4240b65de8 100644 --- a/source/Common_Protocols/icmpv6.c +++ b/source/Common_Protocols/icmpv6.c @@ -48,7 +48,6 @@ #define TRACE_GROUP "icmp" static buffer_t *icmpv6_echo_request_handler(struct buffer *buf); -static buffer_t *icmpv6_na_handler(struct buffer *buf); /* Check to see if a message is recognisable ICMPv6, and if so, fill in code/type */ /* This used ONLY for the e.1 + e.2 tests in RFC 4443, to try to avoid ICMPv6 error loops */ @@ -486,7 +485,6 @@ static buffer_t *icmpv6_ns_handler(buffer_t *buf) * interface, which we should only do in the whiteboard case. */ if (addr_interface_address_compare(cur, target) != 0) { - int8_t mesh_id = -1; //tr_debug("Received NS for proxy %s", trace_ipv6(target)); proxy = true; @@ -495,7 +493,7 @@ static buffer_t *icmpv6_ns_handler(buffer_t *buf) goto drop; } - if (!nd_proxy_enabled_for_downstream(cur->id) || !nd_proxy_target_address_validation(cur->id, target, &mesh_id)) { + if (!nd_proxy_enabled_for_downstream(cur->id) || !nd_proxy_target_address_validation(cur->id, target)) { goto drop; } } @@ -922,6 +920,80 @@ static buffer_t *icmpv6_redirect_handler(buffer_t *buf, protocol_interface_info_ tr_warn("Redirect drop"); return buffer_free(buf); } + +static buffer_t *icmpv6_na_handler(buffer_t *buf) +{ + protocol_interface_info_entry_t *cur; + uint8_t *dptr = buffer_data_pointer(buf); + uint8_t flags; + const uint8_t *target; + const uint8_t *tllao; + if_address_entry_t *addr_entry; + ipv6_neighbour_t *neighbour_entry; + + //"Parse NA at IPv6\n"); + + if (buf->options.code != 0 || buf->options.hop_limit != 255) { + goto drop; + } + + if (!icmpv6_options_well_formed_in_buffer(buf, 20)) { + goto drop; + } + + // Skip the 4 reserved bytes + flags = *dptr; + dptr += 4; + + // Note the target IPv6 address + target = dptr; + + if (addr_is_ipv6_multicast(target)) { + goto drop; + } + + /* Solicited flag must be clear if sent to a multicast address */ + if (addr_is_ipv6_multicast(buf->dst_sa.address) && (flags & NA_S)) { + goto drop; + } + + cur = buf->interface; + + /* RFC 4862 5.4.4 DAD checks */ + addr_entry = addr_get_entry(cur, target); + if (addr_entry) { + if (addr_entry->tentative) { + tr_debug("Received NA for our tentative address"); + addr_duplicate_detected(cur, target); + } else { + tr_debug("NA received for our own address: %s", trace_ipv6(target)); + } + goto drop; + } + + if (cur->ipv6_neighbour_cache.recv_na_aro) { + const uint8_t *aro = icmpv6_find_option_in_buffer(buf, 20, ICMPV6_OPT_ADDR_REGISTRATION, 2); + if (aro) { + icmpv6_na_aro_handler(cur, aro, buf->dst_sa.address); + } + } + + /* No need to create a neighbour cache entry if one doesn't already exist */ + neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, target); + if (!neighbour_entry) { + goto drop; + } + + tllao = icmpv6_find_option_in_buffer(buf, 20, ICMPV6_OPT_TGT_LL_ADDR, 0); + if (!tllao || !cur->if_llao_parse(cur, tllao, &buf->dst_sa)) { + buf->dst_sa.addr_type = ADDR_NONE; + } + + ipv6_neighbour_update_from_na(&cur->ipv6_neighbour_cache, neighbour_entry, flags, buf->dst_sa.addr_type, buf->dst_sa.address); + +drop: + return buffer_free(buf); +} #endif // HAVE_IPV6_ND buffer_t *icmpv6_up(buffer_t *buf) @@ -994,7 +1066,7 @@ buffer_t *icmpv6_up(buffer_t *buf) case ICMPV6_TYPE_INFO_ECHO_REPLY: ipv6_neighbour_reachability_confirmation(buf->src_sa.address, buf->interface->id); - /* no break */ + /* fall through */ case ICMPV6_TYPE_ERROR_DESTINATION_UNREACH: #ifdef HAVE_RPL_ROOT @@ -1499,79 +1571,6 @@ buffer_t *icmpv6_build_na(protocol_interface_info_entry_t *cur, bool solicited, return (buf); } -static buffer_t *icmpv6_na_handler(buffer_t *buf) -{ - protocol_interface_info_entry_t *cur; - uint8_t *dptr = buffer_data_pointer(buf); - uint8_t flags; - const uint8_t *target; - const uint8_t *tllao; - if_address_entry_t *addr_entry; - ipv6_neighbour_t *neighbour_entry; - - //"Parse NA at IPv6\n"); - - if (buf->options.code != 0 || buf->options.hop_limit != 255) { - goto drop; - } - - if (!icmpv6_options_well_formed_in_buffer(buf, 20)) { - goto drop; - } - - // Skip the 4 reserved bytes - flags = *dptr; - dptr += 4; - - // Note the target IPv6 address - target = dptr; - - if (addr_is_ipv6_multicast(target)) { - goto drop; - } - - /* Solicited flag must be clear if sent to a multicast address */ - if (addr_is_ipv6_multicast(buf->dst_sa.address) && (flags & NA_S)) { - goto drop; - } - - cur = buf->interface; - - /* RFC 4862 5.4.4 DAD checks */ - addr_entry = addr_get_entry(cur, target); - if (addr_entry) { - if (addr_entry->tentative) { - tr_debug("Received NA for our tentative address"); - addr_duplicate_detected(cur, target); - } else { - tr_debug("NA received for our own address: %s", trace_ipv6(target)); - } - goto drop; - } - - if (cur->ipv6_neighbour_cache.recv_na_aro) { - const uint8_t *aro = icmpv6_find_option_in_buffer(buf, 20, ICMPV6_OPT_ADDR_REGISTRATION, 2); - if (aro) { - icmpv6_na_aro_handler(cur, aro, buf->dst_sa.address); - } - } - - /* No need to create a neighbour cache entry if one doesn't already exist */ - neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, target); - if (!neighbour_entry) { - goto drop; - } - - tllao = icmpv6_find_option_in_buffer(buf, 20, ICMPV6_OPT_TGT_LL_ADDR, 0); - if (!tllao || !cur->if_llao_parse(cur, tllao, &buf->dst_sa)) { - buf->dst_sa.addr_type = ADDR_NONE; - } - - ipv6_neighbour_update_from_na(&cur->ipv6_neighbour_cache, neighbour_entry, flags, buf->dst_sa.addr_type, buf->dst_sa.address); - -drop: - return buffer_free(buf); -} #endif // HAVE_IPV6_ND #ifdef HAVE_IPV6_ND diff --git a/source/Common_Protocols/tcp.c b/source/Common_Protocols/tcp.c index d492f563004a..5fb61554edef 100644 --- a/source/Common_Protocols/tcp.c +++ b/source/Common_Protocols/tcp.c @@ -559,7 +559,7 @@ tcp_error tcp_session_abort(tcp_session_t *tcp_session) case TCP_STATE_FIN_WAIT_2: case TCP_STATE_CLOSE_WAIT: tcp_session_send_reset_to_abort_connection(tcp_session); - /* no break */ + /* fall through */ case TCP_STATE_LISTEN: case TCP_STATE_SYN_SENT: tcp_session_delete_with_error(tcp_session, SOCKET_CONNECTION_RESET); diff --git a/source/Core/include/ns_buffer.h b/source/Core/include/ns_buffer.h index 5e4681bbeb91..60e5f22bff46 100644 --- a/source/Core/include/ns_buffer.h +++ b/source/Core/include/ns_buffer.h @@ -340,12 +340,20 @@ struct socket *buffer_socket_set(buffer_t *buf, struct socket *socket); /** Removes z amount of bytes from the begining of buffer * uint8_t *buffer_data_strip_header(buffer_t *x, uint16_t z) * */ -#define buffer_data_strip_header(x,z) ((x)->buf_ptr += (z), buffer_data_pointer_after_adjustment(x)) +static inline uint8_t *buffer_data_strip_header(buffer_t *x, uint16_t z) +{ + x->buf_ptr += z; + return buffer_data_pointer_after_adjustment(x); +} /** Adds z amount of bytes to the begining of buffer check if this is allowed using buffer_headroom method. * uint8_t *buffer_data_reserve_header(buffer_t *x, uint16_t z) * */ -#define buffer_data_reserve_header(x,z) ((x)->buf_ptr -= (z), buffer_data_pointer_after_adjustment(x)) +static inline uint8_t *buffer_data_reserve_header(buffer_t *x, uint16_t z) +{ + x->buf_ptr -= z; + return buffer_data_pointer_after_adjustment(x); +} /** append 1 byte to data*/ #define buffer_push_uint8(x, z) do {\ diff --git a/source/MAC/IEEE802_15_4/mac_header_helper_functions.c b/source/MAC/IEEE802_15_4/mac_header_helper_functions.c index 1a23d00b38bb..e5ed44e63e52 100644 --- a/source/MAC/IEEE802_15_4/mac_header_helper_functions.c +++ b/source/MAC/IEEE802_15_4/mac_header_helper_functions.c @@ -58,8 +58,10 @@ uint8_t mac_header_security_aux_header_length(uint8_t security_level, uint8_t ke switch (keyIdmode) { case MAC_KEY_ID_MODE_SRC8_IDX: header_length += 4; //64-bit key source first part + /* fall through */ case MAC_KEY_ID_MODE_SRC4_IDX: header_length += 4; //32-bit key source inline + /* fall through */ case MAC_KEY_ID_MODE_IDX: header_length += 1; break; @@ -128,8 +130,10 @@ void mac_header_security_parameter_set(mac_aux_security_header_t *header, const case MAC_KEY_ID_MODE_SRC8_IDX: keysource_len += 4; //64-bit key source first part + /* fall through */ case MAC_KEY_ID_MODE_SRC4_IDX: keysource_len += 4; //32-bit key source inline + /* fall through */ case MAC_KEY_ID_MODE_IDX: //Security header + 32-bit security counter + Key index header->KeyIndex = frame_setup->KeyIndex; @@ -198,10 +202,12 @@ void mac_header_security_components_read(mac_pre_parsed_frame_t *buffer, mlme_se break; case MAC_KEY_ID_MODE_SRC8_IDX: key_source_len += 4; + /* fall through */ case MAC_KEY_ID_MODE_SRC4_IDX: key_source_len += 4; memcpy(security_params->Keysource, ptr, key_source_len); ptr += key_source_len; + /* fall through */ case MAC_KEY_ID_MODE_IDX: security_params->KeyIndex = *ptr; break; diff --git a/source/MPL/mpl.c b/source/MPL/mpl.c index b72600da69f2..9ad06d49d3be 100644 --- a/source/MPL/mpl.c +++ b/source/MPL/mpl.c @@ -685,7 +685,8 @@ buffer_t *mpl_control_handler(buffer_t *buf, protocol_interface_info_entry_t *cu // by its colour not being flipped. // This is equivalent to having a "mentioned" flag, except we don't have // to have a separate "reset" loop. - bool new_colour = --domain->colour; // smart-alec binary flip + domain->colour = !domain->colour; + bool new_colour = domain->colour; while (ptr < end) { if (end - ptr < 2) { diff --git a/source/Service_Libs/fhss/fhss_beacon_tasklet.c b/source/Service_Libs/fhss/fhss_beacon_tasklet.c index 2ba416cf909e..7c54b6d2b0f7 100644 --- a/source/Service_Libs/fhss/fhss_beacon_tasklet.c +++ b/source/Service_Libs/fhss/fhss_beacon_tasklet.c @@ -68,7 +68,9 @@ static void fhss_beacon_tasklet_func(arm_event_s* event) if (!fhss_structure) { return; } +#ifdef FEA_TRACE_SUPPORT uint8_t parent_address[8]; +#endif fhss_clear_active_event(fhss_structure, event->event_type); // skip the init event as there will be a timer event after if (event->event_type == FHSS_TIMER_EVENT) { diff --git a/source/Service_Libs/nd_proxy/nd_proxy.c b/source/Service_Libs/nd_proxy/nd_proxy.c index 72a841343fd5..51b96b207946 100644 --- a/source/Service_Libs/nd_proxy/nd_proxy.c +++ b/source/Service_Libs/nd_proxy/nd_proxy.c @@ -434,11 +434,11 @@ bool nd_proxy_enabled_for_upstream(int8_t interface_id) return false; } -bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address, int8_t *downstream_id_ptr) +bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address) { nd_proxy_downstream_list_s *downstream; nd_proxy_connected_list_s *upstream = proxy_upstream_conection_get(upstream_id); - *downstream_id_ptr = -1; + if (!upstream) { return false; } @@ -447,7 +447,6 @@ bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address, in downstream = proxy_cache_downstream_interface_get(downstream_entry->id, &downstream_interface_list); if (downstream) { if (downstream->nd_proxy_validation(downstream_entry->id, address) == 0) { - *downstream_id_ptr = downstream_entry->id; return true; } } diff --git a/source/Service_Libs/nd_proxy/nd_proxy.h b/source/Service_Libs/nd_proxy/nd_proxy.h index 0059d6de9588..4ab48e23e5a2 100644 --- a/source/Service_Libs/nd_proxy/nd_proxy.h +++ b/source/Service_Libs/nd_proxy/nd_proxy.h @@ -125,7 +125,7 @@ bool nd_proxy_enabled_for_upstream(int8_t interface_id); *\return true Address validated behind downstream_id_ptr interface *\return false Unknown address for this proxy */ -bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address, int8_t *downstream_id_ptr); +bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address); /** * Downstream interface validate prefix route on Link status from connected Upstream interface * @@ -147,9 +147,9 @@ NS_DUMMY_DEFINITIONS_OK #define nd_proxy_upstream_interface_unregister(interface_id) -1 #define nd_proxy_enabled_for_downstream(interface_id) false #define nd_proxy_enabled_for_upstream(interface_id) false -#define nd_proxy_target_address_validation(upstream_id, address, downstream_id_ptr) false +#define nd_proxy_target_address_validation(upstream_id, address) false #define nd_proxy_upstream_route_onlink(downstream_id, address) false -#define nd_proxy_target_address_validation(upstream_id, address, downstream_id_ptr) false + #endif /* HAVE_ND_PROXY */ #endif /* ND_PROXY_H_ */ diff --git a/source/ipv6_stack/ipv6_routing_table.c b/source/ipv6_stack/ipv6_routing_table.c index 4c30a332099c..9e36a43a2a26 100644 --- a/source/ipv6_stack/ipv6_routing_table.c +++ b/source/ipv6_stack/ipv6_routing_table.c @@ -73,7 +73,6 @@ static void ipv6_destination_cache_forget_neighbour(const ipv6_neighbour_t *neig static void ipv6_destination_release(ipv6_destination_t *dest); static void ipv6_route_table_remove_router(int8_t interface_id, const uint8_t *addr, ipv6_route_src_t source); static uint16_t total_metric(const ipv6_route_t *route); -static void trace_debug_print(const char *fmt, ...); static uint8_t ipv6_route_table_count_source(int8_t interface_id, ipv6_route_src_t source); static void ipv6_route_table_remove_last_one_from_source(int8_t interface_id, ipv6_route_src_t source); static uint8_t ipv6_route_table_get_max_entries(int8_t interface_id, ipv6_route_src_t source); @@ -758,7 +757,7 @@ void ipv6_neighbour_cache_fast_timer(ipv6_neighbour_cache_t *cache, uint16_t tic ipv6_neighbour_set_state(cache, cur, IP_NEIGHBOUR_UNREACHABLE); } } - /* no break */ + /* fall through */ case IP_NEIGHBOUR_UNREACHABLE: if (cur->retrans_count < 0xFF) { cur->retrans_count++; diff --git a/test/nanostack/unittest/stub/nd_proxy_stub.c b/test/nanostack/unittest/stub/nd_proxy_stub.c index fa117fed2baf..89901f16369b 100644 --- a/test/nanostack/unittest/stub/nd_proxy_stub.c +++ b/test/nanostack/unittest/stub/nd_proxy_stub.c @@ -56,7 +56,7 @@ bool nd_proxy_enabled_for_upstream(int8_t interface_id) return false; } -bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address, int8_t *downstream_id_ptr) +bool nd_proxy_target_address_validation(int8_t upstream_id, uint8_t *address) { return false; }