@@ -460,15 +460,15 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
460
460
return 0 ;
461
461
}
462
462
ipv6_route_t * route = ipv6_route_choose_next_hop (addr_data_ptr , this -> interface_id , NULL );
463
- if (!route || route -> prefix_len < 128 || !route -> on_link || route -> info .source != ROUTE_THREAD_PROXIED_DUA_HOST ) {
463
+ if (!route || route -> prefix_len < 128 || !route -> on_link || route -> info .source != ROUTE_THREAD_PROXIED_DUA_HOST || ! route -> info . info ) {
464
464
//address not in mesh
465
465
return 0 ;
466
466
}
467
467
if (thread_meshcop_tlv_data_get_uint16 (request_ptr -> payload_ptr , request_ptr -> payload_len , TMFCOP_TLV_RLOC16 , & rloc ) > 1 ) {
468
468
rloc_ptr = & rloc ;
469
469
}
470
470
471
- uint32_t last_transaction_time = 30 ;
471
+ uint32_t last_transaction_time = protocol_core_monotonic_time - (( thread_pbbr_dua_info_t * ) route -> info . info ) -> last_contact_time ;
472
472
uint8_t * ml_eid_ptr = & route -> prefix [8 ];// TODO MLEID needs to be stored in own structure route->info.info and support for dealloc made
473
473
474
474
// This address is valid in our MESH
@@ -477,6 +477,44 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
477
477
return 0 ;
478
478
}
479
479
480
+ static void thread_pbbr_pro_bb_ntf_process (protocol_interface_info_entry_t * cur , uint8_t * network_name_ptr , uint8_t network_name_len , uint8_t * ml_eid_ptr , uint8_t * addr_data_ptr , uint32_t last_transaction_time )
481
+ {
482
+ (void ) network_name_ptr ;
483
+ (void ) network_name_len ;
484
+ thread_pbbr_dua_info_t * mleid_dua_map ;
485
+ thread_pbbr_t * this = thread_border_router_find_by_service (cur -> id );
486
+ if (!this ) {
487
+ return ;
488
+ }
489
+ ipv6_route_t * route = thread_bbr_dua_entry_find (cur -> id , addr_data_ptr );
490
+ if (!route || !route -> info .info ) {
491
+ return ;
492
+ }
493
+ mleid_dua_map = route -> info .info ;
494
+ if (memcmp (mleid_dua_map -> mleid_ptr , ml_eid_ptr , 8 ) == 0 ) {
495
+ // matching ml-eid present in our dua map, device has roamed
496
+ if (last_transaction_time <= protocol_core_monotonic_time - mleid_dua_map -> last_contact_time ) {
497
+ // remove entry
498
+ goto remove_entry ;
499
+ } else {
500
+ thread_border_router_bb_ans_send (this , this -> pbbr_multicast_address , addr_data_ptr , ml_eid_ptr , protocol_core_monotonic_time - mleid_dua_map -> last_contact_time , thread_joiner_application_network_name_get (cur -> id ), NULL );
501
+ return ;
502
+ }
503
+ }
504
+
505
+ // duplicate dua address detected
506
+ // Address should be ML-prefix + MLeid TODO create spec issue
507
+ uint8_t destination_address [16 ];
508
+ thread_management_get_ml_prefix (cur -> id , destination_address );
509
+ memcpy (& destination_address [8 ], mleid_dua_map -> mleid_ptr , 8 );
510
+ thread_resolution_client_address_error (cur -> id , destination_address , addr_data_ptr , mleid_dua_map -> mleid_ptr );
511
+
512
+ remove_entry :
513
+ tr_info ("Remove dua registration for %s" , trace_ipv6 (addr_data_ptr ));
514
+ ipv6_route_delete (route -> prefix , route -> prefix_len , cur -> id , route -> info .next_hop_addr , ROUTE_THREAD_PROXIED_DUA_HOST );
515
+ return ;
516
+ }
517
+
480
518
static int thread_pbbr_dua_duplicate_address_detection (int8_t service_id , uint8_t * addr_data_ptr , uint8_t * ml_eid_ptr )
481
519
{
482
520
thread_pbbr_t * this = thread_border_router_find_by_service (service_id );
@@ -512,9 +550,6 @@ static int thread_pbbr_dua_duplicate_address_detection(int8_t service_id, uint8_
512
550
ipv6_route_delete (route -> prefix , route -> prefix_len , this -> interface_id , route -> info .next_hop_addr , ROUTE_THREAD_PROXIED_DUA_HOST );
513
551
}
514
552
return 0 ;
515
-
516
- // TODO check last transaction time for migrated device if this answer is newer delete entry
517
- // ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_HOST);
518
553
}
519
554
520
555
static int thread_pbbr_bb_ans_cb (int8_t service_id , uint8_t source_address [16 ], uint16_t source_port , sn_coap_hdr_s * request_ptr )
@@ -562,11 +597,7 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
562
597
563
598
// If rloc16 is present then a/an is sent to the thread device with the rloc
564
599
if (thread_tmfcop_tlv_data_get_uint16 (request_ptr -> payload_ptr , request_ptr -> payload_len , TMFCOP_TLV_RLOC16 , & rloc16 ) != 2 ) {
565
- // this is Pro active ANS to inform that device has moved in new network
566
- // This message was sent to multicast address
567
- // in spec there is checks for Last transaction time, but we always know that this message has zero and we have lower
568
- // TODO create function to process
569
- // Delete route to DUA as it is moved
600
+ thread_pbbr_pro_bb_ntf_process (cur ,network_name_ptr ,network_name_len ,ml_eid_ptr ,addr_data_ptr ,last_transaction_time );
570
601
return 0 ;
571
602
}
572
603
@@ -787,8 +818,10 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
787
818
tr_debug ("DUA.req addr:%s ml_eid:%s" , trace_array (addr_data_ptr , addr_len ), trace_array (ml_eid_ptr , ml_eid_len ));
788
819
789
820
entry_keep_alive = false;
790
- // TODO add ml_eid to structure saved in info pointer to detect duplicates
791
- if (thread_bbr_dua_entry_find (this -> interface_id , addr_data_ptr ) != NULL ) {
821
+ ipv6_route_t * route = thread_bbr_dua_entry_find (this -> interface_id , addr_data_ptr );
822
+
823
+ if ( route != NULL && route -> info .info != NULL ) {
824
+ ((thread_pbbr_dua_info_t * )route -> info .info )-> last_contact_time = protocol_core_monotonic_time ;
792
825
entry_keep_alive = true;
793
826
}
794
827
if (thread_bbr_dua_entry_add (this -> interface_id , addr_data_ptr , 0xFFFFFFFF , ml_eid_ptr ) != 0 ) {
@@ -803,8 +836,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
803
836
}
804
837
*/
805
838
806
- // Update entry timeout value and sequence number needs to be stored
807
-
808
839
if (entry_keep_alive ) {
809
840
// send proactive BB_ans.ntf
810
841
thread_border_router_bb_ans_send (this , this -> pbbr_multicast_address , addr_data_ptr , ml_eid_ptr , 0 , link_configuration_ptr -> name , NULL );
0 commit comments