From 9d79ca91e7d430028c574a1991f33c22453752c7 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Thu, 27 Sep 2018 14:01:12 +0300 Subject: [PATCH 1/2] FHSS: Added minimum synch interval --- source/Service_Libs/fhss/fhss_ws.c | 5 +++++ source/Service_Libs/fhss/fhss_ws.h | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index 66b17c20b6e..0e5174065ad 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -91,6 +91,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati fhss_struct->number_of_channels = channel_count; fhss_struct->own_hop = 0xff; fhss_struct->rx_channel = fhss_configuration->unicast_fixed_channel; + fhss_struct->ws->min_synch_interval = DEFAULT_MIN_SYNCH_INTERVAL; fhss_set_txrx_slot_length(fhss_struct); ns_list_init(&fhss_struct->fhss_failed_tx_list); return fhss_struct; @@ -666,6 +667,10 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], if (!bc_timing_info->broadcast_interval || !bc_timing_info->broadcast_dwell_interval) { return -1; } + if (((uint32_t)fhss_structure->ws->min_synch_interval*1000000) > (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - fhss_structure->ws->synchronization_time)) { + return 0; + } + fhss_structure->ws->synchronization_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api); platform_enter_critical(); fhss_stop_timer(fhss_structure, fhss_broadcast_handler); uint32_t time_from_reception_ms = (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - bc_timing_info->bt_rx_timestamp)/1000; diff --git a/source/Service_Libs/fhss/fhss_ws.h b/source/Service_Libs/fhss/fhss_ws.h index ff8f30de11e..6b1c59ee873 100644 --- a/source/Service_Libs/fhss/fhss_ws.h +++ b/source/Service_Libs/fhss/fhss_ws.h @@ -23,6 +23,8 @@ #define WS_NUMBER_OF_CHANNEL_RETRIES 4 //TX/RX slot length in milliseconds #define WS_MAX_TXRX_SLOT_LEN_MS 100 +// Default minimum broadcast synchronization interval in seconds +#define DEFAULT_MIN_SYNCH_INTERVAL 60 typedef struct fhss_ws fhss_ws_t; struct fhss_ws @@ -30,7 +32,9 @@ struct fhss_ws uint8_t bc_channel; uint16_t uc_slot; uint16_t bc_slot; + uint16_t min_synch_interval; uint32_t txrx_slot_length_ms; + uint32_t synchronization_time; bool unicast_timer_running; bool is_on_bc_channel; struct fhss_ws_configuration fhss_configuration; From 33afc9c348e6bed402bad8c4052d359de3131f62 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Thu, 27 Sep 2018 15:14:46 +0300 Subject: [PATCH 2/2] FHSS: Added force synch boolean in parent set --- nanostack/fhss_ws_extension.h | 3 ++- source/6LoWPAN/ws/ws_bootstrap.c | 2 +- source/6LoWPAN/ws/ws_llc_data_service.c | 4 +--- source/Service_Libs/fhss/fhss_configuration_interface.c | 4 ++-- source/Service_Libs/fhss/fhss_ws.c | 4 ++-- source/Service_Libs/fhss/fhss_ws.h | 2 +- source/Service_Libs/fhss/fhss_ws_empty_functions.c | 2 +- .../unittest/service_libs/fhss_config/test_fhss_config.c | 4 ++-- test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c | 4 ++-- test/nanostack/unittest/stub/fhss_config_stub.c | 2 +- test/nanostack/unittest/stub/fhss_ws_stub.c | 2 +- 11 files changed, 16 insertions(+), 17 deletions(-) diff --git a/nanostack/fhss_ws_extension.h b/nanostack/fhss_ws_extension.h index 3798d3bb191..44d86d1f6d9 100644 --- a/nanostack/fhss_ws_extension.h +++ b/nanostack/fhss_ws_extension.h @@ -80,9 +80,10 @@ typedef fhss_ws_neighbor_timing_info_t *fhss_get_neighbor_info(const fhss_api_t * @param fhss_api FHSS instance. * @param eui64 EUI-64 address of parent. * @param bc_timing_info Pointer to parent broadcast timing/hopping schedule info. + * @param force_synch If false, synchronization is done only if minimum (internal) synchronization interval is exceed. * @return 0 on success, -1 on fail. */ -extern int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info); +extern int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch); /** * @brief Remove parent which was set by ns_fhss_ws_set_parent function. diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index 6ac2ec6436c..c19ce516778 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -497,7 +497,7 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry ns_fhss_ws_configuration_set(cur->ws_info->fhss_api, &fhss_configuration); // We have broadcast schedule set up set the broadcast parent schedule - ns_fhss_ws_set_parent(cur->ws_info->fhss_api, neighbor_info->neighbor->mac64, &neighbor_info->ws_neighbor->fhss_data.bc_timing_info); + ns_fhss_ws_set_parent(cur->ws_info->fhss_api, neighbor_info->neighbor->mac64, &neighbor_info->ws_neighbor->fhss_data.bc_timing_info, true); // Update LLC to follow updated fhss settings ws_bootstrap_llc_hopping_update(cur,&fhss_configuration); diff --git a/source/6LoWPAN/ws/ws_llc_data_service.c b/source/6LoWPAN/ws/ws_llc_data_service.c index 1d274b85c5c..3f8e9e3a075 100644 --- a/source/6LoWPAN/ws/ws_llc_data_service.c +++ b/source/6LoWPAN/ws/ws_llc_data_service.c @@ -520,8 +520,6 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t ws_neighbor_class_neighbor_unicast_time_info_update(neighbor_info.ws_neighbor, &ws_utt, data->timestamp); if (us_ie_inline) { ws_neighbor_class_neighbor_unicast_schedule_set(neighbor_info.ws_neighbor, &us_ie); - - } //Update BT if it is part of message ws_bt_ie_t ws_bt; @@ -529,7 +527,7 @@ static void ws_llc_mac_indication_cb(const mac_api_t* api, const mcps_data_ind_t ws_neighbor_class_neighbor_broadcast_time_info_update(neighbor_info.ws_neighbor, &ws_bt, data->timestamp); if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) { // We have broadcast schedule set up set the broadcast parent schedule - ns_fhss_ws_set_parent(interface->ws_info->fhss_api, neighbor_info.neighbor->mac64, &neighbor_info.ws_neighbor->fhss_data.bc_timing_info); + ns_fhss_ws_set_parent(interface->ws_info->fhss_api, neighbor_info.neighbor->mac64, &neighbor_info.ws_neighbor->fhss_data.bc_timing_info, false); } } diff --git a/source/Service_Libs/fhss/fhss_configuration_interface.c b/source/Service_Libs/fhss/fhss_configuration_interface.c index 0c7567e5169..c1acfc38ac3 100644 --- a/source/Service_Libs/fhss/fhss_configuration_interface.c +++ b/source/Service_Libs/fhss/fhss_configuration_interface.c @@ -62,13 +62,13 @@ fhss_api_t *ns_fhss_ws_create(const fhss_ws_configuration_t *fhss_configuration, return this; } -int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info) +int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch) { fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api); if (!fhss_structure || !eui64 || !bc_timing_info) { return -1; } - return fhss_ws_set_parent(fhss_structure, eui64, bc_timing_info); + return fhss_ws_set_parent(fhss_structure, eui64, bc_timing_info, force_synch); } int ns_fhss_ws_remove_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8]) diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index 0e5174065ad..5fc04e3f98e 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -658,7 +658,7 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure) return 0; } -int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info) +int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch) { (void) eui64; if (!fhss_structure->ws) { @@ -667,7 +667,7 @@ int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], if (!bc_timing_info->broadcast_interval || !bc_timing_info->broadcast_dwell_interval) { return -1; } - if (((uint32_t)fhss_structure->ws->min_synch_interval*1000000) > (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - fhss_structure->ws->synchronization_time)) { + if ((((uint32_t)fhss_structure->ws->min_synch_interval*1000000) > (fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api) - fhss_structure->ws->synchronization_time)) && !force_synch) { return 0; } fhss_structure->ws->synchronization_time = fhss_structure->callbacks.read_timestamp(fhss_structure->fhss_api); diff --git a/source/Service_Libs/fhss/fhss_ws.h b/source/Service_Libs/fhss/fhss_ws.h index 6b1c59ee873..f09fb4b2461 100644 --- a/source/Service_Libs/fhss/fhss_ws.h +++ b/source/Service_Libs/fhss/fhss_ws.h @@ -44,7 +44,7 @@ struct fhss_ws fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configuration_t *fhss_configuration, const fhss_timer_t *fhss_timer); int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure); -int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info); +int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch); int fhss_ws_remove_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8]); int fhss_ws_configuration_set(fhss_structure_t *fhss_structure, const fhss_ws_configuration_t *fhss_configuration); int fhss_ws_set_hop_count(fhss_structure_t *fhss_structure, const uint8_t hop_count); diff --git a/source/Service_Libs/fhss/fhss_ws_empty_functions.c b/source/Service_Libs/fhss/fhss_ws_empty_functions.c index df6bc4813cf..07597662f93 100644 --- a/source/Service_Libs/fhss/fhss_ws_empty_functions.c +++ b/source/Service_Libs/fhss/fhss_ws_empty_functions.c @@ -46,7 +46,7 @@ int fhss_ws_set_callbacks(fhss_structure_t *fhss_structure) return -1; } -int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info) +int fhss_ws_set_parent(fhss_structure_t *fhss_structure, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch) { (void) fhss_structure; (void) eui64; diff --git a/test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c b/test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c index a0747f8bf05..e9400633cd2 100644 --- a/test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c +++ b/test/nanostack/unittest/service_libs/fhss_config/test_fhss_config.c @@ -127,12 +127,12 @@ bool test_ns_fhss_ws_set_parent() broadcast_timing_info_t bc_timing_info; // Test without api fhss_common_stub.bool_value = false; - if (-1 != ns_fhss_ws_set_parent(NULL, dest_address, &bc_timing_info)) { + if (-1 != ns_fhss_ws_set_parent(NULL, dest_address, &bc_timing_info, false)) { return false; } // Test success fhss_common_stub.bool_value = true; - if (0 != ns_fhss_ws_set_parent(&api, dest_address, &bc_timing_info)) { + if (0 != ns_fhss_ws_set_parent(&api, dest_address, &bc_timing_info, false)) { return false; } return true; diff --git a/test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c b/test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c index bc8158391d3..2e0264d336e 100644 --- a/test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c +++ b/test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c @@ -624,7 +624,7 @@ bool test_fhss_ws_set_parent() // Test without WS enabled FHSS fhss_structure_t fake_fhss_structure; memset(&fake_fhss_structure, 0, sizeof(fhss_structure_t)); - if (-1 != fhss_ws_set_parent(&fake_fhss_structure, dest_address, &bc_timing_info)) { + if (-1 != fhss_ws_set_parent(&fake_fhss_structure, dest_address, &bc_timing_info, true)) { return false; } @@ -637,7 +637,7 @@ bool test_fhss_ws_set_parent() bc_timing_info.broadcast_schedule_id = 1; bc_timing_info.broadcast_slot = 10; bc_timing_info.bt_rx_timestamp = 100000; - if (0 != fhss_ws_set_parent(&fhss_common_stub.fhss_struct, dest_address, &bc_timing_info) + if (0 != fhss_ws_set_parent(&fhss_common_stub.fhss_struct, dest_address, &bc_timing_info, true) || (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_channel_function != WS_TR51CF) || (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_dwell_interval != 250) || (fhss_common_stub.fhss_struct.ws->parent_bc_info->broadcast_interval != 1000) diff --git a/test/nanostack/unittest/stub/fhss_config_stub.c b/test/nanostack/unittest/stub/fhss_config_stub.c index 1607e9cfaea..bbab7c68c22 100644 --- a/test/nanostack/unittest/stub/fhss_config_stub.c +++ b/test/nanostack/unittest/stub/fhss_config_stub.c @@ -91,7 +91,7 @@ fhss_api_t *ns_fhss_create(const fhss_configuration_t *fhss_configuration, const return &fhss_config_stub.fhss_api_ptr; } -int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info) +int ns_fhss_ws_set_parent(const fhss_api_t *fhss_api, const uint8_t eui64[8], const broadcast_timing_info_t *bc_timing_info, const bool force_synch) { return 0; } diff --git a/test/nanostack/unittest/stub/fhss_ws_stub.c b/test/nanostack/unittest/stub/fhss_ws_stub.c index 74d61921ea5..0c84650885e 100644 --- a/test/nanostack/unittest/stub/fhss_ws_stub.c +++ b/test/nanostack/unittest/stub/fhss_ws_stub.c @@ -39,7 +39,7 @@ fhss_structure_t *fhss_ws_enable(fhss_api_t *fhss_api, const fhss_ws_configurati return &fhss_ws_stub.fhss_struct; } -int fhss_ws_set_parent(fhss_structure_t *fhss_structure, uint8_t eui64[8], broadcast_timing_info_t *bc_timing_info) +int fhss_ws_set_parent(fhss_structure_t *fhss_structure, uint8_t eui64[8], broadcast_timing_info_t *bc_timing_info, const bool force_synch) { return 0; }