@@ -319,7 +319,7 @@ static void ws_bootstrap_pan_advertisement_analyse_active(struct protocol_interf
319319 *
320320 */
321321
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 ) {
323323 trickle_consistent_heard (& cur -> ws_info -> trickle_pan_advertisement );
324324 } else {
325325 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
372372 if (memcmp (cur -> ws_info -> parent_info .addr , ADDR_UNSPECIFIED ,8 ) != 0 ) {
373373 //Decide which is better parent for authentication
374374 if (cur -> ws_info -> parent_info .link_quality > data -> mpduLinkQuality ) {
375+ tr_info ("EAPOL target dropped Lower link quality" );
375376 return ;
376377 }
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+
377386 }
378387 // Parent valid store information
379388 cur -> ws_info -> parent_info .ws_utt = * ws_utt ;
380389 // Saved from unicast IE
381390 cur -> ws_info -> parent_info .ws_us = * ws_us ;
382391
383392 // Saved from Pan information
384- cur -> ws_info -> parent_info .pan_configuration = pan_information ;
393+ cur -> ws_info -> parent_info .pan_information = pan_information ;
385394
386395 // Saved from message
387396 cur -> ws_info -> parent_info .timestamp = data -> timestamp ;
@@ -399,11 +408,13 @@ static void ws_bootstrap_pan_advertisement_analyse(struct protocol_interface_inf
399408 // Active state processing
400409 ws_bootstrap_pan_advertisement_analyse_active (cur , & pan_information );
401410
402- // TODO Learn routing cost per neighbour
403-
404411 // Learn latest network information
405412 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 ;
407418 }
408419}
409420
@@ -489,7 +500,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
489500 ws_neighbor_class_neighbor_broadcast_schedule_set (neighbor_info .ws_neighbor , & ws_bs_ie );
490501
491502 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 )) {
493504 // received version is lower se we need to reset the trickle
494505 tr_info ("older pan version heard" );
495506 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
504515 return ;
505516 }
506517 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 ) {
508519 // No new information
509520 return ;
510521 }
@@ -515,7 +526,7 @@ static void ws_bootstrap_pan_config_analyse(struct protocol_interface_info_entry
515526 tr_info ("Updated PAN configuration heard" );
516527
517528 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 ;
519530 memcpy (cur -> ws_info -> gtkhash ,gtkhash_ptr ,32 );
520531
521532 //Broadcast schedule
@@ -866,8 +877,8 @@ static void ws_bootstrap_network_information_learn(protocol_interface_info_entry
866877
867878 // Save network information
868879 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
871882
872883 // TODO create parent neighbour table entry for unicast schedule to enable authentication
873884
@@ -878,7 +889,7 @@ static void ws_bootstrap_network_configuration_learn(protocol_interface_info_ent
878889 tr_debug ("Start using PAN configuration" );
879890
880891 // 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 );
882893 ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
883894 // TODO update own fhss schedules we are starting to follow first parent
884895
@@ -952,7 +963,7 @@ static void ws_bootstrap_rpl_activate(protocol_interface_info_entry_t *cur)
952963
953964 cur -> ws_info -> rpl_state = 0xff ; // Set invalid state and learn from event
954965 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
956967 rpl_control_transmit_dis (cur -> rpl_domain , cur , 0 , 0 , NULL , 0 , ADDR_LINK_LOCAL_ALL_RPL_NODES );
957968 }
958969}
@@ -961,7 +972,7 @@ static void ws_bootstrap_network_start(protocol_interface_info_entry_t *cur)
961972{
962973 //Set Network names, Pan information configure, hopping schedule & GTKHash
963974 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 );
965976}
966977
967978static 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
10851096
10861097 ws_llc_asynch_request (cur , & async_req );
10871098}
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+ }
10881114
10891115static void ws_bootstrap_pan_advert (protocol_interface_info_entry_t * cur )
10901116{
@@ -1104,9 +1130,15 @@ static void ws_bootstrap_pan_advert(protocol_interface_info_entry_t *cur)
11041130
11051131 if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
11061132 // 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 );
11081139 }
11091140
1141+
11101142 ws_llc_asynch_request (cur , & async_req );
11111143}
11121144
@@ -1166,12 +1198,12 @@ static void ws_bootstrap_event_handler(arm_event_s *event)
11661198 if (cur -> bootsrap_mode == ARM_NWK_BOOTSRAP_MODE_6LoWPAN_BORDER_ROUTER ) {
11671199 tr_debug ("Border router start network" );
11681200 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 ;
11751207 cur -> ws_info -> hopping_schdule .channel_function = WS_FIXED_CHANNEL ;
11761208 ws_llc_set_gtkhash (cur , cur -> ws_info -> gtkhash );
11771209 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
13751407 // Border router has timed out
13761408 tr_debug ("Border router version number update" );
13771409 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 ++ ;
13791411 // Inconsistent for border router to make information distribute faster
13801412 trickle_inconsistent_heard (& cur -> ws_info -> trickle_pan_config ,& trickle_params_pan_configuration );
13811413 }
0 commit comments