Skip to content

Commit

Permalink
esp32: erase fabric information during factoryreset (#13861)
Browse files Browse the repository at this point in the history
  • Loading branch information
chshu authored and pull[bot] committed Jan 23, 2024
1 parent 3a8cee8 commit 3015683
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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

0 comments on commit 3015683

Please sign in to comment.