Skip to content

Commit

Permalink
Merge pull request ARMmbed#1646 from ARMmbed/IOTTHD-2404
Browse files Browse the repository at this point in the history
FHSS: Added excluded channels in neighbor table
  • Loading branch information
Jarkko Paso authored Apr 10, 2018
2 parents baaec35 + 69c1483 commit b7428e0
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 34 deletions.
1 change: 1 addition & 0 deletions nanostack/fhss_ws_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
28 changes: 13 additions & 15 deletions source/Service_Libs/fhss/channel_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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++;
}
Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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];
}
6 changes: 2 additions & 4 deletions source/Service_Libs/fhss/channel_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,19 @@
* @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.
* @param slot_number Current slot number.
* @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.
Expand Down
6 changes: 3 additions & 3 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,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;
}
Expand Down Expand Up @@ -222,7 +222,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;
}
Expand Down Expand Up @@ -269,7 +269,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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<list_size; i++) {
if (list[i] == channel) {
return true;
}
uint8_t index = channel/32;
channel %= 32;
if (list[index] & (1 << channel)) {
return true;
}
return false;
}
Expand All @@ -89,7 +89,7 @@ bool test_tr51_get_uc_channel_index()
int32_t test_table[number_of_channels];
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
for (i=0; i<number_of_channels; i++) {
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, NULL, 0);
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, NULL);
// Not sure yet which one is correct since there might be bug in spec
// if (channel != test_HopSequenceTable[i]) {
if (channel != test_HopSequenceTable2[i]) {
Expand All @@ -111,24 +111,23 @@ bool test_tr51_get_uc_channel_index()
}
// Test with excluded channels
int l=0;
uint16_t excluded_channels[10] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90};
uint32_t excluded_channels[8] = {0x40100401, 0x10040100, 0x04010040, 0, 0, 0, 0, 0};
uint16_t number_of_excluded_channels = 10;
for (i=0; i<number_of_channels-number_of_excluded_channels; i++) {
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, excluded_channels, number_of_excluded_channels);
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, excluded_channels);
// Shouldn't find channel from excluded channels
if (channel_on_the_list(excluded_channels, number_of_excluded_channels, channel)) {
if (channel_on_the_list(excluded_channels, channel)) {
return false;
}
// Test against channel sequence
while (channel_on_the_list(excluded_channels, number_of_excluded_channels, test_HopSequenceTable2[l])) {
while (channel_on_the_list(excluded_channels, test_HopSequenceTable2[l])) {
l++;
}
if (channel != test_HopSequenceTable2[l]) {
return false;
}
l++;
}

return true;
}

Expand All @@ -139,7 +138,7 @@ bool test_tr51_get_bc_channel_index()
uint16_t bsi = 100;
int32_t test_table[number_of_channels];
for (int i=0; i<number_of_channels; i++) {
test_table[i] = channel = tr51_get_bc_channel_index(i, bsi, number_of_channels, NULL, 0);
test_table[i] = channel = tr51_get_bc_channel_index(i, bsi, number_of_channels, NULL);
if (channel != test_HopSequenceTable3[i]) {
return false;
}
Expand Down

0 comments on commit b7428e0

Please sign in to comment.