Skip to content

Commit

Permalink
added support for modifying fhss configuration after initial startup
Browse files Browse the repository at this point in the history
Refactored default configuration set so that configuration is only called onse

Separated border router configuration
Save fixed channel only when updating to fixed channel

Fixed Configuration inconsistency/consistency rules

modify ASYNC message sending to use full channel mask and not follow the configured
channel mask
  • Loading branch information
Mika Tervonen committed Aug 28, 2018
1 parent 88e239d commit b162d7b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 39 deletions.
89 changes: 50 additions & 39 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,29 +230,34 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
}
return 0;
}
static int8_t ws_fhss_set_defaults(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_channel_function = cur->ws_info->fhss_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;
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
for (uint8_t n = 0;n < 8;n++) {
fhss_configuration->channel_mask[n] &= cur->ws_info->fhss_channel_mask[n];
}
return 0;
}
static int8_t ws_fhss_border_router_configure(protocol_interface_info_entry_t *cur)
{
// Read configuration of existing FHSS and start using the default values for any network
fhss_ws_configuration_t fhss_configuration = {0};
if (ns_fhss_ws_configuration_get(cur->ws_info->fhss_api)) {
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
}

fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->fhss_uc_dwell_interval;
fhss_configuration.ws_channel_function = cur->ws_info->fhss_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;
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
for (uint8_t n = 0;n < 8;n++) {
fhss_configuration.channel_mask[n] &= cur->ws_info->fhss_channel_mask[n];
}

ws_fhss_set_defaults(cur, &fhss_configuration);
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api,&fhss_configuration);
ws_bootstrap_llc_hopping_update(cur,&fhss_configuration);

return 0;
}

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 Down Expand Up @@ -304,8 +309,13 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
fhss_ws_configuration_t fhss_configuration;
memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));

ws_fhss_set_defaults(cur, &fhss_configuration);

// Learning unicast network configuration
fhss_configuration.ws_channel_function = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.unicast_channel_function;
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
if (fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
cur->ws_info->hopping_schdule.fixed_channel = neighbor_info->ws_neighbor->fhss_data.uc_timing_info.fixed_channel;
}
/* Learning different unicast is not working currently at fhss network follows border router
*/
// Learn broadcast information from selected parent
Expand Down Expand Up @@ -704,16 +714,21 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
ws_neighbor_class_neighbor_broadcast_schedule_set(neighbor_info.ws_neighbor, &ws_bs_ie);
neighbor_info.neighbor->trusted_device = true;

if (cur->ws_info->configuration_learned &&
common_serial_number_greater_16(cur->ws_info->pan_information.pan_version, pan_version)) {
if (cur->ws_info->configuration_learned) {
// received version is lower se we need to reset the trickle
tr_info("older pan version heard");
if (trickle_running(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery)) {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery);
if (cur->ws_info->pan_information.pan_version == pan_version) {
trickle_consistent_heard(&cur->ws_info->trickle_pan_config);
} else {
tr_info("different pan version heard");
if (trickle_running(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery)) {
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config,&trickle_params_pan_discovery);
}
if (common_serial_number_greater_16(cur->ws_info->pan_information.pan_version, pan_version)) {
// older version heard ignoring the message
return;
}
}
return;
}
trickle_consistent_heard(&cur->ws_info->trickle_pan_config);

if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
//Border router does not learn network information
Expand Down Expand Up @@ -741,14 +756,11 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
// return to state machine after 1-2 s
cur->bootsrap_state_machine_cnt = randLIB_get_random_in_range(10 ,20);
// enable frequency hopping for unicast channel and start listening first neighbour
ws_fhss_set_defaults(cur);
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
} else if (neighbor_info.neighbor->link_role == PRIORITY_PARENT_NEIGHBOUR) {
// RPL priority parent configuration we must update FHSS data
ws_bootstrap_primary_parent_set(cur, &neighbor_info);
}


}

static void ws_bootstrap_pan_config_solicit_analyse(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, ws_utt_ie_t *ws_utt, ws_us_ie_t *ws_us)
Expand Down Expand Up @@ -1343,9 +1355,9 @@ static void ws_bootstrap_pan_advert_solicit(protocol_interface_info_entry_t *cur
async_req.wh_requested_ie_list.utt_ie = true;
async_req.wp_requested_nested_ie_list.us_ie = true;
async_req.wp_requested_nested_ie_list.net_name_ie = true;
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}

ws_generate_channel_list(async_req.channel_list.channel_mask,cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain);

async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = 0;

Expand All @@ -1361,9 +1373,9 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur
async_req.wh_requested_ie_list.utt_ie = true;
async_req.wp_requested_nested_ie_list.us_ie = true;
async_req.wp_requested_nested_ie_list.net_name_ie = true;
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}

ws_generate_channel_list(async_req.channel_list.channel_mask,cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain);

async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = 0;

Expand Down Expand Up @@ -1415,9 +1427,9 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
async_req.wp_requested_nested_ie_list.us_ie = true;
async_req.wp_requested_nested_ie_list.pan_ie = true;
async_req.wp_requested_nested_ie_list.net_name_ie = true;
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}

ws_generate_channel_list(async_req.channel_list.channel_mask,cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain);

async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = 0;

Expand Down Expand Up @@ -1448,9 +1460,9 @@ static void ws_bootstrap_pan_config(protocol_interface_info_entry_t *cur)
async_req.wp_requested_nested_ie_list.pan_version_ie = true;
async_req.wp_requested_nested_ie_list.gtkhash_ie = true;
async_req.wp_requested_nested_ie_list.vp_ie = true;
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}

ws_generate_channel_list(async_req.channel_list.channel_mask,cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain);

async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = mac_helper_default_security_level_get(cur);
async_req.security.KeyIdMode = mac_helper_default_security_key_id_mode_get(cur);
Expand Down Expand Up @@ -1501,9 +1513,6 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
trickle_stop(&cur->ws_info->trickle_pan_advertisement);
trickle_stop(&cur->ws_info->trickle_pan_config);

// Set default parameters for FHSS when starting a discovery
ws_fhss_set_defaults(cur);

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
Expand All @@ -1517,7 +1526,9 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
cur->ws_info->pan_information.version = WS_FAN_VERSION_1_0;
ws_llc_set_gtkhash(cur, cur->ws_info->gtkhash);
cur->ws_info->pan_version_timer = PAN_VERSION_LIFETIME;

// Set default parameters for FHSS when starting a discovery
ws_fhss_border_router_configure(cur);
ws_bootstrap_fhss_activate(cur);
ws_bootstrap_set_test_key(cur);
ws_bootstrap_event_operation_start(cur);
Expand Down
5 changes: 5 additions & 0 deletions source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ static void fhss_broadcast_handler(const fhss_api_t *fhss_api, uint16_t delay)
return;
}

if (fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval == 0 || fhss_structure->ws->fhss_configuration.fhss_broadcast_interval == 0) {
// stop broadcast schedule
fhss_structure->ws->is_on_bc_channel = false;
return;
}
if (fhss_structure->ws->is_on_bc_channel == false) {
fhss_start_timer(fhss_structure, fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval*1000, fhss_broadcast_handler);
fhss_structure->ws->is_on_bc_channel = true;
Expand Down

0 comments on commit b162d7b

Please sign in to comment.