Skip to content

Commit

Permalink
WS bootstrap: Updated channel function set apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Sep 7, 2018
1 parent 42b2e7c commit b68f394
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
22 changes: 17 additions & 5 deletions nanostack/ws_management_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
#include "net_interface.h" /* Declaration for channel_list_s. */

// TODO: Remove when application updated
#define ws_management_fhss_channel_function_configure ws_management_fhss_unicast_channel_function_configure
#define DEFAULT_FIXED_CHANNEL 11
#define DEFAULT_DWELL_TIME 250
#define ws_management_fhss_channel_function_configure(x,y) ws_management_fhss_unicast_channel_function_configure(x,y,DEFAULT_FIXED_CHANNEL,DEFAULT_DWELL_TIME)

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -188,14 +190,18 @@ int ws_management_fhss_timing_configure(
* if application defined is used the behaviour is undefined
*
* \param interface_id Network interface ID.
* \param channel_function Unicast channel function
* \param channel_function Unicast channel function.
* \param fixed_channel Used channel when channel function is fixed channel.
* \param dwell_interval Used dwell interval when channel function is TR51 or DH1.
*
* \return 0, Init OK.
* \return <0 Init fail.
*/
int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function);
uint8_t channel_function,
uint8_t fixed_channel,
uint8_t dwell_interval);

/**
* Configure broadcast channel function.
Expand All @@ -205,13 +211,19 @@ int ws_management_fhss_unicast_channel_function_configure(
* if application defined is used the behaviour is undefined
*
* \param interface_id Network interface ID.
* \param channel_function Broadcast channel function
* \param channel_function Broadcast channel function.
* \param fixed_channel Used channel when channel function is fixed channel.
* \param dwell_interval Broadcast channel dwell interval.
* \param broadcast_interval Broadcast interval.
*
* \return 0, Init OK.
* \return <0 Init fail.
*/
int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function);
uint8_t channel_function,
uint8_t fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval);

#endif /* WS_MANAGEMENT_API_H_ */
26 changes: 14 additions & 12 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ static fhss_ws_neighbor_timing_info_t *ws_get_neighbor_info(const fhss_api_t *ap
static void ws_bootstrap_llc_hopping_update(struct protocol_interface_info_entry *cur, const fhss_ws_configuration_t *fhss_configuration)
{
memcpy(cur->ws_info->hopping_schdule.channel_mask, fhss_configuration->channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->hopping_schdule.uc_fixed_channel = fhss_configuration->unicast_fixed_channel;
cur->ws_info->hopping_schdule.bc_fixed_channel = fhss_configuration->broadcast_fixed_channel;
cur->ws_info->hopping_schdule.uc_channel_function = fhss_configuration->ws_uc_channel_function;
cur->ws_info->hopping_schdule.bc_channel_function = fhss_configuration->ws_bc_channel_function;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = fhss_configuration->fhss_bc_dwell_interval;
Expand Down Expand Up @@ -240,8 +242,8 @@ static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur, fhss_ws
fhss_configuration->ws_bc_channel_function = cur->ws_info->fhss_bc_channel_function;
fhss_configuration->fhss_bc_dwell_interval = cur->ws_info->fhss_bc_dwell_interval;
fhss_configuration->fhss_broadcast_interval = cur->ws_info->fhss_bc_interval;
fhss_configuration->unicast_fixed_channel = cur->ws_info->hopping_schdule.uc_fixed_channel;
fhss_configuration->broadcast_fixed_channel = cur->ws_info->hopping_schdule.bc_fixed_channel;
fhss_configuration->unicast_fixed_channel = cur->ws_info->fhss_uc_fixed_channel;
fhss_configuration->broadcast_fixed_channel = cur->ws_info->fhss_bc_fixed_channel;
ws_generate_channel_list(fhss_configuration->channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain);

// using bitwise AND operation for user set channel mask to remove channels not allowed in this device
Expand Down Expand Up @@ -277,12 +279,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->hopping_schdule.uc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
cur->ws_info->hopping_schdule.bc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
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);
memset(fhss_configuration.channel_mask, 0, sizeof(uint32_t) * 8);
channel_list_set_channel(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.uc_fixed_channel, true);
fhss_configuration.unicast_fixed_channel = cur->ws_info->hopping_schdule.uc_fixed_channel;
fhss_configuration.broadcast_fixed_channel = cur->ws_info->hopping_schdule.bc_fixed_channel;
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;
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);

Expand Down Expand Up @@ -328,8 +330,8 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
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;
fhss_configuration.fhss_broadcast_interval = neighbor_info->ws_neighbor->fhss_data.bc_timing_info.broadcast_interval;
fhss_configuration.unicast_fixed_channel = cur->ws_info->hopping_schdule.uc_fixed_channel;
fhss_configuration.broadcast_fixed_channel = cur->ws_info->hopping_schdule.bc_fixed_channel;
fhss_configuration.unicast_fixed_channel = cur->ws_info->fhss_uc_fixed_channel;
fhss_configuration.broadcast_fixed_channel = cur->ws_info->fhss_bc_fixed_channel;
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api, &fhss_configuration);

