Skip to content

Commit b2687c8

Browse files
committed
Clean up of logs
1 parent c024e4f commit b2687c8

File tree

3 files changed

+129
-199
lines changed

3 files changed

+129
-199
lines changed

examples/platform/silabs/SiWx917/SiWx917/wfx_rsi_host.cpp

+46-91
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,22 @@
1515
* limitations under the License.
1616
*/
1717

18-
#include "stdbool.h"
18+
#include <stdbool.h>
1919
#include <stdio.h>
2020
#include <stdlib.h>
2121
#include <string.h>
2222

2323
#include "FreeRTOS.h"
2424
#include "event_groups.h"
25-
#include "silabs_utils.h"
26-
#include "sl_status.h"
2725
#include "task.h"
26+
27+
#include <lib/support/logging/CHIPLogging.h>
28+
2829
#include "wfx_host_events.h"
2930
#include "wfx_rsi.h"
3031

32+
#include "sl_status.h"
33+
3134
/* wfxRsi Task will use as its stack */
3235
StackType_t wfxRsiTaskStack[WFX_RSI_TASK_SZ] = { 0 };
3336

@@ -45,24 +48,16 @@ StaticTask_t wfxRsiTaskBuffer;
4548
***********************************************************************/
4649
sl_status_t wfx_wifi_start(void)
4750
{
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);
5352
wfx_rsi.dev_state |= WFX_RSI_ST_STARTED;
54-
SILABS_LOG("%s: starting..", __func__);
5553
/*
5654
* Create the Wifi driver task
5755
*/
5856
wfx_rsi.wlan_task = xTaskCreateStatic(wfx_rsi_task, "wfx_rsi", WFX_RSI_TASK_SZ, NULL, WLAN_DRIVER_TASK_PRIORITY,
5957
wfxRsiTaskStack, &wfxRsiTaskBuffer);
6058

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");
6661
return SL_STATUS_OK;
6762
}
6863

@@ -103,14 +98,12 @@ bool wfx_is_sta_mode_enabled(void)
10398
***********************************************************************/
10499
void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr)
105100
{
106-
if (addr)
107-
{
101+
VerifyOrReturn(addr != NULL);
108102
#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;
110104
#else
111-
*addr = wfx_rsi.sta_mac;
105+
*addr = wfx_rsi.sta_mac;
112106
#endif
113-
}
114107
}
115108

116109
/*********************************************************************
@@ -123,11 +116,9 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t *
123116
***********************************************************************/
124117
void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg)
125118
{
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;
131122
}
132123

133124
/*********************************************************************
@@ -140,15 +131,10 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg)
140131
***********************************************************************/
141132
bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig)
142133
{
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;
152138
}
153139

154140
/*********************************************************************
@@ -160,9 +146,10 @@ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig)
160146
***********************************************************************/
161147
void wfx_clear_wifi_provision(void)
162148
{
149+
VerifyOrReturn(wfx_rsi.sec != NULL);
163150
memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec));
164151
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED;
165-
SILABS_LOG("%s: completed.", __func__);
152+
ChipLogProgress(DeviceLayer, "Clear WiFi Provision");
166153
}
167154

168155
/*************************************************************************
@@ -175,18 +162,12 @@ void wfx_clear_wifi_provision(void)
175162
****************************************************************************/
176163
sl_status_t wfx_connect_to_ap(void)
177164
{
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);
178168
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);
190171
return SL_STATUS_OK;
191172
}
192173

@@ -202,11 +183,7 @@ sl_status_t wfx_connect_to_ap(void)
202183
***********************************************************************/
203184
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)
204185
{
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);
210187
}
211188
#endif /* SL_ICD_ENABLED */
212189

@@ -223,7 +200,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
223200
* TODO: Implement IPV6 setup, currently in wfx_rsi_task()
224201
* This is hooked with MATTER code.
225202
*/
226-
SILABS_LOG("%s: warning: not implemented.", __func__);
203+
return;
227204
}
228205

229206
/*********************************************************************
@@ -237,7 +214,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif)
237214
bool wfx_is_sta_connected(void)
238215
{
239216
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"));
241218
return status;
242219
}
243220

@@ -266,11 +243,9 @@ wifi_mode_t wfx_get_wifi_mode()
266243
***********************************************************************/
267244
sl_status_t wfx_sta_discon(void)
268245
{
269-
SILABS_LOG("%s: started.", __func__);
270-
int32_t status;
246+
sl_status_t status;
271247
status = wfx_rsi_disconnect();
272248
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED;
273-
SILABS_LOG("%s: completed.", __func__);
274249
return status;
275250
}
276251
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
@@ -284,17 +259,8 @@ sl_status_t wfx_sta_discon(void)
284259
***********************************************************************/
285260
bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if)
286261
{
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);
298264
}
299265
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
300266

@@ -308,17 +274,9 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if)
308274
***********************************************************************/
309275
bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if)
310276
{
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);
322280
}
323281

324282
/*********************************************************************
@@ -384,21 +342,18 @@ int32_t wfx_reset_counts()
384342
*******************************************************************************/
385343
bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
386344
{
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);
400347
wfx_rsi.scan_cb = callback;
401348

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;
402357
event.eventType = WFX_EVT_SCAN;
403358
WfxPostEvent(&event);
404359

@@ -416,6 +371,6 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *))
416371
void wfx_cancel_scan(void)
417372
{
418373
/* Not possible */
419-
SILABS_LOG("%s: cannot cancel scan", __func__);
374+
ChipLogError(DeviceLayer, "cannot cancel scan");
420375
}
421376
#endif /* SL_WFX_CONFIG_SCAN */

0 commit comments

Comments
 (0)