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