Skip to content

Commit

Permalink
WS: Enable FHSS in bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
Jarkko Paso committed Mar 28, 2018
1 parent ff72d95 commit 3980870
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 11 deletions.
28 changes: 22 additions & 6 deletions source/6LoWPAN/ws/ws_bootstrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "randLIB.h"
#include "common_functions.h"
#include "mac_common_defines.h"
#include "sw_mac.h"
#include "NWK_INTERFACE/Include/protocol.h"
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
Expand Down Expand Up @@ -137,8 +138,23 @@ static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t
return eventOS_event_send(&event);
}

static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
{
fhss_ws_configuration_t fhss_configuration;
fhss_configuration.bsi = cur->ws_info->hopping_schdule.fhss_bsi;
memcpy(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.channel_mask, sizeof(uint32_t) * 8);
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->hopping_schdule.fhss_bc_dwell_interval;
fhss_configuration.fhss_broadcast_interval = cur->ws_info->hopping_schdule.fhss_broadcast_interval;
fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->hopping_schdule.fhss_uc_dwell_interval;
fhss_configuration.ws_channel_function = cur->ws_info->hopping_schdule.channel_function;
fhss_api_t *fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
if (fhss_api) {
ns_sw_mac_fhss_register(cur->mac_api, fhss_api);
}
return 0;
}

static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
{
int8_t ret_val = -1;

Expand All @@ -150,7 +166,7 @@ static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t
tr_debug("Interface not yet fully configured");
return -5;
}

ws_enable_fhss(cur);

addr_interface_set_ll64(cur, NULL);
cur->nwk_nd_re_scan_count = 0;
Expand Down Expand Up @@ -921,7 +937,7 @@ static void ws_bootstrap_pan_advert_solicit(protocol_interface_info_entry_t *cur
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}
async_req.channel_list.channel_page = CHANNEL_PAGE_0;
async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = 0;

ws_llc_asynch_request(cur, &async_req);
Expand All @@ -939,7 +955,7 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}
async_req.channel_list.channel_page = CHANNEL_PAGE_0;
async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = 0;

ws_llc_asynch_request(cur, &async_req);
Expand All @@ -958,7 +974,7 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}
async_req.channel_list.channel_page = CHANNEL_PAGE_0;
async_req.channel_list.channel_page = CHANNEL_PAGE_10;
async_req.security.SecurityLevel = 0;

ws_llc_asynch_request(cur, &async_req);
Expand All @@ -980,7 +996,7 @@ static void ws_bootstrap_pan_config(protocol_interface_info_entry_t *cur)
for (int i=0; i<8; i++) {
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
}
async_req.channel_list.channel_page = CHANNEL_PAGE_0;
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);
async_req.security.KeyIndex = mac_helper_default_key_index_get(cur);
Expand Down
15 changes: 13 additions & 2 deletions source/6LoWPAN/ws/ws_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@

#ifdef HAVE_WS
#define TRACE_GROUP "wscm"

static int8_t ws_generate_channel_list(ws_hopping_schedule_t *hopping_schedule)
{
for (uint8_t i=0; i<hopping_schedule->number_of_channels; i++) {
hopping_schedule->channel_mask[0+(i/32)] |= (1 << (i%32));
}
return 0;
}

int8_t ws_common_regulatory_domain_config(protocol_interface_info_entry_t *cur)
{
cur->ws_info->hopping_schdule.channel_plan = 0;
Expand Down Expand Up @@ -108,6 +117,8 @@ int8_t ws_common_regulatory_domain_config(protocol_interface_info_entry_t *cur)
} else {
return -1;
}
// Note: doesn't work for Brazil region
ws_generate_channel_list(&cur->ws_info->hopping_schdule);
return 0;
}

Expand Down Expand Up @@ -135,8 +146,8 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = 250;
cur->ws_info->hopping_schdule.fhss_broadcast_interval = 800;
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = 200;

memset(&cur->ws_info->hopping_schdule.channel_mask,0xff,sizeof(cur->ws_info->hopping_schdule.channel_mask));
// By default, uses fixed channel
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;

return 0;
}
Expand Down
1 change: 1 addition & 0 deletions source/6LoWPAN/ws/ws_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "ns_types.h"
#include "fhss_api.h"
#include "fhss_config.h"
#include "net_fhss.h"
#include "6LoWPAN/ws/ws_common_defines.h"
#include "6LoWPAN/ws/ws_neighbor_class.h"

Expand Down
7 changes: 6 additions & 1 deletion source/Service_Libs/fhss/fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states
if (!fhss_structure) {
return;
}
if (fhss_state == FHSS_SYNCHRONIZED) {
if ((fhss_state == FHSS_SYNCHRONIZED) && (fhss_structure->ws->fhss_configuration.ws_channel_function != WS_FIXED_CHANNEL)) {
uint32_t fhss_broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;
uint8_t fhss_bc_dwell_interval = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval;
// Start broadcast schedule when BC intervals are known
Expand Down Expand Up @@ -242,6 +242,11 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
return 0;
}
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
// TODO: Waits for neighbor table support
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
return -2;
}

fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->fhss_configuration.get_neighbor_info(api, destination_address);
if (!neighbor_timing_info) {
return -1;
Expand Down
6 changes: 4 additions & 2 deletions test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ bool test_fhss_ws_tx_handle_callback()
return false;
}
// Test when no neighbor info found
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
fhss_common_stub.fhss_struct.fhss_state = DEFAULT_FHSS_STATE;
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_no_neighbor_info;
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -1) {
Expand All @@ -216,7 +217,7 @@ bool test_fhss_ws_tx_handle_callback()
// Test fixed channel
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_get_neighbor_info;
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -1) {
if (fhss_common_stub.fhss_struct.fhss_api->tx_handle(api, DEFAULT_IS_BC_DEST, dest_address, DEFAULT_FRAME_TYPE, DEFAULT_FRAME_LENGTH, DEFAULT_PHY_HEAD_LENGTH, DEFAULT_PHY_TAIL_LENGTH, DEFAULT_TX_TIME) != -2) {
return false;
}
/* Test TR51 channel function
Expand Down Expand Up @@ -493,11 +494,12 @@ bool test_fhss_unicast_handler()
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 0;
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 0;
fhss_common_stub.fhss_struct.ws->uc_slot = fhss_common_stub.fhss_struct.number_of_channels - 1;
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;

// Call state set just to get fhss_stub.callback
enable_fhss_struct();
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
if (fhss_common_stub.fhss_struct.rx_channel != DEFAULT_CHANNEL) {
if (fhss_common_stub.fhss_struct.rx_channel != 3) {
return false;
}
// Test when FHSS struct can be found
Expand Down

0 comments on commit 3980870

Please sign in to comment.