diff --git a/src/core/BUILD.gn b/src/core/BUILD.gn index 918bc3333..1474c21bf 100644 --- a/src/core/BUILD.gn +++ b/src/core/BUILD.gn @@ -660,8 +660,7 @@ openthread_core_files = [ "thread/mesh_forwarder_mtd.cpp", "thread/mle.cpp", "thread/mle.hpp", - "thread/mle_router.cpp", - "thread/mle_router.hpp", + "thread/mle_ftd.cpp", "thread/mle_tlvs.cpp", "thread/mle_tlvs.hpp", "thread/mle_types.cpp", diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 16d5db54d..5ad76fb14 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -224,7 +224,7 @@ set(COMMON_SOURCES thread/mesh_forwarder_ftd.cpp thread/mesh_forwarder_mtd.cpp thread/mle.cpp - thread/mle_router.cpp + thread/mle_ftd.cpp thread/mle_tlvs.cpp thread/mle_types.cpp thread/mlr_manager.cpp diff --git a/src/core/api/ip6_api.cpp b/src/core/api/ip6_api.cpp index a72e64a01..3ff0941e5 100644 --- a/src/core/api/ip6_api.cpp +++ b/src/core/api/ip6_api.cpp @@ -266,7 +266,7 @@ void otIp6SetSlaacPrefixFilter(otInstance *aInstance, otIp6SlaacPrefixFilter aFi otError otIp6SetMeshLocalIid(otInstance *aInstance, const otIp6InterfaceIdentifier *aIid) { - return AsCoreType(aInstance).Get().SetMeshLocalIid(AsCoreType(aIid)); + return AsCoreType(aInstance).Get().SetMeshLocalIid(AsCoreType(aIid)); } #endif diff --git a/src/core/api/link_api.cpp b/src/core/api/link_api.cpp index 15767000f..f53373370 100644 --- a/src/core/api/link_api.cpp +++ b/src/core/api/link_api.cpp @@ -69,7 +69,7 @@ otError otLinkSetChannel(otInstance *aInstance, uint8_t aChannel) } #endif - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); SuccessOrExit(error = instance.Get().SetPanChannel(aChannel)); instance.Get().Clear(); @@ -90,7 +90,7 @@ otError otLinkSetWakeupChannel(otInstance *aInstance, uint8_t aChannel) Error error = kErrorNone; Instance &instance = AsCoreType(aInstance); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); SuccessOrExit(error = instance.Get().SetWakeupChannel(aChannel)); @@ -112,7 +112,7 @@ otError otLinkSetSupportedChannelMask(otInstance *aInstance, uint32_t aChannelMa Error error = kErrorNone; Instance &instance = AsCoreType(aInstance); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetSupportedChannelMask(Mac::ChannelMask(aChannelMask)); @@ -130,11 +130,11 @@ otError otLinkSetExtendedAddress(otInstance *aInstance, const otExtAddress *aExt Error error = kErrorNone; Instance &instance = AsCoreType(aInstance); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetExtAddress(AsCoreType(aExtAddress)); - instance.Get().UpdateLinkLocalAddress(); + instance.Get().UpdateLinkLocalAddress(); exit: return error; @@ -152,7 +152,7 @@ otError otLinkSetPanId(otInstance *aInstance, otPanId aPanId) Error error = kErrorNone; Instance &instance = AsCoreType(aInstance); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetPanId(aPanId); instance.Get().Clear(); @@ -464,17 +464,14 @@ exit: return error; } -uint32_t otLinkGetCslTimeout(otInstance *aInstance) -{ - return AsCoreType(aInstance).Get().GetCslTimeout(); -} +uint32_t otLinkGetCslTimeout(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetCslTimeout(); } otError otLinkSetCslTimeout(otInstance *aInstance, uint32_t aTimeout) { Error error = kErrorNone; VerifyOrExit(kMaxCslTimeout >= aTimeout, error = kErrorInvalidArgs); - AsCoreType(aInstance).Get().SetCslTimeout(aTimeout); + AsCoreType(aInstance).Get().SetCslTimeout(aTimeout); exit: return error; diff --git a/src/core/api/netdata_api.cpp b/src/core/api/netdata_api.cpp index 1a5bec859..9db82b122 100644 --- a/src/core/api/netdata_api.cpp +++ b/src/core/api/netdata_api.cpp @@ -108,12 +108,12 @@ void otNetDataGetCommissioningDataset(otInstance *aInstance, otCommissioningData uint8_t otNetDataGetVersion(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetLeaderData().GetDataVersion(NetworkData::kFullSet); + return AsCoreType(aInstance).Get().GetLeaderData().GetDataVersion(NetworkData::kFullSet); } uint8_t otNetDataGetStableVersion(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetLeaderData().GetDataVersion(NetworkData::kStableSubset); + return AsCoreType(aInstance).Get().GetLeaderData().GetDataVersion(NetworkData::kStableSubset); } otError otNetDataSteeringDataCheckJoiner(otInstance *aInstance, const otExtAddress *aEui64) diff --git a/src/core/api/network_time_api.cpp b/src/core/api/network_time_api.cpp index 19c52f323..29d826b31 100644 --- a/src/core/api/network_time_api.cpp +++ b/src/core/api/network_time_api.cpp @@ -52,7 +52,7 @@ otError otNetworkTimeSetSyncPeriod(otInstance *aInstance, uint16_t aTimeSyncPeri { Error error = kErrorNone; - VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); AsCoreType(aInstance).Get().SetTimeSyncPeriod(aTimeSyncPeriod); @@ -69,7 +69,7 @@ otError otNetworkTimeSetXtalThreshold(otInstance *aInstance, uint16_t aXtalThres { Error error = kErrorNone; - VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); AsCoreType(aInstance).Get().SetXtalThreshold(aXtalThreshold); diff --git a/src/core/api/thread_api.cpp b/src/core/api/thread_api.cpp index 9065ea449..d3529f054 100644 --- a/src/core/api/thread_api.cpp +++ b/src/core/api/thread_api.cpp @@ -39,14 +39,11 @@ using namespace ot; -uint32_t otThreadGetChildTimeout(otInstance *aInstance) -{ - return AsCoreType(aInstance).Get().GetTimeout(); -} +uint32_t otThreadGetChildTimeout(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetTimeout(); } void otThreadSetChildTimeout(otInstance *aInstance, uint32_t aTimeout) { - AsCoreType(aInstance).Get().SetTimeout(aTimeout); + AsCoreType(aInstance).Get().SetTimeout(aTimeout); } const otExtendedPanId *otThreadGetExtendedPanId(otInstance *aInstance) @@ -60,7 +57,7 @@ otError otThreadSetExtendedPanId(otInstance *aInstance, const otExtendedPanId *a Instance &instance = AsCoreType(aInstance); const MeshCoP::ExtendedPanId &extPanId = AsCoreType(aExtendedPanId); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetExtPanId(extPanId); @@ -86,14 +83,14 @@ otLinkModeConfig otThreadGetLinkMode(otInstance *aInstance) { otLinkModeConfig config; - AsCoreType(aInstance).Get().GetDeviceMode().Get(config); + AsCoreType(aInstance).Get().GetDeviceMode().Get(config); return config; } otError otThreadSetLinkMode(otInstance *aInstance, otLinkModeConfig aConfig) { - return AsCoreType(aInstance).Get().SetDeviceMode(Mle::DeviceMode(aConfig)); + return AsCoreType(aInstance).Get().SetDeviceMode(Mle::DeviceMode(aConfig)); } void otThreadGetNetworkKey(otInstance *aInstance, otNetworkKey *aNetworkKey) @@ -113,7 +110,7 @@ otError otThreadSetNetworkKey(otInstance *aInstance, const otNetworkKey *aKey) Error error = kErrorNone; Instance &instance = AsCoreType(aInstance); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetNetworkKey(AsCoreType(aKey)); @@ -132,7 +129,7 @@ otError otThreadSetNetworkKeyRef(otInstance *aInstance, otNetworkKeyRef aKeyRef) VerifyOrExit(aKeyRef != 0, error = kErrorInvalidArgs); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetNetworkKeyRef((aKeyRef)); instance.Get().Clear(); @@ -145,26 +142,26 @@ exit: const otIp6Address *otThreadGetRloc(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetMeshLocalRloc(); + return &AsCoreType(aInstance).Get().GetMeshLocalRloc(); } const otIp6Address *otThreadGetMeshLocalEid(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetMeshLocalEid(); + return &AsCoreType(aInstance).Get().GetMeshLocalEid(); } const otMeshLocalPrefix *otThreadGetMeshLocalPrefix(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetMeshLocalPrefix(); + return &AsCoreType(aInstance).Get().GetMeshLocalPrefix(); } otError otThreadSetMeshLocalPrefix(otInstance *aInstance, const otMeshLocalPrefix *aMeshLocalPrefix) { Error error = kErrorNone; - VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); - AsCoreType(aInstance).Get().SetMeshLocalPrefix(AsCoreType(aMeshLocalPrefix)); + AsCoreType(aInstance).Get().SetMeshLocalPrefix(AsCoreType(aMeshLocalPrefix)); AsCoreType(aInstance).Get().Clear(); AsCoreType(aInstance).Get().Clear(); @@ -174,17 +171,17 @@ exit: const otIp6Address *otThreadGetLinkLocalIp6Address(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetLinkLocalAddress(); + return &AsCoreType(aInstance).Get().GetLinkLocalAddress(); } const otIp6Address *otThreadGetLinkLocalAllThreadNodesMulticastAddress(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetLinkLocalAllThreadNodesAddress(); + return &AsCoreType(aInstance).Get().GetLinkLocalAllThreadNodesAddress(); } const otIp6Address *otThreadGetRealmLocalAllThreadNodesMulticastAddress(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetRealmLocalAllThreadNodesAddress(); + return &AsCoreType(aInstance).Get().GetRealmLocalAllThreadNodesAddress(); } otError otThreadGetServiceAloc(otInstance *aInstance, uint8_t aServiceId, otIp6Address *aServiceAloc) @@ -207,7 +204,7 @@ otError otThreadSetNetworkName(otInstance *aInstance, const char *aNetworkName) { Error error = kErrorNone; - VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); #if !OPENTHREAD_CONFIG_ALLOW_EMPTY_NETWORK_NAME // Thread interfaces support a zero length name internally for backwards compatibility, but new names @@ -233,7 +230,7 @@ otError otThreadSetDomainName(otInstance *aInstance, const char *aDomainName) { Error error = kErrorNone; - VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); error = AsCoreType(aInstance).Get().SetDomainName(aDomainName); @@ -295,12 +292,9 @@ void otThreadSetKeySwitchGuardTime(otInstance *aInstance, uint16_t aKeySwitchGua AsCoreType(aInstance).Get().SetKeySwitchGuardTime(aKeySwitchGuardTime); } -otError otThreadBecomeDetached(otInstance *aInstance) -{ - return AsCoreType(aInstance).Get().BecomeDetached(); -} +otError otThreadBecomeDetached(otInstance *aInstance) { return AsCoreType(aInstance).Get().BecomeDetached(); } -otError otThreadBecomeChild(otInstance *aInstance) { return AsCoreType(aInstance).Get().BecomeChild(); } +otError otThreadBecomeChild(otInstance *aInstance) { return AsCoreType(aInstance).Get().BecomeChild(); } otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterator *aIterator, otNeighborInfo *aInfo) { @@ -311,7 +305,7 @@ otError otThreadGetNextNeighborInfo(otInstance *aInstance, otNeighborInfoIterato otDeviceRole otThreadGetDeviceRole(otInstance *aInstance) { - return MapEnum(AsCoreType(aInstance).Get().GetRole()); + return MapEnum(AsCoreType(aInstance).Get().GetRole()); } const char *otThreadDeviceRoleToString(otDeviceRole aRole) { return Mle::RoleToString(MapEnum(aRole)); } @@ -322,29 +316,26 @@ otError otThreadGetLeaderData(otInstance *aInstance, otLeaderData *aLeaderData) AssertPointerIsNotNull(aLeaderData); - VerifyOrExit(AsCoreType(aInstance).Get().IsAttached(), error = kErrorDetached); - *aLeaderData = AsCoreType(aInstance).Get().GetLeaderData(); + VerifyOrExit(AsCoreType(aInstance).Get().IsAttached(), error = kErrorDetached); + *aLeaderData = AsCoreType(aInstance).Get().GetLeaderData(); exit: return error; } -uint8_t otThreadGetLeaderRouterId(otInstance *aInstance) -{ - return AsCoreType(aInstance).Get().GetLeaderId(); -} +uint8_t otThreadGetLeaderRouterId(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetLeaderId(); } uint8_t otThreadGetLeaderWeight(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetLeaderData().GetWeighting(); + return AsCoreType(aInstance).Get().GetLeaderData().GetWeighting(); } uint32_t otThreadGetPartitionId(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetLeaderData().GetPartitionId(); + return AsCoreType(aInstance).Get().GetLeaderData().GetPartitionId(); } -uint16_t otThreadGetRloc16(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetRloc16(); } +uint16_t otThreadGetRloc16(otInstance *aInstance) { return AsCoreType(aInstance).Get().GetRloc16(); } otError otThreadGetParentInfo(otInstance *aInstance, otRouterInfo *aParentInfo) { @@ -357,7 +348,7 @@ otError otThreadGetParentAverageRssi(otInstance *aInstance, int8_t *aParentRssi) AssertPointerIsNotNull(aParentRssi); - *aParentRssi = AsCoreType(aInstance).Get().GetParent().GetLinkInfo().GetAverageRss(); + *aParentRssi = AsCoreType(aInstance).Get().GetParent().GetLinkInfo().GetAverageRss(); VerifyOrExit(*aParentRssi != Radio::kInvalidRssi, error = kErrorFailed); @@ -371,7 +362,7 @@ otError otThreadGetParentLastRssi(otInstance *aInstance, int8_t *aLastRssi) AssertPointerIsNotNull(aLastRssi); - *aLastRssi = AsCoreType(aInstance).Get().GetParent().GetLinkInfo().GetLastRss(); + *aLastRssi = AsCoreType(aInstance).Get().GetParent().GetLinkInfo().GetLastRss(); VerifyOrExit(*aLastRssi != Radio::kInvalidRssi, error = kErrorFailed); @@ -390,11 +381,11 @@ otError otThreadSetEnabled(otInstance *aInstance, bool aEnabled) if (aEnabled) { - error = AsCoreType(aInstance).Get().Start(); + error = AsCoreType(aInstance).Get().Start(); } else { - AsCoreType(aInstance).Get().Stop(); + AsCoreType(aInstance).Get().Stop(); } return error; @@ -407,7 +398,7 @@ bool otThreadIsSingleton(otInstance *aInstance) bool isSingleton = false; #if OPENTHREAD_FTD - isSingleton = AsCoreType(aInstance).Get().IsSingleton(); + isSingleton = AsCoreType(aInstance).Get().IsSingleton(); #else OT_UNUSED_VARIABLE(aInstance); #endif @@ -470,14 +461,14 @@ void otThreadResetTimeInQueueStat(otInstance *aInstance) const otMleCounters *otThreadGetMleCounters(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetCounters(); + return &AsCoreType(aInstance).Get().GetCounters(); } -void otThreadResetMleCounters(otInstance *aInstance) { AsCoreType(aInstance).Get().ResetCounters(); } +void otThreadResetMleCounters(otInstance *aInstance) { AsCoreType(aInstance).Get().ResetCounters(); } uint32_t otThreadGetCurrentAttachDuration(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetCurrentAttachDuration(); + return AsCoreType(aInstance).Get().GetCurrentAttachDuration(); } #if OPENTHREAD_CONFIG_MLE_PARENT_RESPONSE_CALLBACK_API_ENABLE @@ -485,7 +476,7 @@ void otThreadRegisterParentResponseCallback(otInstance *aInst otThreadParentResponseCallback aCallback, void *aContext) { - AsCoreType(aInstance).Get().RegisterParentResponseStatsCallback(aCallback, aContext); + AsCoreType(aInstance).Get().RegisterParentResponseStatsCallback(aCallback, aContext); } #endif @@ -506,7 +497,7 @@ bool otThreadIsAnycastLocateInProgress(otInstance *aInstance) otError otThreadDetachGracefully(otInstance *aInstance, otDetachGracefullyCallback aCallback, void *aContext) { - return AsCoreType(aInstance).Get().DetachGracefully(aCallback, aContext); + return AsCoreType(aInstance).Get().DetachGracefully(aCallback, aContext); } #if OPENTHREAD_CONFIG_DYNAMIC_STORE_FRAME_AHEAD_COUNTER_ENABLE diff --git a/src/core/api/thread_ftd_api.cpp b/src/core/api/thread_ftd_api.cpp index f02cd70b5..4b758f6d5 100644 --- a/src/core/api/thread_ftd_api.cpp +++ b/src/core/api/thread_ftd_api.cpp @@ -51,62 +51,62 @@ otError otThreadSetMaxAllowedChildren(otInstance *aInstance, uint16_t aMaxChildr uint8_t otThreadGetMaxChildIpAddresses(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetMaxChildIpAddresses(); + return AsCoreType(aInstance).Get().GetMaxChildIpAddresses(); } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE otError otThreadSetMaxChildIpAddresses(otInstance *aInstance, uint8_t aMaxIpAddresses) { - return AsCoreType(aInstance).Get().SetMaxChildIpAddresses(aMaxIpAddresses); + return AsCoreType(aInstance).Get().SetMaxChildIpAddresses(aMaxIpAddresses); } #endif bool otThreadIsRouterEligible(otInstance *aInstance) { - return AsCoreType(aInstance).Get().IsRouterEligible(); + return AsCoreType(aInstance).Get().IsRouterEligible(); } otError otThreadSetRouterEligible(otInstance *aInstance, bool aEligible) { - return AsCoreType(aInstance).Get().SetRouterEligible(aEligible); + return AsCoreType(aInstance).Get().SetRouterEligible(aEligible); } otError otThreadSetPreferredRouterId(otInstance *aInstance, uint8_t aRouterId) { - return AsCoreType(aInstance).Get().SetPreferredRouterId(aRouterId); + return AsCoreType(aInstance).Get().SetPreferredRouterId(aRouterId); } #if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE const otDeviceProperties *otThreadGetDeviceProperties(otInstance *aInstance) { - return &AsCoreType(aInstance).Get().GetDeviceProperties(); + return &AsCoreType(aInstance).Get().GetDeviceProperties(); } void otThreadSetDeviceProperties(otInstance *aInstance, const otDeviceProperties *aDeviceProperties) { - AsCoreType(aInstance).Get().SetDeviceProperties(AsCoreType(aDeviceProperties)); + AsCoreType(aInstance).Get().SetDeviceProperties(AsCoreType(aDeviceProperties)); } #endif uint8_t otThreadGetLocalLeaderWeight(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetLeaderWeight(); + return AsCoreType(aInstance).Get().GetLeaderWeight(); } void otThreadSetLocalLeaderWeight(otInstance *aInstance, uint8_t aWeight) { - AsCoreType(aInstance).Get().SetLeaderWeight(aWeight); + AsCoreType(aInstance).Get().SetLeaderWeight(aWeight); } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE uint32_t otThreadGetPreferredLeaderPartitionId(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetPreferredLeaderPartitionId(); + return AsCoreType(aInstance).Get().GetPreferredLeaderPartitionId(); } void otThreadSetPreferredLeaderPartitionId(otInstance *aInstance, uint32_t aPartitionId) { - AsCoreType(aInstance).Get().SetPreferredLeaderPartitionId(aPartitionId); + AsCoreType(aInstance).Get().SetPreferredLeaderPartitionId(aPartitionId); } #endif @@ -134,32 +134,32 @@ void otThreadSetContextIdReuseDelay(otInstance *aInstance, uint32_t aDelay) uint8_t otThreadGetNetworkIdTimeout(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetNetworkIdTimeout(); + return AsCoreType(aInstance).Get().GetNetworkIdTimeout(); } void otThreadSetNetworkIdTimeout(otInstance *aInstance, uint8_t aTimeout) { - AsCoreType(aInstance).Get().SetNetworkIdTimeout(aTimeout); + AsCoreType(aInstance).Get().SetNetworkIdTimeout(aTimeout); } uint8_t otThreadGetRouterUpgradeThreshold(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetRouterUpgradeThreshold(); + return AsCoreType(aInstance).Get().GetRouterUpgradeThreshold(); } void otThreadSetRouterUpgradeThreshold(otInstance *aInstance, uint8_t aThreshold) { - AsCoreType(aInstance).Get().SetRouterUpgradeThreshold(aThreshold); + AsCoreType(aInstance).Get().SetRouterUpgradeThreshold(aThreshold); } uint8_t otThreadGetChildRouterLinks(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetChildRouterLinks(); + return AsCoreType(aInstance).Get().GetChildRouterLinks(); } otError otThreadSetChildRouterLinks(otInstance *aInstance, uint8_t aChildRouterLinks) { - return AsCoreType(aInstance).Get().SetChildRouterLinks(aChildRouterLinks); + return AsCoreType(aInstance).Get().SetChildRouterLinks(aChildRouterLinks); } otError otThreadReleaseRouterId(otInstance *aInstance, uint8_t aRouterId) @@ -176,32 +176,32 @@ exit: otError otThreadBecomeRouter(otInstance *aInstance) { - return AsCoreType(aInstance).Get().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest); + return AsCoreType(aInstance).Get().BecomeRouter(ThreadStatusTlv::kHaveChildIdRequest); } otError otThreadBecomeLeader(otInstance *aInstance) { - return AsCoreType(aInstance).Get().BecomeLeader(/* aCheckWeight */ true); + return AsCoreType(aInstance).Get().BecomeLeader(/* aCheckWeight */ true); } uint8_t otThreadGetRouterDowngradeThreshold(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetRouterDowngradeThreshold(); + return AsCoreType(aInstance).Get().GetRouterDowngradeThreshold(); } void otThreadSetRouterDowngradeThreshold(otInstance *aInstance, uint8_t aThreshold) { - AsCoreType(aInstance).Get().SetRouterDowngradeThreshold(aThreshold); + AsCoreType(aInstance).Get().SetRouterDowngradeThreshold(aThreshold); } uint8_t otThreadGetRouterSelectionJitter(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetRouterSelectionJitter(); + return AsCoreType(aInstance).Get().GetRouterSelectionJitter(); } void otThreadSetRouterSelectionJitter(otInstance *aInstance, uint8_t aRouterJitter) { - AsCoreType(aInstance).Get().SetRouterSelectionJitter(aRouterJitter); + AsCoreType(aInstance).Get().SetRouterSelectionJitter(aRouterJitter); } otError otThreadGetChildInfoById(otInstance *aInstance, uint16_t aChildId, otChildInfo *aChildInfo) @@ -260,7 +260,7 @@ otError otThreadGetNextCacheEntry(otInstance *aInstance, otCacheEntryInfo *aEntr #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE void otThreadSetSteeringData(otInstance *aInstance, const otExtAddress *aExtAddress) { - AsCoreType(aInstance).Get().SetSteeringData(AsCoreTypePtr(aExtAddress)); + AsCoreType(aInstance).Get().SetSteeringData(AsCoreTypePtr(aExtAddress)); } #endif @@ -277,7 +277,7 @@ otError otThreadSetPskc(otInstance *aInstance, const otPskc *aPskc) { Error error = kErrorNone; - VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(AsCoreType(aInstance).Get().IsDisabled(), error = kErrorInvalidState); AsCoreType(aInstance).Get().SetPskc(AsCoreType(aPskc)); AsCoreType(aInstance).Get().Clear(); @@ -294,7 +294,7 @@ otError otThreadSetPskcRef(otInstance *aInstance, otPskcRef aKeyRef) Instance &instance = AsCoreType(aInstance); VerifyOrExit(aKeyRef != 0, error = kErrorInvalidArgs); - VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(instance.Get().IsDisabled(), error = kErrorInvalidState); instance.Get().SetPskcRef(aKeyRef); instance.Get().Clear(); @@ -307,12 +307,12 @@ exit: int8_t otThreadGetParentPriority(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetAssignParentPriority(); + return AsCoreType(aInstance).Get().GetAssignParentPriority(); } otError otThreadSetParentPriority(otInstance *aInstance, int8_t aParentPriority) { - return AsCoreType(aInstance).Get().SetAssignParentPriority(aParentPriority); + return AsCoreType(aInstance).Get().SetAssignParentPriority(aParentPriority); } void otThreadRegisterNeighborTableCallback(otInstance *aInstance, otNeighborTableCallback aCallback) @@ -324,7 +324,7 @@ void otThreadSetDiscoveryRequestCallback(otInstance *aInsta otThreadDiscoveryRequestCallback aCallback, void *aContext) { - AsCoreType(aInstance).Get().SetDiscoveryRequestCallback(aCallback, aContext); + AsCoreType(aInstance).Get().SetDiscoveryRequestCallback(aCallback, aContext); } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE @@ -351,12 +351,12 @@ otError otThreadSendProactiveBackboneNotification(otInstance *aIns void otThreadSetCcmEnabled(otInstance *aInstance, bool aEnabled) { - AsCoreType(aInstance).Get().SetCcmEnabled(aEnabled); + AsCoreType(aInstance).Get().SetCcmEnabled(aEnabled); } void otThreadSetThreadVersionCheckEnabled(otInstance *aInstance, bool aEnabled) { - AsCoreType(aInstance).Get().SetThreadVersionCheckEnabled(aEnabled); + AsCoreType(aInstance).Get().SetThreadVersionCheckEnabled(aEnabled); } void otThreadSetTmfOriginFilterEnabled(otInstance *aInstance, bool aEnabled) @@ -384,7 +384,7 @@ otError otThreadSetRouterIdRange(otInstance *aInstance, uint8_t aMinRouterId, ui uint32_t otThreadGetAdvertisementTrickleIntervalMax(otInstance *aInstance) { - return AsCoreType(aInstance).Get().GetAdvertisementTrickleIntervalMax(); + return AsCoreType(aInstance).Get().GetAdvertisementTrickleIntervalMax(); } #endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE diff --git a/src/core/api/udp_api.cpp b/src/core/api/udp_api.cpp index d6096ad11..dde53dc76 100644 --- a/src/core/api/udp_api.cpp +++ b/src/core/api/udp_api.cpp @@ -97,7 +97,7 @@ void otUdpForwardReceive(otInstance *aInstance, { Ip6::MessageInfo messageInfo; - messageInfo.SetSockAddr(AsCoreType(aInstance).Get().GetMeshLocalRloc()); + messageInfo.SetSockAddr(AsCoreType(aInstance).Get().GetMeshLocalRloc()); messageInfo.SetSockPort(aSockPort); messageInfo.SetPeerAddr(AsCoreType(aPeerAddr)); messageInfo.SetPeerPort(aPeerPort); diff --git a/src/core/backbone_router/bbr_local.cpp b/src/core/backbone_router/bbr_local.cpp index 2f5e20f12..84b18aefa 100644 --- a/src/core/backbone_router/bbr_local.cpp +++ b/src/core/backbone_router/bbr_local.cpp @@ -176,7 +176,7 @@ Error Local::AddService(RegisterMode aMode) { case kDecideBasedOnState: VerifyOrExit(!Get().HasPrimary() || - Get().GetServer16() == Get().GetRloc16()); + Get().GetServer16() == Get().GetRloc16()); break; case kForceRegistration: break; @@ -213,7 +213,7 @@ void Local::SetState(State aState) { case kStateDisabled: // Update All Network Backbone Routers Multicast Address for both Secondary and Primary state. - mAllNetworkBackboneRouters.SetMulticastNetworkPrefix(Get().GetMeshLocalPrefix()); + mAllNetworkBackboneRouters.SetMulticastNetworkPrefix(Get().GetMeshLocalPrefix()); break; case kStateSecondary: break; @@ -225,7 +225,7 @@ void Local::SetState(State aState) if (aState == kStatePrimary) { // Add Primary Backbone Router ALOC for Primary Backbone Router. - mBbrPrimaryAloc.GetAddress().SetPrefix(Get().GetMeshLocalPrefix()); + mBbrPrimaryAloc.GetAddress().SetPrefix(Get().GetMeshLocalPrefix()); Get().AddUnicastAddress(mBbrPrimaryAloc); } @@ -241,14 +241,14 @@ void Local::HandleBackboneRouterPrimaryUpdate(Leader::State aState, const Config { OT_UNUSED_VARIABLE(aState); - VerifyOrExit(IsEnabled() && Get().IsAttached()); + VerifyOrExit(IsEnabled() && Get().IsAttached()); // Wait some jitter before trying to Register. if (aConfig.mServer16 == Mle::kInvalidRloc16) { mRegistrationTimeout = 1; - if (!Get().IsLeader()) + if (!Get().IsLeader()) { mRegistrationTimeout += Random::NonCrypto::GetUint16InRange(0, static_cast(mRegistrationJitter) + 1); @@ -256,7 +256,7 @@ void Local::HandleBackboneRouterPrimaryUpdate(Leader::State aState, const Config Get().RegisterReceiver(TimeTicker::kBbrLocal); } - else if (aConfig.mServer16 != Get().GetRloc16()) + else if (aConfig.mServer16 != Get().GetRloc16()) { Reset(); } @@ -285,7 +285,7 @@ void Local::HandleTimeTick(void) // Delay registration while router role transition is pending // (i.e., device may soon switch from REED to router role). - VerifyOrExit(!Get().IsRouterRoleTransitionPending()); + VerifyOrExit(!Get().IsRouterRoleTransitionPending()); if (mRegistrationTimeout > 0) { @@ -362,7 +362,7 @@ void Local::ApplyNewMeshLocalPrefix(void) VerifyOrExit(IsEnabled()); Get().UnsubscribeMulticast(mAllNetworkBackboneRouters); - mAllNetworkBackboneRouters.SetMulticastNetworkPrefix(Get().GetMeshLocalPrefix()); + mAllNetworkBackboneRouters.SetMulticastNetworkPrefix(Get().GetMeshLocalPrefix()); Get().SubscribeMulticast(mAllNetworkBackboneRouters); exit: diff --git a/src/core/backbone_router/bbr_manager.cpp b/src/core/backbone_router/bbr_manager.cpp index 5c2a9e24a..859c42934 100644 --- a/src/core/backbone_router/bbr_manager.cpp +++ b/src/core/backbone_router/bbr_manager.cpp @@ -495,7 +495,7 @@ bool Manager::ShouldForwardDuaToBackbone(const Ip6::Address &aAddress) // Do not forward to Backbone if the DUA belongs to a MTD Child (which may have failed in DUA registration) VerifyOrExit(Get().FindNeighbor(aAddress) == nullptr); // Forward to Backbone only if the DUA is resolved to the PBBR's RLOC16 - VerifyOrExit(Get().LookUp(aAddress) == Get().GetRloc16()); + VerifyOrExit(Get().LookUp(aAddress) == Get().GetRloc16()); forwardToBackbone = true; @@ -688,7 +688,7 @@ void Manager::HandleDadBackboneAnswer(const Ip6::Address &aDua, const Ip6::Inter { Ip6::Address dest; - dest.SetToRoutingLocator(Get().GetMeshLocalPrefix(), ndProxy->GetRloc16()); + dest.SetToRoutingLocator(Get().GetMeshLocalPrefix(), ndProxy->GetRloc16()); Get().SendAddressError(aDua, aMeshLocalIid, &dest); } @@ -706,7 +706,7 @@ void Manager::HandleExtendedBackboneAnswer(const Ip6::Address &aDua, { Ip6::Address dest; - dest.SetToRoutingLocator(Get().GetMeshLocalPrefix(), aSrcRloc16); + dest.SetToRoutingLocator(Get().GetMeshLocalPrefix(), aSrcRloc16); Get().SendAddressQueryResponse(aDua, aMeshLocalIid, &aTimeSinceLastTransaction, dest); LogInfo("HandleExtendedBackboneAnswer: target=%s, mliid=%s, LTT=%lus, rloc16=%04x", aDua.ToString().AsCString(), diff --git a/src/core/border_router/routing_manager.cpp b/src/core/border_router/routing_manager.cpp index 169018ab0..43789c6b0 100644 --- a/src/core/border_router/routing_manager.cpp +++ b/src/core/border_router/routing_manager.cpp @@ -281,7 +281,7 @@ exit: void RoutingManager::EvaluateState(void) { - if (mIsEnabled && Get().IsAttached() && mInfraIf.IsRunning()) + if (mIsEnabled && Get().IsAttached() && mInfraIf.IsRunning()) { Start(); } diff --git a/src/core/common/time_ticker.cpp b/src/core/common/time_ticker.cpp index 5efa1a49d..eeaba6dfb 100644 --- a/src/core/common/time_ticker.cpp +++ b/src/core/common/time_ticker.cpp @@ -74,9 +74,9 @@ void TimeTicker::HandleTimer(void) } #if OPENTHREAD_FTD - if (mReceivers & Mask(kMleRouter)) + if (mReceivers & Mask(kMle)) { - Get().HandleTimeTick(); + Get().HandleTimeTick(); } if (mReceivers & Mask(kAddressResolver)) diff --git a/src/core/common/time_ticker.hpp b/src/core/common/time_ticker.hpp index 8243abe6d..55873a3b7 100644 --- a/src/core/common/time_ticker.hpp +++ b/src/core/common/time_ticker.hpp @@ -62,7 +62,7 @@ public: enum Receiver : uint8_t { kMeshForwarder, ///< `MeshForwarder` - kMleRouter, ///< `Mle::MleRouter` + kMle, ///< `Mle::Mle` kAddressResolver, ///< `AddressResolver` kChildSupervisor, ///< `ChildSupervisor` kIp6FragmentReassembler, ///< `Ip6::Ip6` (handling of fragmented messages) diff --git a/src/core/instance/instance.cpp b/src/core/instance/instance.cpp index 0452d83c0..e0748b359 100644 --- a/src/core/instance/instance.cpp +++ b/src/core/instance/instance.cpp @@ -146,7 +146,7 @@ Instance::Instance(void) , mLowpan(*this) , mMac(*this) , mMeshForwarder(*this) - , mMleRouter(*this) + , mMle(*this) , mDiscoverScanner(*this) , mAddressResolver(*this) #if OPENTHREAD_CONFIG_MULTI_RADIO @@ -403,7 +403,7 @@ void Instance::AfterInit(void) // Restore datasets and network information Get().Init(); - Get().Restore(); + Get().Restore(); #if OPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE Get().AfterInit(); @@ -470,7 +470,7 @@ Error Instance::ErasePersistentInfo(void) { Error error = kErrorNone; - VerifyOrExit(Get().IsDisabled(), error = kErrorInvalidState); + VerifyOrExit(Get().IsDisabled(), error = kErrorInvalidState); Get().Wipe(); #if OPENTHREAD_CONFIG_PLATFORM_KEY_REFERENCES_ENABLE Get().DestroyTemporaryKeys(); @@ -496,7 +496,7 @@ void Instance::GetBufferInfo(BufferInfo &aInfo) Get().GetBufferedMessageSetInfo(aInfo.mMplQueue); #endif - Get().GetMessageQueueInfo(aInfo.mMleQueue); + Get().GetMessageQueueInfo(aInfo.mMleQueue); Get().GetRequestAndCachedResponsesQueueInfo(aInfo.mCoapQueue); diff --git a/src/core/instance/instance.hpp b/src/core/instance/instance.hpp index bef7b2b6f..7e9e6e4e2 100644 --- a/src/core/instance/instance.hpp +++ b/src/core/instance/instance.hpp @@ -122,7 +122,6 @@ #include "thread/link_quality.hpp" #include "thread/mesh_forwarder.hpp" #include "thread/mle.hpp" -#include "thread/mle_router.hpp" #include "thread/mlr_manager.hpp" #include "thread/network_data_local.hpp" #include "thread/network_data_notifier.hpp" @@ -551,7 +550,7 @@ private: Lowpan::Lowpan mLowpan; Mac::Mac mMac; MeshForwarder mMeshForwarder; - Mle::MleRouter mMleRouter; + Mle::Mle mMle; Mle::DiscoverScanner mDiscoverScanner; AddressResolver mAddressResolver; @@ -770,24 +769,20 @@ template <> inline Crypto::Storage::KeyRefManager &Instance::Get(void) { return template <> inline RadioSelector &Instance::Get(void) { return mRadioSelector; } #endif -template <> inline Mle::Mle &Instance::Get(void) { return mMleRouter; } - -#if OPENTHREAD_FTD -template <> inline Mle::MleRouter &Instance::Get(void) { return mMleRouter; } -#endif +template <> inline Mle::Mle &Instance::Get(void) { return mMle; } template <> inline Mle::DiscoverScanner &Instance::Get(void) { return mDiscoverScanner; } -template <> inline NeighborTable &Instance::Get(void) { return mMleRouter.mNeighborTable; } +template <> inline NeighborTable &Instance::Get(void) { return mMle.mNeighborTable; } #if OPENTHREAD_FTD -template <> inline ChildTable &Instance::Get(void) { return mMleRouter.mChildTable; } +template <> inline ChildTable &Instance::Get(void) { return mMle.mChildTable; } -template <> inline RouterTable &Instance::Get(void) { return mMleRouter.mRouterTable; } +template <> inline RouterTable &Instance::Get(void) { return mMle.mRouterTable; } #endif #if OPENTHREAD_CONFIG_WAKEUP_COORDINATOR_ENABLE -template <> inline WakeupTxScheduler &Instance::Get(void) { return mMleRouter.mWakeupTxScheduler; } +template <> inline WakeupTxScheduler &Instance::Get(void) { return mMle.mWakeupTxScheduler; } #endif template <> inline Ip6::Netif &Instance::Get(void) { return mThreadNetif; } diff --git a/src/core/mac/data_poll_handler.cpp b/src/core/mac/data_poll_handler.cpp index b3d975970..e567daf9d 100644 --- a/src/core/mac/data_poll_handler.cpp +++ b/src/core/mac/data_poll_handler.cpp @@ -90,7 +90,7 @@ void DataPollHandler::HandleDataPoll(Mac::RxFrame &aFrame) uint16_t indirectMsgCount; VerifyOrExit(aFrame.GetSecurityEnabled()); - VerifyOrExit(!Get().IsDetached()); + VerifyOrExit(!Get().IsDetached()); SuccessOrExit(aFrame.GetSrcAddr(macSource)); child = Get().FindChild(macSource, Child::kInStateValidOrRestoring); diff --git a/src/core/mac/data_poll_sender.cpp b/src/core/mac/data_poll_sender.cpp index c21bbacfe..f434e4ff6 100644 --- a/src/core/mac/data_poll_sender.cpp +++ b/src/core/mac/data_poll_sender.cpp @@ -57,16 +57,16 @@ DataPollSender::DataPollSender(Instance &aInstance) const Neighbor &DataPollSender::GetParent(void) const { - const Neighbor &parentCandidate = Get().GetParentCandidate(); + const Neighbor &parentCandidate = Get().GetParentCandidate(); - return parentCandidate.IsStateValid() ? parentCandidate : Get().GetParent(); + return parentCandidate.IsStateValid() ? parentCandidate : Get().GetParent(); } void DataPollSender::StartPolling(void) { VerifyOrExit(!mEnabled); - OT_ASSERT(!Get().IsRxOnWhenIdle()); + OT_ASSERT(!Get().IsRxOnWhenIdle()); mEnabled = true; ScheduleNextPoll(kRecalculatePollPeriod); @@ -136,7 +136,7 @@ Error DataPollSender::GetPollDestinationAddress(Mac::Address &aDest) const // Use extended address attaching to a new parent (i.e. parent is the parent candidate). if ((Get().GetShortAddress() == Mac::kShortAddrInvalid) || - (&parent == &Get().GetParentCandidate())) + (&parent == &Get().GetParentCandidate())) { aDest.SetExtended(parent.GetExtAddress()); } @@ -206,7 +206,7 @@ void DataPollSender::HandlePollSent(Mac::TxFrame &aFrame, Error aError) if (GetParent().IsStateInvalid()) { StopPolling(); - IgnoreError(Get().BecomeDetached()); + IgnoreError(Get().BecomeDetached()); ExitNow(); } @@ -328,7 +328,7 @@ void DataPollSender::ProcessTxDone(const Mac::TxFrame &aFrame, const Mac::RxFram bool sendDataPoll = false; VerifyOrExit(mEnabled); - VerifyOrExit(Get().GetParent().IsEnhancedKeepAliveSupported()); + VerifyOrExit(Get().GetParent().IsEnhancedKeepAliveSupported()); VerifyOrExit(aFrame.GetSecurityEnabled()); #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE @@ -522,12 +522,12 @@ uint32_t DataPollSender::GetDefaultPollPeriod(void) const uint32_t pollAhead = static_cast(kRetxPollPeriod) * kMaxPollRetxAttempts; uint32_t period; - period = Time::SecToMsec(Min(Get().GetTimeout(), Time::MsecToSec(TimerMilli::kMaxDelay))); + period = Time::SecToMsec(Min(Get().GetTimeout(), Time::MsecToSec(TimerMilli::kMaxDelay))); #if OPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE && OPENTHREAD_CONFIG_MAC_CSL_AUTO_SYNC_ENABLE if (Get().IsCslEnabled()) { - period = Min(period, Time::SecToMsec(Get().GetCslTimeout())); + period = Min(period, Time::SecToMsec(Get().GetCslTimeout())); pollAhead = static_cast(kRetxPollPeriod); } #endif diff --git a/src/core/mac/mac.cpp b/src/core/mac/mac.cpp index 4596f0855..d759dbf8f 100644 --- a/src/core/mac/mac.cpp +++ b/src/core/mac/mac.cpp @@ -1879,7 +1879,7 @@ void Mac::HandleReceivedFrame(RxFrame *aFrame, Error aError) #if OPENTHREAD_FTD // Allow multicasts from neighbor routers if FTD - if (neighbor == nullptr && dstaddr.IsBroadcast() && Get().IsFullThreadDevice()) + if (neighbor == nullptr && dstaddr.IsBroadcast() && Get().IsFullThreadDevice()) { neighbor = Get().FindRxOnlyNeighborRouter(srcaddr); } diff --git a/src/core/meshcop/border_agent.cpp b/src/core/meshcop/border_agent.cpp index 97f69d2c0..3d15a4039 100644 --- a/src/core/meshcop/border_agent.cpp +++ b/src/core/meshcop/border_agent.cpp @@ -162,7 +162,7 @@ void BorderAgent::HandleNotifierEvents(Events aEvents) { if (aEvents.Contains(kEventThreadRoleChanged)) { - if (Get().IsAttached()) + if (Get().IsAttached()) { Start(); } @@ -397,8 +397,8 @@ Error BorderAgent::MeshCoPTxtEncoder::EncodeTxtData(void) if (state.mThreadIfStatus == kThreadIfStatusActive) { - SuccessOrExit(error = AppendTxtEntry( - "pt", BigEndian::HostSwap32(Get().GetLeaderData().GetPartitionId()))); + SuccessOrExit( + error = AppendTxtEntry("pt", BigEndian::HostSwap32(Get().GetLeaderData().GetPartitionId()))); if (Get().GetTimestamp().IsValid()) { SuccessOrExit(error = AppendTxtEntry("at", Get().GetTimestamp())); @@ -469,7 +469,7 @@ BorderAgent::MeshCoPTxtEncoder::StateBitmap BorderAgent::MeshCoPTxtEncoder::GetS state.mConnectionMode = kConnectionModePskc; state.mAvailability = kAvailabilityHigh; - switch (Get().GetRole()) + switch (Get().GetRole()) { case Mle::DeviceRole::kRoleDisabled: state.mThreadIfStatus = kThreadIfStatusNotInitialized; diff --git a/src/core/meshcop/commissioner.cpp b/src/core/meshcop/commissioner.cpp index 6ebbbd7b7..83b2e5b98 100644 --- a/src/core/meshcop/commissioner.cpp +++ b/src/core/meshcop/commissioner.cpp @@ -265,7 +265,7 @@ Error Commissioner::Start(StateCallback aStateCallback, JoinerCallback aJoinerCa { Error error = kErrorNone; - VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); + VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); VerifyOrExit(mState == kStateDisabled, error = kErrorAlready); SuccessOrExit(error = Get().Open()); @@ -932,7 +932,7 @@ template <> void Commissioner::HandleTmf(Coap::Message &aMessage, c aMessage.SetOffset(offsetRange.GetOffset()); SuccessOrExit(error = aMessage.SetLength(offsetRange.GetEndOffset())); - joinerMessageInfo.SetPeerAddr(Get().GetMeshLocalEid()); + joinerMessageInfo.SetPeerAddr(Get().GetMeshLocalEid()); joinerMessageInfo.GetPeerAddr().SetIid(mJoinerIid); joinerMessageInfo.SetPeerPort(mJoinerPort); diff --git a/src/core/meshcop/dataset_manager.cpp b/src/core/meshcop/dataset_manager.cpp index 049ce263b..38aba5b48 100644 --- a/src/core/meshcop/dataset_manager.cpp +++ b/src/core/meshcop/dataset_manager.cpp @@ -229,7 +229,7 @@ Error DatasetManager::ApplyConfiguration(const Dataset &aDataset) const #endif case Tlv::kMeshLocalPrefix: - Get().SetMeshLocalPrefix(cur->ReadValueAs()); + Get().SetMeshLocalPrefix(cur->ReadValueAs()); break; case Tlv::kSecurityPolicy: @@ -324,7 +324,7 @@ void DatasetManager::SaveLocal(const Dataset &aDataset) { LocalSave(aDataset); - switch (Get().GetRole()) + switch (Get().GetRole()) { case Mle::kRoleDisabled: Restore(aDataset); @@ -439,7 +439,7 @@ void DatasetManager::SyncLocalWithLeader(const Dataset &aDataset) Error error = kErrorNone; VerifyOrExit(!mMgmtPending, error = kErrorBusy); - VerifyOrExit(Get().IsChild() || Get().IsRouter(), error = kErrorInvalidState); + VerifyOrExit(Get().IsChild() || Get().IsRouter(), error = kErrorInvalidState); VerifyOrExit(mNetworkTimestamp < mLocalTimestamp, error = kErrorAlready); diff --git a/src/core/meshcop/dataset_manager_ftd.cpp b/src/core/meshcop/dataset_manager_ftd.cpp index 0b57437f8..6c4c9de3c 100644 --- a/src/core/meshcop/dataset_manager_ftd.cpp +++ b/src/core/meshcop/dataset_manager_ftd.cpp @@ -98,7 +98,7 @@ Error DatasetManager::ProcessSetOrReplaceRequest(MgmtCommand aCommand, } if ((dataset.Read(meshLocalPrefix) == kErrorNone) && - (meshLocalPrefix != Get().GetMeshLocalPrefix())) + (meshLocalPrefix != Get().GetMeshLocalPrefix())) { aInfo.mAffectsConnectivity = true; } @@ -262,7 +262,7 @@ Error ActiveDatasetManager::GenerateLocal(void) Error error = kErrorNone; Dataset dataset; - VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); + VerifyOrExit(Get().IsAttached(), error = kErrorInvalidState); VerifyOrExit(!mLocalTimestamp.IsValid(), error = kErrorAlready); IgnoreError(Read(dataset)); @@ -306,7 +306,7 @@ Error ActiveDatasetManager::GenerateLocal(void) if (!dataset.Contains()) { - IgnoreError(dataset.Write(Get().GetMeshLocalPrefix())); + IgnoreError(dataset.Write(Get().GetMeshLocalPrefix())); } if (!dataset.Contains()) diff --git a/src/core/meshcop/joiner.cpp b/src/core/meshcop/joiner.cpp index 78d1d6fa8..4e7cf7fbf 100644 --- a/src/core/meshcop/joiner.cpp +++ b/src/core/meshcop/joiner.cpp @@ -135,7 +135,7 @@ Error Joiner::Start(const char *aPskd, // Use random-generated extended address. randomAddress.GenerateRandom(); Get().SetExtAddress(randomAddress); - Get().UpdateLinkLocalAddress(); + Get().UpdateLinkLocalAddress(); SuccessOrExit(error = Get().Open(Ip6::NetifIdentifier::kNetifThreadInternal)); SuccessOrExit(error = Get().Bind(kJoinerUdpPort)); @@ -256,7 +256,7 @@ void Joiner::HandleDiscoverResult(Mle::DiscoverScanner::ScanResult *aResult) else { Get().SetExtAddress(mId); - Get().UpdateLinkLocalAddress(); + Get().UpdateLinkLocalAddress(); mJoinerRouterIndex = 0; TryNextJoinerRouter(kErrorNone); @@ -577,7 +577,7 @@ void Joiner::HandleTimer(void) extAddress.GenerateRandom(); Get().SetExtAddress(extAddress); - Get().UpdateLinkLocalAddress(); + Get().UpdateLinkLocalAddress(); error = kErrorNone; break; diff --git a/src/core/meshcop/joiner_router.cpp b/src/core/meshcop/joiner_router.cpp index 6d515aa81..b93ed9a0b 100644 --- a/src/core/meshcop/joiner_router.cpp +++ b/src/core/meshcop/joiner_router.cpp @@ -61,7 +61,7 @@ void JoinerRouter::HandleNotifierEvents(Events aEvents) void JoinerRouter::Start(void) { - VerifyOrExit(Get().IsFullThreadDevice()); + VerifyOrExit(Get().IsFullThreadDevice()); if (Get().IsJoiningAllowed()) { @@ -132,7 +132,7 @@ void JoinerRouter::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &a SuccessOrExit(error = Tlv::Append(*message, aMessageInfo.GetPeerPort())); SuccessOrExit(error = Tlv::Append(*message, aMessageInfo.GetPeerAddr().GetIid())); - SuccessOrExit(error = Tlv::Append(*message, Get().GetRloc16())); + SuccessOrExit(error = Tlv::Append(*message, Get().GetRloc16())); offsetRange.InitFromMessageOffsetToEnd(aMessage); diff --git a/src/core/meshcop/meshcop_leader.cpp b/src/core/meshcop/meshcop_leader.cpp index 3f8e746ca..24028c197 100644 --- a/src/core/meshcop/meshcop_leader.cpp +++ b/src/core/meshcop/meshcop_leader.cpp @@ -60,9 +60,9 @@ template <> void Leader::HandleTmf(Coap::Message &aMessage, LogInfo("Received %s", UriToString()); - VerifyOrExit(Get().IsLeader()); + VerifyOrExit(Get().IsLeader()); - VerifyOrExit(Get().IsRoutingLocator(aMessageInfo.GetPeerAddr())); + VerifyOrExit(Get().IsRoutingLocator(aMessageInfo.GetPeerAddr())); SuccessOrExit(Tlv::Find(aMessage, commissionerId)); @@ -124,7 +124,7 @@ template <> void Leader::HandleTmf(Coap::Message &aMessage, LogInfo("Received %s", UriToString()); - VerifyOrExit(Get().IsLeader()); + VerifyOrExit(Get().IsLeader()); SuccessOrExit(Tlv::Find(aMessage, state)); @@ -214,7 +214,7 @@ exit: void Leader::HandleTimer(void) { - VerifyOrExit(Get().IsLeader()); + VerifyOrExit(Get().IsLeader()); ResignCommissioner(); diff --git a/src/core/meshcop/tcat_agent.cpp b/src/core/meshcop/tcat_agent.cpp index 5c39757e9..805ce212d 100644 --- a/src/core/meshcop/tcat_agent.cpp +++ b/src/core/meshcop/tcat_agent.cpp @@ -924,7 +924,7 @@ Error TcatAgent::HandleStartThreadInterface(void) #endif Get().Up(); - error = Get().Start(); + error = Get().Start(); exit: return error; diff --git a/src/core/net/dhcp6_client.cpp b/src/core/net/dhcp6_client.cpp index b8b99e6e5..4a461b478 100644 --- a/src/core/net/dhcp6_client.cpp +++ b/src/core/net/dhcp6_client.cpp @@ -268,9 +268,9 @@ void Client::Solicit(uint16_t aRloc16) #if OPENTHREAD_ENABLE_DHCP6_MULTICAST_SOLICIT messageInfo.GetPeerAddr().SetToRealmLocalAllRoutersMulticast(); #else - messageInfo.GetPeerAddr().SetToRoutingLocator(Get().GetMeshLocalPrefix(), aRloc16); + messageInfo.GetPeerAddr().SetToRoutingLocator(Get().GetMeshLocalPrefix(), aRloc16); #endif - messageInfo.SetSockAddr(Get().GetMeshLocalRloc()); + messageInfo.SetSockAddr(Get().GetMeshLocalRloc()); messageInfo.mPeerPort = kDhcpServerPort; SuccessOrExit(error = mSocket.SendTo(*message, messageInfo)); diff --git a/src/core/net/dhcp6_server.cpp b/src/core/net/dhcp6_server.cpp index 7e9c07e47..e595189af 100644 --- a/src/core/net/dhcp6_server.cpp +++ b/src/core/net/dhcp6_server.cpp @@ -54,7 +54,7 @@ Server::Server(Instance &aInstance) Error Server::UpdateService(void) { Error error = kErrorNone; - uint16_t rloc16 = Get().GetRloc16(); + uint16_t rloc16 = Get().GetRloc16(); NetworkData::Iterator iterator; NetworkData::OnMeshPrefixConfig config; Lowpan::Context lowpanContext; @@ -159,7 +159,7 @@ void Server::AddPrefixAgent(const Ip6::Prefix &aIp6Prefix, const Lowpan::Context VerifyOrExit(newEntry != nullptr, error = kErrorNoBufs); - newEntry->Set(aIp6Prefix, Get().GetMeshLocalPrefix(), aContext.mContextId); + newEntry->Set(aIp6Prefix, Get().GetMeshLocalPrefix(), aContext.mContextId); Get().AddUnicastAddress(newEntry->GetAloc()); mPrefixAgentsCount++; diff --git a/src/core/net/ip6_filter.cpp b/src/core/net/ip6_filter.cpp index ec0b56256..c10835b9d 100644 --- a/src/core/net/ip6_filter.cpp +++ b/src/core/net/ip6_filter.cpp @@ -57,7 +57,7 @@ bool Filter::Accept(Message &aMessage) const VerifyOrExit(headers.GetDestinationAddress().IsLinkLocalUnicastOrMulticast()); // Allow all link-local IPv6 datagrams when Thread is not enabled - if (Get().GetRole() == Mle::kRoleDisabled) + if (Get().GetRole() == Mle::kRoleDisabled) { ExitNow(rval = true); } diff --git a/src/core/net/nd_agent.cpp b/src/core/net/nd_agent.cpp index 392b50c7d..d6b26042f 100644 --- a/src/core/net/nd_agent.cpp +++ b/src/core/net/nd_agent.cpp @@ -43,7 +43,7 @@ namespace NeighborDiscovery { void Agent::UpdateService(void) { Error error; - uint16_t rloc16 = Get().GetRloc16(); + uint16_t rloc16 = Get().GetRloc16(); NetworkData::Iterator iterator; NetworkData::OnMeshPrefixConfig config; Lowpan::Context lowpanContext; @@ -99,7 +99,7 @@ void Agent::UpdateService(void) uint16_t aloc16 = Mle::kAloc16NeighborDiscoveryAgentStart + lowpanContext.mContextId - 1; mAloc.InitAsThreadOrigin(); - mAloc.GetAddress().SetToAnycastLocator(Get().GetMeshLocalPrefix(), aloc16); + mAloc.GetAddress().SetToAnycastLocator(Get().GetMeshLocalPrefix(), aloc16); mAloc.mMeshLocal = true; Get().AddUnicastAddress(mAloc); ExitNow(); diff --git a/src/core/radio/trel_link.cpp b/src/core/radio/trel_link.cpp index 10a356e3a..ed6968150 100644 --- a/src/core/radio/trel_link.cpp +++ b/src/core/radio/trel_link.cpp @@ -214,7 +214,7 @@ void Link::BeginTransmit(void) { uint16_t fcf = Mac::Frame::kTypeAck; - if (!Get().IsRxOnWhenIdle()) + if (!Get().IsRxOnWhenIdle()) { fcf |= kFcfFramePending; } @@ -275,20 +275,20 @@ void Link::HandleTimer(void) // router/leader during a partition merge, so it is always treated // as a neighbor. - switch (Get().GetRole()) + switch (Get().GetRole()) { case Mle::kRoleDisabled: break; case Mle::kRoleDetached: case Mle::kRoleChild: - HandleTimer(Get().GetParent()); + HandleTimer(Get().GetParent()); OT_FALL_THROUGH; case Mle::kRoleRouter: case Mle::kRoleLeader: - HandleTimer(Get().GetParentCandidate()); + HandleTimer(Get().GetParentCandidate()); break; } } diff --git a/src/core/thread/address_resolver.cpp b/src/core/thread/address_resolver.cpp index b3082c4bd..eb042c5da 100644 --- a/src/core/thread/address_resolver.cpp +++ b/src/core/thread/address_resolver.cpp @@ -123,7 +123,7 @@ Error AddressResolver::GetNextCacheEntry(EntryInfo &aInfo, Iterator &aIterator) VerifyOrExit(entry->IsLastTransactionTimeValid()); aInfo.mLastTransTime = entry->GetLastTransactionTime(); - AsCoreType(&aInfo.mMeshLocalEid).SetPrefix(Get().GetMeshLocalPrefix()); + AsCoreType(&aInfo.mMeshLocalEid).SetPrefix(Get().GetMeshLocalPrefix()); AsCoreType(&aInfo.mMeshLocalEid).SetIid(entry->GetMeshLocalIid()); ExitNow(); @@ -369,7 +369,7 @@ void AddressResolver::UpdateSnoopedCacheEntry(const Ip6::Address &aEid, uint16_t uint16_t numNonEvictable = 0; CacheEntry *entry; - VerifyOrExit(Get().IsFullThreadDevice()); + VerifyOrExit(Get().IsFullThreadDevice()); #if OPENTHREAD_CONFIG_TMF_ALLOW_ADDRESS_RESOLUTION_USING_NET_DATA_SERVICES { @@ -634,7 +634,7 @@ exit: #if OPENTHREAD_CONFIG_BACKBONE_ROUTER_DUA_NDPROXYING_ENABLE if (Get().IsPrimary() && Get().IsDomainUnicast(aEid)) { - uint16_t selfRloc16 = Get().GetRloc16(); + uint16_t selfRloc16 = Get().GetRloc16(); LogInfo("Extending %s to %s for target %s, rloc16=%04x(self)", UriToString(), UriToString(), aEid.ToString().AsCString(), selfRloc16); @@ -785,7 +785,7 @@ void AddressResolver::HandleTmf(Coap::Message &aMessage, const for (Ip6::Netif::UnicastAddress &address : Get().GetUnicastAddresses()) { - if (address.GetAddress() == target && Get().GetMeshLocalEid().GetIid() != meshLocalIid) + if (address.GetAddress() == target && Get().GetMeshLocalEid().GetIid() != meshLocalIid) { // Target EID matches address and Mesh Local EID differs #if OPENTHREAD_CONFIG_DUA_ENABLE @@ -854,7 +854,7 @@ void AddressResolver::HandleTmf(Coap::Message &aMessage, const if (Get().HasUnicastAddress(target)) { - SendAddressQueryResponse(target, Get().GetMeshLocalEid().GetIid(), nullptr, + SendAddressQueryResponse(target, Get().GetMeshLocalEid().GetIid(), nullptr, aMessageInfo.GetPeerAddr()); ExitNow(); } @@ -903,7 +903,7 @@ void AddressResolver::SendAddressQueryResponse(const Ip6::Address &a SuccessOrExit(error = Tlv::Append(*message, aTarget)); SuccessOrExit(error = Tlv::Append(*message, aMeshLocalIid)); - SuccessOrExit(error = Tlv::Append(*message, Get().GetRloc16())); + SuccessOrExit(error = Tlv::Append(*message, Get().GetRloc16())); if (aLastTransactionTime != nullptr) { diff --git a/src/core/thread/address_resolver.hpp b/src/core/thread/address_resolver.hpp index 799348238..67fd84a5f 100644 --- a/src/core/thread/address_resolver.hpp +++ b/src/core/thread/address_resolver.hpp @@ -36,6 +36,8 @@ #include "openthread-core-config.h" +#include + #include "coap/coap.hpp" #include "common/as_core_type.hpp" #include "common/linked_list.hpp" diff --git a/src/core/thread/announce_sender.cpp b/src/core/thread/announce_sender.cpp index 0550e2e0a..979088555 100644 --- a/src/core/thread/announce_sender.cpp +++ b/src/core/thread/announce_sender.cpp @@ -116,7 +116,7 @@ exit: void AnnounceSenderBase::HandleTimer(void) { - Get().SendAnnounce(mChannel); + Get().SendAnnounce(mChannel); // Go to the next channel in the mask. If we have reached the end // of the channel mask, we start over from the first channel in @@ -206,7 +206,7 @@ void AnnounceSender::HandleRoleChanged(void) case Mle::kRoleChild: #if OPENTHREAD_FTD - if (Get().IsRouterEligible() && Get().IsRxOnWhenIdle()) + if (Get().IsRouterEligible() && Get().IsRxOnWhenIdle()) { break; } diff --git a/src/core/thread/child.cpp b/src/core/thread/child.cpp index be2f2ca86..f5d382b32 100644 --- a/src/core/thread/child.cpp +++ b/src/core/thread/child.cpp @@ -152,7 +152,7 @@ Error Child::GetMeshLocalIp6Address(Ip6::Address &aAddress) const VerifyOrExit(!mMeshLocalIid.IsUnspecified(), error = kErrorNotFound); - aAddress.SetPrefix(Get().GetMeshLocalPrefix()); + aAddress.SetPrefix(Get().GetMeshLocalPrefix()); aAddress.SetIid(mMeshLocalIid); exit: @@ -188,7 +188,7 @@ Error Child::AddIp6Address(const Ip6::Address &aAddress) VerifyOrExit(!aAddress.IsUnspecified(), error = kErrorInvalidArgs); - if (Get().IsMeshLocalAddress(aAddress)) + if (Get().IsMeshLocalAddress(aAddress)) { VerifyOrExit(mMeshLocalIid.IsUnspecified(), error = kErrorAlready); mMeshLocalIid = aAddress.GetIid(); @@ -207,7 +207,7 @@ Error Child::RemoveIp6Address(const Ip6::Address &aAddress) Error error = kErrorNotFound; Ip6AddrEntry *entry; - if (Get().IsMeshLocalAddress(aAddress)) + if (Get().IsMeshLocalAddress(aAddress)) { if (aAddress.GetIid() == mMeshLocalIid) { @@ -251,7 +251,7 @@ bool Child::HasIp6Address(const Ip6::Address &aAddress) const VerifyOrExit(!aAddress.IsUnspecified()); - if (Get().IsMeshLocalAddress(aAddress)) + if (Get().IsMeshLocalAddress(aAddress)) { hasAddress = (aAddress.GetIid() == mMeshLocalIid); ExitNow(); diff --git a/src/core/thread/child_supervision.cpp b/src/core/thread/child_supervision.cpp index 427535307..4381e317f 100644 --- a/src/core/thread/child_supervision.cpp +++ b/src/core/thread/child_supervision.cpp @@ -182,8 +182,8 @@ void SupervisionListener::UpdateOnReceive(const Mac::Address &aSourceAddress, bo { // If listener is enabled and device is a child and it received a secure frame from its parent, restart the timer. - VerifyOrExit(mTimer.IsRunning() && aIsSecure && Get().IsChild() && - (Get().FindNeighbor(aSourceAddress) == &Get().GetParent())); + VerifyOrExit(mTimer.IsRunning() && aIsSecure && Get().IsChild() && + (Get().FindNeighbor(aSourceAddress) == &Get().GetParent())); RestartTimer(); @@ -193,7 +193,7 @@ exit: void SupervisionListener::RestartTimer(void) { - if ((mTimeout != 0) && !Get().IsDisabled() && !Get().GetRxOnWhenIdle()) + if ((mTimeout != 0) && !Get().IsDisabled() && !Get().GetRxOnWhenIdle()) { mTimer.Start(Time::SecToMsec(mTimeout)); } @@ -205,7 +205,7 @@ void SupervisionListener::RestartTimer(void) void SupervisionListener::HandleTimer(void) { - VerifyOrExit(Get().IsChild() && !Get().GetRxOnWhenIdle()); + VerifyOrExit(Get().IsChild() && !Get().GetRxOnWhenIdle()); LogWarn("Supervision timeout. No frame from parent in %u sec", mTimeout); mCounter++; diff --git a/src/core/thread/dua_manager.cpp b/src/core/thread/dua_manager.cpp index 3cbf9f84a..1e8a3ad4c 100644 --- a/src/core/thread/dua_manager.cpp +++ b/src/core/thread/dua_manager.cpp @@ -291,7 +291,7 @@ void DuaManager::UpdateCheckDelay(uint8_t aDelay) void DuaManager::HandleNotifierEvents(Events aEvents) { - Mle::MleRouter &mle = Get(); + Mle::Mle &mle = Get(); #if OPENTHREAD_CONFIG_DUA_ENABLE if (aEvents.Contains(kEventThreadNetdataChanged)) @@ -420,7 +420,7 @@ void DuaManager::UpdateTimeTickerRegistration(void) void DuaManager::PerformNextRegistration(void) { Error error = kErrorNone; - Mle::MleRouter &mle = Get(); + Mle::Mle &mle = Get(); Coap::Message *message = nullptr; Tmf::MessageInfo messageInfo(GetInstance()); Ip6::Address dua; diff --git a/src/core/thread/energy_scan_server.hpp b/src/core/thread/energy_scan_server.hpp index c3095b2c0..606f862ea 100644 --- a/src/core/thread/energy_scan_server.hpp +++ b/src/core/thread/energy_scan_server.hpp @@ -40,6 +40,7 @@ #include "common/non_copyable.hpp" #include "common/notifier.hpp" #include "common/timer.hpp" +#include "mac/mac.hpp" #include "net/ip6_address.hpp" #include "net/udp6.hpp" #include "thread/thread_tlvs.hpp" diff --git a/src/core/thread/key_manager.cpp b/src/core/thread/key_manager.cpp index a9ab0b0ff..c2a49f8e1 100644 --- a/src/core/thread/key_manager.cpp +++ b/src/core/thread/key_manager.cpp @@ -230,7 +230,7 @@ void KeyManager::ResetFrameCounters(void) Router *parent; // reset parent frame counters - parent = &Get().GetParent(); + parent = &Get().GetParent(); parent->SetKeySequence(0); parent->GetLinkFrameCounters().Reset(); parent->SetLinkAckFrameCounter(0); @@ -473,7 +473,7 @@ void KeyManager::MacFrameCounterUsed(uint32_t aMacFrameCounter) if (mMacFrameCounters.Get154() >= mStoredMacFrameCounter) { - IgnoreError(Get().Store()); + IgnoreError(Get().Store()); } exit: @@ -490,7 +490,7 @@ void KeyManager::IncrementTrelMacFrameCounter(void) if (mMacFrameCounters.GetTrel() >= mStoredMacFrameCounter) { - IgnoreError(Get().Store()); + IgnoreError(Get().Store()); } } #endif @@ -501,7 +501,7 @@ void KeyManager::IncrementMleFrameCounter(void) if (mMleFrameCounter >= mStoredMleFrameCounter) { - IgnoreError(Get().Store()); + IgnoreError(Get().Store()); } } diff --git a/src/core/thread/mesh_forwarder.cpp b/src/core/thread/mesh_forwarder.cpp index d4fda4a7e..4c724c86c 100644 --- a/src/core/thread/mesh_forwarder.cpp +++ b/src/core/thread/mesh_forwarder.cpp @@ -640,9 +640,9 @@ exit: Error MeshForwarder::UpdateIp6Route(Message &aMessage) { - Mle::MleRouter &mle = Get(); - Error error = kErrorNone; - Ip6::Header ip6Header; + Mle::Mle &mle = Get(); + Error error = kErrorNone; + Ip6::Header ip6Header; mAddMeshHeader = false; @@ -790,7 +790,7 @@ Mac::TxFrame *MeshForwarder::HandleFrameRequest(Mac::TxFrames &aTxFrames) { Mac::Address macDestAddr; - macDestAddr.SetShort(Get().GetParent().GetRloc16()); + macDestAddr.SetShort(Get().GetParent().GetRloc16()); PrepareEmptyFrame(*frame, macDestAddr, /* aAckRequest */ true); } break; @@ -1172,7 +1172,7 @@ void MeshForwarder::UpdateNeighborLinkFailures(Neighbor &aNeighbor, (aNeighbor.GetLinkFailures() >= aFailLimit)) { #if OPENTHREAD_FTD - Get().RemoveRouterLink(static_cast(aNeighbor)); + Get().RemoveRouterLink(static_cast(aNeighbor)); #else IgnoreError(Get().BecomeDetached()); #endif @@ -1726,7 +1726,7 @@ Error MeshForwarder::SendEmptyMessage(void) OwnedPtr messagePtr; VerifyOrExit(mEnabled && !Get().GetRxOnWhenIdle() && - Get().GetParent().IsStateValidOrRestoring(), + Get().GetParent().IsStateValidOrRestoring(), error = kErrorInvalidState); messagePtr.Reset(Get().Allocate(Message::kTypeMacEmptyData)); diff --git a/src/core/thread/mesh_forwarder_ftd.cpp b/src/core/thread/mesh_forwarder_ftd.cpp index 9c9b80e2d..def491724 100644 --- a/src/core/thread/mesh_forwarder_ftd.cpp +++ b/src/core/thread/mesh_forwarder_ftd.cpp @@ -389,9 +389,9 @@ exit: Error MeshForwarder::UpdateIp6RouteFtd(const Ip6::Header &aIp6Header, Message &aMessage) { - Mle::MleRouter &mle = Get(); - Error error = kErrorNone; - Neighbor *neighbor; + Mle::Mle &mle = Get(); + Error error = kErrorNone; + Neighbor *neighbor; mMeshDest = Mle::kInvalidRloc16; @@ -663,7 +663,7 @@ void MeshForwarder::ResolveRoutingLoops(uint16_t aSourceRloc16, uint16_t aDestRl VerifyOrExit(router != nullptr); router->SetNextHopToInvalid(); - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); exit: return; @@ -696,7 +696,7 @@ void MeshForwarder::UpdateEidRlocCacheAndStaleChild(RxInfo &aRxInfo) if (!Get().HasMatchingRouterIdWith(aRxInfo.GetSrcAddr().GetShort())) { - Get().RemoveNeighbor(*neighbor); + Get().RemoveNeighbor(*neighbor); } exit: diff --git a/src/core/thread/mle.cpp b/src/core/thread/mle.cpp index 235b6d82a..f6d14d852 100644 --- a/src/core/thread/mle.cpp +++ b/src/core/thread/mle.cpp @@ -92,6 +92,36 @@ Mle::Mle(Instance &aInstance) , mWedAttachState(kWedDetached) , mWedAttachTimer(aInstance) #endif +#if OPENTHREAD_FTD + , mRouterEligible(true) + , mAddressSolicitPending(false) + , mAddressSolicitRejected(false) +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + , mCcmEnabled(false) + , mThreadVersionCheckEnabled(true) +#endif + , mNetworkIdTimeout(kNetworkIdTimeout) + , mRouterUpgradeThreshold(kRouterUpgradeThreshold) + , mRouterDowngradeThreshold(kRouterDowngradeThreshold) + , mPreviousPartitionRouterIdSequence(0) + , mPreviousPartitionIdTimeout(0) + , mChildRouterLinks(kChildRouterLinks) + , mAlternateRloc16Timeout(0) +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + , mMaxChildIpAddresses(0) +#endif + , mParentPriority(kParentPriorityUnspecified) + , mNextChildId(kMaxChildId) + , mPreviousPartitionIdRouter(0) + , mPreviousPartitionId(0) +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + , mPreferredLeaderPartitionId(0) +#endif + , mAdvertiseTrickleTimer(aInstance, Mle::HandleAdvertiseTrickleTimer) + , mChildTable(aInstance) + , mRouterTable(aInstance) + , mRouterRoleRestorer(aInstance) +#endif // OPENTHREAD_FTD { mParent.Init(aInstance); mParentCandidate.Init(aInstance); @@ -121,6 +151,26 @@ Mle::Mle(Instance &aInstance) mMeshLocalPrefix.Clear(); SetMeshLocalPrefix(AsCoreType(&kMeshLocalPrefixInit)); + +#if OPENTHREAD_FTD + + mDeviceMode.Set(mDeviceMode.Get() | DeviceMode::kModeFullThreadDevice | DeviceMode::kModeFullNetworkData); + +#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE + mLeaderWeight = mDeviceProperties.CalculateLeaderWeight(); +#else + mLeaderWeight = kDefaultLeaderWeight; +#endif + + mLeaderAloc.InitAsThreadOriginMeshLocal(); + + SetRouterId(kInvalidRouterId); + +#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE + mSteeringData.Clear(); +#endif + +#endif // OPENTHREAD_FTD } Error Mle::Enable(void) @@ -193,7 +243,7 @@ Error Mle::Start(StartMode aMode) #if OPENTHREAD_FTD else if (IsRouterRloc16(GetRloc16())) { - if (Get().BecomeRouter(ThreadStatusTlv::kTooFewRouters) != kErrorNone) + if (BecomeRouter(ThreadStatusTlv::kTooFewRouters) != kErrorNone) { Attach(kAnyPartition); } @@ -228,7 +278,7 @@ void Mle::Stop(StopMode aMode) Get().RemoveUnicastAddress(mMeshLocalEid); #if OPENTHREAD_FTD - Get().mRouterRoleRestorer.Stop(); + mRouterRoleRestorer.Stop(); #endif SetRole(kRoleDisabled); @@ -442,8 +492,8 @@ void Mle::Restore(void) #if OPENTHREAD_FTD else { - Get().SetRouterId(RouterIdFromRloc16(GetRloc16())); - Get().SetPreviousPartitionId(networkInfo.GetPreviousPartitionId()); + SetRouterId(RouterIdFromRloc16(GetRloc16())); + SetPreviousPartitionId(networkInfo.GetPreviousPartitionId()); Get().Restore(); } #endif @@ -603,7 +653,7 @@ void Mle::Attach(AttachMode aMode) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - Get().StopAdvertiseTrickleTimer(); + StopAdvertiseTrickleTimer(); } #endif } @@ -695,7 +745,7 @@ void Mle::SetStateDetached(void) #if OPENTHREAD_FTD if (IsLeader()) { - Get().RemoveUnicastAddress(Get().mLeaderAloc); + Get().RemoveUnicastAddress(mLeaderAloc); } #endif @@ -712,8 +762,8 @@ void Mle::SetStateDetached(void) Get().SetRxOnWhenIdle(true); Get().SetBeaconEnabled(false); #if OPENTHREAD_FTD - Get().ClearAlternateRloc16(); - Get().HandleDetachStart(); + ClearAlternateRloc16(); + HandleDetachStart(); #endif } @@ -722,7 +772,7 @@ void Mle::SetStateChild(uint16_t aRloc16) #if OPENTHREAD_FTD if (IsLeader()) { - Get().RemoveUnicastAddress(Get().mLeaderAloc); + Get().RemoveUnicastAddress(mLeaderAloc); } #endif @@ -739,7 +789,7 @@ void Mle::SetStateChild(uint16_t aRloc16) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - Get().HandleChildStart(mAttachMode); + HandleChildStart(mAttachMode); } #endif @@ -768,7 +818,7 @@ void Mle::InformPreviousChannel(void) VerifyOrExit(IsChild() || IsRouter()); #if OPENTHREAD_FTD - VerifyOrExit(!IsFullThreadDevice() || IsRouter() || !Get().IsRouterRoleTransitionPending()); + VerifyOrExit(!IsFullThreadDevice() || IsRouter() || !IsRouterRoleTransitionPending()); #endif mAlternatePanId = Mac::kPanIdBroadcast; @@ -839,7 +889,7 @@ Error Mle::SetDeviceMode(DeviceMode aDeviceMode) #if OPENTHREAD_FTD if (!aDeviceMode.IsFullThreadDevice()) { - Get().ClearAlternateRloc16(); + ClearAlternateRloc16(); } #endif @@ -985,7 +1035,7 @@ void Mle::SetRloc16(uint16_t aRloc16) else { #if OPENTHREAD_FTD - Get().ClearAlternateRloc16(); + ClearAlternateRloc16(); #endif } } @@ -1000,7 +1050,7 @@ void Mle::SetLeaderData(uint32_t aPartitionId, uint8_t aWeighting, uint8_t aLead if (mLeaderData.GetPartitionId() != aPartitionId) { #if OPENTHREAD_FTD - Get().HandlePartitionChange(); + HandlePartitionChange(); #endif Get().Signal(kEventThreadPartitionIdChanged); mCounters.mPartitionIdChanges++; @@ -1161,7 +1211,7 @@ void Mle::HandleNotifierEvents(Events aEvents) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - Get().HandleNetworkDataUpdateRouter(); + HandleNetworkDataUpdateRouter(); } else #endif @@ -1206,7 +1256,7 @@ void Mle::HandleNotifierEvents(Events aEvents) #if OPENTHREAD_FTD if (aEvents.Contains(kEventSecurityPolicyChanged)) { - Get().HandleSecurityPolicyChanged(); + HandleSecurityPolicyChanged(); } #endif @@ -1446,9 +1496,9 @@ void Mle::HandleAttachTimer(void) } #if OPENTHREAD_FTD - if (IsDetached() && Get().mRouterRoleRestorer.IsActive()) + if (IsDetached() && mRouterRoleRestorer.IsActive()) { - Get().mRouterRoleRestorer.HandleTimer(); + mRouterRoleRestorer.HandleTimer(); ExitNow(); } #endif @@ -1613,7 +1663,7 @@ uint32_t Mle::Reattach(void) IgnoreError(BecomeDetached()); } #if OPENTHREAD_FTD - else if (IsFullThreadDevice() && Get().BecomeLeader(/* aCheckWeight */ false) == kErrorNone) + else if (IsFullThreadDevice() && BecomeLeader(/* aCheckWeight */ false) == kErrorNone) { // do nothing } @@ -2374,7 +2424,7 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn { #if OPENTHREAD_FTD case kCommandDiscoveryRequest: - Get().HandleDiscoveryRequest(rxInfo); + HandleDiscoveryRequest(rxInfo); break; #endif case kCommandDiscoveryResponse: @@ -2537,27 +2587,27 @@ void Mle::HandleUdpReceive(Message &aMessage, const Ip6::MessageInfo &aMessageIn #if OPENTHREAD_FTD case kCommandLinkRequest: - Get().HandleLinkRequest(rxInfo); + HandleLinkRequest(rxInfo); break; case kCommandLinkAccept: - Get().HandleLinkAccept(rxInfo); + HandleLinkAccept(rxInfo); break; case kCommandLinkAcceptAndRequest: - Get().HandleLinkAcceptAndRequest(rxInfo); + HandleLinkAcceptAndRequest(rxInfo); break; case kCommandDataRequest: - Get().HandleDataRequest(rxInfo); + HandleDataRequest(rxInfo); break; case kCommandParentRequest: - Get().HandleParentRequest(rxInfo); + HandleParentRequest(rxInfo); break; case kCommandChildIdRequest: - Get().HandleChildIdRequest(rxInfo); + HandleChildIdRequest(rxInfo); break; #endif // OPENTHREAD_FTD @@ -2708,14 +2758,14 @@ void Mle::ReestablishLinkWithNeighbor(Neighbor &aNeighbor) if (IsRouterRloc16(aNeighbor.GetRloc16())) { - Get().SendLinkRequest(static_cast(&aNeighbor)); + SendLinkRequest(static_cast(&aNeighbor)); } else if (Get().Contains(aNeighbor)) { Child &child = static_cast(aNeighbor); child.SetState(Child::kStateChildUpdateRequest); - IgnoreError(Get().SendChildUpdateRequestToChild(child)); + IgnoreError(SendChildUpdateRequestToChild(child)); } #endif @@ -2741,7 +2791,7 @@ void Mle::HandleAdvertisement(RxInfo &aRxInfo) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - SuccessOrExit(error = Get().HandleAdvertisementOnFtd(aRxInfo, sourceAddress, leaderData)); + SuccessOrExit(error = HandleAdvertisementOnFtd(aRxInfo, sourceAddress, leaderData)); } #endif @@ -2762,7 +2812,7 @@ void Mle::HandleAdvertisement(RxInfo &aRxInfo) SetLeaderData(leaderData); #if OPENTHREAD_FTD - SuccessOrExit(error = Get().ReadAndProcessRouteTlvOnFtdChild(aRxInfo, mParent.GetRouterId())); + SuccessOrExit(error = ReadAndProcessRouteTlvOnFtdChild(aRxInfo, mParent.GetRouterId())); #endif mRetrieveNewNetworkData = true; @@ -2808,7 +2858,7 @@ void Mle::HandleDataResponse(RxInfo &aRxInfo) #endif #if OPENTHREAD_FTD - SuccessOrExit(error = Get().ReadAndProcessRouteTlvOnFtdChild(aRxInfo, mParent.GetRouterId())); + SuccessOrExit(error = ReadAndProcessRouteTlvOnFtdChild(aRxInfo, mParent.GetRouterId())); #endif error = HandleLeaderData(aRxInfo); @@ -3149,8 +3199,8 @@ void Mle::HandleParentResponse(RxInfo &aRxInfo) case kBetterPartition: VerifyOrExit(!isPartitionIdSame); - VerifyOrExit(MleRouter::ComparePartitions(connectivityTlv.IsSingleton(), leaderData, - Get().IsSingleton(), mLeaderData) > 0); + VerifyOrExit(Mle::ComparePartitions(connectivityTlv.IsSingleton(), leaderData, IsSingleton(), mLeaderData) > + 0); break; case kBetterParent: @@ -3172,8 +3222,8 @@ void Mle::HandleParentResponse(RxInfo &aRxInfo) #if OPENTHREAD_FTD if (IsFullThreadDevice()) { - compare = MleRouter::ComparePartitions(connectivityTlv.IsSingleton(), leaderData, - mParentCandidate.mIsSingleton, mParentCandidate.mLeaderData); + compare = Mle::ComparePartitions(connectivityTlv.IsSingleton(), leaderData, mParentCandidate.mIsSingleton, + mParentCandidate.mLeaderData); } // Only consider partitions that are the same or better @@ -3313,8 +3363,7 @@ void Mle::HandleChildIdResponse(RxInfo &aRxInfo) SetLeaderData(leaderData); #if OPENTHREAD_FTD - SuccessOrExit(error = - Get().ReadAndProcessRouteTlvOnFtdChild(aRxInfo, RouterIdFromRloc16(sourceAddress))); + SuccessOrExit(error = ReadAndProcessRouteTlvOnFtdChild(aRxInfo, RouterIdFromRloc16(sourceAddress))); #endif mParentCandidate.CopyTo(mParent); @@ -3351,7 +3400,7 @@ void Mle::HandleChildUpdateRequest(RxInfo &aRxInfo) #if OPENTHREAD_FTD if (IsRouterOrLeader()) { - Get().HandleChildUpdateRequestOnParent(aRxInfo); + HandleChildUpdateRequestOnParent(aRxInfo); } else #endif @@ -3474,7 +3523,7 @@ void Mle::HandleChildUpdateResponse(RxInfo &aRxInfo) #if OPENTHREAD_FTD if (IsRouterOrLeader()) { - Get().HandleChildUpdateResponseOnParent(aRxInfo); + HandleChildUpdateResponseOnParent(aRxInfo); } else #endif @@ -4462,7 +4511,7 @@ Error Mle::DetachGracefully(DetachCallback aCallback, void *aContext) case kRoleRouter: #if OPENTHREAD_FTD - Get().SendAddressRelease(); + SendAddressRelease(); #endif break; @@ -4724,16 +4773,16 @@ void Mle::DelayedSender::Execute(const Schedule &aSchedule) ParentResponseInfo info; IgnoreError(aSchedule.Read(sizeof(Header), info)); - Get().SendParentResponse(info); + Get().SendParentResponse(info); break; } case kTypeAdvertisement: - Get().SendAdvertisement(header.mDestination); + Get().SendAdvertisement(header.mDestination); break; case kTypeDataResponse: - Get().SendMulticastDataResponse(); + Get().SendMulticastDataResponse(); break; case kTypeLinkAccept: @@ -4741,7 +4790,7 @@ void Mle::DelayedSender::Execute(const Schedule &aSchedule) LinkAcceptInfo info; IgnoreError(aSchedule.Read(sizeof(Header), info)); - IgnoreError(Get().SendLinkAccept(info)); + IgnoreError(Get().SendLinkAccept(info)); break; } @@ -4755,7 +4804,7 @@ void Mle::DelayedSender::Execute(const Schedule &aSchedule) if (router != nullptr) { - Get().SendLinkRequest(router); + Get().SendLinkRequest(router); } break; @@ -4766,7 +4815,7 @@ void Mle::DelayedSender::Execute(const Schedule &aSchedule) DiscoveryResponseInfo info; IgnoreError(aSchedule.Read(sizeof(Header), info)); - IgnoreError(Get().SendDiscoveryResponse(header.mDestination, info)); + IgnoreError(Get().SendDiscoveryResponse(header.mDestination, info)); break; } #endif // OPENTHREAD_FTD @@ -5231,7 +5280,7 @@ Error Mle::TxMessage::AppendConnectivityTlv(void) ConnectivityTlv tlv; tlv.Init(); - Get().FillConnectivityTlv(tlv); + Get().FillConnectivityTlv(tlv); return tlv.AppendTo(*this); } @@ -5321,9 +5370,9 @@ Error Mle::TxMessage::AppendSteeringDataTlv(void) MeshCoP::SteeringData steeringData; #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE - if (!Get().mSteeringData.IsEmpty()) + if (!Get().mSteeringData.IsEmpty()) { - steeringData = Get().mSteeringData; + steeringData = Get().mSteeringData; } else #endif diff --git a/src/core/thread/mle.hpp b/src/core/thread/mle.hpp index d38da8d26..cb2fb9756 100644 --- a/src/core/thread/mle.hpp +++ b/src/core/thread/mle.hpp @@ -36,28 +36,41 @@ #include "openthread-core-config.h" +#include + +#include "coap/coap_message.hpp" #include "common/callback.hpp" #include "common/encoding.hpp" #include "common/locator.hpp" #include "common/log.hpp" #include "common/non_copyable.hpp" #include "common/notifier.hpp" +#include "common/time_ticker.hpp" #include "common/timer.hpp" +#include "common/trickle_timer.hpp" #include "crypto/aes_ccm.hpp" #include "mac/mac.hpp" +#include "mac/mac_types.hpp" #include "mac/wakeup_tx_scheduler.hpp" #include "meshcop/dataset.hpp" #include "meshcop/joiner_router.hpp" #include "meshcop/meshcop.hpp" +#include "meshcop/meshcop_tlvs.hpp" +#include "net/icmp6.hpp" #include "net/udp6.hpp" #include "thread/child.hpp" +#include "thread/child_table.hpp" #include "thread/link_metrics.hpp" #include "thread/link_metrics_tlvs.hpp" +#include "thread/mle.hpp" #include "thread/mle_tlvs.hpp" #include "thread/mle_types.hpp" #include "thread/neighbor_table.hpp" #include "thread/network_data_types.hpp" #include "thread/router.hpp" +#include "thread/router_table.hpp" +#include "thread/thread_tlvs.hpp" +#include "thread/tmf.hpp" namespace ot { @@ -97,18 +110,11 @@ namespace Mle { * @{ */ -#if OPENTHREAD_FTD -class MleRouter; -#endif - /** * Implements MLE functionality required by the Thread EndDevices, Router, and Leader roles. */ class Mle : public InstanceLocator, private NonCopyable { -#if OPENTHREAD_FTD - friend class MleRouter; -#endif friend class DiscoverScanner; friend class ot::Instance; friend class ot::Notifier; @@ -117,6 +123,10 @@ class Mle : public InstanceLocator, private NonCopyable friend class ot::LinkMetrics::Initiator; #endif friend class ot::UnitTester; +#if OPENTHREAD_FTD + friend class ot::TimeTicker; + friend class Tmf::Agent; +#endif public: typedef otDetachGracefullyCallback DetachCallback; ///< Callback to signal end of graceful detach. @@ -758,6 +768,408 @@ public: void *aCallbackContext); #endif // OPENTHREAD_CONFIG_WAKEUP_COORDINATOR_ENABLE +#if OPENTHREAD_FTD + /** + * Indicates whether or not the device is router-eligible. + * + * @retval true If device is router-eligible. + * @retval false If device is not router-eligible. + */ + bool IsRouterEligible(void) const; + + /** + * Sets whether or not the device is router-eligible. + * + * If @p aEligible is false and the device is currently operating as a router, this call will cause the device to + * detach and attempt to reattach as a child. + * + * @param[in] aEligible TRUE to configure device router-eligible, FALSE otherwise. + * + * @retval kErrorNone Successfully set the router-eligible configuration. + * @retval kErrorNotCapable The device is not capable of becoming a router. + */ + Error SetRouterEligible(bool aEligible); + + /** + * Indicates whether a node is the only router on the network. + * + * @retval TRUE It is the only router in the network. + * @retval FALSE It is a child or is not a single router in the network. + */ + bool IsSingleton(void) const; + + /** + * Generates an Address Solicit request for a Router ID. + * + * @param[in] aStatus The reason for requesting a Router ID. + * + * @retval kErrorNone Successfully generated an Address Solicit message. + * @retval kErrorNotCapable Device is not capable of becoming a router + * @retval kErrorInvalidState Thread is not enabled + */ + Error BecomeRouter(ThreadStatusTlv::Status aStatus); + + /** + * Becomes a leader and starts a new partition. + * + * If the device is already attached, this method can be used to attempt to take over as the leader, creating a new + * partition. For this to work, the local leader weight must be greater than the weight of the current leader. The + * @p aCheckWeight can be used to ensure that this check is performed. + * + * @param[in] aCheckWeight Check that the local leader weight is larger than the weight of the current leader. + * + * @retval kErrorNone Successfully become a Leader and started a new partition. + * @retval kErrorInvalidState Thread is not enabled. + * @retval kErrorNotCapable Device is not capable of becoming a leader (not router eligible), or + * @p aCheckWeight is true and cannot override the current leader due to its local + * leader weight being same or smaller than current leader's weight. + */ + Error BecomeLeader(bool aCheckWeight); + +#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE + /** + * Gets the device properties which are used to determine the Leader Weight. + * + * @returns The current device properties. + */ + const DeviceProperties &GetDeviceProperties(void) const { return mDeviceProperties; } + + /** + * Sets the device properties which are then used to determine and set the Leader Weight. + * + * @param[in] aDeviceProperties The device properties. + */ + void SetDeviceProperties(const DeviceProperties &aDeviceProperties); +#endif + + /** + * Returns the Leader Weighting value for this Thread interface. + * + * @returns The Leader Weighting value for this Thread interface. + */ + uint8_t GetLeaderWeight(void) const { return mLeaderWeight; } + + /** + * Sets the Leader Weighting value for this Thread interface. + * + * Directly sets the Leader Weight to the new value replacing its previous value (which may have been + * determined from a previous call to `SetDeviceProperties()`). + * + * @param[in] aWeight The Leader Weighting value. + */ + void SetLeaderWeight(uint8_t aWeight) { mLeaderWeight = aWeight; } + +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + + /** + * Returns the preferred Partition Id when operating in the Leader role for certification testing. + * + * @returns The preferred Partition Id value. + */ + uint32_t GetPreferredLeaderPartitionId(void) const { return mPreferredLeaderPartitionId; } + + /** + * Sets the preferred Partition Id when operating in the Leader role for certification testing. + * + * @param[in] aPartitionId The preferred Leader Partition Id. + */ + void SetPreferredLeaderPartitionId(uint32_t aPartitionId) { mPreferredLeaderPartitionId = aPartitionId; } +#endif + + /** + * Sets the preferred Router Id. Upon becoming a router/leader the node + * attempts to use this Router Id. If the preferred Router Id is not set or if it + * can not be used, a randomly generated router Id is picked. + * This property can be set when he device role is detached or disabled. + * + * @param[in] aRouterId The preferred Router Id. + * + * @retval kErrorNone Successfully set the preferred Router Id. + * @retval kErrorInvalidState Could not set (role is other than detached and disabled) + */ + Error SetPreferredRouterId(uint8_t aRouterId); + + /** + * Gets the Partition Id which the device joined successfully once. + */ + uint32_t GetPreviousPartitionId(void) const { return mPreviousPartitionId; } + + /** + * Sets the Partition Id which the device joins successfully. + * + * @param[in] aPartitionId The Partition Id. + */ + void SetPreviousPartitionId(uint32_t aPartitionId) { mPreviousPartitionId = aPartitionId; } + + /** + * Sets the Router Id. + * + * @param[in] aRouterId The Router Id. + */ + void SetRouterId(uint8_t aRouterId); + + /** + * Returns the NETWORK_ID_TIMEOUT value. + * + * @returns The NETWORK_ID_TIMEOUT value. + */ + uint8_t GetNetworkIdTimeout(void) const { return mNetworkIdTimeout; } + + /** + * Sets the NETWORK_ID_TIMEOUT value. + * + * @param[in] aTimeout The NETWORK_ID_TIMEOUT value. + */ + void SetNetworkIdTimeout(uint8_t aTimeout) { mNetworkIdTimeout = aTimeout; } + + /** + * Returns the ROUTER_SELECTION_JITTER value. + * + * @returns The ROUTER_SELECTION_JITTER value in seconds. + */ + uint8_t GetRouterSelectionJitter(void) const { return mRouterRoleTransition.GetJitter(); } + + /** + * Sets the ROUTER_SELECTION_JITTER value. + * + * @param[in] aRouterJitter The router selection jitter value (in seconds). + */ + void SetRouterSelectionJitter(uint8_t aRouterJitter) { mRouterRoleTransition.SetJitter(aRouterJitter); } + + /** + * Indicates whether or not router role transition (upgrade from REED or downgrade to REED) is pending. + * + * @retval TRUE Router role transition is pending. + * @retval FALSE Router role transition is not pending + */ + bool IsRouterRoleTransitionPending(void) const { return mRouterRoleTransition.IsPending(); } + + /** + * Returns the current timeout delay in seconds till router role transition (upgrade from REED or downgrade to + * REED). + * + * @returns The timeout in seconds till router role transition, or zero if not pending role transition. + */ + uint8_t GetRouterRoleTransitionTimeout(void) const { return mRouterRoleTransition.GetTimeout(); } + + /** + * Returns the ROUTER_UPGRADE_THRESHOLD value. + * + * @returns The ROUTER_UPGRADE_THRESHOLD value. + */ + uint8_t GetRouterUpgradeThreshold(void) const { return mRouterUpgradeThreshold; } + + /** + * Sets the ROUTER_UPGRADE_THRESHOLD value. + * + * @param[in] aThreshold The ROUTER_UPGRADE_THRESHOLD value. + */ + void SetRouterUpgradeThreshold(uint8_t aThreshold) { mRouterUpgradeThreshold = aThreshold; } + + /** + * Returns the ROUTER_DOWNGRADE_THRESHOLD value. + * + * @returns The ROUTER_DOWNGRADE_THRESHOLD value. + */ + uint8_t GetRouterDowngradeThreshold(void) const { return mRouterDowngradeThreshold; } + + /** + * Sets the ROUTER_DOWNGRADE_THRESHOLD value. + * + * @param[in] aThreshold The ROUTER_DOWNGRADE_THRESHOLD value. + */ + void SetRouterDowngradeThreshold(uint8_t aThreshold) { mRouterDowngradeThreshold = aThreshold; } + + /** + * Returns the MLE_CHILD_ROUTER_LINKS value. + * + * @returns The MLE_CHILD_ROUTER_LINKS value. + */ + uint8_t GetChildRouterLinks(void) const { return mChildRouterLinks; } + + /** + * Sets the MLE_CHILD_ROUTER_LINKS value. + * + * @param[in] aChildRouterLinks The MLE_CHILD_ROUTER_LINKS value. + * + * @retval kErrorNone Successfully set the value. + * @retval kErrorInvalidState Thread protocols are enabled. + */ + Error SetChildRouterLinks(uint8_t aChildRouterLinks); + + /** + * Returns if the REED is expected to become Router soon. + * + * @retval TRUE If the REED is going to become a Router soon. + * @retval FALSE If the REED is not going to become a Router soon. + */ + bool IsExpectedToBecomeRouterSoon(void) const; + + /** + * Removes a link to a neighbor. + * + * @param[in] aNeighbor A reference to the neighbor object. + */ + void RemoveNeighbor(Neighbor &aNeighbor); + + /** + * Invalidates a direct link to a neighboring router (due to failed link-layer acks). + * + * @param[in] aRouter A reference to the router object. + */ + void RemoveRouterLink(Router &aRouter); + + /** + * Indicates whether or not the given Thread partition attributes are preferred. + * + * @param[in] aSingletonA Whether or not the Thread Partition A has a single router. + * @param[in] aLeaderDataA A reference to Thread Partition A's Leader Data. + * @param[in] aSingletonB Whether or not the Thread Partition B has a single router. + * @param[in] aLeaderDataB A reference to Thread Partition B's Leader Data. + * + * @retval 1 If partition A is preferred. + * @retval 0 If partition A and B have equal preference. + * @retval -1 If partition B is preferred. + */ + static int ComparePartitions(bool aSingletonA, + const LeaderData &aLeaderDataA, + bool aSingletonB, + const LeaderData &aLeaderDataB); + + /** + * Fills an ConnectivityTlv. + * + * @param[out] aTlv A reference to the tlv to be filled. + */ + void FillConnectivityTlv(ConnectivityTlv &aTlv); + + /** + * Schedule tx of MLE Advertisement message (unicast) to the given neighboring router after a random delay. + * + * @param[in] aRouter The router to send the Advertisement to. + * + */ + void ScheduleUnicastAdvertisementTo(const Router &aRouter); + +#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE + /** + * Sets steering data out of band + * + * @param[in] aExtAddress Value used to set steering data + * All zeros clears steering data + * All 0xFFs sets steering data to 0xFF + * Anything else is used to compute the bloom filter + */ + void SetSteeringData(const Mac::ExtAddress *aExtAddress); +#endif + + /** + * Gets the assigned parent priority. + * + * @returns The assigned parent priority value, -2 means not assigned. + */ + int8_t GetAssignParentPriority(void) const { return mParentPriority; } + + /** + * Sets the parent priority. + * + * @param[in] aParentPriority The parent priority value. + * + * @retval kErrorNone Successfully set the parent priority. + * @retval kErrorInvalidArgs If the parent priority value is not among 1, 0, -1 and -2. + */ + Error SetAssignParentPriority(int8_t aParentPriority); + + /** + * Gets the longest MLE Timeout TLV for all active MTD children. + * + * @param[out] aTimeout A reference to where the information is placed. + * + * @retval kErrorNone Successfully get the max child timeout + * @retval kErrorInvalidState Not an active router + * @retval kErrorNotFound NO MTD child + */ + Error GetMaxChildTimeout(uint32_t &aTimeout) const; + + /** + * Sets the callback that is called when processing an MLE Discovery Request message. + * + * @param[in] aCallback A pointer to a function that is called to deliver MLE Discovery Request data. + * @param[in] aContext A pointer to application-specific context. + */ + void SetDiscoveryRequestCallback(otThreadDiscoveryRequestCallback aCallback, void *aContext) + { + mDiscoveryRequestCallback.Set(aCallback, aContext); + } + + /** + * Resets the MLE Advertisement Trickle timer interval. + */ + void ResetAdvertiseInterval(void); + + /** + * Updates the MLE Advertisement Trickle timer max interval (if timer is running). + * + * This is called when there is change in router table. + */ + void UpdateAdvertiseInterval(void); + +#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE + /** + * Generates an MLE Time Synchronization message. + * + * @retval kErrorNone Successfully sent an MLE Time Synchronization message. + * @retval kErrorNoBufs Insufficient buffers to generate the MLE Time Synchronization message. + */ + Error SendTimeSync(void); +#endif + + /** + * Gets the maximum number of IP addresses that each MTD child may register with this device as parent. + * + * @returns The maximum number of IP addresses that each MTD child may register with this device as parent. + */ + uint8_t GetMaxChildIpAddresses(void) const; + +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + + /** + * Sets/restores the maximum number of IP addresses that each MTD child may register with this + * device as parent. + * + * @param[in] aMaxIpAddresses The maximum number of IP addresses that each MTD child may register with this + * device as parent. 0 to clear the setting and restore the default. + * + * @retval kErrorNone Successfully set/cleared the number. + * @retval kErrorInvalidArgs If exceeds the allowed maximum number. + */ + Error SetMaxChildIpAddresses(uint8_t aMaxIpAddresses); + + /** + * Sets whether the device was commissioned using CCM. + * + * @param[in] aEnabled TRUE if the device was commissioned using CCM, FALSE otherwise. + */ + void SetCcmEnabled(bool aEnabled) { mCcmEnabled = aEnabled; } + + /** + * Sets whether the Security Policy TLV version-threshold for routing (VR field) is enabled. + * + * @param[in] aEnabled TRUE to enable Security Policy TLV version-threshold for routing, FALSE otherwise. + */ + void SetThreadVersionCheckEnabled(bool aEnabled) { mThreadVersionCheckEnabled = aEnabled; } + + /** + * Gets the current Interval Max value used by Advertisement trickle timer. + * + * @returns The Interval Max of Advertisement trickle timer in milliseconds. + */ + uint32_t GetAdvertisementTrickleIntervalMax(void) const { return mAdvertiseTrickleTimer.GetIntervalMax(); } + +#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + +#endif // OPENTHREAD_FTD + private: //------------------------------------------------------------------------------------------------------------------ // Constants @@ -832,6 +1244,65 @@ private: static constexpr uint32_t kDefaultChildTimeout = OPENTHREAD_CONFIG_MLE_CHILD_TIMEOUT_DEFAULT; static constexpr uint32_t kDefaultCslTimeout = OPENTHREAD_CONFIG_CSL_TIMEOUT; +#if OPENTHREAD_FTD + // Advertisement trickle timer constants - all times are in milliseconds. + static constexpr uint32_t kAdvIntervalMin = 1000; // I_MIN + static constexpr uint32_t kAdvIntervalNeighborMultiplier = 4000; // Multiplier for I_MAX per router neighbor + static constexpr uint32_t kAdvIntervalMaxLowerBound = 12000; // Lower bound for I_MAX + static constexpr uint32_t kAdvIntervalMaxUpperBound = 32000; // Upper bound for I_MAX + static constexpr uint32_t kReedAdvIntervalMin = 570000; + static constexpr uint32_t kReedAdvIntervalMax = 630000; +#if OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE + static constexpr uint32_t kAdvIntervalMaxLogRoutes = 5000; +#endif + + static constexpr uint32_t kMaxUnicastAdvertisementDelay = 1000; // Max random delay for unciast Adv tx + static constexpr uint32_t kMaxNeighborAge = 100000; // Max neighbor age on router (in msec) + static constexpr uint32_t kMaxNeighborAgeOnChild = 150000; // Max neighbor age on FTD child (in msec) + static constexpr uint32_t kMaxLeaderToRouterTimeout = 90000; // (in msec) + static constexpr uint8_t kMinDowngradeNeighbors = 7; + static constexpr uint8_t kNetworkIdTimeout = 120; // (in sec) + static constexpr uint8_t kRouterSelectionJitter = 120; // (in sec) + static constexpr uint8_t kRouterDowngradeThreshold = 23; + static constexpr uint8_t kRouterUpgradeThreshold = 16; + static constexpr uint16_t kDiscoveryMaxJitter = 250; // Max jitter delay Discovery Responses (in msec). + static constexpr uint16_t kUnsolicitedDataResponseJitter = 500; // Max delay for unsol Data Response (in msec). + static constexpr uint8_t kLeaderDowngradeExtraDelay = 10; // Extra delay to downgrade leader (in sec). + static constexpr uint8_t kDefaultLeaderWeight = 64; + static constexpr uint8_t kAlternateRloc16Timeout = 8; // Time to use alternate RLOC16 (in sec). + + // Threshold to accept a router upgrade request with reason + // `kBorderRouterRequest` (number of BRs acting as router in + // Network Data). + static constexpr uint8_t kRouterUpgradeBorderRouterRequestThreshold = 2; + + static constexpr uint8_t kLinkRequestMinMargin = OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN; + static constexpr uint8_t kPartitionMergeMinMargin = OPENTHREAD_CONFIG_MLE_PARTITION_MERGE_MARGIN_MIN; + static constexpr uint8_t kChildRouterLinks = OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS; + static constexpr uint8_t kMaxChildIpAddresses = OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD; + + // Constants for gradual router link establishment (on FTD child) + struct GradualChildRouterLink + { + static constexpr uint8_t kExtraChildRouterLinks = OPENTHREAD_CONFIG_MLE_EXTRA_CHILD_ROUTER_LINKS_GRADUAL; + static constexpr uint32_t kWaitDurationAfterAttach = 300; // in seconds (5 minutes) + static constexpr uint32_t kMinLinkRequestDelay = 1500; // in msec + static constexpr uint32_t kMaxLinkRequestDelay = 10000; // in msec + static constexpr uint32_t kProbabilityPercentage = 5; // in percent + }; + + static constexpr uint8_t kMinCriticalChildrenCount = 6; + + static constexpr uint16_t kChildSupervisionDefaultIntervalForOlderVersion = + OPENTHREAD_CONFIG_CHILD_SUPERVISION_OLDER_VERSION_CHILD_DEFAULT_INTERVAL; + + static constexpr int8_t kParentPriorityHigh = 1; + static constexpr int8_t kParentPriorityMedium = 0; + static constexpr int8_t kParentPriorityLow = -1; + static constexpr int8_t kParentPriorityUnspecified = -2; + +#endif // OPENTHREAD_FTD + //------------------------------------------------------------------------------------------------------------------ // Enumerations @@ -1317,6 +1788,57 @@ private: }; #endif // OPENTHREAD_CONFIG_PARENT_SEARCH_ENABLE + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +#if OPENTHREAD_FTD + + class RouterRoleTransition + { + public: + RouterRoleTransition(void); + + bool IsPending(void) const { return (mTimeout != 0); } + void StartTimeout(void); + void StopTimeout(void) { mTimeout = 0; } + void IncreaseTimeout(uint8_t aIncrement) { mTimeout += aIncrement; } + uint8_t GetTimeout(void) const { return mTimeout; } + bool HandleTimeTick(void); + uint8_t GetJitter(void) const { return mJitter; } + void SetJitter(uint8_t aJitter) { mJitter = aJitter; } + + private: + uint8_t mTimeout; + uint8_t mJitter; + }; + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + class RouterRoleRestorer : public InstanceLocator + { + // Attempts to restore the router or leader role after an MLE + // restart(e.g., after a device reboot) by sending multicast + // Link Requests. + + public: + RouterRoleRestorer(Instance &aInstance); + + bool IsActive(void) const { return mAttempts > 0; } + void Start(DeviceRole aPreviousRole); + void Stop(void) { mAttempts = 0; } + void HandleTimer(void); + + void GenerateRandomChallenge(void) { mChallenge.GenerateRandom(); } + const TxChallenge &GetChallenge(void) const { return mChallenge; } + + private: + void SendMulticastLinkRequest(void); + + uint8_t mAttempts; + TxChallenge mChallenge; + }; + +#endif // OPENTHREAD_FTD + //------------------------------------------------------------------------------------------------------------------ // Methods @@ -1452,6 +1974,83 @@ private: static void LogSendError(MessageType, Error) {} #endif +#if OPENTHREAD_FTD + void SetAlternateRloc16(uint16_t aRloc16); + void ClearAlternateRloc16(void); + void HandleDetachStart(void); + void HandleChildStart(AttachMode aMode); + void HandleSecurityPolicyChanged(void); + void HandleLinkRequest(RxInfo &aRxInfo); + void HandleLinkAccept(RxInfo &aRxInfo); + void HandleLinkAcceptAndRequest(RxInfo &aRxInfo); + void HandleLinkAcceptVariant(RxInfo &aRxInfo, MessageType aMessageType); + Error HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData); + void HandleParentRequest(RxInfo &aRxInfo); + void HandleChildIdRequest(RxInfo &aRxInfo); + void HandleChildUpdateRequestOnParent(RxInfo &aRxInfo); + void HandleChildUpdateResponseOnParent(RxInfo &aRxInfo); + void HandleDataRequest(RxInfo &aRxInfo); + void HandleNetworkDataUpdateRouter(void); + void HandleDiscoveryRequest(RxInfo &aRxInfo); + void EstablishRouterLinkOnFtdChild(Router &aRouter, RxInfo &aRxInfo, uint8_t aLinkMargin); + Error ProcessRouteTlv(const RouteTlv &aRouteTlv, RxInfo &aRxInfo); + Error ReadAndProcessRouteTlvOnFtdChild(RxInfo &aRxInfo, uint8_t aParentId); + void StopAdvertiseTrickleTimer(void); + uint32_t DetermineAdvertiseIntervalMax(void) const; + Error SendAddressSolicit(ThreadStatusTlv::Status aStatus); + void SendAddressSolicitResponse(const Coap::Message &aRequest, + ThreadStatusTlv::Status aResponseStatus, + const Router *aRouter, + const Ip6::MessageInfo &aMessageInfo); + void SendAddressRelease(void); + void SendMulticastAdvertisement(void); + void SendAdvertisement(const Ip6::Address &aDestination); + void SendLinkRequest(Router *aRouter); + Error SendLinkAccept(const LinkAcceptInfo &aInfo); + void SendParentResponse(const ParentResponseInfo &aInfo); + Error SendChildIdResponse(Child &aChild); + Error SendChildUpdateRequestToChild(Child &aChild); + void SendChildUpdateResponseToChild(Child *aChild, + const Ip6::MessageInfo &aMessageInfo, + const TlvList &aTlvList, + const RxChallenge &aChallenge); + void SendMulticastDataResponse(void); + void SendDataResponse(const Ip6::Address &aDestination, + const TlvList &aTlvList, + const Message *aRequestMessage = nullptr); + Error SendDiscoveryResponse(const Ip6::Address &aDestination, const DiscoveryResponseInfo &aInfo); + void SetStateRouter(uint16_t aRloc16); + void SetStateLeader(uint16_t aRloc16, LeaderStartMode aStartMode); + void SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, LeaderStartMode aStartMode); + void StopLeader(void); + void SynchronizeChildNetworkData(void); + Error ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild); + bool HasNeighborWithGoodLinkQuality(void) const; + void HandlePartitionChange(void); + void SetChildStateToValid(Child &aChild); + bool HasChildren(void); + void RemoveChildren(void); + bool ShouldDowngrade(uint8_t aNeighborId, const RouteTlv &aRouteTlv) const; + bool NeighborHasComparableConnectivity(const RouteTlv &aRouteTlv, uint8_t aNeighborId) const; + void HandleAdvertiseTrickleTimer(void); + void HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); + void HandleTimeTick(void); + + template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); + +#if OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE + void SignalDuaAddressEvent(const Child &aChild, const Ip6::Address &aOldDua) const; +#endif + + static bool IsMessageMleSubType(const Message &aMessage); + static bool IsMessageChildUpdateRequest(const Message &aMessage); + static void HandleAdvertiseTrickleTimer(TrickleTimer &aTimer); + static void HandleAddressSolicitResponse(void *aContext, + otMessage *aMessage, + const otMessageInfo *aMessageInfo, + otError aResult); +#endif // OPENTHREAD_FTD + //------------------------------------------------------------------------------------------------------------------ // Variables @@ -1533,8 +2132,60 @@ private: WedAttachTimer mWedAttachTimer; Callback mWakeupCallback; #endif + +#if OPENTHREAD_FTD + + bool mRouterEligible : 1; + bool mAddressSolicitPending : 1; + bool mAddressSolicitRejected : 1; +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + bool mCcmEnabled : 1; + bool mThreadVersionCheckEnabled : 1; +#endif + + uint8_t mRouterId; + uint8_t mPreviousRouterId; + uint8_t mNetworkIdTimeout; + uint8_t mRouterUpgradeThreshold; + uint8_t mRouterDowngradeThreshold; + uint8_t mLeaderWeight; + uint8_t mPreviousPartitionRouterIdSequence; + uint8_t mPreviousPartitionIdTimeout; + uint8_t mChildRouterLinks; + uint8_t mAlternateRloc16Timeout; +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + uint8_t mMaxChildIpAddresses; +#endif + int8_t mParentPriority; + uint16_t mNextChildId; + uint32_t mPreviousPartitionIdRouter; + uint32_t mPreviousPartitionId; +#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE + uint32_t mPreferredLeaderPartitionId; +#endif + + TrickleTimer mAdvertiseTrickleTimer; + ChildTable mChildTable; + RouterTable mRouterTable; + RouterRoleRestorer mRouterRoleRestorer; + RouterRoleTransition mRouterRoleTransition; + Ip6::Netif::UnicastAddress mLeaderAloc; +#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE + DeviceProperties mDeviceProperties; +#endif +#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE + MeshCoP::SteeringData mSteeringData; +#endif + Callback mDiscoveryRequestCallback; + +#endif // OPENTHREAD_FTD }; +#if OPENTHREAD_FTD +DeclareTmfHandler(Mle, kUriAddressSolicit); +DeclareTmfHandler(Mle, kUriAddressRelease); +#endif + } // namespace Mle /** diff --git a/src/core/thread/mle_router.cpp b/src/core/thread/mle_ftd.cpp similarity index 92% rename from src/core/thread/mle_router.cpp rename to src/core/thread/mle_ftd.cpp index 2d97710a6..5b7812954 100644 --- a/src/core/thread/mle_router.cpp +++ b/src/core/thread/mle_ftd.cpp @@ -30,7 +30,7 @@ * This file implements MLE functionality required for the Thread Router and Leader roles. */ -#include "mle_router.hpp" +#include "mle.hpp" #if OPENTHREAD_FTD @@ -41,55 +41,7 @@ namespace Mle { RegisterLogModule("Mle"); -MleRouter::MleRouter(Instance &aInstance) - : Mle(aInstance) - , mRouterEligible(true) - , mAddressSolicitPending(false) - , mAddressSolicitRejected(false) -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - , mCcmEnabled(false) - , mThreadVersionCheckEnabled(true) -#endif - , mNetworkIdTimeout(kNetworkIdTimeout) - , mRouterUpgradeThreshold(kRouterUpgradeThreshold) - , mRouterDowngradeThreshold(kRouterDowngradeThreshold) - , mPreviousPartitionRouterIdSequence(0) - , mPreviousPartitionIdTimeout(0) - , mChildRouterLinks(kChildRouterLinks) - , mAlternateRloc16Timeout(0) -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - , mMaxChildIpAddresses(0) -#endif - , mParentPriority(kParentPriorityUnspecified) - , mNextChildId(kMaxChildId) - , mPreviousPartitionIdRouter(0) - , mPreviousPartitionId(0) -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - , mPreferredLeaderPartitionId(0) -#endif - , mAdvertiseTrickleTimer(aInstance, MleRouter::HandleAdvertiseTrickleTimer) - , mChildTable(aInstance) - , mRouterTable(aInstance) - , mRouterRoleRestorer(aInstance) -{ - mDeviceMode.Set(mDeviceMode.Get() | DeviceMode::kModeFullThreadDevice | DeviceMode::kModeFullNetworkData); - -#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE - mLeaderWeight = mDeviceProperties.CalculateLeaderWeight(); -#else - mLeaderWeight = kDefaultLeaderWeight; -#endif - - mLeaderAloc.InitAsThreadOriginMeshLocal(); - - SetRouterId(kInvalidRouterId); - -#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE - mSteeringData.Clear(); -#endif -} - -void MleRouter::SetAlternateRloc16(uint16_t aRloc16) +void Mle::SetAlternateRloc16(uint16_t aRloc16) { VerifyOrExit(aRloc16 != Mac::kShortAddrInvalid); @@ -102,7 +54,7 @@ exit: return; } -void MleRouter::ClearAlternateRloc16(void) +void Mle::ClearAlternateRloc16(void) { VerifyOrExit(Get().GetAlternateShortAddress() != Mac::kShortAddrInvalid); @@ -113,18 +65,18 @@ exit: mAlternateRloc16Timeout = 0; } -void MleRouter::HandlePartitionChange(void) +void Mle::HandlePartitionChange(void) { mPreviousPartitionId = mLeaderData.GetPartitionId(); mPreviousPartitionRouterIdSequence = mRouterTable.GetRouterIdSequence(); mPreviousPartitionIdTimeout = GetNetworkIdTimeout(); Get().Clear(); - IgnoreError(Get().AbortTransaction(&MleRouter::HandleAddressSolicitResponse, this)); + IgnoreError(Get().AbortTransaction(&Mle::HandleAddressSolicitResponse, this)); mRouterTable.Clear(); } -bool MleRouter::IsRouterEligible(void) const +bool Mle::IsRouterEligible(void) const { bool rval = false; const SecurityPolicy &secPolicy = Get().GetSecurityPolicy(); @@ -161,7 +113,7 @@ exit: return rval; } -Error MleRouter::SetRouterEligible(bool aEligible) +Error Mle::SetRouterEligible(bool aEligible) { Error error = kErrorNone; @@ -203,7 +155,7 @@ exit: return error; } -void MleRouter::HandleSecurityPolicyChanged(void) +void Mle::HandleSecurityPolicyChanged(void) { // If we are currently router or leader and no longer eligible to // be a router (due to security policy change), we start jitter @@ -225,7 +177,7 @@ exit: } #if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE -void MleRouter::SetDeviceProperties(const DeviceProperties &aDeviceProperties) +void Mle::SetDeviceProperties(const DeviceProperties &aDeviceProperties) { mDeviceProperties = aDeviceProperties; mDeviceProperties.ClampWeightAdjustment(); @@ -233,7 +185,7 @@ void MleRouter::SetDeviceProperties(const DeviceProperties &aDeviceProperties) } #endif -Error MleRouter::BecomeRouter(ThreadStatusTlv::Status aStatus) +Error Mle::BecomeRouter(ThreadStatusTlv::Status aStatus) { Error error = kErrorNone; @@ -264,7 +216,7 @@ exit: return error; } -Error MleRouter::BecomeLeader(bool aCheckWeight) +Error Mle::BecomeLeader(bool aCheckWeight) { Error error = kErrorNone; Router *router; @@ -321,27 +273,27 @@ exit: return error; } -void MleRouter::StopLeader(void) +void Mle::StopLeader(void) { StopAdvertiseTrickleTimer(); Get().UnsubscribeAllRoutersMulticast(); } -void MleRouter::HandleDetachStart(void) +void Mle::HandleDetachStart(void) { mRouterTable.ClearNeighbors(); StopLeader(); - Get().UnregisterReceiver(TimeTicker::kMleRouter); + Get().UnregisterReceiver(TimeTicker::kMle); } -void MleRouter::HandleChildStart(AttachMode aMode) +void Mle::HandleChildStart(AttachMode aMode) { mAddressSolicitRejected = false; mRouterRoleTransition.StartTimeout(); StopLeader(); - Get().RegisterReceiver(TimeTicker::kMleRouter); + Get().RegisterReceiver(TimeTicker::kMle); if (mRouterEligible) { @@ -416,18 +368,18 @@ exit: } } -void MleRouter::SetStateRouter(uint16_t aRloc16) +void Mle::SetStateRouter(uint16_t aRloc16) { // The `aStartMode` is ignored when used with `kRoleRouter` SetStateRouterOrLeader(kRoleRouter, aRloc16, /* aStartMode */ kStartingAsLeader); } -void MleRouter::SetStateLeader(uint16_t aRloc16, LeaderStartMode aStartMode) +void Mle::SetStateLeader(uint16_t aRloc16, LeaderStartMode aStartMode) { SetStateRouterOrLeader(kRoleLeader, aRloc16, aStartMode); } -void MleRouter::SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, LeaderStartMode aStartMode) +void Mle::SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, LeaderStartMode aStartMode) { if (aRole == kRoleLeader) { @@ -449,7 +401,7 @@ void MleRouter::SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, Leade Get().SubscribeAllRoutersMulticast(); mPreviousPartitionIdRouter = mLeaderData.GetPartitionId(); Get().SetBeaconEnabled(true); - Get().RegisterReceiver(TimeTicker::kMleRouter); + Get().RegisterReceiver(TimeTicker::kMle); if (aRole == kRoleLeader) { @@ -473,12 +425,9 @@ void MleRouter::SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, Leade LogNote("Partition ID 0x%lx", ToUlong(mLeaderData.GetPartitionId())); } -void MleRouter::HandleAdvertiseTrickleTimer(TrickleTimer &aTimer) -{ - aTimer.Get().HandleAdvertiseTrickleTimer(); -} +void Mle::HandleAdvertiseTrickleTimer(TrickleTimer &aTimer) { aTimer.Get().HandleAdvertiseTrickleTimer(); } -void MleRouter::HandleAdvertiseTrickleTimer(void) +void Mle::HandleAdvertiseTrickleTimer(void) { VerifyOrExit(IsRouterEligible(), mAdvertiseTrickleTimer.Stop()); @@ -488,9 +437,9 @@ exit: return; } -void MleRouter::StopAdvertiseTrickleTimer(void) { mAdvertiseTrickleTimer.Stop(); } +void Mle::StopAdvertiseTrickleTimer(void) { mAdvertiseTrickleTimer.Stop(); } -uint32_t MleRouter::DetermineAdvertiseIntervalMax(void) const +uint32_t Mle::DetermineAdvertiseIntervalMax(void) const { uint32_t interval; @@ -507,7 +456,7 @@ uint32_t MleRouter::DetermineAdvertiseIntervalMax(void) const return interval; } -void MleRouter::UpdateAdvertiseInterval(void) +void Mle::UpdateAdvertiseInterval(void) { if (IsRouterOrLeader() && mAdvertiseTrickleTimer.IsRunning()) { @@ -515,7 +464,7 @@ void MleRouter::UpdateAdvertiseInterval(void) } } -void MleRouter::ResetAdvertiseInterval(void) +void Mle::ResetAdvertiseInterval(void) { VerifyOrExit(IsRouterOrLeader()); @@ -530,7 +479,7 @@ exit: return; } -void MleRouter::SendMulticastAdvertisement(void) +void Mle::SendMulticastAdvertisement(void) { Ip6::Address destination; @@ -538,7 +487,7 @@ void MleRouter::SendMulticastAdvertisement(void) SendAdvertisement(destination); } -void MleRouter::ScheduleUnicastAdvertisementTo(const Router &aRouter) +void Mle::ScheduleUnicastAdvertisementTo(const Router &aRouter) { Ip6::Address destination; @@ -547,7 +496,7 @@ void MleRouter::ScheduleUnicastAdvertisementTo(const Router &aRouter) Random::NonCrypto::GetUint32InRange(0, kMaxUnicastAdvertisementDelay)); } -void MleRouter::SendAdvertisement(const Ip6::Address &aDestination) +void Mle::SendAdvertisement(const Ip6::Address &aDestination) { Error error = kErrorNone; TxMessage *message = nullptr; @@ -595,7 +544,7 @@ exit: LogSendError(kTypeAdvertisement, error); } -void MleRouter::SendLinkRequest(Router *aRouter) +void Mle::SendLinkRequest(Router *aRouter) { static const uint8_t kDetachedTlvs[] = {Tlv::kAddress16, Tlv::kRoute}; static const uint8_t kRouterTlvs[] = {Tlv::kLinkMargin}; @@ -677,7 +626,7 @@ exit: FreeMessageOnError(message, error); } -void MleRouter::HandleLinkRequest(RxInfo &aRxInfo) +void Mle::HandleLinkRequest(RxInfo &aRxInfo) { Error error = kErrorNone; Neighbor *neighbor = nullptr; @@ -784,7 +733,7 @@ exit: OT_UNUSED_VARIABLE(neighbor); } -Error MleRouter::SendLinkAccept(const LinkAcceptInfo &aInfo) +Error Mle::SendLinkAccept(const LinkAcceptInfo &aInfo) { static const uint8_t kRouterTlvs[] = {Tlv::kLinkMargin}; @@ -871,14 +820,11 @@ exit: return error; } -void MleRouter::HandleLinkAccept(RxInfo &aRxInfo) { HandleLinkAcceptVariant(aRxInfo, kTypeLinkAccept); } +void Mle::HandleLinkAccept(RxInfo &aRxInfo) { HandleLinkAcceptVariant(aRxInfo, kTypeLinkAccept); } -void MleRouter::HandleLinkAcceptAndRequest(RxInfo &aRxInfo) -{ - HandleLinkAcceptVariant(aRxInfo, kTypeLinkAcceptAndRequest); -} +void Mle::HandleLinkAcceptAndRequest(RxInfo &aRxInfo) { HandleLinkAcceptVariant(aRxInfo, kTypeLinkAcceptAndRequest); } -void MleRouter::HandleLinkAcceptVariant(RxInfo &aRxInfo, MessageType aMessageType) +void Mle::HandleLinkAcceptVariant(RxInfo &aRxInfo, MessageType aMessageType) { // Handles "Link Accept" or "Link Accept And Request". @@ -1087,7 +1033,7 @@ exit: LogProcessError(aMessageType, error); } -Error MleRouter::ProcessRouteTlv(const RouteTlv &aRouteTlv, RxInfo &aRxInfo) +Error Mle::ProcessRouteTlv(const RouteTlv &aRouteTlv, RxInfo &aRxInfo) { // This method processes `aRouteTlv` read from an MLE message. // @@ -1122,7 +1068,7 @@ Error MleRouter::ProcessRouteTlv(const RouteTlv &aRouteTlv, RxInfo &aRxInfo) return error; } -Error MleRouter::ReadAndProcessRouteTlvOnFtdChild(RxInfo &aRxInfo, uint8_t aParentId) +Error Mle::ReadAndProcessRouteTlvOnFtdChild(RxInfo &aRxInfo, uint8_t aParentId) { // This method reads and processes Route TLV from message on an // FTD child if message contains one. It returns `kErrorNone` @@ -1154,7 +1100,7 @@ exit: return error; } -bool MleRouter::IsSingleton(void) const +bool Mle::IsSingleton(void) const { bool isSingleton = true; @@ -1165,10 +1111,10 @@ exit: return isSingleton; } -int MleRouter::ComparePartitions(bool aSingletonA, - const LeaderData &aLeaderDataA, - bool aSingletonB, - const LeaderData &aLeaderDataB) +int Mle::ComparePartitions(bool aSingletonA, + const LeaderData &aLeaderDataA, + bool aSingletonB, + const LeaderData &aLeaderDataB) { int rval = 0; @@ -1185,7 +1131,7 @@ exit: return rval; } -Error MleRouter::HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData) +Error Mle::HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData) { // This method processes a received MLE Advertisement message on // an FTD device. It is called from `Mle::HandleAdvertisement()` @@ -1375,7 +1321,7 @@ exit: return error; } -void MleRouter::EstablishRouterLinkOnFtdChild(Router &aRouter, RxInfo &aRxInfo, uint8_t aLinkMargin) +void Mle::EstablishRouterLinkOnFtdChild(Router &aRouter, RxInfo &aRxInfo, uint8_t aLinkMargin) { // Decide on an FTD child whether to establish a link with a // router upon receiving an advertisement from it. @@ -1437,7 +1383,7 @@ exit: return; } -void MleRouter::HandleParentRequest(RxInfo &aRxInfo) +void Mle::HandleParentRequest(RxInfo &aRxInfo) { Error error = kErrorNone; uint16_t version; @@ -1537,7 +1483,7 @@ exit: LogProcessError(kTypeParentRequest, error); } -bool MleRouter::HasNeighborWithGoodLinkQuality(void) const +bool Mle::HasNeighborWithGoodLinkQuality(void) const { bool haveNeighbor = true; uint8_t linkMargin; @@ -1570,11 +1516,11 @@ exit: return haveNeighbor; } -void MleRouter::HandleTimeTick(void) +void Mle::HandleTimeTick(void) { bool roleTransitionTimeoutExpired = false; - VerifyOrExit(IsFullThreadDevice(), Get().UnregisterReceiver(TimeTicker::kMleRouter)); + VerifyOrExit(IsFullThreadDevice(), Get().UnregisterReceiver(TimeTicker::kMle)); if (mPreviousPartitionIdTimeout > 0) { @@ -1802,7 +1748,7 @@ exit: return; } -void MleRouter::SendParentResponse(const ParentResponseInfo &aInfo) +void Mle::SendParentResponse(const ParentResponseInfo &aInfo) { Error error = kErrorNone; TxMessage *message = nullptr; @@ -1848,7 +1794,7 @@ exit: LogSendError(kTypeParentResponse, error); } -uint8_t MleRouter::GetMaxChildIpAddresses(void) const +uint8_t Mle::GetMaxChildIpAddresses(void) const { uint8_t num = kMaxChildIpAddresses; @@ -1863,7 +1809,7 @@ uint8_t MleRouter::GetMaxChildIpAddresses(void) const } #if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE -Error MleRouter::SetMaxChildIpAddresses(uint8_t aMaxIpAddresses) +Error Mle::SetMaxChildIpAddresses(uint8_t aMaxIpAddresses) { Error error = kErrorNone; @@ -1876,7 +1822,7 @@ exit: } #endif -Error MleRouter::ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild) +Error Mle::ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild) { Error error; OffsetRange offsetRange; @@ -2044,7 +1990,7 @@ exit: } #if OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE -void MleRouter::SignalDuaAddressEvent(const Child &aChild, const Ip6::Address &aOldDua) const +void Mle::SignalDuaAddressEvent(const Child &aChild, const Ip6::Address &aOldDua) const { DuaManager::ChildDuaAddressEvent event = DuaManager::kAddressUnchanged; Ip6::Address newDua; @@ -2077,14 +2023,14 @@ exit: } #endif // OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE -bool MleRouter::IsMessageMleSubType(const Message &aMessage) { return aMessage.IsSubTypeMle(); } +bool Mle::IsMessageMleSubType(const Message &aMessage) { return aMessage.IsSubTypeMle(); } -bool MleRouter::IsMessageChildUpdateRequest(const Message &aMessage) +bool Mle::IsMessageChildUpdateRequest(const Message &aMessage) { return aMessage.IsMleCommand(kCommandChildUpdateRequest); } -void MleRouter::HandleChildIdRequest(RxInfo &aRxInfo) +void Mle::HandleChildIdRequest(RxInfo &aRxInfo) { Error error = kErrorNone; Mac::ExtAddress extAddr; @@ -2245,7 +2191,7 @@ exit: LogProcessError(kTypeChildIdRequest, error); } -void MleRouter::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo) +void Mle::HandleChildUpdateRequestOnParent(RxInfo &aRxInfo) { Error error = kErrorNone; Mac::ExtAddress extAddr; @@ -2463,7 +2409,7 @@ exit: LogProcessError(kTypeChildUpdateRequestOfChild, error); } -void MleRouter::HandleChildUpdateResponseOnParent(RxInfo &aRxInfo) +void Mle::HandleChildUpdateResponseOnParent(RxInfo &aRxInfo) { Error error = kErrorNone; uint16_t sourceAddress; @@ -2608,7 +2554,7 @@ exit: LogProcessError(kTypeChildUpdateResponseOfChild, error); } -void MleRouter::HandleDataRequest(RxInfo &aRxInfo) +void Mle::HandleDataRequest(RxInfo &aRxInfo) { Error error = kErrorNone; TlvList tlvList; @@ -2665,7 +2611,7 @@ exit: LogProcessError(kTypeDataRequest, error); } -void MleRouter::HandleNetworkDataUpdateRouter(void) +void Mle::HandleNetworkDataUpdateRouter(void) { uint16_t delay; @@ -2687,7 +2633,7 @@ exit: return; } -void MleRouter::SynchronizeChildNetworkData(void) +void Mle::SynchronizeChildNetworkData(void) { VerifyOrExit(IsRouterOrLeader()); @@ -2711,7 +2657,7 @@ exit: } #if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE -void MleRouter::SetSteeringData(const Mac::ExtAddress *aExtAddress) +void Mle::SetSteeringData(const Mac::ExtAddress *aExtAddress) { Mac::ExtAddress nullExtAddr; Mac::ExtAddress allowAnyExtAddr; @@ -2738,7 +2684,7 @@ void MleRouter::SetSteeringData(const Mac::ExtAddress *aExtAddress) } #endif // OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE -void MleRouter::HandleDiscoveryRequest(RxInfo &aRxInfo) +void Mle::HandleDiscoveryRequest(RxInfo &aRxInfo) { Error error = kErrorNone; Tlv::ParsedInfo tlvInfo; @@ -2826,7 +2772,7 @@ exit: LogProcessError(kTypeDiscoveryRequest, error); } -Error MleRouter::SendDiscoveryResponse(const Ip6::Address &aDestination, const DiscoveryResponseInfo &aInfo) +Error Mle::SendDiscoveryResponse(const Ip6::Address &aDestination, const DiscoveryResponseInfo &aInfo) { Error error = kErrorNone; TxMessage *message; @@ -2902,7 +2848,7 @@ exit: return error; } -Error MleRouter::SendChildIdResponse(Child &aChild) +Error Mle::SendChildIdResponse(Child &aChild) { Error error = kErrorNone; Ip6::Address destination; @@ -2994,7 +2940,7 @@ exit: return error; } -Error MleRouter::SendChildUpdateRequestToChild(Child &aChild) +Error Mle::SendChildUpdateRequestToChild(Child &aChild) { static const uint8_t kTlvs[] = {Tlv::kTimeout, Tlv::kAddressRegistration}; @@ -3063,10 +3009,10 @@ exit: return error; } -void MleRouter::SendChildUpdateResponseToChild(Child *aChild, - const Ip6::MessageInfo &aMessageInfo, - const TlvList &aTlvList, - const RxChallenge &aChallenge) +void Mle::SendChildUpdateResponseToChild(Child *aChild, + const Ip6::MessageInfo &aMessageInfo, + const TlvList &aTlvList, + const RxChallenge &aChallenge) { Error error = kErrorNone; TxMessage *message; @@ -3165,7 +3111,7 @@ exit: FreeMessageOnError(message, error); } -void MleRouter::SendMulticastDataResponse(void) +void Mle::SendMulticastDataResponse(void) { Ip6::Address destination; TlvList tlvList; @@ -3175,9 +3121,7 @@ void MleRouter::SendMulticastDataResponse(void) SendDataResponse(destination, tlvList); } -void MleRouter::SendDataResponse(const Ip6::Address &aDestination, - const TlvList &aTlvList, - const Message *aRequestMessage) +void Mle::SendDataResponse(const Ip6::Address &aDestination, const TlvList &aTlvList, const Message *aRequestMessage) { OT_UNUSED_VARIABLE(aRequestMessage); @@ -3239,7 +3183,7 @@ exit: LogSendError(kTypeDataResponse, error); } -void MleRouter::RemoveRouterLink(Router &aRouter) +void Mle::RemoveRouterLink(Router &aRouter) { switch (mRole) { @@ -3260,7 +3204,7 @@ void MleRouter::RemoveRouterLink(Router &aRouter) } } -void MleRouter::RemoveNeighbor(Neighbor &aNeighbor) +void Mle::RemoveNeighbor(Neighbor &aNeighbor) { VerifyOrExit(!aNeighbor.IsStateInvalid()); @@ -3311,7 +3255,7 @@ exit: return; } -Error MleRouter::SetPreferredRouterId(uint8_t aRouterId) +Error Mle::SetPreferredRouterId(uint8_t aRouterId) { Error error = kErrorNone; @@ -3323,13 +3267,13 @@ exit: return error; } -void MleRouter::SetRouterId(uint8_t aRouterId) +void Mle::SetRouterId(uint8_t aRouterId) { mRouterId = aRouterId; mPreviousRouterId = mRouterId; } -Error MleRouter::SendAddressSolicit(ThreadStatusTlv::Status aStatus) +Error Mle::SendAddressSolicit(ThreadStatusTlv::Status aStatus) { Error error = kErrorNone; Tmf::MessageInfo messageInfo(GetInstance()); @@ -3365,7 +3309,7 @@ exit: return error; } -void MleRouter::SendAddressRelease(void) +void Mle::SendAddressRelease(void) { Error error = kErrorNone; Tmf::MessageInfo messageInfo(GetInstance()); @@ -3388,18 +3332,16 @@ exit: LogSendError(kTypeAddressRelease, error); } -void MleRouter::HandleAddressSolicitResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult) +void Mle::HandleAddressSolicitResponse(void *aContext, + otMessage *aMessage, + const otMessageInfo *aMessageInfo, + otError aResult) { - static_cast(aContext)->HandleAddressSolicitResponse(AsCoapMessagePtr(aMessage), - AsCoreTypePtr(aMessageInfo), aResult); + static_cast(aContext)->HandleAddressSolicitResponse(AsCoapMessagePtr(aMessage), AsCoreTypePtr(aMessageInfo), + aResult); } -void MleRouter::HandleAddressSolicitResponse(Coap::Message *aMessage, - const Ip6::MessageInfo *aMessageInfo, - Error aResult) +void Mle::HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult) { uint8_t status; uint16_t rloc16; @@ -3507,7 +3449,7 @@ exit: InformPreviousChannel(); } -Error MleRouter::SetChildRouterLinks(uint8_t aChildRouterLinks) +Error Mle::SetChildRouterLinks(uint8_t aChildRouterLinks) { Error error = kErrorNone; @@ -3517,7 +3459,7 @@ exit: return error; } -bool MleRouter::IsExpectedToBecomeRouterSoon(void) const +bool Mle::IsExpectedToBecomeRouterSoon(void) const { static constexpr uint8_t kMaxDelay = 10; @@ -3526,7 +3468,7 @@ bool MleRouter::IsExpectedToBecomeRouterSoon(void) const mAddressSolicitPending); } -template <> void MleRouter::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) +template <> void Mle::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { Error error = kErrorNone; ThreadStatusTlv::Status responseStatus = ThreadStatusTlv::kNoAddressAvailable; @@ -3624,10 +3566,10 @@ exit: } } -void MleRouter::SendAddressSolicitResponse(const Coap::Message &aRequest, - ThreadStatusTlv::Status aResponseStatus, - const Router *aRouter, - const Ip6::MessageInfo &aMessageInfo) +void Mle::SendAddressSolicitResponse(const Coap::Message &aRequest, + ThreadStatusTlv::Status aResponseStatus, + const Router *aRouter, + const Ip6::MessageInfo &aMessageInfo) { Coap::Message *message = Get().NewPriorityResponseMessage(aRequest); @@ -3676,7 +3618,7 @@ exit: FreeMessage(message); } -template <> void MleRouter::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) +template <> void Mle::HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo) { uint16_t rloc16; Mac::ExtAddress extAddress; @@ -3707,7 +3649,7 @@ exit: return; } -void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv) +void Mle::FillConnectivityTlv(ConnectivityTlv &aTlv) { int8_t parentPriority = kParentPriorityMedium; @@ -3763,7 +3705,7 @@ void MleRouter::FillConnectivityTlv(ConnectivityTlv &aTlv) aTlv.SetSedDatagramCount(OPENTHREAD_CONFIG_DEFAULT_SED_DATAGRAM_COUNT); } -bool MleRouter::ShouldDowngrade(uint8_t aNeighborId, const RouteTlv &aRouteTlv) const +bool Mle::ShouldDowngrade(uint8_t aNeighborId, const RouteTlv &aRouteTlv) const { // Determine whether all conditions are satisfied for the router // to downgrade after receiving info for a neighboring router @@ -3825,7 +3767,7 @@ exit: return shouldDowngrade; } -bool MleRouter::NeighborHasComparableConnectivity(const RouteTlv &aRouteTlv, uint8_t aNeighborId) const +bool Mle::NeighborHasComparableConnectivity(const RouteTlv &aRouteTlv, uint8_t aNeighborId) const { // Check whether the neighboring router with Router ID `aNeighborId` // (along with its `aRouteTlv`) has as good or better-quality links @@ -3881,7 +3823,7 @@ exit: return isComparable; } -void MleRouter::SetChildStateToValid(Child &aChild) +void Mle::SetChildStateToValid(Child &aChild) { VerifyOrExit(!aChild.IsStateValid()); @@ -3898,9 +3840,9 @@ exit: return; } -bool MleRouter::HasChildren(void) { return mChildTable.HasChildren(Child::kInStateValidOrAttaching); } +bool Mle::HasChildren(void) { return mChildTable.HasChildren(Child::kInStateValidOrAttaching); } -void MleRouter::RemoveChildren(void) +void Mle::RemoveChildren(void) { for (Child &child : Get().Iterate(Child::kInStateValidOrRestoring)) { @@ -3908,7 +3850,7 @@ void MleRouter::RemoveChildren(void) } } -Error MleRouter::SetAssignParentPriority(int8_t aParentPriority) +Error Mle::SetAssignParentPriority(int8_t aParentPriority) { Error error = kErrorNone; @@ -3921,7 +3863,7 @@ exit: return error; } -Error MleRouter::GetMaxChildTimeout(uint32_t &aTimeout) const +Error Mle::GetMaxChildTimeout(uint32_t &aTimeout) const { Error error = kErrorNotFound; @@ -3949,7 +3891,7 @@ exit: } #if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE -Error MleRouter::SendTimeSync(void) +Error Mle::SendTimeSync(void) { Error error = kErrorNone; Ip6::Address destination; @@ -3973,18 +3915,15 @@ exit: //---------------------------------------------------------------------------------------------------------------------- // RouterRoleTransition -MleRouter::RouterRoleTransition::RouterRoleTransition(void) +Mle::RouterRoleTransition::RouterRoleTransition(void) : mTimeout(0) , mJitter(kRouterSelectionJitter) { } -void MleRouter::RouterRoleTransition::StartTimeout(void) -{ - mTimeout = 1 + Random::NonCrypto::GetUint8InRange(0, mJitter); -} +void Mle::RouterRoleTransition::StartTimeout(void) { mTimeout = 1 + Random::NonCrypto::GetUint8InRange(0, mJitter); } -bool MleRouter::RouterRoleTransition::HandleTimeTick(void) +bool Mle::RouterRoleTransition::HandleTimeTick(void) { bool expired = false; @@ -3999,13 +3938,13 @@ exit: //---------------------------------------------------------------------------------------------------------------------- // RouterRoleRestorer -MleRouter::RouterRoleRestorer::RouterRoleRestorer(Instance &aInstance) +Mle::RouterRoleRestorer::RouterRoleRestorer(Instance &aInstance) : InstanceLocator(aInstance) , mAttempts(0) { } -void MleRouter::RouterRoleRestorer::Start(DeviceRole aPreviousRole) +void Mle::RouterRoleRestorer::Start(DeviceRole aPreviousRole) { // If the device was previously the leader or had more than // `kMinCriticalChildrenCount` children, we use more link @@ -4016,7 +3955,7 @@ void MleRouter::RouterRoleRestorer::Start(DeviceRole aPreviousRole) switch (aPreviousRole) { case kRoleRouter: - if (Get().mChildTable.GetNumChildren(Child::kInStateValidOrRestoring) < kMinCriticalChildrenCount) + if (Get().mChildTable.GetNumChildren(Child::kInStateValidOrRestoring) < kMinCriticalChildrenCount) { mAttempts = kMaxTxCount; break; @@ -4037,7 +3976,7 @@ void MleRouter::RouterRoleRestorer::Start(DeviceRole aPreviousRole) SendMulticastLinkRequest(); } -void MleRouter::RouterRoleRestorer::HandleTimer(void) +void Mle::RouterRoleRestorer::HandleTimer(void) { if (mAttempts > 0) { @@ -4047,7 +3986,7 @@ void MleRouter::RouterRoleRestorer::HandleTimer(void) SendMulticastLinkRequest(); } -void MleRouter::RouterRoleRestorer::SendMulticastLinkRequest(void) +void Mle::RouterRoleRestorer::SendMulticastLinkRequest(void) { uint32_t delay; @@ -4059,7 +3998,7 @@ void MleRouter::RouterRoleRestorer::SendMulticastLinkRequest(void) ExitNow(); } - Get().SendLinkRequest(nullptr); + Get().SendLinkRequest(nullptr); delay = (mAttempts == 1) ? kLinkRequestTimeout : Random::NonCrypto::GetUint32InRange(kMulticastRetxDelayMin, kMulticastRetxDelayMax); diff --git a/src/core/thread/mle_router.hpp b/src/core/thread/mle_router.hpp deleted file mode 100644 index a9e8ccd37..000000000 --- a/src/core/thread/mle_router.hpp +++ /dev/null @@ -1,742 +0,0 @@ -/* - * Copyright (c) 2016, The OpenThread Authors. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holder nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -/** - * @file - * This file includes definitions for MLE functionality required by the Thread Router and Leader roles. - */ - -#ifndef MLE_ROUTER_HPP_ -#define MLE_ROUTER_HPP_ - -#include "openthread-core-config.h" - -#include - -#include "coap/coap_message.hpp" -#include "common/callback.hpp" -#include "common/time_ticker.hpp" -#include "common/timer.hpp" -#include "common/trickle_timer.hpp" -#include "mac/mac_types.hpp" -#include "meshcop/meshcop_tlvs.hpp" -#include "net/icmp6.hpp" -#include "net/udp6.hpp" -#include "thread/child.hpp" -#include "thread/child_table.hpp" -#include "thread/mle.hpp" -#include "thread/mle_tlvs.hpp" -#include "thread/router.hpp" -#include "thread/router_table.hpp" -#include "thread/thread_tlvs.hpp" -#include "thread/tmf.hpp" - -namespace ot { -namespace Mle { - -/** - * @addtogroup core-mle-router - * - * @brief - * This module includes definitions for MLE functionality required by the Thread Router and Leader roles. - * - * @{ - */ - -#if OPENTHREAD_FTD - -/** - * Implements MLE functionality required by the Thread Router and Leader roles. - */ -class MleRouter : public Mle -{ - friend class Mle; - friend class ot::Instance; - friend class ot::TimeTicker; - friend class Tmf::Agent; - -public: - /** - * Initializes the object. - * - * @param[in] aInstance A reference to the OpenThread instance. - */ - explicit MleRouter(Instance &aInstance); - - /** - * Indicates whether or not the device is router-eligible. - * - * @retval true If device is router-eligible. - * @retval false If device is not router-eligible. - */ - bool IsRouterEligible(void) const; - - /** - * Sets whether or not the device is router-eligible. - * - * If @p aEligible is false and the device is currently operating as a router, this call will cause the device to - * detach and attempt to reattach as a child. - * - * @param[in] aEligible TRUE to configure device router-eligible, FALSE otherwise. - * - * @retval kErrorNone Successfully set the router-eligible configuration. - * @retval kErrorNotCapable The device is not capable of becoming a router. - */ - Error SetRouterEligible(bool aEligible); - - /** - * Indicates whether a node is the only router on the network. - * - * @retval TRUE It is the only router in the network. - * @retval FALSE It is a child or is not a single router in the network. - */ - bool IsSingleton(void) const; - - /** - * Generates an Address Solicit request for a Router ID. - * - * @param[in] aStatus The reason for requesting a Router ID. - * - * @retval kErrorNone Successfully generated an Address Solicit message. - * @retval kErrorNotCapable Device is not capable of becoming a router - * @retval kErrorInvalidState Thread is not enabled - */ - Error BecomeRouter(ThreadStatusTlv::Status aStatus); - - /** - * Becomes a leader and starts a new partition. - * - * If the device is already attached, this method can be used to attempt to take over as the leader, creating a new - * partition. For this to work, the local leader weight must be greater than the weight of the current leader. The - * @p aCheckWeight can be used to ensure that this check is performed. - * - * @param[in] aCheckWeight Check that the local leader weight is larger than the weight of the current leader. - * - * @retval kErrorNone Successfully become a Leader and started a new partition. - * @retval kErrorInvalidState Thread is not enabled. - * @retval kErrorNotCapable Device is not capable of becoming a leader (not router eligible), or - * @p aCheckWeight is true and cannot override the current leader due to its local - * leader weight being same or smaller than current leader's weight. - */ - Error BecomeLeader(bool aCheckWeight); - -#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE - /** - * Gets the device properties which are used to determine the Leader Weight. - * - * @returns The current device properties. - */ - const DeviceProperties &GetDeviceProperties(void) const { return mDeviceProperties; } - - /** - * Sets the device properties which are then used to determine and set the Leader Weight. - * - * @param[in] aDeviceProperties The device properties. - */ - void SetDeviceProperties(const DeviceProperties &aDeviceProperties); -#endif - - /** - * Returns the Leader Weighting value for this Thread interface. - * - * @returns The Leader Weighting value for this Thread interface. - */ - uint8_t GetLeaderWeight(void) const { return mLeaderWeight; } - - /** - * Sets the Leader Weighting value for this Thread interface. - * - * Directly sets the Leader Weight to the new value replacing its previous value (which may have been - * determined from a previous call to `SetDeviceProperties()`). - * - * @param[in] aWeight The Leader Weighting value. - */ - void SetLeaderWeight(uint8_t aWeight) { mLeaderWeight = aWeight; } - -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - - /** - * Returns the preferred Partition Id when operating in the Leader role for certification testing. - * - * @returns The preferred Partition Id value. - */ - uint32_t GetPreferredLeaderPartitionId(void) const { return mPreferredLeaderPartitionId; } - - /** - * Sets the preferred Partition Id when operating in the Leader role for certification testing. - * - * @param[in] aPartitionId The preferred Leader Partition Id. - */ - void SetPreferredLeaderPartitionId(uint32_t aPartitionId) { mPreferredLeaderPartitionId = aPartitionId; } -#endif - - /** - * Sets the preferred Router Id. Upon becoming a router/leader the node - * attempts to use this Router Id. If the preferred Router Id is not set or if it - * can not be used, a randomly generated router Id is picked. - * This property can be set when he device role is detached or disabled. - * - * @param[in] aRouterId The preferred Router Id. - * - * @retval kErrorNone Successfully set the preferred Router Id. - * @retval kErrorInvalidState Could not set (role is other than detached and disabled) - */ - Error SetPreferredRouterId(uint8_t aRouterId); - - /** - * Gets the Partition Id which the device joined successfully once. - */ - uint32_t GetPreviousPartitionId(void) const { return mPreviousPartitionId; } - - /** - * Sets the Partition Id which the device joins successfully. - * - * @param[in] aPartitionId The Partition Id. - */ - void SetPreviousPartitionId(uint32_t aPartitionId) { mPreviousPartitionId = aPartitionId; } - - /** - * Sets the Router Id. - * - * @param[in] aRouterId The Router Id. - */ - void SetRouterId(uint8_t aRouterId); - - /** - * Returns the NETWORK_ID_TIMEOUT value. - * - * @returns The NETWORK_ID_TIMEOUT value. - */ - uint8_t GetNetworkIdTimeout(void) const { return mNetworkIdTimeout; } - - /** - * Sets the NETWORK_ID_TIMEOUT value. - * - * @param[in] aTimeout The NETWORK_ID_TIMEOUT value. - */ - void SetNetworkIdTimeout(uint8_t aTimeout) { mNetworkIdTimeout = aTimeout; } - - /** - * Returns the ROUTER_SELECTION_JITTER value. - * - * @returns The ROUTER_SELECTION_JITTER value in seconds. - */ - uint8_t GetRouterSelectionJitter(void) const { return mRouterRoleTransition.GetJitter(); } - - /** - * Sets the ROUTER_SELECTION_JITTER value. - * - * @param[in] aRouterJitter The router selection jitter value (in seconds). - */ - void SetRouterSelectionJitter(uint8_t aRouterJitter) { mRouterRoleTransition.SetJitter(aRouterJitter); } - - /** - * Indicates whether or not router role transition (upgrade from REED or downgrade to REED) is pending. - * - * @retval TRUE Router role transition is pending. - * @retval FALSE Router role transition is not pending - */ - bool IsRouterRoleTransitionPending(void) const { return mRouterRoleTransition.IsPending(); } - - /** - * Returns the current timeout delay in seconds till router role transition (upgrade from REED or downgrade to - * REED). - * - * @returns The timeout in seconds till router role transition, or zero if not pending role transition. - */ - uint8_t GetRouterRoleTransitionTimeout(void) const { return mRouterRoleTransition.GetTimeout(); } - - /** - * Returns the ROUTER_UPGRADE_THRESHOLD value. - * - * @returns The ROUTER_UPGRADE_THRESHOLD value. - */ - uint8_t GetRouterUpgradeThreshold(void) const { return mRouterUpgradeThreshold; } - - /** - * Sets the ROUTER_UPGRADE_THRESHOLD value. - * - * @param[in] aThreshold The ROUTER_UPGRADE_THRESHOLD value. - */ - void SetRouterUpgradeThreshold(uint8_t aThreshold) { mRouterUpgradeThreshold = aThreshold; } - - /** - * Returns the ROUTER_DOWNGRADE_THRESHOLD value. - * - * @returns The ROUTER_DOWNGRADE_THRESHOLD value. - */ - uint8_t GetRouterDowngradeThreshold(void) const { return mRouterDowngradeThreshold; } - - /** - * Sets the ROUTER_DOWNGRADE_THRESHOLD value. - * - * @param[in] aThreshold The ROUTER_DOWNGRADE_THRESHOLD value. - */ - void SetRouterDowngradeThreshold(uint8_t aThreshold) { mRouterDowngradeThreshold = aThreshold; } - - /** - * Returns the MLE_CHILD_ROUTER_LINKS value. - * - * @returns The MLE_CHILD_ROUTER_LINKS value. - */ - uint8_t GetChildRouterLinks(void) const { return mChildRouterLinks; } - - /** - * Sets the MLE_CHILD_ROUTER_LINKS value. - * - * @param[in] aChildRouterLinks The MLE_CHILD_ROUTER_LINKS value. - * - * @retval kErrorNone Successfully set the value. - * @retval kErrorInvalidState Thread protocols are enabled. - */ - Error SetChildRouterLinks(uint8_t aChildRouterLinks); - - /** - * Returns if the REED is expected to become Router soon. - * - * @retval TRUE If the REED is going to become a Router soon. - * @retval FALSE If the REED is not going to become a Router soon. - */ - bool IsExpectedToBecomeRouterSoon(void) const; - - /** - * Removes a link to a neighbor. - * - * @param[in] aNeighbor A reference to the neighbor object. - */ - void RemoveNeighbor(Neighbor &aNeighbor); - - /** - * Invalidates a direct link to a neighboring router (due to failed link-layer acks). - * - * @param[in] aRouter A reference to the router object. - */ - void RemoveRouterLink(Router &aRouter); - - /** - * Indicates whether or not the given Thread partition attributes are preferred. - * - * @param[in] aSingletonA Whether or not the Thread Partition A has a single router. - * @param[in] aLeaderDataA A reference to Thread Partition A's Leader Data. - * @param[in] aSingletonB Whether or not the Thread Partition B has a single router. - * @param[in] aLeaderDataB A reference to Thread Partition B's Leader Data. - * - * @retval 1 If partition A is preferred. - * @retval 0 If partition A and B have equal preference. - * @retval -1 If partition B is preferred. - */ - static int ComparePartitions(bool aSingletonA, - const LeaderData &aLeaderDataA, - bool aSingletonB, - const LeaderData &aLeaderDataB); - - /** - * Fills an ConnectivityTlv. - * - * @param[out] aTlv A reference to the tlv to be filled. - */ - void FillConnectivityTlv(ConnectivityTlv &aTlv); - - /** - * Schedule tx of MLE Advertisement message (unicast) to the given neighboring router after a random delay. - * - * @param[in] aRouter The router to send the Advertisement to. - * - */ - void ScheduleUnicastAdvertisementTo(const Router &aRouter); - -#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE - /** - * Sets steering data out of band - * - * @param[in] aExtAddress Value used to set steering data - * All zeros clears steering data - * All 0xFFs sets steering data to 0xFF - * Anything else is used to compute the bloom filter - */ - void SetSteeringData(const Mac::ExtAddress *aExtAddress); -#endif - - /** - * Gets the assigned parent priority. - * - * @returns The assigned parent priority value, -2 means not assigned. - */ - int8_t GetAssignParentPriority(void) const { return mParentPriority; } - - /** - * Sets the parent priority. - * - * @param[in] aParentPriority The parent priority value. - * - * @retval kErrorNone Successfully set the parent priority. - * @retval kErrorInvalidArgs If the parent priority value is not among 1, 0, -1 and -2. - */ - Error SetAssignParentPriority(int8_t aParentPriority); - - /** - * Gets the longest MLE Timeout TLV for all active MTD children. - * - * @param[out] aTimeout A reference to where the information is placed. - * - * @retval kErrorNone Successfully get the max child timeout - * @retval kErrorInvalidState Not an active router - * @retval kErrorNotFound NO MTD child - */ - Error GetMaxChildTimeout(uint32_t &aTimeout) const; - - /** - * Sets the callback that is called when processing an MLE Discovery Request message. - * - * @param[in] aCallback A pointer to a function that is called to deliver MLE Discovery Request data. - * @param[in] aContext A pointer to application-specific context. - */ - void SetDiscoveryRequestCallback(otThreadDiscoveryRequestCallback aCallback, void *aContext) - { - mDiscoveryRequestCallback.Set(aCallback, aContext); - } - - /** - * Resets the MLE Advertisement Trickle timer interval. - */ - void ResetAdvertiseInterval(void); - - /** - * Updates the MLE Advertisement Trickle timer max interval (if timer is running). - * - * This is called when there is change in router table. - */ - void UpdateAdvertiseInterval(void); - -#if OPENTHREAD_CONFIG_TIME_SYNC_ENABLE - /** - * Generates an MLE Time Synchronization message. - * - * @retval kErrorNone Successfully sent an MLE Time Synchronization message. - * @retval kErrorNoBufs Insufficient buffers to generate the MLE Time Synchronization message. - */ - Error SendTimeSync(void); -#endif - - /** - * Gets the maximum number of IP addresses that each MTD child may register with this device as parent. - * - * @returns The maximum number of IP addresses that each MTD child may register with this device as parent. - */ - uint8_t GetMaxChildIpAddresses(void) const; - -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - - /** - * Sets/restores the maximum number of IP addresses that each MTD child may register with this - * device as parent. - * - * @param[in] aMaxIpAddresses The maximum number of IP addresses that each MTD child may register with this - * device as parent. 0 to clear the setting and restore the default. - * - * @retval kErrorNone Successfully set/cleared the number. - * @retval kErrorInvalidArgs If exceeds the allowed maximum number. - */ - Error SetMaxChildIpAddresses(uint8_t aMaxIpAddresses); - - /** - * Sets whether the device was commissioned using CCM. - * - * @param[in] aEnabled TRUE if the device was commissioned using CCM, FALSE otherwise. - */ - void SetCcmEnabled(bool aEnabled) { mCcmEnabled = aEnabled; } - - /** - * Sets whether the Security Policy TLV version-threshold for routing (VR field) is enabled. - * - * @param[in] aEnabled TRUE to enable Security Policy TLV version-threshold for routing, FALSE otherwise. - */ - void SetThreadVersionCheckEnabled(bool aEnabled) { mThreadVersionCheckEnabled = aEnabled; } - - /** - * Gets the current Interval Max value used by Advertisement trickle timer. - * - * @returns The Interval Max of Advertisement trickle timer in milliseconds. - */ - uint32_t GetAdvertisementTrickleIntervalMax(void) const { return mAdvertiseTrickleTimer.GetIntervalMax(); } - -#endif // OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - -private: - //------------------------------------------------------------------------------------------------------------------ - // Constants - - // Advertisement trickle timer constants - all times are in milliseconds. - static constexpr uint32_t kAdvIntervalMin = 1000; // I_MIN - static constexpr uint32_t kAdvIntervalNeighborMultiplier = 4000; // Multiplier for I_MAX per router neighbor - static constexpr uint32_t kAdvIntervalMaxLowerBound = 12000; // Lower bound for I_MAX - static constexpr uint32_t kAdvIntervalMaxUpperBound = 32000; // Upper bound for I_MAX - static constexpr uint32_t kReedAdvIntervalMin = 570000; - static constexpr uint32_t kReedAdvIntervalMax = 630000; -#if OPENTHREAD_CONFIG_MLE_LONG_ROUTES_ENABLE - static constexpr uint32_t kAdvIntervalMaxLogRoutes = 5000; -#endif - - static constexpr uint32_t kMaxUnicastAdvertisementDelay = 1000; // Max random delay for unciast Adv tx - static constexpr uint32_t kMaxNeighborAge = 100000; // Max neighbor age on router (in msec) - static constexpr uint32_t kMaxNeighborAgeOnChild = 150000; // Max neighbor age on FTD child (in msec) - static constexpr uint32_t kMaxLeaderToRouterTimeout = 90000; // (in msec) - static constexpr uint8_t kMinDowngradeNeighbors = 7; - static constexpr uint8_t kNetworkIdTimeout = 120; // (in sec) - static constexpr uint8_t kRouterSelectionJitter = 120; // (in sec) - static constexpr uint8_t kRouterDowngradeThreshold = 23; - static constexpr uint8_t kRouterUpgradeThreshold = 16; - static constexpr uint16_t kDiscoveryMaxJitter = 250; // Max jitter delay Discovery Responses (in msec). - static constexpr uint16_t kUnsolicitedDataResponseJitter = 500; // Max delay for unsol Data Response (in msec). - static constexpr uint8_t kLeaderDowngradeExtraDelay = 10; // Extra delay to downgrade leader (in sec). - static constexpr uint8_t kDefaultLeaderWeight = 64; - static constexpr uint8_t kAlternateRloc16Timeout = 8; // Time to use alternate RLOC16 (in sec). - - // Threshold to accept a router upgrade request with reason - // `kBorderRouterRequest` (number of BRs acting as router in - // Network Data). - static constexpr uint8_t kRouterUpgradeBorderRouterRequestThreshold = 2; - - static constexpr uint8_t kLinkRequestMinMargin = OPENTHREAD_CONFIG_MLE_LINK_REQUEST_MARGIN_MIN; - static constexpr uint8_t kPartitionMergeMinMargin = OPENTHREAD_CONFIG_MLE_PARTITION_MERGE_MARGIN_MIN; - static constexpr uint8_t kChildRouterLinks = OPENTHREAD_CONFIG_MLE_CHILD_ROUTER_LINKS; - static constexpr uint8_t kMaxChildIpAddresses = OPENTHREAD_CONFIG_MLE_IP_ADDRS_PER_CHILD; - - // Constants for gradual router link establishment (on FTD child) - struct GradualChildRouterLink - { - static constexpr uint8_t kExtraChildRouterLinks = OPENTHREAD_CONFIG_MLE_EXTRA_CHILD_ROUTER_LINKS_GRADUAL; - static constexpr uint32_t kWaitDurationAfterAttach = 300; // in seconds (5 minutes) - static constexpr uint32_t kMinLinkRequestDelay = 1500; // in msec - static constexpr uint32_t kMaxLinkRequestDelay = 10000; // in msec - static constexpr uint32_t kProbabilityPercentage = 5; // in percent - }; - - static constexpr uint8_t kMinCriticalChildrenCount = 6; - - static constexpr uint16_t kChildSupervisionDefaultIntervalForOlderVersion = - OPENTHREAD_CONFIG_CHILD_SUPERVISION_OLDER_VERSION_CHILD_DEFAULT_INTERVAL; - - static constexpr int8_t kParentPriorityHigh = 1; - static constexpr int8_t kParentPriorityMedium = 0; - static constexpr int8_t kParentPriorityLow = -1; - static constexpr int8_t kParentPriorityUnspecified = -2; - - //------------------------------------------------------------------------------------------------------------------ - // Nested types - - class RouterRoleTransition - { - public: - RouterRoleTransition(void); - - bool IsPending(void) const { return (mTimeout != 0); } - void StartTimeout(void); - void StopTimeout(void) { mTimeout = 0; } - void IncreaseTimeout(uint8_t aIncrement) { mTimeout += aIncrement; } - uint8_t GetTimeout(void) const { return mTimeout; } - bool HandleTimeTick(void); - uint8_t GetJitter(void) const { return mJitter; } - void SetJitter(uint8_t aJitter) { mJitter = aJitter; } - - private: - uint8_t mTimeout; - uint8_t mJitter; - }; - - //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - class RouterRoleRestorer : public InstanceLocator - { - // Attempts to restore the router or leader role after an MLE - // restart(e.g., after a device reboot) by sending multicast - // Link Requests. - - public: - RouterRoleRestorer(Instance &aInstance); - - bool IsActive(void) const { return mAttempts > 0; } - void Start(DeviceRole aPreviousRole); - void Stop(void) { mAttempts = 0; } - void HandleTimer(void); - - void GenerateRandomChallenge(void) { mChallenge.GenerateRandom(); } - const TxChallenge &GetChallenge(void) const { return mChallenge; } - - private: - void SendMulticastLinkRequest(void); - - uint8_t mAttempts; - TxChallenge mChallenge; - }; - - //------------------------------------------------------------------------------------------------------------------ - // Methods - - void SetAlternateRloc16(uint16_t aRloc16); - void ClearAlternateRloc16(void); - void HandleDetachStart(void); - void HandleChildStart(AttachMode aMode); - void HandleSecurityPolicyChanged(void); - void HandleLinkRequest(RxInfo &aRxInfo); - void HandleLinkAccept(RxInfo &aRxInfo); - void HandleLinkAcceptAndRequest(RxInfo &aRxInfo); - void HandleLinkAcceptVariant(RxInfo &aRxInfo, MessageType aMessageType); - Error HandleAdvertisementOnFtd(RxInfo &aRxInfo, uint16_t aSourceAddress, const LeaderData &aLeaderData); - void HandleParentRequest(RxInfo &aRxInfo); - void HandleChildIdRequest(RxInfo &aRxInfo); - void HandleChildUpdateRequestOnParent(RxInfo &aRxInfo); - void HandleChildUpdateResponseOnParent(RxInfo &aRxInfo); - void HandleDataRequest(RxInfo &aRxInfo); - void HandleNetworkDataUpdateRouter(void); - void HandleDiscoveryRequest(RxInfo &aRxInfo); - void EstablishRouterLinkOnFtdChild(Router &aRouter, RxInfo &aRxInfo, uint8_t aLinkMargin); - Error ProcessRouteTlv(const RouteTlv &aRouteTlv, RxInfo &aRxInfo); - Error ReadAndProcessRouteTlvOnFtdChild(RxInfo &aRxInfo, uint8_t aParentId); - void StopAdvertiseTrickleTimer(void); - uint32_t DetermineAdvertiseIntervalMax(void) const; - Error SendAddressSolicit(ThreadStatusTlv::Status aStatus); - void SendAddressSolicitResponse(const Coap::Message &aRequest, - ThreadStatusTlv::Status aResponseStatus, - const Router *aRouter, - const Ip6::MessageInfo &aMessageInfo); - void SendAddressRelease(void); - void SendMulticastAdvertisement(void); - void SendAdvertisement(const Ip6::Address &aDestination); - void SendLinkRequest(Router *aRouter); - Error SendLinkAccept(const LinkAcceptInfo &aInfo); - void SendParentResponse(const ParentResponseInfo &aInfo); - Error SendChildIdResponse(Child &aChild); - Error SendChildUpdateRequestToChild(Child &aChild); - void SendChildUpdateResponseToChild(Child *aChild, - const Ip6::MessageInfo &aMessageInfo, - const TlvList &aTlvList, - const RxChallenge &aChallenge); - void SendMulticastDataResponse(void); - void SendDataResponse(const Ip6::Address &aDestination, - const TlvList &aTlvList, - const Message *aRequestMessage = nullptr); - Error SendDiscoveryResponse(const Ip6::Address &aDestination, const DiscoveryResponseInfo &aInfo); - void SetStateRouter(uint16_t aRloc16); - void SetStateLeader(uint16_t aRloc16, LeaderStartMode aStartMode); - void SetStateRouterOrLeader(DeviceRole aRole, uint16_t aRloc16, LeaderStartMode aStartMode); - void StopLeader(void); - void SynchronizeChildNetworkData(void); - Error ProcessAddressRegistrationTlv(RxInfo &aRxInfo, Child &aChild); - bool HasNeighborWithGoodLinkQuality(void) const; - void HandlePartitionChange(void); - void SetChildStateToValid(Child &aChild); - bool HasChildren(void); - void RemoveChildren(void); - bool ShouldDowngrade(uint8_t aNeighborId, const RouteTlv &aRouteTlv) const; - bool NeighborHasComparableConnectivity(const RouteTlv &aRouteTlv, uint8_t aNeighborId) const; - void HandleAdvertiseTrickleTimer(void); - void HandleAddressSolicitResponse(Coap::Message *aMessage, const Ip6::MessageInfo *aMessageInfo, Error aResult); - void HandleTimeTick(void); - - template void HandleTmf(Coap::Message &aMessage, const Ip6::MessageInfo &aMessageInfo); - -#if OPENTHREAD_CONFIG_TMF_PROXY_DUA_ENABLE - void SignalDuaAddressEvent(const Child &aChild, const Ip6::Address &aOldDua) const; -#endif - - static bool IsMessageMleSubType(const Message &aMessage); - static bool IsMessageChildUpdateRequest(const Message &aMessage); - static void HandleAdvertiseTrickleTimer(TrickleTimer &aTimer); - static void HandleAddressSolicitResponse(void *aContext, - otMessage *aMessage, - const otMessageInfo *aMessageInfo, - otError aResult); - - //------------------------------------------------------------------------------------------------------------------ - // Variables - - bool mRouterEligible : 1; - bool mAddressSolicitPending : 1; - bool mAddressSolicitRejected : 1; -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - bool mCcmEnabled : 1; - bool mThreadVersionCheckEnabled : 1; -#endif - - uint8_t mRouterId; - uint8_t mPreviousRouterId; - uint8_t mNetworkIdTimeout; - uint8_t mRouterUpgradeThreshold; - uint8_t mRouterDowngradeThreshold; - uint8_t mLeaderWeight; - uint8_t mPreviousPartitionRouterIdSequence; - uint8_t mPreviousPartitionIdTimeout; - uint8_t mChildRouterLinks; - uint8_t mAlternateRloc16Timeout; -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - uint8_t mMaxChildIpAddresses; -#endif - int8_t mParentPriority; - uint16_t mNextChildId; - uint32_t mPreviousPartitionIdRouter; - uint32_t mPreviousPartitionId; -#if OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE - uint32_t mPreferredLeaderPartitionId; -#endif - - TrickleTimer mAdvertiseTrickleTimer; - ChildTable mChildTable; - RouterTable mRouterTable; - RouterRoleRestorer mRouterRoleRestorer; - RouterRoleTransition mRouterRoleTransition; - Ip6::Netif::UnicastAddress mLeaderAloc; -#if OPENTHREAD_CONFIG_MLE_DEVICE_PROPERTY_LEADER_WEIGHT_ENABLE - DeviceProperties mDeviceProperties; -#endif -#if OPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE - MeshCoP::SteeringData mSteeringData; -#endif - Callback mDiscoveryRequestCallback; -}; - -DeclareTmfHandler(MleRouter, kUriAddressSolicit); -DeclareTmfHandler(MleRouter, kUriAddressRelease); - -#endif // OPENTHREAD_FTD - -#if OPENTHREAD_MTD - -typedef Mle MleRouter; - -#endif - -} // namespace Mle - -/** - * @} - */ - -} // namespace ot - -#endif // MLE_ROUTER_HPP_ diff --git a/src/core/thread/mlr_manager.cpp b/src/core/thread/mlr_manager.cpp index 5027d3711..b3e9f309b 100644 --- a/src/core/thread/mlr_manager.cpp +++ b/src/core/thread/mlr_manager.cpp @@ -61,7 +61,7 @@ void MlrManager::HandleNotifierEvents(Events aEvents) } #endif - if (aEvents.Contains(kEventThreadRoleChanged) && Get().IsChild()) + if (aEvents.Contains(kEventThreadRoleChanged) && Get().IsChild()) { // Reregistration after re-attach UpdateReregistrationDelay(true); @@ -211,9 +211,9 @@ void MlrManager::UpdateTimeTickerRegistration(void) void MlrManager::SendMlr(void) { - Error error; - Mle::MleRouter &mle = Get(); - AddressArray addresses; + Error error; + Mle::Mle &mle = Get(); + AddressArray addresses; VerifyOrExit(!mMlrPending, error = kErrorBusy); VerifyOrExit(mle.IsAttached(), error = kErrorInvalidState); @@ -370,7 +370,7 @@ Error MlrManager::SendMlrMessage(const Ip6::Address *aAddresses, OT_UNUSED_VARIABLE(aTimeout); Error error = kErrorNone; - Mle::MleRouter &mle = Get(); + Mle::Mle &mle = Get(); Coap::Message *message = nullptr; Tmf::MessageInfo messageInfo(GetInstance()); Ip6AddressesTlv addressesTlv; @@ -607,7 +607,7 @@ void MlrManager::Reregister(void) void MlrManager::UpdateReregistrationDelay(bool aRereg) { - Mle::MleRouter &mle = Get(); + Mle::Mle &mle = Get(); bool needSendMlr = (mle.IsFullThreadDevice() || mle.GetParent().IsThreadVersion1p1()) && Get().HasPrimary(); diff --git a/src/core/thread/network_data.hpp b/src/core/thread/network_data.hpp index a507fa5f1..fd1c2988d 100644 --- a/src/core/thread/network_data.hpp +++ b/src/core/thread/network_data.hpp @@ -48,7 +48,7 @@ #include "common/timer.hpp" #include "net/udp6.hpp" #include "thread/lowpan.hpp" -#include "thread/mle_router.hpp" +#include "thread/mle.hpp" #include "thread/network_data_tlvs.hpp" #include "thread/network_data_types.hpp" diff --git a/src/core/thread/network_data_leader.cpp b/src/core/thread/network_data_leader.cpp index 9813ac6d1..82ca120e5 100644 --- a/src/core/thread/network_data_leader.cpp +++ b/src/core/thread/network_data_leader.cpp @@ -164,7 +164,7 @@ Error Leader::GetContext(const Ip6::Address &aAddress, Lowpan::Context &aContext aContext.mPrefix.SetLength(0); - if (Get().IsMeshLocalAddress(aAddress)) + if (Get().IsMeshLocalAddress(aAddress)) { GetContextForMeshLocalPrefix(aContext); } @@ -236,7 +236,7 @@ exit: void Leader::GetContextForMeshLocalPrefix(Lowpan::Context &aContext) const { - aContext.mPrefix.Set(Get().GetMeshLocalPrefix()); + aContext.mPrefix.Set(Get().GetMeshLocalPrefix()); aContext.mContextId = Mle::kMeshLocalPrefixContextId; aContext.mCompressFlag = true; aContext.mIsValid = true; @@ -247,7 +247,7 @@ bool Leader::IsOnMesh(const Ip6::Address &aAddress) const const PrefixTlv *prefixTlv = nullptr; bool isOnMesh = false; - VerifyOrExit(!Get().IsMeshLocalAddress(aAddress), isOnMesh = true); + VerifyOrExit(!Get().IsMeshLocalAddress(aAddress), isOnMesh = true); while ((prefixTlv = FindNextMatchingPrefixTlv(aAddress, prefixTlv)) != nullptr) { @@ -484,7 +484,7 @@ Error Leader::SetNetworkData(uint8_t aVersion, } #if OPENTHREAD_FTD - if (Get().IsLeader()) + if (Get().IsLeader()) { Get().HandleNetworkDataRestoredAfterReset(); } diff --git a/src/core/thread/network_data_leader.hpp b/src/core/thread/network_data_leader.hpp index b73e76edd..7bfde4f86 100644 --- a/src/core/thread/network_data_leader.hpp +++ b/src/core/thread/network_data_leader.hpp @@ -44,7 +44,7 @@ #include "common/numeric_limits.hpp" #include "common/timer.hpp" #include "net/ip6_address.hpp" -#include "thread/mle_router.hpp" +#include "thread/mle.hpp" #include "thread/network_data.hpp" #include "thread/tmf.hpp" diff --git a/src/core/thread/network_data_leader_ftd.cpp b/src/core/thread/network_data_leader_ftd.cpp index f3419472e..8ec6031f1 100644 --- a/src/core/thread/network_data_leader_ftd.cpp +++ b/src/core/thread/network_data_leader_ftd.cpp @@ -58,7 +58,7 @@ void Leader::Start(Mle::LeaderStartMode aStartMode) void Leader::IncrementVersion(void) { - if (Get().IsLeader()) + if (Get().IsLeader()) { IncrementVersions(/* aIncludeStable */ false); } @@ -66,7 +66,7 @@ void Leader::IncrementVersion(void) void Leader::IncrementVersionAndStableVersion(void) { - if (Get().IsLeader()) + if (Get().IsLeader()) { IncrementVersions(/* aIncludeStable */ true); } @@ -293,7 +293,7 @@ template <> void Leader::HandleTmf(Coap::Message &aMessage, state = MeshCoP::StateTlv::kAccept; exit: - if (Get().IsLeader()) + if (Get().IsLeader()) { SendCommissioningSetResponse(aMessage, aMessageInfo, state); } @@ -664,7 +664,7 @@ void Leader::CheckForNetDataGettingFull(const NetworkData &aNetworkData, uint16_ // device. If provided, then entries matching old RLOC16 are first // removed, before checking if new entries from @p aNetworkData can fit. - if (!Get().IsLeader()) + if (!Get().IsLeader()) { // Create a clone of the leader's network data, and try to register // `aNetworkData` into the copy (as if this device itself is the @@ -1415,7 +1415,7 @@ void Leader::HandleTimer(void) if (mWaitingForNetDataSync) { LogInfo("Timed out waiting for netdata on restoring leader role after reset"); - IgnoreError(Get().BecomeDetached()); + IgnoreError(Get().BecomeDetached()); } else { diff --git a/src/core/thread/network_data_local.cpp b/src/core/thread/network_data_local.cpp index 9520d6b63..d90bbdf9f 100644 --- a/src/core/thread/network_data_local.cpp +++ b/src/core/thread/network_data_local.cpp @@ -152,7 +152,7 @@ exit: void Local::UpdateRloc(PrefixTlv &aPrefixTlv) { - uint16_t rloc16 = Get().GetRloc16(); + uint16_t rloc16 = Get().GetRloc16(); for (NetworkDataTlv *cur = aPrefixTlv.GetSubTlvs(); cur < aPrefixTlv.GetNext(); cur = cur->GetNext()) { @@ -197,7 +197,7 @@ Error Local::AddService(uint32_t aEnterpriseNumber, serviceTlv->SetSubTlvsLength(sizeof(ServerTlv) + aServerData.GetLength()); serverTlv = As(serviceTlv->GetSubTlvs()); - serverTlv->Init(Get().GetRloc16(), aServerData); + serverTlv->Init(Get().GetRloc16(), aServerData); // According to Thread spec 1.1.1, section 5.18.6 Service TLV: // "The Stable flag is set if any of the included sub-TLVs have their Stable flag set." @@ -237,7 +237,7 @@ exit: void Local::UpdateRloc(ServiceTlv &aService) { - uint16_t rloc16 = Get().GetRloc16(); + uint16_t rloc16 = Get().GetRloc16(); for (NetworkDataTlv *cur = aService.GetSubTlvs(); cur < aService.GetNext(); cur = cur->GetNext()) { diff --git a/src/core/thread/network_data_notifier.cpp b/src/core/thread/network_data_notifier.cpp index f7bf8afef..99c389950 100644 --- a/src/core/thread/network_data_notifier.cpp +++ b/src/core/thread/network_data_notifier.cpp @@ -74,7 +74,7 @@ void Notifier::SynchronizeServerData(void) { Error error = kErrorNotFound; - VerifyOrExit(Get().IsAttached() && !mWaitingForResponse); + VerifyOrExit(Get().IsAttached() && !mWaitingForResponse); VerifyOrExit((mNextDelay == 0) || !mTimer.IsRunning()); @@ -101,7 +101,7 @@ exit: break; #if OPENTHREAD_FTD case kErrorInvalidState: - mTimer.Start(Time::SecToMsec(Get().GetRouterRoleTransitionTimeout() + 1)); + mTimer.Start(Time::SecToMsec(Get().GetRouterRoleTransitionTimeout() + 1)); break; #endif case kErrorNotFound: @@ -125,7 +125,7 @@ Error Notifier::RemoveStaleChildEntries(void) Error error = kErrorNotFound; Rlocs rlocs; - VerifyOrExit(Get().IsRouterOrLeader()); + VerifyOrExit(Get().IsRouterOrLeader()); Get().FindRlocs(kAnyBrOrServer, kAnyRole, rlocs); @@ -148,13 +148,13 @@ exit: Error Notifier::UpdateInconsistentData(void) { Error error = kErrorNone; - uint16_t deviceRloc = Get().GetRloc16(); + uint16_t deviceRloc = Get().GetRloc16(); #if OPENTHREAD_FTD // Don't send this Server Data Notification if the device is going // to upgrade to Router. - if (Get().IsExpectedToBecomeRouterSoon()) + if (Get().IsExpectedToBecomeRouterSoon()) { ExitNow(error = kErrorInvalidState); } @@ -294,12 +294,12 @@ bool Notifier::IsEligibleForRouterRoleUpgradeAsBorderRouter(void) const uint16_t rloc16 = Get().GetRloc16(); uint8_t activeRouterCount; - VerifyOrExit(Get().IsRouterEligible()); + VerifyOrExit(Get().IsRouterEligible()); // RouterUpgradeThreshold can be explicitly set to zero in some of // cert tests to disallow device to become router. - VerifyOrExit(Get().GetRouterUpgradeThreshold() != 0); + VerifyOrExit(Get().GetRouterUpgradeThreshold() != 0); // Check that we are a border router providing IP connectivity and already // in the leader's network data and therefore eligible to request router @@ -309,7 +309,7 @@ bool Notifier::IsEligibleForRouterRoleUpgradeAsBorderRouter(void) const Get().ContainsBorderRouterWithRloc(rloc16)); activeRouterCount = Get().GetActiveRouterCount(); - VerifyOrExit((activeRouterCount >= Get().GetRouterUpgradeThreshold()) && + VerifyOrExit((activeRouterCount >= Get().GetRouterUpgradeThreshold()) && (activeRouterCount < Mle::kMaxRouters)); VerifyOrExit(Get().CountBorderRouters(kRouterRoleOnly) < Mle::kRouterUpgradeBorderRouterRequestThreshold); @@ -333,7 +333,7 @@ void Notifier::ScheduleRouterRoleUpgradeIfEligible(void) VerifyOrExit(!mDidRequestRouterRoleUpgrade); - VerifyOrExit(Get().IsChild()); + VerifyOrExit(Get().IsChild()); VerifyOrExit(IsEligibleForRouterRoleUpgradeAsBorderRouter() && (mRouterRoleUpgradeTimeout == 0)); mRouterRoleUpgradeTimeout = Random::NonCrypto::GetUint8InRange(1, kRouterRoleUpgradeMaxTimeout + 1); @@ -357,11 +357,11 @@ void Notifier::HandleTimeTick(void) // upgrade (note that state can change since the last time we // checked and registered to receive time ticks). - if (Get().IsChild() && IsEligibleForRouterRoleUpgradeAsBorderRouter()) + if (Get().IsChild() && IsEligibleForRouterRoleUpgradeAsBorderRouter()) { LogInfo("Requesting router role as BR"); mDidRequestRouterRoleUpgrade = true; - IgnoreError(Get().BecomeRouter(ThreadStatusTlv::kBorderRouterRequest)); + IgnoreError(Get().BecomeRouter(ThreadStatusTlv::kBorderRouterRequest)); } } exit: diff --git a/src/core/thread/network_data_service.cpp b/src/core/thread/network_data_service.cpp index dc706ceab..ead0b05b7 100644 --- a/src/core/thread/network_data_service.cpp +++ b/src/core/thread/network_data_service.cpp @@ -143,7 +143,7 @@ bool Manager::IsBackboneRouterPreferredTo(const ServerTlv &aServerTlv, const BbrServerData &aOtherServerData) const { bool isPreferred; - uint16_t leaderRloc16 = Get().GetLeaderRloc16(); + uint16_t leaderRloc16 = Get().GetLeaderRloc16(); VerifyOrExit(aServerTlv.GetServer16() != leaderRloc16, isPreferred = true); VerifyOrExit(aOtherServerTlv.GetServer16() != leaderRloc16, isPreferred = false); diff --git a/src/core/thread/network_data_types.cpp b/src/core/thread/network_data_types.cpp index 0799db1d3..b1176b0a0 100644 --- a/src/core/thread/network_data_types.cpp +++ b/src/core/thread/network_data_types.cpp @@ -206,7 +206,7 @@ void ExternalRouteConfig::SetFrom(Instance &aInstance, SetFromTlvFlags(aHasRouteEntry.GetFlags()); mStable = aHasRouteTlv.IsStable(); mRloc16 = aHasRouteEntry.GetRloc(); - mNextHopIsThisDevice = (aHasRouteEntry.GetRloc() == aInstance.Get().GetRloc16()); + mNextHopIsThisDevice = (aHasRouteEntry.GetRloc() == aInstance.Get().GetRloc16()); } void ExternalRouteConfig::SetFromTlvFlags(uint8_t aFlags) diff --git a/src/core/thread/network_diagnostic.cpp b/src/core/thread/network_diagnostic.cpp index 93c136add..dcd291371 100644 --- a/src/core/thread/network_diagnostic.cpp +++ b/src/core/thread/network_diagnostic.cpp @@ -99,7 +99,7 @@ void Server::PrepareMessageInfoForDest(const Ip6::Address &aDestination, Tmf::Me if (aDestination.IsLinkLocalUnicastOrMulticast()) { - aMessageInfo.SetSockAddr(Get().GetLinkLocalAddress()); + aMessageInfo.SetSockAddr(Get().GetLinkLocalAddress()); } else { @@ -152,7 +152,7 @@ Error Server::AppendChildTable(Message &aMessage) Error error = kErrorNone; uint16_t count; - VerifyOrExit(Get().IsRouterOrLeader()); + VerifyOrExit(Get().IsRouterOrLeader()); count = Min(Get().GetNumChildren(Child::kInStateValid), kMaxChildEntries); @@ -400,11 +400,11 @@ Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage) break; case Tlv::kAddress16: - error = Tlv::Append(aMessage, Get().GetRloc16()); + error = Tlv::Append(aMessage, Get().GetRloc16()); break; case Tlv::kMode: - error = Tlv::Append(aMessage, Get().GetDeviceMode().Get()); + error = Tlv::Append(aMessage, Get().GetDeviceMode().Get()); break; case Tlv::kEui64: @@ -421,8 +421,8 @@ Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage) break; case Tlv::kTimeout: - VerifyOrExit(!Get().IsRxOnWhenIdle()); - error = Tlv::Append(aMessage, Get().GetTimeout()); + VerifyOrExit(!Get().IsRxOnWhenIdle()); + error = Tlv::Append(aMessage, Get().GetTimeout()); break; case Tlv::kLeaderData: @@ -430,7 +430,7 @@ Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage) LeaderDataTlv tlv; tlv.Init(); - tlv.Set(Get().GetLeaderData()); + tlv.Set(Get().GetLeaderData()); error = tlv.AppendTo(aMessage); break; } @@ -511,7 +511,7 @@ Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage) ConnectivityTlv tlv; tlv.Init(); - Get().FillConnectivityTlv(tlv); + Get().FillConnectivityTlv(tlv); error = tlv.AppendTo(aMessage); break; } @@ -538,7 +538,7 @@ Error Server::AppendDiagTlv(uint8_t aTlvType, Message &aMessage) { uint32_t maxTimeout; - SuccessOrExit(Get().GetMaxChildTimeout(maxTimeout)); + SuccessOrExit(Get().GetMaxChildTimeout(maxTimeout)); error = Tlv::Append(aMessage, maxTimeout); break; } diff --git a/src/core/thread/router_table.cpp b/src/core/thread/router_table.cpp index ce0246371..1f125e115 100644 --- a/src/core/thread/router_table.cpp +++ b/src/core/thread/router_table.cpp @@ -175,7 +175,7 @@ Router *RouterTable::Allocate(uint8_t aRouterId) mRouterIdSequence++; mRouterIdSequenceLastUpdated = TimerMilli::GetNow(); - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); LogNote("Allocate router id %d", aRouterId); @@ -190,7 +190,7 @@ Error RouterTable::Release(uint8_t aRouterId) OT_ASSERT(aRouterId <= Mle::kMaxRouterId); - VerifyOrExit(Get().IsLeader(), error = kErrorInvalidState); + VerifyOrExit(Get().IsLeader(), error = kErrorInvalidState); router = FindRouterById(aRouterId); VerifyOrExit(router != nullptr, error = kErrorNotFound); @@ -211,7 +211,7 @@ Error RouterTable::Release(uint8_t aRouterId) Get().RemoveEntriesForRouterId(aRouterId); Get().RemoveBorderRouter(Mle::Rloc16FromRouterId(aRouterId), NetworkData::Leader::kMatchModeRouterId); - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); LogNote("Release router id %d", aRouterId); @@ -237,14 +237,14 @@ void RouterTable::RemoveRouterLink(Router &aRouter) if (GetLinkCost(router) >= Mle::kMaxRouteCost) { - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); } } } if (aRouter.GetNextHop() == Mle::kInvalidRouterId) { - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); // Clear all EID-to-RLOC entries associated with the router. Get().RemoveEntriesForRouterId(aRouter.GetRouterId()); @@ -328,7 +328,7 @@ exit: return error; } -const Router *RouterTable::GetLeader(void) const { return FindRouterById(Get().GetLeaderId()); } +const Router *RouterTable::GetLeader(void) const { return FindRouterById(Get().GetLeaderId()); } uint32_t RouterTable::GetLeaderAge(void) const { @@ -411,7 +411,7 @@ void RouterTable::GetNextHopAndPathCost(uint16_t aDestRloc16, uint16_t &aNextHop router = FindRouterById(Mle::RouterIdFromRloc16(aDestRloc16)); nextHop = (router != nullptr) ? FindNextHopOf(*router) : nullptr; - if (Get().IsChild()) + if (Get().IsChild()) { const Router &parent = Get().GetParent(); bool destIsParentOrItsChild; @@ -544,7 +544,7 @@ void RouterTable::UpdateRouterIdSet(uint8_t aRouterIdSequence, const Mle::Router } } - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); exit: return; @@ -613,7 +613,7 @@ void RouterTable::UpdateRoutes(const Mle::RouteTlv &aRouteTlv, uint8_t aNeighbor if (neighbor->IsStateValid() && (aRouteTlv.GetLinkQualityOut(index) == kLinkQuality0) && (neighbor->GetTwoWayLinkQuality() >= kLinkQuality2)) { - Get().ScheduleUnicastAdvertisementTo(*neighbor); + Get().ScheduleUnicastAdvertisementTo(*neighbor); } } @@ -684,7 +684,7 @@ void RouterTable::UpdateRoutes(const Mle::RouteTlv &aRouteTlv, uint8_t aNeighbor if (newCostFinite != oldCostFinite) { - Get().ResetAdvertiseInterval(); + Get().ResetAdvertiseInterval(); break; } } @@ -817,7 +817,7 @@ void RouterTable::HandleTimeTick(void) { mRouterIdMap.HandleTimeTick(); - VerifyOrExit(Get().IsLeader()); + VerifyOrExit(Get().IsLeader()); // Update router id sequence if (GetLeaderAge() >= kRouterIdSequencePeriod) @@ -890,7 +890,7 @@ void RouterTable::HandleTableChanged(void) Get().RecordRouterTableChange(); #endif - Get().UpdateAdvertiseInterval(); + Get().UpdateAdvertiseInterval(); } #if OT_SHOULD_LOG_AT(OT_LOG_LEVEL_INFO) diff --git a/src/core/thread/thread_netif.cpp b/src/core/thread/thread_netif.cpp index 98047e2e9..11bf357ef 100644 --- a/src/core/thread/thread_netif.cpp +++ b/src/core/thread/thread_netif.cpp @@ -57,7 +57,7 @@ void ThreadNetif::Up(void) mIsUp = true; SubscribeAllNodesMulticast(); - IgnoreError(Get().Enable()); + IgnoreError(Get().Enable()); IgnoreError(Get().Start()); #if OPENTHREAD_CONFIG_DNSSD_SERVER_ENABLE IgnoreError(Get().Start()); @@ -88,7 +88,7 @@ void ThreadNetif::Down(void) Get().Stop(); #endif IgnoreError(Get().Stop()); - IgnoreError(Get().Disable()); + IgnoreError(Get().Disable()); RemoveAllExternalUnicastAddresses(); UnsubscribeAllExternalMulticastAddresses(); UnsubscribeAllRoutersMulticast(); diff --git a/src/core/thread/thread_tlvs.hpp b/src/core/thread/thread_tlvs.hpp index 7161f2d35..c41d6db6d 100644 --- a/src/core/thread/thread_tlvs.hpp +++ b/src/core/thread/thread_tlvs.hpp @@ -41,7 +41,6 @@ #include "common/tlvs.hpp" #include "meshcop/network_name.hpp" #include "net/ip6_address.hpp" -#include "thread/mle.hpp" #include "thread/mle_types.hpp" namespace ot { diff --git a/src/core/thread/time_sync_service.cpp b/src/core/thread/time_sync_service.cpp index 8b2f4d2ad..5add0ce4f 100644 --- a/src/core/thread/time_sync_service.cpp +++ b/src/core/thread/time_sync_service.cpp @@ -86,7 +86,7 @@ void TimeSync::HandleTimeSyncMessage(const Message &aMessage) LogInfo("Older time sync seq received:%u. Forwarding current seq:%u", aMessage.GetTimeSyncSeq(), mTimeSyncSeq); } - else if (Get().IsLeader() && timeSyncSeqDelta > 0) + else if (Get().IsLeader() && timeSyncSeqDelta > 0) { // Another device is forwarding a later time sync sequence, perhaps because it merged from a different // partition. The leader is authoritative, so ensure all devices synchronize to the time being seeded by this @@ -97,13 +97,13 @@ void TimeSync::HandleTimeSyncMessage(const Message &aMessage) LogInfo("Newer time sync seq:%u received by leader. Setting current seq to:%u and forwarding", aMessage.GetTimeSyncSeq(), mTimeSyncSeq); } - else if (!Get().IsLeader()) + else if (!Get().IsLeader()) { // For all devices aside from the leader, update network time in following three cases: // 1. During first attach. // 2. Already attached, and a newer time sync sequence was received. // 3. During reattach or migration process. - if (mTimeSyncSeq == OT_TIME_SYNC_INVALID_SEQ || timeSyncSeqDelta > 0 || Get().IsDetached()) + if (mTimeSyncSeq == OT_TIME_SYNC_INVALID_SEQ || timeSyncSeqDelta > 0 || Get().IsDetached()) { // Update network time and forward it. mLastTimeSyncReceived = TimerMilli::GetNow(); @@ -137,8 +137,7 @@ void TimeSync::NotifyTimeSyncCallback(void) { mTimeSyncCallback.InvokeIfSet(); } #if OPENTHREAD_FTD void TimeSync::ProcessTimeSync(void) { - if (Get().IsLeader() && - (TimerMilli::GetNow() - mLastTimeSyncSent > Time::SecToMsec(mTimeSyncPeriod))) + if (Get().IsLeader() && (TimerMilli::GetNow() - mLastTimeSyncSent > Time::SecToMsec(mTimeSyncPeriod))) { IncrementTimeSyncSeq(); mTimeSyncRequired = true; @@ -148,7 +147,7 @@ void TimeSync::ProcessTimeSync(void) if (mTimeSyncRequired) { - VerifyOrExit(Get().SendTimeSync() == kErrorNone); + VerifyOrExit(Get().SendTimeSync() == kErrorNone); mLastTimeSyncSent = TimerMilli::GetNow(); mTimeSyncRequired = false; @@ -168,7 +167,7 @@ void TimeSync::HandleNotifierEvents(Events aEvents) stateChanged = true; } - if (aEvents.Contains(kEventThreadPartitionIdChanged) && !Get().IsLeader()) + if (aEvents.Contains(kEventThreadPartitionIdChanged) && !Get().IsLeader()) { // Partition has changed. Accept any network time currently being seeded on the new partition // and don't attempt to forward the currently held network time from the previous partition. @@ -200,7 +199,7 @@ void TimeSync::CheckAndHandleChanges(bool aTimeUpdated) mTimer.Stop(); - switch (Get().GetRole()) + switch (Get().GetRole()) { case Mle::kRoleDisabled: case Mle::kRoleDetached: diff --git a/src/core/thread/tmf.cpp b/src/core/thread/tmf.cpp index 37b7f763c..9d18cf27d 100644 --- a/src/core/thread/tmf.cpp +++ b/src/core/thread/tmf.cpp @@ -41,18 +41,18 @@ namespace Tmf { //---------------------------------------------------------------------------------------------------------------------- // MessageInfo -void MessageInfo::SetSockAddrToRloc(void) { SetSockAddr(Get().GetMeshLocalRloc()); } +void MessageInfo::SetSockAddrToRloc(void) { SetSockAddr(Get().GetMeshLocalRloc()); } void MessageInfo::SetSockAddrToRlocPeerAddrToLeaderAloc(void) { SetSockAddrToRloc(); - Get().GetLeaderAloc(GetPeerAddr()); + Get().GetLeaderAloc(GetPeerAddr()); } void MessageInfo::SetSockAddrToRlocPeerAddrToLeaderRloc(void) { SetSockAddrToRloc(); - Get().GetLeaderRloc(GetPeerAddr()); + Get().GetLeaderRloc(GetPeerAddr()); } void MessageInfo::SetSockAddrToRlocPeerAddrToRealmLocalAllRoutersMulticast(void) @@ -127,8 +127,8 @@ bool Agent::HandleResource(const char *aUriPath, Message &aMessage, const Ip6::M #if OPENTHREAD_FTD Case(kUriAddressQuery, AddressResolver); Case(kUriAddressNotify, AddressResolver); - Case(kUriAddressSolicit, Mle::MleRouter); - Case(kUriAddressRelease, Mle::MleRouter); + Case(kUriAddressSolicit, Mle::Mle); + Case(kUriAddressRelease, Mle::Mle); Case(kUriActiveSet, MeshCoP::ActiveDatasetManager); Case(kUriActiveReplace, MeshCoP::ActiveDatasetManager); Case(kUriPendingSet, MeshCoP::PendingDatasetManager); diff --git a/src/core/utils/jam_detector.cpp b/src/core/utils/jam_detector.cpp index 8c317cc2c..c77dd091a 100644 --- a/src/core/utils/jam_detector.cpp +++ b/src/core/utils/jam_detector.cpp @@ -96,7 +96,7 @@ void JamDetector::CheckState(void) { VerifyOrExit(mEnabled); - switch (Get().GetRole()) + switch (Get().GetRole()) { case Mle::kRoleDisabled: VerifyOrExit(mTimer.IsRunning()); diff --git a/tests/nexus/platform/nexus_node.cpp b/tests/nexus/platform/nexus_node.cpp index 23e4e37df..14d819bd9 100644 --- a/tests/nexus/platform/nexus_node.cpp +++ b/tests/nexus/platform/nexus_node.cpp @@ -40,7 +40,7 @@ void Node::Form(void) Get().SaveLocal(datasetInfo); Get().Up(); - SuccessOrQuit(Get().Start()); + SuccessOrQuit(Get().Start()); } void Node::Join(Node &aNode, JoinMode aJoinMode) @@ -51,7 +51,7 @@ void Node::Join(Node &aNode, JoinMode aJoinMode) switch (aJoinMode) { case kAsFed: - SuccessOrQuit(Get().SetRouterEligible(false)); + SuccessOrQuit(Get().SetRouterEligible(false)); OT_FALL_THROUGH; case kAsFtd: @@ -72,7 +72,7 @@ void Node::Join(Node &aNode, JoinMode aJoinMode) Get().SaveLocal(dataset); Get().Up(); - SuccessOrQuit(Get().Start()); + SuccessOrQuit(Get().Start()); } void Node::AllowList(Node &aNode) diff --git a/tests/nexus/test_border_agent.cpp b/tests/nexus/test_border_agent.cpp index 587395926..d7d09e512 100644 --- a/tests/nexus/test_border_agent.cpp +++ b/tests/nexus/test_border_agent.cpp @@ -866,7 +866,7 @@ void TestBorderAgentMeshCoPServiceChangedCallback(void) VerifyOrQuit(meshCoPServiceTester.FindTxtEntry("sb", txtEntry)); VerifyOrQuit(meshCoPServiceTester.FindTxtEntry("pt", txtEntry)); VerifyOrQuit(CheckObjectSameAsTxtEntryData( - txtEntry, BigEndian::HostSwap32(node0.Get().GetLeaderData().GetPartitionId()))); + txtEntry, BigEndian::HostSwap32(node0.Get().GetLeaderData().GetPartitionId()))); VerifyOrQuit(meshCoPServiceTester.FindTxtEntry("at", txtEntry)); VerifyOrQuit(CheckObjectSameAsTxtEntryData(txtEntry, node0.Get().GetTimestamp())); diff --git a/tests/nexus/test_dtls.cpp b/tests/nexus/test_dtls.cpp index 6f52b0b7f..c9d85450f 100644 --- a/tests/nexus/test_dtls.cpp +++ b/tests/nexus/test_dtls.cpp @@ -247,12 +247,12 @@ void TestDtlsSingleSession(void) nexus.AdvanceTime(50 * Time::kOneSecondInMsec); VerifyOrQuit(node0.Get().IsLeader()); - SuccessOrQuit(node1.Get().SetRouterEligible(false)); + SuccessOrQuit(node1.Get().SetRouterEligible(false)); node1.Join(node0); nexus.AdvanceTime(20 * Time::kOneSecondInMsec); VerifyOrQuit(node1.Get().IsChild()); - SuccessOrQuit(node2.Get().SetRouterEligible(false)); + SuccessOrQuit(node2.Get().SetRouterEligible(false)); node2.Join(node0); nexus.AdvanceTime(20 * Time::kOneSecondInMsec); VerifyOrQuit(node2.Get().IsChild()); @@ -489,12 +489,12 @@ void TestDtlsMultiSession(void) nexus.AdvanceTime(50 * Time::kOneSecondInMsec); VerifyOrQuit(node0.Get().IsLeader()); - SuccessOrQuit(node1.Get().SetRouterEligible(false)); + SuccessOrQuit(node1.Get().SetRouterEligible(false)); node1.Join(node0); nexus.AdvanceTime(20 * Time::kOneSecondInMsec); VerifyOrQuit(node1.Get().IsChild()); - SuccessOrQuit(node2.Get().SetRouterEligible(false)); + SuccessOrQuit(node2.Get().SetRouterEligible(false)); node2.Join(node0); nexus.AdvanceTime(20 * Time::kOneSecondInMsec); VerifyOrQuit(node2.Get().IsChild()); diff --git a/tests/unit/test_child.cpp b/tests/unit/test_child.cpp index 560fc9a9f..d7263cf30 100644 --- a/tests/unit/test_child.cpp +++ b/tests/unit/test_child.cpp @@ -78,7 +78,7 @@ void VerifyChildIp6Addresses(const Child &aChild, uint8_t aAddressListLength, co { Ip6::Address address; - if (sInstance->Get().IsMeshLocalAddress(aAddressList[index])) + if (sInstance->Get().IsMeshLocalAddress(aAddressList[index])) { SuccessOrQuit(aChild.GetMeshLocalIp6Address(address)); VerifyOrQuit(address == aAddressList[index], "GetMeshLocalIp6Address() did not return expected address"); @@ -127,7 +127,7 @@ void TestChildIp6Address(void) numAddresses = 0; // First addresses uses the mesh local prefix (mesh-local address). - addresses[numAddresses] = sInstance->Get().GetMeshLocalEid(); + addresses[numAddresses] = sInstance->Get().GetMeshLocalEid(); addresses[numAddresses].SetIid(meshLocalIid); numAddresses++; diff --git a/tests/unit/test_lowpan.cpp b/tests/unit/test_lowpan.cpp index 992a21407..22e1e1139 100644 --- a/tests/unit/test_lowpan.cpp +++ b/tests/unit/test_lowpan.cpp @@ -104,7 +104,7 @@ static void Init(void) otMeshLocalPrefix meshLocalPrefix = {{0xfd, 0x00, 0xca, 0xfe, 0xfa, 0xce, 0x12, 0x34}}; OffsetRange offsetRange; - sInstance->Get().SetMeshLocalPrefix(static_cast(meshLocalPrefix)); + sInstance->Get().SetMeshLocalPrefix(static_cast(meshLocalPrefix)); // Emulate global prefixes with contextes. uint8_t mockNetworkData[] = {