Skip to content

Commit b7428e0

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1646 from ARMmbed/IOTTHD-2404
FHSS: Added excluded channels in neighbor table
2 parents baaec35 + 69c1483 commit b7428e0

File tree

5 files changed

+30
-34
lines changed

5 files changed

+30
-34
lines changed

nanostack/fhss_ws_extension.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ typedef struct fhss_ws_neighbor_timing_info {
6262
uint8_t timing_accuracy; /**< Neighbor timing accuracy */
6363
unicast_timing_info_t uc_timing_info; /**< Neighbor unicast timing info */
6464
broadcast_timing_info_t bc_timing_info; /**< Neighbor broadcast timing info */
65+
uint32_t *excluded_channels; /**< Neighbor excluded channels (bit mask) */
6566
} fhss_ws_neighbor_timing_info_t;
6667

6768
/**

source/Service_Libs/fhss/channel_functions.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,16 @@ static void tr51_compute_cfd(uint8_t *mac, uint8_t *first_element, uint8_t *step
109109
*step_size = (mac[7] % (channel_table_length - 1)) + 1;
110110
}
111111

112-
static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels, uint16_t number_of_excluded_channels)
112+
static uint8_t tr51_find_excluded(int32_t channel, uint32_t *excluded_channels)
113113
{
114-
uint8_t count = 0;
115114
if (excluded_channels != NULL) {
116-
for (count = 0; count < number_of_excluded_channels; count++) {
117-
if (channel == excluded_channels[count]) {
118-
return 1;
119-
}
115+
uint8_t index = channel / 32;
116+
channel %= 32;
117+
if (excluded_channels[index] & ((uint32_t)1 << channel)) {
118+
return true;
120119
}
121120
}
122-
return 0;
121+
return false;
123122
}
124123

125124
/**
@@ -129,18 +128,17 @@ static uint8_t tr51_find_excluded(int32_t channel, uint16_t *excluded_channels,
129128
* @param first_element Start generated by CFD function.
130129
* @param step_size Step size generated by CFD function.
131130
* @param output_table Output hopping sequence table.
132-
* @param excluded_channels List of not used channels.
133-
* @param number_of_excluded_channels Number of not used channels.
131+
* @param excluded_channels Bit mask where excluded channels are set to 1.
134132
* @return Number of channels in sequence.
135133
*/
136-
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)
134+
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)
137135
{
138136
uint16_t cntr = channel_table_length;
139137
uint8_t index = first_element;
140138
uint8_t slot = 0;
141139
while (cntr--) {
142140
if (channel_table[index] != -1) {
143-
if (!tr51_find_excluded(channel_table[index], excluded_channels, number_of_excluded_channels)) {
141+
if (tr51_find_excluded(channel_table[index], excluded_channels) == false) {
144142
output_table[slot] = channel_table[index];
145143
slot++;
146144
}
@@ -196,7 +194,7 @@ int32_t dh1cf_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t n
196194
return channel_number;
197195
}
198196

199-
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)
197+
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels, uint32_t *excluded_channels)
200198
{
201199
uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels);
202200
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
207205
tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime);
208206
// Not sure yet which one is the correct second parameter
209207
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0);
210-
tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels, number_of_excluded_channels);
208+
tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels);
211209
return output_table[slot_number];
212210
}
213211

214-
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)
212+
int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels, uint32_t *excluded_channels)
215213
{
216214
uint16_t nearest_prime = tr51_calc_nearest_prime_number(number_of_channels);
217215
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
223221
tr51_compute_cfd(mac, &first_element, &step_size, nearest_prime);
224222
// Not sure yet which one is the correct second parameter
225223
// tr51_calculate_hopping_sequence(channel_table, number_of_channels, first_element, step_size, output_table, NULL, 0);
226-
tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels, number_of_excluded_channels);
224+
tr51_calculate_hopping_sequence(channel_table, nearest_prime, first_element, step_size, output_table, excluded_channels);
227225
return output_table[slot_number];
228226
}

source/Service_Libs/fhss/channel_functions.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,19 @@
2323
* @param mac MAC address of the node for which the index is calculated.
2424
* @param number_of_channels Number of channels.
2525
* @param excluded_channels Excluded channels.
26-
* @param number_of_excluded_channels Number of excluded channels.
2726
* @return Channel index.
2827
*/
29-
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);
28+
int32_t tr51_get_uc_channel_index(uint16_t slot_number, uint8_t *mac, int16_t number_of_channels, uint32_t *excluded_channels);
3029

3130
/**
3231
* @brief Compute the broadcast schedule channel index using tr51 channel function.
3332
* @param slot_number Current slot number.
3433
* @param bsi Broadcast schedule identifier of the node for which the index is calculated.
3534
* @param number_of_channels Number of channels.
3635
* @param excluded_channels Excluded channels.
37-
* @param number_of_excluded_channels Number of excluded channels.
3836
* @return Channel index.
3937
*/
40-
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);
38+
int32_t tr51_get_bc_channel_index(uint16_t slot_number, uint16_t bsi, int16_t number_of_channels, uint32_t *excluded_channels);
4139

