Skip to content

Commit

Permalink
WS: fixed overwriting fixed channel with random
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Sep 25, 2018
1 parent e7fa605 commit 9c88a7f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 20 deletions.
10 changes: 4 additions & 6 deletions nanostack/ws_management_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,11 @@ int ws_management_fhss_timing_configure(
* Configure unicast channel function.
*
* Change the default configuration for Wi-SUN FHSS operation.
* This will use randomized value for fixed channel if used.
* if application defined is used the behaviour is undefined
*
* \param interface_id Network interface ID.
* \param channel_function Unicast channel function.
* \param fixed_channel Used channel when channel function is fixed channel.
* \param fixed_channel Used channel when channel function is fixed channel. If 0xFFFF, randomly chosen channel is used.
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
*
* \return 0, Init OK.
Expand All @@ -201,19 +200,18 @@ int ws_management_fhss_timing_configure(
int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function,
uint8_t fixed_channel,
uint16_t fixed_channel,
uint8_t dwell_interval);

/**
* Configure broadcast channel function.
*
* Change the default configuration for Wi-SUN FHSS operation.
* This will use randomized value for fixed channel if used.
* if application defined is used the behaviour is undefined
*
* \param interface_id Network interface ID.
* \param channel_function Broadcast channel function.
* \param fixed_channel Used channel when channel function is fixed channel.
* \param fixed_channel Used channel when channel function is fixed channel. If 0xFFFF, randomly chosen channel is used.
* \param dwell_interval Broadcast channel dwell interval.
* \param broadcast_interval Broadcast interval.
*
Expand All @@ -223,7 +221,7 @@ int ws_management_fhss_unicast_channel_function_configure(
int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function,
uint8_t fixed_channel,
uint16_t fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval);

Expand Down
26 changes: 18 additions & 8 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,15 @@ static int8_t ws_fhss_border_router_configure(protocol_interface_info_entry_t *c
return 0;
}

static uint16_t ws_randomize_fixed_channel(uint16_t configured_fixed_channel, uint8_t number_of_channels)
{
if (configured_fixed_channel == 0xFFFF) {
return randLIB_get_random_in_range(0, number_of_channels - 1);
} else {
return configured_fixed_channel;
}
}

static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
{
// Read configuration of existing FHSS and start using the default values for any network
Expand All @@ -420,12 +429,12 @@ static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)
fhss_configuration.ws_bc_channel_function = WS_FIXED_CHANNEL;
fhss_configuration.fhss_bc_dwell_interval = 0;
fhss_configuration.fhss_broadcast_interval = 0;
cur->ws_info->fhss_uc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
cur->ws_info->fhss_bc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
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);
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);
memset(fhss_configuration.channel_mask, 0, sizeof(uint32_t) * 8);
channel_list_set_channel(fhss_configuration.channel_mask, cur->ws_info->fhss_uc_fixed_channel, true);
fhss_configuration.unicast_fixed_channel = cur->ws_info->fhss_uc_fixed_channel;
fhss_configuration.broadcast_fixed_channel = cur->ws_info->fhss_bc_fixed_channel;
channel_list_set_channel(fhss_configuration.channel_mask, tmp_uc_fixed_channel, true);
fhss_configuration.unicast_fixed_channel = tmp_uc_fixed_channel;
fhss_configuration.broadcast_fixed_channel = tmp_bc_fixed_channel;
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);

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

if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
tr_debug("Border router start network");
// Randomize fixed channel. Only used if channel plan is fixed
cur->ws_info->fhss_uc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
cur->ws_info->fhss_bc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
// Randomize fixed channels. Only used if channel plan is fixed.
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);
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);
cur->ws_info->network_pan_id = randLIB_get_random_in_range(0,0xfffd);
cur->ws_info->pan_information.pan_size = 0;
cur->ws_info->pan_information.pan_version = randLIB_get_random_in_range(0,0xffff);
Expand Down
2 changes: 2 additions & 0 deletions source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
ws_common_regulatory_domain_config(cur);

// Set defaults for the device. user can modify these.
cur->ws_info->fhss_uc_fixed_channel = 0xffff;
cur->ws_info->fhss_bc_fixed_channel = 0xffff;
cur->ws_info->fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL;
cur->ws_info->fhss_bc_interval = WS_FHSS_BC_INTERVAL;
cur->ws_info->fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ typedef struct ws_info_s {
uint32_t fhss_bc_interval;
uint8_t fhss_uc_channel_function;
uint8_t fhss_bc_channel_function;
uint8_t fhss_uc_fixed_channel;
uint8_t fhss_bc_fixed_channel;
uint16_t fhss_uc_fixed_channel;
uint16_t fhss_bc_fixed_channel;
uint32_t fhss_channel_mask[8];
ws_nud_table_entry_t nud_table_entrys[ACTIVE_NUD_PROCESS_MAX];
ws_nud_table_list_t active_nud_process;
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_empty_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int ws_management_fhss_timing_configure(
int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function,
uint8_t fixed_channel,
uint16_t fixed_channel,
uint8_t dwell_interval)
{
(void)interface_id;
Expand All @@ -108,7 +108,7 @@ int ws_management_fhss_unicast_channel_function_configure(
int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function,
uint8_t fixed_channel,
uint16_t fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval)
{
Expand Down
4 changes: 2 additions & 2 deletions source/6LoWPAN/ws/ws_management_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ int ws_management_fhss_timing_configure(
int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function,
uint8_t fixed_channel,
uint16_t fixed_channel,
uint8_t dwell_interval)
{
protocol_interface_info_entry_t *cur;
Expand Down Expand Up @@ -195,7 +195,7 @@ int ws_management_fhss_unicast_channel_function_configure(
int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function,
uint8_t fixed_channel,
uint16_t fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval)
{
Expand Down

0 comments on commit 9c88a7f

Please sign in to comment.