diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index b6d6791b1..8cfe5d4f6 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -765,9 +765,7 @@ void AddressResolver::HandleAddressError(Coap::Message &aMessage, const Ip6::Mes if (child.RemoveIp6Address(target) == OT_ERROR_NONE) { - destination.Clear(); - destination.mFields.m16[0] = HostSwap16(0xfe80); - destination.SetIid(child.GetExtAddress()); + SuccessOrExit(error = Get().GetLocatorAddress(destination, child.GetRloc16())); SendAddressError(target, meshLocalIid, &destination); ExitNow(); diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 0c6e2fcfb..330af0f3d 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -1108,14 +1108,14 @@ exit: return error; } -otError Mle::GetAlocAddress(Ip6::Address &aAddress, uint16_t aAloc16) const +otError Mle::GetLocatorAddress(Ip6::Address &aAddress, uint16_t aLocator) const { otError error = OT_ERROR_NONE; VerifyOrExit(GetRloc16() != Mac::kShortAddrInvalid, error = OT_ERROR_DETACHED); memcpy(&aAddress, &mMeshLocal16.GetAddress(), 14); - aAddress.SetLocator(aAloc16); + aAddress.SetLocator(aLocator); exit: return error; diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index cffeaaa19..cb82a2507 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -779,7 +779,7 @@ public: * @retval OT_ERROR_DETACHED The Thread interface is not currently attached to a Thread Partition. * */ - otError GetLeaderAloc(Ip6::Address &aAddress) const { return GetAlocAddress(aAddress, kAloc16Leader); } + otError GetLeaderAloc(Ip6::Address &aAddress) const { return GetLocatorAddress(aAddress, kAloc16Leader); } /** * This method computes the Commissioner's ALOC. @@ -793,7 +793,7 @@ public: */ otError GetCommissionerAloc(Ip6::Address &aAddress, uint16_t aSessionId) const { - return GetAlocAddress(aAddress, CommissionerAloc16FromId(aSessionId)); + return GetLocatorAddress(aAddress, CommissionerAloc16FromId(aSessionId)); } /** @@ -973,6 +973,18 @@ public: */ void RequestShorterChildIdRequest(void); + /** + * This method gets the RLOC or ALOC of a given RLOC16 or ALOC16. + * + * @param[out] aAddress A reference to the RLOC or ALOC. + * @param[in] aLocator RLOC16 or ALOC16. + * + * @retval OT_ERROR_NONE If got the RLOC or ALOC successfully. + * @retval OT_ERROR_DETACHED If device is detached. + * + */ + otError GetLocatorAddress(Ip6::Address &aAddress, uint16_t aLocator) const; + protected: /** * States during attach (when searching for a parent). @@ -1756,7 +1768,6 @@ private: uint8_t aVersion); bool IsNetworkDataNewer(const LeaderData &aLeaderData); - otError GetAlocAddress(Ip6::Address &aAddress, uint16_t aAloc16) const; #if OPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE /** * This method scans for network data from the leader and updates IP addresses assigned to this