if (fhss_configuration.fhss_bc_dwell_interval && fhss_configuration.fhss_broadcast_interval) {
Expand Down Expand Up @@ -1158,7 +1160,7 @@ static void ws_bootstrap_fhss_activate(protocol_interface_info_entry_t *cur)
tr_debug("MAC init");
mac_helper_pib_boolean_set(cur, macRxOnWhenIdle, true);
cur->lowpan_info &= ~INTERFACE_NWK_CONF_MAC_RX_OFF_IDLE;
ws_bootstrap_mac_activate(cur, cur->ws_info->hopping_schdule.uc_fixed_channel, cur->ws_info->network_pan_id, true);
ws_bootstrap_mac_activate(cur, cur->ws_info->fhss_uc_fixed_channel, cur->ws_info->network_pan_id, true);
return;
}

Expand Down Expand Up @@ -1561,8 +1563,8 @@ 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->hopping_schdule.uc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
cur->ws_info->hopping_schdule.bc_fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
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);
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.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,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;
uint32_t fhss_channel_mask[8];

struct ws_pan_information_s pan_information;
Expand Down
14 changes: 12 additions & 2 deletions source/6LoWPAN/ws/ws_empty_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,29 @@ int ws_management_fhss_timing_configure(

int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function)
uint8_t channel_function,
uint8_t fixed_channel,
uint8_t dwell_interval)
{
(void)interface_id;
(void)channel_function;
(void)fixed_channel;
(void)dwell_interval;
return -1;
}

int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function)
uint8_t channel_function,
uint8_t fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval)
{
(void)interface_id;
(void)channel_function;
(void)fixed_channel;
(void)dwell_interval;
(void)broadcast_interval;
return -1;
}

Expand Down
14 changes: 12 additions & 2 deletions source/6LoWPAN/ws/ws_management_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ int ws_management_fhss_timing_configure(

int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function)
uint8_t channel_function,
uint8_t fixed_channel,
uint8_t dwell_interval)
{
protocol_interface_info_entry_t *cur;

Expand All @@ -178,6 +180,8 @@ int ws_management_fhss_unicast_channel_function_configure(
return -2;
}
cur->ws_info->fhss_uc_channel_function = channel_function;
cur->ws_info->fhss_uc_fixed_channel = fixed_channel;
cur->ws_info->fhss_uc_dwell_interval = dwell_interval;

// if settings change reset_restart for the settings needed
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
Expand All @@ -190,7 +194,10 @@ 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 channel_function,
uint8_t fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval)
{
protocol_interface_info_entry_t *cur;

Expand All @@ -205,6 +212,9 @@ int ws_management_fhss_broadcast_channel_function_configure(
return -2;
}
cur->ws_info->fhss_bc_channel_function = channel_function;
cur->ws_info->fhss_bc_fixed_channel = fixed_channel;
cur->ws_info->fhss_bc_dwell_interval = dwell_interval;
cur->ws_info->fhss_bc_interval = broadcast_interval;

// if settings change reset_restart for the settings needed
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
Expand Down

0 comments on commit b68f394

Please sign in to comment.