mirror of
https://github.com/espressif/openthread.git
synced 2026-10-06 07:47:41 +00:00
[srp-server] allow disabling "Fast Start Mode" via auto-enable (#11319)
This commit updates the `Srp::Server` so that Fast Start Mode can be disabled by a call to `otSrpServerSetAutoEnableMode()`, in addition to the existing method of calling `otSrpServerSetEnabled()`. The `test_srp_server` unit test is updated to validate this new behavior.
This commit is contained in:
@@ -52,7 +52,7 @@ extern "C" {
|
|||||||
*
|
*
|
||||||
* @note This number versions both OpenThread platform and user APIs.
|
* @note This number versions both OpenThread platform and user APIs.
|
||||||
*/
|
*/
|
||||||
#define OPENTHREAD_API_VERSION (482)
|
#define OPENTHREAD_API_VERSION (483)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @addtogroup api-instance
|
* @addtogroup api-instance
|
||||||
|
|||||||
@@ -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
|
* 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`).
|
* 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()`,
|
* After successfully enabling Fast Start Mode, it can be disabled either by a call to `otSrpServerSetEnabled()`,
|
||||||
* explicitly enabling or disabling the SRP server function.
|
* 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.
|
* @param[in] aInstance A pointer to the OpenThread instance.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ void Server::SetEnabled(bool aEnabled)
|
|||||||
mAutoEnable = false;
|
mAutoEnable = false;
|
||||||
#endif
|
#endif
|
||||||
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
||||||
mFastStartMode = false;
|
DisableFastStartMode();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (aEnabled)
|
if (aEnabled)
|
||||||
@@ -144,6 +144,15 @@ void Server::SetEnabled(bool aEnabled)
|
|||||||
void Server::Enable(void)
|
void Server::Enable(void)
|
||||||
{
|
{
|
||||||
VerifyOrExit(mState == kStateDisabled);
|
VerifyOrExit(mState == kStateDisabled);
|
||||||
|
|
||||||
|
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
||||||
|
if (mFastStartMode)
|
||||||
|
{
|
||||||
|
mPrevAddressMode = mAddressMode;
|
||||||
|
IgnoreError(SetAddressMode(kAddressModeUnicastForceAdd));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
mState = kStateStopped;
|
mState = kStateStopped;
|
||||||
|
|
||||||
// Request publishing of "DNS/SRP Address Service" entry in the
|
// Request publishing of "DNS/SRP Address Service" entry in the
|
||||||
@@ -199,6 +208,13 @@ void Server::Disable(void)
|
|||||||
Stop();
|
Stop();
|
||||||
mState = kStateDisabled;
|
mState = kStateDisabled;
|
||||||
|
|
||||||
|
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
||||||
|
if (mFastStartMode)
|
||||||
|
{
|
||||||
|
IgnoreError(SetAddressMode(mPrevAddressMode));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -206,6 +222,10 @@ exit:
|
|||||||
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
#if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
|
||||||
void Server::SetAutoEnableMode(bool aEnabled)
|
void Server::SetAutoEnableMode(bool aEnabled)
|
||||||
{
|
{
|
||||||
|
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
||||||
|
DisableFastStartMode();
|
||||||
|
#endif
|
||||||
|
|
||||||
VerifyOrExit(mAutoEnable != aEnabled);
|
VerifyOrExit(mAutoEnable != aEnabled);
|
||||||
mAutoEnable = aEnabled;
|
mAutoEnable = aEnabled;
|
||||||
|
|
||||||
@@ -236,6 +256,18 @@ exit:
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Server::DisableFastStartMode(void)
|
||||||
|
{
|
||||||
|
VerifyOrExit(mFastStartMode);
|
||||||
|
|
||||||
|
Disable();
|
||||||
|
mFastStartMode = false;
|
||||||
|
LogInfo("FastStartMode disabled");
|
||||||
|
|
||||||
|
exit:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
void Server::HandleNotifierEvents(Events aEvents)
|
void Server::HandleNotifierEvents(Events aEvents)
|
||||||
{
|
{
|
||||||
VerifyOrExit(mFastStartMode);
|
VerifyOrExit(mFastStartMode);
|
||||||
@@ -248,9 +280,6 @@ void Server::HandleNotifierEvents(Events aEvents)
|
|||||||
if (!NetDataContainsOtherSrpServers())
|
if (!NetDataContainsOtherSrpServers())
|
||||||
{
|
{
|
||||||
LogInfo("FastStartMode - No SRP server in NetData");
|
LogInfo("FastStartMode - No SRP server in NetData");
|
||||||
|
|
||||||
mPrevAddressMode = mAddressMode;
|
|
||||||
IgnoreError(SetAddressMode(kAddressModeUnicastForceAdd));
|
|
||||||
Enable();
|
Enable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -261,9 +290,7 @@ void Server::HandleNotifierEvents(Events aEvents)
|
|||||||
if (NetDataContainsOtherSrpServers())
|
if (NetDataContainsOtherSrpServers())
|
||||||
{
|
{
|
||||||
LogInfo("FastStartMode - New SRP server entry in NetData");
|
LogInfo("FastStartMode - New SRP server entry in NetData");
|
||||||
|
|
||||||
Disable();
|
Disable();
|
||||||
IgnoreError(SetAddressMode(mPrevAddressMode));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -949,6 +949,7 @@ private:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
#if OPENTHREAD_CONFIG_SRP_SERVER_FAST_START_MODE_ENABLE
|
||||||
|
void DisableFastStartMode(void);
|
||||||
void HandleNotifierEvents(Events aEvents);
|
void HandleNotifierEvents(Events aEvents);
|
||||||
bool NetDataContainsOtherSrpServers(void) const;
|
bool NetDataContainsOtherSrpServers(void) const;
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1367,6 +1367,22 @@ void TestSrpServerFastStartMode(void)
|
|||||||
VerifyOrQuit(srpServer->IsFastStartModeEnabled());
|
VerifyOrQuit(srpServer->IsFastStartModeEnabled());
|
||||||
VerifyOrQuit(srpServer->GetState() == Srp::Server::kStateRunning);
|
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.
|
// Finalize OT instance and validate all heap allocations are freed.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user