Skip to content

Commit 1dc21a1

Browse files
thread extension fixes. (ARMmbed#1495)
1 parent bade70e commit 1dc21a1

File tree

2 files changed

+38
-25
lines changed

2 files changed

+38
-25
lines changed

source/6LoWPAN/Thread/thread_bbr_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ void thread_bbr_seconds_timer(int8_t interface_id, uint32_t seconds)
943943
#endif // HAVE_THREAD_ROUTER
944944

945945
#ifdef HAVE_THREAD_BORDER_ROUTER
946-
static int thread_bbr_na_send(int8_t interface_id, uint32_t lifetime, const uint8_t target[static 16])
946+
static int thread_bbr_na_send(int8_t interface_id, const uint8_t target[static 16])
947947
{
948948
protocol_interface_info_entry_t *cur = protocol_stack_interface_info_get_by_id(interface_id);
949949
if (!cur) {
@@ -970,7 +970,7 @@ int thread_bbr_nd_entry_add (int8_t interface_id, const uint8_t *addr_data_ptr,
970970
return -2;
971971
}
972972
// send NA
973-
thread_bbr_na_send(this->backbone_interface_id, lifetime, addr_data_ptr);
973+
thread_bbr_na_send(this->backbone_interface_id, addr_data_ptr);
974974

975975
return 0;
976976
}

source/6LoWPAN/Thread/thread_extension_bbr.c

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "6LoWPAN/Thread/thread_extension_bootstrap.h"
5353
#include "6LoWPAN/Thread/thread_extension_constants.h"
5454
#include "6LoWPAN/Thread/thread_bbr_api_internal.h"
55+
#include "6LoWPAN/Thread/thread_resolution_client.h"
5556
#include "NWK_INTERFACE/Include/protocol.h"
5657
#include "Common_Protocols/ipv6.h"
5758

@@ -87,8 +88,9 @@ typedef struct {
8788

8889
typedef struct {
8990
int8_t interface_id;
91+
uint8_t source_address[16];
92+
uint8_t ml_eid[8];
9093
uint8_t target_eid[16];
91-
uint16_t request_msg_id;
9294
uint16_t ttl;
9395
ns_list_link_t link;
9496
} duplicate_dua_tr_t;
@@ -152,6 +154,22 @@ static thread_pbbr_t *thread_border_router_find_by_service(int8_t service_id)
152154
return this;
153155
}
154156

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+
155173
static void thread_border_router_dup_tr_delete(duplicate_dua_tr_t *this)
156174
{
157175

@@ -183,7 +201,7 @@ static duplicate_dua_tr_t *thread_border_router_dup_tr_find(int8_t interface_id,
183201
* DUA Registration Sequence Number TLV
184202
* Network Name TLV
185203
*/
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)
187205
{
188206
uint8_t *payload_ptr, *ptr;
189207

@@ -201,7 +219,7 @@ static void thread_border_router_bb_ans_send(thread_pbbr_t *this, uint8_t *targe
201219
ptr = thread_meshcop_tlv_data_write(ptr, TMFCOP_TLV_NETWORK_NAME, stringlen((char *)network_name_ptr, 16), network_name_ptr);
202220

203221
/* 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,
205223
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);
206224

207225
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],
443461
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
444462

445463
// 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);
447465

448466
return 0;
449467
}
450468
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)
451469
{
452470
(void)service_id;
453-
(void)source_address;
454471
(void)source_port;
455472
(void)request_ptr;
456473
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],
499516
duplicate_dua_tr_t *tr_ptr = thread_border_router_dup_tr_find(this->interface_id,addr_data_ptr);
500517
if (tr_ptr) {
501518
// 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+
}
510526
}
511527
ipv6_route_delete(route->prefix, route->prefix_len, this->interface_id, route->info.next_hop_addr, ROUTE_THREAD_PROXIED_HOST);
512528

@@ -611,7 +627,6 @@ static int thread_extension_bbr_bmlr_cb(int8_t service_id, uint8_t source_addres
611627

612628
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)
613629
{
614-
(void)source_address;
615630
(void)source_port;
616631
uint16_t addr_len, ml_eid_len;
617632
uint8_t *addr_data_ptr;
@@ -697,11 +712,13 @@ static int thread_extension_bbr_dua_cb(int8_t service_id, uint8_t source_address
697712

698713
if (entry_keep_alive) {
699714
// 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);
701716
} else {
702717
// 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);
704720
thread_border_router_bb_qry_send(this,addr_data_ptr,NULL);
721+
705722
}
706723
// TODO
707724
// 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)
785802
// Register Primary BBR backbone multicast address
786803
memset(this->pbbr_multicast_address, 0, 16);
787804
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
789806
this->pbbr_multicast_address[2] = 0x00; //Reserved
790807
this->pbbr_multicast_address[3] = 0x40; //Prefix length 64 bits
791808
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)
956973
ns_list_foreach_safe(duplicate_dua_tr_t, cur_dup_tr, &duplicate_dua_tr_list) {
957974
if (cur_dup_tr->interface_id == interface_id && cur_dup_tr->ttl > seconds) {
958975
cur_dup_tr->ttl -= seconds;
976+
// TODO Repeat the ANS 2 times.
959977
} 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
966979
thread_border_router_dup_tr_delete(cur_dup_tr);
967980
}
968981
}

0 commit comments

Comments
 (0)