Skip to content

Commit

Permalink
Merge pull request ARMmbed#1810 from ARMmbed/IOTTHD-2734
Browse files Browse the repository at this point in the history
Iotthd 2734
  • Loading branch information
Jarkko Paso authored Sep 11, 2018
2 parents a40e012 + b68f394 commit 89b8eeb
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 71 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
46 changes: 40 additions & 6 deletions nanostack/ws_management_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
#include "ns_types.h"
#include "net_interface.h" /* Declaration for channel_list_s. */

// TODO: Remove when application updated
#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" {
#endif
Expand Down Expand Up @@ -140,7 +145,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 +157,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,20 +183,47 @@ 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 channel
* \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_channel_function_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);

/**
* 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 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 fixed_channel,
uint8_t dwell_interval,
uint32_t broadcast_interval);

#endif /* WS_MANAGEMENT_API_H_ */
45 changes: 27 additions & 18 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,10 @@ 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_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;
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 @@ -205,7 +208,8 @@ 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_channel_function;
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 @@ -223,7 +227,8 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
return 0;
}
memcpy(cur->ws_info->fhss_channel_mask, fhss_configuration->channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->fhss_channel_function = fhss_configuration->ws_uc_channel_function;
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 @@ -233,11 +238,12 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration)
{
fhss_configuration->fhss_uc_dwell_interval = cur->ws_info->fhss_uc_dwell_interval;
fhss_configuration->ws_uc_channel_function = cur->ws_info->fhss_channel_function;
// TODO: Just temporarily using hard coded broadcast channel function
fhss_configuration->ws_bc_channel_function = WS_DH1CF;
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;
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 @@ -270,12 +276,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->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.fixed_channel, true);

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 @@ -313,17 +322,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->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 @@ -1152,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.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 @@ -1555,7 +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.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
3 changes: 2 additions & 1 deletion source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
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;
cur->ws_info->fhss_channel_function = WS_FIXED_CHANNEL;
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
5 changes: 4 additions & 1 deletion source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ typedef struct ws_info_s {
uint8_t fhss_uc_dwell_interval;
uint8_t fhss_bc_dwell_interval;
uint32_t fhss_bc_interval;
uint8_t fhss_channel_function;
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
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
30 changes: 26 additions & 4 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,34 @@ 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,
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;
}

/* ### 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
Loading

0 comments on commit 89b8eeb

Please sign in to comment.