2121#include < app/server/Server.h>
2222#include < zephyr/fs/nvs.h>
2323#include < zephyr/settings/settings.h>
24- #include < zephyr/sys/reboot.h>
2524#ifdef CONFIG_CHIP_WIFI
2625#include " WiFiManager.h"
2726#endif
@@ -46,6 +45,13 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
4645
4746 if (server.GetFabricTable ().FabricCount () == 0 )
4847 {
48+ // ScheduleFactoryReset in case of failed commissioning
49+ if (AppTaskCommon::IsCommissioningFailed ())
50+ {
51+ chip::Server::GetInstance ().ScheduleFactoryReset ();
52+ return ;
53+ }
54+
4955 if (chip::DeviceLayer::ConnectivityMgr ().IsBLEAdvertisingEnabled ())
5056 {
5157 server.GetCommissioningWindowManager ().CloseCommissioningWindow ();
@@ -63,9 +69,8 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
6369 {
6470 LogErrorOnFailure (chip::DeviceLayer::PlatformMgr ().ScheduleWork ([](intptr_t ) {
6571#ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
66- #ifdef CONFIG_CHIP_WIFI
6772 chip::Server::GetInstance ().ScheduleFactoryReset ();
68- #else
73+ #elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY)
6974 ChipLogProgress (DeviceLayer, " Erasing settings partition" );
7075 // TC-OPCREDS-3.6 (device doesn't need to reboot automatically after the last fabric is removed) can't use
7176 // FactoryReset
@@ -89,14 +94,7 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
8994#ifdef CONFIG_TFLM_FEATURE
9095 AppTask::MicroSpeechProcessStop ();
9196#endif
92- // Reboot in case of failed commissioning to allow new pairing via BLE
93- if (AppTaskCommon::IsCommissioningFailed ())
94- {
95- ChipLogProgress (DeviceLayer, " Rebooting board" );
96- sys_reboot (SYS_REBOOT_WARM);
97- }
98- #endif // CONFIG_CHIP_WIFI
99- #elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_ONLY) || defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
97+ #elif defined(CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START)
10098#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
10199 LogErrorOnFailure (chip::DeviceLayer::ThreadStackMgr ().ClearAllSrpHostAndServices ());
102100#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
@@ -112,7 +110,6 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
112110 LogErrorOnFailure (chip::DeviceLayer::WiFiManager::Instance ().Disconnect ());
113111 chip::DeviceLayer::ConnectivityMgr ().ClearWiFiStationProvision ();
114112#endif
115- #ifdef CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
116113#if CHIP_DEVICE_CONFIG_ENABLE_THREAD && !CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION
117114 LogErrorOnFailure (chip::DeviceLayer::ThreadStackMgr ().SetThreadEnabled (false ));
118115 LogErrorOnFailure (chip::DeviceLayer::PlatformMgr ().ScheduleWork (StartThreadPrescan, 0 ));
@@ -127,7 +124,6 @@ class AppFabricTableDelegate : public chip::FabricTable::Delegate
127124 }
128125 ChipLogError (FabricProvisioning, " Could not start Bluetooth LE advertising" );
129126#endif
130- #endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_PAIRING_START
131127#endif // CONFIG_CHIP_LAST_FABRIC_REMOVED_ERASE_AND_REBOOT
132128 }));
133129 }
0 commit comments