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

[Telink] Turn off the CHIP_FACTORY_RESET_ERASE_NVS by default #28947

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
2 changes: 1 addition & 1 deletion config/telink/chip-module/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ endif #CHIP_FACTORY_DATA_BUILD
# See config/zephyr/Kconfig for full definition
config CHIP_FACTORY_RESET_ERASE_NVS
bool
default y
default n

config CHIP_LOG_SIZE_OPTIMIZATION
bool "Disable some detailed logs to decrease flash usage"
Expand Down
60 changes: 25 additions & 35 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
#include <app/InteractionModelEngine.h>
#endif

#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
#include <zephyr/fs/nvs.h>
#include <zephyr/settings/settings.h>
#endif

using namespace chip::app;

Expand Down Expand Up @@ -103,10 +101,11 @@ Button sThreadStartButton;
k_timer sFactoryResetTimer;
uint8_t sFactoryResetCntr = 0;

bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sIsThreadAttached = false;
bool sHaveBLEConnections = false;
bool sIsCommissioningFailed = false;
bool sIsThreadProvisioned = false;
bool sIsThreadEnabled = false;
bool sIsThreadAttached = false;
bool sHaveBLEConnections = false;

#if APP_SET_DEVICE_INFO_PROVIDER
chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
Expand Down Expand Up @@ -138,9 +137,10 @@ class AppCallbacks : public AppDelegate
bool isComissioningStarted;

public:
void OnCommissioningSessionEstablishmentStarted() {}
void OnCommissioningSessionEstablishmentStarted() override { sIsCommissioningFailed = false; }
void OnCommissioningSessionStarted() override { isComissioningStarted = true; }
void OnCommissioningSessionStopped() override { isComissioningStarted = false; }
void OnCommissioningSessionEstablishmentError(CHIP_ERROR err) override { sIsCommissioningFailed = true; }
void OnCommissioningWindowClosed() override
{
if (!isComissioningStarted)
Expand All @@ -157,51 +157,41 @@ class AppFabricTableDelegate : public FabricTable::Delegate
{
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
bool isBasicCommissioningMode = chip::Server::GetInstance().GetCommissioningWindowManager().GetCommissioningMode() ==
Dnssd::CommissioningMode::kEnabledBasic;
ChipLogProgress(DeviceLayer, "Performing erasing of settings partition");

#ifdef CONFIG_CHIP_FACTORY_RESET_ERASE_NVS
void * storage = nullptr;
int status = settings_storage_get(&storage);

if (status == 0)
// Do FactoryReset in case of failed commissioning to allow new pairing via BLE
if (sIsCommissioningFailed)
bzbarsky-apple marked this conversation as resolved.
Show resolved Hide resolved
{
status = nvs_clear(static_cast<nvs_fs *>(storage));
chip::Server::GetInstance().ScheduleFactoryReset();
}

if (!isBasicCommissioningMode)
// TC-OPCREDS-3.6 (device doesn't need to reboot automatically after the last fabric is removed) can't use FactoryReset
else
{
void * storage = nullptr;
int status = settings_storage_get(&storage);

if (!status)
{
status = nvs_mount(static_cast<nvs_fs *>(storage));
status = nvs_clear(static_cast<nvs_fs *>(storage));
}
}

if (status)
{
ChipLogError(DeviceLayer, "Storage clearance failed: %d", status);
}
#else
const CHIP_ERROR err = PersistedStorage::KeyValueStoreMgrImpl().DoFactoryReset();

if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Factory reset failed: %" CHIP_ERROR_FORMAT, err.Format());
}
if (!status)
{
status = nvs_mount(static_cast<nvs_fs *>(storage));
}

ConnectivityMgr().ErasePersistentInfo();
#endif
if (isBasicCommissioningMode)
{
PlatformMgr().Shutdown();
if (status)
{
ChipLogError(DeviceLayer, "Storage clearance failed: %d", status);
}
}
}
}
};

class PlatformMgrDelegate : public DeviceLayer::PlatformManagerDelegate
{
// Disable openthread before reset to prevent writing to NVS
void OnShutDown() override
{
if (ThreadStackManagerImpl().IsThreadEnabled())
Expand Down