Skip to content

Commit 0a32cb4

Browse files
added active and pending timestamps to child update response (ARMmbed#1533)
if network data is requested. Active and pending operational datasets are also added if the timestamps do not match.
1 parent d0eec80 commit 0a32cb4

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

source/6LoWPAN/Thread/thread_router_bootstrap.c

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ static void thread_bootstrap_client_router_id_release_cb(int8_t interface_id, in
100100
static int thread_router_synch_accept_request_build(protocol_interface_info_entry_t *cur, mle_message_t *mle_msg, uint16_t shortAddress, uint8_t *challenge, uint8_t chalLen, uint8_t *tlvReq, uint8_t tlvReqLen);
101101
static int thread_router_accept_to_endevice(protocol_interface_info_entry_t *cur, mle_message_t *mle_msg, uint8_t *challenge, uint8_t chalLen);
102102
static int thread_router_accept_request_build(protocol_interface_info_entry_t *cur, mle_message_t *mle_msg, uint16_t shortAddress, uint8_t *challenge, uint8_t chalLen, uint8_t type, bool rssi_tlv, uint8_t rssi);
103-
static int thread_child_update_response(protocol_interface_info_entry_t *cur, uint8_t *dst_address, uint8_t mode, uint16_t short_address, uint32_t timeout, mle_tlv_info_t *addressRegisterTlv,mle_tlv_info_t *tlvReq, mle_tlv_info_t *challengeTlv);
103+
static int thread_child_update_response(protocol_interface_info_entry_t *cur, uint8_t *dst_address, uint8_t mode, uint16_t short_address, uint32_t timeout, mle_tlv_info_t *addressRegisterTlv,mle_tlv_info_t *tlvReq, mle_tlv_info_t *challengeTlv, uint64_t active_timestamp, uint64_t pending_timestamp);
104104
static int mle_build_and_send_data_response_msg(protocol_interface_info_entry_t *cur, uint8_t *dst_address, uint8_t *data_ptr, uint16_t data_len, mle_tlv_info_t *request_tlv, uint8_t mode);
105105
static int thread_attach_parent_response_build(protocol_interface_info_entry_t *cur, uint8_t *dstAddress, uint8_t *challenge, uint16_t chalLen, uint8_t linkMargin, uint8_t scanMask, uint8_t mode);
106106
static int mle_attach_child_id_response_build(protocol_interface_info_entry_t *cur, uint8_t *dstAddress,thread_pending_child_id_req_t *child_req,mle_neigh_table_entry_t *neigh_info);
@@ -681,16 +681,39 @@ static uint8_t *thread_tlv_add(protocol_interface_info_entry_t *cur, uint8_t *pt
681681
return ptr;
682682
}
683683

684-
static int thread_child_update_response(protocol_interface_info_entry_t *cur, uint8_t *dst_address, uint8_t mode, uint16_t short_address, uint32_t timeout, mle_tlv_info_t *addressRegisterTlv,mle_tlv_info_t *tlvReq, mle_tlv_info_t *challengeTlv)
684+
static int thread_child_update_response(protocol_interface_info_entry_t *cur, uint8_t *dst_address, uint8_t mode, uint16_t short_address, uint32_t timeout, mle_tlv_info_t *addressRegisterTlv,mle_tlv_info_t *tlvReq, mle_tlv_info_t *challengeTlv, uint64_t active_timestamp, uint64_t pending_timestamp)
685685
{
686686
uint16_t i;
687687
uint16_t len = 64;
688688
uint32_t keySequence;
689+
bool add_active_configuration = false;
690+
bool add_pending_configuration = false;
691+
uint64_t own_pending_timestamp = 0;
689692
uint8_t *ptr;
690693
if (!thread_info(cur)) {
691694
return -1;
692695
}
696+
link_configuration_s *link_configuration;
697+
link_configuration = thread_joiner_application_get_config(cur->id);
698+
699+
if (!link_configuration) {
700+
return -1;
701+
}
693702

703+
len += 10; // active timestamp tlv size
704+
len += thread_pending_timestamp_tlv_size(cur);
705+
706+
if (!active_timestamp || active_timestamp != link_configuration->timestamp) {
707+
len += thread_active_operational_dataset_size(cur);
708+
add_active_configuration = true;
709+
}
710+
own_pending_timestamp = thread_joiner_application_pending_config_timestamp_get(cur->id);
711+
// if pending config is not in sync from requested device
712+
if (!pending_timestamp ||
713+
(own_pending_timestamp && own_pending_timestamp != pending_timestamp)) {
714+
len += thread_pending_operational_dataset_size(cur);
715+
add_pending_configuration = true;
716+
}
694717
if (tlvReq && tlvReq->tlvLen) {
695718
mle_tlv_ignore(tlvReq->dataPtr, tlvReq->tlvLen, MLE_TYPE_LL_FRAME_COUNTER);
696719
len += thread_tlv_len(cur, tlvReq->dataPtr, tlvReq->tlvLen, mode);
@@ -743,6 +766,16 @@ static int thread_child_update_response(protocol_interface_info_entry_t *cur, ui
743766
if (mle_tlv_requested(tlvReq->dataPtr, tlvReq->tlvLen, MLE_TYPE_ADDRESS16)) {
744767
ptr = mle_tlv_write_short_address(ptr, short_address);
745768
}
769+
if (mle_tlv_requested(tlvReq->dataPtr, tlvReq->tlvLen, MLE_TYPE_NETWORK_DATA)) {
770+
ptr = thread_active_timestamp_write(cur,ptr);
771+
ptr = thread_pending_timestamp_write(cur,ptr);
772+
if (add_active_configuration) {
773+
ptr = thread_active_operational_dataset_write(cur, ptr);
774+
}
775+
if (add_pending_configuration) {
776+
ptr = thread_pending_operational_dataset_write(cur, ptr);
777+
}
778+
}
746779
}
747780

748781
if (mle_service_update_length_by_ptr(bufId,ptr)!= 0) {
@@ -1826,6 +1859,8 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
18261859
uint8_t mode;
18271860
uint8_t status;
18281861
uint32_t timeout = 0;
1862+
uint64_t active_timestamp = 0;
1863+
uint64_t pending_timestamp = 0;
18291864
mle_tlv_info_t addressRegisterTlv = {0};
18301865
mle_tlv_info_t challengeTlv = {0};
18311866
mle_tlv_info_t tlv_req = {0};
@@ -1859,6 +1894,8 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
18591894

18601895
addressRegisterTlv.tlvType = MLE_TYPE_UNASSIGNED;
18611896
mle_tlv_read_tlv(MLE_TYPE_ADDRESS_REGISTRATION, mle_msg->data_ptr, mle_msg->data_length, &addressRegisterTlv);
1897+
mle_tlv_read_64_bit_tlv(MLE_TYPE_ACTIVE_TIMESTAMP, mle_msg->data_ptr, mle_msg->data_length, &active_timestamp);
1898+
mle_tlv_read_64_bit_tlv(MLE_TYPE_PENDING_TIMESTAMP, mle_msg->data_ptr, mle_msg->data_length, &pending_timestamp);
18621899

18631900
mle_tlv_read_tlv(MLE_TYPE_TLV_REQUEST, mle_msg->data_ptr, mle_msg->data_length, &tlv_req);
18641901

@@ -1881,7 +1918,7 @@ void thread_router_bootstrap_mle_receive_cb(int8_t interface_id, mle_message_t *
18811918

18821919
tr_debug("Keep-Alive -->Respond Child");
18831920
//Response
1884-
thread_child_update_response(cur, mle_msg->packet_src_address, mode, entry_temp->short_adr, timeout, &addressRegisterTlv, &tlv_req, &challengeTlv);
1921+
thread_child_update_response(cur, mle_msg->packet_src_address, mode, entry_temp->short_adr, timeout, &addressRegisterTlv, &tlv_req, &challengeTlv, active_timestamp, pending_timestamp);
18851922

18861923
}
18871924
break;

0 commit comments

Comments
 (0)