4646#include "Common_Protocols/ipv6_constants.h"
4747#include "6LoWPAN/ws/ws_common_defines.h"
4848#include "Service_Libs/Trickle/trickle.h"
49+ #include "Service_Libs/fhss/channel_list.h"
4950#include "6LoWPAN/ws/ws_common_defines.h"
5051#include "6LoWPAN/ws/ws_llc.h"
5152#include "6LoWPAN/ws/ws_neighbor_class.h"
@@ -249,26 +250,45 @@ static int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur)
249250
250251 return 0 ;
251252}
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+ }
252274
253275static int8_t ws_fhss_enable (protocol_interface_info_entry_t * cur )
254276{
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 );
257278
258- if (!fhss_api || !fhss_configuration ) {
279+ if (!cur -> ws_info -> fhss_api || !fhss_configuration ) {
259280 return -1 ;
260281 }
261282 // Set the LLC information to follow the actual fhss settings
262283 ws_bootstrap_llc_hopping_update (cur ,fhss_configuration );
263284
264285 // 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 )) {
266287 return -1 ;
267288 }
268289 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 );
270291 }
271- cur -> ws_info -> fhss_api = fhss_api ;
272292 return 0 ;
273293}
274294
@@ -281,16 +301,10 @@ static void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry
281301 fhss_ws_configuration_t fhss_configuration ;
282302 memcpy (& fhss_configuration , ns_fhss_ws_configuration_get (cur -> ws_info -> fhss_api ), sizeof (fhss_ws_configuration_t ));
283303
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+ */
294308 // Learn broadcast information from selected parent
295309 fhss_configuration .bsi = neighbor_info -> ws_neighbor -> fhss_data .bc_timing_info .broadcast_schedule_id ;
296310 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)
368382 tr_error ("fhss initialization failed" );
369383 return -3 ;
370384 }
385+ // Save FHSS api
386+ cur -> ws_info -> fhss_api = ns_sw_mac_get_fhss_api (cur -> mac_api );
371387
372388 addr_interface_set_ll64 (cur , NULL );
373389 cur -> nwk_nd_re_scan_count = 0 ;
@@ -715,19 +731,21 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
715731 cur -> ws_info -> pan_information .pan_version = pan_version ;
716732 memcpy (cur -> ws_info -> gtkhash ,gtkhash_ptr ,32 );
717733
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-
723734 if (!cur -> ws_info -> configuration_learned ) {
724735 // Generate own hopping schedules Follow first parent broadcast and plans and also use same unicast dwell
736+ tr_info ("learn network configuration" );
725737 cur -> ws_info -> configuration_learned = true;
726738 // return to state machine after 1-2 s
727739 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
728745 ws_bootstrap_primary_parent_set (cur , & neighbor_info );
729746 }
730747
748+
731749}
732750
733751static 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)
10411059 return ret_val ;
10421060}
10431061
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+
10441072static void ws_bootstrap_mac_activate (protocol_interface_info_entry_t * cur , uint16_t channel , uint16_t panid , bool coordinator )
10451073{
10461074 mlme_start_t start_req ;
@@ -1199,14 +1227,7 @@ static void ws_bootstrap_network_discovery_configure(protocol_interface_info_ent
11991227 cur -> ws_info -> network_pan_id = 0xffff ;
12001228
12011229 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 );
12101231
12111232 //Set Network names, Pan information configure, hopping schedule & GTKHash
12121233 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)
14791500
14801501 if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
14811502 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 );
14821505 cur -> ws_info -> network_pan_id = randLIB_get_random_in_range (0 ,0xfffd );
14831506 cur -> ws_info -> pan_information .pan_size = 0 ;
14841507 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)
14881511 cur -> ws_info -> pan_information .version = WS_FAN_VERSION_1_0 ;
14891512 ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
14901513 cur -> ws_info -> pan_version_timer = PAN_VERSION_LIFETIME ;
1514+ // Set default parameters for FHSS when starting a discovery
14911515 ws_bootstrap_fhss_activate (cur );
14921516 ws_bootstrap_set_test_key (cur );
14931517 ws_bootstrap_event_operation_start (cur );
0 commit comments