Skip to content

Commit 3980870

Browse files
author
Jarkko Paso
committed
WS: Enable FHSS in bootstrap
1 parent ff72d95 commit 3980870

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "randLIB.h"
2727
#include "common_functions.h"
2828
#include "mac_common_defines.h"
29+
#include "sw_mac.h"
2930
#include "NWK_INTERFACE/Include/protocol.h"
3031
#include "6LoWPAN/Bootstraps/protocol_6lowpan.h"
3132
#include "6LoWPAN/Bootstraps/protocol_6lowpan_interface.h"
@@ -137,8 +138,23 @@ static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t
137138
return eventOS_event_send(&event);
138139
}
139140

141+
static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
142+
{
143+
fhss_ws_configuration_t fhss_configuration;
144+
fhss_configuration.bsi = cur->ws_info->hopping_schdule.fhss_bsi;
145+
memcpy(fhss_configuration.channel_mask, cur->ws_info->hopping_schdule.channel_mask, sizeof(uint32_t) * 8);
146+
fhss_configuration.fhss_bc_dwell_interval = cur->ws_info->hopping_schdule.fhss_bc_dwell_interval;
147+
fhss_configuration.fhss_broadcast_interval = cur->ws_info->hopping_schdule.fhss_broadcast_interval;
148+
fhss_configuration.fhss_uc_dwell_interval = cur->ws_info->hopping_schdule.fhss_uc_dwell_interval;
149+
fhss_configuration.ws_channel_function = cur->ws_info->hopping_schdule.channel_function;
150+
fhss_api_t *fhss_api = ns_fhss_ws_create(&fhss_configuration, cur->ws_info->fhss_timer_ptr);
151+
if (fhss_api) {
152+
ns_sw_mac_fhss_register(cur->mac_api, fhss_api);
153+
}
154+
return 0;
155+
}
140156

141-
static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
157+
static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
142158
{
143159
int8_t ret_val = -1;
144160

@@ -150,7 +166,7 @@ static int8_t ws_bootsrap_event_trig(ws_bootsrap_event_type_e event_type, int8_t
150166
tr_debug("Interface not yet fully configured");
151167
return -5;
152168
}
153-
169+
ws_enable_fhss(cur);
154170

155171
addr_interface_set_ll64(cur, NULL);
156172
cur->nwk_nd_re_scan_count = 0;
@@ -921,7 +937,7 @@ static void ws_bootstrap_pan_advert_solicit(protocol_interface_info_entry_t *cur
921937
for (int i=0; i<8; i++) {
922938
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
923939
}
924-
async_req.channel_list.channel_page = CHANNEL_PAGE_0;
940+
async_req.channel_list.channel_page = CHANNEL_PAGE_10;
925941
async_req.security.SecurityLevel = 0;
926942

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

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

964980
ws_llc_asynch_request(cur, &async_req);
@@ -980,7 +996,7 @@ static void ws_bootstrap_pan_config(protocol_interface_info_entry_t *cur)
980996
for (int i=0; i<8; i++) {
981997
async_req.channel_list.channel_mask[i] = cur->ws_info->hopping_schdule.channel_mask[i];
982998
}
983-
async_req.channel_list.channel_page = CHANNEL_PAGE_0;
999+
async_req.channel_list.channel_page = CHANNEL_PAGE_10;
9841000
async_req.security.SecurityLevel = mac_helper_default_security_level_get(cur);
9851001
async_req.security.KeyIdMode = mac_helper_default_security_key_id_mode_get(cur);
9861002
async_req.security.KeyIndex = mac_helper_default_key_index_get(cur);

source/6LoWPAN/ws/ws_common.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@
2828

2929
#ifdef HAVE_WS
3030
#define TRACE_GROUP "wscm"
31+
32+
static int8_t ws_generate_channel_list(ws_hopping_schedule_t *hopping_schedule)
33+
{
34+
for (uint8_t i=0; i<hopping_schedule->number_of_channels; i++) {
35+
hopping_schedule->channel_mask[0+(i/32)] |= (1 << (i%32));
36+
}
37+
return 0;
38+
}
39+
3140
int8_t ws_common_regulatory_domain_config(protocol_interface_info_entry_t *cur)
3241
{
3342
cur->ws_info->hopping_schdule.channel_plan = 0;
@@ -108,6 +117,8 @@ int8_t ws_common_regulatory_domain_config(protocol_interface_info_entry_t *cur)
108117
} else {
109118
return -1;
110119
}
120+
// Note: doesn't work for Brazil region
121+
ws_generate_channel_list(&cur->ws_info->hopping_schdule);
111122
return 0;
112123
}
113124

@@ -135,8 +146,8 @@ int8_t ws_common_allocate_and_init(protocol_interface_info_entry_t *cur)
135146
cur->ws_info->hopping_schdule.fhss_uc_dwell_interval = 250;
136147
cur->ws_info->hopping_schdule.fhss_broadcast_interval = 800;
137148
cur->ws_info->hopping_schdule.fhss_bc_dwell_interval = 200;
138-
139-
memset(&cur->ws_info->hopping_schdule.channel_mask,0xff,sizeof(cur->ws_info->hopping_schdule.channel_mask));
149+
// By default, uses fixed channel
150+
cur->ws_info->hopping_schdule.channel_function = WS_FIXED_CHANNEL;
140151

141152
return 0;
142153
}

