Skip to content

Commit

Permalink
WS bootstrap: Separated unicast and broadcast channel functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Sep 6, 2018
1 parent bbc0d77 commit b6236f9
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 53 deletions.
6 changes: 6 additions & 0 deletions nanostack/fhss_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ typedef struct fhss_ws_configuration
/** Broadcast dwell interval. Range: 15-250 milliseconds. */
uint8_t fhss_bc_dwell_interval;

/** Unicast fixed channel */
uint8_t unicast_fixed_channel;

/** Broadcast fixed channel */
uint8_t broadcast_fixed_channel;

/** Channel mask. */
uint32_t channel_mask[8];

Expand Down
3 changes: 2 additions & 1 deletion nanostack/fhss_ws_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct unicast_timing_info {
unsigned unicast_channel_function:3; /**< Unicast schedule channel function */
uint8_t unicast_dwell_interval; /**< Unicast dwell interval */
uint16_t unicast_number_of_channels; /**< Unicast number of channels */
uint16_t fixed_channel; /**< fixed channel*/
uint16_t fixed_channel; /**< Unicast fixed channel*/
uint_fast24_t ufsi; /**< Unicast fractional sequence interval */
uint32_t utt_rx_timestamp; /**< UTT-IE reception timestamp */
} unicast_timing_info_t;
Expand All @@ -48,6 +48,7 @@ typedef struct unicast_timing_info {
typedef struct broadcast_timing_info {
unsigned broadcast_channel_function:3; /**< Broadcast schedule channel function */
uint8_t broadcast_dwell_interval; /**< Broadcast dwell interval */
uint16_t fixed_channel; /**< Broadcast fixed channel*/
uint16_t broadcast_slot; /**< Broadcast slot number */
uint16_t broadcast_schedule_id; /**< Broadcast schedule identifier */
uint_fast24_t broadcast_interval_offset; /**< Broadcast interval offset */
Expand Down
32 changes: 27 additions & 5 deletions nanostack/ws_management_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include "ns_types.h"
#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

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -140,7 +143,8 @@ int ws_management_channel_mask_set(
*
* \param interface_id Network interface ID.
* \param channel_plan Channel plan must be 1 application defined if deviating from regulatory domain (0).
* \param channel_function 0: Fixed channel, 1:TR51CF, 2: Direct Hash, 3: Vendor defined.
* \param uc_channel_function 0: Fixed channel, 1:TR51CF, 2: Direct Hash, 3: Vendor defined.
* \param bc_channel_function 0: Fixed channel, 1:TR51CF, 2: Direct Hash, 3: Vendor defined.
* \param ch0_freq ch0 center frequency.
* \param channel_spacing Channel spacing value 0:200k, 1:400k, 2:600k, 3:100k.
* \param number_of_channels FHSS phy operating mode default to "1b".
Expand All @@ -151,7 +155,8 @@ int ws_management_channel_mask_set(
int ws_management_channel_plan_set(
int8_t interface_id,
uint8_t channel_plan,
uint8_t channel_function,
uint8_t uc_channel_function,
uint8_t bc_channel_function,
uint32_t ch0_freq, // Stack can not modify this
uint8_t channel_spacing,// Stack can not modify this
uint8_t number_of_channels);// Stack can not modify this
Expand All @@ -176,19 +181,36 @@ int ws_management_fhss_timing_configure(
uint8_t fhss_bc_dwell_interval);

/**
* Configure channel function.
* 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
*
* \return 0, Init OK.
* \return <0 Init fail.
*/
int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function);

/**
* 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 channel
* \param channel_function Broadcast channel function
*
* \return 0, Init OK.
* \return <0 Init fail.
*/
int ws_management_fhss_channel_function_configure(
int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function);

Expand Down
37 changes: 22 additions & 15 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +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.channel_function = fhss_configuration->ws_uc_channel_function;
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;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = fhss_configuration->fhss_broadcast_interval;
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = fhss_configuration->fhss_uc_dwell_interval;
Expand All @@ -206,6 +207,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)

fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->fhss_uc_dwell_interval;
fhss_configuration.ws_uc_channel_function = cur->ws_info->fhss_uc_channel_function;
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;

Expand All @@ -224,6 +226,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
}
memcpy(cur->ws_info->fhss_channel_mask, fhss_configuration->channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->fhss_uc_channel_function = fhss_configuration->ws_uc_channel_function;
cur->ws_info->fhss_bc_channel_function = fhss_configuration->ws_bc_channel_function;
cur->ws_info->fhss_bc_dwell_interval = fhss_configuration->fhss_bc_dwell_interval;
cur->ws_info->fhss_bc_interval = fhss_configuration->fhss_broadcast_interval;
cur->ws_info->fhss_uc_dwell_interval = fhss_configuration->fhss_uc_dwell_interval;
Expand All @@ -234,10 +237,11 @@ static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur, fhss_ws
{
fhss_configuration->fhss_uc_dwell_interval = cur->ws_info->fhss_uc_dwell_interval;
fhss_configuration->ws_uc_channel_function = cur->ws_info->fhss_uc_channel_function;
// TODO: Just temporarily using hard coded broadcast channel function
fhss_configuration->ws_bc_channel_function = WS_DH1CF;
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;
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 @@ -270,12 +274,15 @@ static int8_t ws_fhss_discovery_configure(protocol_interface_info_entry_t *cur)

fhss_configuration.fhss_uc_dwell_interval = 0;
fhss_configuration.ws_uc_channel_function = WS_FIXED_CHANNEL;
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.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
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);
memset(fhss_configuration.channel_mask, 0, sizeof(uint32_t) * 8);
channel_list_set_channel(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.fixed_channel, true);

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;
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);

Expand Down Expand Up @@ -313,17 +320,16 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry

ws_fhss_set_defaults(cur, &fhss_configuration);

// Learning unicast network configuration
fhss_configuration.ws_uc_channel_function = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function;
if (fhss_configuration.ws_uc_channel_function == WS_FIXED_CHANNEL) {
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
// Learning broadcast network configuration
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;
}
/* Learning different unicast is not working currently at fhss network follows border router
*/
// Learn broadcast information from selected parent
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;
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 @@ -1152,7 +1158,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.fixed_channel, cur->ws_info->network_pan_id, true);
ws_bootstrap_mac_activate(cur, cur->ws_info->hopping_schdule.uc_fixed_channel, cur->ws_info->network_pan_id, true);
return;
}

