@@ -97,13 +97,14 @@ static void ws_bootstrap_nw_frame_counter_set(protocol_interface_info_entry_t *c
97
97
static void ws_bootstrap_nw_frame_counter_read (protocol_interface_info_entry_t * cur , uint32_t * counter , uint8_t slot );
98
98
static void ws_bootstrap_nw_info_updated (protocol_interface_info_entry_t * interface_ptr , uint16_t pan_id , char * network_name );
99
99
static void ws_bootstrap_authentication_completed (protocol_interface_info_entry_t * cur , auth_result_e result , uint8_t * target_eui_64 );
100
+ static const uint8_t * ws_bootstrap_authentication_next_target (protocol_interface_info_entry_t * cur , const uint8_t * previous_eui_64 , uint16_t * pan_id );
100
101
static void ws_bootstrap_pan_version_increment (protocol_interface_info_entry_t * cur );
101
102
static ws_nud_table_entry_t * ws_nud_entry_discover (protocol_interface_info_entry_t * cur , void * neighbor );
102
103
static void ws_nud_entry_remove (protocol_interface_info_entry_t * cur , mac_neighbor_table_entry_t * entry_ptr );
103
104
static bool ws_neighbor_entry_nud_notify (mac_neighbor_table_entry_t * entry_ptr , void * user_data );
104
105
105
106
static void ws_address_registration_update (protocol_interface_info_entry_t * interface , const uint8_t addr [16 ]);
106
-
107
+ static int8_t ws_bootstrap_neighbor_set ( protocol_interface_info_entry_t * cur , parent_info_t * parent_ptr );
107
108
108
109
static void ws_bootstrap_candidate_table_reset (protocol_interface_info_entry_t * cur );
109
110
static parent_info_t * ws_bootstrap_candidate_parent_get (struct protocol_interface_info_entry * cur , const uint8_t * addr , bool create );
@@ -1129,7 +1130,7 @@ static parent_info_t *ws_bootstrap_candidate_parent_allocate(protocol_interface_
1129
1130
return entry ;
1130
1131
}
1131
1132
1132
- static void ws_bootstrap_candidate_parent_free (protocol_interface_info_entry_t * cur , uint8_t * addr )
1133
+ static void ws_bootstrap_candidate_parent_free (protocol_interface_info_entry_t * cur , const uint8_t * addr )
1133
1134
{
1134
1135
ns_list_foreach_safe (parent_info_t , entry , & cur -> ws_info -> parent_list_reserved ) {
1135
1136
if (memcmp (entry -> addr , addr , 8 ) == 0 ) {
@@ -1986,7 +1987,7 @@ int ws_bootstrap_init(int8_t interface_id, net_6lowpan_mode_e bootstrap_mode)
1986
1987
ret_val = -4 ;
1987
1988
goto init_fail ;
1988
1989
}
1989
- if (ws_pae_controller_cb_register (cur , & ws_bootstrap_authentication_completed , & ws_bootstrap_nw_key_set , & ws_bootstrap_nw_key_clear , & ws_bootstrap_nw_key_index_set , & ws_bootstrap_nw_frame_counter_set , & ws_bootstrap_nw_frame_counter_read , & ws_bootstrap_pan_version_increment , & ws_bootstrap_nw_info_updated ) < 0 ) {
1990
+ if (ws_pae_controller_cb_register (cur , & ws_bootstrap_authentication_completed , & ws_bootstrap_authentication_next_target , & ws_bootstrap_nw_key_set , & ws_bootstrap_nw_key_clear , & ws_bootstrap_nw_key_index_set , & ws_bootstrap_nw_frame_counter_set , & ws_bootstrap_nw_frame_counter_read , & ws_bootstrap_pan_version_increment , & ws_bootstrap_nw_info_updated ) < 0 ) {
1990
1991
ret_val = -4 ;
1991
1992
goto init_fail ;
1992
1993
}
@@ -2759,6 +2760,24 @@ static void ws_bootstrap_authentication_completed(protocol_interface_info_entry_
2759
2760
}
2760
2761
}
2761
2762
2763
+ static const uint8_t * ws_bootstrap_authentication_next_target (protocol_interface_info_entry_t * cur , const uint8_t * previous_eui_64 , uint16_t * pan_id )
2764
+ {
2765
+ ws_bootstrap_candidate_parent_free (cur , previous_eui_64 );
2766
+
2767
+ // Gets best target
2768
+ parent_info_t * parent_info = ws_bootstrap_candidate_parent_get_best (cur );
2769
+ if (parent_info ) {
2770
+ /* On failure still continues with the new parent, and on next call,
2771
+ will try to set the neighbor again */
2772
+ ws_bootstrap_neighbor_set (cur , parent_info );
2773
+ * pan_id = parent_info -> pan_id ;
2774
+ return parent_info -> addr ;
2775
+ }
2776
+
2777
+ // If no targets found, retries the last one
2778
+ return previous_eui_64 ;
2779
+ }
2780
+
2762
2781
// Start configuration learning
2763
2782
static void ws_bootstrap_start_configuration_learn (protocol_interface_info_entry_t * cur )
2764
2783
{
@@ -3148,6 +3167,34 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
3148
3167
}
3149
3168
}
3150
3169
3170
+ static int8_t ws_bootstrap_neighbor_set (protocol_interface_info_entry_t * cur , parent_info_t * parent_ptr )
3171
+ {
3172
+ uint16_t pan_id = cur -> ws_info -> network_pan_id ;
3173
+
3174
+ // Add EAPOL neighbor
3175
+ cur -> ws_info -> network_pan_id = parent_ptr -> pan_id ;
3176
+ cur -> ws_info -> pan_information = parent_ptr -> pan_information ;
3177
+ cur -> ws_info -> pan_information .pan_version = 0 ; // This is learned from actual configuration
3178
+
3179
+ // If PAN ID changes, clear learned neighbors and activate FHSS
3180
+ if (pan_id != cur -> ws_info -> network_pan_id ) {
3181
+ ws_bootstrap_neighbor_list_clean (cur );
3182
+ ws_bootstrap_fhss_activate (cur );
3183
+ }
3184
+
3185
+ llc_neighbour_req_t neighbor_info ;
3186
+ if (!ws_bootstrap_neighbor_info_request (cur , parent_ptr -> addr , & neighbor_info , true)) {
3187
+ //Remove Neighbour and set Link setup back
3188
+ ns_list_remove (& cur -> ws_info -> parent_list_reserved , parent_ptr );
3189
+ ns_list_add_to_end (& cur -> ws_info -> parent_list_free , parent_ptr );
3190
+ return -1 ;
3191
+ }
3192
+
3193
+ ws_neighbor_class_neighbor_unicast_time_info_update (neighbor_info .ws_neighbor , & parent_ptr -> ws_utt , parent_ptr -> timestamp );
3194
+ ws_neighbor_class_neighbor_unicast_schedule_set (neighbor_info .ws_neighbor , & parent_ptr -> ws_us );
3195
+ return 0 ;
3196
+ }
3197
+
3151
3198
/*
3152
3199
* State machine
3153
3200
*
@@ -3174,23 +3221,10 @@ void ws_bootstrap_network_scan_process(protocol_interface_info_entry_t *cur)
3174
3221
}
3175
3222
tr_info ("selected parent:%s panid %u" , trace_array (selected_parent_ptr -> addr , 8 ), selected_parent_ptr -> pan_id );
3176
3223
3177
- // Add EAPOL neighbour
3178
- cur -> ws_info -> network_pan_id = selected_parent_ptr -> pan_id ;
3179
- cur -> ws_info -> pan_information = selected_parent_ptr -> pan_information ;
3180
- cur -> ws_info -> pan_information .pan_version = 0 ; // This is learned from actual configuration
3181
-
3182
- ws_bootstrap_fhss_activate (cur );
3183
- llc_neighbour_req_t neighbor_info ;
3184
- if (!ws_bootstrap_neighbor_info_request (cur , selected_parent_ptr -> addr , & neighbor_info , true)) {
3185
- //Remove Neighbour and set Link setup back
3186
- ns_list_remove (& cur -> ws_info -> parent_list_reserved , selected_parent_ptr );
3187
- ns_list_add_to_end (& cur -> ws_info -> parent_list_free , selected_parent_ptr );
3224
+ if (ws_bootstrap_neighbor_set (cur , selected_parent_ptr ) < 0 ) {
3188
3225
goto select_best_candidate ;
3189
3226
}
3190
3227
3191
- ws_neighbor_class_neighbor_unicast_time_info_update (neighbor_info .ws_neighbor , & selected_parent_ptr -> ws_utt , selected_parent_ptr -> timestamp );
3192
- ws_neighbor_class_neighbor_unicast_schedule_set (neighbor_info .ws_neighbor , & selected_parent_ptr -> ws_us );
3193
-
3194
3228
ws_pae_controller_set_target (cur , selected_parent_ptr -> pan_id , selected_parent_ptr -> addr ); // temporary!!! store since auth
3195
3229
ws_bootstrap_event_authentication_start (cur );
3196
3230
return ;
0 commit comments