46
46
#include "Common_Protocols/ipv6_constants.h"
47
47
#include "6LoWPAN/ws/ws_common_defines.h"
48
48
#include "Service_Libs/Trickle/trickle.h"
49
+ #include "Service_Libs/fhss/channel_list.h"
49
50
#include "6LoWPAN/ws/ws_common_defines.h"
50
51
#include "6LoWPAN/ws/ws_llc.h"
51
52
#include "6LoWPAN/ws/ws_neighbor_class.h"
@@ -249,26 +250,45 @@ static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur)
249
250
250
251
return 0 ;
251
252
}
253
+ static int8_t ws_fhss_discovery_configure (protocol_interface_info_entry_t * cur )
254
+ {
255
+ // Read configuration of existing FHSS and start using the default values for any network
256
+ fhss_ws_configuration_t fhss_configuration = {0 };
257
+ if (ns_fhss_ws_configuration_get (cur -> ws_info -> fhss_api )) {
258
+ memcpy (& fhss_configuration , ns_fhss_ws_configuration_get (cur -> ws_info -> fhss_api ), sizeof (fhss_ws_configuration_t ));
259
+ }
260
+
261
+ fhss_configuration .fhss_uc_dwell_interval = 0 ;
262
+ fhss_configuration .ws_channel_function = WS_FIXED_CHANNEL ;
263
+ fhss_configuration .fhss_bc_dwell_interval = 0 ;
264
+ fhss_configuration .fhss_broadcast_interval = 0 ;
265
+ cur -> ws_info -> hopping_schdule .fixed_channel = randLIB_get_random_in_range (0 ,cur -> ws_info -> hopping_schdule .number_of_channels );
266
+ memset (fhss_configuration .channel_mask , 0 , sizeof (uint32_t ) * 8 );
267
+ channel_list_set_channel (fhss_configuration .channel_mask , cur -> ws_info -> hopping_schdule .fixed_channel , true);
268
+
269
+ ns_fhss_ws_configuration_set (cur -> ws_info -> fhss_api ,& fhss_configuration );
270
+ ws_bootstrap_llc_hopping_update (cur ,& fhss_configuration );
271
+
272
+ return 0 ;
273
+ }
252
274
253
275
static int8_t ws_fhss_enable (protocol_interface_info_entry_t * cur )
254
276
{
255
- fhss_api_t * fhss_api = ns_sw_mac_get_fhss_api (cur -> mac_api );
256
- const fhss_ws_configuration_t * fhss_configuration = ns_fhss_ws_configuration_get (fhss_api );
277
+ const fhss_ws_configuration_t * fhss_configuration = ns_fhss_ws_configuration_get (cur -> ws_info -> fhss_api );
257
278
258
- if (!fhss_api || !fhss_configuration ) {
279
+ if (!cur -> ws_info -> fhss_api || !fhss_configuration ) {
259
280
return -1 ;
260
281
}
261
282
// Set the LLC information to follow the actual fhss settings
262
283
ws_bootstrap_llc_hopping_update (cur ,fhss_configuration );
263
284
264
285
// Set neighbor info callback
265
- if (ns_fhss_set_neighbor_info_fp (fhss_api , & ws_get_neighbor_info )) {
286
+ if (ns_fhss_set_neighbor_info_fp (cur -> ws_info -> fhss_api , & ws_get_neighbor_info )) {
266
287
return -1 ;
267
288
}
268
289
if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
269
- ns_fhss_ws_set_hop_count (fhss_api , 0 );
290
+ ns_fhss_ws_set_hop_count (cur -> ws_info -> fhss_api , 0 );
270
291
}
271
- cur -> ws_info -> fhss_api = fhss_api ;
272
292
return 0 ;
273
293
}
274
294
@@ -281,16 +301,10 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
281
301
fhss_ws_configuration_t fhss_configuration ;
282
302
memcpy (& fhss_configuration , ns_fhss_ws_configuration_get (cur -> ws_info -> fhss_api ), sizeof (fhss_ws_configuration_t ));
283
303
284
- // unicast information is only followed from parent if fixed channel is selected
285
- if (neighbor_info -> ws_neighbor -> fhss_data .uc_timing_info .unicast_channel_function == WS_FIXED_CHANNEL ) {
286
- cur -> ws_info -> hopping_schdule .fixed_channel = neighbor_info -> ws_neighbor -> fhss_data .uc_timing_info .fixed_channel ;
287
- fhss_configuration .ws_channel_function = WS_FIXED_CHANNEL ;
288
- tr_info ("attaching to fixed channel network following configurtion" );
289
- } else if (fhss_configuration .ws_channel_function == WS_FIXED_CHANNEL ) {
290
- // fixed channel cannot be mixed with other channel functions as it messes the broadcast schedule
291
- fhss_configuration .ws_channel_function = WS_DH1CF ;
292
- tr_info ("attaching channel hopping network changing to hopping" );
293
- }
304
+ fhss_configuration .ws_channel_function = neighbor_info -> ws_neighbor -> fhss_data .uc_timing_info .unicast_channel_function ;
305
+ cur -> ws_info -> hopping_schdule .fixed_channel = neighbor_info -> ws_neighbor -> fhss_data .uc_timing_info .fixed_channel ;
306
+ /* Learning different unicast is not working currently at fhss network follows border router
307
+ */
294
308
// Learn broadcast information from selected parent
295
309
fhss_configuration .bsi = neighbor_info -> ws_neighbor -> fhss_data .bc_timing_info .broadcast_schedule_id ;
296
310
fhss_configuration .fhss_bc_dwell_interval = neighbor_info -> ws_neighbor -> fhss_data .bc_timing_info .broadcast_dwell_interval ;
@@ -368,6 +382,8 @@ static int8_t ws_bootstrap_up(protocol_interface_info_entry_t *cur)
368
382
tr_error ("fhss initialization failed" );
369
383
return -3 ;
370
384
}
385
+ // Save FHSS api
386
+ cur -> ws_info -> fhss_api = ns_sw_mac_get_fhss_api (cur -> mac_api );
371
387
372
388
addr_interface_set_ll64 (cur , NULL );
373
389
cur -> nwk_nd_re_scan_count = 0 ;
@@ -715,19 +731,21 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
715
731
cur -> ws_info -> pan_information .pan_version = pan_version ;
716
732
memcpy (cur -> ws_info -> gtkhash ,gtkhash_ptr ,32 );
717
733
718
- if (neighbor_info .neighbor -> link_role == PRIORITY_PARENT_NEIGHBOUR ) {
719
- // RPL priority parent configuration we must update FHSS data
720
- ws_bootstrap_primary_parent_set (cur , & neighbor_info );
721
- }
722
-
723
734
if (!cur -> ws_info -> configuration_learned ) {
724
735
// Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell
736
+ tr_info ("learn network configuration" );
725
737
cur -> ws_info -> configuration_learned = true;
726
738
// return to state machine after 1-2 s
727
739
cur -> bootsrap_state_machine_cnt = randLIB_get_random_in_range (10 ,20 );
740
+ // enable frequency hopping for unicast channel and start listening first neighbour
741
+ ws_fhss_set_defaults (cur );
742
+ ws_bootstrap_primary_parent_set (cur , & neighbor_info );
743
+ } else if (neighbor_info .neighbor -> link_role == PRIORITY_PARENT_NEIGHBOUR ) {
744
+ // RPL priority parent configuration we must update FHSS data
728
745
ws_bootstrap_primary_parent_set (cur , & neighbor_info );
729
746
}
730
747
748
+
731
749
}
732
750
733
751
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 )
@@ -1041,6 +1059,16 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
1041
1059
return ret_val ;
1042
1060
}
1043
1061
1062
+ int ws_bootstrap_restart (int8_t interface_id )
1063
+ {
1064
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (interface_id );
1065
+ if (!cur || !cur -> ws_info ) {
1066
+ return -1 ;
1067
+ }
1068
+ ws_bootstrap_event_discovery_start (cur );
1069
+ return 0 ;
1070
+ }
1071
+
1044
1072
static void ws_bootstrap_mac_activate (protocol_interface_info_entry_t * cur , uint16_t channel , uint16_t panid , bool coordinator )
1045
1073
{
1046
1074
mlme_start_t start_req ;
@@ -1199,14 +1227,7 @@ static void ws_bootstrap_network_discovery_configure(protocol_interface_info_ent
1199
1227
cur -> ws_info -> network_pan_id = 0xffff ;
1200
1228
1201
1229
ws_common_regulatory_domain_config (cur );
1202
-
1203
- // Set default schedules for discovery
1204
- cur -> ws_info -> hopping_schdule .fhss_uc_dwell_interval = WS_FHSS_UC_DWELL_INTERVAL ;
1205
- cur -> ws_info -> hopping_schdule .fhss_broadcast_interval = WS_FHSS_BC_INTERVAL ;
1206
- cur -> ws_info -> hopping_schdule .fhss_bc_dwell_interval = WS_FHSS_BC_DWELL_INTERVAL ;
1207
- // By default, uses fixed channel
1208
- cur -> ws_info -> hopping_schdule .channel_function = WS_FIXED_CHANNEL ;
1209
- cur -> ws_info -> hopping_schdule .fixed_channel = randLIB_get_random_in_range (11 ,25 );
1230
+ ws_fhss_discovery_configure (cur );
1210
1231
1211
1232
//Set Network names, Pan information configure, hopping schedule & GTKHash
1212
1233
ws_llc_set_network_name (cur , (uint8_t * )cur -> ws_info -> network_name , strlen (cur -> ws_info -> network_name ));
@@ -1479,6 +1500,8 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
1479
1500
1480
1501
if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
1481
1502
tr_debug ("Border router start network" );
1503
+ // Randomize fixed channel. Only used if channel plan is fixed
1504
+ cur -> ws_info -> hopping_schdule .fixed_channel = randLIB_get_random_in_range (0 ,cur -> ws_info -> hopping_schdule .number_of_channels );
1482
1505
cur -> ws_info -> network_pan_id = randLIB_get_random_in_range (0 ,0xfffd );
1483
1506
cur -> ws_info -> pan_information .pan_size = 0 ;
1484
1507
cur -> ws_info -> pan_information .pan_version = randLIB_get_random_in_range (0 ,0xffff );
@@ -1488,6 +1511,7 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
1488
1511
cur -> ws_info -> pan_information .version = WS_FAN_VERSION_1_0 ;
1489
1512
ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
1490
1513
cur -> ws_info -> pan_version_timer = PAN_VERSION_LIFETIME ;
1514
+ // Set default parameters for FHSS when starting a discovery
1491
1515
ws_bootstrap_fhss_activate (cur );
1492
1516
ws_bootstrap_set_test_key (cur );
1493
1517
ws_bootstrap_event_operation_start (cur );
0 commit comments