52
52
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
53
53
#include "6LoWPAN/Thread/thread_extension_constants.h"
54
54
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
55
+ #include "6LoWPAN/Thread/thread_resolution_client.h"
55
56
#include "NWK_INTERFACE/Include/protocol.h"
56
57
#include "Common_Protocols/ipv6.h"
57
58
@@ -87,8 +88,9 @@ typedef struct {
87
88
88
89
typedef struct {
89
90
int8_t interface_id ;
91
+ uint8_t source_address [16 ];
92
+ uint8_t ml_eid [8 ];
90
93
uint8_t target_eid [16 ];
91
- uint16_t request_msg_id ;
92
94
uint16_t ttl ;
93
95
ns_list_link_t link ;
94
96
} duplicate_dua_tr_t ;
@@ -152,6 +154,22 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
152
154
return this ;
153
155
}
154
156
157
+ static duplicate_dua_tr_t * thread_border_router_dup_tr_create (int8_t interface_id , uint8_t * source_addr_ptr , uint8_t * target_eid_ptr , uint8_t * ml_eid_ptr )
158
+ {
159
+ duplicate_dua_tr_t * this = ns_dyn_mem_alloc (sizeof (duplicate_dua_tr_t ));
160
+
161
+ if (!this ) {
162
+ return NULL ;
163
+ }
164
+ ns_list_add_to_start (& duplicate_dua_tr_list , this );
165
+ this -> interface_id = interface_id ;
166
+ memcpy (this -> target_eid , target_eid_ptr ,16 );
167
+ memcpy (this -> source_address , source_addr_ptr , 16 );
168
+ memcpy (this -> ml_eid , ml_eid_ptr ,8 );
169
+ this -> ttl = 2 ;
170
+ return this ;
171
+ }
172
+
155
173
static void thread_border_router_dup_tr_delete (duplicate_dua_tr_t * this )
156
174
{
157
175
@@ -183,7 +201,7 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_find(int8_t interface_id,
183
201
* DUA Registration Sequence Number TLV
184
202
* Network Name TLV
185
203
*/
186
- static void thread_border_router_bb_ans_send (thread_pbbr_t * this , uint8_t * target_eid_ptr , uint8_t * ml_eid_ptr , uint32_t last_transaction_time , uint8_t * network_name_ptr )
204
+ static void thread_border_router_bb_ans_send (thread_pbbr_t * this , uint8_t * destination_addr_ptr , uint8_t * target_eid_ptr , uint8_t * ml_eid_ptr , uint32_t last_transaction_time , uint8_t * network_name_ptr )
187
205
{
188
206
uint8_t * payload_ptr , * ptr ;
189
207
@@ -201,7 +219,7 @@ static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *targe
201
219
ptr = thread_meshcop_tlv_data_write (ptr , TMFCOP_TLV_NETWORK_NAME , stringlen ((char * )network_name_ptr , 16 ), network_name_ptr );
202
220
203
221
/* UDP Encapsulation TLV */
204
- coap_service_request_send (this -> br_bb_service_id , COAP_REQUEST_OPTIONS_NONE , this -> pbbr_multicast_address , this -> pbbr_port ,
222
+ coap_service_request_send (this -> br_bb_service_id , COAP_REQUEST_OPTIONS_NONE , destination_addr_ptr , this -> pbbr_port ,
205
223
COAP_MSG_TYPE_NON_CONFIRMABLE , COAP_MSG_CODE_REQUEST_POST , THREAD_URI_BBR_BB_ANS_NTF , COAP_CT_OCTET_STREAM , payload_ptr , ptr - payload_ptr , NULL );
206
224
207
225
ns_dyn_mem_free (payload_ptr );
@@ -443,14 +461,13 @@ static int thread_pbbr_bb_qry_cb(int8_t service_id, uint8_t source_address[16],
443
461
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
444
462
445
463
// This address is valid in our MESH
446
- thread_border_router_bb_ans_send (this , addr_data_ptr , ml_eid_ptr , last_transaction_time , link_configuration_ptr -> name );
464
+ thread_border_router_bb_ans_send (this , source_address , addr_data_ptr , ml_eid_ptr , last_transaction_time , link_configuration_ptr -> name );
447
465
448
466
return 0 ;
449
467
}
450
468
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 )
451
469
{
452
470
(void )service_id ;
453
- (void )source_address ;
454
471
(void )source_port ;
455
472
(void )request_ptr ;
456
473
uint16_t addr_len , ml_eid_len , last_transaction_time_len , network_name_len ;
@@ -499,14 +516,13 @@ static int thread_pbbr_bb_ans_cb(int8_t service_id, uint8_t source_address[16],
499
516
duplicate_dua_tr_t * tr_ptr = thread_border_router_dup_tr_find (this -> interface_id ,addr_data_ptr );
500
517
if (tr_ptr ) {
501
518
// We have pending request and received answer
502
- uint8_t * ptr ;
503
- uint8_t payload [13 ];
504
- ptr = payload ;
505
- ptr = thread_tmfcop_tlv_data_write_uint8 (ptr , TMFCOP_TLV_STATUS , THREAD_BBR_STATUS_DUA_ALREADY_IN_USE );
506
- ptr = thread_tmfcop_tlv_data_write (ptr , TMFCOP_TLV_ML_EID , 8 , ml_eid_ptr );
507
-
508
- coap_service_response_send_by_msg_id (this -> coap_service_id , COAP_REQUEST_OPTIONS_NONE , tr_ptr -> request_msg_id , COAP_MSG_CODE_RESPONSE_CHANGED , COAP_CT_OCTET_STREAM , payload , ptr - payload );
509
-
519
+ thread_resolution_client_address_error (this -> interface_id , tr_ptr -> source_address , tr_ptr -> target_eid , tr_ptr -> ml_eid );
520
+ ipv6_neighbour_t * neighbour_entry ;
521
+ neighbour_entry = ipv6_neighbour_lookup (& cur -> ipv6_neighbour_cache , tr_ptr -> target_eid );
522
+ if (neighbour_entry ) {
523
+ tr_debug ("Remove from neigh Cache: %s" , tr_ipv6 (tr_ptr -> target_eid ));
524
+ ipv6_neighbour_entry_remove (& cur -> ipv6_neighbour_cache , neighbour_entry );
525
+ }
510
526
}
511
527
ipv6_route_delete (route -> prefix , route -> prefix_len , this -> interface_id , route -> info .next_hop_addr , ROUTE_THREAD_PROXIED_HOST );
512
528
@@ -611,7 +627,6 @@ static int thread_extension_bbr_bmlr_cb(int8_t service_id, uint8_t source_addres
611
627
612
628
static int thread_extension_bbr_dua_cb (int8_t service_id , uint8_t source_address [16 ], uint16_t source_port , sn_coap_hdr_s * request_ptr )
613
629
{
614
- (void )source_address ;
615
630
(void )source_port ;
616
631
uint16_t addr_len , ml_eid_len ;
617
632
uint8_t * addr_data_ptr ;
@@ -697,11 +712,13 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
697
712
698
713
if (entry_keep_alive ) {
699
714
// send proactive BB_ans.ntf
700
- thread_border_router_bb_ans_send (this , addr_data_ptr , ml_eid_ptr , 0 , link_configuration_ptr -> name );
715
+ thread_border_router_bb_ans_send (this , this -> pbbr_multicast_address , addr_data_ptr , ml_eid_ptr , 0 , link_configuration_ptr -> name );
701
716
} else {
702
717
// send BB.qry
703
- // TODO Delay and replay this meessage and answer the response after 2 seconds passed
718
+ // TODO Create duplicate Transaction to wait answers from Backbone
719
+ thread_border_router_dup_tr_create (this -> interface_id , source_address , addr_data_ptr , ml_eid_ptr );
704
720
thread_border_router_bb_qry_send (this ,addr_data_ptr ,NULL );
721
+
705
722
}
706
723
// TODO
707
724
// Save RLOC to destination cache with Last transaction time. Should these be made as sticky or should I have own table for these?
@@ -785,7 +802,7 @@ static int thread_extension_bbr_pbbr_start(thread_pbbr_t *this)
785
802
// Register Primary BBR backbone multicast address
786
803
memset (this -> pbbr_multicast_address , 0 , 16 );
787
804
this -> pbbr_multicast_address [0 ] = 0xff ;
788
- this -> pbbr_multicast_address [1 ] = 0x30 | 2 ; //Thread specification says p and t bits are 1 Scope is 2
805
+ this -> pbbr_multicast_address [1 ] = 0x30 | 3 ; //Thread specification says p and t bits are 1 Scope is 3
789
806
this -> pbbr_multicast_address [2 ] = 0x00 ; //Reserved
790
807
this -> pbbr_multicast_address [3 ] = 0x40 ; //Prefix length 64 bits
791
808
if (0 != thread_extension_network_prefix_get (this -> interface_id , NULL , & this -> pbbr_multicast_address [4 ], NULL )) {
@@ -956,13 +973,9 @@ void thread_extension_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
956
973
ns_list_foreach_safe (duplicate_dua_tr_t , cur_dup_tr , & duplicate_dua_tr_list ) {
957
974
if (cur_dup_tr -> interface_id == interface_id && cur_dup_tr -> ttl > seconds ) {
958
975
cur_dup_tr -> ttl -= seconds ;
976
+ // TODO Repeat the ANS 2 times.
959
977
} else {
960
- // Timeout
961
- uint8_t * ptr ;
962
- uint8_t payload [3 ];
963
- ptr = payload ;
964
- ptr = thread_tmfcop_tlv_data_write_uint8 (ptr , TMFCOP_TLV_STATUS , THREAD_BBR_STATUS_SUCCESS );
965
- coap_service_response_send_by_msg_id (this -> coap_service_id , COAP_REQUEST_OPTIONS_NONE , cur_dup_tr -> request_msg_id , COAP_MSG_CODE_RESPONSE_CHANGED , COAP_CT_OCTET_STREAM , payload , ptr - payload );
978
+ // Timeout Remmove the duplicate detection timer
966
979
thread_border_router_dup_tr_delete (cur_dup_tr );
967
980
}
968
981
}
0 commit comments