source/6LoWPAN/ws/ws_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "ns_types.h"
2222
#include "fhss_api.h"
2323
#include "fhss_config.h"
24+
#include "net_fhss.h"
2425
#include "6LoWPAN/ws/ws_common_defines.h"
2526
#include "6LoWPAN/ws/ws_neighbor_class.h"
2627

source/Service_Libs/fhss/fhss_ws.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ static void fhss_ws_synch_state_set_callback(const fhss_api_t *api, fhss_states
181181
if (!fhss_structure) {
182182
return;
183183
}
184-
if (fhss_state == FHSS_SYNCHRONIZED) {
184+
if ((fhss_state == FHSS_SYNCHRONIZED) && (fhss_structure->ws->fhss_configuration.ws_channel_function != WS_FIXED_CHANNEL)) {
185185
uint32_t fhss_broadcast_interval = fhss_structure->ws->fhss_configuration.fhss_broadcast_interval;
186186
uint8_t fhss_bc_dwell_interval = fhss_structure->ws->fhss_configuration.fhss_bc_dwell_interval;
187187
// Start broadcast schedule when BC intervals are known
@@ -242,6 +242,11 @@ static int fhss_ws_tx_handle_callback(const fhss_api_t *api, bool is_broadcast_a
242242
return 0;
243243
}
244244
if (fhss_structure->fhss_state == FHSS_SYNCHRONIZED) {
245+
// TODO: Waits for neighbor table support
246+
if (fhss_structure->ws->fhss_configuration.ws_channel_function == WS_FIXED_CHANNEL) {
247+
return -2;
248+
}
249+
245250
fhss_ws_neighbor_timing_info_t *neighbor_timing_info = fhss_structure->ws->fhss_configuration.get_neighbor_info(api, destination_address);
246251
if (!neighbor_timing_info) {
247252
return -1;

test/nanostack/unittest/service_libs/fhss_ws/test_fhss_ws.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ bool test_fhss_ws_tx_handle_callback()
208208
return false;
209209
}
210210
// Test when no neighbor info found
211+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
211212
fhss_common_stub.fhss_struct.fhss_state = DEFAULT_FHSS_STATE;
212213
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_no_neighbor_info;
213214
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) {
@@ -216,7 +217,7 @@ bool test_fhss_ws_tx_handle_callback()
216217
// Test fixed channel
217218
fhss_common_stub.fhss_struct.ws->fhss_configuration.get_neighbor_info = &app_get_neighbor_info;
218219
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_FIXED_CHANNEL;
219-
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) {
220+
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) {
220221
return false;
221222
}
222223
/* Test TR51 channel function
@@ -493,11 +494,12 @@ bool test_fhss_unicast_handler()
493494
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_bc_dwell_interval = 0;
494495
fhss_common_stub.fhss_struct.ws->fhss_configuration.fhss_broadcast_interval = 0;
495496
fhss_common_stub.fhss_struct.ws->uc_slot = fhss_common_stub.fhss_struct.number_of_channels - 1;
497+
fhss_common_stub.fhss_struct.ws->fhss_configuration.ws_channel_function = WS_TR51CF;
496498

497499
// Call state set just to get fhss_stub.callback
498500
enable_fhss_struct();
499501
fhss_common_stub.fhss_struct.fhss_api->synch_state_set(api, DEFAULT_FHSS_STATE, DEFAULT_PANID);
500-
if (fhss_common_stub.fhss_struct.rx_channel != DEFAULT_CHANNEL) {
502+
if (fhss_common_stub.fhss_struct.rx_channel != 3) {
501503
return false;
502504
}
503505
// Test when FHSS struct can be found

0 commit comments

Comments
 (0)