4240
/**
4341
* @brief Compute the unicast schedule channel index using direct hash channel function.

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static int32_t fhss_ws_calc_bc_channel(fhss_structure_t *fhss_structure)
8181
int32_t next_channel = fhss_structure->rx_channel;
8282

8383
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
84-
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);
84+
next_channel = tr51_get_bc_channel_index(fhss_structure->ws->bc_slot, fhss_structure->ws->fhss_configuration.bsi, fhss_structure->number_of_channels, NULL);
8585
if (++fhss_structure->ws->bc_slot == fhss_structure->number_of_channels) {
8686
fhss_structure->ws->bc_slot = 0;
8787
}
@@ -222,7 +222,7 @@ static void fhss_ws_update_uc_channel_callback(fhss_structure_t *fhss_structure)
222222
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
223223
return;
224224
} else if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_TR51CF) {
225-
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);
225+
next_channel = fhss_structure->rx_channel = tr51_get_uc_channel_index(fhss_structure->ws->uc_slot, mac_address, fhss_structure->number_of_channels, NULL);
226226
if (++fhss_structure->ws->uc_slot == fhss_structure->number_of_channels) {
227227
fhss_structure->ws->uc_slot = 0;
228228
}
@@ -269,7 +269,7 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
269269
uint16_t destination_slot = fhss_ws_calculate_destination_slot(neighbor_timing_info, tx_time);
270270
int32_t tx_channel;
271271
if (neighbor_timing_info->uc_timing_info.unicast_channel_function == WS_TR51CF) {
272-
tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, neighbor_timing_info->uc_timing_info.unicast_number_of_channels, NULL, 0);
272+
tx_channel = tr51_get_uc_channel_index(destination_slot, destination_address, neighbor_timing_info->uc_timing_info.unicast_number_of_channels, NULL);
273273
} else if(neighbor_timing_info->uc_timing_info.unicast_channel_function == WS_DH1CF) {
274274
tx_channel = dh1cf_get_uc_channel_index(destination_slot, destination_address, neighbor_timing_info->uc_timing_info.unicast_number_of_channels);
275275
} else if (neighbor_timing_info->uc_timing_info.unicast_channel_function == WS_VENDOR_DEF_CF) {

test/nanostack/unittest/service_libs/channel_functions/test_channel_functions.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,12 @@ const int32_t test_HopSequenceTable3[129] = { 124, 114, 65, 104, 33, 20, 118,
7171
102, 10, 91, 76, 117, 61, 81, 13,
7272
46 };
7373

74-
static bool channel_on_the_list(uint16_t *list, uint16_t list_size, int32_t channel)
74+
static bool channel_on_the_list(uint32_t *list, int32_t channel)
7575
{
76-
for (int i=0; i<list_size; i++) {
77-
if (list[i] == channel) {
78-
return true;
79-
}
76+
uint8_t index = channel/32;
77+
channel %= 32;
78+
if (list[index] & (1 << channel)) {
79+
return true;
8080
}
8181
return false;
8282
}
@@ -89,7 +89,7 @@ bool test_tr51_get_uc_channel_index()
8989
int32_t test_table[number_of_channels];
9090
uint8_t mac[8] = {0x00, 0x13, 0x50, 0x04, 0x00, 0x00, 0x05, 0xf8};
9191
for (i=0; i<number_of_channels; i++) {
92-
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, NULL, 0);
92+
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, NULL);
9393
// Not sure yet which one is correct since there might be bug in spec
9494
// if (channel != test_HopSequenceTable[i]) {
9595
if (channel != test_HopSequenceTable2[i]) {
@@ -111,24 +111,23 @@ bool test_tr51_get_uc_channel_index()
111111
}
112112
// Test with excluded channels
113113
int l=0;
114-
uint16_t excluded_channels[10] = {0, 10, 20, 30, 40, 50, 60, 70, 80, 90};
114+
uint32_t excluded_channels[8] = {0x40100401, 0x10040100, 0x04010040, 0, 0, 0, 0, 0};
115115
uint16_t number_of_excluded_channels = 10;
116116
for (i=0; i<number_of_channels-number_of_excluded_channels; i++) {
117-
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, excluded_channels, number_of_excluded_channels);
117+
test_table[i] = channel = tr51_get_uc_channel_index(i, mac, number_of_channels, excluded_channels);
118118
// Shouldn't find channel from excluded channels
119-
if (channel_on_the_list(excluded_channels, number_of_excluded_channels, channel)) {
119+
if (channel_on_the_list(excluded_channels, channel)) {
120120
return false;
121121
}
122122
// Test against channel sequence
123-
while (channel_on_the_list(excluded_channels, number_of_excluded_channels, test_HopSequenceTable2[l])) {
123+
while (channel_on_the_list(excluded_channels, test_HopSequenceTable2[l])) {
124124
l++;
125125
}
126126
if (channel != test_HopSequenceTable2[l]) {
127127
return false;
128128
}
129129
l++;
130130
}
131-
132131
return true;
133132
}
134133

@@ -139,7 +138,7 @@ bool test_tr51_get_bc_channel_index()
139138
uint16_t bsi = 100;
140139
int32_t test_table[number_of_channels];
141140
for (int i=0; i<number_of_channels; i++) {
142-
test_table[i] = channel = tr51_get_bc_channel_index(i, bsi, number_of_channels, NULL, 0);
141+
test_table[i] = channel = tr51_get_bc_channel_index(i, bsi, number_of_channels, NULL);
143142
if (channel != test_HopSequenceTable3[i]) {
144143
return false;
145144
}

0 commit comments

Comments
 (0)