5151#include "6LoWPAN/Thread/thread_discovery.h"
5252#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
5353#include "6LoWPAN/Thread/thread_extension_constants.h"
54+ #include "6LoWPAN/Thread/thread_bbr_api_internal.h"
5455#include "NWK_INTERFACE/Include/protocol.h"
5556#include "Common_Protocols/ipv6.h"
5657
@@ -151,21 +152,6 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
151152 return this ;
152153}
153154
154- static duplicate_dua_tr_t * thread_border_router_dup_tr_create (int8_t interface_id , uint8_t * target_eid_ptr , sn_coap_hdr_s * request_ptr )
155- {
156- duplicate_dua_tr_t * this = ns_dyn_mem_alloc (sizeof (duplicate_dua_tr_t ));
157-
158- if (!this ) {
159- return NULL ;
160- }
161- ns_list_add_to_start (& duplicate_dua_tr_list , this );
162- memcpy (this -> target_eid , target_eid_ptr ,16 );
163- this -> interface_id = interface_id ;
164- this -> request_msg_id = request_ptr -> msg_id ;
165- this -> ttl = 2 ;
166- return this ;
167- }
168-
169155static void thread_border_router_dup_tr_delete (duplicate_dua_tr_t * this )
170156{
171157
@@ -422,7 +408,6 @@ static int thread_pbbr_nmkp_req_recv_cb(int8_t service_id, uint8_t source_addres
422408static int thread_pbbr_bb_qry_cb (int8_t service_id , uint8_t source_address [16 ], uint16_t source_port , sn_coap_hdr_s * request_ptr )
423409{
424410 (void )source_port ;
425- (void )source_address ;
426411 uint16_t addr_len ;
427412 uint8_t * addr_data_ptr ;
428413 tr_info ("Thread BBR BB_QRY.ntf Received" );
@@ -633,6 +618,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
633618 uint8_t * ml_eid_ptr ;
634619 uint8_t payload [2 + 16 + 2 + 2 + 1 + 8 ];
635620 uint8_t domain_prefix [8 ];
621+ uint8_t bbr_rloc_addr [16 ];
636622 uint8_t * ptr ;
637623 bool entry_keep_alive = false;
638624 uint8_t bbr_status = THREAD_BBR_STATUS_SUCCESS ;
@@ -663,6 +649,14 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
663649 goto send_response;
664650 }
665651 */
652+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (this -> interface_id );
653+ if (0 != thread_extension_primary_bbr_get (cur , bbr_rloc_addr , NULL , NULL , NULL ) ||
654+ !addr_get_entry (cur ,bbr_rloc_addr )) {
655+ // Primary BBR not present or I am not BBR
656+ bbr_status = THREAD_BBR_STATUS_NOT_PRIMARY_BBR ;
657+ goto send_response ;
658+ }
659+
666660 addr_len = thread_meshcop_tlv_find (request_ptr -> payload_ptr , request_ptr -> payload_len , TMFCOP_TLV_TARGET_EID , & addr_data_ptr );
667661 ml_eid_len = thread_meshcop_tlv_find (request_ptr -> payload_ptr , request_ptr -> payload_len , TMFCOP_TLV_ML_EID , & ml_eid_ptr );
668662
@@ -683,11 +677,13 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
683677
684678 entry_keep_alive = true;
685679 // TODO add ml_eid to structure saved in info pointer to detect duplicates
686- ipv6_route_t * route = ipv6_route_choose_next_hop (addr_data_ptr , this -> interface_id , NULL );
687- if (!route || route -> prefix_len < 128 || !route -> on_link || route -> info .source != ROUTE_THREAD_PROXIED_HOST ) {
688- //This is new registration
680+ if (thread_bbr_nd_entry_find (this -> interface_id , addr_data_ptr ) == 0 ) {
689681 entry_keep_alive = false;
690- route = NULL ;
682+ }
683+
684+ if (thread_bbr_nd_entry_add (this -> interface_id , addr_data_ptr , this -> dua_timeout + this -> delay_timer /500 , NULL , ml_eid_ptr ) == -1 ) {
685+ bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE ;
686+ goto send_response ;
691687 }
692688 /*if (route && memcmp(route->info.next_hop_addr, ml_addr,16) != 0) {
693689 // MLEID not matching duplicate detected
@@ -696,14 +692,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
696692 goto send_response;
697693 }
698694 */
699- route = ipv6_route_add_with_info (addr_data_ptr , 128 , this -> interface_id , NULL , ROUTE_THREAD_PROXIED_HOST , NULL , 0 , this -> dua_timeout + this -> delay_timer /500 , 0 );
700- // We are using route info field to store sequence number
701- if (!route ) {
702- // Direct route to host allows ND proxying to work
703- tr_err ("out of resources" );
704- bbr_status = THREAD_BBR_STATUS_RESOURCE_SHORTAGE ;
705- goto send_response ;
706- }
695+
707696 // Update entry timeout value and sequence number needs to be stored
708697
709698 if (entry_keep_alive ) {
@@ -713,10 +702,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
713702 // send BB.qry
714703 // TODO Delay and replay this meessage and answer the response after 2 seconds passed
715704 thread_border_router_bb_qry_send (this ,addr_data_ptr ,NULL );
716- if (thread_border_router_dup_tr_create (this -> interface_id , addr_data_ptr , request_ptr ) ) {
717- // Waiting for duplicate timeout
718- return 0 ;
719- }
720705 }
721706 // TODO
722707 // Save RLOC to destination cache with Last transaction time. Should these be made as sticky or should I have own table for these?
0 commit comments