Skip to content

Commit

Permalink
Refactor SILABS_LOGS
Browse files Browse the repository at this point in the history
  • Loading branch information
brosahay committed Aug 11, 2024
1 parent e625cc8 commit da1d447
Showing 1 changed file with 47 additions and 55 deletions.
102 changes: 47 additions & 55 deletions examples/platform/silabs/efr32/rs911x/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
/*
* We should enable retry.. (Need config variable for this)
*/
SILABS_LOG("%s: failed. retry: %d", __func__, wfx_rsi.join_retries);
SILABS_LOG("wfx_rsi_join_cb: failed. retry: %d", wfx_rsi.join_retries);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
Expand All @@ -292,8 +292,8 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
/*
* Join was complete - Do the DHCP
*/
SILABS_LOG("wfx_rsi_join_cb: success");
memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t));
SILABS_LOG("%s: join completed.", __func__);
WfxEvent.eventType = WFX_EVT_STA_CONN;
WfxPostEvent(&WfxEvent);
wfx_rsi.join_retries = 0;
Expand All @@ -313,7 +313,7 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
*********************************************************************/
static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len)
{
SILABS_LOG("%s: error: failed status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_join_fail_cb: status: %02x", status);
WfxEvent_t WfxEvent;
wfx_rsi.join_retries += 1;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
Expand Down Expand Up @@ -354,31 +354,28 @@ static int32_t wfx_rsi_init(void)
uint8_t buf[RSI_RESPONSE_HOLD_BUFF_SIZE];
extern void rsi_hal_board_init(void);

SILABS_LOG("%s: starting(HEAP_SZ = %d)", __func__, SL_HEAP_SIZE);
SILABS_LOG("wfx_rsi_init: starting(HEAP_SZ = %d)", SL_HEAP_SIZE);
//! Driver initialization
status = rsi_driver_init(wfx_rsi_drv_buf, WFX_RSI_BUF_SZ);
if ((status < RSI_DRIVER_STATUS) || (status > WFX_RSI_BUF_SZ))
{
SILABS_LOG("%s: error: RSI Driver initialization failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_driver_init failed: %02x", status);
return status;
}

SILABS_LOG("%s: rsi_device_init", __func__);
/* ! Redpine module intialisation */
if ((status = rsi_device_init(LOAD_NWP_FW)) != RSI_SUCCESS)
{
SILABS_LOG("%s: error: rsi_device_init failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_device_init failed: %02x", status);
return status;
}
SILABS_LOG("%s: start wireless drv task", __func__);
/*
* Create the driver task
*/
wfx_rsi.drv_task = xTaskCreateStatic((TaskFunction_t) rsi_wireless_driver_task, "rsi_drv", WFX_RSI_WLAN_TASK_SZ, NULL,
WLAN_TASK_PRIORITY, driverRsiTaskStack, &driverRsiTaskBuffer);
if (NULL == wfx_rsi.drv_task)
{
SILABS_LOG("%s: error: rsi_wireless_driver_task failed", __func__);
SILABS_LOG("wfx_rsi_init: failed to create task");
return RSI_ERROR_INVALID_PARAM;
}

Expand All @@ -389,40 +386,38 @@ static int32_t wfx_rsi_init(void)
if ((status = rsi_wireless_init(OPER_MODE_0, COEX_MODE_0)) != RSI_SUCCESS)
{
#endif
SILABS_LOG("%s: error: Initialize WiSeConnect failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_wireless_init failed: %02x", status);
return status;
}

SILABS_LOG("%s: get FW version..", __func__);
/*
* Get the MAC and other info to let the user know about it.
*/
if (rsi_wlan_get(RSI_FW_VERSION, buf, sizeof(buf)) != RSI_SUCCESS)
{
SILABS_LOG("%s: error: rsi_wlan_get(RSI_FW_VERSION) failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_wlan_get(RSI_FW_VERSION) failed: %02x", status);
return status;
}

buf[sizeof(buf) - 1] = 0;
SILABS_LOG("%s: RSI firmware version: %s", __func__, buf);
SILABS_LOG("RSI firmware version: %s", buf);
//! Send feature frame
if ((status = rsi_send_feature_frame()) != RSI_SUCCESS)
{
SILABS_LOG("%s: error: rsi_send_feature_frame failed with status: %02x", __func__, status);
SILABS_LOG("error: rsi_send_feature_frame failed: %02x", status);
return status;
}

SILABS_LOG("%s: sent rsi_send_feature_frame", __func__);
/* initializes wlan radio parameters and WLAN supplicant parameters.
*/
(void) rsi_wlan_radio_init(); /* Required so we can get MAC address */
if ((status = rsi_wlan_get(RSI_MAC_ADDRESS, &wfx_rsi.sta_mac.octet[0], RESP_BUFF_SIZE)) != RSI_SUCCESS)
{
SILABS_LOG("%s: error: rsi_wlan_get failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_wlan_get(RSI_MAC_ADDRESS) failed: %02x", status);
return status;
}

SILABS_LOG("%s: WLAN: MAC %02x:%02x:%02x %02x:%02x:%02x", __func__, wfx_rsi.sta_mac.octet[0], wfx_rsi.sta_mac.octet[1],
SILABS_LOG("wfx_rsi_init: MAC: %02x:%02x:%02x %02x:%02x:%02x", wfx_rsi.sta_mac.octet[0], wfx_rsi.sta_mac.octet[1],
wfx_rsi.sta_mac.octet[2], wfx_rsi.sta_mac.octet[3], wfx_rsi.sta_mac.octet[4], wfx_rsi.sta_mac.octet[5]);

// Create the message queue
Expand All @@ -445,12 +440,12 @@ static int32_t wfx_rsi_init(void)
*/
if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS)
{
SILABS_LOG("%s: RSI callback register join failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_wlan_register_callbacks failed: %02x", status);
return status;
}
if ((status = rsi_wlan_register_callbacks(RSI_WLAN_DATA_RECEIVE_NOTIFY_CB, wfx_rsi_wlan_pkt_cb)) != RSI_SUCCESS)
{
SILABS_LOG("%s: RSI callback register data-notify failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_init: rsi_wlan_register_callbacks failed with status: %02x", status);
return status;
}

Expand All @@ -459,7 +454,7 @@ static int32_t wfx_rsi_init(void)
#endif

wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY;
SILABS_LOG("%s: RSI: OK", __func__);
SILABS_LOG("wfx_rsi_init: success");
return RSI_SUCCESS;
}

