Skip to content

Commit 2d063d3

Browse files
Mika TervonenMika Tervonen
authored andcommitted
Moved State machine and timer functions to own files
Reorganized bootstrap file a bit to place function related to others in closer proximity Moved Wi-SUN FFN functions to own files and renamed
1 parent edb8bec commit 2d063d3

File tree

9 files changed

+480
-355
lines changed

9 files changed

+480
-355
lines changed

source/6LoWPAN/ws/ws_bootstrap.c

Lines changed: 169 additions & 351 deletions
Large diffs are not rendered by default.

source/6LoWPAN/ws/ws_bootstrap.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ void ws_bootstrap_test_procedure_trigger_exec(protocol_interface_info_entry_t *c
145145

146146
void ws_bootstrap_network_down(protocol_interface_info_entry_t *cur);
147147

148+
// Bootstrap functions
149+
void ws_bootstrap_start_authentication(protocol_interface_info_entry_t *cur);
150+
148151

149152
// Bootstrap state machine state Functions
150153
bool ws_bootstrap_state_discovery(struct protocol_interface_info_entry *cur);
@@ -160,15 +163,19 @@ void ws_bootstrap_candidate_parent_store(parent_info_t *parent, const struct mcp
160163
void ws_bootstrap_candidate_table_reset(protocol_interface_info_entry_t *cur);
161164
parent_info_t *ws_bootstrap_candidate_parent_get(struct protocol_interface_info_entry *cur, const uint8_t *addr, bool create);
162165
void ws_bootstrap_candidate_parent_sort(struct protocol_interface_info_entry *cur, parent_info_t *new_entry);
166+
parent_info_t *ws_bootstrap_candidate_parent_get_best(protocol_interface_info_entry_t *cur);
163167

164168
void ws_bootstrap_primary_parent_set(struct protocol_interface_info_entry *cur, struct llc_neighbour_req *neighbor_info, ws_parent_synch_e synch_req);
165169
void ws_bootstrap_parent_confirm(protocol_interface_info_entry_t *cur, struct rpl_instance *instance);
166170
bool ws_bootstrap_neighbor_info_request(struct protocol_interface_info_entry *interface, const uint8_t *mac_64, struct llc_neighbour_req *neighbor_buffer, bool request_new);
167171
void ws_bootstrap_neighbor_list_clean(struct protocol_interface_info_entry *interface);
172+
int8_t ws_bootstrap_neighbor_set(protocol_interface_info_entry_t *cur, parent_info_t *parent_ptr, bool clear_list);
168173
void ws_nud_table_reset(protocol_interface_info_entry_t *cur);
174+
void ws_address_registration_update(protocol_interface_info_entry_t *interface, const uint8_t addr[16]);
169175

170176

171177
void ws_bootstrap_configure_csma_ca_backoffs(protocol_interface_info_entry_t *cur, uint8_t max_backoffs, uint8_t min_be, uint8_t max_be);
178+
int8_t ws_fhss_configure(protocol_interface_info_entry_t *cur, bool discovery);
172179
void ws_fhss_configure_channel_masks(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration);
173180
int8_t ws_fhss_set_defaults(protocol_interface_info_entry_t *cur, fhss_ws_configuration_t *fhss_configuration);
174181
void ws_bootstrap_fhss_activate(protocol_interface_info_entry_t *cur);
@@ -190,7 +197,6 @@ void ws_bootstrap_packet_congestion_init(protocol_interface_info_entry_t *cur);
190197

191198
void ws_bootstrap_asynch_trickle_stop(protocol_interface_info_entry_t *cur);
192199
void ws_bootstrap_advertise_start(protocol_interface_info_entry_t *cur);
193-
void ws_bootstrap_network_discovery_configure(protocol_interface_info_entry_t *cur);
194200

195201
void ws_bootstrap_network_start(protocol_interface_info_entry_t *cur);
196202

source/6LoWPAN/ws/ws_bootstrap_6lbr.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,45 @@ void ws_bootstrap_6lbr_event_handler(protocol_interface_info_entry_t *cur, arm_e
439439
}
440440
}
441441

442+
void ws_bootstrap_6lbr_state_machine(protocol_interface_info_entry_t *cur)
443+
{
444+
445+
switch (cur->nwk_bootstrap_state) {
446+
case ER_WAIT_RESTART:
447+
tr_debug("WS SM:Wait for startup");
448+
ws_bootstrap_event_discovery_start(cur);
449+
break;
450+
case ER_ACTIVE_SCAN:
451+
tr_debug("WS SM:Active Scan");
452+
break;
453+
case ER_SCAN:
454+
tr_debug("WS SM:configuration Scan");
455+
break;
456+
case ER_PANA_AUTH:
457+
tr_info("authentication start");
458+
break;
459+
case ER_RPL_SCAN:
460+
tr_debug("WS SM:Wait RPL to contact DODAG root");
461+
break;
462+
case ER_BOOTSRAP_DONE:
463+
tr_debug("WS SM:Bootstrap Done");
464+
// Bootstrap_done event to application
465+
nwk_bootsrap_state_update(ARM_NWK_BOOTSTRAP_READY, cur);
466+
break;
467+
case ER_RPL_NETWORK_LEAVING:
468+
tr_debug("WS SM:RPL Leaving ready trigger discovery");
469+
ws_bootstrap_event_discovery_start(cur);
470+
break;
471+
default:
472+
tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state);
473+
}
474+
}
475+
476+
void ws_bootstrap_6lbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
477+
{
478+
(void)cur;
479+
(void)seconds;
480+
}
481+
482+
442483
#endif //HAVE_WS_BORDER_ROUTER && HAVE_WS

