Skip to content

Commit da9860f

Browse files
Pending set after link sync (ARMmbed#1526)
Pending configuration synced after router restart using data request and data response.
1 parent ffa1569 commit da9860f

10 files changed

+39
-12
lines changed

source/6LoWPAN/Thread/thread_bootstrap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1427,9 +1427,9 @@ static void thread_bootstrap_generate_leader_and_link(protocol_interface_info_en
14271427
static int8_t thread_bootstrap_attempt_attach_with_pending_set(protocol_interface_info_entry_t *cur)
14281428
{
14291429
tr_debug("Attempting to attach with pending set");
1430-
uint32_t pending_timestamp = thread_joiner_application_pending_config_timeout_get(cur->id);
1431-
if (pending_timestamp > 0) {
1432-
tr_debug("We have a pending timestamp running");
1430+
uint32_t pending_delay_timer = thread_joiner_application_pending_config_timeout_get(cur->id);
1431+
if (pending_delay_timer > 0 && thread_joiner_application_pending_delay_timer_in_sync(cur->id)) {
1432+
tr_debug("We have a pending delay timer running");
14331433
//we already have a pending set that can be activated so return
14341434
return -1;
14351435
}

source/6LoWPAN/Thread/thread_common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,6 @@ bool thread_pending_operational_dataset_process(protocol_interface_info_entry_t
16601660
tr_error("pending set creation failed");
16611661
return false;
16621662
}
1663-
16641663
tr_debug("updating pending dataset");
16651664
thread_joiner_application_pending_config_timestamp_set(cur->id,mle_pending_timestamp);
16661665
thread_joiner_application_pending_config_enable(cur->id,delay_timer);

source/6LoWPAN/Thread/thread_common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ typedef struct thread_info_s {
304304
bool networkDataRequested: 1;
305305
bool end_device_link_synch: 1;
306306
bool router_mc_addrs_registered: 1;
307+
bool leader_synced:1; // flag used by leader after restart
307308
} thread_info_t;
308309

309310
#ifdef HAVE_THREAD

source/6LoWPAN/Thread/thread_host_bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,9 @@ static void thread_child_synch_receive_cb(int8_t interface_id, mle_message_t *ml
407407
tr_debug("End device synch Possible");
408408

409409
cur->thread_info->thread_attached_state = THREAD_STATE_CONNECTED;
410-
410+
// read network data, and leader data check. Send data request sent if pending set is not in sync
411411
if (mle_tlv_read_tlv(MLE_TYPE_NETWORK_DATA, mle_msg->data_ptr, mle_msg->data_length, &networkDataTlv) &&
412-
thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData)) {
412+
thread_leader_data_parse(mle_msg->data_ptr, mle_msg->data_length, &leaderData) && thread_joiner_application_pending_delay_timer_in_sync(cur->id)) {
413413
thread_bootstrap_network_data_save(cur, &leaderData, networkDataTlv.dataPtr, networkDataTlv.tlvLen);
414414
} else {
415415
thread_bootstrap_parent_network_data_request(cur, true);

source/6LoWPAN/Thread/thread_joiner_application.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ typedef struct {
218218
int8_t interface_id;
219219
int8_t coap_service_id;
220220
int8_t secure_coap_service_id;
221+
bool pending_set_in_sync:1;
221222
ns_list_link_t link;
222223
} thread_joiner_t;
223224

@@ -988,6 +989,7 @@ static int thread_joiner_application_nvm_link_config_read(thread_joiner_t *this)
988989
}
989990
this->pending_configuration_ptr = pend_conf_ptr;
990991
this->pending_configuration_ptr->timeout_in_ms = 0;
992+
this->pending_set_in_sync = false;
991993
}
992994
else {
993995
tr_info("Reading pending from NVM error:%d", pending_ret);
@@ -1201,10 +1203,19 @@ bool thread_joiner_application_pending_config_exists(int8_t interface_id)
12011203
return true;
12021204
}
12031205

1204-
uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id)
1206+
bool thread_joiner_application_pending_delay_timer_in_sync(int8_t interface_id)
12051207
{
12061208
thread_joiner_t *this = thread_joiner_find(interface_id);
12071209
if (!this || !this->pending_configuration_ptr) {
1210+
return false;
1211+
}
1212+
return this->pending_set_in_sync;
1213+
}
1214+
1215+
uint64_t thread_joiner_application_pending_config_timestamp_get(int8_t interface_id)
1216+
{
1217+
thread_joiner_t *this = thread_joiner_find(interface_id);
1218+
if (!this || !this->pending_configuration_ptr || !this->pending_set_in_sync) {
12081219
return 0;
12091220
}
12101221
return this->pending_configuration_ptr->timestamp;
@@ -1228,6 +1239,7 @@ int thread_joiner_application_pending_config_enable(int8_t interface_id, uint32_
12281239
return -1;
12291240
}
12301241
this->pending_configuration_ptr->timeout_in_ms = timeout_in_ms;
1242+
this->pending_set_in_sync = true;
12311243

12321244
if(this->pending_configuration_ptr->timeout_in_ms > THREAD_MAX_DELAY_TIMER_SECONDS*1000) {
12331245
this->pending_configuration_ptr->timeout_in_ms = THREAD_MAX_DELAY_TIMER_SECONDS*1000;

source/6LoWPAN/Thread/thread_joiner_application.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ bool thread_joiner_application_next_pending_config_exists(int8_t interface_id);
259259
uint16_t thread_joiner_application_next_pending_config_length(int8_t interface_id);
260260
uint8_t *thread_joiner_application_next_pending_config_build(int8_t interface_id, uint8_t *ptr);
261261
void thread_joiner_application_next_pending_config_delete(int8_t interface_id);
262-
262+
bool thread_joiner_application_pending_delay_timer_in_sync(int8_t interface_id);
263263

264264

265265
void thread_joiner_application_next_active_config_save(int8_t interface_id);

source/6LoWPAN/Thread/thread_leader_service.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,6 @@ int thread_leader_service_thread_partitition_restart(int8_t interface_id, mle_tl
16371637
// Clear network data (if exists) and propagate new empty network data
16381638
thread_network_data_free_and_clean(&cur->thread_info->networkDataStorage);
16391639
thread_network_data_base_init(&cur->thread_info->networkDataStorage);
1640-
thread_leader_service_network_data_changed(cur, true, true);
16411640
return 0;
16421641
}
16431642

source/6LoWPAN/Thread/thread_mle_message_handler.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "6LoWPAN/Thread/thread_bootstrap.h"
4343
#include "6LoWPAN/Thread/thread_management_internal.h"
4444
#include "6LoWPAN/Thread/thread_joiner_application.h"
45+
#include "6LoWPAN/Thread/thread_leader_service.h"
4546
#include "6LoWPAN/Thread/thread_tmfcop_lib.h"
4647
#include "6LoWPAN/Thread/thread_host_bootstrap.h"
4748
#include "6LoWPAN/Thread/thread_router_bootstrap.h"
@@ -594,6 +595,12 @@ static void thread_parse_data_response(protocol_interface_info_entry_t *cur, mle
594595
tr_debug("SET NWK data Request state");
595596
}
596597
}
598+
599+
// leader has finished synching network data after reset/restart
600+
if (cur->thread_info->leader_synced) {
601+
cur->thread_info->leader_synced = false;
602+
thread_leader_service_network_data_changed(cur, true, true);
603+
}
597604
}
598605
static int thread_host_child_update_response_send(protocol_interface_info_entry_t *cur, uint8_t *dst_address, mle_tlv_info_t *challengeTlv, mle_tlv_info_t *requestTlv)
599606
{

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,11 @@ static void thread_router_synch_receive_cb(int8_t interface_id, mle_message_t *m
399399
if (thread_leader_service_thread_partitition_restart(interface_id, &routing)) {
400400
return;
401401
}
402+
thread_network_data_request_send(cur, mle_msg->packet_src_address, false);
403+
// force leader to learn active/pending sets from data response
404+
cur->thread_info->leader_synced = true;
405+
// Prevent the Leader to learn network data from data response
406+
cur->thread_info->networkDataRequested = false;
402407
tr_info("Router synch OK as Leader");
403408
} else {
404409
// Decrement data version and request network data to be updated
@@ -773,13 +778,14 @@ static int mle_build_and_send_data_response_msg(protocol_interface_info_entry_t
773778

774779
length += thread_pending_timestamp_tlv_size(cur);
775780

776-
777781
if (!active_timestamp_present_in_request || active_timestamp != link_configuration->timestamp) {
778782
length += thread_active_operational_dataset_size(cur);
779783
add_active_configuration = true;
780784
}
781785
own_pending_timestamp = thread_joiner_application_pending_config_timestamp_get(cur->id);
782-
if (!pending_timestamp_present_in_request || (own_pending_timestamp && own_pending_timestamp != pending_timestamp)) {
786+
// if pending config is not in sync from requested device
787+
if (!pending_timestamp_present_in_request ||
788+
(own_pending_timestamp && own_pending_timestamp != pending_timestamp)) {
783789
length += thread_pending_operational_dataset_size(cur);
784790
add_pending_configuration = true;
785791
}

test/nanostack/unittest/stub/thread_joiner_application_stub.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,4 +419,7 @@ int thread_joiner_application_link_configuration_delete(int8_t interface_id)
419419
{
420420
return 0;
421421
}
422-
422+
bool thread_joiner_application_pending_delay_timer_in_sync(int8_t interface_id)
423+
{
424+
return false;
425+
}

0 commit comments

Comments
 (0)