Expand Down Expand Up @@ -1555,7 +1561,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.fixed_channel = randLIB_get_random_in_range(0,cur->ws_info->hopping_schdule.number_of_channels - 1);
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->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
1 change: 1 addition & 0 deletions source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
cur->ws_info->fhss_bc_interval = WS_FHSS_BC_INTERVAL;
cur->ws_info->fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL;
cur->ws_info->fhss_uc_channel_function = WS_FIXED_CHANNEL;
cur->ws_info->fhss_bc_channel_function = WS_DH1CF;
for (uint8_t n = 0;n < 8;n++) {
cur->ws_info->fhss_channel_mask[n] = 0xffffffff;
}
Expand Down
6 changes: 4 additions & 2 deletions source/6LoWPAN/ws/ws_common_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,14 @@ typedef struct ws_hopping_schedule_s {
uint8_t operating_class; /**< PHY operating class default to 1 */
uint8_t operating_mode; /**< PHY operating mode default to "1b" symbol rate 50, modulation index 1 */
uint8_t channel_plan; /**< 0: use regulatory domain values 1: application defined plan */
uint8_t channel_function; /**< 0: Fixed channel, 1:TR51CF, 2: Direct Hash, 3: Vendor defined */
uint8_t uc_channel_function; /**< 0: Fixed channel, 1:TR51CF, 2: Direct Hash, 3: Vendor defined */
uint8_t bc_channel_function; /**< 0: Fixed channel, 1:TR51CF, 2: Direct Hash, 3: Vendor defined */
uint8_t channel_spacing; /**< derived from regulatory domain. 0:200k, 1:400k, 2:600k, 3:100k */
uint8_t number_of_channels; /**< derived from regulatory domain */
uint8_t clock_drift;
uint8_t timing_accurancy;
uint16_t fixed_channel;
uint16_t uc_fixed_channel;
uint16_t bc_fixed_channel;
uint16_t fhss_bsi;
uint32_t fhss_broadcast_interval;
uint32_t channel_mask[8];
Expand Down
18 changes: 15 additions & 3 deletions source/6LoWPAN/ws/ws_empty_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,16 @@ int ws_management_channel_mask_set(
int ws_management_channel_plan_set(
int8_t interface_id,
uint8_t channel_plan,
uint8_t channel_function,
uint8_t uc_channel_function,
uint8_t bc_channel_function,
uint32_t ch0_freq, // Stack can not modify this
uint8_t channel_spacing,// Stack can not modify this
uint8_t number_of_channels)
{
(void)interface_id;
(void)channel_plan;
(void)channel_function;
(void)uc_channel_function;
(void)bc_channel_function;
(void)ch0_freq;
(void)channel_spacing;
(void)number_of_channels;
Expand All @@ -90,14 +92,24 @@ int ws_management_fhss_timing_configure(
return -1;
}

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

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

/* ### test api ### */
int ws_test_pan_size_set(int8_t interface_id, uint16_t pan_size)
{
Expand Down
25 changes: 20 additions & 5 deletions source/6LoWPAN/ws/ws_ie_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ static uint16_t ws_channel_function_length(uint8_t channel_function, uint16_t ho
uint16_t ws_wp_nested_hopping_schedule_length(struct ws_hopping_schedule_s *hopping_schedule, bool unicast_schedule)
{
uint16_t length;
uint8_t channel_function;
if (unicast_schedule) {
length = 4;
channel_function = hopping_schedule->uc_channel_function;
} else {
length = 10;
channel_function = hopping_schedule->bc_channel_function;
}

length += ws_channel_plan_length(hopping_schedule->channel_plan);
length += ws_channel_function_length(hopping_schedule->channel_function, 1);

length += ws_channel_function_length(channel_function, 1);

//Todo Derive some how exluded channel control
return length;
Expand Down Expand Up @@ -147,7 +151,11 @@ uint8_t *ws_wp_nested_hopping_schedule_write(uint8_t *ptr,struct ws_hopping_sche
*ptr++ = hopping_schedule->timing_accurancy;
uint8_t channel_info_base = 0;
channel_info_base = (hopping_schedule->channel_plan);
channel_info_base |= (hopping_schedule->channel_function << 3);
if (unicast_schedule) {
channel_info_base |= (hopping_schedule->uc_channel_function << 3);
} else {
channel_info_base |= (hopping_schedule->bc_channel_function << 3);
}
//Todo define excluded channel ctrl

*ptr++ = channel_info_base;
Expand All @@ -167,11 +175,18 @@ uint8_t *ws_wp_nested_hopping_schedule_write(uint8_t *ptr,struct ws_hopping_sche
default:
break;
}

switch (hopping_schedule->channel_function) {
uint8_t cf = hopping_schedule->uc_channel_function;
uint16_t fixed_channel = hopping_schedule->uc_fixed_channel;
if (!unicast_schedule) {
cf = hopping_schedule->bc_channel_function;
}
switch (cf) {
case 0:
//Fixed channel inline
ptr = common_write_16_bit_inverse(hopping_schedule->fixed_channel, ptr);
if (!unicast_schedule) {
fixed_channel = hopping_schedule->bc_fixed_channel;
}
ptr = common_write_16_bit_inverse(fixed_channel, ptr);
break;
case 1:
case 2:
Expand Down
35 changes: 32 additions & 3 deletions source/6LoWPAN/ws/ws_management_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ int ws_management_channel_mask_set(
int ws_management_channel_plan_set(
int8_t interface_id,
uint8_t channel_plan,
uint8_t channel_function,
uint8_t uc_channel_function,
uint8_t bc_channel_function,
uint32_t ch0_freq, // Stack can not modify this
uint8_t channel_spacing,// Stack can not modify this
uint8_t number_of_channels)
Expand All @@ -118,7 +119,8 @@ int ws_management_channel_plan_set(
return -1;
}
cur->ws_info->hopping_schdule.channel_plan = channel_plan;
cur->ws_info->hopping_schdule.channel_function = channel_function;
cur->ws_info->hopping_schdule.uc_channel_function = uc_channel_function;
cur->ws_info->hopping_schdule.bc_channel_function = bc_channel_function;
cur->ws_info->hopping_schdule.ch0_freq = ch0_freq;
cur->ws_info->hopping_schdule.channel_spacing = channel_spacing;
cur->ws_info->hopping_schdule.number_of_channels = number_of_channels;
Expand Down Expand Up @@ -159,7 +161,7 @@ int ws_management_fhss_timing_configure(
return 0;
}

int ws_management_fhss_channel_function_configure(
int ws_management_fhss_unicast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function)
{
Expand All @@ -184,5 +186,32 @@ int ws_management_fhss_channel_function_configure(
}
return 0;

}

int ws_management_fhss_broadcast_channel_function_configure(
int8_t interface_id,
uint8_t channel_function)
{
protocol_interface_info_entry_t *cur;

cur = protocol_stack_interface_info_get_by_id(interface_id);
if (!cur || !ws_info(cur)) {
return -1;
}
if (channel_function != WS_FIXED_CHANNEL &&
channel_function != WS_VENDOR_DEF_CF &&
channel_function != WS_DH1CF &&
channel_function != WS_TR51CF) {
return -2;
}
cur->ws_info->fhss_bc_channel_function = channel_function;

// if settings change reset_restart for the settings needed
if (cur->lowpan_info & INTERFACE_NWK_ACTIVE) {
// bootstrap active need to restart
ws_bootstrap_restart(interface_id);
}
return 0;

}
#endif // HAVE_WS
4 changes: 4 additions & 0 deletions source/6LoWPAN/ws/ws_neighbor_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ void ws_neighbor_class_neighbor_broadcast_time_info_update(ws_neighbor_class_ent

void ws_neighbor_class_neighbor_broadcast_schedule_set(ws_neighbor_class_entry_t *ws_neighbor, ws_bs_ie_t *ws_bs_ie)
{
ws_neighbor->fhss_data.bc_timing_info.broadcast_channel_function = ws_bs_ie->channel_function;
if (ws_bs_ie->channel_function == WS_FIXED_CHANNEL) {
ws_neighbor->fhss_data.bc_timing_info.fixed_channel = ws_bs_ie->function.zero.fixed_channel;
}
ws_neighbor->fhss_data.bc_timing_info.broadcast_dwell_interval = ws_bs_ie->dwell_interval;
ws_neighbor->fhss_data.bc_timing_info.broadcast_interval = ws_bs_ie->broadcast_interval;
ws_neighbor->fhss_data.bc_timing_info.broadcast_schedule_id = ws_bs_ie->broadcast_schedule_identifier;
Expand Down
Loading

0 comments on commit b6236f9

Please sign in to comment.