Expand Down Expand Up @@ -488,7 +483,7 @@ static void wfx_rsi_save_ap_info() // translation
#else /* !WIFI_ENABLE_SECURITY_WPA3_TRANSITION */
wfx_rsi.sec.security = WFX_SEC_WPA2;
#endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */
SILABS_LOG("%s: warn: failed with status: %02x", __func__, status);
SILABS_LOG("warn: scan failed with status: %02x", status);
return;
}
wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED;
Expand Down Expand Up @@ -524,7 +519,7 @@ static void wfx_rsi_save_ap_info() // translation
break;
}

SILABS_LOG("%s: WLAN: connecting to %s, sec=%d, status=%02x", __func__, &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security, status);
SILABS_LOG("wfx_rsi_save_ap_info: connecting to %s, sec=%d, status=%02x", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security, status);
}

/********************************************************************************************
Expand All @@ -541,7 +536,7 @@ static void wfx_rsi_do_join(void)

if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED))
{
SILABS_LOG("%s: not joining - already in progress", __func__);
SILABS_LOG("wfx_rsi_do_join: already in progress");
}
else
{
Expand All @@ -564,11 +559,11 @@ static void wfx_rsi_do_join(void)
connect_security_mode = RSI_OPEN;
break;
default:
SILABS_LOG("%s: error: unknown security type.", __func__);
SILABS_LOG("wfx_rsi_do_join: error: unknown security type.");
return;
}

SILABS_LOG("%s: WLAN: connecting to %s, sec=%d", __func__, &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security);
SILABS_LOG("wfx_rsi_do_join: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security);

/*
* Join the network
Expand All @@ -580,7 +575,7 @@ static void wfx_rsi_do_join(void)

if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS)
{
SILABS_LOG("%s: RSI callback register join failed with status: %02x", __func__, status);
SILABS_LOG("wfx_rsi_do_join: rsi_wlan_register_callbacks failed: %02x", status);
}

/* Try to connect Wifi with given Credentials
Expand All @@ -596,14 +591,14 @@ static void wfx_rsi_do_join(void)
{

wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
SILABS_LOG("%s: rsi_wlan_connect_async failed with status: %02x on try %d", __func__, status, wfx_rsi.join_retries);
SILABS_LOG("wfx_rsi_do_join: rsi_wlan_connect_async failed: %02x on try %d", status, wfx_rsi.join_retries);

wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
wfx_rsi.join_retries++;
}
else
{
SILABS_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0],
SILABS_LOG("wfx_rsi_do_join: starting join to %s after %d tries", (char *) &wfx_rsi.sec.ssid[0],
wfx_rsi.join_retries);
break; // exit while loop
}
Expand Down Expand Up @@ -701,7 +696,7 @@ void ProcessEvent(WfxEvent_t inEvent)
switch (inEvent.eventType)
{
case WFX_EVT_STA_CONN:
SILABS_LOG("%s: starting LwIP STA", __func__);
SILABS_LOG("_onWFXEvent: WFX_EVT_STA_CONN");
wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTED;
ResetDHCPNotificationFlags();
wfx_lwip_set_sta_link_up();
Expand All @@ -712,10 +707,10 @@ void ProcessEvent(WfxEvent_t inEvent)
// is independant of IP connectivity.
break;
case WFX_EVT_STA_DISCONN:
SILABS_LOG("_onWFXEvent: WFX_EVT_STA_DISCONN");
// TODO: This event is not being posted anywhere, seems to be a dead code or we are missing something
wfx_rsi.dev_state &=
~(WFX_RSI_ST_STA_READY | WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED | WFX_RSI_ST_STA_DHCP_DONE);
SILABS_LOG("%s: disconnect notify", __func__);
/* TODO: Implement disconnect notify */
ResetDHCPNotificationFlags();
wfx_lwip_set_sta_link_down(); // Internally dhcpclient_poll(netif) ->
Expand All @@ -736,32 +731,30 @@ void ProcessEvent(WfxEvent_t inEvent)
rsi_rsp_scan_t scan_rsp = { 0 };
int32_t status = rsi_wlan_bgscan_profile(1, &scan_rsp, sizeof(scan_rsp));

