Skip to content

Commit

Permalink
[bouffalo lab] open commission window when last fabric is removed (pr…
Browse files Browse the repository at this point in the history
…oject-chip#37517)

* [bouffalo lab] open commission window when last fabric is removed

* Restyled by whitespace

* fix compile error

---------

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
wy-hh and restyled-commits authored Feb 11, 2025
1 parent 16e3971 commit 9c8cb33
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 2 deletions.
32 changes: 32 additions & 0 deletions examples/platform/bouffalolab/common/plat/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,35 @@ void UnlockOpenThreadTask(void)
}
#endif

class AppFabricTableDelegate : public FabricTable::Delegate
{
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
{
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
ChipLogProgress(DeviceLayer, "Performing erasing of settings partition");
PlatformMgr().ScheduleWork([](intptr_t) {
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
ConfigurationManagerImpl::GetDefaultInstance().ClearThreadStack();
ThreadStackMgrImpl().FactoryResetThreadStack();
ThreadStackMgr().InitThreadStack();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD

#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
ChipLogProgress(DeviceLayer, "Clearing WiFi provision");
chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision();
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION

CHIP_ERROR err = Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
if (err != CHIP_NO_ERROR)
{
ChipLogError(AppServer, "Failed to open the Basic Commissioning Window");
}
});
}
}
};

CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
{
chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork);
Expand Down Expand Up @@ -265,6 +294,9 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)

gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage());

static AppFabricTableDelegate sAppFabricDelegate;
chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate);

chip::DeviceLayer::PlatformMgr().UnlockChipStack();

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
Expand Down
6 changes: 6 additions & 0 deletions src/platform/bouffalolab/BL616/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ bool ThreadStackManagerImpl::IsInitialized()
return sInstance.mThreadStackLock != NULL;
}

void ThreadStackManagerImpl::FactoryResetThreadStack(void)
{
VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL);
otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance());
}

} // namespace DeviceLayer
} // namespace chip

Expand Down
6 changes: 6 additions & 0 deletions src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ bool ThreadStackManagerImpl::IsInitialized()
return sInstance.mThreadStackLock != NULL;
}

void ThreadStackManagerImpl::FactoryResetThreadStack(void)
{
VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL);
otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance());
}

} // namespace DeviceLayer
} // namespace chip

Expand Down
6 changes: 6 additions & 0 deletions src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ bool ThreadStackManagerImpl::IsInitialized()
return sInstance.mThreadStackLock != NULL;
}

void ThreadStackManagerImpl::FactoryResetThreadStack(void)
{
VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL);
otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance());
}

} // namespace DeviceLayer
} // namespace chip

Expand Down
4 changes: 2 additions & 2 deletions src/platform/bouffalolab/common/BLConfig_littlefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si

blconfig_lfs->cfg->lock(blconfig_lfs->cfg);

ret = lfs_file_open(blconfig_lfs, &file, write_key, LFS_O_CREAT | LFS_O_RDWR);
ret = lfs_file_open(blconfig_lfs, &file, write_key, LFS_O_CREAT | LFS_O_RDWR | LFS_O_TRUNC);
VerifyOrExit(ret == LFS_ERR_OK, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);

lfs_file_write(blconfig_lfs, &file, val, size);
Expand Down Expand Up @@ -353,7 +353,7 @@ CHIP_ERROR BLConfig::FactoryResetConfig(void)

blconfig_lfs->cfg->lock(blconfig_lfs->cfg);

ret = lfs_file_open(blconfig_lfs, &file, reset_key, LFS_O_CREAT | LFS_O_RDWR);
ret = lfs_file_open(blconfig_lfs, &file, reset_key, LFS_O_CREAT | LFS_O_RDWR | LFS_O_TRUNC);
if (ret != LFS_ERR_OK)
{
blconfig_lfs->cfg->unlock(blconfig_lfs->cfg);
Expand Down
11 changes: 11 additions & 0 deletions src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,17 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
BLConfig::RunConfigUnitTest();
}

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
void ConfigurationManagerImpl::ClearThreadStack()
{
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
ThreadStackMgr().ClearAllSrpHostAndServices();
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
ChipLogProgress(DeviceLayer, "Clearing Thread provision");
ThreadStackMgr().ErasePersistentInfo();
}
#endif

void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
{
CHIP_ERROR err;
Expand Down
4 changes: 4 additions & 0 deletions src/platform/bouffalolab/common/ConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours);
bool IsFullyProvisioned();

#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
void ClearThreadStack();
#endif

private:
// ===== Members that implement the ConfigurationManager private interface.

Expand Down
1 change: 1 addition & 0 deletions src/platform/bouffalolab/common/ThreadStackManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager,

using ThreadStackManager::InitThreadStack;
CHIP_ERROR InitThreadStack(otInstance * otInst);
void FactoryResetThreadStack(void);

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

0 comments on commit 9c8cb33

Please sign in to comment.