Skip to content

Commit

Permalink
Implemented unregistering FHSS from MAC. FHSS deleted in ifdown call. (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso authored Jan 9, 2020
1 parent eabca17 commit 11c486f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
7 changes: 7 additions & 0 deletions nanostack/sw_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ extern int8_t ns_sw_mac_virtual_client_unregister(struct mac_api_s *api);
*/
extern int ns_sw_mac_fhss_register(struct mac_api_s *mac_api, struct fhss_api *fhss_api);

/**
* @brief Unregister FHSS API instance from given software MAC instance.
* @param mac_api MAC instance.
* @return 0 on success, -1 on fail.
*/
extern int ns_sw_mac_fhss_unregister(struct mac_api_s *mac_api);

/**
* @brief Request registered FHSS API instance from software MAC instance.
* @param mac_api MAC instance.
Expand Down
27 changes: 7 additions & 20 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,7 @@ static void ws_bootstrap_llc_hopping_update(struct protocol_interface_info_entry
static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
{
fhss_api_t *fhss_api = ns_sw_mac_get_fhss_api(cur->mac_api);

if (!fhss_api || (fhss_api && cur->ws_info->fhss_owner)) {
if (!fhss_api) {
// When FHSS doesn't exist yet, create one
fhss_ws_configuration_t fhss_configuration;
memset(&fhss_configuration, 0, sizeof(fhss_ws_configuration_t));
Expand All @@ -440,26 +439,11 @@ static int8_t ws_fhss_initialize(protocol_interface_info_entry_t *cur)
fhss_configuration.ws_bc_channel_function = (fhss_ws_channel_functions)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_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
if (!fhss_api) {
fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
if (!fhss_api) {
tr_error("fhss create failed");
return -1;
}
ns_sw_mac_fhss_register(cur->mac_api, fhss_api);
cur->ws_info->fhss_owner = true;
} else {
//Configuration set
ns_fhss_ws_configuration_set(cur->ws_info->fhss_api, &fhss_configuration);

if (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER) {
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, 0);
} else {
//Clear OWN HOP
ns_fhss_ws_set_hop_count(cur->ws_info->fhss_api, 0xff);
}
return -1;
}
ns_sw_mac_fhss_register(cur->mac_api, fhss_api);
} else {
// Read defaults from the configuration to help FHSS testing
const fhss_ws_configuration_t *fhss_configuration = ns_fhss_ws_configuration_get(fhss_api);
Expand Down Expand Up @@ -810,6 +794,9 @@ static int8_t ws_bootstrap_down(protocol_interface_info_entry_t *cur)
tr_info("Wi-SUN ifdown");
// Reset MAC for safe upper layer memory free
protocol_mac_reset(cur);
ns_sw_mac_fhss_unregister(cur->mac_api);
ns_fhss_delete(cur->ws_info->fhss_api);
cur->ws_info->fhss_api = NULL;
// Reset WS information
// ws_common_reset(cur)
ws_llc_reset(cur);
Expand Down
1 change: 0 additions & 1 deletion source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ typedef struct ws_info_s {
bool trickle_pa_running: 1;
bool trickle_pcs_running: 1;
bool trickle_pc_running: 1;
bool fhss_owner: 1;
ws_pending_key_index_t pending_key_index_info;
// default fhss parameters for this device
uint8_t fhss_uc_dwell_interval;
Expand Down
14 changes: 14 additions & 0 deletions source/MAC/IEEE802_15_4/sw_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ int ns_sw_mac_fhss_register(mac_api_t *mac_api, fhss_api_t *fhss_api)
return 0;
}

int ns_sw_mac_fhss_unregister(mac_api_t *mac_api)
{
if (!mac_api) {
return -1;
}
// Get a pointer to MAC setup structure
protocol_interface_rf_mac_setup_s *mac_setup = get_sw_mac_ptr_by_mac_api(mac_api);
if (!mac_setup) {
return -1;
}
mac_setup->fhss_api = NULL;
return 0;
}

struct fhss_api *ns_sw_mac_get_fhss_api(struct mac_api_s *mac_api)
{
if (!mac_api) {
Expand Down
2 changes: 2 additions & 0 deletions source/Service_Libs/fhss/fhss_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ int8_t fhss_disable(fhss_structure_t *fhss_structure)
}
fhss_structure->fhss_api->synch_state_set(fhss_structure->fhss_api, FHSS_UNSYNCHRONIZED, 0);
ns_dyn_mem_free(fhss_structure->bs);
ns_dyn_mem_free(fhss_structure->ws->tr51_channel_table);
ns_dyn_mem_free(fhss_structure->ws->tr51_output_table);
ns_dyn_mem_free(fhss_structure->ws);
ns_dyn_mem_free(fhss_structure);
fhss_struct = 0;
Expand Down
8 changes: 7 additions & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,11 @@ static void fhss_event_timer_cb(int8_t timer_id, uint16_t slots)
{
(void) slots;
uint16_t queue_size = 0;
fhss_structure_t *fhss_structure = fhss_get_object_with_timer_id(timer_id);

fhss_structure_t *fhss_structure = fhss_get_object_with_timer_id(timer_id);
if (!fhss_structure) {
return;
}

if (fhss_structure->ws->is_on_bc_channel == true) {
queue_size = fhss_structure->callbacks.read_tx_queue_size(fhss_structure->fhss_api, true);
Expand Down Expand Up @@ -407,6 +410,9 @@ static int16_t fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_stat
}
} else if (fhss_state == FHSS_UNSYNCHRONIZED) {
fhss_structure->ws->synchronization_time = 0;
eventOS_callback_timer_stop(fhss_structure->fhss_event_timer);
fhss_stop_timer(fhss_structure, fhss_unicast_handler);
fhss_stop_timer(fhss_structure, fhss_broadcast_handler);
}

fhss_structure->fhss_state = fhss_state;
Expand Down

0 comments on commit 11c486f

Please sign in to comment.