if (status)
if (status != RSI_SUCCESS)
{
SILABS_LOG("SSID scan failed: %02x ", status);
SILABS_LOG("rsi_wlan_bgscan failed: %02x ", status);
return;
}
else
rsi_scan_info_t * scan;
wfx_wifi_scan_result_t ap;
for (int x = 0; x < scan_rsp.scan_count[0]; x++)
{
rsi_scan_info_t * scan;
wfx_wifi_scan_result_t ap;
for (int x = 0; x < scan_rsp.scan_count[0]; x++)
scan = &scan_rsp.scan_info[x];
// is it a scan all or target scan
if (!wfx_rsi.scan_ssid || (wfx_rsi.scan_ssid && strcmp(wfx_rsi.scan_ssid, (char *) scan->ssid) == CMP_SUCCESS))
{
scan = &scan_rsp.scan_info[x];
// is it a scan all or target scan
if (!wfx_rsi.scan_ssid || (wfx_rsi.scan_ssid && strcmp(wfx_rsi.scan_ssid, (char *) scan->ssid) == CMP_SUCCESS))
strncpy(ap.ssid, (char *) scan->ssid, MIN(sizeof(ap.ssid), sizeof(scan->ssid)));
ap.security = scan->security_mode;
ap.rssi = (-1) * scan->rssi_val;
configASSERT(sizeof(ap.bssid) >= BSSID_LEN);
configASSERT(sizeof(scan->bssid) >= BSSID_LEN);
memcpy(ap.bssid, scan->bssid, BSSID_LEN);
(*wfx_rsi.scan_cb)(&ap);

if (wfx_rsi.scan_ssid)
{
strncpy(ap.ssid, (char *) scan->ssid, MIN(sizeof(ap.ssid), sizeof(scan->ssid)));
ap.security = scan->security_mode;
ap.rssi = (-1) * scan->rssi_val;
configASSERT(sizeof(ap.bssid) >= BSSID_LEN);
configASSERT(sizeof(scan->bssid) >= BSSID_LEN);
memcpy(ap.bssid, scan->bssid, BSSID_LEN);
(*wfx_rsi.scan_cb)(&ap);

if (wfx_rsi.scan_ssid)
{
break; // we found the targeted ssid.
}
break; // we found the targeted ssid.
}
}
}
Expand Down Expand Up @@ -813,7 +806,7 @@ void wfx_rsi_task(void * arg)
uint32_t rsi_status = wfx_rsi_init();
if (rsi_status != RSI_SUCCESS)
{
SILABS_LOG("%s: error: wfx_rsi_init with status: %02x", __func__, rsi_status);
SILABS_LOG("error: wfx_rsi_init with status: %02x", rsi_status);
return;
}
WfxEvent_t wfxEvent;
Expand Down Expand Up @@ -853,8 +846,7 @@ void wfx_dhcp_got_ipv4(uint32_t ip)
wfx_rsi.ip4_addr[1] = (ip >> 8) & HEX_VALUE_FF;
wfx_rsi.ip4_addr[2] = (ip >> 16) & HEX_VALUE_FF;
wfx_rsi.ip4_addr[3] = (ip >> 24) & HEX_VALUE_FF;
SILABS_LOG("%s: DHCP OK: IP=%d.%d.%d.%d", __func__, wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2],
wfx_rsi.ip4_addr[3]);
SILABS_LOG("DHCP OK: IP=%d.%d.%d.%d", wfx_rsi.ip4_addr[0], wfx_rsi.ip4_addr[1], wfx_rsi.ip4_addr[2], wfx_rsi.ip4_addr[3]);
/* Notify the Connectivity Manager - via the app */
wfx_rsi.dev_state |= WFX_RSI_ST_STA_DHCP_DONE;
wfx_ip_changed_notify(IP_STATUS_SUCCESS);
Expand Down

0 comments on commit da1d447

Please sign in to comment.