@@ -78,6 +78,8 @@ static bool ws_bootstrap_state_wait_rpl(struct protocol_interface_info_entry *cu
78
78
static int8_t ws_bootsrap_event_trig (ws_bootsrap_event_type_e event_type , int8_t interface_id , arm_library_event_priority_e priority , void * event_data );
79
79
80
80
static bool ws_bootstrap_neighbor_info_request (struct protocol_interface_info_entry * interface , const uint8_t * mac_64 , llc_neighbour_req_t * neighbor_buffer , bool request_new );
81
+ static uint16_t ws_bootstrap_route_cost_calculate (protocol_interface_info_entry_t * cur );
82
+ static uint16_t ws_bootstrap_get_min_rank_inc (protocol_interface_info_entry_t * cur );
81
83
82
84
mac_neighbor_table_entry_t * ws_bootstrap_mac_neighbor_add (struct protocol_interface_info_entry * interface , const uint8_t * src64 )
83
85
{
@@ -208,6 +210,9 @@ static int8_t ws_enable_fhss(protocol_interface_info_entry_t *cur)
208
210
if (ns_fhss_set_neighbor_info_fp (fhss_api , & ws_get_neighbor_info )) {
209
211
return -1 ;
210
212
}
213
+ if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
214
+ ns_fhss_ws_set_hop_count (fhss_api , 0 );
215
+ }
211
216
cur -> ws_info -> fhss_api = fhss_api ;
212
217
return 0 ;
213
218
}
@@ -979,6 +984,15 @@ static void ws_bootstrap_rpl_callback(rpl_event_t event, void *handle)
979
984
if (event == RPL_EVENT_DAO_DONE ) {
980
985
// Trigger statemachine check
981
986
cur -> bootsrap_state_machine_cnt = 1 ;
987
+ uint16_t own_rank = ws_bootstrap_route_cost_calculate (cur );
988
+ uint16_t rank_inc = ws_bootstrap_get_min_rank_inc (cur );
989
+ if (own_rank == 0xffff || rank_inc == 0xffff ) {
990
+ return ;
991
+ }
992
+ // Calculate own hop count. This method gets inaccurate when hop count increases.
993
+ uint8_t own_hop = (own_rank - rank_inc ) / rank_inc ;
994
+ ns_fhss_ws_set_hop_count (cur -> ws_info -> fhss_api , own_hop );
995
+
982
996
} else if (event == RPL_EVENT_LOCAL_REPAIR_NO_MORE_DIS ) {
983
997
/*
984
998
* RPL goes to passive mode, but does not require any extra changed
@@ -1158,20 +1172,40 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur
1158
1172
1159
1173
ws_llc_asynch_request (cur , & async_req );
1160
1174
}
1161
- static uint16_t ws_bootstrap_route_cost_calculate (protocol_interface_info_entry_t * cur )
1162
- {
1163
- // Find selected parent from RPL
1164
1175
1176
+ static struct rpl_instance * ws_get_rpl_instance (protocol_interface_info_entry_t * cur )
1177
+ {
1178
+ if (!cur || !cur -> rpl_domain ) {
1179
+ return NULL ;
1180
+ }
1165
1181
struct rpl_instance * best_instance = NULL ;
1166
-
1167
1182
ns_list_foreach (struct rpl_instance , instance , & cur -> rpl_domain -> instances ) {
1168
1183
best_instance = instance ;
1169
1184
// Select best grounded and lowest rank? But there should be only one really
1170
1185
}
1171
- if (!best_instance ) {
1186
+ return best_instance ;
1187
+ }
1188
+
1189
+ static uint16_t ws_bootstrap_route_cost_calculate (protocol_interface_info_entry_t * cur )
1190
+ {
1191
+ struct rpl_instance * rpl_instance = ws_get_rpl_instance (cur );
1192
+ if (!rpl_instance ) {
1193
+ return 0xffff ;
1194
+ }
1195
+ return rpl_control_current_rank (rpl_instance );
1196
+ }
1197
+
1198
+ static uint16_t ws_bootstrap_get_min_rank_inc (protocol_interface_info_entry_t * cur )
1199
+ {
1200
+ struct rpl_instance * rpl_instance = ws_get_rpl_instance (cur );
1201
+ if (!rpl_instance ) {
1202
+ return 0xffff ;
1203
+ }
1204
+ struct rpl_dodag_info_t dodag_info ;
1205
+ if (!rpl_control_read_dodag_info (rpl_instance , & dodag_info )) {
1172
1206
return 0xffff ;
1173
1207
}
1174
- return rpl_control_current_rank ( best_instance ) ;
1208
+ return dodag_info . dag_min_hop_rank_inc ;
1175
1209
}
1176
1210
1177
1211
static void ws_bootstrap_pan_advert (protocol_interface_info_entry_t * cur )
0 commit comments