Skip to content

Commit

Permalink
Refactoring Wi-SUN stack (ARMmbed#2686)
Browse files Browse the repository at this point in the history
* Removed option to create FHSS on application

* Separate module for WS PHY mode functions

* Renamed functions to use ws_common prefix

* Use struct assignment instead of memcpy to get FHSS config
  • Loading branch information
Jarkko Paso authored Sep 9, 2021
1 parent 9d2386d commit 50ecc3d
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 447 deletions.
88 changes: 28 additions & 60 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include "6LoWPAN/ws/ws_bootstrap_6lbr.h"
#include "6LoWPAN/ws/ws_bootstrap_ffn.h"
#include "6LoWPAN/ws/ws_bootstrap_lfn.h"
#include "6LoWPAN/ws/ws_phy.h"
#include "6LoWPAN/lowpan_adaptation_interface.h"
#include "Service_Libs/etx/etx.h"
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
Expand Down Expand Up @@ -582,8 +583,8 @@ static uint8_t ws_generate_exluded_channel_list_from_active_channels(ws_excluded
void ws_fhss_configure_channel_masks(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration)
{
fhss_configuration->channel_mask_size = cur->ws_info->hopping_schdule.number_of_channels;
ws_generate_channel_list(fhss_configuration->channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
ws_generate_channel_list(fhss_configuration->unicast_channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
ws_common_generate_channel_list(fhss_configuration->channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
ws_common_generate_channel_list(fhss_configuration->unicast_channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
// 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->unicast_channel_mask[n] &= cur->ws_info->cfg->fhss.fhss_channel_mask[n];
Expand All @@ -600,12 +601,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
if (!fhss_api) {
// When FHSS doesn't exist yet, create one
ws_fhss_configure_channel_masks(cur, &fhss_configuration);

fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->cfg->fhss.fhss_uc_dwell_interval;
fhss_configuration.ws_uc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_uc_channel_function;
fhss_configuration.ws_bc_channel_function = (fhss_ws_channel_functions)cur->ws_info->cfg->fhss.fhss_bc_channel_function;
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->cfg->fhss.fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->cfg->fhss.fhss_bc_interval;
ws_fhss_set_defaults(cur, &fhss_configuration);
fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);

if (!fhss_api) {
Expand All @@ -615,26 +611,7 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
// Allow transmitting unicast frames only on TX slots in normal and expedited forwarding mode
ns_fhss_ws_set_tx_allowance_level(fhss_api, WS_TX_SLOT, WS_TX_SLOT);
} else {
// Read defaults from the configuration to help FHSS testing
const fhss_ws_configuration_t *fhss_configuration_copy = ns_fhss_ws_configuration_get(fhss_api);
if (!fhss_configuration_copy) {
// no configuration set yet
return 0;
}
fhss_configuration = *fhss_configuration_copy;
//Overwrite domain channel setup this will over write a default 35 channel
int num_of_channels = channel_list_count_channels(fhss_configuration_copy->unicast_channel_mask);
cur->ws_info->hopping_schdule.number_of_channels = (uint8_t) num_of_channels;
memcpy(cur->ws_info->cfg->fhss.fhss_channel_mask, fhss_configuration_copy->unicast_channel_mask, sizeof(uint32_t) * 8);
cur->ws_info->cfg->fhss.fhss_uc_channel_function = fhss_configuration_copy->ws_uc_channel_function;
cur->ws_info->cfg->fhss.fhss_bc_channel_function = fhss_configuration_copy->ws_bc_channel_function;
cur->ws_info->cfg->fhss.fhss_bc_dwell_interval = fhss_configuration_copy->fhss_bc_dwell_interval;
cur->ws_info->cfg->fhss.fhss_bc_interval = fhss_configuration_copy->fhss_broadcast_interval;
cur->ws_info->cfg->fhss.fhss_uc_dwell_interval = fhss_configuration_copy->fhss_uc_dwell_interval;
cur->ws_info->cfg->fhss.fhss_bc_fixed_channel = fhss_configuration_copy->broadcast_fixed_channel;
cur->ws_info->cfg->fhss.fhss_uc_fixed_channel = fhss_configuration_copy->unicast_fixed_channel;
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
ns_fhss_ws_configuration_set(fhss_api, &fhss_configuration);
return -1;
}

return 0;
Expand Down Expand Up @@ -677,14 +654,10 @@ uint16_t ws_randomize_fixed_channel(uint16_t configured_fixed_channel, uint8_t n
int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery)
{
// Read configuration of existing FHSS and start using the default values for any network
fhss_ws_configuration_t fhss_configuration;
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);
ws_fhss_set_defaults(cur, &fhss_configuration);
ws_fhss_configure_channel_masks(cur, &fhss_configuration);

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));
ws_fhss_set_defaults(cur, &fhss_configuration);
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
}
// Discovery is done using fixed channel
if (discovery) {
fhss_configuration.ws_uc_channel_function = WS_FIXED_CHANNEL;
Expand All @@ -706,13 +679,10 @@ int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery)

static int8_t ws_fhss_enable(protocol_interface_info_entry_t *cur)
{
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(cur->ws_info->fhss_api);
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);

if (!cur->ws_info->fhss_api || !fhss_configuration) {
return -1;
}
// Set the LLC information to follow the actual fhss settings
ws_bootstrap_llc_hopping_update(cur, fhss_configuration);
ws_bootstrap_llc_hopping_update(cur, &fhss_configuration);

// Set neighbor info callback
if (ns_fhss_set_neighbor_info_fp(cur->ws_info->fhss_api, &ws_get_neighbor_info)) {
Expand All @@ -729,14 +699,12 @@ static int8_t ws_fhss_enable(protocol_interface_info_entry_t *cur)
*/
void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry *cur, llc_neighbour_req_t *neighbor_info, ws_parent_synch_e synch_req)
{

fhss_ws_configuration_t fhss_configuration;
if (!neighbor_info->ws_neighbor->broadcast_timing_info_stored) {
tr_error("No BC timing info for set new parent");
return;
}

memcpy(&fhss_configuration, ns_fhss_ws_configuration_get(cur->ws_info->fhss_api), sizeof(fhss_ws_configuration_t));
fhss_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);

// Learning broadcast network configuration
if (neighbor_info->ws_neighbor->broadcast_shedule_info_stored) {
Expand Down Expand Up @@ -1871,7 +1839,7 @@ int ws_bootstrap_restart_delayed(int8_t interface_id)

static int8_t ws_bootstrap_phy_mode_resolver(const mac_api_t *api, uint8_t phy_mode_id, phy_rf_channel_configuration_s *rf_config)
{
rf_config->modulation = ws_get_modulation_using_phy_mode_id(phy_mode_id);
rf_config->modulation = ws_phy_get_modulation_using_phy_mode_id(phy_mode_id);
if (rf_config->modulation == M_UNDEFINED) {
return -1;
}
Expand All @@ -1882,28 +1850,28 @@ static int8_t ws_bootstrap_phy_mode_resolver(const mac_api_t *api, uint8_t phy_m
uint8_t regulatory_domain = interface->ws_info->hopping_schdule.regulatory_domain;
uint8_t base_channel_plan_id = interface->ws_info->hopping_schdule.channel_plan_id;
if (base_channel_plan_id == 255) {
base_channel_plan_id = ws_convert_operating_class_to_channel_plan_id(interface->ws_info->hopping_schdule.operating_class, regulatory_domain);
base_channel_plan_id = ws_phy_convert_operating_class_to_channel_plan_id(interface->ws_info->hopping_schdule.operating_class, regulatory_domain);
}
if (!base_channel_plan_id) {
return -1;
}
// Function returns base channel plan ID, if it matches the PHY mode ID. Otherwise, nearest matching channel plan ID where PHY mode ID is allowed will be returned.
uint8_t channel_plan_id = ws_get_channel_plan_id_using_phy_mode_id(phy_mode_id, regulatory_domain, base_channel_plan_id);
uint8_t channel_plan_id = ws_phy_get_channel_plan_id_using_phy_mode_id(phy_mode_id, regulatory_domain, base_channel_plan_id);
if (!channel_plan_id) {
return -1;
}

rf_config->channel_0_center_frequency = ws_get_channel_0_frequency_using_channel_plan_id(channel_plan_id);
rf_config->channel_spacing = ws_get_channel_spacing_using_channel_plan_id(channel_plan_id);
rf_config->number_of_channels = ws_get_number_of_channels_using_channel_plan_id(channel_plan_id);
rf_config->datarate = ws_get_datarate_using_phy_mode_id(phy_mode_id);
rf_config->channel_0_center_frequency = ws_phy_get_channel_0_frequency_using_channel_plan_id(channel_plan_id);
rf_config->channel_spacing = ws_phy_get_channel_spacing_using_channel_plan_id(channel_plan_id);
rf_config->number_of_channels = ws_phy_get_number_of_channels_using_channel_plan_id(channel_plan_id);
rf_config->datarate = ws_phy_get_datarate_using_phy_mode_id(phy_mode_id);
if (!rf_config->channel_0_center_frequency || !rf_config->channel_spacing || !rf_config->number_of_channels || !rf_config->datarate) {
return -1;
}
rf_config->ofdm_option = ws_get_ofdm_option_using_phy_mode_id(phy_mode_id);
rf_config->ofdm_mcs = ws_get_ofdm_mcs_using_phy_mode_id(phy_mode_id);
rf_config->fec = ws_get_fsk_fec_enabled_using_phy_mode_id(phy_mode_id);
rf_config->modulation_index = ws_get_modulation_index_using_phy_mode_id(phy_mode_id);
rf_config->ofdm_option = ws_phy_get_ofdm_option_using_phy_mode_id(phy_mode_id);
rf_config->ofdm_mcs = ws_phy_get_ofdm_mcs_using_phy_mode_id(phy_mode_id);
rf_config->fec = ws_phy_get_fsk_fec_enabled_using_phy_mode_id(phy_mode_id);
rf_config->modulation_index = ws_phy_get_modulation_index_using_phy_mode_id(phy_mode_id);
return 0;
}

Expand Down Expand Up @@ -1942,7 +1910,7 @@ static int ws_bootstrap_set_rf_config(protocol_interface_info_entry_t *cur, phy_
// Enable MAC mode switch when base PHY mode ID could be found, otherwise disable the feature
uint8_t phy_mode_id = cur->ws_info->hopping_schdule.phy_mode_id;
if (phy_mode_id == 255) {
phy_mode_id = ws_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
phy_mode_id = ws_phy_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
}
if (!phy_mode_id) {
cur->mac_api->mac_mode_switch_resolver_set(cur->mac_api, NULL, phy_mode_id);
Expand Down Expand Up @@ -1974,10 +1942,10 @@ static int ws_bootstrap_operating_mode_resolver(protocol_interface_info_entry_t
memset(rf_config, 0, sizeof(phy_rf_channel_configuration_s));
rf_config->fec = false;
rf_config->modulation = M_2FSK;
rf_config->datarate = ws_get_datarate_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
rf_config->modulation_index = ws_get_modulation_index_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
rf_config->datarate = ws_phy_get_datarate_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
rf_config->modulation_index = ws_phy_get_modulation_index_using_operating_mode(cur->ws_info->hopping_schdule.operating_mode);
rf_config->channel_0_center_frequency = (uint32_t)cur->ws_info->hopping_schdule.ch0_freq * 100000;
rf_config->channel_spacing = ws_decode_channel_spacing(cur->ws_info->hopping_schdule.channel_spacing);
rf_config->channel_spacing = ws_phy_decode_channel_spacing(cur->ws_info->hopping_schdule.channel_spacing);
rf_config->number_of_channels = cur->ws_info->hopping_schdule.number_of_channels;
return 0;
}
Expand All @@ -1989,7 +1957,7 @@ int ws_bootstrap_set_domain_rf_config(protocol_interface_info_entry_t *cur)

uint8_t phy_mode_id = cur->ws_info->hopping_schdule.phy_mode_id;
if (phy_mode_id == 255) {
phy_mode_id = ws_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
phy_mode_id = ws_phy_convert_operating_mode_to_phy_mode_id(cur->ws_info->hopping_schdule.operating_mode);
}

if (!phy_mode_id || ws_bootstrap_phy_mode_resolver(cur->mac_api, phy_mode_id, &rf_config)) {
Expand Down Expand Up @@ -2963,7 +2931,7 @@ static void ws_set_asynch_channel_list(protocol_interface_info_entry_t *cur, asy
uint16_t channel_number = cur->ws_info->cfg->fhss.fhss_uc_fixed_channel;
async_req->channel_list.channel_mask[channel_number / 32] = 1U << (channel_number % 32);
} else {
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, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
ws_common_generate_channel_list(async_req->channel_list.channel_mask, cur->ws_info->hopping_schdule.number_of_channels, cur->ws_info->hopping_schdule.regulatory_domain, cur->ws_info->hopping_schdule.operating_class, cur->ws_info->hopping_schdule.channel_plan_id);
}

async_req->channel_list.channel_page = CHANNEL_PAGE_10;
Expand Down
8 changes: 1 addition & 7 deletions source/6LoWPAN/ws/ws_bootstrap_6lbr.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,7 @@
static int8_t ws_bootstrap_6lbr_fhss_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;
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));

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_ws_configuration_t fhss_configuration = ws_common_get_current_fhss_configuration(cur);
//GET BSI from BBR module
fhss_configuration.bsi = ws_bbr_bsi_generate(cur);
ws_fhss_configure_channel_masks(cur, &fhss_configuration);
Expand Down
Loading

0 comments on commit 50ecc3d

Please sign in to comment.