Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Silabs]Clear all srp client services on factory reset #31606

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/platform/silabs/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,19 @@ class ThreadStackManagerImpl final : public ThreadStackManager,

using ThreadStackManager::InitThreadStack;
CHIP_ERROR InitThreadStack(otInstance * otInst);
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
void RemoveAllSrpServices();
#endif

private:
// ===== Methods that implement the ThreadStackManager abstract interface.

CHIP_ERROR _InitThreadStack(void);

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
static void OnSrpClientRemoveCallback(otError aError, const otSrpClientHostInfo * aHostInfo,
const otSrpClientService * aServices, const otSrpClientService * aRemovedServices,
void * aContext);
#endif
// ===== Members for internal use by the following friends.

friend ThreadStackManager & ::chip::DeviceLayer::ThreadStackMgr(void);
Expand All @@ -87,6 +94,9 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
static ThreadStackManagerImpl sInstance;

static bool IsInitialized();
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
TaskHandle_t srpRemoveRequester = nullptr;
#endif

// ===== Private members for use by this class only.

Expand Down
5 changes: 3 additions & 2 deletions src/platform/silabs/efr32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,11 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
ThreadStackMgrImpl().RemoveAllSrpServices();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
ChipLogProgress(DeviceLayer, "Clearing Thread provision");
ThreadStackMgr().ErasePersistentInfo();

#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

PersistedStorage::KeyValueStoreMgrImpl().ErasePartition();
Expand Down
52 changes: 52 additions & 0 deletions src/platform/silabs/efr32/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,58 @@ bool ThreadStackManagerImpl::IsInitialized()
return sInstance.mThreadStackLock != NULL;
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
/*
* @brief Notifies `RemoveAllSrpServices` that the Srp Client removal has completed
* and unblock the calling task.
*
* No data is processed.
*/
void ThreadStackManagerImpl::OnSrpClientRemoveCallback(otError aError, const otSrpClientHostInfo * aHostInfo,
const otSrpClientService * aServices,
const otSrpClientService * aRemovedServices, void * aContext)
{
if (ThreadStackMgrImpl().srpRemoveRequester)
{
xTaskNotifyGive(ThreadStackMgrImpl().srpRemoveRequester);
}
}

/*
* @brief This is a utility function to remove all Thread client Srp services
* established between the device and the srp server (in most cases the OTBR).
* The calling task is blocked until OnSrpClientRemoveCallback.
*
* Note: This function is meant to be used during the factory reset sequence.
* It overrides the generic SrpClient callback `OnSrpClientNotification` with
* OnSrpClientRemoveCallback which doesn't process any of the callback data.
*
* If there is a usecase where this function would be needed in a non-Factory reset context,
* OnSrpClientRemoveCallback should be extended and tied back with the GenericThreadStackManagerImpl_OpenThread
* management of the srp clients.
*/
void ThreadStackManagerImpl::RemoveAllSrpServices()
{
// This check ensure that only one srp services removal is running
if (ThreadStackMgrImpl().srpRemoveRequester == nullptr)
{
srpRemoveRequester = xTaskGetCurrentTaskHandle();
otSrpClientSetCallback(OTInstance(), &OnSrpClientRemoveCallback, nullptr);
InvalidateAllSrpServices();
if (RemoveInvalidSrpServices() == CHIP_NO_ERROR)
{
// Wait for the OnSrpClientRemoveCallback.
ulTaskNotifyTake(pdTRUE, pdMS_TO_TICKS(2000));
}
else
{
ChipLogError(DeviceLayer, "Failed to remove srp services");
}
ThreadStackMgrImpl().srpRemoveRequester = nullptr;
}
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT

} // namespace DeviceLayer
} // namespace chip

Expand Down
Loading