From 69c14838e8bf34188694b00496379bfdda8211c0 Mon Sep 17 00:00:00 2001 From: Jarkko Paso Date: Mon, 9 Apr 2018 11:35:49 +0300 Subject: [PATCH] FHSS: Added excluded channels in neighbor table --- nanostack/fhss_ws_extension.h | 1 + source/Service_Libs/fhss/channel_functions.c | 28 +++++++++---------- source/Service_Libs/fhss/channel_functions.h | 6 ++-- source/Service_Libs/fhss/fhss_ws.c | 6 ++-- .../test_channel_functions.c | 23 ++++++++------- 5 files changed, 30 insertions(+), 34 deletions(-) diff --git a/nanostack/fhss_ws_extension.h b/nanostack/fhss_ws_extension.h index 39dbe302aab..8ebd4151a10 100644 --- a/nanostack/fhss_ws_extension.h +++ b/nanostack/fhss_ws_extension.h @@ -62,6 +62,7 @@ typedef struct fhss_ws_neighbor_timing_info { uint8_t timing_accuracy; /**< Neighbor timing accuracy */ unicast_timing_info_t uc_timing_info; /**< Neighbor unicast timing info */ broadcast_timing_info_t bc_timing_info; /**< Neighbor broadcast timing info */ + uint32_t *excluded_channels; /**< Neighbor excluded channels (bit mask) */ } fhss_ws_neighbor_timing_info_t; /** diff --git a/source/Service_Libs/fhss/channel_functions.c b/source/Service_Libs/fhss/channel_functions.c index 7c8d06b9d1d..fee8e2697c6 100644 --- a/source/Service_Libs/fhss/channel_functions.c +++ b/source/Service_Libs/fhss/channel_functions.c @@ -109,17 +109,16 @@ static void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step *step_size = (mac[7] % (channel_table_length - 1)) + 1; } -static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, uint16_t number_of_excluded_channels) +static uint8_t tr51_find_excluded(int32_t channel, uint32_t *excluded_channels) { - uint8_t count = 0; if (excluded_channels != NULL) { - for (count = 0; count < number_of_excluded_channels; count++) { - if (channel == excluded_channels[count]) { - return 1; - } + uint8_t index = channel / 32; + channel %= 32; + if (excluded_channels[index] & ((uint32_t)1 << channel)) { + return true; } } - return 0; + return false; } /** @@ -129,18 +128,17 @@ static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, * @param first_element Start generated by CFD function. * @param step_size Step size generated by CFD function. * @param output_table Output hopping sequence table. - * @param excluded_channels List of not used channels. - * @param number_of_excluded_channels Number of not used channels. + * @param excluded_channels Bit mask where excluded channels are set to 1. * @return Number of channels in sequence. */ -static uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channel_table_length, uint8_t first_element, uint8_t step_size, int32_t *output_table, uint16_t *excluded_channels, uint16_t number_of_excluded_channels) +static uint16_t tr51_calculate_hopping_sequence(int32_t *channel_table, uint16_t channel_table_length, uint8_t first_element, uint8_t step_size, int32_t *output_table, uint32_t *excluded_channels) { uint16_t cntr = channel_table_length; uint8_t index = first_element; uint8_t slot = 0; while (cntr--) { if (channel_table[index] != -1) { - if (!tr51_find_excluded(channel_table[index], excluded_channels, number_of_excluded_channels)) { + if (tr51_find_excluded(channel_table[index], excluded_channels) == false) { output_table[slot] = channel_table[index]; slot++; } @@ -196,7 +194,7 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n return channel_number; } -int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels, uint16_t *excluded_channels, uint16_t number_of_excluded_channels) +int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels, uint32_t *excluded_channels) { uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels); int32_t channel_table[nearest_prime]; @@ -207,11 +205,11 @@ int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t nu tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime); // Not sure yet which one is the correct second parameter // tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0); - tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels, number_of_excluded_channels); + tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels); return output_table[slot_number]; } -int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels, uint16_t *excluded_channels, uint16_t number_of_excluded_channels) +int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels, uint32_t *excluded_channels) { uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels); int32_t channel_table[nearest_prime]; @@ -223,6 +221,6 @@ int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t nu tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime); // Not sure yet which one is the correct second parameter // tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0); - tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels, number_of_excluded_channels); + tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels); return output_table[slot_number]; } diff --git a/source/Service_Libs/fhss/channel_functions.h b/source/Service_Libs/fhss/channel_functions.h index f4011a1c5b5..70eb8e5fd84 100644 --- a/source/Service_Libs/fhss/channel_functions.h +++ b/source/Service_Libs/fhss/channel_functions.h @@ -23,10 +23,9 @@ * @param mac MAC address of the node for which the index is calculated. * @param number_of_channels Number of channels. * @param excluded_channels Excluded channels. - * @param number_of_excluded_channels Number of excluded channels. * @return Channel index. */ -int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels, uint16_t *excluded_channels, uint16_t number_of_excluded_channels); +int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels, uint32_t *excluded_channels); /** * @brief Compute the broadcast schedule channel index using tr51 channel function. @@ -34,10 +33,9 @@ int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t nu * @param bsi Broadcast schedule identifier of the node for which the index is calculated. * @param number_of_channels Number of channels. * @param excluded_channels Excluded channels. - * @param number_of_excluded_channels Number of excluded channels. * @return Channel index. */ -int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels, uint16_t *excluded_channels, uint16_t number_of_excluded_channels); +int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels, uint32_t *excluded_channels); /** * @brief Compute the unicast schedule channel index using direct hash channel function. diff --git a/source/Service_Libs/fhss/fhss_ws.c b/source/Service_Libs/fhss/fhss_ws.c index c7c6548f91e..4bb79f1777e 100644 --- a/source/Service_Libs/fhss/fhss_ws.c +++ b/source/Service_Libs/fhss/fhss_ws.c @@ -80,7 +80,7 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure) int32_t next_channel = fhss_structure->rx_channel; if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) { - next_channel = tr51_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels, NULL, 0); + next_channel = tr51_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels, NULL); if (++fhss_structure->ws->bc_slot == fhss_structure->number_of_channels) { fhss_structure->ws->bc_slot = 0; } @@ -205,7 +205,7 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure) if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) { return; } else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) { - next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels, NULL, 0); + next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels, NULL); if (++fhss_structure->ws->uc_slot == fhss_structure->number_of_channels) { fhss_structure->ws->uc_slot = 0; } @@ -252,7 +252,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a uint16_t destination_slot = fhss_ws_calculate_destination_slot(neighbor_timing_info, tx_time); int32_t tx_channel; if (neighbor_timing_info->uc_timing_info.unicast_channel_function == WS_TR51CF) { - tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, neighbor_timing_info->uc_timing_info.unicast_number_of_channels, NULL, 0); + tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, neighbor_timing_info->uc_timing_info.unicast_number_of_channels, NULL); } else if(neighbor_timing_info->uc_timing_info.unicast_channel_function == WS_DH1CF) { tx_channel = dh1cf_get_uc_channel_index(destination_slot, destination_address, neighbor_timing_info->uc_timing_info.unicast_number_of_channels); } else if (neighbor_timing_info->uc_timing_info.unicast_channel_function == WS_VENDOR_DEF_CF) { diff --git a/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c b/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c index a4002d822fb..843fafc085a 100644 --- a/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c +++ b/test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c @@ -71,12 +71,12 @@ const int32_t test_HopSequenceTable3[129] = { 124, 114, 65, 104, 33, 20, 118, 102, 10, 91, 76, 117, 61, 81, 13, 46 }; -static bool channel_on_the_list(uint16_t *list, uint16_t list_size, int32_t channel) +static bool channel_on_the_list(uint32_t *list, int32_t channel) { - for (int i=0; i