Skip to content

Commit 160ef0a

Browse files
author
Jarkko Paso
authored
Merge pull request ARMmbed#1829 from ARMmbed/IOTTHD-2821
WS: fixed overwriting fixed channel with random
2 parents efd77f1 + 576f2bf commit 160ef0a

File tree

8 files changed

+39
-36
lines changed

8 files changed

+39
-36
lines changed

nanostack/fhss_config.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ extern "C" {
2929
#endif
3030

3131
#include "fhss_ws_extension.h"
32-
// Just to make the PR work. Will be removed when Application updated.
33-
#define ws_channel_function ws_uc_channel_function
3432

3533
/**
3634
* @brief WS channel functions.

nanostack/ws_management_api.h

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
#include "ns_types.h"
3232
#include "net_interface.h" /* Declaration for channel_list_s. */
3333

34-
// TODO: Remove when application updated
35-
#define DEFAULT_FIXED_CHANNEL 11
36-
#define DEFAULT_DWELL_TIME 250
37-
#define ws_management_fhss_channel_function_configure(x,y) ws_management_fhss_unicast_channel_function_configure(x,y,DEFAULT_FIXED_CHANNEL,DEFAULT_DWELL_TIME)
38-
3934
#ifdef __cplusplus
4035
extern "C" {
4136
#endif
@@ -187,12 +182,11 @@ int ws_management_fhss_timing_configure(
187182
* Configure unicast channel function.
188183
*
189184
* Change the default configuration for Wi-SUN FHSS operation.
190-
* This will use randomized value for fixed channel if used.
191185
* if application defined is used the behaviour is undefined
192186
*
193187
* \param interface_id Network interface ID.
194188
* \param channel_function Unicast channel function.
195-
* \param fixed_channel Used channel when channel function is fixed channel.
189+
* \param fixed_channel Used channel when channel function is fixed channel. If 0xFFFF, randomly chosen channel is used.
196190
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
197191
*
198192
* \return 0, Init OK.
@@ -201,19 +195,18 @@ int ws_management_fhss_timing_configure(
201195
int ws_management_fhss_unicast_channel_function_configure(
202196
int8_t interface_id,
203197
uint8_t channel_function,
204-
uint8_t fixed_channel,
198+
uint16_t fixed_channel,
205199
uint8_t dwell_interval);
206200

207201
/**
208202
* Configure broadcast channel function.
209203
*
210204
* Change the default configuration for Wi-SUN FHSS operation.
211-
* This will use randomized value for fixed channel if used.
212205
* if application defined is used the behaviour is undefined
213206
*
214207
* \param interface_id Network interface ID.
215208
* \param channel_function Broadcast channel function.
216-
* \param fixed_channel Used channel when channel function is fixed channel.
209+
* \param fixed_channel Used channel when channel function is fixed channel. If 0xFFFF, randomly chosen channel is used.
217210
* \param dwell_interval Broadcast channel dwell interval.
218211
* \param broadcast_interval Broadcast interval.
219212
*
@@ -223,7 +216,7 @@ int ws_management_fhss_unicast_channel_function_configure(
223216
int ws_management_fhss_broadcast_channel_function_configure(
224217
int8_t interface_id,
225218
uint8_t channel_function,
226-
uint8_t fixed_channel,
219+
uint16_t fixed_channel,
227220
uint8_t dwell_interval,
228221
uint32_t broadcast_interval);
229222

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@ static int8_t ws_fhss_border_router_configure(protocol_interface_info_entry_t *c
407407
return 0;
408408
}
409409

410+
static uint16_t ws_randomize_fixed_channel(uint16_t configured_fixed_channel, uint8_t number_of_channels)
411+
{
412+
if (configured_fixed_channel == 0xFFFF) {
413+
return randLIB_get_random_in_range(0, number_of_channels - 1);
414+
} else {
415+
return configured_fixed_channel;
416+
}
417+
}
418+
410419
static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
411420
{
412421
// Read configuration of existing FHSS and start using the default values for any network
@@ -420,12 +429,12 @@ static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
420429
fhss_configuration.ws_bc_channel_function = WS_FIXED_CHANNEL;
421430
fhss_configuration.fhss_bc_dwell_interval = 0;
422431
fhss_configuration.fhss_broadcast_interval = 0;
423-
cur->ws_info->fhss_uc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
424-
cur->ws_info->fhss_bc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
432+
uint8_t tmp_uc_fixed_channel = ws_randomize_fixed_channel(cur->ws_info->fhss_uc_fixed_channel, cur->ws_info->hopping_schdule.number_of_channels);
433+
uint8_t tmp_bc_fixed_channel = ws_randomize_fixed_channel(cur->ws_info->fhss_bc_fixed_channel, cur->ws_info->hopping_schdule.number_of_channels);
425434
memset(fhss_configuration.channel_mask, 0, sizeof(uint32_t) * 8);
426-
channel_list_set_channel(fhss_configuration.channel_mask, cur->ws_info->fhss_uc_fixed_channel, true);
427-
fhss_configuration.unicast_fixed_channel = cur->ws_info->fhss_uc_fixed_channel;
428-
fhss_configuration.broadcast_fixed_channel = cur->ws_info->fhss_bc_fixed_channel;
435+
channel_list_set_channel(fhss_configuration.channel_mask, tmp_uc_fixed_channel, true);
436+
fhss_configuration.unicast_fixed_channel = tmp_uc_fixed_channel;
437+
fhss_configuration.broadcast_fixed_channel = tmp_bc_fixed_channel;
429438
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
430439
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);
431440

@@ -473,6 +482,7 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
473482
fhss_configuration.ws_bc_channel_function = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_channel_function;
474483
if (fhss_configuration.ws_bc_channel_function == WS_FIXED_CHANNEL) {
475484
cur->ws_info->hopping_schdule.bc_fixed_channel = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.fixed_channel;
485+
cur->ws_info->fhss_bc_fixed_channel = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.fixed_channel;
476486
}
477487
fhss_configuration.bsi = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_schedule_id;
478488
fhss_configuration.fhss_bc_dwell_interval = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_dwell_interval;
@@ -1776,9 +1786,9 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
17761786

17771787
if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
17781788
tr_debug("Border router start network");
1779-
// Randomize fixed channel. Only used if channel plan is fixed
1780-
cur->ws_info->fhss_uc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
1781-
cur->ws_info->fhss_bc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
1789+
// Randomize fixed channels. Only used if channel plan is fixed.
1790+
cur->ws_info->fhss_uc_fixed_channel = ws_randomize_fixed_channel(cur->ws_info->fhss_uc_fixed_channel, cur->ws_info->hopping_schdule.number_of_channels);
1791+
cur->ws_info->fhss_bc_fixed_channel = ws_randomize_fixed_channel(cur->ws_info->fhss_bc_fixed_channel, cur->ws_info->hopping_schdule.number_of_channels);
17821792
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
17831793
cur->ws_info->pan_information.pan_size = 0;
17841794
cur->ws_info->pan_information.pan_version = randLIB_get_random_in_range(0,0xffff);

source/6LoWPAN/ws/ws_common.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
153153
ws_common_regulatory_domain_config(cur);
154154

155155
// Set defaults for the device. user can modify these.
156+
cur->ws_info->fhss_uc_fixed_channel = 0xffff;
157+
cur->ws_info->fhss_bc_fixed_channel = 0xffff;
156158
cur->ws_info->fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL;
157159
cur->ws_info->fhss_bc_interval = WS_FHSS_BC_INTERVAL;
158160
cur->ws_info->fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;

source/6LoWPAN/ws/ws_common.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ typedef struct ws_info_s {
7878
uint32_t fhss_bc_interval;
7979
uint8_t fhss_uc_channel_function;
8080
uint8_t fhss_bc_channel_function;
81-
uint8_t fhss_uc_fixed_channel;
82-
uint8_t fhss_bc_fixed_channel;
81+
uint16_t fhss_uc_fixed_channel;
82+
uint16_t fhss_bc_fixed_channel;
8383
uint32_t fhss_channel_mask[8];
8484
ws_nud_table_entry_t nud_table_entrys[ACTIVE_NUD_PROCESS_MAX];
8585
ws_nud_table_list_t active_nud_process;

source/6LoWPAN/ws/ws_empty_functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ int ws_management_fhss_timing_configure(
9595
int ws_management_fhss_unicast_channel_function_configure(
9696
int8_t interface_id,
9797
uint8_t channel_function,
98-
uint8_t fixed_channel,
98+
uint16_t fixed_channel,
9999
uint8_t dwell_interval)
100100
{
101101
(void)interface_id;
@@ -108,7 +108,7 @@ int ws_management_fhss_unicast_channel_function_configure(
108108
int ws_management_fhss_broadcast_channel_function_configure(
109109
int8_t interface_id,
110110
uint8_t channel_function,
111-
uint8_t fixed_channel,
111+
uint16_t fixed_channel,
112112
uint8_t dwell_interval,
113113
uint32_t broadcast_interval)
114114
{

source/6LoWPAN/ws/ws_management_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ int ws_management_fhss_timing_configure(
164164
int ws_management_fhss_unicast_channel_function_configure(
165165
int8_t interface_id,
166166
uint8_t channel_function,
167-
uint8_t fixed_channel,
167+
uint16_t fixed_channel,
168168
uint8_t dwell_interval)
169169
{
170170
protocol_interface_info_entry_t *cur;
@@ -195,7 +195,7 @@ int ws_management_fhss_unicast_channel_function_configure(
195195
int ws_management_fhss_broadcast_channel_function_configure(
196196
int8_t interface_id,
197197
uint8_t channel_function,
198-
uint8_t fixed_channel,
198+
uint16_t fixed_channel,
199199
uint8_t dwell_interval,
200200
uint32_t broadcast_interval)
201201
{

test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ bool test_fhss_ws_check_tx_conditions_callback()
301301
return false;
302302
}
303303
// Test broadcast destination on unicast channel
304-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
304+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
305305
if (fhss_common_stub.fhss_struct.fhss_api->check_tx_conditions(api, true, DEFAULT_HANDLE, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH) != false) {
306306
return false;
307307
}
@@ -386,7 +386,7 @@ bool test_fhss_ws_data_tx_done_callback()
386386
// Test when FHSS struct can be found
387387
enable_fhss_struct();
388388
fhss_common_stub.fhss_struct.fhss_state = FHSS_SYNCHRONIZED;
389-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
389+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
390390
fhss_common_stub.fhss_struct.fhss_api->data_tx_done(api, DEFAULT_WAITING_ACK, DEFAULT_TX_COMPLETED, DEFAULT_HANDLE);
391391

392392
return true;
@@ -452,7 +452,7 @@ bool test_fhss_ws_synch_state_set_callback()
452452
bool test_fhss_ws_write_synch_info_callback()
453453
{
454454
fhss_api_t *api = test_generate_fhss_api();
455-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
455+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
456456
fhss_common_stub.fhss_struct.rx_channel = 0;
457457
uint8_t synch_info[100] = {0x05, 0x15, 0x02, 0x00, 0x00, 0x00, 0x00, 0x05, 0x15, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3f};
458458
// Test when FHSS struct not found
@@ -561,28 +561,28 @@ bool test_fhss_ws_update_uc_channel_callback()
561561
return false;
562562
}
563563
// Test setting TR51 unicast channel
564-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
564+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
565565
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
566566
if ((3 != fhss_callbacks_stub.uint8_value) || (fhss_common_stub.fhss_struct.ws->uc_slot != 0)) {
567567
return false;
568568
}
569569
// Test setting direct hash unicast channel
570-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_DH1CF;
570+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_DH1CF;
571571
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
572572
if ((1 != fhss_callbacks_stub.uint8_value) || (fhss_common_stub.fhss_struct.ws->uc_slot != 1)) {
573573
return false;
574574
}
575575
// Test setting vendor defined unicast channel
576576
fhss_common_stub.fhss_struct.ws->fhss_configuration.vendor_defined_cf = app_channel_function;
577-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_VENDOR_DEF_CF;
577+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_VENDOR_DEF_CF;
578578
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
579579
if ((VENDOR_CHANNEL != fhss_callbacks_stub.uint8_value) || (fhss_common_stub.fhss_struct.ws->uc_slot != 1)) {
580580
return false;
581581
}
582582
// Test changing unicast channel when broadcast channel is active
583583
api = test_generate_fhss_api();
584584
enable_fhss_struct();
585-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
585+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
586586
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
587587
if ((3 != fhss_common_stub.fhss_struct.rx_channel) || (3 == fhss_callbacks_stub.uint8_value)) {
588588
return false;
@@ -597,7 +597,7 @@ bool test_fhss_unicast_handler()
597597
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 0;
598598
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 0;
599599
fhss_common_stub.fhss_struct.ws->uc_slot = fhss_common_stub.fhss_struct.number_of_channels - 1;
600-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
600+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
601601

602602
// Call state set just to get fhss_stub.callback
603603
enable_fhss_struct();
@@ -629,7 +629,7 @@ bool test_fhss_ws_set_parent()
629629
}
630630

631631
// Test success
632-
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
632+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_uc_channel_function = WS_TR51CF;
633633
bc_timing_info.broadcast_channel_function = WS_TR51CF;
634634
bc_timing_info.broadcast_dwell_interval = 250;
635635
bc_timing_info.broadcast_interval = 1000;

0 commit comments

Comments
 (0)