@@ -65,7 +65,7 @@ CHIP_ERROR ConnectivityManagerImpl::_Init()
65
65
// TODO Initialize the Chip Addressing and Routing Module.
66
66
67
67
// Ensure that station mode is enabled.
68
- wfx_enable_sta_mode ();
68
+ ConfigureStationMode ();
69
69
70
70
err = DeviceLayer::SystemLayer ().ScheduleWork (DriveStationState, NULL );
71
71
@@ -153,7 +153,7 @@ bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void)
153
153
154
154
bool ConnectivityManagerImpl::_IsWiFiStationEnabled (void )
155
155
{
156
- return wfx_is_sta_mode_enabled ();
156
+ return IsStationModeEnabled ();
157
157
}
158
158
159
159
CHIP_ERROR ConnectivityManagerImpl::_SetWiFiStationMode (ConnectivityManager::WiFiStationMode val)
@@ -218,26 +218,23 @@ CHIP_ERROR ConnectivityManagerImpl::_SetPollingInterval(System::Clock::Milliseco
218
218
219
219
void ConnectivityManagerImpl::DriveStationState ()
220
220
{
221
- sl_status_t serr;
222
- bool stationConnected;
221
+ bool stationConnected = false ;
223
222
224
223
// Refresh the current station mode.
225
224
GetWiFiStationMode ();
226
225
227
226
// If the station interface is NOT under application control...
228
227
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled )
229
228
{
230
- // Ensure that the WFX is started.
231
- if ((serr = wfx_wifi_start ()) != SL_STATUS_OK)
232
- {
233
- ChipLogError (DeviceLayer, " wfx_wifi_start() failed: %lx" , serr);
234
- return ;
235
- }
236
- // Ensure that station mode is enabled in the WFX WiFi layer.
237
- wfx_enable_sta_mode ();
229
+ // Ensure that the Wifi task is started.
230
+ CHIP_ERROR error = StartWifiTask ();
231
+ VerifyOrReturn (error == CHIP_NO_ERROR, ChipLogError (DeviceLayer, " StartWifiTask() failed: %s" , ErrorStr (error)));
232
+
233
+ // Ensure that station mode is enabled in the WiFi layer.
234
+ ConfigureStationMode ();
238
235
}
239
236
240
- stationConnected = wfx_is_sta_connected ();
237
+ stationConnected = IsStationConnected ();
241
238
242
239
// If the station interface is currently connected ...
243
240
if (stationConnected)
@@ -262,12 +259,14 @@ void ConnectivityManagerImpl::DriveStationState()
262
259
(mWiFiStationMode != kWiFiStationMode_Enabled && !IsWiFiStationProvisioned ()))
263
260
{
264
261
ChipLogProgress (DeviceLayer, " Disconnecting WiFi station interface" );
265
- serr = sl_matter_wifi_disconnect ();
266
- if (serr != SL_STATUS_OK)
262
+ sl_status_t status = sl_matter_wifi_disconnect ();
263
+ if (status != SL_STATUS_OK)
267
264
{
268
- ChipLogError (DeviceLayer, " wfx_wifi_disconnect() failed: %lx" , serr);
265
+ ChipLogError (DeviceLayer, " wfx_wifi_disconnect() failed: %lx" , status);
266
+
267
+ // TODO: Clean the function up to remove the usage of goto
268
+ goto exit ;
269
269
}
270
- SuccessOrExit (serr);
271
270
272
271
ChangeWiFiStationState (kWiFiStationState_Disconnecting );
273
272
}
@@ -310,11 +309,14 @@ void ConnectivityManagerImpl::DriveStationState()
310
309
if (mWiFiStationState != kWiFiStationState_Connecting )
311
310
{
312
311
ChipLogProgress (DeviceLayer, " Attempting to connect WiFi" );
313
- if ((serr = wfx_connect_to_ap ()) != SL_STATUS_OK)
312
+
313
+ sl_status_t status = wfx_connect_to_ap ();
314
+ if (status != SL_STATUS_OK)
314
315
{
315
- ChipLogError (DeviceLayer, " wfx_connect_to_ap() failed: %" PRId32, serr);
316
+ ChipLogError (DeviceLayer, " wfx_connect_to_ap() failed: %" PRId32, status);
317
+ // TODO: Clean the function up to remove the usage of goto
318
+ goto exit ;
316
319
}
317
- SuccessOrExit (serr);
318
320
319
321
ChangeWiFiStationState (kWiFiStationState_Connecting );
320
322
}
0 commit comments