15
15
* limitations under the License.
16
16
*/
17
17
18
- #include " stdbool.h"
18
+ #include < stdbool.h>
19
19
#include < stdio.h>
20
20
#include < stdlib.h>
21
21
#include < string.h>
22
22
23
23
#include " FreeRTOS.h"
24
24
#include " event_groups.h"
25
- #include " silabs_utils.h"
26
- #include " sl_status.h"
27
25
#include " task.h"
26
+
27
+ #include < lib/support/logging/CHIPLogging.h>
28
+
28
29
#include " wfx_host_events.h"
29
30
#include " wfx_rsi.h"
30
31
32
+ #include " sl_status.h"
33
+
31
34
/* wfxRsi Task will use as its stack */
32
35
StackType_t wfxRsiTaskStack[WFX_RSI_TASK_SZ] = { 0 };
33
36
@@ -45,24 +48,16 @@ StaticTask_t wfxRsiTaskBuffer;
45
48
***********************************************************************/
46
49
sl_status_t wfx_wifi_start (void )
47
50
{
48
- if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED)
49
- {
50
- SILABS_LOG (" %s: already started." , __func__);
51
- return SL_STATUS_OK;
52
- }
51
+ VerifyOrReturnError (wfx_rsi.dev_state & WFX_RSI_ST_STARTED, SL_STATUS_OK);
53
52
wfx_rsi.dev_state |= WFX_RSI_ST_STARTED;
54
- SILABS_LOG (" %s: starting.." , __func__);
55
53
/*
56
54
* Create the Wifi driver task
57
55
*/
58
56
wfx_rsi.wlan_task = xTaskCreateStatic (wfx_rsi_task, " wfx_rsi" , WFX_RSI_TASK_SZ, NULL , WLAN_DRIVER_TASK_PRIORITY,
59
57
wfxRsiTaskStack, &wfxRsiTaskBuffer);
60
58
61
- if (NULL == wfx_rsi.wlan_task )
62
- {
63
- SILABS_LOG (" %s: error: failed to create task." , __func__);
64
- return SL_STATUS_FAIL;
65
- }
59
+ VerifyOrReturnError (wfx_rsi.wlan_task != NULL , SL_STATUS_FAIL);
60
+ ChipLogProgress (DeviceLayer, " wfx_rsi_task created successfully" );
66
61
return SL_STATUS_OK;
67
62
}
68
63
@@ -103,14 +98,12 @@ bool wfx_is_sta_mode_enabled(void)
103
98
***********************************************************************/
104
99
void wfx_get_wifi_mac_addr (sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr)
105
100
{
106
- if (addr)
107
- {
101
+ VerifyOrReturn (addr != NULL );
108
102
#ifdef SL_WFX_CONFIG_SOFTAP
109
- *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac ;
103
+ *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac ;
110
104
#else
111
- *addr = wfx_rsi.sta_mac ;
105
+ *addr = wfx_rsi.sta_mac ;
112
106
#endif
113
- }
114
107
}
115
108
116
109
/* ********************************************************************
@@ -123,11 +116,9 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t *
123
116
***********************************************************************/
124
117
void wfx_set_wifi_provision (wfx_wifi_provision_t * cfg)
125
118
{
126
- if (cfg)
127
- {
128
- wfx_rsi.sec = *cfg;
129
- wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED;
130
- }
119
+ VerifyOrReturn (cfg != NULL );
120
+ wfx_rsi.sec = *cfg;
121
+ wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED;
131
122
}
132
123
133
124
/* ********************************************************************
@@ -140,15 +131,10 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg)
140
131
***********************************************************************/
141
132
bool wfx_get_wifi_provision (wfx_wifi_provision_t * wifiConfig)
142
133
{
143
- if (wifiConfig != NULL )
144
- {
145
- if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED)
146
- {
147
- *wifiConfig = wfx_rsi.sec ;
148
- return true ;
149
- }
150
- }
151
- return false ;
134
+ VerifyOrReturnError (wifiConfig != NULL , false );
135
+ VerifyOrReturnError (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, false );
136
+ *wifiConfig = wfx_rsi.sec ;
137
+ return true ;
152
138
}
153
139
154
140
/* ********************************************************************
@@ -160,9 +146,10 @@ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig)
160
146
***********************************************************************/
161
147
void wfx_clear_wifi_provision (void )
162
148
{
149
+ VerifyOrReturn (wfx_rsi.sec != NULL );
163
150
memset (&wfx_rsi.sec , 0 , sizeof (wfx_rsi.sec ));
164
151
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED;
165
- SILABS_LOG ( " %s: completed. " , __func__ );
152
+ ChipLogProgress (DeviceLayer, " Clear WiFi Provision " );
166
153
}
167
154
168
155
/* ************************************************************************
@@ -175,18 +162,12 @@ void wfx_clear_wifi_provision(void)
175
162
****************************************************************************/
176
163
sl_status_t wfx_connect_to_ap (void )
177
164
{
165
+ VerifyOrReturnError (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, SL_STATUS_INVALID_CONFIGURATION);
166
+ // TODO: check for '\0' in SSID before printing
167
+ ChipLogProgress (DeviceLayer, " Connect to access point: %s" , wfx_rsi.sec .ssid );
178
168
WfxEvent_t event;
179
- if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED)
180
- {
181
- SILABS_LOG (" Connecting to access point -> SSID: %s" , &wfx_rsi.sec .ssid [0 ]);
182
- event.eventType = WFX_EVT_STA_START_JOIN;
183
- WfxPostEvent (&event);
184
- }
185
- else
186
- {
187
- SILABS_LOG (" Error: access point not provisioned." );
188
- return SL_STATUS_INVALID_CONFIGURATION;
189
- }
169
+ event.eventType = WFX_EVT_STA_START_JOIN;
170
+ WfxPostEvent (&event);
190
171
return SL_STATUS_OK;
191
172
}
192
173
@@ -202,11 +183,7 @@ sl_status_t wfx_connect_to_ap(void)
202
183
***********************************************************************/
203
184
sl_status_t wfx_power_save (rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state)
204
185
{
205
- if (wfx_rsi_power_save (sl_si91x_ble_state, sl_si91x_wifi_state) != SL_STATUS_OK)
206
- {
207
- return SL_STATUS_FAIL;
208
- }
209
- return SL_STATUS_OK;
186
+ return wfx_rsi_power_save (sl_si91x_ble_state, sl_si91x_wifi_state);
210
187
}
211
188
#endif /* SL_ICD_ENABLED */
212
189
@@ -223,7 +200,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
223
200
* TODO: Implement IPV6 setup, currently in wfx_rsi_task()
224
201
* This is hooked with MATTER code.
225
202
*/
226
- SILABS_LOG ( " %s: warning: not implemented. " , __func__) ;
203
+ return ;
227
204
}
228
205
229
206
/* ********************************************************************
@@ -237,7 +214,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
237
214
bool wfx_is_sta_connected (void )
238
215
{
239
216
bool status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0 ;
240
- SILABS_LOG ( " %s: %s" , __func__, (status ? " Connected " : " Disconnected " ));
217
+ ChipLogProgress (DeviceLayer, " Device %s to access point " , (status ? " connected " : " not connected " ));
241
218
return status;
242
219
}
243
220
@@ -266,11 +243,9 @@ wifi_mode_t wfx_get_wifi_mode()
266
243
***********************************************************************/
267
244
sl_status_t wfx_sta_discon (void )
268
245
{
269
- SILABS_LOG (" %s: started." , __func__);
270
- int32_t status;
246
+ sl_status_t status;
271
247
status = wfx_rsi_disconnect ();
272
248
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED;
273
- SILABS_LOG (" %s: completed." , __func__);
274
249
return status;
275
250
}
276
251
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
@@ -284,17 +259,8 @@ sl_status_t wfx_sta_discon(void)
284
259
***********************************************************************/
285
260
bool wfx_have_ipv4_addr (sl_wfx_interface_t which_if)
286
261
{
287
- bool status = false ;
288
- if (which_if == SL_WFX_STA_INTERFACE)
289
- {
290
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0 ;
291
- }
292
- else
293
- {
294
- status = false ; /* TODO */
295
- }
296
- SILABS_LOG (" %s: status: %d" , __func__, status);
297
- return status;
262
+ VerifyOrReturnError (which_if == SL_WFX_STA_INTERFACE, false );
263
+ return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0 );
298
264
}
299
265
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
300
266
@@ -308,17 +274,9 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if)
308
274
***********************************************************************/
309
275
bool wfx_have_ipv6_addr (sl_wfx_interface_t which_if)
310
276
{
311
- bool status = false ;
312
- if (which_if == SL_WFX_STA_INTERFACE)
313
- {
314
- status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0 ;
315
- }
316
- else
317
- {
318
- status = false ; /* TODO */
319
- }
320
- SILABS_LOG (" %s: %d" , __func__, status);
321
- return status;
277
+ VerifyOrReturnError (which_if == SL_WFX_STA_INTERFACE, false );
278
+ // TODO: WFX_RSI_ST_STA_CONNECTED does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG
279
+ return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0 );
322
280
}
323
281
324
282
/* ********************************************************************
@@ -384,21 +342,18 @@ int32_t wfx_reset_counts()
384
342
*******************************************************************************/
385
343
bool wfx_start_scan (char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
386
344
{
387
- int sz;
388
- WfxEvent_t event;
389
- if (wfx_rsi.scan_cb )
390
- return false ; /* Already in progress */
391
- if (ssid)
392
- {
393
- sz = strlen (ssid);
394
- if ((wfx_rsi.scan_ssid = (char *) pvPortMalloc (sz + 1 )) == (char *) 0 )
395
- {
396
- return false ;
397
- }
398
- strcpy (wfx_rsi.scan_ssid , ssid);
399
- }
345
+ // check if already in progress
346
+ VerifyOrReturnError (wfx_rsi.scan_cb != NULL , false );
400
347
wfx_rsi.scan_cb = callback;
401
348
349
+ VerifyOrReturnError (ssid != NULL , false );
350
+ size_t ssid_len;
351
+ ssid_len = strnlen (ssid, WFX_MAX_SSID_LENGTH);
352
+ wfx_rsi.scan_ssid = dynamic_cast <char *>(pvPortMalloc (ssid_len + 1 ));
353
+ VerifyOrReturnError (wfx_rsi.scan_ssid != NULL , false );
354
+ strncpy (wfx_rsi.scan_ssid , ssid, WFX_MAX_SSID_LENGTH);
355
+
356
+ WfxEvent_t event;
402
357
event.eventType = WFX_EVT_SCAN;
403
358
WfxPostEvent (&event);
404
359
@@ -416,6 +371,6 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
416
371
void wfx_cancel_scan (void )
417
372
{
418
373
/* Not possible */
419
- SILABS_LOG ( " %s: cannot cancel scan" , __func__ );
374
+ ChipLogError (DeviceLayer, " cannot cancel scan" );
420
375
}
421
376
#endif /* SL_WFX_CONFIG_SCAN */
0 commit comments