@@ -134,6 +134,19 @@ static void ws_bootstrap_ffn_pan_information_store(struct protocol_interface_inf
134
134
return ;
135
135
}
136
136
137
+ void ws_bootstrap_ffn_network_discovery_configure (protocol_interface_info_entry_t * cur )
138
+ {
139
+ // Reset information to defaults
140
+ cur -> ws_info -> network_pan_id = 0xffff ;
141
+
142
+ ws_common_regulatory_domain_config (cur , & cur -> ws_info -> hopping_schdule );
143
+ ws_bootstrap_set_domain_rf_config (cur );
144
+ ws_fhss_configure (cur , true);
145
+
146
+ //Set Network names, Pan information configure, hopping schedule & GTKHash
147
+ ws_llc_set_network_name (cur , (uint8_t * )cur -> ws_info -> cfg -> gen .network_name , strlen (cur -> ws_info -> cfg -> gen .network_name ));
148
+ }
149
+
137
150
// Start network scan
138
151
static void ws_bootstrap_ffn_start_discovery (protocol_interface_info_entry_t * cur )
139
152
{
@@ -193,7 +206,6 @@ static void ws_bootstrap_ffn_start_discovery(protocol_interface_info_entry_t *cu
193
206
tr_info ("Making parent selection in %u s" , (cur -> bootsrap_state_machine_cnt / 10 ));
194
207
}
195
208
196
-
197
209
// Start configuration learning
198
210
static void ws_bootstrap_ffn_start_configuration_learn (protocol_interface_info_entry_t * cur )
199
211
{
@@ -214,6 +226,19 @@ static void ws_bootstrap_ffn_start_configuration_learn(protocol_interface_info_e
214
226
trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config_solicit , & cur -> ws_info -> trickle_params_pan_discovery );
215
227
}
216
228
229
+ static void ws_bootstrap_ffn_network_configuration_learn (protocol_interface_info_entry_t * cur )
230
+ {
231
+ tr_debug ("Start using PAN configuration" );
232
+
233
+ // Timing information can be modified here
234
+ ws_llc_set_pan_information_pointer (cur , & cur -> ws_info -> pan_information );
235
+ uint8_t * gtkhash = ws_pae_controller_gtk_hash_ptr_get (cur );
236
+ ws_llc_set_gtkhash (cur , gtkhash );
237
+ // TODO update own fhss schedules we are starting to follow first parent
238
+
239
+ return ;
240
+ }
241
+
217
242
static void ws_bootstrap_ffn_pan_advertisement_analyse_active (struct protocol_interface_info_entry * cur , ws_pan_information_t * pan_information )
218
243
{
219
244
/* In Active state
@@ -736,7 +761,7 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev
736
761
// Clear learned neighbours
737
762
ws_bootstrap_neighbor_list_clean (cur );
738
763
// Configure LLC for network discovery
739
- ws_bootstrap_network_discovery_configure (cur );
764
+ ws_bootstrap_ffn_network_discovery_configure (cur );
740
765
ws_bootstrap_fhss_activate (cur );
741
766
// Set retry configuration for discovery state
742
767
ws_bootstrap_configure_max_retries (cur , WS_MAX_FRAME_RETRIES_BOOTSTRAP );
@@ -802,4 +827,171 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev
802
827
}
803
828
}
804
829
830
+ /*
831
+ * Statemachine state functions
832
+ * */
833
+
834
+ static void ws_bootstrap_ffn_network_scan_process (protocol_interface_info_entry_t * cur )
835
+ {
836
+
837
+ parent_info_t * selected_parent_ptr ;
838
+
839
+ tr_debug ("analyze network discovery result" );
840
+
841
+ select_best_candidate :
842
+ selected_parent_ptr = ws_bootstrap_candidate_parent_get_best (cur );
843
+
844
+ if (!selected_parent_ptr ) {
845
+ // Configure LLC for network discovery
846
+ ws_bootstrap_ffn_network_discovery_configure (cur );
847
+ // randomize new channel and start MAC
848
+ ws_bootstrap_fhss_activate (cur );
849
+ // Next check will be after one trickle
850
+ uint32_t random_start = cur -> ws_info -> trickle_params_pan_discovery .Imin + randLIB_get_random_in_range (0 , cur -> ws_info -> trickle_params_pan_discovery .Imin );
851
+ if (random_start > 0xffff ) {
852
+ random_start = 0xffff ;
853
+ }
854
+ cur -> bootsrap_state_machine_cnt = random_start ;
855
+
856
+ tr_info ("Making parent selection in %u s" , (cur -> bootsrap_state_machine_cnt / 10 ));
857
+ return ;
858
+ }
859
+ tr_info ("selected parent:%s panid %u" , trace_array (selected_parent_ptr -> addr , 8 ), selected_parent_ptr -> pan_id );
860
+
861
+ if (ws_bootstrap_neighbor_set (cur , selected_parent_ptr , false) < 0 ) {
862
+ goto select_best_candidate ;
863
+ }
864
+
865
+ ws_pae_controller_set_target (cur , selected_parent_ptr -> pan_id , selected_parent_ptr -> addr ); // temporary!!! store since auth
866
+ ws_bootstrap_event_authentication_start (cur );
867
+ return ;
868
+ }
869
+
870
+ static void ws_bootstrap_ffn_configure_process (protocol_interface_info_entry_t * cur )
871
+ {
872
+
873
+ if (cur -> ws_info -> configuration_learned ) {
874
+ ws_bootstrap_ffn_network_configuration_learn (cur );
875
+ ws_bootstrap_event_operation_start (cur );
876
+ return ;
877
+ }
878
+ return ;
879
+ }
880
+
881
+ void ws_bootstrap_ffn_rpl_wait_process (protocol_interface_info_entry_t * cur )
882
+ {
883
+
884
+ if (cur -> ws_info -> rpl_state == RPL_EVENT_DAO_DONE ) {
885
+ // RPL routing is ready
886
+ cur -> ws_info -> connected_time = cur -> ws_info -> uptime ;
887
+ ws_bootstrap_event_routing_ready (cur );
888
+ } else if (!rpl_control_have_dodag (cur -> rpl_domain )) {
889
+ // RPL not ready send DIS message if possible
890
+ if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER ) {
891
+ // TODO Multicast DIS should be sent only if no DIO heard for some time
892
+ rpl_control_transmit_dis (cur -> rpl_domain , cur , 0 , 0 , NULL , 0 , ADDR_LINK_LOCAL_ALL_RPL_NODES );
893
+ }
894
+ // set timer for next DIS
895
+ cur -> bootsrap_state_machine_cnt = randLIB_get_random_in_range (WS_RPL_DIS_TIMEOUT / 2 , WS_RPL_DIS_TIMEOUT );
896
+ }
897
+ return ;
898
+ }
899
+
900
+
901
+ /*
902
+ * State machine
903
+ */
904
+
905
+ void ws_bootstrap_ffn_state_machine (protocol_interface_info_entry_t * cur )
906
+ {
907
+
908
+ switch (cur -> nwk_bootstrap_state ) {
909
+ case ER_WAIT_RESTART :
910
+ tr_debug ("WS SM:Wait for startup" );
911
+ ws_bootstrap_event_discovery_start (cur );
912
+ break ;
913
+ case ER_ACTIVE_SCAN :
914
+ tr_debug ("WS SM:Active Scan" );
915
+ ws_bootstrap_ffn_network_scan_process (cur );
916
+ break ;
917
+ case ER_SCAN :
918
+ tr_debug ("WS SM:configuration Scan" );
919
+ ws_bootstrap_ffn_configure_process (cur );
920
+ break ;
921
+ case ER_PANA_AUTH :
922
+ tr_info ("authentication start" );
923
+ // Advertisements stopped during the EAPOL
924
+ ws_bootstrap_asynch_trickle_stop (cur );
925
+ ws_fhss_configure (cur , false);
926
+ int8_t new_default = cur -> ws_info -> weakest_received_rssi - 1 ;
927
+ if ((new_default < CCA_DEFAULT_DBM ) && (new_default >= CCA_LOW_LIMIT ) && (new_default <= CCA_HIGH_LIMIT )) {
928
+ // Restart automatic CCA threshold using weakest received RSSI as new default
929
+ mac_helper_start_auto_cca_threshold (cur -> id , cur -> ws_info -> hopping_schdule .number_of_channels , cur -> ws_info -> weakest_received_rssi - 1 , CCA_HIGH_LIMIT , CCA_LOW_LIMIT );
930
+ }
931
+ ws_bootstrap_start_authentication (cur );
932
+ break ;
933
+ case ER_RPL_SCAN :
934
+ tr_debug ("WS SM:Wait RPL to contact DODAG root" );
935
+ ws_bootstrap_ffn_rpl_wait_process (cur );
936
+ break ;
937
+ case ER_BOOTSRAP_DONE :
938
+ tr_debug ("WS SM:Bootstrap Done" );
939
+ // Bootstrap_done event to application
940
+ nwk_bootsrap_state_update (ARM_NWK_BOOTSTRAP_READY , cur );
941
+ break ;
942
+ case ER_RPL_NETWORK_LEAVING :
943
+ tr_debug ("WS SM:RPL Leaving ready trigger discovery" );
944
+ ws_bootstrap_event_discovery_start (cur );
945
+ break ;
946
+ default :
947
+ tr_warn ("WS SM:Invalid state %d" , cur -> nwk_bootstrap_state );
948
+ }
949
+ }
950
+
951
+ void ws_bootstrap_ffn_seconds_timer (protocol_interface_info_entry_t * cur , uint32_t seconds )
952
+ {
953
+ /* Border router keep alive check
954
+ */
955
+ if (cur -> ws_info -> pan_timeout_timer ) {
956
+ // PAN version timer running
957
+ if (cur -> ws_info -> pan_timeout_timer > seconds ) {
958
+ cur -> ws_info -> pan_timeout_timer -= seconds ;
959
+ if (cur -> ws_info -> pan_timeout_timer < cur -> ws_info -> cfg -> timing .pan_timeout / 10 ) {
960
+ /* pan timeout is closing need to verify that DAO is tested before the pan times out.
961
+ This will give some extra time for RPL to find better parents.
962
+ Border router liveliness can be checked from version number change or from successful DAO registrations
963
+ in this case there has not been any version number changes during this PAN lifetime.
964
+ */
965
+ rpl_control_dao_timeout (cur -> rpl_domain , 20 );
966
+ }
967
+ } else {
968
+ // Border router has timed out
969
+ //Clear Timeout timer
970
+ cur -> ws_info -> pan_timeout_timer = 0 ;
971
+ tr_warn ("Border router has timed out" );
972
+ ws_bootstrap_event_disconnect (cur , WS_FAST_DISCONNECT );
973
+ }
974
+ }
975
+ if (cur -> ws_info -> aro_registration_timer ) {
976
+ if (cur -> ws_info -> aro_registration_timer > seconds ) {
977
+ cur -> ws_info -> aro_registration_timer -= seconds ;
978
+ } else {
979
+ // Update all addressess. This function will update the timer value if needed
980
+ cur -> ws_info -> aro_registration_timer = 0 ;
981
+ ws_address_registration_update (cur , NULL );
982
+ }
983
+ }
984
+
985
+ if (cur -> ws_info -> ws_bsi_block .block_time ) {
986
+ if (cur -> ws_info -> ws_bsi_block .block_time > seconds ) {
987
+ cur -> ws_info -> ws_bsi_block .block_time -= seconds ;
988
+ } else {
989
+ //Clear A BSI blokker
990
+ cur -> ws_info -> ws_bsi_block .block_time = 0 ;
991
+ cur -> ws_info -> ws_bsi_block .old_bsi = 0 ;
992
+ }
993
+ }
994
+ }
995
+
996
+
805
997
#endif //HAVE_WS_BORDER_ROUTER && HAVE_WS
0 commit comments