Skip to content

Commit 0b2736f

Browse files
author
Tero Heinonen
authored
Thread address registration improvements (ARMmbed#1779)
Some improvements to thread device address registration and solicit: - THREAD_MAINTENANCE_TIMER_INTERVAL to update network data periodically. - Child update response address registration TLV verification.
1 parent 931a17d commit 0b2736f

File tree

7 files changed

+103
-6
lines changed

7 files changed

+103
-6
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,6 @@ static void thread_neighbor_remove(mac_neighbor_table_entry_t *entry_ptr, void *
136136

137137
static bool thread_neighbor_entry_nud_notify(mac_neighbor_table_entry_t *entry_ptr, void *user_data)
138138
{
139-
140-
// Sleepy host
141139
protocol_interface_info_entry_t *cur_interface = user_data;
142140

143141
if (thread_am_router(cur_interface)) {
@@ -1069,9 +1067,7 @@ void thread_tasklet(arm_event_s *event)
10691067

10701068
case THREAD_CHILD_UPDATE:
10711069
tr_debug_extra("Thread SM THREAD_CHILD_UPDATE");
1072-
if (thread_info(cur)->thread_endnode_parent) {
1073-
thread_host_bootstrap_child_update(cur, cur->thread_info->thread_endnode_parent->mac64);
1074-
}
1070+
thread_host_bootstrap_child_update(cur, cur->thread_info->thread_endnode_parent->mac64);
10751071
break;
10761072
case THREAD_ANNOUNCE_ACTIVE: {
10771073
tr_debug_extra("Thread SM THREAD_ANNOUNCE_ACTIVE");
@@ -1824,7 +1820,6 @@ static void thread_dhcp_client_gua_error_cb(int8_t interface, uint8_t dhcp_addr[
18241820
if (prefix && dhcp_addr) {
18251821
tr_debug("Delete Current Server data");
18261822
thread_dhcp_client_global_address_delete(interface, dhcp_addr, prefix);
1827-
//TODO shuold we try again or select new Server
18281823
}
18291824
}
18301825
}
@@ -2702,6 +2697,8 @@ int thread_bootstrap_network_data_activate(protocol_interface_info_entry_t *cur)
27022697
thread_border_router_network_data_update_notify(cur);
27032698
thread_bbr_network_data_update_notify(cur);
27042699

2700+
thread_maintenance_timer_set(cur, THREAD_MAINTENANCE_TIMER_INTERVAL);
2701+
27052702
return 0;
27062703
}
27072704

source/6LoWPAN/Thread/thread_common.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,7 @@ static void thread_child_update_req_timer(protocol_interface_info_entry_t *cur,
905905
if (cur->thread_info->childUpdateReqTimer == -1) {
906906
return;
907907
}
908+
908909
if (cur->thread_info->childUpdateReqTimer > seconds) {
909910
cur->thread_info->childUpdateReqTimer -= seconds;
910911
} else {
@@ -945,6 +946,20 @@ static void thread_key_switch_timer(protocol_interface_info_entry_t *cur, uint16
945946
}
946947
}
947948

949+
static void thread_maintenance_timer(protocol_interface_info_entry_t *cur, uint32_t seconds)
950+
{
951+
if (thread_info(cur)->thread_maintenance_timer) {
952+
if (thread_info(cur)->thread_maintenance_timer > seconds) {
953+
thread_info(cur)->thread_maintenance_timer -= seconds;
954+
return;
955+
}
956+
}
957+
958+
thread_info(cur)->thread_maintenance_timer = THREAD_MAINTENANCE_TIMER_INTERVAL ;
959+
960+
thread_bootstrap_network_data_activate(cur);
961+
}
962+
948963
void thread_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t ticks)
949964
{
950965
uint8_t leader_address[16];
@@ -1003,6 +1018,7 @@ void thread_seconds_timer(protocol_interface_info_entry_t *cur, uint32_t ticks)
10031018
}
10041019

10051020
thread_router_bootstrap_timer(cur, ticks);
1021+
thread_maintenance_timer(cur, ticks);
10061022
thread_border_router_seconds_timer(cur->id, ticks);
10071023
thread_bbr_seconds_timer(cur->id, ticks);
10081024
thread_lowpower_timer(cur, ticks);
@@ -1997,5 +2013,10 @@ void thread_neighbor_communication_update(protocol_interface_info_entry_t *cur,
19972013
thread_neighbor_last_communication_time_update(&cur->thread_info->neighbor_class, neighbor_attribute_index);
19982014
}
19992015

2016+
void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur, uint16_t delay)
2017+
{
2018+
thread_info(cur)->thread_maintenance_timer = delay;
2019+
}
2020+
20002021
#endif
20012022

source/6LoWPAN/Thread/thread_common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ typedef struct thread_info_s {
313313
int16_t childUpdateReqTimer;
314314
uint16_t childUpdateReqMsgId;
315315
uint16_t proactive_an_timer;
316+
uint16_t thread_maintenance_timer;
316317
//uint8_t lastValidRouteMask[8];
317318
int8_t interface_id; //Thread Interface ID
318319
uint8_t version;
@@ -441,6 +442,7 @@ bool thread_partition_match(protocol_interface_info_entry_t *cur, thread_leader_
441442
void thread_partition_info_update(protocol_interface_info_entry_t *cur, thread_leader_data_t *leaderData);
442443
void thread_neighbor_communication_update(protocol_interface_info_entry_t *cur, uint8_t neighbor_attribute_index);
443444
bool thread_stable_context_check(protocol_interface_info_entry_t *cur, buffer_t *buf);
445+
void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur, uint16_t delay);
444446
#else // HAVE_THREAD
445447

446448
NS_DUMMY_DEFINITIONS_OK

source/6LoWPAN/Thread/thread_config.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@
326326
*/
327327
#define THREAD_BBR_ROUTER_ID_REQUEST_STATUS THREAD_COAP_STATUS_TLV_HAVE_CHILD_ID_REQUEST
328328

329+
/*
330+
* Timeout to solicit address from DHCP if previous request fails.
331+
*/
332+
#define THREAD_MAINTENANCE_TIMER_INTERVAL 300
333+
329334
/**
330335
* Build time flag to enable THCI special traces for test harness purposes
331336
*/

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#ifdef HAVE_THREAD
3131

3232
#include "ns_trace.h"
33+
#include "string.h"
3334
#include "common_functions.h"
3435
#include "NWK_INTERFACE/Include/protocol.h"
3536
#include <nsdynmemLIB.h>
@@ -53,6 +54,7 @@
5354
#include "Service_Libs/mac_neighbor_table/mac_neighbor_table.h"
5455
#include "6LoWPAN/MAC/mac_helper.h"
5556
#include "6LoWPAN/MAC/mac_data_poll.h"
57+
#include "Common_Protocols/ipv6.h"
5658
#include "MLE/mle.h"
5759
#include "mac_api.h"
5860
#define TRACE_GROUP "thmh"
@@ -699,6 +701,54 @@ static int thread_host_child_update_response_send(protocol_interface_info_entry_
699701
return 0;
700702
}
701703

704+
static bool thread_address_registration_tlv_search(if_address_entry_t *entry, mle_tlv_info_t *tlv_info)
705+
{
706+
uint8_t context;
707+
uint16_t length = tlv_info->tlvLen;
708+
uint8_t *ptr = tlv_info->dataPtr;
709+
710+
while (length) {
711+
context = *ptr++;
712+
if (context & 0x80) {
713+
if (memcmp(ptr, entry->address + 8, 8) == 0) {
714+
return true;
715+
}
716+
ptr += 8;
717+
length -= 9;
718+
} else {
719+
if (memcmp(ptr, entry->address, 16) == 0) {
720+
return true;
721+
}
722+
ptr += 16;
723+
length -= 17;
724+
}
725+
}
726+
727+
return false;
728+
729+
}
730+
731+
static bool thread_address_registration_tlv_check(protocol_interface_info_entry_t *cur, mle_tlv_info_t *tlv_info)
732+
{
733+
bool ret_val = true;
734+
735+
ns_list_foreach_safe(if_address_entry_t, e, &cur->ip_addresses) {
736+
if (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_GLOBAL || (addr_ipv6_scope(e->address, cur) == IPV6_SCOPE_REALM_LOCAL &&
737+
!thread_addr_is_mesh_local_16(e->address, cur))) {
738+
739+
if (thread_address_registration_tlv_search(e, tlv_info) == false) {
740+
tr_debug("Address %s registration to parent failed", trace_ipv6(e->address));
741+
addr_set_preferred_lifetime(cur, e, 0); // deprecate address
742+
ret_val = false;
743+
} else if (e->preferred_lifetime == 0) {
744+
addr_set_preferred_lifetime(cur, e, 0xffffffff); // set preferred lifetime to infinite
745+
}
746+
}
747+
}
748+
749+
return ret_val;
750+
}
751+
702752
static void thread_host_child_update_request_process(protocol_interface_info_entry_t *cur, mle_message_t *mle_msg, uint8_t linkMargin)
703753
{
704754
thread_leader_data_t leaderData;
@@ -710,6 +760,7 @@ static void thread_host_child_update_request_process(protocol_interface_info_ent
710760
uint64_t pending_timestamp = 0;// means no pending timestamp
711761
mac_neighbor_table_entry_t *entry_temp;
712762
bool data_request_needed = false;
763+
mle_tlv_info_t tlv_info = {0};
713764

714765
tr_debug("Child update request");
715766
entry_temp = mac_neighbor_entry_get_by_ll64(mac_neighbor_info(cur), mle_msg->packet_src_address, false, NULL);
@@ -738,6 +789,11 @@ static void thread_host_child_update_request_process(protocol_interface_info_ent
738789
thread_bootstrap_network_data_update(cur);
739790
}
740791

792+
// Check Address Registration TLV
793+
if (true == mle_tlv_read_tlv(MLE_TYPE_ADDRESS_REGISTRATION, mle_msg->data_ptr, mle_msg->data_length, &tlv_info)) {
794+
thread_address_registration_tlv_check(cur, &tlv_info);
795+
}
796+
741797
if (thread_info(cur)->thread_leader_data->stableDataVersion != leaderData.stableDataVersion ||
742798
thread_info(cur)->thread_leader_data->dataVersion != leaderData.dataVersion) {
743799
// version numbers not in sync need to send data request
@@ -776,6 +832,7 @@ static void thread_parse_child_update_response(protocol_interface_info_entry_t *
776832
thread_leader_data_t leaderData = {0};
777833
uint8_t status;
778834
bool leader_data_received;
835+
mle_tlv_info_t tlv_info = {0};
779836

780837
if (cur->thread_info->thread_endnode_parent == NULL) {
781838
return;
@@ -822,6 +879,10 @@ static void thread_parse_child_update_response(protocol_interface_info_entry_t *
822879
tr_debug("Setting child timeout, value=%"PRIu32, timeout);
823880
}
824881

882+
if (true == mle_tlv_read_tlv(MLE_TYPE_ADDRESS_REGISTRATION, mle_msg->data_ptr, mle_msg->data_length, &tlv_info)) {
883+
thread_address_registration_tlv_check(cur, &tlv_info);
884+
}
885+
825886
tr_debug("Keep-Alive -->Respond from Parent");
826887
mac_neighbor_table_neighbor_refresh(mac_neighbor_info(cur), entry_temp, timeout);
827888

test/nanostack/unittest/stub/thread_bootstrap_stub.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,3 +306,8 @@ int thread_bootstrap_network_data_process(protocol_interface_info_entry_t *cur,
306306
{
307307
return 0;
308308
}
309+
310+
int thread_bootstrap_network_data_activate(protocol_interface_info_entry_t *cur)
311+
{
312+
return 0;
313+
}

test/nanostack/unittest/stub/thread_common_stub.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,9 @@ bool thread_stable_context_check(protocol_interface_info_entry_t *cur, buffer_t
411411
{
412412
return true;
413413
}
414+
415+
416+
void thread_maintenance_timer_set(protocol_interface_info_entry_t *cur, uint16_t delay)
417+
{
418+
419+
}

0 commit comments

Comments
 (0)