source/6LoWPAN/ws/ws_bootstrap_6lbr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
void ws_bootstrap_6lbr_asynch_ind(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, uint8_t message_type);
2424
void ws_bootstrap_6lbr_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message);
2525
void ws_bootstrap_6lbr_event_handler(protocol_interface_info_entry_t *cur, arm_event_s *event);
26+
void ws_bootstrap_6lbr_state_machine(protocol_interface_info_entry_t *cur);
27+
void ws_bootstrap_6lbr_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);
2628

2729
#define wisun_mode_border_router(cur) (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER)
2830

@@ -31,6 +33,8 @@ void ws_bootstrap_6lbr_event_handler(protocol_interface_info_entry_t *cur, arm_e
3133
#define ws_bootstrap_6lbr_asynch_ind(cur, data, ie_ext, message_type) ((void) 0)
3234
#define ws_bootstrap_6lbr_asynch_confirm(interface, asynch_message) ((void) 0)
3335
#define ws_bootstrap_6lbr_event_handler(cur, event) ((void) 0)
36+
#define ws_bootstrap_6lbr_state_machine(cur) ((void) 0)
37+
#define ws_bootstrap_6lbr_seconds_timer(cur, seconds) ((void) 0)
3438

3539
#define wisun_mode_border_router(cur) (false)
3640

source/6LoWPAN/ws/ws_bootstrap_ffn.c

Lines changed: 194 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,19 @@ static void ws_bootstrap_ffn_pan_information_store(struct protocol_interface_inf
134134
return;
135135
}
136136

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+
137150
// Start network scan
138151
static void ws_bootstrap_ffn_start_discovery(protocol_interface_info_entry_t *cur)
139152
{
@@ -193,7 +206,6 @@ static void ws_bootstrap_ffn_start_discovery(protocol_interface_info_entry_t *cu
193206
tr_info("Making parent selection in %u s", (cur->bootsrap_state_machine_cnt / 10));
194207
}
195208

196-
197209
// Start configuration learning
198210
static void ws_bootstrap_ffn_start_configuration_learn(protocol_interface_info_entry_t *cur)
199211
{
@@ -214,6 +226,19 @@ static void ws_bootstrap_ffn_start_configuration_learn(protocol_interface_info_e
214226
trickle_inconsistent_heard(&cur->ws_info->trickle_pan_config_solicit, &cur->ws_info->trickle_params_pan_discovery);
215227
}
216228

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+
217242
static void ws_bootstrap_ffn_pan_advertisement_analyse_active(struct protocol_interface_info_entry *cur, ws_pan_information_t *pan_information)
218243
{
219244
/* In Active state
@@ -736,7 +761,7 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev
736761
// Clear learned neighbours
737762
ws_bootstrap_neighbor_list_clean(cur);
738763
// Configure LLC for network discovery
739-
ws_bootstrap_network_discovery_configure(cur);
764+
ws_bootstrap_ffn_network_discovery_configure(cur);
740765
ws_bootstrap_fhss_activate(cur);
741766
// Set retry configuration for discovery state
742767
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
802827
}
803828
}
804829

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+
805997
#endif //HAVE_WS_BORDER_ROUTER && HAVE_WS

source/6LoWPAN/ws/ws_bootstrap_ffn.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
void ws_bootstrap_ffn_asynch_ind(struct protocol_interface_info_entry *cur, const struct mcps_data_ind_s *data, const struct mcps_data_ie_list *ie_ext, uint8_t message_type);
2424
void ws_bootstrap_ffn_asynch_confirm(struct protocol_interface_info_entry *interface, uint8_t asynch_message);
2525
void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_event_s *event);
26+
void ws_bootstrap_ffn_state_machine(protocol_interface_info_entry_t *cur);
27+
void ws_bootstrap_ffn_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds);
2628

2729
#define wisun_mode_router(cur) (cur->bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER)
2830

@@ -31,6 +33,8 @@ void ws_bootstrap_ffn_event_handler(protocol_interface_info_entry_t *cur, arm_ev
3133
#define ws_bootstrap_ffn_asynch_ind(cur, data, ie_ext, message_type) ((void) 0)
3234
#define ws_bootstrap_ffn_asynch_confirm(interface, asynch_message) ((void) 0)
3335
#define ws_bootstrap_ffn_event_handler(cur, event) ((void) 0)
36+
#define ws_bootstrap_ffn_state_machine(cur) ((void) 0)
37+
#define ws_bootstrap_ffn_seconds_timer(cur, seconds) ((void) 0)
3438

3539
#define wisun_mode_router(cur) (false)
3640

source/6LoWPAN/ws/ws_bootstrap_lfn.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,43 @@ void ws_bootstrap_lfn_event_handler(protocol_interface_info_entry_t *cur, arm_ev
130130
}
131131
}
132132

133+
void ws_bootstrap_lfn_state_machine(protocol_interface_info_entry_t *cur)
134+
{
135+
136+
switch (cur->nwk_bootstrap_state) {
137+
case ER_WAIT_RESTART:
138+
tr_debug("WS SM:Wait for startup");
139+
break;
140+
case ER_ACTIVE_SCAN:
141+
tr_debug("WS SM:Active Scan");
142+
break;
143+
case ER_SCAN:
144+
tr_debug("WS SM:configuration Scan");
145+
break;
146+
case ER_PANA_AUTH:
147+
tr_info("authentication start");
148+
// Advertisements stopped during the EAPOL
149+
break;
150+
case ER_RPL_SCAN:
151+
tr_debug("WS SM:Wait RPL to contact DODAG root");
152+
break;
153+
case ER_BOOTSRAP_DONE:
154+
tr_debug("WS SM:Bootstrap Done");
155+
// Bootstrap_done event to application
156+
break;
157+
case ER_RPL_NETWORK_LEAVING:
158+
tr_debug("WS SM:RPL Leaving ready trigger discovery");
159+
break;
160+
default:
161+
tr_warn("WS SM:Invalid state %d", cur->nwk_bootstrap_state);
162+
}
163+
}
164+
165+
void ws_bootstrap_lfn_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
166+
{
167+
(void)cur;
168+
(void)seconds;
169+
}
170+
171+
133172
#endif //HAVE_WS_BORDER_ROUTER && HAVE_WS

0 commit comments

Comments
 (0)