Skip to content

Commit 9c88a7f

Browse files
author
Jarkko Paso
committed
WS: fixed overwriting fixed channel with random
1 parent e7fa605 commit 9c88a7f

File tree

6 files changed

+30
-20
lines changed

6 files changed

+30
-20
lines changed

nanostack/ws_management_api.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,11 @@ int ws_management_fhss_timing_configure(
187187
* Configure unicast channel function.
188188
*
189189
* Change the default configuration for Wi-SUN FHSS operation.
190-
* This will use randomized value for fixed channel if used.
191190
* if application defined is used the behaviour is undefined
192191
*
193192
* \param interface_id Network interface ID.
194193
* \param channel_function Unicast channel function.
195-
* \param fixed_channel Used channel when channel function is fixed channel.
194+
* \param fixed_channel Used channel when channel function is fixed channel. If 0xFFFF, randomly chosen channel is used.
196195
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
197196
*
198197
* \return 0, Init OK.
@@ -201,19 +200,18 @@ int ws_management_fhss_timing_configure(
201200
int ws_management_fhss_unicast_channel_function_configure(
202201
int8_t interface_id,
203202
uint8_t channel_function,
204-
uint8_t fixed_channel,
203+
uint16_t fixed_channel,
205204
uint8_t dwell_interval);
206205

207206
/**
208207
* Configure broadcast channel function.
209208
*
210209
* Change the default configuration for Wi-SUN FHSS operation.
211-
* This will use randomized value for fixed channel if used.
212210
* if application defined is used the behaviour is undefined
213211
*
214212
* \param interface_id Network interface ID.
215213
* \param channel_function Broadcast channel function.
216-
* \param fixed_channel Used channel when channel function is fixed channel.
214+
* \param fixed_channel Used channel when channel function is fixed channel. If 0xFFFF, randomly chosen channel is used.
217215
* \param dwell_interval Broadcast channel dwell interval.
218216
* \param broadcast_interval Broadcast interval.
219217
*
@@ -223,7 +221,7 @@ int ws_management_fhss_unicast_channel_function_configure(
223221
int ws_management_fhss_broadcast_channel_function_configure(
224222
int8_t interface_id,
225223
uint8_t channel_function,
226-
uint8_t fixed_channel,
224+
uint16_t fixed_channel,
227225
uint8_t dwell_interval,
228226
uint32_t broadcast_interval);
229227

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
{

0 commit comments

Comments
 (0)