Skip to content

Commit 5612e08

Browse files
DUA.ntf updates (ARMmbed#1752)
dua notification sent from parent to MTD if duplicate dua detected. Dua notification sending moved to a function.
1 parent 708bb3b commit 5612e08

File tree

8 files changed

+75
-34
lines changed

8 files changed

+75
-34
lines changed

source/6LoWPAN/Thread/thread_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,7 @@ static void thread_address_notification_cb(struct protocol_interface_info_entry
19291929
} else {
19301930
if (reason == ADDR_CALLBACK_DAD_COMPLETE) {
19311931
/* Send address notification (our parent doesn't do that for us) */
1932-
thread_extension_address_registration(interface, addr->address, NULL);
1932+
thread_extension_address_registration(interface, addr->address, NULL, false, false);
19331933
}
19341934
}
19351935
}

source/6LoWPAN/Thread/thread_extension.c

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
127127
// registration unsuccessful
128128
ipv6_neighbour_t *neighbour_entry;
129129
uint16_t nce_short_addr;
130-
uint8_t payload[16 + 1]; // Target eid + Status
131-
uint8_t *ptr;
132130
uint8_t destination_address[16] = {0};
133131

134132
neighbour_entry = ipv6_neighbour_lookup(&cur->ipv6_neighbour_cache, addr_data_ptr);
@@ -142,15 +140,7 @@ static int thread_extension_dua_registration_cb(int8_t service_id, uint8_t sourc
142140
}
143141
thread_addr_write_mesh_local_16(destination_address, nce_short_addr, cur->thread_info);
144142

145-
ptr = payload;
146-
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, addr_data_ptr);
147-
ptr = thread_tmfcop_tlv_data_write_uint8(ptr, TMFCOP_TLV_STATUS, *bbr_status);
148-
149-
coap_service_request_send(service_id, COAP_REQUEST_OPTIONS_ADDRESS_SHORT,
150-
destination_address, THREAD_MANAGEMENT_PORT,
151-
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST,
152-
THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_CT_OCTET_STREAM,
153-
payload, ptr - payload, NULL);
143+
thread_extension_addr_ntf_send(cur, destination_address, addr_data_ptr, *bbr_status);
154144

155145
ipv6_neighbour_entry_remove(&cur->ipv6_neighbour_cache, neighbour_entry);
156146

@@ -193,6 +183,39 @@ static int thread_extension_primary_bbr_update_needed(struct protocol_interface_
193183
return 0;
194184
}
195185

