@@ -319,7 +319,7 @@ static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interf
319
319
*
320
320
*/
321
321
322
- if (pan_information -> routing_cost <= cur -> ws_info -> pan_configuration .routing_cost ) {
322
+ if (pan_information -> routing_cost <= cur -> ws_info -> pan_information .routing_cost ) {
323
323
trickle_consistent_heard (& cur -> ws_info -> trickle_pan_advertisement );
324
324
} else {
325
325
trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_advertisement ,& trickle_params_pan_advertisement );
@@ -372,16 +372,25 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
372
372
if (memcmp (cur -> ws_info -> parent_info .addr , ADDR_UNSPECIFIED ,8 ) != 0 ) {
373
373
//Decide which is better parent for authentication
374
374
if (cur -> ws_info -> parent_info .link_quality > data -> mpduLinkQuality ) {
375
+ tr_info ("EAPOL target dropped Lower link quality" );
375
376
return ;
376
377
}
378
+
379
+ uint16_t pan_cost = (pan_information .routing_cost / PRC_WEIGHT_FACTOR ) + (pan_information .pan_size / PS_WEIGHT_FACTOR );
380
+ uint16_t current_pan_cost = (cur -> ws_info -> parent_info .pan_information .routing_cost / PRC_WEIGHT_FACTOR ) + (cur -> ws_info -> parent_info .pan_information .pan_size / PS_WEIGHT_FACTOR );
381
+ if (current_pan_cost < pan_cost ) {
382
+ tr_info ("EAPOL target dropped Higher Pan cost" );
383
+ return ;
384
+ }
385
+
377
386
}
378
387
// Parent valid store information
379
388
cur -> ws_info -> parent_info .ws_utt = * ws_utt ;
380
389
// Saved from unicast IE
381
390
cur -> ws_info -> parent_info .ws_us = * ws_us ;
382
391
383
392
// Saved from Pan information
384
- cur -> ws_info -> parent_info .pan_configuration = pan_information ;
393
+ cur -> ws_info -> parent_info .pan_information = pan_information ;
385
394
386
395
// Saved from message
387
396
cur -> ws_info -> parent_info .timestamp = data -> timestamp ;
@@ -399,11 +408,13 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
399
408
// Active state processing
400
409
ws_bootstrap_pan_advertisement_analyse_active (cur , & pan_information );
401
410
402
- // TODO Learn routing cost per neighbour
403
-
404
411
// Learn latest network information
405
412
if (cur -> bootsrap_mode != ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
406
- cur -> ws_info -> pan_configuration = pan_information ;
413
+ cur -> ws_info -> pan_information .pan_size = pan_information .pan_size ;
414
+ cur -> ws_info -> pan_information .routing_cost = pan_information .routing_cost ;
415
+ cur -> ws_info -> pan_information .rpl_routing_method = pan_information .rpl_routing_method ;
416
+ cur -> ws_info -> pan_information .use_parent_bs = pan_information .use_parent_bs ;
417
+ cur -> ws_info -> pan_information .version = pan_information .version ;
407
418
}
408
419
}
409
420
@@ -489,7 +500,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
489
500
ws_neighbor_class_neighbor_broadcast_schedule_set (neighbor_info .ws_neighbor , & ws_bs_ie );
490
501
491
502
if (cur -> ws_info -> configuration_learned &&
492
- common_serial_number_greater_16 (cur -> ws_info -> pan_configuration .pan_version , pan_version )) {
503
+ common_serial_number_greater_16 (cur -> ws_info -> pan_information .pan_version , pan_version )) {
493
504
// received version is lower se we need to reset the trickle
494
505
tr_info ("older pan version heard" );
495
506
trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config ,& trickle_params_pan_configuration );
@@ -504,7 +515,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
504
515
return ;
505
516
}
506
517
if (cur -> ws_info -> configuration_learned &&
507
- cur -> ws_info -> pan_configuration .pan_version == pan_version ) {
518
+ cur -> ws_info -> pan_information .pan_version == pan_version ) {
508
519
// No new information
509
520
return ;
510
521
}
@@ -515,7 +526,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
515
526
tr_info ("Updated PAN configuration heard" );
516
527
517
528
cur -> ws_info -> pan_version_timeout_timer = PAN_VERSION_TIMEOUT ;
518
- cur -> ws_info -> pan_configuration .pan_version = pan_version ;
529
+ cur -> ws_info -> pan_information .pan_version = pan_version ;
519
530
memcpy (cur -> ws_info -> gtkhash ,gtkhash_ptr ,32 );
520
531
521
532
//Broadcast schedule
@@ -866,8 +877,8 @@ static void ws_bootstrap_network_information_learn(protocol_interface_info_entry
866
877
867
878
// Save network information
868
879
cur -> ws_info -> network_pan_id = cur -> ws_info -> parent_info .pan_id ;
869
- cur -> ws_info -> pan_configuration = cur -> ws_info -> parent_info .pan_configuration ;
870
- cur -> ws_info -> pan_configuration .pan_version = 0 ; // This is learned from actual configuration
880
+ cur -> ws_info -> pan_information = cur -> ws_info -> parent_info .pan_information ;
881
+ cur -> ws_info -> pan_information .pan_version = 0 ; // This is learned from actual configuration
871
882
872
883
// TODO create parent neighbour table entry for unicast schedule to enable authentication
873
884
@@ -878,7 +889,7 @@ static void ws_bootstrap_network_configuration_learn(protocol_interface_info_ent
878
889
tr_debug ("Start using PAN configuration" );
879
890
880
891
// Timing information can be modified here
881
- ws_llc_set_pan_information_pointer (cur , & cur -> ws_info -> pan_configuration );
892
+ ws_llc_set_pan_information_pointer (cur , & cur -> ws_info -> pan_information );
882
893
ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
883
894
// TODO update own fhss schedules we are starting to follow first parent
884
895
@@ -952,7 +963,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
952
963
953
964
cur -> ws_info -> rpl_state = 0xff ; // Set invalid state and learn from event
954
965
if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_ROUTER ) {
955
- // TODO RPL should have function to reset DIS trickle and it should be called here
966
+ // TODO Multicast DIS should be sent only if no DIO heard for some time
956
967
rpl_control_transmit_dis (cur -> rpl_domain , cur , 0 , 0 , NULL , 0 , ADDR_LINK_LOCAL_ALL_RPL_NODES );
957
968
}
958
969
}
@@ -961,7 +972,7 @@ static void ws_bootstrap_network_start(protocol_interface_info_entry_t *cur)
961
972
{
962
973
//Set Network names, Pan information configure, hopping schedule & GTKHash
963
974
ws_llc_set_network_name (cur , (uint8_t * )cur -> ws_info -> network_name , strlen (cur -> ws_info -> network_name ));
964
- ws_llc_set_pan_information_pointer (cur , & cur -> ws_info -> pan_configuration );
975
+ ws_llc_set_pan_information_pointer (cur , & cur -> ws_info -> pan_information );
965
976
}
966
977
967
978
static void ws_bootstrap_network_discovery_configure (protocol_interface_info_entry_t * cur )
@@ -1085,6 +1096,21 @@ static void ws_bootstrap_pan_config_solicit(protocol_interface_info_entry_t *cur
1085
1096
1086
1097
ws_llc_asynch_request (cur , & async_req );
1087
1098
}
1099
+ static uint16_t ws_bootstrap_route_cost_calculate (protocol_interface_info_entry_t * cur )
1100
+ {
1101
+ // Find selected parent from RPL
1102
+
1103
+ struct rpl_instance * best_instance = NULL ;
1104
+
1105
+ ns_list_foreach (struct rpl_instance , instance , & cur -> rpl_domain -> instances ) {
1106
+ best_instance = instance ;
1107
+ // Select best grounded and lowest rank? But there should be only one really
1108
+ }
1109
+ if (!best_instance ) {
1110
+ return 0xffff ;
1111
+ }
1112
+ return rpl_control_current_rank (best_instance );
1113
+ }
1088
1114
1089
1115
static void ws_bootstrap_pan_advert (protocol_interface_info_entry_t * cur )
1090
1116
{
@@ -1104,9 +1130,15 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
1104
1130
1105
1131
if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
1106
1132
// Border routers write the NW size
1107
- cur -> ws_info -> pan_configuration .pan_size = ws_bbr_pan_size (cur );
1133
+ cur -> ws_info -> pan_information .pan_size = ws_bbr_pan_size (cur );
1134
+ cur -> ws_info -> pan_information .routing_cost = 0 ;
1135
+ } else {
1136
+ // Nodes need to calculate routing cost
1137
+ // PAN size is saved from latest PAN advertisement
1138
+ cur -> ws_info -> pan_information .routing_cost = ws_bootstrap_route_cost_calculate (cur );
1108
1139
}
1109
1140
1141
+
1110
1142
ws_llc_asynch_request (cur , & async_req );
1111
1143
}
1112
1144
@@ -1166,12 +1198,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
1166
1198
if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
1167
1199
tr_debug ("Border router start network" );
1168
1200
cur -> ws_info -> network_pan_id = randLIB_get_random_in_range (0 ,0xfffd );
1169
- cur -> ws_info -> pan_configuration .pan_size = 0 ;
1170
- cur -> ws_info -> pan_configuration .pan_version = randLIB_get_random_in_range (0 ,0xffff );
1171
- cur -> ws_info -> pan_configuration .routing_cost = 0 ;
1172
- cur -> ws_info -> pan_configuration .rpl_routing_method = true;
1173
- cur -> ws_info -> pan_configuration .use_parent_bs = true;
1174
- cur -> ws_info -> pan_configuration .version = WS_FAN_VERSION_1_0 ;
1201
+ cur -> ws_info -> pan_information .pan_size = 0 ;
1202
+ cur -> ws_info -> pan_information .pan_version = randLIB_get_random_in_range (0 ,0xffff );
1203
+ cur -> ws_info -> pan_information .routing_cost = 0 ;
1204
+ cur -> ws_info -> pan_information .rpl_routing_method = true;
1205
+ cur -> ws_info -> pan_information .use_parent_bs = true;
1206
+ cur -> ws_info -> pan_information .version = WS_FAN_VERSION_1_0 ;
1175
1207
cur -> ws_info -> hopping_schdule .channel_function = WS_FIXED_CHANNEL ;
1176
1208
ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
1177
1209
cur -> ws_info -> pan_version_timer = PAN_VERSION_LIFETIME ;
@@ -1375,7 +1407,7 @@ void ws_bootstrap_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t s
1375
1407
// Border router has timed out
1376
1408
tr_debug ("Border router version number update" );
1377
1409
cur -> ws_info -> pan_version_timer = PAN_VERSION_LIFETIME ;
1378
- cur -> ws_info -> pan_configuration .pan_version ++ ;
1410
+ cur -> ws_info -> pan_information .pan_version ++ ;
1379
1411
// Inconsistent for border router to make information distribute faster
1380
1412
trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config ,& trickle_params_pan_configuration );
1381
1413
}
0 commit comments