Skip to content

Commit

Permalink
[nrf5-example] Use ConfigurationMgr().InitiateFactoryReset() (#1317)
Browse files Browse the repository at this point in the history
* Add factory reset to NRF5 platform

* Make name consistent with ot

* Update src/platform/nRF5/ConfigurationManagerImpl.cpp

Co-authored-by: Yakun Xu <xyk@google.com>

Co-authored-by: Yakun Xu <xyk@google.com>
  • Loading branch information
erjiaqing and bukepo authored Jun 29, 2020
1 parent 193db63 commit 5f0b920
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 28 deletions.
2 changes: 1 addition & 1 deletion examples/lock-app/nrf5/main/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent)
{
// Actually trigger Factory Reset
sAppTask.mFunction = kFunction_NoneSelected;
ThreadStackMgr().FactoryReset();
ConfigurationMgr().InitiateFactoryReset();
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/include/platform/ConnectivityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ConnectivityManager
CHIP_ERROR SetThreadPollingConfig(const ThreadPollingConfig & pollingConfig);
bool IsThreadAttached(void);
bool IsThreadProvisioned(void);
void ClearThreadProvision(void);
void ErasePersistentInfo(void);
bool HaveServiceConnectivityViaThread(void);

// Internet connectivity methods
Expand Down Expand Up @@ -441,9 +441,9 @@ inline bool ConnectivityManager::IsThreadProvisioned(void)
return static_cast<ImplClass *>(this)->_IsThreadProvisioned();
}

inline void ConnectivityManager::ClearThreadProvision(void)
inline void ConnectivityManager::ErasePersistentInfo(void)
{
static_cast<ImplClass *>(this)->_ClearThreadProvision();
static_cast<ImplClass *>(this)->_ErasePersistentInfo();
}

inline bool ConnectivityManager::HaveServiceConnectivityViaThread(void)
Expand Down
11 changes: 3 additions & 8 deletions src/include/platform/ThreadStackManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class ThreadStackManager
bool IsThreadAttached(void);
CHIP_ERROR GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials);
CHIP_ERROR SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo);
void ClearThreadProvision(void);
void ErasePersistentInfo(void);
ConnectivityManager::ThreadDeviceType GetThreadDeviceType(void);
CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole);
void GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig);
Expand Down Expand Up @@ -232,9 +232,9 @@ inline CHIP_ERROR ThreadStackManager::SetThreadProvision(const Internal::DeviceN
return static_cast<ImplClass *>(this)->_SetThreadProvision(netInfo);
}

inline void ThreadStackManager::ClearThreadProvision(void)
inline void ThreadStackManager::ErasePersistentInfo(void)
{
static_cast<ImplClass *>(this)->_ClearThreadProvision();
static_cast<ImplClass *>(this)->_ErasePersistentInfo();
}

inline ConnectivityManager::ThreadDeviceType ThreadStackManager::GetThreadDeviceType(void)
Expand Down Expand Up @@ -297,11 +297,6 @@ inline CHIP_ERROR ThreadStackManager::GetPrimary802154MACAddress(uint8_t * buf)
return static_cast<ImplClass *>(this)->_GetPrimary802154MACAddress(buf);
}

inline void ThreadStackManager::FactoryReset()
{
return static_cast<ImplClass *>(this)->_FactoryReset();
}

} // namespace DeviceLayer
} // namespace chip

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class GenericConnectivityManagerImpl_NoThread
CHIP_ERROR _SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig);
bool _IsThreadAttached(void);
bool _IsThreadProvisioned(void);
void _ClearThreadProvision(void);
void _ErasePersistentInfo(void);
bool _HaveServiceConnectivityViaThread(void);

ImplClass * Impl() { return static_cast<ImplClass *>(this); }
Expand Down Expand Up @@ -96,7 +96,7 @@ inline bool GenericConnectivityManagerImpl_NoThread<ImplClass>::_IsThreadProvisi
}

