@@ -115,9 +115,10 @@ app::Clusters::NetworkCommissioning::Instance
115
115
sWiFiNetworkCommissioningInstance (0 /* Endpoint Id */ , &(NetworkCommissioning::SlWiFiDriver::GetInstance()));
116
116
#endif /* SL_WIFI */
117
117
118
- #if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
119
118
bool sIsEnabled = false ;
120
119
bool sIsAttached = false ;
120
+
121
+ #if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER)
121
122
bool sHaveBLEConnections = false ;
122
123
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
123
124
@@ -156,14 +157,13 @@ Identify gIdentify = {
156
157
};
157
158
158
159
#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER
160
+
159
161
} // namespace
160
162
161
163
bool BaseApplication::sIsProvisioned = false ;
162
164
bool BaseApplication::sIsFactoryResetTriggered = false ;
163
165
LEDWidget * BaseApplication::sAppActionLed = nullptr ;
164
- #if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
165
166
BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate();
166
- #endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
167
167
168
168
#ifdef DIC_ENABLE
169
169
namespace {
@@ -181,17 +181,19 @@ void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_
181
181
} // namespace
182
182
#endif // DIC_ENABLE
183
183
184
- #if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
185
184
void BaseApplicationDelegate::OnCommissioningSessionStarted ()
186
185
{
187
186
isComissioningStarted = true ;
188
187
}
188
+
189
189
void BaseApplicationDelegate::OnCommissioningSessionStopped ()
190
190
{
191
191
isComissioningStarted = false ;
192
192
}
193
+
193
194
void BaseApplicationDelegate::OnCommissioningWindowClosed ()
194
195
{
196
+ #if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
195
197
if (!BaseApplication::GetProvisionStatus () && !isComissioningStarted)
196
198
{
197
199
int32_t status = wfx_power_save (RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
@@ -200,8 +202,27 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
200
202
ChipLogError (DeviceLayer, " Failed to enable the TA Deep Sleep" );
201
203
}
202
204
}
205
+ #endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917qq
206
+ }
207
+
208
+ void BaseApplicationDelegate::OnFabricCommitted (const FabricTable & fabricTable, FabricIndex fabricIndex)
209
+ {
210
+ // If we commissioned our first fabric, Update the commissioned status of the App
211
+ if (fabricTable.FabricCount () == 1 )
212
+ {
213
+ BaseApplication::UpdateCommissioningStatus (true );
214
+ }
215
+ }
216
+
217
+ void BaseApplicationDelegate::OnFabricRemoved (const FabricTable & fabricTable, FabricIndex fabricIndex)
218
+ {
219
+ if (fabricTable.FabricCount () == 0 )
220
+ {
221
+ BaseApplication::UpdateCommissioningStatus (false );
222
+
223
+ BaseApplication::DoProvisioningReset ();
224
+ }
203
225
}
204
- #endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
205
226
206
227
/* *********************************************************
207
228
* AppTask Definitions
@@ -298,6 +319,8 @@ CHIP_ERROR BaseApplication::Init()
298
319
#if CHIP_ENABLE_OPENTHREAD
299
320
BaseApplication::sIsProvisioned = ConnectivityMgr ().IsThreadProvisioned ();
300
321
#endif
322
+
323
+ err = chip::Server::GetInstance ().GetFabricTable ().AddFabricDelegate (&sAppDelegate );
301
324
return err;
302
325
}
303
326
@@ -411,6 +434,23 @@ bool BaseApplication::ActivateStatusLedPatterns()
411
434
return isPatternSet;
412
435
}
413
436
437
+ void BaseApplication::UpdateCommissioningStatus (bool newState)
438
+ {
439
+ #ifdef SL_WIFI
440
+ BaseApplication::sIsProvisioned = ConnectivityMgr ().IsWiFiStationProvisioned ();
441
+ sIsEnabled = ConnectivityMgr ().IsWiFiStationEnabled ();
442
+ sIsAttached = ConnectivityMgr ().IsWiFiStationConnected ();
443
+ #endif /* SL_WIFI */
444
+ #if CHIP_ENABLE_OPENTHREAD
445
+ // TODO: This is a temporary solution until we can read Thread provisioning status from RAM instead of NVM.
446
+ BaseApplication::sIsProvisioned = newState;
447
+ sIsEnabled = ConnectivityMgr ().IsThreadEnabled ();
448
+ sIsAttached = ConnectivityMgr ().IsThreadAttached ();
449
+ #endif /* CHIP_ENABLE_OPENTHREAD */
450
+
451
+ ActivateStatusLedPatterns ();
452
+ }
453
+
414
454
// TODO Move State Monitoring elsewhere
415
455
void BaseApplication::LightEventHandler ()
416
456
{
@@ -750,15 +790,42 @@ void BaseApplication::ScheduleFactoryReset()
750
790
{
751
791
Provision::Manager::GetInstance ().SetProvisionRequired (true );
752
792
}
753
- PlatformMgr ().HandleServerShuttingDown ();
793
+ PlatformMgr ().HandleServerShuttingDown (); // HandleServerShuttingDown calls OnShutdown() which is only implemented for the basic information cluster it seems. And triggers and Event flush, which is not relevant when there are no fabrics left
754
794
ConfigurationMgr ().InitiateFactoryReset ();
755
795
});
756
796
}
757
797
798
+ void BaseApplication::DoProvisioningReset ()
799
+ {
800
+ PlatformMgr ().ScheduleWork ([](intptr_t ) {
801
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD
802
+ #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
803
+ ThreadStackMgr ().ClearAllSrpHostAndServices ();
804
+ #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT
805
+ ChipLogProgress (DeviceLayer, " Clearing Thread provision" );
806
+ chip::DeviceLayer::ConnectivityMgr ().ErasePersistentInfo ();
807
+ ThreadStackMgrImpl ().FactoryResetThreadStack ();
808
+ ThreadStackMgr ().InitThreadStack ();
809
+ #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD
810
+
811
+ #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
812
+ ChipLogProgress (DeviceLayer, " Clearing WiFi provision" );
813
+ chip::DeviceLayer::ConnectivityMgr ().ClearWiFiStationProvision ();
814
+ #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
815
+
816
+ CHIP_ERROR err = Server::GetInstance ().GetCommissioningWindowManager ().OpenBasicCommissioningWindow ();
817
+ if (err != CHIP_NO_ERROR)
818
+ {
819
+ SILABS_LOG (" Failed to open the Basic Commissioning Window" );
820
+ }
821
+ });
822
+ }
823
+
758
824
void BaseApplication::OnPlatformEvent (const ChipDeviceEvent * event, intptr_t )
759
825
{
760
826
if (event->Type == DeviceEventType::kServiceProvisioningChange )
761
827
{
828
+ // Note: This is only called on Attach, we need to add a method to detect Thread Network Detach
762
829
BaseApplication::sIsProvisioned = event->ServiceProvisioningChange .IsServiceProvisioned ;
763
830
}
764
831
}
0 commit comments