From 5a37354e85c0651634dc9dd0a18ea08b16a5c920 Mon Sep 17 00:00:00 2001 From: Juha Heiskanen Date: Tue, 11 Sep 2018 11:36:01 +0300 Subject: [PATCH] Primary Parent Update Hook to Wi-sun for synch broadcast schedule. Change-Id: I804200fda6cf47beb0180cd37f2b97ffe8917d58 --- .../Bootstraps/Generic/protocol_6lowpan.c | 10 ++++++++-- source/6LoWPAN/ws/ws_bootstrap.c | 16 +++++++++++++--- source/6LoWPAN/ws/ws_bootstrap.h | 3 +++ .../Bootstraps/protocol_6lowpan/Makefile | 1 + test/nanostack/unittest/stub/ws_bootstrap_stub.c | 5 +++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c b/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c index c14b97c7abb8..7f2a60dfcc8e 100644 --- a/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c +++ b/source/6LoWPAN/Bootstraps/Generic/protocol_6lowpan.c @@ -74,6 +74,7 @@ #include "6LoWPAN/Fragmentation/cipv6_fragmenter.h" #include "Service_Libs/etx/etx.h" #include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h" +#include "6LoWPAN/ws/ws_bootstrap.h" #define TRACE_GROUP_LOWPAN "6lo" @@ -473,7 +474,6 @@ void protocol_6lowpan_neighbor_priority_update(protocol_interface_info_entry_t * } #ifdef HAVE_RPL -#ifndef NO_MLE uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t addr_type, const uint8_t *addr_ptr) { @@ -486,9 +486,12 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t mac_neighbor_table_entry_t * entry = mac_neighbor_table_address_discover(mac_neighbor_info(cur), addr_ptr + PAN_ID_LEN, addr_type); if (entry) { + + bool new_primary = false; etx_storage_t *etx_entry = etx_storage_entry_get(interface_id, entry->index); // If primary parent has changed clears priority from previous parent if (entry->link_role != PRIORITY_PARENT_NEIGHBOUR) { + new_primary = true; protocol_6lowpan_neighbor_priority_clear_all(interface_id, PRIORITY_1ST); } entry->link_role = PRIORITY_PARENT_NEIGHBOUR; @@ -501,6 +504,10 @@ uint16_t protocol_6lowpan_neighbor_priority_set(int8_t interface_id, addrtype_t if (etx_entry) { protocol_stats_update(STATS_ETX_1ST_PARENT, etx_entry->etx >> 4); } + + if (new_primary) { + ws_primary_parent_update(cur, entry); + } return 1; } else { return 0; @@ -557,7 +564,6 @@ void protocol_6lowpan_neighbor_priority_clear_all(int8_t interface_id, neighbor_ } } -#endif #endif #endif diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index 117ca735cf20..8cf66cc69c7d 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -342,9 +342,6 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry // Update LLC to follow updated fhss settings ws_bootstrap_llc_hopping_update(cur,&fhss_configuration); - // set neighbor as priority parent clear if there is others - protocol_6lowpan_neighbor_priority_clear_all(cur->id, PRIORITY_1ST); - neighbor_info->neighbor->link_role = PRIORITY_PARENT_NEIGHBOUR; } /* \return 0x0100 to 0xFFFF ETX value (8 bit fraction) @@ -765,6 +762,9 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,20); // enable frequency hopping for unicast channel and start listening first neighbour ws_bootstrap_primary_parent_set(cur, &neighbor_info); + // set neighbor as priority parent clear if there is others + protocol_6lowpan_neighbor_priority_clear_all(cur->id, PRIORITY_1ST); + neighbor_info.neighbor->link_role = PRIORITY_PARENT_NEIGHBOUR; } else if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) { // RPL priority parent configuration we must update FHSS data ws_bootstrap_primary_parent_set(cur, &neighbor_info); @@ -1858,4 +1858,14 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s } } +void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor) +{ + if (interface->ws_info) { + llc_neighbour_req_t neighbor_info; + neighbor_info.neighbor = neighbor; + neighbor_info.ws_neighbor = ws_neighbor_class_entry_get(&interface->ws_info->neighbor_storage, neighbor->index); + ws_bootstrap_primary_parent_set(interface, &neighbor_info); + } +} + #endif //HAVE_WS diff --git a/source/6LoWPAN/ws/ws_bootstrap.h b/source/6LoWPAN/ws/ws_bootstrap.h index c50135e1b645..9dc4301cc545 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.h +++ b/source/6LoWPAN/ws/ws_bootstrap.h @@ -54,11 +54,14 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s void ws_bootstrap_trickle_timer(protocol_interface_info_entry_t *cur, uint16_t ticks); +void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor); + #else #define ws_bootstrap_init(interface_id, bootstrap_mode) (-1) #define ws_bootstrap_state_machine(cur) #define ws_bootstrap_restart(cur) +#define ws_primary_parent_update(interface, neighbor) #endif //HAVE_WS diff --git a/test/nanostack/unittest/Bootstraps/protocol_6lowpan/Makefile b/test/nanostack/unittest/Bootstraps/protocol_6lowpan/Makefile index 94510b7e3544..d00636869276 100644 --- a/test/nanostack/unittest/Bootstraps/protocol_6lowpan/Makefile +++ b/test/nanostack/unittest/Bootstraps/protocol_6lowpan/Makefile @@ -41,6 +41,7 @@ TEST_SRC_FILES = \ ../../stub/adaptation_interface_stub.c \ ../../stub/security_lib_stub.c \ ../../stub/net_load_balance_stub.c \ + ../../stub/ws_bootstrap_stub.c \ ../../stub/etx_stub.c \ include ../../MakefileWorker.mk diff --git a/test/nanostack/unittest/stub/ws_bootstrap_stub.c b/test/nanostack/unittest/stub/ws_bootstrap_stub.c index 9798612d9334..bf009821e56e 100644 --- a/test/nanostack/unittest/stub/ws_bootstrap_stub.c +++ b/test/nanostack/unittest/stub/ws_bootstrap_stub.c @@ -51,3 +51,8 @@ void ws_bootstrap_configuration_trickle_reset(protocol_interface_info_entry_t *c { } + +void ws_primary_parent_update(protocol_interface_info_entry_t *interface, mac_neighbor_table_entry_t *neighbor) +{ + +}