diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index 8a6b8611f..5ff167ed0 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -1157,7 +1157,7 @@ void MeshForwarder::UpdateNeighborLinkFailures(Neighbor &aNeighbor, { aNeighbor.IncrementLinkFailures(); - if (aAllowNeighborRemove && (Mle::IsActiveRouter(aNeighbor.GetRloc16())) && + if (aAllowNeighborRemove && (Mle::IsRouterRloc16(aNeighbor.GetRloc16())) && (aNeighbor.GetLinkFailures() >= aFailLimit)) { #if OPENTHREAD_FTD diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 4b29627d5..810d2c62f 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -487,7 +487,7 @@ Error MeshForwarder::AnycastRouteLookup(uint8_t aServiceId, AnycastType aType, u routerId = Mle::RouterIdFromRloc16(bestDest); - if (!(Mle::IsActiveRouter(bestDest) || Mle::Rloc16FromRouterId(routerId) == Get().GetRloc16())) + if (!(Mle::IsRouterRloc16(bestDest) || Mle::Rloc16FromRouterId(routerId) == Get().GetRloc16())) { // if agent is neither active router nor child of this device // use the parent of the ED Agent as Dest diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 246d73f2c..00d754c50 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -214,7 +214,7 @@ Error Mle::Start(StartMode aMode) Attach(kAnyPartition); } #if OPENTHREAD_FTD - else if (IsActiveRouter(GetRloc16())) + else if (IsRouterRloc16(GetRloc16())) { if (Get().BecomeRouter(ThreadStatusTlv::kTooFewRouters) != kErrorNone) { @@ -397,7 +397,7 @@ void Mle::Restore(void) } #if OPENTHREAD_MTD - if (!IsActiveRouter(networkInfo.GetRloc16())) + if (IsChildRloc16(networkInfo.GetRloc16())) #endif { Get().SetShortAddress(networkInfo.GetRloc16()); @@ -412,7 +412,7 @@ void Mle::Restore(void) ExitNow(); } - if (!IsActiveRouter(networkInfo.GetRloc16())) + if (IsChildRloc16(networkInfo.GetRloc16())) { if (Get().Read(parentInfo) != kErrorNone) { @@ -2751,7 +2751,7 @@ void Mle::ReestablishLinkWithNeighbor(Neighbor &aNeighbor) #if OPENTHREAD_FTD VerifyOrExit(IsFullThreadDevice()); - if (IsActiveRouter(aNeighbor.GetRloc16())) + if (IsRouterRloc16(aNeighbor.GetRloc16())) { IgnoreError(Get().SendLinkRequest(&aNeighbor)); } @@ -3045,7 +3045,7 @@ bool Mle::IsBetterParent(uint16_t aRloc16, rval = ThreeWayCompare(LinkQualityForLinkMargin(aTwoWayLinkMargin), mParentCandidate.GetTwoWayLinkQuality()); VerifyOrExit(rval == 0); - rval = ThreeWayCompare(IsActiveRouter(aRloc16), IsActiveRouter(mParentCandidate.GetRloc16())); + rval = ThreeWayCompare(IsRouterRloc16(aRloc16), IsRouterRloc16(mParentCandidate.GetRloc16())); VerifyOrExit(rval == 0); rval = ThreeWayCompare(aConnectivityTlv.GetParentPriority(), mParentCandidate.mPriority); diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_router.cpp index 9642aaef1..2edd75f44 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_router.cpp @@ -702,7 +702,7 @@ void MleRouter::HandleLinkRequest(RxInfo &aRxInfo) switch (Tlv::Find(aRxInfo.mMessage, sourceAddress)) { case kErrorNone: - if (IsActiveRouter(sourceAddress)) + if (IsRouterRloc16(sourceAddress)) { neighbor = mRouterTable.FindRouterByRloc16(sourceAddress); VerifyOrExit(neighbor != nullptr, error = kErrorParse); @@ -727,7 +727,7 @@ void MleRouter::HandleLinkRequest(RxInfo &aRxInfo) case kErrorNotFound: // A missing source address indicates that the router was // recently reset. - VerifyOrExit(aRxInfo.IsNeighborStateValid() && IsActiveRouter(aRxInfo.mNeighbor->GetRloc16()), + VerifyOrExit(aRxInfo.IsNeighborStateValid() && IsRouterRloc16(aRxInfo.mNeighbor->GetRloc16()), error = kErrorDrop); neighbor = aRxInfo.mNeighbor; break; @@ -791,7 +791,7 @@ Error MleRouter::SendLinkAccept(const RxInfo &aRxInfo, linkMargin = Get().ComputeLinkMargin(aRxInfo.mMessage.GetAverageRss()); SuccessOrExit(error = message->AppendLinkMarginTlv(linkMargin)); - if (aNeighbor != nullptr && IsActiveRouter(aNeighbor->GetRloc16())) + if (aNeighbor != nullptr && IsRouterRloc16(aNeighbor->GetRloc16())) { SuccessOrExit(error = message->AppendLeaderDataTlv()); } @@ -891,7 +891,7 @@ Error MleRouter::HandleLinkAccept(RxInfo &aRxInfo, bool aRequest) Log(kMessageReceive, aRequest ? kTypeLinkAcceptAndRequest : kTypeLinkAccept, aRxInfo.mMessageInfo.GetPeerAddr(), sourceAddress); - VerifyOrExit(IsActiveRouter(sourceAddress), error = kErrorParse); + VerifyOrExit(IsRouterRloc16(sourceAddress), error = kErrorParse); routerId = RouterIdFromRloc16(sourceAddress); router = mRouterTable.FindRouterById(routerId); @@ -1249,7 +1249,7 @@ Error MleRouter::HandleAdvertisement(RxInfo &aRxInfo, uint16_t aSourceAddress, c ExitNow(); } - VerifyOrExit(IsActiveRouter(aSourceAddress) && routeTlv.IsValid()); + VerifyOrExit(IsRouterRloc16(aSourceAddress) && routeTlv.IsValid()); routerId = RouterIdFromRloc16(aSourceAddress); #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE @@ -2353,7 +2353,7 @@ void MleRouter::HandleChildUpdateResponse(RxInfo &aRxInfo) LeaderData leaderData; Child *child; - if ((aRxInfo.mNeighbor == nullptr) || IsActiveRouter(aRxInfo.mNeighbor->GetRloc16()) || + if ((aRxInfo.mNeighbor == nullptr) || IsRouterRloc16(aRxInfo.mNeighbor->GetRloc16()) || !Get().Contains(*aRxInfo.mNeighbor)) { Log(kMessageReceive, kTypeChildUpdateResponseOfUnknownChild, aRxInfo.mMessageInfo.GetPeerAddr()); @@ -3143,7 +3143,7 @@ void MleRouter::RemoveNeighbor(Neighbor &aNeighbor) { ClearParentCandidate(); } - else if (!IsActiveRouter(aNeighbor.GetRloc16())) + else if (IsChildRloc16(aNeighbor.GetRloc16())) { OT_ASSERT(mChildTable.Contains(aNeighbor)); diff --git a/src/core/thread/mle_types.hpp b/src/core/thread/mle_types.hpp index fd08cdccd..a228d06ee 100644 --- a/src/core/thread/mle_types.hpp +++ b/src/core/thread/mle_types.hpp @@ -682,15 +682,26 @@ inline uint16_t CommissionerAloc16FromId(uint16_t aSessionId) inline uint16_t Rloc16FromRouterId(uint8_t aRouterId) { return static_cast(aRouterId << kRouterIdOffset); } /** - * Indicates whether or not @p aRloc16 refers to an active router. + * Indicates whether or not @p aRloc16 refers to a router. * * @param[in] aRloc16 The RLOC16 value. * - * @retval TRUE If @p aRloc16 refers to an active router. - * @retval FALSE If @p aRloc16 does not refer to an active router. + * @retval TRUE If @p aRloc16 refers to a router. + * @retval FALSE If @p aRloc16 does not refer to a router. * */ -inline bool IsActiveRouter(uint16_t aRloc16) { return ChildIdFromRloc16(aRloc16) == 0; } +inline bool IsRouterRloc16(uint16_t aRloc16) { return ChildIdFromRloc16(aRloc16) == 0; } + +/** + * Indicates whether or not @p aRloc16 refers to a child. + * + * @param[in] aRloc16 The RLOC16 value. + * + * @retval TRUE If @p aRloc16 refers to a child. + * @retval FALSE If @p aRloc16 does not refer to a child. + * + */ +inline bool IsChildRloc16(uint16_t aRloc16) { return ChildIdFromRloc16(aRloc16) != 0; } /** * Converts a device role into a human-readable string. diff --git a/src/core/thread/network_data.cpp b/src/core/thread/network_data.cpp index 28675ad6f..9ced6a310 100644 --- a/src/core/thread/network_data.cpp +++ b/src/core/thread/network_data.cpp @@ -579,11 +579,11 @@ void NetworkData::AddRloc16ToRlocs(uint16_t aRloc16, Rlocs &aRlocs, RoleFilter a break; case kRouterRoleOnly: - VerifyOrExit(Mle::IsActiveRouter(aRloc16)); + VerifyOrExit(Mle::IsRouterRloc16(aRloc16)); break; case kChildRoleOnly: - VerifyOrExit(!Mle::IsActiveRouter(aRloc16)); + VerifyOrExit(Mle::IsChildRloc16(aRloc16)); break; } diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 187e431c2..95b978907 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -339,7 +339,7 @@ int Leader::CompareRouteEntries(int8_t aFirstPreference, // If all the same, prefer the BR acting as a router over an // end device. - result = ThreeWayCompare(Mle::IsActiveRouter(aFirstRloc), Mle::IsActiveRouter(aSecondRloc)); + result = ThreeWayCompare(Mle::IsRouterRloc16(aFirstRloc), Mle::IsRouterRloc16(aSecondRloc)); #endif exit: diff --git a/src/core/thread/network_data_notifier.cpp b/src/core/thread/network_data_notifier.cpp index e5eebe62c..8d086baa2 100644 --- a/src/core/thread/network_data_notifier.cpp +++ b/src/core/thread/network_data_notifier.cpp @@ -138,7 +138,7 @@ Error Notifier::RemoveStaleChildEntries(void) for (uint16_t rloc16 : rlocs) { - if (!Mle::IsActiveRouter(rloc16) && Mle::RouterIdMatch(Get().GetRloc16(), rloc16) && + if (Mle::IsChildRloc16(rloc16) && Mle::RouterIdMatch(Get().GetRloc16(), rloc16) && Get().FindChild(rloc16, Child::kInStateValid) == nullptr) { error = SendServerDataNotification(rloc16); diff --git a/src/core/thread/network_data_publisher.cpp b/src/core/thread/network_data_publisher.cpp index 3ad23a330..5bf16d30e 100644 --- a/src/core/thread/network_data_publisher.cpp +++ b/src/core/thread/network_data_publisher.cpp @@ -275,7 +275,7 @@ bool Publisher::Entry::IsPreferred(uint16_t aRloc16) const // router over an entry from an end-device (e.g., a REED). If both // are the same type, then the one with smaller RLOC16 is preferred. - bool isOtherRouter = Mle::IsActiveRouter(aRloc16); + bool isOtherRouter = Mle::IsRouterRloc16(aRloc16); return (Get().IsRouterOrLeader() == isOtherRouter) ? (aRloc16 < Get().GetRloc16()) : isOtherRouter; diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index 7117e5c94..16a4d98c5 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -322,7 +322,7 @@ Error RouterTable::GetRouterInfo(uint16_t aRouterId, Router::Info &aRouterInfo) } else { - VerifyOrExit(Mle::IsActiveRouter(aRouterId), error = kErrorInvalidArgs); + VerifyOrExit(Mle::IsRouterRloc16(aRouterId), error = kErrorInvalidArgs); routerId = Mle::RouterIdFromRloc16(aRouterId); VerifyOrExit(routerId <= Mle::kMaxRouterId, error = kErrorInvalidArgs); } @@ -486,7 +486,7 @@ void RouterTable::GetNextHopAndPathCost(uint16_t aDestRloc16, uint16_t &aNextHop } } - if (!Mle::IsActiveRouter(aDestRloc16)) + if (Mle::IsChildRloc16(aDestRloc16)) { // Destination is a child. we assume best link quality // between destination and its parent router. @@ -721,7 +721,7 @@ void RouterTable::FillRouteTlv(Mle::RouteTlv &aRouteTlv, const Neighbor *aNeighb mRouterIdMap.GetAsRouterIdSet(routerIdSet); - if ((aNeighbor != nullptr) && Mle::IsActiveRouter(aNeighbor->GetRloc16())) + if ((aNeighbor != nullptr) && Mle::IsRouterRloc16(aNeighbor->GetRloc16())) { // Sending a Link Accept message that may require truncation // of Route64 TLV. diff --git a/src/core/utils/mesh_diag.cpp b/src/core/utils/mesh_diag.cpp index e8092eb25..5e470b3f4 100644 --- a/src/core/utils/mesh_diag.cpp +++ b/src/core/utils/mesh_diag.cpp @@ -172,7 +172,7 @@ Error MeshDiag::SendQuery(uint16_t aRloc16, const uint8_t *aTlvs, uint8_t aTlvsL VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); VerifyOrExit(mState == kStateIdle, error = kErrorBusy); - VerifyOrExit(Mle::IsActiveRouter(aRloc16), error = kErrorInvalidArgs); + VerifyOrExit(Mle::IsRouterRloc16(aRloc16), error = kErrorInvalidArgs); VerifyOrExit(Get().IsAllocated(Mle::RouterIdFromRloc16(aRloc16)), error = kErrorNotFound); destination.SetToRoutingLocator(Get().GetMeshLocalPrefix(), aRloc16);