From 827555139c8390911f12860330febd08e2bf4610 Mon Sep 17 00:00:00 2001 From: Buke Po Date: Fri, 17 Feb 2017 06:00:07 +0800 Subject: [PATCH] reattach when parent fails to respond to child update request (#1330) --- src/core/thread/mle.cpp | 15 +++++++++++++-- src/core/thread/mle.hpp | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 2cf37b000..30ed28780 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -539,6 +539,7 @@ ThreadError Mle::SetStateChild(uint16_t aRloc16) if ((mDeviceMode & ModeTlv::kModeRxOnWhenIdle) != 0) { + mKeepAliveAttemptsSent = 0; mParentRequestTimer.Start(Timer::SecToMsec(mTimeout / kMaxChildKeepAliveAttempts)); } @@ -1256,8 +1257,17 @@ void Mle::HandleParentRequestTimer(void) { if (mDeviceMode & ModeTlv::kModeRxOnWhenIdle) { - SendChildUpdateRequest(); - mParentRequestTimer.Start(Timer::SecToMsec(mTimeout / kMaxChildKeepAliveAttempts)); + if (mKeepAliveAttemptsSent >= kMaxChildKeepAliveAttempts) + { + // Reattach when no Child Update Response received for more than kMaxChildKeepAliveAttempts + BecomeDetached(); + } + else + { + SendChildUpdateRequest(); + mKeepAliveAttemptsSent++; + mParentRequestTimer.Start(Timer::SecToMsec(mTimeout / kMaxChildKeepAliveAttempts)); + } } } else @@ -2927,6 +2937,7 @@ ThreadError Mle::HandleChildUpdateResponse(const Message &aMessage, const Ip6::M } else { + mKeepAliveAttemptsSent = 0; mNetif.GetMeshForwarder().SetRxOnWhenIdle(true); } diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 614ac6e0c..54d1f868f 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -1419,6 +1419,7 @@ private: uint8_t mParentLinkQuality3; uint8_t mParentLinkQuality2; uint8_t mParentLinkQuality1; + uint8_t mKeepAliveAttemptsSent; LeaderDataTlv mParentLeaderData; bool mParentIsSingleton;