diff --git a/include/openthread/instance.h b/include/openthread/instance.h index 2d245f91c..e53305d93 100644 --- a/include/openthread/instance.h +++ b/include/openthread/instance.h @@ -52,7 +52,7 @@ extern "C" { * * @note This number versions both OpenThread platform and user APIs. */ -#define OPENTHREAD_API_VERSION (482) +#define OPENTHREAD_API_VERSION (483) /** * @addtogroup api-instance diff --git a/include/openthread/srp_server.h b/include/openthread/srp_server.h index 55b257666..f97d7d31c 100644 --- a/include/openthread/srp_server.h +++ b/include/openthread/srp_server.h @@ -301,8 +301,12 @@ bool otSrpServerIsAutoEnableMode(otInstance *aInstance); * The Fast Start Mode can be enabled when the device is in the detached or disabled state, the SRP server is currently * disabled, and "auto-enable mode" is not in use (i.e., `otSrpServerIsAutoEnableMode()` returns `false`). * - * After successfully enabling Fast Start Mode, it can be disabled by a direct call to `otSrpServerSetEnabled()`, - * explicitly enabling or disabling the SRP server function. + * After successfully enabling Fast Start Mode, it can be disabled either by a call to `otSrpServerSetEnabled()`, + * explicitly enabling or disabling the SRP server, or by a call to `otSrpServerSetAutoEnableMode()`, enabling or + * disabling the auto-enable mode. If the Fast Start Mode (while active) enables the SRP server, upon disabling + * Fast Start Mode (regardless of how it is done), the SRP server will also be stopped, and the use of the + * `OT_SRP_SERVER_ADDRESS_MODE_UNICAST_FORCE_ADD` address mode will be stopped, and the address mode will be + * automatically reverted back to its previous setting before Fast Start Mode was enabled. * * @param[in] aInstance A pointer to the OpenThread instance. * diff --git a/src/core/net/srp_server.cpp b/src/core/net/srp_server.cpp index 141854170..bb090043f 100644 --- a/src/core/net/srp_server.cpp +++ b/src/core/net/srp_server.cpp @@ -128,7 +128,7 @@ void Server::SetEnabled(bool aEnabled) mAutoEnable = false; #endif #if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE - mFastStartMode = false; + DisableFastStartMode(); #endif if (aEnabled) @@ -144,6 +144,15 @@ void Server::SetEnabled(bool aEnabled) void Server::Enable(void) { VerifyOrExit(mState == kStateDisabled); + +#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE + if (mFastStartMode) + { + mPrevAddressMode = mAddressMode; + IgnoreError(SetAddressMode(kAddressModeUnicastForceAdd)); + } +#endif + mState = kStateStopped; // Request publishing of "DNS/SRP Address Service" entry in the @@ -199,6 +208,13 @@ void Server::Disable(void) Stop(); mState = kStateDisabled; +#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE + if (mFastStartMode) + { + IgnoreError(SetAddressMode(mPrevAddressMode)); + } +#endif + exit: return; } @@ -206,6 +222,10 @@ exit: #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE void Server::SetAutoEnableMode(bool aEnabled) { +#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE + DisableFastStartMode(); +#endif + VerifyOrExit(mAutoEnable != aEnabled); mAutoEnable = aEnabled; @@ -236,6 +256,18 @@ exit: return error; } +void Server::DisableFastStartMode(void) +{ + VerifyOrExit(mFastStartMode); + + Disable(); + mFastStartMode = false; + LogInfo("FastStartMode disabled"); + +exit: + return; +} + void Server::HandleNotifierEvents(Events aEvents) { VerifyOrExit(mFastStartMode); @@ -248,9 +280,6 @@ void Server::HandleNotifierEvents(Events aEvents) if (!NetDataContainsOtherSrpServers()) { LogInfo("FastStartMode - No SRP server in NetData"); - - mPrevAddressMode = mAddressMode; - IgnoreError(SetAddressMode(kAddressModeUnicastForceAdd)); Enable(); } } @@ -261,9 +290,7 @@ void Server::HandleNotifierEvents(Events aEvents) if (NetDataContainsOtherSrpServers()) { LogInfo("FastStartMode - New SRP server entry in NetData"); - Disable(); - IgnoreError(SetAddressMode(mPrevAddressMode)); } } diff --git a/src/core/net/srp_server.hpp b/src/core/net/srp_server.hpp index 33006ca09..150e4f070 100644 --- a/src/core/net/srp_server.hpp +++ b/src/core/net/srp_server.hpp @@ -949,6 +949,7 @@ private: #endif #if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE + void DisableFastStartMode(void); void HandleNotifierEvents(Events aEvents); bool NetDataContainsOtherSrpServers(void) const; #endif diff --git a/tests/unit/test_srp_server.cpp b/tests/unit/test_srp_server.cpp index 5ac0ef9aa..cc03dc61a 100644 --- a/tests/unit/test_srp_server.cpp +++ b/tests/unit/test_srp_server.cpp @@ -1367,6 +1367,22 @@ void TestSrpServerFastStartMode(void) VerifyOrQuit(srpServer->IsFastStartModeEnabled()); VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateRunning); + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Start auto-enable mode and ensure "fast start mode" is turned + // off and the original AddressMode is restored on the SRP server. + +#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE + srpServer->SetAutoEnableMode(true); + + VerifyOrQuit(!srpServer->IsFastStartModeEnabled()); + VerifyOrQuit(srpServer->IsAutoEnableMode()); + + VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateDisabled); + VerifyOrQuit(srpServer->GetAddressMode() == Srp::Server::kAddressModeUnicast); + + VerifyOrQuit(srpServer->EnableFastStartMode() == kErrorInvalidState); +#endif + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // Finalize OT instance and validate all heap allocations are freed.