186+
void thread_extension_addr_ntf_send(struct protocol_interface_info_entry *cur, uint8_t *destination_address, const uint8_t *addr_data_ptr, uint8_t bbr_status)
187+
{
188+
uint8_t payload[16 + 1]; // Target eid + Status
189+
uint8_t *ptr;
190+
uint8_t domain_prefix[16];
191+
uint8_t domain_prefix_len;
192+
uint8_t br_ml_addr[16];
193+
uint8_t seq;
194+
uint32_t delay_timer;
195+
196+
if (0 != thread_extension_network_prefix_get(cur->id, NULL, domain_prefix, &domain_prefix_len) ||
197+
!bitsequal(addr_data_ptr, domain_prefix, domain_prefix_len)) {
198+
//Not in commercial Mode
199+
return;
200+
}
201+
202+
if ( 0 != thread_extension_primary_bbr_get(cur, br_ml_addr, &seq, &delay_timer, NULL) ) {
203+
// No pBBR present
204+
return;
205+
}
206+
207+
ptr = payload;
208+
ptr = thread_tmfcop_tlv_data_write(ptr, TMFCOP_TLV_TARGET_EID, 16, addr_data_ptr);
209+
ptr = thread_tmfcop_tlv_data_write_uint8(ptr, TMFCOP_TLV_STATUS, bbr_status);
210+
211+
coap_service_request_send(thread_management_client_service_id_get(cur->id), COAP_REQUEST_OPTIONS_ADDRESS_SHORT,
212+
destination_address, THREAD_MANAGEMENT_PORT,
213+
COAP_MSG_TYPE_NON_CONFIRMABLE, COAP_MSG_CODE_REQUEST_POST,
214+
THREAD_URI_BBR_DOMAIN_ADDRESS_NOTIFICATION, COAP_CT_OCTET_STREAM,
215+
payload, ptr - payload, NULL);
216+
return;
217+
}
218+
196219
int thread_extension_network_prefix_get(int8_t interface_id, uint8_t *options_ptr, uint8_t *domain_prefix_ptr, uint8_t *domain_prefix_len)
197220
{
198221
uint8_t *ptr;
@@ -417,7 +440,7 @@ static int thread_extension_mlr_req_send(protocol_interface_info_entry_t *cur, c
417440
}
418441

419442

420-
void thread_extension_address_registration(struct protocol_interface_info_entry *interface, const uint8_t *addr, const uint8_t *child_mac64)
443+
void thread_extension_address_registration(struct protocol_interface_info_entry *interface, const uint8_t *addr, const uint8_t *child_mac64, bool refresh_child_entry, bool duplicate_child_detected)
421444
{
422445
uint8_t *ml_eid;
423446
uint8_t br_ml_addr[16];
@@ -451,6 +474,17 @@ void thread_extension_address_registration(struct protocol_interface_info_entry
451474
tr_error("No Thread neighbor.");
452475
return;
453476
}
477+
478+
if (duplicate_child_detected) {
479+
uint8_t dest_address[16] = {0};
480+
thread_addr_write_mesh_local_16(dest_address, entry->mac16, interface->thread_info);
481+
thread_extension_addr_ntf_send(interface, dest_address, addr, 3);
482+
return;
483+
}
484+
if (!refresh_child_entry) {
485+
// don't send n/dr for existing entry
486+
return;
487+
}
454488
} else {
455489
link_configuration_s *link_config = thread_joiner_application_get_config(interface->id);
456490

@@ -630,15 +664,15 @@ void thread_extension_address_registration_trigger(protocol_interface_info_entry
630664
if (n->type == IP_NEIGHBOUR_REGISTERED && addr_ipv6_scope(n->ip_address, interface) > IPV6_SCOPE_REALM_LOCAL) {
631665
mac_neighbor_table_entry_t *entry = mac_neighbor_table_address_discover(mac_neighbor_info(interface), &n->ll_address[2], ADDR_802_15_4_SHORT);
632666
if (entry) {
633-
thread_extension_address_registration(interface, n->ip_address, entry->mac64);
667+
thread_extension_address_registration(interface, n->ip_address, entry->mac64, true, false);
634668
}
635669
}
636670
}
637671

638672
// Send own Address
639673
ns_list_foreach(if_address_entry_t, e, &interface->ip_addresses) {
640674
if (addr_ipv6_scope(e->address, interface) > IPV6_SCOPE_REALM_LOCAL) {
641-
thread_extension_address_registration(interface, e->address, NULL);
675+
thread_extension_address_registration(interface, e->address, NULL, false, false);
642676
}
643677
}
644678
}

source/6LoWPAN/Thread/thread_extension.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void thread_extension_mtd_service_register(protocol_interface_info_entry_t *cur)
4949
int thread_extension_network_prefix_get(int8_t interface_id, uint8_t *options_ptr, uint8_t *prefix_ptr, uint8_t *prefix_len);
5050
void thread_extension_network_data_process(struct protocol_interface_info_entry *cur);
5151
int thread_extension_primary_bbr_get(struct protocol_interface_info_entry *cur, uint8_t *addr_ptr, uint8_t *seq_ptr, uint32_t *timer1_ptr, uint32_t *timer2_ptr);
52-
void thread_extension_address_registration(struct protocol_interface_info_entry *interface, const uint8_t *addr, const uint8_t *child_mac64);
52+
void thread_extension_address_registration(struct protocol_interface_info_entry *interface, const uint8_t *addr, const uint8_t *child_mac64, bool refresh_child_entry, bool duplicate_child_detected);
5353
void thread_extension_address_generate(protocol_interface_info_entry_t *cur);
5454
void thread_extension_aloc_generate(struct protocol_interface_info_entry *cur);
5555
bool thread_extension_aloc_map(protocol_interface_info_entry_t *cur, uint16_t *addr16);
@@ -63,6 +63,7 @@ bool thread_extension_version_check(uint8_t version);
6363
void thread_extension_discover_response_read(struct discovery_response_list *nwk_info, uint16_t discover_response_tlv, uint8_t *data_ptr, uint16_t data_len);
6464
void thread_extension_discover_response_tlv_write(uint16_t *data, uint8_t version, uint16_t securityPolicy);
6565
int thread_extension_service_init(protocol_interface_info_entry_t *cur);
66+
void thread_extension_addr_ntf_send(struct protocol_interface_info_entry *cur, uint8_t *destination_address, const uint8_t *addr_data_ptr, uint8_t bbr_status);
6667
#ifdef HAVE_THREAD_ROUTER
6768
bool thread_extension_joining_enabled(int8_t interface_id);
6869
uint8_t thread_extension_discover_response_len(protocol_interface_info_entry_t *cur);
@@ -81,7 +82,7 @@ uint8_t *thread_extension_discover_response_write(protocol_interface_info_entry_
8182
#define thread_extension_network_prefix_get(interface_id,options_ptr,prefix_ptr,prefix_len) (-1)
8283
#define thread_extension_network_data_process(cur)
8384
#define thread_extension_primary_bbr_get(cur,addr_ptr,seq_ptr,timer1_ptr, timer2_ptr) (-1)
84-
#define thread_extension_address_registration(interface,addr,child_mac64)
85+
#define thread_extension_address_registration(interface,addr,child_mac64,refresh_child_entry,duplicate_child_detected)
8586
#define thread_extension_address_generate(cur)
8687
#define thread_extension_aloc_generate(cur)
8788
#define thread_extension_aloc_map(cur, addr16) false
@@ -96,6 +97,7 @@ uint8_t *thread_extension_discover_response_write(protocol_interface_info_entry_
9697
#define thread_extension_joining_enabled(interface_id) false
9798
#define thread_extension_discover_response_len(cur) 0
9899
#define thread_extension_discover_response_write(cur, ptr) (ptr)
100+
#define thread_extension_addr_ntf_send(cur,destination_address,addr_data_ptr,bbr_status)
99101
#define thread_extension_context_can_delete(id, servicesPrefix, context_prefix_length) false
100102
#endif
101103

source/6LoWPAN/Thread/thread_nd.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,11 @@ buffer_t *thread_nd_icmp_handler(protocol_interface_info_entry_t *cur, buffer_t
533533
return buf;
534534
}
535535

536-
int thread_nd_address_registration(protocol_interface_info_entry_t *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64)
536+
int thread_nd_address_registration(protocol_interface_info_entry_t *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64, bool *new_neighbour_created)
537537
{
538538
ipv6_neighbour_t *neigh;
539539
uint8_t ll_address[4];
540+
bool neighbor_created = false;
540541
common_write_16_bit(panId, ll_address + 0);
541542
common_write_16_bit(mac16, ll_address + 2);
542543
neigh = ipv6_neighbour_lookup_or_create(&cur->ipv6_neighbour_cache, ipv6Address);
@@ -545,21 +546,24 @@ int thread_nd_address_registration(protocol_interface_info_entry_t *cur, const u
545546
}
546547

547548
uint8_t *nce_eui64 = ipv6_neighbour_eui64(&cur->ipv6_neighbour_cache, neigh);
548-
/*if (neigh->state != IP_NEIGHBOUR_NEW)
549-
{
550-
// Worry about this later
551-
// Compare mac64 to nce_eui64 to spot duplicates
552-
}
553-
else*/
549+
if (neigh->state != IP_NEIGHBOUR_NEW && memcmp(nce_eui64, mac64, 8) != 0)
554550
{
555-
/* New entry */
556-
memcpy(nce_eui64, mac64, 8);
551+
return -2;
557552
}
553+
554+
/* New entry */
555+
if (neigh->state == IP_NEIGHBOUR_NEW) {
556+
neighbor_created = true;
557+
}
558+
memcpy(nce_eui64, mac64, 8);
558559
/* Set the LL address, ensure it's marked STALE */
559560
ipv6_neighbour_entry_update_unsolicited(&cur->ipv6_neighbour_cache, neigh, ADDR_802_15_4_SHORT, ll_address);
560561
neigh->type = IP_NEIGHBOUR_REGISTERED;
561562
neigh->lifetime = 0xffffffff; //Set Infinite
562563
ipv6_neighbour_set_state(&cur->ipv6_neighbour_cache, neigh, IP_NEIGHBOUR_STALE);
564+
if (new_neighbour_created) {
565+
*new_neighbour_created = neighbor_created;
566+
}
563567
return 0;
564568
}
565569

source/6LoWPAN/Thread/thread_nd.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ int thread_nd_map_anycast_address(protocol_interface_info_entry_t *cur, uint16_t
5555
void thread_nd_address_remove(protocol_interface_info_entry_t *cur_interface, addrtype_t ll_type, const uint8_t *ll_address);
5656
void thread_nd_flush_neighbour_cache_for_short_addr(struct protocol_interface_info_entry *cur, uint16_t flushee, bool children);
5757

58-
int thread_nd_address_registration(struct protocol_interface_info_entry *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64);
58+
int thread_nd_address_registration(struct protocol_interface_info_entry *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64, bool *new_neighbour_created);
5959

6060
#else //HAVE_THREAD_NEIGHBOR_DISCOVERY
6161

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ void thread_router_bootstrap_child_id_handler(protocol_interface_info_entry_t *c
13501350

13511351
tr_debug("Register %s", trace_ipv6(tempIPv6Address));
13521352
//Register GP --> 16
1353-
thread_nd_address_registration(cur, tempIPv6Address, entry_temp->mac16, cur->mac_parameters->pan_id, entry_temp->mac64);
1353+
thread_nd_address_registration(cur, tempIPv6Address, entry_temp->mac16, cur->mac_parameters->pan_id, entry_temp->mac64, NULL);
13541354
}
13551355

13561356
mle_attach_child_id_response_build(cur,ll64,req, entry_temp);
@@ -1365,6 +1365,7 @@ static void thread_address_registration_tlv_parse(uint8_t *ptr, uint16_t data_le
13651365
lowpan_context_t *ctx;
13661366
uint8_t tempIPv6Address[16];
13671367
uint8_t ctxId;
1368+
bool new_neighbour_created;
13681369

13691370
while (data_length) {
13701371
//Read
@@ -1377,8 +1378,8 @@ static void thread_address_registration_tlv_parse(uint8_t *ptr, uint16_t data_le
13771378
memcpy(&tempIPv6Address[8], ptr, 8);
13781379
tr_debug("Register %s", trace_ipv6(tempIPv6Address));
13791380
//Register GP --> 16
1380-
thread_nd_address_registration(cur, tempIPv6Address, mac16, cur->mac_parameters->pan_id, mac64);
1381-
thread_extension_address_registration(cur, tempIPv6Address, mac64);
1381+
int retVal = thread_nd_address_registration(cur, tempIPv6Address, mac16, cur->mac_parameters->pan_id, mac64, &new_neighbour_created);
1382+
thread_extension_address_registration(cur, tempIPv6Address, mac64, new_neighbour_created, retVal == -2);
13821383
} else {
13831384
tr_debug("No Context %u", ctxId);
13841385
}
@@ -1397,8 +1398,8 @@ static void thread_address_registration_tlv_parse(uint8_t *ptr, uint16_t data_le
13971398
}
13981399
} else {
13991400
//Register GP --> 16
1400-
thread_nd_address_registration(cur, ptr, mac16, cur->mac_parameters->pan_id, mac64);
1401-
thread_extension_address_registration(cur, ptr, mac64);
1401+
int retVal = thread_nd_address_registration(cur, ptr, mac16, cur->mac_parameters->pan_id, mac64, &new_neighbour_created);
1402+
thread_extension_address_registration(cur, ptr, mac64, new_neighbour_created, retVal == -2);
14021403
}
14031404

14041405
ptr += 16;

test/nanostack/unittest/stub/thread_extension_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void thread_extension_generate_domain_address(protocol_interface_info_entry_t *c
109109
(void)cur;
110110

111111
}
112-
void thread_extension_address_registration(struct protocol_interface_info_entry *interface, const uint8_t *addr, const uint8_t *child_mac64)
112+
void thread_extension_address_registration(struct protocol_interface_info_entry *interface, const uint8_t *addr, const uint8_t *child_mac64, bool refresh_child_entry, bool duplicate_child_detected)
113113
{
114114
(void)interface;
115115
(void)addr;

test/nanostack/unittest/stub/thread_nd_stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ buffer_t *thread_nd_icmp_handler(protocol_interface_info_entry_t *cur, buffer_t
9292
return NULL;
9393
}
9494

95-
int thread_nd_address_registration(protocol_interface_info_entry_t *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64)
95+
int thread_nd_address_registration(protocol_interface_info_entry_t *cur, const uint8_t *ipv6Address, uint16_t mac16, uint16_t panId, const uint8_t *mac64, bool *new_neighbour_created)
9696
{
9797
return 0;
9898
}

0 commit comments

Comments
 (0)