diff --git a/source/6LoWPAN/Thread/thread_bootstrap.c b/source/6LoWPAN/Thread/thread_bootstrap.c index d39f913af13..453b50be6fb 100644 --- a/source/6LoWPAN/Thread/thread_bootstrap.c +++ b/source/6LoWPAN/Thread/thread_bootstrap.c @@ -1190,6 +1190,31 @@ void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur) } } +void thread_reed_fed_neighbour_links_clean(struct protocol_interface_info_entry *cur) +{ + mac_neighbor_table_list_t *mac_table_list = &mac_neighbor_info(cur)->neighbour_list; + + if (thread_i_am_router(cur)) { + return; + } + + if (thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_END_DEVICE || + thread_info(cur)->thread_device_mode == THREAD_DEVICE_MODE_SLEEPY_END_DEVICE) { + return; + } + + if (!thread_info(cur)->thread_endnode_parent) { + return; + } + ns_list_foreach_safe(mac_neighbor_table_entry_t, cur_entry, mac_table_list) { + // do not remove parent entry + if (memcmp(cur_entry->mac64, thread_info(cur)->thread_endnode_parent->mac64, 8) != 0) { + tr_debug("Free short addr: %x", cur_entry->mac16); + mac_neighbor_table_neighbor_remove(mac_neighbor_info(cur), cur_entry); + } + } +} + void thread_clean_old_16_bit_address_based_addresses(protocol_interface_info_entry_t *cur) { uint8_t static_address[16]; diff --git a/source/6LoWPAN/Thread/thread_bootstrap.h b/source/6LoWPAN/Thread/thread_bootstrap.h index 212f1ca0449..7880ff1fece 100644 --- a/source/6LoWPAN/Thread/thread_bootstrap.h +++ b/source/6LoWPAN/Thread/thread_bootstrap.h @@ -106,6 +106,9 @@ void thread_general_mle_receive_cb(int8_t interface_id, mle_message_t *mle_msg, void thread_bootstrap_ready(struct protocol_interface_info_entry *cur); int thread_bootstrap_reset(struct protocol_interface_info_entry *cur); void thread_neighbor_list_clean(struct protocol_interface_info_entry *cur); + +/* Function to remove linked neighbours for REEDs and FEDs */ +void thread_reed_fed_neighbour_links_clean(struct protocol_interface_info_entry *cur); bool thread_bootstrap_request_network_data(struct protocol_interface_info_entry *cur, struct thread_leader_data_s *leaderData, uint16_t short_address); bool thread_check_is_this_my_parent(struct protocol_interface_info_entry *cur, struct mac_neighbor_table_entry *entry_temp); void thread_clean_old_16_bit_address_based_addresses(struct protocol_interface_info_entry *cur); diff --git a/source/6LoWPAN/Thread/thread_common.c b/source/6LoWPAN/Thread/thread_common.c index a82bfebb896..a02faa1891f 100644 --- a/source/6LoWPAN/Thread/thread_common.c +++ b/source/6LoWPAN/Thread/thread_common.c @@ -1983,6 +1983,9 @@ void thread_partition_data_purge(protocol_interface_info_entry_t *cur) /* Flush address cache */ ipv6_neighbour_cache_flush(&cur->ipv6_neighbour_cache); + /* Remove linked neighbours for REEDs and FEDs */ + thread_reed_fed_neighbour_links_clean(cur); + } bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData) diff --git a/source/6LoWPAN/Thread/thread_host_bootstrap.c b/source/6LoWPAN/Thread/thread_host_bootstrap.c index 50366616120..b7dcfdcd00a 100644 --- a/source/6LoWPAN/Thread/thread_host_bootstrap.c +++ b/source/6LoWPAN/Thread/thread_host_bootstrap.c @@ -121,11 +121,11 @@ static void thread_network_data_clean(protocol_interface_info_entry_t *cur) static void thread_merge_prepare(protocol_interface_info_entry_t *cur) { + thread_partition_data_purge(cur); thread_clean_old_16_bit_address_based_addresses(cur); mpl_clear_realm_scope_seeds(cur); ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_HOST, NULL); ipv6_route_table_remove_info(cur->id, ROUTE_THREAD_PROXIED_DUA_HOST, NULL); - thread_partition_data_purge(cur); thread_network_data_clean(cur); cur->nwk_mode = ARM_NWK_GP_IP_MODE; } diff --git a/test/nanostack/unittest/stub/thread_bootstrap_stub.c b/test/nanostack/unittest/stub/thread_bootstrap_stub.c index 83ed6ac760f..d5726755c5c 100644 --- a/test/nanostack/unittest/stub/thread_bootstrap_stub.c +++ b/test/nanostack/unittest/stub/thread_bootstrap_stub.c @@ -88,6 +88,9 @@ void thread_clean_old_16_bit_address_based_addresses(protocol_interface_info_ent { } +void thread_reed_fed_neighbour_links_clean(struct protocol_interface_info_entry *cur) +{ +} void thread_bootstrap_ready(protocol_interface_info_entry_t *cur) {