template <class ImplClass>
inline void GenericConnectivityManagerImpl_NoThread<ImplClass>::_ClearThreadProvision(void)
inline void GenericConnectivityManagerImpl_NoThread<ImplClass>::_ErasePersistentInfo(void)
{}

template <class ImplClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class GenericConnectivityManagerImpl_Thread
CHIP_ERROR _SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig);
bool _IsThreadAttached(void);
bool _IsThreadProvisioned(void);
void _ClearThreadProvision(void);
void _ErasePersistentInfo(void);
bool _HaveServiceConnectivityViaThread(void);

// ===== Members for use by the implementation subclass.
Expand Down Expand Up @@ -119,9 +119,9 @@ inline bool GenericConnectivityManagerImpl_Thread<ImplClass>::_IsThreadProvision
}

template <class ImplClass>
inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_ClearThreadProvision(void)
inline void GenericConnectivityManagerImpl_Thread<ImplClass>::_ErasePersistentInfo(void)
{
ThreadStackMgrImpl().ClearThreadProvision();
ThreadStackMgrImpl().ErasePersistentInfo();
}

template <class ImplClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
#define GENERIC_NETWORK_PROVISIONING_SERVER_IMPL_IPP

#include <platform/internal/CHIPDeviceLayerInternal.h>
#include <platform/internal/NetworkProvisioningServer.h>
#include <platform/internal/GenericNetworkProvisioningServerImpl.h>
#include <platform/internal/NetworkProvisioningServer.h>
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
#include <platform/ThreadStackManager.h>
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
Expand Down Expand Up @@ -431,7 +431,7 @@ CHIP_ERROR GenericNetworkProvisioningServerImpl<ImplClass>::HandleRemoveNetwork(
}

// Clear the Thread provision.
ThreadStackMgr().ClearThreadProvision();
ThreadStackMgr().ErasePersistentInfo();

break;

Expand Down
2 changes: 1 addition & 1 deletion src/platform/EFR32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

ChipLogProgress(DeviceLayer, "Clearing Thread provision");
ThreadStackMgr().ClearThreadProvision();
ThreadStackMgr().ErasePersistentInfo();

#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

Expand Down
2 changes: 1 addition & 1 deletion src/platform/Linux/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

ChipLogProgress(DeviceLayer, "Clearing Thread provision");
ThreadStackMgr().ClearThreadProvision();
ThreadStackMgr().ErasePersistentInfo();

#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class GenericThreadStackManagerImpl_OpenThread
bool _IsThreadAttached(void);
CHIP_ERROR _GetThreadProvision(DeviceNetworkInfo & netInfo, bool includeCredentials);
CHIP_ERROR _SetThreadProvision(const DeviceNetworkInfo & netInfo);
void _ClearThreadProvision(void);
void _ErasePersistentInfo(void);
ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(void);
CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType);
void _GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig);
Expand All @@ -89,7 +89,6 @@ class GenericThreadStackManagerImpl_OpenThread
CHIP_ERROR DoInit(otInstance * otInst);
bool IsThreadAttachedNoLock(void);
CHIP_ERROR AdjustPollingInterval(void);
void _FactoryReset(void);

private:
// ===== Private members for use by this class only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,12 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread<ImplClass>::AdjustPollingInt
}

template <class ImplClass>
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_FactoryReset(void)
void GenericThreadStackManagerImpl_OpenThread<ImplClass>::_ErasePersistentInfo(void)
{
ChipLogProgress(DeviceLayer, "About to factory reset ...");
ChipLogProgress(DeviceLayer, "Erasing Thread persistent info...");
Impl()->LockThreadStack();
otInstanceFactoryReset(mOTInst);
otThreadSetEnabled(mOTInst, false);
otInstanceErasePersistentInfo(mOTInst);
Impl()->UnlockThreadStack();
}

Expand Down
3 changes: 1 addition & 2 deletions src/platform/nRF5/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

ChipLogProgress(DeviceLayer, "Clearing Thread provision");
ThreadStackMgr().ClearThreadProvision();
ThreadStackMgr().ErasePersistentInfo();

#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

Expand Down

0 comments on commit 5f0b920

Please sign in to comment.