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

esp32: erase fabric information during factoryreset #13861

Merged
merged 1 commit into from
Jan 24, 2022
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
8 changes: 8 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
#elif CHIP_DEVICE_CONFIG_ENABLE_THREAD
ThreadStackMgr().ErasePersistentInfo();
#endif

// Erase all key-values including fabric info.
err = PersistedStorage::KeyValueStoreMgrImpl().EraseAll();
if (err != CHIP_NO_ERROR)
{
ChipLogError(DeviceLayer, "Clear Key-Value Storage failed");
}

// Restart the system.
ChipLogProgress(DeviceLayer, "System restarting");
esp_restart();
Expand Down
11 changes: 11 additions & 0 deletions src/platform/ESP32/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
return CHIP_NO_ERROR;
}

CHIP_ERROR KeyValueStoreManagerImpl::EraseAll(void)
{
Internal::ScopedNvsHandle handle;

ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE));
ReturnMappedErrorOnFailure(nvs_erase_all(handle));
ReturnMappedErrorOnFailure(nvs_commit(handle));

return CHIP_NO_ERROR;
}

} // namespace PersistedStorage
} // namespace DeviceLayer
} // namespace chip
2 changes: 2 additions & 0 deletions src/platform/ESP32/KeyValueStoreManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class KeyValueStoreManagerImpl final : public KeyValueStoreManager

CHIP_ERROR _Put(const char * key, const void * value, size_t value_size);

CHIP_ERROR EraseAll(void);

private:
const char * kNamespace = "CHIP_KVS";

Expand Down