From d092f833a8b5a3e1c82ec25ee960024f8b889414 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Thu, 23 Apr 2020 10:22:56 +0300 Subject: [PATCH] Iotthd 3995 (#2347) * FHSS WS: Created test api for setting number of channel retries * FHSS WS: API to configure channel retries * Compiler warning if max frame retries is too low --- nanostack/fhss_config.h | 13 +++++++++++++ nanostack/fhss_test_api.h | 11 +++++++++++ source/6LoWPAN/ws/ws_bootstrap.c | 3 +++ source/6LoWPAN/ws/ws_common_defines.h | 20 ++++++++++++++++++++ source/Service_Libs/fhss/fhss_test_api.c | 15 +++++++++++++++ source/Service_Libs/fhss/fhss_ws.c | 8 +++++--- source/Service_Libs/fhss/fhss_ws.h | 4 ---- 7 files changed, 67 insertions(+), 7 deletions(-) diff --git a/nanostack/fhss_config.h b/nanostack/fhss_config.h index 9a286128acf..5c55965733f 100644 --- a/nanostack/fhss_config.h +++ b/nanostack/fhss_config.h @@ -88,6 +88,16 @@ typedef struct fhss_configuration { */ typedef int32_t fhss_vendor_defined_cf(const fhss_api_t *api, uint16_t slot, uint8_t eui64[8], uint16_t bsi, uint16_t number_of_channels); +/** + * \brief Struct fhss_config_parameters defines FHSS configuration parameters. + * + */ +typedef struct fhss_config_parameters { + /** Number of channel retries defines how many consecutive channels are used when retransmitting a frame after initial transmission channel. */ + uint8_t number_of_channel_retries; +} fhss_config_parameters_t; + + /** * \brief Struct fhss_ws_configuration defines configuration of WS FHSS. */ @@ -125,6 +135,9 @@ typedef struct fhss_ws_configuration { /** Vendor defined channel function. */ fhss_vendor_defined_cf *vendor_defined_cf; + /** Configuration parameters. */ + fhss_config_parameters_t config_parameters; + } fhss_ws_configuration_t; /** diff --git a/nanostack/fhss_test_api.h b/nanostack/fhss_test_api.h index 270c5a27a31..e6a93cc2c0b 100644 --- a/nanostack/fhss_test_api.h +++ b/nanostack/fhss_test_api.h @@ -39,6 +39,17 @@ extern "C" { */ int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packet_length); +/** + * \brief Set number of channel retries + * + * \param fhss_api FHSS instance. + * \param number_of_channel_retries Number of channel retries + * + * \return 0 Success + * \return -1 Failure + */ +int8_t fhss_set_number_of_channel_retries(const fhss_api_t *fhss_api, uint8_t number_of_channel_retries); + #ifdef __cplusplus } #endif diff --git a/source/6LoWPAN/ws/ws_bootstrap.c b/source/6LoWPAN/ws/ws_bootstrap.c index 62cb2a36c85..cc89944506f 100644 --- a/source/6LoWPAN/ws/ws_bootstrap.c +++ b/source/6LoWPAN/ws/ws_bootstrap.c @@ -510,6 +510,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur) fhss_configuration.ws_bc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_bc_channel_function; fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->cfg->fhss.fhss_bc_dwell_interval; fhss_configuration.fhss_broadcast_interval = cur->ws_info->cfg->fhss.fhss_bc_interval; + fhss_configuration.config_parameters.number_of_channel_retries = WS_NUMBER_OF_CHANNEL_RETRIES; fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr); if (!fhss_api) { @@ -1957,6 +1958,8 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode) set_req.value_size = sizeof(bool); cur->mac_api->mlme_req(cur->mac_api, MLME_SET, &set_req); + mac_helper_mac_mlme_max_retry_set(cur->id, WS_MAX_FRAME_RETRIES); + // Set the default parameters for MPL cur->mpl_proactive_forwarding = true; diff --git a/source/6LoWPAN/ws/ws_common_defines.h b/source/6LoWPAN/ws/ws_common_defines.h index d2797f8e803..b3bf4b6434d 100644 --- a/source/6LoWPAN/ws/ws_common_defines.h +++ b/source/6LoWPAN/ws/ws_common_defines.h @@ -295,6 +295,26 @@ typedef struct ws_bs_ie { */ #define WS_TACK_MAX_MS 5 + +/* WS requires at least 19 MAC retransmissions (total 1+19=20 attempts). Default 802.15.4 macMaxFrameRetries is 3 (total 1+3=4 attempts). + * At least 4 channel retries must be used: (Initial channel + WS_NUMBER_OF_CHANNEL_RETRIES) * MAC attempts = (1+4)*4=20 attempts + * + * Valid settings could be for example: + * WS_MAX_FRAME_RETRIES WS_NUMBER_OF_CHANNEL_RETRIES Total attempts + * 0 19 1+0*1+19=20 + * 1 9 1+1*1+9=20 + * 2 6 1+2*1+6=21 + * 3 4 1+3*1+4=20 + * + */ +#define WS_MAX_FRAME_RETRIES 3 +#define WS_NUMBER_OF_CHANNEL_RETRIES 4 + + +#if (1 + WS_MAX_FRAME_RETRIES) * (1 + WS_NUMBER_OF_CHANNEL_RETRIES) < 20 +#warning "MAX frame retries set too low" +#endif + /* * Config new version consistent filter period in 100ms periods */ diff --git a/source/Service_Libs/fhss/fhss_test_api.c b/source/Service_Libs/fhss/fhss_test_api.c index 7b1e696ea04..02e63af682c 100644 --- a/source/Service_Libs/fhss/fhss_test_api.c +++ b/source/Service_Libs/fhss/fhss_test_api.c @@ -44,3 +44,18 @@ int8_t fhss_set_optimal_packet_length(const fhss_api_t *fhss_api, uint16_t packe #endif return 0; } + +int8_t fhss_set_number_of_channel_retries(const fhss_api_t *fhss_api, uint8_t number_of_channel_retries) +{ + (void) fhss_api; + (void) number_of_channel_retries; +#ifdef HAVE_WS + fhss_structure_t *fhss_structure = fhss_get_object_with_api(fhss_api); + if (!fhss_structure || !fhss_structure->ws) { + return -1; + } + fhss_structure->ws->fhss_configuration.config_parameters.number_of_channel_retries = number_of_channel_retries; + tr_debug("Setting number of channel retries to: %u", number_of_channel_retries); +#endif + return 0; +} diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index 35b59d2a66d..80c3f90d149 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -750,16 +750,18 @@ static bool fhss_ws_data_tx_fail_callback(const fhss_api_t *api, uint8_t handle, if (fhss_structure->fhss_state == FHSS_UNSYNCHRONIZED) { return false; } - // Use channel retries only for data frames if (FHSS_DATA_FRAME != frame_type) { return false; } - + // Channel retries are disabled + if (!fhss_structure->ws->fhss_configuration.config_parameters.number_of_channel_retries) { + return false; + } fhss_failed_tx_t *fhss_failed_tx = fhss_failed_handle_find(fhss_structure, handle); if (fhss_failed_tx) { fhss_failed_tx->retries_done++; - if (fhss_failed_tx->retries_done >= WS_NUMBER_OF_CHANNEL_RETRIES) { + if (fhss_failed_tx->retries_done >= fhss_structure->ws->fhss_configuration.config_parameters.number_of_channel_retries) { // No more retries. Return false to stop retransmitting. fhss_failed_handle_remove(fhss_structure, handle); return false; diff --git a/source/Service_Libs/fhss/fhss_ws.h b/source/Service_Libs/fhss/fhss_ws.h index c3d31fa67ef..f4d27c1bff0 100644 --- a/source/Service_Libs/fhss/fhss_ws.h +++ b/source/Service_Libs/fhss/fhss_ws.h @@ -17,10 +17,6 @@ #ifndef FHSS_WS_H_ #define FHSS_WS_H_ -/* WS requires at least 19 MAC retransmissions (total 1+19=20 attempts). 802.15.4 macMaxFrameRetries is 3 (total 1+3=4 attempts). - * At least 4 channel retries must be used: (Initial channel + WS_NUMBER_OF_CHANNEL_RETRIES) * MAC attempts = (1+4)*4=20 attempts - */ -#define WS_NUMBER_OF_CHANNEL_RETRIES 4 // TX slot length is optimised to this packet length #define OPTIMAL_PACKET_LENGTH 500 // Default TX/RX slot length in milliseconds. Is used when datarate is not given by PHY.