diff --git a/src/core/mac/data_poll_sender.cpp b/src/core/mac/data_poll_sender.cpp index 189139bbc..e1395d16c 100644 --- a/src/core/mac/data_poll_sender.cpp +++ b/src/core/mac/data_poll_sender.cpp @@ -62,6 +62,13 @@ DataPollSender::DataPollSender(Instance &aInstance) { } +const Neighbor &DataPollSender::GetParent(void) const +{ + const Neighbor &parentCandidate = Get().GetParentCandidate(); + + return parentCandidate.IsStateValid() ? parentCandidate : Get().GetParent(); +} + otError DataPollSender::StartPolling(void) { otError error = OT_ERROR_NONE; @@ -90,14 +97,12 @@ void DataPollSender::StopPolling(void) otError DataPollSender::SendDataPoll(void) { - otError error; - Neighbor *parent; + otError error; VerifyOrExit(mEnabled, error = OT_ERROR_INVALID_STATE); VerifyOrExit(!Get().GetRxOnWhenIdle(), error = OT_ERROR_INVALID_STATE); - parent = Get().GetParentCandidate(); - VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE); + VerifyOrExit(GetParent().IsStateValidOrRestoring(), error = OT_ERROR_INVALID_STATE); mTimer.Stop(); @@ -133,18 +138,20 @@ exit: otError DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const { - otError error = OT_ERROR_NONE; - Neighbor *parent = Get().GetParentCandidate(); + otError error = OT_ERROR_NONE; + const Neighbor &parent = GetParent(); - VerifyOrExit((parent != NULL) && parent->IsStateValidOrRestoring(), error = OT_ERROR_ABORT); + VerifyOrExit(parent.IsStateValidOrRestoring(), error = OT_ERROR_ABORT); - if ((Get().GetShortAddress() == Mac::kShortAddrInvalid) || (parent != &Get().GetParent())) + // Use extended address attaching to a new parent (i.e. parent is the parent candidate). + if ((Get().GetShortAddress() == Mac::kShortAddrInvalid) || + (&parent == &Get().GetParentCandidate())) { - aDest.SetExtended(parent->GetExtAddress()); + aDest.SetExtended(parent.GetExtAddress()); } else { - aDest.SetShort(parent->GetRloc16()); + aDest.SetShort(parent.GetRloc16()); } exit: @@ -205,7 +212,7 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, otError aError) Get().UpdateNeighborOnSentFrame(aFrame, aError, macDest); } - if (Get().GetParentCandidate()->IsStateInvalid()) + if (GetParent().IsStateInvalid()) { StopPolling(); Get().BecomeDetached(); diff --git a/src/core/mac/data_poll_sender.hpp b/src/core/mac/data_poll_sender.hpp index 40458500a..4d6dc4035 100644 --- a/src/core/mac/data_poll_sender.hpp +++ b/src/core/mac/data_poll_sender.hpp @@ -40,6 +40,7 @@ #include "common/locator.hpp" #include "common/timer.hpp" #include "mac/mac_frame.hpp" +#include "thread/topology.hpp" namespace ot { @@ -266,10 +267,11 @@ private: kRecalculatePollPeriod, }; - void ScheduleNextPoll(PollPeriodSelector aPollPeriodSelector); - uint32_t CalculatePollPeriod(void) const; - static void HandlePollTimer(Timer &aTimer); - static void UpdateIfLarger(uint32_t &aPeriod, uint32_t aNewPeriod); + void ScheduleNextPoll(PollPeriodSelector aPollPeriodSelector); + uint32_t CalculatePollPeriod(void) const; + const Neighbor &GetParent(void) const; + static void HandlePollTimer(Timer &aTimer); + static void UpdateIfLarger(uint32_t &aPeriod, uint32_t aNewPeriod); TimeMilli mTimerStartTime; uint32_t mPollPeriod; diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index f45fecaf5..ca2b589c3 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -3959,22 +3959,6 @@ bool Mle::IsMeshLocalAddress(const Ip6::Address &aAddress) const return aAddress.PrefixMatch(GetMeshLocal16()) >= Ip6::Address::kMeshLocalPrefixLength; } -Router *Mle::GetParentCandidate(void) -{ - Router *rval; - - if (mParentCandidate.IsStateValid()) - { - rval = &mParentCandidate; - } - else - { - rval = &mParent; - } - - return rval; -} - otError Mle::CheckReachability(uint16_t aMeshSource, uint16_t aMeshDest, Ip6::Header &aIp6Header) { otError error = OT_ERROR_DROP; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index 4230c9476..2910b4010 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -755,15 +755,12 @@ public: Router &GetParent(void) { return mParent; } /** - * This method returns a pointer to the parent candidate or parent. + * This method get the parent candidate. * - * This method is useful when sending IEEE 802.15.4 Data Request frames while attempting to attach to a new parent. - * - * If attempting to attach to a new parent, this method returns the parent candidate. - * If not attempting to attach, this method returns the parent. + * The parent candidate is valid when attempting to attach to a new parent. * */ - Router *GetParentCandidate(void); + Router &GetParentCandidate(void) { return mParentCandidate; } /** * This method indicates whether or not an IPv6 address is an RLOC.