51
51
#include "6LoWPAN/Thread/thread_discovery.h"
52
52
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
53
53
#include "6LoWPAN/Thread/thread_extension_constants.h"
54
+ #include "6LoWPAN/Thread/thread_bbr_api_internal.h"
54
55
#include "NWK_INTERFACE/Include/protocol.h"
55
56
#include "Common_Protocols/ipv6.h"
56
57
@@ -151,21 +152,6 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
151
152
return this ;
152
153
}
153
154
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
-
169
155
static void thread_border_router_dup_tr_delete (duplicate_dua_tr_t * this )
170
156
{
171
157
@@ -422,7 +408,6 @@ static int thread_pbbr_nmkp_req_recv_cb(int8_t service_id, uint8_t source_addres
422
408
static 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 )
423
409
{
424
410
(void )source_port ;
425
- (void )source_address ;
426
411
uint16_t addr_len ;
427
412
uint8_t * addr_data_ptr ;
428
413
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
633
618
uint8_t * ml_eid_ptr ;
634
619
uint8_t payload [2 + 16 + 2 + 2 + 1 + 8 ];
635
620
uint8_t domain_prefix [8 ];
621
+ uint8_t bbr_rloc_addr [16 ];
636
622
uint8_t * ptr ;
637
623
bool entry_keep_alive = false;
638
624
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
663
649
goto send_response;
664
650
}
665
651
*/
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
+
666
660
addr_len = thread_meshcop_tlv_find (request_ptr -> payload_ptr , request_ptr -> payload_len , TMFCOP_TLV_TARGET_EID , & addr_data_ptr );
667
661
ml_eid_len = thread_meshcop_tlv_find (request_ptr -> payload_ptr , request_ptr -> payload_len , TMFCOP_TLV_ML_EID , & ml_eid_ptr );
668
662
@@ -683,11 +677,13 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
683
677
684
678
entry_keep_alive = true;
685
679
// 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 ) {
689
681
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 ;
691
687
}
692
688
/*if (route && memcmp(route->info.next_hop_addr, ml_addr,16) != 0) {
693
689
// MLEID not matching duplicate detected
@@ -696,14 +692,7 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
696
692
goto send_response;
697
693
}
698
694
*/
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
+
707
696
// Update entry timeout value and sequence number needs to be stored
708
697
709
698
if (entry_keep_alive ) {
@@ -713,10 +702,6 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
713
702
// send BB.qry
714
703
// TODO Delay and replay this meessage and answer the response after 2 seconds passed
715
704
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
- }
720
705
}
721
706
// TODO
722
707
// 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