Skip to content

Commit c47254a

Browse files
wy-hhrestyled-commits
authored andcommitted
[bouffalo lab] open commission window when last fabric is removed (project-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>
1 parent 65b439a commit c47254a

File tree

8 files changed

+68
-2
lines changed

8 files changed

+68
-2
lines changed

examples/platform/bouffalolab/common/plat/platform.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,35 @@ void UnlockOpenThreadTask(void)
178178
}
179179
#endif
180180

181+
class AppFabricTableDelegate : public FabricTable::Delegate
182+
{
183+
void OnFabricRemoved(const FabricTable & fabricTable, FabricIndex fabricIndex)
184+
{
185+
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
186+
{
187+
ChipLogProgress(DeviceLayer, "Performing erasing of settings partition");
188+
PlatformMgr().ScheduleWork([](intptr_t) {
189+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
190+
ConfigurationManagerImpl::GetDefaultInstance().ClearThreadStack();
191+
ThreadStackMgrImpl().FactoryResetThreadStack();
192+
ThreadStackMgr().InitThreadStack();
193+
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
194+
195+
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
196+
ChipLogProgress(DeviceLayer, "Clearing WiFi provision");
197+
chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision();
198+
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
199+
200+
CHIP_ERROR err = Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow();
201+
if (err != CHIP_NO_ERROR)
202+
{
203+
ChipLogError(AppServer, "Failed to open the Basic Commissioning Window");
204+
}
205+
});
206+
}
207+
}
208+
};
209+
181210
CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
182211
{
183212
chip::RendezvousInformationFlags rendezvousMode(chip::RendezvousInformationFlag::kOnNetwork);
@@ -265,6 +294,9 @@ CHIP_ERROR PlatformManagerImpl::PlatformInit(void)
265294

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

297+
static AppFabricTableDelegate sAppFabricDelegate;
298+
chip::Server::GetInstance().GetFabricTable().AddFabricDelegate(&sAppFabricDelegate);
299+
268300
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
269301

270302
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD

src/platform/bouffalolab/BL616/ThreadStackManagerImpl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ bool ThreadStackManagerImpl::IsInitialized()
6363
return sInstance.mThreadStackLock != NULL;
6464
}
6565

66+
void ThreadStackManagerImpl::FactoryResetThreadStack(void)
67+
{
68+
VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL);
69+
otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance());
70+
}
71+
6672
} // namespace DeviceLayer
6773
} // namespace chip
6874

src/platform/bouffalolab/BL702/ThreadStackManagerImpl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ bool ThreadStackManagerImpl::IsInitialized()
6565
return sInstance.mThreadStackLock != NULL;
6666
}
6767

68+
void ThreadStackManagerImpl::FactoryResetThreadStack(void)
69+
{
70+
VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL);
71+
otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance());
72+
}
73+
6874
} // namespace DeviceLayer
6975
} // namespace chip
7076

src/platform/bouffalolab/BL702L/ThreadStackManagerImpl.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ bool ThreadStackManagerImpl::IsInitialized()
6565
return sInstance.mThreadStackLock != NULL;
6666
}
6767

68+
void ThreadStackManagerImpl::FactoryResetThreadStack(void)
69+
{
70+
VerifyOrReturn(ThreadStackMgrImpl().OTInstance() != NULL);
71+
otInstanceFactoryReset(ThreadStackMgrImpl().OTInstance());
72+
}
73+
6874
} // namespace DeviceLayer
6975
} // namespace chip
7076

src/platform/bouffalolab/common/BLConfig_littlefs.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ CHIP_ERROR BLConfig::WriteConfigValue(const char * key, uint8_t * val, size_t si
278278

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

281-
ret = lfs_file_open(blconfig_lfs, &file, write_key, LFS_O_CREAT | LFS_O_RDWR);
281+
ret = lfs_file_open(blconfig_lfs, &file, write_key, LFS_O_CREAT | LFS_O_RDWR | LFS_O_TRUNC);
282282
VerifyOrExit(ret == LFS_ERR_OK, err = CHIP_ERROR_PERSISTED_STORAGE_FAILED);
283283

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

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

356-
ret = lfs_file_open(blconfig_lfs, &file, reset_key, LFS_O_CREAT | LFS_O_RDWR);
356+
ret = lfs_file_open(blconfig_lfs, &file, reset_key, LFS_O_CREAT | LFS_O_RDWR | LFS_O_TRUNC);
357357
if (ret != LFS_ERR_OK)
358358
{
359359
blconfig_lfs->cfg->unlock(blconfig_lfs->cfg);

src/platform/bouffalolab/common/ConfigurationManagerImpl.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,17 @@ void ConfigurationManagerImpl::RunConfigUnitTest(void)
190190
BLConfig::RunConfigUnitTest();
191191
}
192192

193+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
194+
void ConfigurationManagerImpl::ClearThreadStack()
195+
{
196+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
197+
ThreadStackMgr().ClearAllSrpHostAndServices();
198+
#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
199+
ChipLogProgress(DeviceLayer, "Clearing Thread provision");
200+
ThreadStackMgr().ErasePersistentInfo();
201+
}
202+
#endif
203+
193204
void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg)
194205
{
195206
CHIP_ERROR err;

src/platform/bouffalolab/common/ConfigurationManagerImpl.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class ConfigurationManagerImpl : public Internal::GenericConfigurationManagerImp
3838
CHIP_ERROR StoreTotalOperationalHours(uint32_t totalOperationalHours);
3939
bool IsFullyProvisioned();
4040

41+
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
42+
void ClearThreadStack();
43+
#endif
44+
4145
private:
4246
// ===== Members that implement the ConfigurationManager private interface.
4347

src/platform/bouffalolab/common/ThreadStackManagerImpl.h

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class ThreadStackManagerImpl final : public ThreadStackManager,
6565

6666
using ThreadStackManager::InitThreadStack;
6767
CHIP_ERROR InitThreadStack(otInstance * otInst);
68+
void FactoryResetThreadStack(void);
6869

6970
private:
7071
// ===== Methods that implement the ThreadStackManager abstract interface.

0 commit comments

Comments
 (0)