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;