Skip to content

Commit 9aa6a95

Browse files
Address registration changes for MED and SED (ARMmbed#1863)
updated address registration tlv in child id request from MED and SED to contain only ML-EID. Other addresses are registered separately in Child update request that is triggered immediately after receiving child id response.
1 parent 67ea075 commit 9aa6a95

File tree

5 files changed

+104
-1
lines changed

5 files changed

+104
-1
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,10 @@ void thread_bootstrap_ready(protocol_interface_info_entry_t *cur)
11701170
thread_leader_service_generate_network_data(cur);
11711171
}
11721172

1173+
if (thread_addresses_needs_to_be_registered(cur)) {
1174+
thread_info(cur)->childUpdateReqTimer = 1;
1175+
}
1176+
11731177
cur->bootsrap_state_machine_cnt = 0;
11741178
mac_data_poll_protocol_poll_mode_decrement(cur);
11751179
}

source/6LoWPAN/Thread/thread_common.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,96 @@ uint8_t *thread_leader_data_tlv_write(uint8_t *ptr, protocol_interface_info_entr
17361736
return ptr;
17371737
}
17381738

1739+
bool thread_addresses_needs_to_be_registered(protocol_interface_info_entry_t *cur)
1740+
{
1741+
lowpan_context_t *ctx;
1742+
uint8_t thread_realm_local_mcast_addr[16];
1743+
if (thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_SLEEPY_END_DEVICE &&
1744+
thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_END_DEVICE) {
1745+
// No address registration for others than MED or SED
1746+
return false;
1747+
}
1748+
1749+
// check for addresses
1750+
ns_list_foreach(if_address_entry_t, e, &cur->ip_addresses) {
1751+
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL || (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_REALM_LOCAL
1752+
&& !thread_addr_is_mesh_local_16(e->address, cur))) {
1753+
ctx = lowpan_context_get_by_address(&cur->lowpan_contexts, e->address);
1754+
if (!ctx) {
1755+
return true;
1756+
}
1757+
if (ctx->cid != 0) {
1758+
return true;
1759+
1760+
}
1761+
}
1762+
}
1763+
1764+
// check for multicast groups
1765+
thread_bootstrap_all_nodes_address_generate(thread_realm_local_mcast_addr, cur->thread_info->threadPrivatePrefixInfo.ulaPrefix, 3);
1766+
ns_list_foreach(if_group_entry_t, entry, &cur->ip_groups)
1767+
{
1768+
if (addr_ipv6_multicast_scope(entry->group) < IPV6_SCOPE_REALM_LOCAL) {
1769+
/* Skip Link Local multicast address */
1770+
continue;
1771+
}
1772+
1773+
if (addr_ipv6_equal(entry->group, thread_realm_local_mcast_addr)) {
1774+
/* Skip well-known realm-local all Thread nodes multicast address */
1775+
continue;
1776+
}
1777+
if (addr_ipv6_equal(entry->group, ADDR_ALL_MPL_FORWARDERS)) {
1778+
/* Skip All MPL Forwarders address */
1779+
continue;
1780+
}
1781+
if (addr_ipv6_equal(entry->group, ADDR_REALM_LOCAL_ALL_NODES)) {
1782+
/* Skip Mesh local all nodes */
1783+
continue;
1784+
}
1785+
if (addr_ipv6_equal(entry->group, ADDR_REALM_LOCAL_ALL_ROUTERS)) {
1786+
/* Skip Mesh local all routers */
1787+
continue;
1788+
}
1789+
return true;
1790+
}
1791+
return false;
1792+
}
1793+
1794+
uint8_t *thread_ml_address_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur)
1795+
{
1796+
lowpan_context_t *ctx;
1797+
uint8_t *address_len_ptr;
1798+
1799+
if (thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_SLEEPY_END_DEVICE &&
1800+
thread_info(cur)->thread_device_mode != THREAD_DEVICE_MODE_END_DEVICE) {
1801+
// No address registration for others than MED or SED
1802+
return ptr;
1803+
}
1804+
*ptr++ = MLE_TYPE_ADDRESS_REGISTRATION;
1805+
address_len_ptr = ptr++;
1806+
1807+
*address_len_ptr = 0;
1808+
1809+
ns_list_foreach(if_address_entry_t, e, &cur->ip_addresses) {
1810+
1811+
if (*address_len_ptr > 148 ) {
1812+
// Maximum length of address registrations
1813+
continue;
1814+
}
1815+
if (!thread_addr_is_mesh_local_16(e->address, cur)) {
1816+
ctx = lowpan_context_get_by_address(&cur->lowpan_contexts, e->address);
1817+
if (ctx && ctx->cid == 0) {
1818+
//Write TLV to list
1819+
*ptr++ = (ctx->cid | 0x80);
1820+
memcpy(ptr, e->address + 8, 8);
1821+
ptr += 8;
1822+
*address_len_ptr += 9;
1823+
}
1824+
}
1825+
}
1826+
return ptr;
1827+
}
1828+
17391829
uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur)
17401830
{
17411831
uint8_t thread_realm_local_mcast_addr[16];

source/6LoWPAN/Thread/thread_common.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,11 @@ void thread_child_mcast_entries_remove(protocol_interface_info_entry_t *cur, con
398398
uint8_t thread_leader_data_tlv_size(protocol_interface_info_entry_t *cur);
399399
uint8_t *thread_leader_data_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
400400
uint8_t *thread_address_registration_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
401+
402+
// returns true if SED/MED needs to register additional address to parent
403+
bool thread_addresses_needs_to_be_registered(protocol_interface_info_entry_t *cur);
404+
// write mesh local address tlv
405+
uint8_t *thread_ml_address_tlv_write(uint8_t *ptr, protocol_interface_info_entry_t *cur);
401406
int thread_link_reject_send(protocol_interface_info_entry_t *interface, const uint8_t *ll64);
402407
thread_leader_info_t *thread_allocate_and_init_leader_private_data(void);
403408
thread_route_cost_t thread_link_quality_to_cost(thread_link_quality_e quality);

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ static int thread_attach_child_id_request_build(protocol_interface_info_entry_t
11241124

11251125
//Add ML-EID
11261126
if ((mode & MLE_FFD_DEV) == 0) {
1127-
ptr = thread_address_registration_tlv_write(ptr, cur);
1127+
ptr = thread_ml_address_tlv_write(ptr,cur);
11281128
}
11291129

11301130
reqTlvCnt = 2;

test/nanostack/unittest/stub/thread_common_stub.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,7 @@ void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur, uint16_t
417417
{
418418

419419
}
420+
bool thread_addresses_needs_to_be_registered(protocol_interface_info_entry_t *cur)
421+
{
422+
return true;
423+
}

0 commit comments

Comments
 (0)