diff --git a/examples/platform/silabs/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp index cbef67996c4528..c61b91f7400879 100644 --- a/examples/platform/silabs/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -621,7 +621,7 @@ void BaseApplication::CancelFactoryResetSequence() if (sIsFactoryResetTriggered) { sIsFactoryResetTriggered = false; - ChipLogProgress(AppServer, "Factory Reset has been Canceled"); + ChipLogProgress(AppServer, "Factory Reset has been cancelled"); } } @@ -854,7 +854,7 @@ void BaseApplication::OnPlatformEvent(const ChipDeviceEvent * event, intptr_t) VerifyOrReturn(event->InternetConnectivityChange.IPv4 == kConnectivity_Established); if (DIC_OK != dic_init(dic::control::subscribeCB)) { - SILABS_LOG("Failed to initialize DIC module\n"); + ChipLogError(AppServer, "dic_init failed"); } #endif // DIC_ENABLE #ifdef DISPLAY_ENABLED diff --git a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp index ad3e15f6715c43..d283f05162bd54 100644 --- a/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp +++ b/examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp @@ -36,8 +36,12 @@ #include "task.h" #include "wfx_host_events.h" #include "wfx_rsi.h" + #include #include +#include +#include +#include #include extern "C" { @@ -120,7 +124,7 @@ static void DHCPTimerEventHandler(void * arg) WfxPostEvent(&event); } -static void CancelDHCPTimer() +static void CancelDHCPTimer(void) { osStatus_t status; @@ -164,8 +168,10 @@ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) { sl_status_t status = SL_STATUS_OK; int32_t rssi = 0; + ap->ssid_length = wfx_rsi.sec.ssid_length; ap->security = wfx_rsi.sec.security; ap->chan = wfx_rsi.ap_chan; + chip::Platform::CopyString(ap->ssid, ap->ssid_length, wfx_rsi.sec.ssid); memcpy(&ap->bssid[0], &wfx_rsi.ap_mac.octet[0], BSSID_LEN); sl_wifi_get_signal_strength(SL_WIFI_CLIENT_INTERFACE, &rssi); ap->rssi = rssi; @@ -197,14 +203,14 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) } /****************************************************************** - * @fn int32_t wfx_rsi_reset_count() + * @fn int32_t wfx_rsi_reset_count(void) * @brief * Getting the driver reset count * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_reset_count() +int32_t wfx_rsi_reset_count(void) { sl_wifi_statistics_t test = { 0 }; sl_status_t status = SL_STATUS_OK; @@ -221,14 +227,14 @@ int32_t wfx_rsi_reset_count() } /****************************************************************** - * @fn wfx_rsi_disconnect() + * @fn wfx_rsi_disconnect(void) * @brief * Getting the driver disconnect status * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_disconnect() +int32_t wfx_rsi_disconnect(void) { return sl_wifi_disconnect(SL_WIFI_CLIENT_INTERFACE); } @@ -251,18 +257,17 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t */ ChipLogDetail(DeviceLayer, "join_callback_handler: success"); memset(&temp_reset, 0, sizeof(temp_reset)); - - WfxEvent.eventType = WFX_EVT_STA_CONN; - WfxPostEvent(&WfxEvent); wfx_rsi.join_retries = 0; callback_status = SL_STATUS_OK; + WfxEvent.eventType = WFX_EVT_STA_CONN; + WfxPostEvent(&WfxEvent); return SL_STATUS_OK; } #if CHIP_CONFIG_ENABLE_ICD_SERVER #if SLI_SI91X_MCU_INTERFACE // Required to invoke button press event during sleep as falling edge is not detected -void sl_si91x_invoke_btn_press_event() +void sl_si91x_invoke_btn_press_event(void) { // TODO: should be removed once we are getting the press interrupt for button 0 with sleep if (!RSI_NPSSGPIO_GetPin(SL_BUTTON_BTN0_PIN) && !btn0_pressed) @@ -298,12 +303,12 @@ void sl_si91x_invoke_btn_press_event() #endif // SLI_SI91X_MCU_INTERFACE /****************************************************************** - * @fn wfx_rsi_power_save() + * @fn wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_si91x_performance_profile_t sl_si91x_wifi_state) * @brief * Setting the RS911x in DTIM sleep based mode * * @param[in] sl_si91x_ble_state : State to set for the BLE - sl_si91x_wifi_state : State to set for the WiFi + * @param[in] sl_si91x_wifi_state : State to set for the WiFi * @return * None *********************************************************************/ @@ -339,7 +344,7 @@ int32_t wfx_rsi_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_ *****************************************************************************************/ int32_t wfx_wifi_rsi_init(void) { - ChipLogDetail(DeviceLayer, "wfx_wifi_rsi_init started"); + ChipLogDetail(DeviceLayer, "wfx_wifi_rsi_init: started"); sl_status_t status; status = sl_wifi_init(&config, NULL, sl_wifi_default_event_handler); VerifyOrReturnError(status == SL_STATUS_OK, status); @@ -534,7 +539,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) for (int idx = 0; idx < (int) scan_result->scan_count; idx++) { memset(&cur_scan_result, 0, sizeof(cur_scan_result)); - strncpy(cur_scan_result.ssid, (char *) &scan_result->scan_info[idx].ssid, WFX_MAX_SSID_LENGTH); + + cur_scan_result.ssid_length = strnlen((char *) scan_result->scan_info[idx].ssid, + chip::min(sizeof(scan_result->scan_info[idx].ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(cur_scan_result.ssid, cur_scan_result.ssid_length, (char *) scan_result->scan_info[idx].ssid); // if user has provided ssid, then check if the current scan result ssid matches the user provided ssid if (wfx_rsi.scan_ssid != NULL && @@ -559,10 +567,10 @@ sl_status_t show_scan_results(sl_wifi_scan_result_t * scan_result) // cleanup and return wfx_rsi.dev_state &= ~WFX_RSI_ST_SCANSTARTED; wfx_rsi.scan_cb((wfx_wifi_scan_result_t *) 0); - wfx_rsi.scan_cb = NULL; + wfx_rsi.scan_cb = nullptr; if (wfx_rsi.scan_ssid) { - vPortFree(wfx_rsi.scan_ssid); + chip::Platform::MemoryFree(wfx_rsi.scan_ssid); wfx_rsi.scan_ssid = NULL; } return SL_STATUS_OK; @@ -576,14 +584,14 @@ sl_status_t bg_scan_callback_handler(sl_wifi_event_t event, sl_wifi_scan_result_ return SL_STATUS_OK; } /*************************************************************************************** - * @fn static void wfx_rsi_save_ap_info() + * @fn static void wfx_rsi_save_ap_info(void) * @brief * Saving the details of the AP * @param[in] None * @return * None *******************************************************************************************/ -static void wfx_rsi_save_ap_info() // translation +static void wfx_rsi_save_ap_info(void) // translation { sl_status_t status = SL_STATUS_OK; #ifndef EXP_BOARD @@ -592,8 +600,8 @@ static void wfx_rsi_save_ap_info() // translation #endif sl_wifi_ssid_t ssid_arg; memset(&ssid_arg, 0, sizeof(ssid_arg)); - ssid_arg.length = strnlen(wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); - strncpy((char *) &ssid_arg.value[0], wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); + ssid_arg.length = wfx_rsi.sec.ssid_length; + chip::Platform::CopyString((char *) &ssid_arg.value[0], ssid_arg.length, wfx_rsi.sec.ssid); sl_wifi_set_scan_callback(scan_callback_handler, NULL); scan_results_complete = false; #ifndef EXP_BOARD @@ -619,7 +627,7 @@ static sl_status_t wfx_rsi_do_join(void) sl_status_t status = SL_STATUS_OK; sl_wifi_client_configuration_t ap; memset(&ap, 0, sizeof(ap)); - WfxEvent_t event; + switch (wfx_rsi.sec.security) { case WFX_SEC_WEP: @@ -662,19 +670,17 @@ static sl_status_t wfx_rsi_do_join(void) status = sl_wifi_set_advanced_client_configuration(SL_WIFI_CLIENT_INTERFACE, &client_config); VerifyOrReturnError(status == SL_STATUS_OK, status); #endif // CHIP_CONFIG_ENABLE_ICD_SERVER - size_t psk_length = strlen(wfx_rsi.sec.passkey); - VerifyOrReturnError(psk_length <= SL_WIFI_MAX_PSK_LENGTH, SL_STATUS_SI91X_INVALID_PSK_LENGTH); sl_net_credential_id_t id = SL_NET_DEFAULT_WIFI_CLIENT_CREDENTIAL_ID; - status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], psk_length); + status = sl_net_set_credential(id, SL_NET_WIFI_PSK, &wfx_rsi.sec.passkey[0], wfx_rsi.sec.passkey_length); VerifyOrReturnError(status == SL_STATUS_OK, status); uint32_t timeout_ms = 0; - ap.ssid.length = strnlen(wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); + ap.ssid.length = wfx_rsi.sec.ssid_length; ap.encryption = SL_WIFI_NO_ENCRYPTION; ap.credential_id = id; - memset(&ap.ssid.value, 0, (sizeof(ap.ssid.value) / sizeof(ap.ssid.value[0]))); - strncpy((char *) &ap.ssid.value[0], wfx_rsi.sec.ssid, WFX_MAX_SSID_LENGTH); + memcpy((char *) &ap.ssid.value[0], wfx_rsi.sec.ssid, wfx_rsi.sec.ssid_length); ChipLogDetail(DeviceLayer, "wfx_rsi_do_join: SSID: %s, SECURITY: %d(%d)", ap.ssid.value, ap.security, wfx_rsi.sec.security); + status = sl_wifi_connect(SL_WIFI_CLIENT_INTERFACE, &ap, timeout_ms); // sl_wifi_connect returns SL_STATUS_IN_PROGRESS if join is in progress // after the initial scan is done, the scan does not check for SSID @@ -687,24 +693,25 @@ static sl_status_t wfx_rsi_do_join(void) wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED); ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: retry attempt %d", wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); + + WfxEvent_t event; event.eventType = WFX_EVT_STA_START_JOIN; WfxPostEvent(&event); + return status; } /// NotifyConnectivity /// @brief Notify the application about the connectivity status if it has not been notified yet. /// Helper function for HandleDHCPPolling. -void NotifyConnectivity() +void NotifyConnectivity(void) { - if (!hasNotifiedWifiConnectivity) - { - wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); - hasNotifiedWifiConnectivity = true; - } + VerifyOrReturn(!hasNotifiedWifiConnectivity); + wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &wfx_rsi.ap_mac); + hasNotifiedWifiConnectivity = true; } -void HandleDHCPPolling() +void HandleDHCPPolling(void) { struct netif * sta_netif; WfxEvent_t event; @@ -722,6 +729,8 @@ void HandleDHCPPolling() { wfx_dhcp_got_ipv4((uint32_t) sta_netif->ip_addr.u_addr.ip4.addr); hasNotifiedIPV4 = true; + event.eventType = WFX_EVT_STA_DHCP_DONE; + WfxPostEvent(&event); NotifyConnectivity(); } else if (dhcp_state == DHCP_OFF) @@ -760,7 +769,7 @@ void WfxPostEvent(WfxEvent_t * event) /// ResetDHCPNotificationFlags /// @brief Reset the flags that are used to notify the application about DHCP connectivity /// and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. -void ResetDHCPNotificationFlags() +void ResetDHCPNotificationFlags(void) { WfxEvent_t outEvent; @@ -877,7 +886,7 @@ void ProcessEvent(WfxEvent_t inEvent) /********************************************************************************* * @fn void wfx_rsi_task(void *arg) * @brief - * The main WLAN task - started by wfx_wifi_start () that interfaces with RSI. + * The main WLAN task - started by wfx_wifi_start() that interfaces with RSI. * The rest of RSI stuff come in call-backs. * The initialization has been already done. * @param[in] arg: diff --git a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp index d5560d69e97219..02500c80f78e35 100644 --- a/examples/platform/silabs/efr32/rs911x/rsi_if.cpp +++ b/examples/platform/silabs/efr32/rs911x/rsi_if.cpp @@ -54,10 +54,10 @@ extern "C" { #include "silabs_utils.h" #include "wfx_rsi.h" -// TODO convert this file to cpp and use CodeUtils.h -#ifndef MIN -#define MIN(a, b) ((a) < (b) ? (a) : (b)) -#endif +#include +#include +#include +#include #define WFX_QUEUE_SIZE 10 @@ -112,21 +112,21 @@ static void DHCPTimerEventHandler(void * arg) WfxPostEvent(&event); } -static void CancelDHCPTimer() +static void CancelDHCPTimer(void) { osStatus_t status; // Check if timer started if (!osTimerIsRunning(sDHCPTimer)) { - SILABS_LOG("CancelDHCPTimer: timer not running"); + ChipLogError(DeviceLayer, "CancelDHCPTimer: timer not running"); return; } status = osTimerStop(sDHCPTimer); if (status != osOK) { - SILABS_LOG("CancelDHCPTimer: failed to stop timer with status: %d", status); + ChipLogError(DeviceLayer, "CancelDHCPTimer: failed to stop timer with status: %d", status); } } @@ -140,7 +140,7 @@ static void StartDHCPTimer(uint32_t timeout) status = osTimerStart(sDHCPTimer, pdMS_TO_TICKS(timeout)); if (status != osOK) { - SILABS_LOG("StartDHCPTimer: failed to start timer with status: %d", status); + ChipLogError(DeviceLayer, "StartDHCPTimer: failed to start timer with status: %d", status); } } @@ -154,7 +154,7 @@ static void StartDHCPTimer(uint32_t timeout) *********************************************************************/ int32_t wfx_rsi_get_ap_info(wfx_wifi_scan_result_t * ap) { - int32_t status; + int32_t status = RSI_SUCCESS; uint8_t rssi; ap->security = wfx_rsi.sec.security; ap->chan = wfx_rsi.ap_chan; @@ -182,70 +182,65 @@ int32_t wfx_rsi_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) status = rsi_wlan_get(RSI_WLAN_EXT_STATS, buff, sizeof(buff)); if (status != RSI_SUCCESS) { - SILABS_LOG("Failed, Error Code : 0x%lX", status); - } - else - { - rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; - extra_info->beacon_lost_count = test->beacon_lost_count - temp_reset.beacon_lost_count; - extra_info->beacon_rx_count = test->beacon_rx_count - temp_reset.beacon_rx_count; - extra_info->mcast_rx_count = test->mcast_rx_count - temp_reset.mcast_rx_count; - extra_info->mcast_tx_count = test->mcast_tx_count - temp_reset.mcast_tx_count; - extra_info->ucast_rx_count = test->ucast_rx_count - temp_reset.ucast_rx_count; - extra_info->ucast_tx_count = test->ucast_tx_count - temp_reset.ucast_tx_count; - extra_info->overrun_count = test->overrun_count - temp_reset.overrun_count; + ChipLogError(DeviceLayer, "Failed, Error Code : 0x%lX", status); + return status; } + rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; + extra_info->beacon_lost_count = test->beacon_lost_count - temp_reset.beacon_lost_count; + extra_info->beacon_rx_count = test->beacon_rx_count - temp_reset.beacon_rx_count; + extra_info->mcast_rx_count = test->mcast_rx_count - temp_reset.mcast_rx_count; + extra_info->mcast_tx_count = test->mcast_tx_count - temp_reset.mcast_tx_count; + extra_info->ucast_rx_count = test->ucast_rx_count - temp_reset.ucast_rx_count; + extra_info->ucast_tx_count = test->ucast_tx_count - temp_reset.ucast_tx_count; + extra_info->overrun_count = test->overrun_count - temp_reset.overrun_count; return status; } /****************************************************************** - * @fn int32_t wfx_rsi_reset_count() + * @fn int32_t wfx_rsi_reset_count(void) * @brief * Getting the driver reset count * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_reset_count() +int32_t wfx_rsi_reset_count(void) { int32_t status; uint8_t buff[RSI_RESPONSE_MAX_SIZE] = { 0 }; status = rsi_wlan_get(RSI_WLAN_EXT_STATS, buff, sizeof(buff)); if (status != RSI_SUCCESS) { - SILABS_LOG("Failed, Error Code : 0x%lX", status); - } - else - { - rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; - temp_reset.beacon_lost_count = test->beacon_lost_count; - temp_reset.beacon_rx_count = test->beacon_rx_count; - temp_reset.mcast_rx_count = test->mcast_rx_count; - temp_reset.mcast_tx_count = test->mcast_tx_count; - temp_reset.ucast_rx_count = test->ucast_rx_count; - temp_reset.ucast_tx_count = test->ucast_tx_count; - temp_reset.overrun_count = test->overrun_count; + ChipLogError(DeviceLayer, "Failed, Error Code : 0x%lX", status); + return status; } + rsi_wlan_ext_stats_t * test = (rsi_wlan_ext_stats_t *) buff; + temp_reset.beacon_lost_count = test->beacon_lost_count; + temp_reset.beacon_rx_count = test->beacon_rx_count; + temp_reset.mcast_rx_count = test->mcast_rx_count; + temp_reset.mcast_tx_count = test->mcast_tx_count; + temp_reset.ucast_rx_count = test->ucast_rx_count; + temp_reset.ucast_tx_count = test->ucast_tx_count; + temp_reset.overrun_count = test->overrun_count; return status; } /****************************************************************** - * @fn wfx_rsi_disconnect() + * @fn wfx_rsi_disconnect(void) * @brief * Getting the driver disconnect status * @param[in] None * @return * status *********************************************************************/ -int32_t wfx_rsi_disconnect() +int32_t wfx_rsi_disconnect(void) { - int32_t status = rsi_wlan_disconnect(); - return status; + return rsi_wlan_disconnect(); } #if SL_ICD_ENABLED /****************************************************************** - * @fn wfx_rsi_power_save() + * @fn wfx_rsi_power_save(void) * @brief * Setting the RS911x in DTIM sleep based mode * @@ -253,14 +248,14 @@ int32_t wfx_rsi_disconnect() * @return * None *********************************************************************/ -int32_t wfx_rsi_power_save() +int32_t wfx_rsi_power_save(void) { int32_t status; #ifdef RSI_BLE_ENABLE status = rsi_bt_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP); if (status != RSI_SUCCESS) { - SILABS_LOG("BT Powersave Config Failed, Error Code : 0x%lX", status); + ChipLogError(DeviceLayer, "BT Powersave Config Failed, Error Code : 0x%lX", status); return status; } #endif /* RSI_BLE_ENABLE */ @@ -268,10 +263,10 @@ int32_t wfx_rsi_power_save() status = rsi_wlan_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP); if (status != RSI_SUCCESS) { - SILABS_LOG("Powersave Config Failed, Error Code : 0x%lX", status); + ChipLogError(DeviceLayer, "Powersave Config Failed, Error Code : 0x%lX", status); return status; } - SILABS_LOG("Powersave Config Success"); + ChipLogDetail(DeviceLayer, "Powersave Config Success"); return status; } #endif /* SL_ICD_ENABLED */ @@ -295,20 +290,19 @@ 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("wfx_rsi_join_cb: failed. retry: %d", wfx_rsi.join_retries); + ChipLogProgress(DeviceLayer, "wfx_rsi_join_cb: failed. retry: %d", wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); + return; } - else - { - /* - * Join was complete - Do the DHCP - */ - memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t)); - SILABS_LOG("wfx_rsi_join_cb: join completed."); - WfxEvent.eventType = WFX_EVT_STA_CONN; - WfxPostEvent(&WfxEvent); - wfx_rsi.join_retries = 0; - } + + /* + * Join was complete - Do the DHCP + */ + ChipLogProgress(DeviceLayer, "wfx_rsi_join_cb: success"); + memset(&temp_reset, 0, sizeof(wfx_wifi_scan_ext_t)); + WfxEvent.eventType = WFX_EVT_STA_CONN; + WfxPostEvent(&WfxEvent); + wfx_rsi.join_retries = 0; } /****************************************************************** @@ -323,7 +317,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("wfx_rsi_join_fail_cb: error: failed status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_join_fail_cb: status: %d", status); WfxEvent_t WfxEvent; wfx_rsi.join_retries += 1; wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED); @@ -363,30 +357,27 @@ static int32_t wfx_rsi_init(void) uint8_t buf[RSI_RESPONSE_HOLD_BUFF_SIZE]; extern void rsi_hal_board_init(void); - SILABS_LOG("wfx_rsi_init: starting(HEAP_SZ = %d)", SL_HEAP_SIZE); + ChipLogProgress(DeviceLayer, "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("wfx_rsi_init: error: RSI Driver initialization failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_driver_init failed: %ld", status); return status; } - - SILABS_LOG("wfx_rsi_init: rsi_device_init", __func__); /* ! Redpine module intialisation */ if ((status = rsi_device_init(LOAD_NWP_FW)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: error: rsi_device_init failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_device_init failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: start wireless drv task", __func__); /* * Create the driver wrapper thread */ sDrvThread = osThreadNew(rsi_wireless_driver_task_wrapper, NULL, &kDrvTaskAttr); if (NULL == sDrvThread) { - SILABS_LOG("wfx_rsi_init: error: rsi_wireless_driver_task failed", __func__); + ChipLogError(DeviceLayer, "wfx_rsi_init: failed to create task"); return RSI_ERROR_INVALID_PARAM; } @@ -397,41 +388,40 @@ static int32_t wfx_rsi_init(void) if ((status = rsi_wireless_init(OPER_MODE_0, COEX_MODE_0)) != RSI_SUCCESS) { #endif - SILABS_LOG("wfx_rsi_init: error: Initialize WiSeConnect failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wireless_init failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: 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("wfx_rsi_init: error: rsi_wlan_get(RSI_FW_VERSION) failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_get(RSI_FW_VERSION) failed: %ld", status); return status; } buf[sizeof(buf) - 1] = 0; - SILABS_LOG("wfx_rsi_init: RSI firmware version: %s", buf); + ChipLogProgress(DeviceLayer, "RSI firmware version: %s", buf); //! Send feature frame if ((status = rsi_send_feature_frame()) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: error: rsi_send_feature_frame failed with status: %02x", status); + ChipLogError(DeviceLayer, "error: rsi_send_feature_frame failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: 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("wfx_rsi_init: error: rsi_wlan_get failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_get(RSI_MAC_ADDRESS) failed: %ld", status); return status; } - SILABS_LOG("wfx_rsi_init: WLAN: 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]); + ChipLogDetail(DeviceLayer, "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 sWifiEventQueue = osMessageQueueNew(WFX_QUEUE_SIZE, sizeof(WfxEvent_t), NULL); @@ -453,12 +443,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("wfx_rsi_init: RSI callback register join failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_register_callbacks failed: %ld", status); return status; } if ((status = rsi_wlan_register_callbacks(RSI_WLAN_DATA_RECEIVE_NOTIFY_CB, wfx_rsi_wlan_pkt_cb)) != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_init: RSI callback register data-notify failed with status: %02x", status); + ChipLogError(DeviceLayer, "wfx_rsi_init: rsi_wlan_register_callbacks failed: %ld", status); return status; } @@ -467,26 +457,26 @@ static int32_t wfx_rsi_init(void) #endif wfx_rsi.dev_state |= WFX_RSI_ST_DEV_READY; - SILABS_LOG("wfx_rsi_init: RSI: OK", __func__); + ChipLogProgress(DeviceLayer, "wfx_rsi_init: success"); return RSI_SUCCESS; } /*************************************************************************************** - * @fn static void wfx_rsi_save_ap_info() + * @fn static void wfx_rsi_save_ap_info(void) * @brief * Saving the details of the AP * @param[in] None * @return * None *******************************************************************************************/ -static void wfx_rsi_save_ap_info() // translation +static void wfx_rsi_save_ap_info(void) // translation { int32_t status; rsi_rsp_scan_t rsp; status = rsi_wlan_scan_with_bitmap_options((int8_t *) &wfx_rsi.sec.ssid[0], AP_CHANNEL_NO_0, &rsp, sizeof(rsp), SCAN_BITMAP_OPTN_1); - if (status) + if (status != RSI_SUCCESS) { /* * Scan is done - failed @@ -496,7 +486,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("wfx_rsi_save_ap_info: warn: failed with status: %02x", status); + ChipLogProgress(DeviceLayer, "warn: scan failed: %ld", status); return; } wfx_rsi.sec.security = WFX_SEC_UNSPECIFIED; @@ -532,8 +522,8 @@ static void wfx_rsi_save_ap_info() // translation break; } - SILABS_LOG("wfx_rsi_save_ap_info: WLAN: connecting to %s, sec=%d, status=%02x", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security, - status); + ChipLogProgress(DeviceLayer, "wfx_rsi_save_ap_info: connecting to %s, sec=%d, status=%ld", &wfx_rsi.sec.ssid[0], + wfx_rsi.sec.security, status); } /******************************************************************************************** @@ -550,58 +540,56 @@ static void wfx_rsi_do_join(void) if (wfx_rsi.dev_state & (WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED)) { - SILABS_LOG("wfx_rsi_do_join: not joining - already in progress"); + ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: already in progress"); + return; } - else - { - switch (wfx_rsi.sec.security) - { - case WFX_SEC_WEP: - connect_security_mode = RSI_WEP; - break; - case WFX_SEC_WPA: - case WFX_SEC_WPA2: - connect_security_mode = RSI_WPA_WPA2_MIXED; - break; + switch (wfx_rsi.sec.security) + { + case WFX_SEC_WEP: + connect_security_mode = RSI_WEP; + break; + case WFX_SEC_WPA: + case WFX_SEC_WPA2: + connect_security_mode = RSI_WPA_WPA2_MIXED; + break; #if WIFI_ENABLE_SECURITY_WPA3_TRANSITION - case WFX_SEC_WPA3: - connect_security_mode = RSI_WPA3_PERSONAL_TRANSITION; - break; + case WFX_SEC_WPA3: + connect_security_mode = RSI_WPA3_PERSONAL_TRANSITION; + break; #endif // WIFI_ENABLE_SECURITY_WPA3_TRANSITION - case WFX_SEC_NONE: - connect_security_mode = RSI_OPEN; - break; - default: - SILABS_LOG("wfx_rsi_do_join: error: unknown security type."); - return; - } + case WFX_SEC_NONE: + connect_security_mode = RSI_OPEN; + break; + default: + ChipLogError(DeviceLayer, "wfx_rsi_do_join: error: unknown security type."); + return; + } - SILABS_LOG("wfx_rsi_do_join: WLAN: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security); + ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: connecting to %s, sec=%d", &wfx_rsi.sec.ssid[0], wfx_rsi.sec.security); - /* - * Join the network - */ - /* TODO - make the WFX_SECURITY_xxx - same as RSI_xxx - * Right now it's done by hand - we need something better - */ - wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING; + /* + * Join the network + */ + /* TODO - make the WFX_SECURITY_xxx - same as RSI_xxx + * Right now it's done by hand - we need something better + */ + wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING; - if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) - { - SILABS_LOG("wfx_rsi_do_join: RSI callback register join failed with status: %02x", status); - } + if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS) + { + ChipLogError(DeviceLayer, "wfx_rsi_do_join: rsi_wlan_register_callbacks failed: %ld", status); + } - /* Try to connect Wifi with given Credentials - * untill there is a success or maximum number of tries allowed - */ - if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], connect_security_mode, &wfx_rsi.sec.passkey[0], - wfx_rsi_join_cb)) != RSI_SUCCESS) - { - wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING; - SILABS_LOG("wfx_rsi_do_join: rsi_wlan_connect_async failed with status: %02x on try %d", status, wfx_rsi.join_retries); - wfx_retry_connection(++wfx_rsi.join_retries); - } + /* Try to connect Wifi with given Credentials + * until there is a success or maximum number of tries allowed + */ + if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], connect_security_mode, &wfx_rsi.sec.passkey[0], + wfx_rsi_join_cb)) != RSI_SUCCESS) + { + wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING; + ChipLogProgress(DeviceLayer, "wfx_rsi_do_join: rsi_wlan_connect_async failed: %ld on try %d", status, wfx_rsi.join_retries); + wfx_retry_connection(++wfx_rsi.join_retries); } } @@ -609,7 +597,7 @@ static void wfx_rsi_do_join(void) * @brief Notify the application about the connectivity status if it has not been notified yet. * Helper function for HandleDHCPPolling. */ -void NotifyConnectivity() +void NotifyConnectivity(void) { if (!hasNotifiedWifiConnectivity) { @@ -618,7 +606,7 @@ void NotifyConnectivity() } } -void HandleDHCPPolling() +void HandleDHCPPolling(void) { struct netif * sta_netif; WfxEvent_t event; @@ -628,7 +616,7 @@ void HandleDHCPPolling() { // TODO: Notify the application that the interface is not set up or Chipdie here because we // are in an unkonwn state - SILABS_LOG("HandleDHCPPolling: failed to get STA netif"); + ChipLogError(DeviceLayer, "HandleDHCPPolling: failed to get STA netif"); return; } #if (CHIP_DEVICE_CONFIG_ENABLE_IPV4) @@ -662,7 +650,7 @@ void HandleDHCPPolling() * @brief Reset the flags that are used to notify the application about DHCP connectivity * and emits a WFX_EVT_STA_DO_DHCP event to trigger DHCP polling checks. Helper function for ProcessEvent. */ -void ResetDHCPNotificationFlags() +void ResetDHCPNotificationFlags(void) { WfxEvent_t outEvent; @@ -685,19 +673,27 @@ void WfxPostEvent(WfxEvent_t * event) if (status != osOK) { - SILABS_LOG("WfxPostEvent: failed to post event with status: %d", status); + ChipLogError(DeviceLayer, "WfxPostEvent: failed to post event with status: %ld", status); // TODO: Handle error, requeue event depending on queue size or notify relevant task, // Chipdie, etc. } } +/** + * @brief Process the Wi-Fi event. + * + * This function is responsible for processing different types of Wi-Fi events and taking appropriate actions based on the event + * type. + * + * @param inEvent The input Wi-Fi event to be processed. + */ void ProcessEvent(WfxEvent_t inEvent) { // Process event switch (inEvent.eventType) { case WFX_EVT_STA_CONN: { - SILABS_LOG("Starting LwIP STA"); + ChipLogDetail(DeviceLayer, "_onWFXEvent: WFX_EVT_STA_CONN"); wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTED; ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_up(); @@ -709,10 +705,10 @@ void ProcessEvent(WfxEvent_t inEvent) } break; case WFX_EVT_STA_DISCONN: { + ChipLogDetail(DeviceLayer, "_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("Disconnect notify"); /* TODO: Implement disconnect notify */ ResetDHCPNotificationFlags(); wfx_lwip_set_sta_link_down(); // Internally dhcpclient_poll(netif) -> @@ -732,48 +728,64 @@ void ProcessEvent(WfxEvent_t inEvent) case WFX_EVT_SCAN: { #ifdef SL_WFX_CONFIG_SCAN rsi_rsp_scan_t scan_rsp = { 0 }; - int32_t status = rsi_wlan_bgscan_profile(1, &scan_rsp, sizeof(scan_rsp)); + memset(&scan_rsp, 0, sizeof(scan_rsp)); + 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); + ChipLogError(DeviceLayer, "rsi_wlan_bgscan failed: %ld ", status); + return; } - else + + if (wfx_rsi.scan_cb == NULL) + { + ChipLogError(DeviceLayer, "wfx_rsi.scan_cb is NULL"); + return; + } + + 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]; + // clear structure and calculate size of SSID + memset(&ap, 0, sizeof(ap)); + ap.ssid_length = + strnlen(reinterpret_cast(scan->ssid), chip::min(sizeof(scan->ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(ap.ssid, ap.ssid_length, reinterpret_cast(scan->ssid)); + + // check if the scanned ssid is the one we are looking for + if (wfx_rsi.scan_ssid_length != 0 && strncmp(wfx_rsi.scan_ssid, ap.ssid, WFX_MAX_SSID_LENGTH) != CMP_SUCCESS) { - scan = &scan_rsp.scan_info[x]; - // is it a scan all or target scan - if (wfx_rsi.scan_ssid != NULL && - (strncmp(wfx_rsi.scan_ssid, (char *) scan->ssid, MIN(strlen(wfx_rsi.scan_ssid), sizeof(scan->ssid))) == - CMP_SUCCESS)) - { - strncpy(ap.ssid, (char *) scan->ssid, MIN(sizeof(ap.ssid), sizeof(scan->ssid))); - ap.security = static_cast(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. - } - } + continue; // we found the targeted ssid. } + // TODO: convert security mode from RSI to WFX + ap.security = static_cast(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); + + // no ssid filter set, return all results + if (wfx_rsi.scan_ssid_length == 0) + { + continue; + } + + break; } /* Terminate with end of scan which is no ap sent back */ - (*wfx_rsi.scan_cb)((wfx_wifi_scan_result_t *) 0); - wfx_rsi.scan_cb = (void (*)(wfx_wifi_scan_result_t *)) 0; + (*wfx_rsi.scan_cb)((wfx_wifi_scan_result_t *) NULL); + wfx_rsi.scan_cb = nullptr; if (wfx_rsi.scan_ssid) { - vPortFree(wfx_rsi.scan_ssid); - wfx_rsi.scan_ssid = (char *) 0; + chip::Platform::MemoryFree(wfx_rsi.scan_ssid); + wfx_rsi.scan_ssid = NULL; } #endif /* SL_WFX_CONFIG_SCAN */ } @@ -819,14 +831,14 @@ void wfx_rsi_task(void * arg) uint32_t rsi_status = wfx_rsi_init(); if (rsi_status != RSI_SUCCESS) { - SILABS_LOG("wfx_rsi_task: error: wfx_rsi_init with status: %02x", rsi_status); + ChipLogError(DeviceLayer, "wfx_rsi_task: wfx_rsi_init failed: %ld", rsi_status); return; } WfxEvent_t wfxEvent; wfx_lwip_start(); wfx_started_notify(); - SILABS_LOG("Starting event loop"); + ChipLogProgress(DeviceLayer, "wfx_rsi_task: starting event loop"); for (;;) { osStatus_t status = osMessageQueueGet(sWifiEventQueue, &wfxEvent, NULL, osWaitForever); @@ -836,7 +848,7 @@ void wfx_rsi_task(void * arg) } else { - SILABS_LOG("Failed to get event with status: %x", status); + ChipLogProgress(DeviceLayer, "wfx_rsi_task: get event failed: %x", status); } } } @@ -859,8 +871,8 @@ 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("wfx_dhcp_got_ipv4: 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]); + ChipLogProgress(DeviceLayer, "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); @@ -875,14 +887,14 @@ void wfx_dhcp_got_ipv4(uint32_t ip) * see also: int32_t rsi_wlan_send_data_xx(uint8_t *buffer, uint32_t length) */ /******************************************************************************************** - * @fn void *wfx_rsi_alloc_pkt() + * @fn void *wfx_rsi_alloc_pkt(void) * @brief * Allocate packet to send data * @param[in] None * @return * None **********************************************************************************************/ -void * wfx_rsi_alloc_pkt() +void * wfx_rsi_alloc_pkt(void) { rsi_pkt_t * pkt; diff --git a/examples/platform/silabs/efr32/wf200/host_if.cpp b/examples/platform/silabs/efr32/wf200/host_if.cpp index 8247e385f61bcf..044ecc6e978cbd 100644 --- a/examples/platform/silabs/efr32/wf200/host_if.cpp +++ b/examples/platform/silabs/efr32/wf200/host_if.cpp @@ -42,6 +42,9 @@ #include "dhcp_client.h" #include "ethernetif.h" +#include +#include +#include #include using namespace ::chip; @@ -91,7 +94,7 @@ struct netif * sta_netif; wfx_wifi_provision_t wifi_provision; sl_wfx_get_counters_cnf_t * counters; sl_wfx_get_counters_cnf_t * Tempcounters; -#define PUT_COUNTER(name) SILABS_LOG("%-24s %lu\r\n", #name, (unsigned long) counters->body.count_##name); +#define PUT_COUNTER(name) ChipLogDetail(DeviceLayer, "%-24s %lu", #name, (unsigned long) counters->body.count_##name); bool hasNotifiedIPV6 = false; bool hasNotifiedIPV4 = false; @@ -108,6 +111,7 @@ static struct scan_result_holder static uint8_t scan_count = 0; static void (*scan_cb)(wfx_wifi_scan_result_t *); /* user-callback - when scan is done */ static char * scan_ssid; /* Which one are we scanning for */ +size_t scan_ssid_length = 0; static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_result); static void sl_wfx_scan_complete_callback(uint32_t status); #endif /* SL_WFX_CONFIG_SCAN */ @@ -133,7 +137,7 @@ extern uint32_t gOverrunCount; * @brief * Creates WFX events processing task. ******************************************************************************/ -static void wfx_events_task_start() +static void wfx_events_task_start(void) { /* create an event group to track Wi-Fi events */ sl_wfx_event_group = xEventGroupCreateStatic(&wfxEventGroup); @@ -142,7 +146,7 @@ static void wfx_events_task_start() wfxEventTaskStack, &wfxEventTaskBuffer); if (NULL == wfx_events_task_handle) { - SILABS_LOG("Failed to create WFX wfx_events"); + ChipLogError(DeviceLayer, "Failed to create WFX wfx_events"); } } @@ -159,7 +163,7 @@ sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload) { /******** INDICATION ********/ case SL_WFX_STARTUP_IND_ID: { - SILABS_LOG("WFX Startup Completed\r\n"); + ChipLogProgress(DeviceLayer, "startup completed."); PlatformMgrImpl().HandleWFXSystemEvent(WIFI_EVENT, event_payload); break; } @@ -237,34 +241,21 @@ sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload) } case SL_WFX_EXCEPTION_IND_ID: { sl_wfx_exception_ind_t * firmware_exception = (sl_wfx_exception_ind_t *) event_payload; - uint8_t * exception_tmp = (uint8_t *) firmware_exception; - SILABS_LOG("firmware exception\r\n"); - for (uint16_t i = 0; i < firmware_exception->header.length; i += 16) - { - SILABS_LOG("hif: %.8x:", i); - for (uint8_t j = 0; (j < 16) && ((i + j) < firmware_exception->header.length); j++) - { - SILABS_LOG(" %.2x", *exception_tmp); - exception_tmp++; - } - SILABS_LOG("\r\n"); - } + ChipLogError(DeviceLayer, "event: SL_WFX_EXCEPTION_IND_ID"); + ChipLogError(DeviceLayer, "firmware_exception->header.length: %d", firmware_exception->header.length); + // create a bytespan header.length with exception payload + ByteSpan exception_byte_span = ByteSpan((uint8_t *) firmware_exception, firmware_exception->header.length); + ChipLogByteSpan(DeviceLayer, exception_byte_span); break; } case SL_WFX_ERROR_IND_ID: { sl_wfx_error_ind_t * firmware_error = (sl_wfx_error_ind_t *) event_payload; - uint8_t * error_tmp = (uint8_t *) firmware_error; - SILABS_LOG("firmware error %lu\r\n", firmware_error->body.type); - for (uint16_t i = 0; i < firmware_error->header.length; i += 16) - { - SILABS_LOG("hif: %.8x:", i); - for (uint8_t j = 0; (j < 16) && ((i + j) < firmware_error->header.length); j++) - { - SILABS_LOG(" %.2x", *error_tmp); - error_tmp++; - } - SILABS_LOG("\r\n"); - } + ChipLogError(DeviceLayer, "event: SL_WFX_ERROR_IND_ID"); + ChipLogError(DeviceLayer, "firmware_error->type: %lu", firmware_error->body.type); + ChipLogError(DeviceLayer, "firmware_error->header.length: %d", firmware_error->header.length); + // create a bytespan header.length with error payload + ByteSpan error_byte_span = ByteSpan((uint8_t *) firmware_error, firmware_error->header.length); + ChipLogByteSpan(DeviceLayer, error_byte_span); break; } } @@ -282,28 +273,26 @@ static void sl_wfx_scan_result_callback(sl_wfx_scan_result_ind_body_t * scan_res { struct scan_result_holder * ap; - SILABS_LOG("# %2d %2d %03d %02X:%02X:%02X:%02X:%02X:%02X %s", scan_count, scan_result->channel, - ((int16_t) (scan_result->rcpi - 220) / 2), scan_result->mac[0], scan_result->mac[1], scan_result->mac[2], - scan_result->mac[3], scan_result->mac[4], scan_result->mac[5], scan_result->ssid_def.ssid); - /*Report one AP information*/ - SILABS_LOG("\r\n"); + ChipLogDetail(DeviceLayer, "# %2d %2d %03d %02X:%02X:%02X:%02X:%02X:%02X %s", scan_count, scan_result->channel, + ((int16_t) (scan_result->rcpi - 220) / 2), scan_result->mac[0], scan_result->mac[1], scan_result->mac[2], + scan_result->mac[3], scan_result->mac[4], scan_result->mac[5], scan_result->ssid_def.ssid); + /* Report one AP information */ /* don't save if filter only wants specific ssid */ - if (scan_ssid != (char *) 0) + if (scan_ssid != nullptr) { if (strcmp(scan_ssid, (char *) &scan_result->ssid_def.ssid[0]) != CMP_SUCCESS) return; } - if ((ap = (struct scan_result_holder *) pvPortMalloc(sizeof(*ap))) == (struct scan_result_holder *) 0) + if ((ap = (struct scan_result_holder *) (chip::Platform::MemoryAlloc(sizeof(*ap)))) == (struct scan_result_holder *) 0) { - SILABS_LOG("*ERR*Scan: No Mem"); + ChipLogError(DeviceLayer, "Scan: No Mem"); } else { ap->next = scan_save; scan_save = ap; /* Not checking if scan_result->ssid_length is < 33 */ - memcpy(ap->scan.ssid, scan_result->ssid_def.ssid, scan_result->ssid_def.ssid_length); - ap->scan.ssid[scan_result->ssid_def.ssid_length] = 0; /* make sure about null terminate */ + chip::Platform::CopyString(ap->scan.ssid, sizeof(ap->scan.ssid), (char *) &scan_result->ssid_def.ssid[0]); /* We do it in this order WPA3 first */ /* No EAP supported - Is this required */ ap->scan.security = WFX_SEC_UNSPECIFIED; @@ -363,7 +352,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication switch (status) { case WFM_STATUS_SUCCESS: { - SILABS_LOG("STA-Connected\r\n"); + ChipLogProgress(DeviceLayer, "STA-Connected"); memcpy(&ap_mac.octet[0], mac, MAC_ADDRESS_FIRST_OCTET); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_STA_INTERFACE_CONNECTED)); @@ -371,27 +360,27 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication break; } case WFM_STATUS_NO_MATCHING_AP: { - SILABS_LOG("WFX Connection failed, access point not found\r\n"); + ChipLogError(DeviceLayer, "Connection failed, access point not found"); break; } case WFM_STATUS_CONNECTION_ABORTED: { - SILABS_LOG("WFX Connection aborted\r\n"); + ChipLogError(DeviceLayer, "Connection aborted"); break; } case WFM_STATUS_CONNECTION_TIMEOUT: { - SILABS_LOG("WFX Connection timeout\r\n"); + ChipLogError(DeviceLayer, "Connection timeout"); break; } case WFM_STATUS_CONNECTION_REJECTED_BY_AP: { - SILABS_LOG("WFX Connection rejected by the access point\r\n"); + ChipLogError(DeviceLayer, "Connection rejected by the access point"); break; } case WFM_STATUS_CONNECTION_AUTH_FAILURE: { - SILABS_LOG("WFX Connection authentication failure\r\n"); + ChipLogError(DeviceLayer, "Connection authentication failure"); break; } default: { - SILABS_LOG("WF Connection attempt error\r\n"); + ChipLogError(DeviceLayer, "Connection attempt error"); } } @@ -399,7 +388,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication { retryJoin += 1; retryInProgress = false; - SILABS_LOG("WFX Retry to connect to network count: %d", retryJoin); + ChipLogProgress(DeviceLayer, "Retry to connect to network count: %d", retryJoin); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) & ~static_cast(SL_WFX_STARTED)); wfx_retry_connection(retryJoin); @@ -415,7 +404,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication static void sl_wfx_disconnect_callback(uint8_t * mac, uint16_t reason) { (void) (mac); - SILABS_LOG("WFX Disconnected %d\r\n", reason); + ChipLogProgress(DeviceLayer, "Disconnected %d", reason); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) & ~static_cast(SL_WFX_STA_INTERFACE_CONNECTED)); retryInProgress = false; @@ -430,18 +419,10 @@ static void sl_wfx_disconnect_callback(uint8_t * mac, uint16_t reason) *****************************************************************************/ static void sl_wfx_start_ap_callback(uint32_t status) { - if (status == AP_START_SUCCESS) - { - SILABS_LOG("AP started\r\n"); - sl_wfx_context->state = - static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_AP_INTERFACE_UP)); - xEventGroupSetBits(sl_wfx_event_group, SL_WFX_START_AP); - } - else - { - SILABS_LOG("AP start failed\r\n"); - strcpy(event_log, "AP start failed"); - } + VerifyOrReturnLogError(status == AP_START_SUCCESS, CHIP_ERROR_INTERNAL); + sl_wfx_context->state = + static_cast(static_cast(sl_wfx_context->state) | static_cast(SL_WFX_AP_INTERFACE_UP)); + xEventGroupSetBits(sl_wfx_event_group, SL_WFX_START_AP); } /**************************************************************************** @@ -452,7 +433,7 @@ static void sl_wfx_stop_ap_callback(void) { // TODO // dhcpserver_clear_stored_mac(); - SILABS_LOG("SoftAP stopped\r\n"); + ChipLogProgress(DeviceLayer, "SoftAP stopped"); sl_wfx_context->state = static_cast(static_cast(sl_wfx_context->state) & ~static_cast(SL_WFX_AP_INTERFACE_UP)); xEventGroupSetBits(sl_wfx_event_group, SL_WFX_STOP_AP); @@ -465,9 +446,8 @@ static void sl_wfx_stop_ap_callback(void) *****************************************************************************/ static void sl_wfx_client_connected_callback(uint8_t * mac) { - SILABS_LOG("Client connected, MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - // TODO - SILABS_LOG("Open a web browser and go to http://%d.%d.%d.%d\r\n", ap_ip_addr0, ap_ip_addr1, ap_ip_addr2, ap_ip_addr3); + ChipLogProgress(DeviceLayer, "Client connected, MAC: %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], + mac[5]); } /**************************************************************************** @@ -478,8 +458,8 @@ static void sl_wfx_client_connected_callback(uint8_t * mac) *****************************************************************************/ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac) { - SILABS_LOG("Client rejected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", (int) status, mac[0], mac[1], mac[2], mac[3], - mac[4], mac[5]); + ChipLogError(DeviceLayer, "Client rejected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X", (int) status, mac[0], mac[1], + mac[2], mac[3], mac[4], mac[5]); } /**************************************************************************** @@ -490,9 +470,8 @@ static void sl_wfx_ap_client_rejected_callback(uint32_t status, uint8_t * mac) *****************************************************************************/ static void sl_wfx_ap_client_disconnected_callback(uint32_t status, uint8_t * mac) { - // TODO - SILABS_LOG("Client disconnected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", (int) status, mac[0], mac[1], mac[2], - mac[3], mac[4], mac[5]); + ChipLogError(DeviceLayer, "Client disconnected, reason: %d, MAC: %02X:%02X:%02X:%02X:%02X:%02X", (int) status, mac[0], mac[1], + mac[2], mac[3], mac[4], mac[5]); } #endif /* SL_WFX_CONFIG_SOFTAP */ @@ -504,7 +483,6 @@ static void sl_wfx_ap_client_disconnected_callback(uint32_t status, uint8_t * ma static void sl_wfx_generic_status_callback(sl_wfx_generic_ind_t * frame) { (void) (frame); - SILABS_LOG("WFX Generic status received\r\n"); } /*************************************************************************** @@ -534,7 +512,7 @@ static void wfx_events_task(void * p_arg) pdTRUE, pdFALSE, pdMS_TO_TICKS(250)); /* 250 msec delay converted to ticks */ if (flags & SL_WFX_RETRY_CONNECT) { - SILABS_LOG("WFX sending the connect command"); + ChipLogProgress(DeviceLayer, "sending the connect command"); wfx_connect_to_ap(); } @@ -551,7 +529,7 @@ static void wfx_events_task(void * p_arg) hasNotifiedIPV4 = true; if (!hasNotifiedWifiConnectivity) { - SILABS_LOG("WIFI: Has Notified Wifi Connectivity"); + ChipLogProgress(DeviceLayer, "will notify WiFi connectivity"); wfx_connected_notify(CONNECTION_STATUS_SUCCESS, &ap_mac); hasNotifiedWifiConnectivity = true; } @@ -585,7 +563,7 @@ static void wfx_events_task(void * p_arg) wfx_ipv6_notify(GET_IPV6_FAIL); hasNotifiedIPV6 = false; hasNotifiedWifiConnectivity = false; - SILABS_LOG("WIFI: Connected to AP"); + ChipLogProgress(DeviceLayer, "connected to AP"); wifi_extra |= WE_ST_STA_CONN; retryJoin = 0; wfx_lwip_set_sta_link_up(); @@ -593,7 +571,7 @@ static void wfx_events_task(void * p_arg) if (!(wfx_get_wifi_state() & SL_WFX_AP_INTERFACE_UP)) { // Enable the power save - SILABS_LOG("WF200 going to DTIM based sleep"); + ChipLogProgress(DeviceLayer, "WF200 going to DTIM based sleep"); sl_wfx_set_power_mode(WFM_PM_MODE_DTIM, WFM_PM_POLL_FAST_PS, BEACON_1, 0 /*timeout*/); sl_wfx_enable_device_power_save(); } @@ -637,9 +615,10 @@ static void wfx_events_task(void * p_arg) sp = (sl_wfx_ssid_def_t *) 0; } - SILABS_LOG("WIFI Scan Paramter set to Active channel time %d, Passive " - "Channel Time: %d, Number of prob: %d", - ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); + ChipLogDetail(DeviceLayer, + "WIFI Scan Paramter set to Active channel time %d, Passive " + "Channel Time: %d, Number of prob: %d", + ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); (void) sl_wfx_set_scan_parameters(ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); (void) sl_wfx_send_scan_command(WFM_SCAN_MODE_ACTIVE, CHANNEL_LIST, /* Channel list */ CHANNEL_COUNT, /* Scan all chans */ @@ -650,20 +629,20 @@ static void wfx_events_task(void * p_arg) { struct scan_result_holder *hp, *next; - SILABS_LOG("WIFI: Return %d scan results", scan_count); + ChipLogDetail(DeviceLayer, "WIFI: Return %d scan results", scan_count); for (hp = scan_save; hp; hp = next) { next = hp->next; (*scan_cb)(&hp->scan); - vPortFree(hp); + chip::Platform::MemoryFree(hp); } (*scan_cb)((wfx_wifi_scan_result *) 0); scan_save = (struct scan_result_holder *) 0; scan_count = 0; if (scan_ssid) { - vPortFree(scan_ssid); - scan_ssid = (char *) 0; + chip::Platform::MemoryFree(scan_ssid); + scan_ssid = NULL; } /* Terminate scan */ scan_cb = 0; @@ -681,15 +660,15 @@ static sl_status_t wfx_init(void) /* Initialize the WF200 used by the two interfaces */ wfx_events_task_start(); sl_status_t status = sl_wfx_init(&wifiContext); - SILABS_LOG("FMAC Driver version %s", FMAC_DRIVER_VERSION_STRING); + ChipLogProgress(DeviceLayer, "FMAC Driver version: %s", FMAC_DRIVER_VERSION_STRING); switch (status) { case SL_STATUS_OK: - SILABS_LOG("WF200 FW ver:%d.%d.%d [MAC %02x:%02x:%02x-%02x:%02x:%02x]", wifiContext.firmware_major, - wifiContext.firmware_minor, wifiContext.firmware_build, wifiContext.mac_addr_0.octet[0], - wifiContext.mac_addr_0.octet[1], wifiContext.mac_addr_0.octet[2], wifiContext.mac_addr_0.octet[3], - wifiContext.mac_addr_0.octet[4], wifiContext.mac_addr_0.octet[5]); - SILABS_LOG("WF200 Init OK"); + ChipLogProgress(DeviceLayer, "WF200 FW ver:%d.%d.%d [MAC %02x:%02x:%02x-%02x:%02x:%02x]", wifiContext.firmware_major, + wifiContext.firmware_minor, wifiContext.firmware_build, wifiContext.mac_addr_0.octet[0], + wifiContext.mac_addr_0.octet[1], wifiContext.mac_addr_0.octet[2], wifiContext.mac_addr_0.octet[3], + wifiContext.mac_addr_0.octet[4], wifiContext.mac_addr_0.octet[5]); + ChipLogProgress(DeviceLayer, "WF200 Init OK"); if (wifiContext.state == SL_WFX_STA_INTERFACE_CONNECTED) { @@ -698,19 +677,19 @@ static sl_status_t wfx_init(void) break; case SL_STATUS_WIFI_INVALID_KEY: - SILABS_LOG("*ERR*WF200: F/W keyset invalid"); + ChipLogError(DeviceLayer, "WF200: F/W keyset invalid"); break; case SL_STATUS_WIFI_FIRMWARE_DOWNLOAD_TIMEOUT: - SILABS_LOG("*ERR*WF200: F/W download timo"); + ChipLogError(DeviceLayer, "WF200: F/W download timo"); break; case SL_STATUS_TIMEOUT: - SILABS_LOG("*ERR*WF200: Poll for value timo"); + ChipLogError(DeviceLayer, "WF200: Poll for value timo"); break; case SL_STATUS_FAIL: - SILABS_LOG("*ERR*WF200: Error"); + ChipLogError(DeviceLayer, "WF200: Error"); break; default: - SILABS_LOG("*ERR*WF200: Unknown"); + ChipLogError(DeviceLayer, "WF200: Unknown"); } return status; @@ -728,22 +707,22 @@ static void wfx_wifi_hw_start(void) if (wifi_extra & WE_ST_HW_STARTED) return; - SILABS_LOG("STARTING WF200\n"); + ChipLogDetail(DeviceLayer, "STARTING WF200"); wifi_extra |= WE_ST_HW_STARTED; sl_wfx_host_gpio_init(); if ((status = wfx_init()) == SL_STATUS_OK) { /* Initialize the LwIP stack */ - SILABS_LOG("WF200:Start LWIP"); + ChipLogDetail(DeviceLayer, "WF200:Start LWIP"); wfx_lwip_start(); wfx_started_notify(); wifiContext.state = SL_WFX_STARTED; /* Really this is a bit mask */ - SILABS_LOG("WF200:ready.."); + ChipLogDetail(DeviceLayer, "WF200:ready.."); } else { - SILABS_LOG("*ERR*WF200:init failed"); + ChipLogError(DeviceLayer, "WF200:init failed"); } } @@ -756,23 +735,22 @@ static void wfx_wifi_hw_start(void) int32_t wfx_get_ap_info(wfx_wifi_scan_result_t * ap) { int32_t signal_strength; - SILABS_LOG("WIFI:SSID:: %s", &ap_info.ssid[0]); - memcpy(ap->ssid, ap_info.ssid, sizeof(ap_info.ssid)); - SILABS_LOG("WIFI:Mac addr:: %02x:%02x:%02x:%02x:%02x:%02x", ap_info.bssid[0], ap_info.bssid[1], ap_info.bssid[2], - ap_info.bssid[3], ap_info.bssid[4], ap_info.bssid[5]); + + ap->ssid_length = strnlen(ap_info.ssid, chip::min(sizeof(ap_info.ssid), WFX_MAX_SSID_LENGTH)); + chip::Platform::CopyString(ap->ssid, ap->ssid_length, ap_info.ssid); memcpy(ap->bssid, ap_info.bssid, sizeof(ap_info.bssid)); ap->security = ap_info.security; - SILABS_LOG("WIFI:security:: %d", ap->security); - ap->chan = ap_info.chan; - SILABS_LOG("WIFI:Channel:: to %d", ap->chan); + ap->chan = ap_info.chan; + ChipLogDetail(DeviceLayer, "WIFI:SSID :: %s", &ap_info.ssid[0]); + ChipLogDetail(DeviceLayer, "WIFI:BSSID :: %02x:%02x:%02x:%02x:%02x:%02x", ap_info.bssid[0], ap_info.bssid[1], + ap_info.bssid[2], ap_info.bssid[3], ap_info.bssid[4], ap_info.bssid[5]); + ChipLogDetail(DeviceLayer, "WIFI:security :: %d", ap->security); + ChipLogDetail(DeviceLayer, "WIFI:channel :: %d", ap->chan); sl_status_t status = sl_wfx_get_signal_strength((uint32_t *) &signal_strength); - - if (status == SL_STATUS_OK) - { - SILABS_LOG("status SL_STATUS_OK & signal_strength:: %d", signal_strength); - ap->rssi = (signal_strength - 220) / 2; - } + VerifyOrReturnError(status == SL_STATUS_OK, status); + ChipLogDetail(DeviceLayer, "signal_strength: %ld", signal_strength); + ap->rssi = (signal_strength - 220) / 2; return status; } @@ -788,7 +766,7 @@ int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) status = get_all_counters(); if (status != SL_STATUS_OK) { - SILABS_LOG("Failed to get the couters"); + ChipLogError(DeviceLayer, "Failed to get the couters"); } else { @@ -808,15 +786,13 @@ sl_status_t get_all_counters(void) sl_status_t result; uint8_t command_id = 0x05; uint16_t mib_id = 0x2035; - sl_wfx_mib_req_t * request = NULL; + sl_wfx_mib_req_t * request = nullptr; uint32_t request_length = SL_WFX_ROUND_UP_EVEN(sizeof(sl_wfx_header_mib_t) + sizeof(sl_wfx_mib_req_body_t)); result = sl_wfx_allocate_command_buffer((sl_wfx_generic_message_t **) &request, command_id, SL_WFX_CONTROL_BUFFER, request_length); - if (request == NULL) - { - } + VerifyOrReturnError(request != nullptr, SL_STATUS_NULL_POINTER); request->body.mib_id = mib_id; request->header.interface = 0x2; @@ -828,8 +804,8 @@ sl_status_t get_all_counters(void) result = sl_wfx_host_wait_for_confirmation(command_id, SL_WFX_DEFAULT_REQUEST_TIMEOUT_MS, (void **) &counters); SL_WFX_ERROR_CHECK(result); - SILABS_LOG("%-24s %12s \r\n", "", "Debug Counters Content"); - SILABS_LOG("%-24s %lu\r\n", "rcpi", (unsigned long) counters->body.rcpi); + ChipLogDetail(DeviceLayer, "%-24s %12s ", "", "Debug Counters Content"); + ChipLogDetail(DeviceLayer, "%-24s %lu", "rcpi", (unsigned long) counters->body.rcpi); PUT_COUNTER(plcp_errors); PUT_COUNTER(fcs_errors); PUT_COUNTER(tx_packets); @@ -865,7 +841,7 @@ sl_status_t get_all_counters(void) sl_wfx_context->used_buffers--; } } - if (request != NULL) + if (request != nullptr) { sl_wfx_free_command_buffer((sl_wfx_generic_message_t *) request, command_id, SL_WFX_CONTROL_BUFFER); } @@ -878,7 +854,7 @@ sl_status_t get_all_counters(void) * reset the count * @return returns -1 **************************************************************************/ -int32_t wfx_reset_counts() +int32_t wfx_reset_counts(void) { /* TODO */ return -1; @@ -893,7 +869,7 @@ sl_status_t wfx_wifi_start(void) { if (wifi_extra & WE_ST_STARTED) { - SILABS_LOG("WIFI: Already started"); + ChipLogDetail(DeviceLayer, "WIFI: Already started"); return SL_STATUS_OK; } wifi_extra |= WE_ST_STARTED; @@ -921,7 +897,7 @@ sl_wfx_state_t wfx_get_wifi_state(void) *****************************************************************************/ struct netif * wfx_GetNetif(sl_wfx_interface_t interface) { - struct netif * SelectedNetif = NULL; + struct netif * SelectedNetif = nullptr; if (interface == SL_WFX_STA_INTERFACE) { SelectedNetif = sta_netif; @@ -955,10 +931,10 @@ sl_wfx_mac_address_t wfx_get_wifi_mac_addr(sl_wfx_interface_t interface) *****************************************************************************/ void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig) { - memcpy(wifi_provision.ssid, wifiConfig->ssid, sizeof(wifiConfig->ssid)); - memcpy(wifi_provision.passkey, wifiConfig->passkey, sizeof(wifiConfig->passkey)); + Platform::CopyString(wifi_provision.ssid, sizeof(wifi_provision.ssid), wifiConfig->ssid); + Platform::CopyString(wifi_provision.passkey, sizeof(wifi_provision.passkey), wifiConfig->passkey); wifi_provision.security = wifiConfig->security; - SILABS_LOG("WIFI: Provision SSID=%s", &wifi_provision.ssid[0]); + ChipLogProgress(DeviceLayer, "WIFI: Provision SSID=%s", &wifi_provision.ssid[0]); } /**************************************************************************** @@ -970,12 +946,8 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * wifiConfig) *****************************************************************************/ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) { - if (wifiConfig == NULL) - { - return false; - } + VerifyOrReturnError(wifiConfig != nullptr, false); memcpy(wifiConfig, &wifi_provision, sizeof(wfx_wifi_provision_t)); - return true; } @@ -1012,15 +984,13 @@ sl_status_t wfx_connect_to_ap(void) sl_status_t result; sl_wfx_security_mode_t connect_security_mode; - if (wifi_provision.ssid[0] == 0) - { - return SL_STATUS_NOT_AVAILABLE; - } - SILABS_LOG("WIFI:JOIN to %s", &wifi_provision.ssid[0]); + VerifyOrReturnError(wifi_provision.ssid[0], SL_STATUS_NOT_AVAILABLE); + ChipLogDetail(DeviceLayer, "WIFI:JOIN to %s", &wifi_provision.ssid[0]); - SILABS_LOG("WIFI Scan Paramter set to Active channel time %d, Passive Channel " - "Time: %d, Number of prob: %d", - ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); + ChipLogDetail(DeviceLayer, + "WIFI Scan Paramter set to Active channel time %d, Passive Channel " + "Time: %d, Number of prob: %d", + ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); (void) sl_wfx_set_scan_parameters(ACTIVE_CHANNEL_TIME, PASSIVE_CHANNEL_TIME, NUM_PROBE_REQUEST); switch (wifi_provision.security) { @@ -1038,7 +1008,7 @@ sl_status_t wfx_connect_to_ap(void) connect_security_mode = sl_wfx_security_mode_e::WFM_SECURITY_MODE_OPEN; break; default: - SILABS_LOG("%s: error: unknown security type."); + ChipLogError(DeviceLayer, "error: unknown security type."); return SL_STATUS_INVALID_STATE; } result = sl_wfx_send_join_command((uint8_t *) wifi_provision.ssid, strlen(wifi_provision.ssid), NULL, CHANNEL_0, @@ -1064,8 +1034,8 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * mac = &wifiContext.mac_addr_0; #endif *addr = *mac; - SILABS_LOG("WLAN:Get WiFi Mac addr %02x:%02x:%02x:%02x:%02x:%02x", mac->octet[0], mac->octet[1], mac->octet[2], mac->octet[3], - mac->octet[4], mac->octet[5]); + ChipLogDetail(DeviceLayer, "WLAN:Get WiFi Mac addr %02x:%02x:%02x:%02x:%02x:%02x", mac->octet[0], mac->octet[1], mac->octet[2], + mac->octet[3], mac->octet[4], mac->octet[5]); memcpy(&ap_info.bssid[0], &mac->octet[0], 6); } @@ -1078,14 +1048,8 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * *****************************************************************************/ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) { - if (which_if == SL_WFX_STA_INTERFACE) - { - return (sta_ip == STA_IP_FAIL) ? false : true; - } - else - { - return false; /* TODO */ - } + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return (sta_ip == STA_IP_FAIL) ? false : true; } /**************************************************************************** @@ -1097,18 +1061,8 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) *****************************************************************************/ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) { - SILABS_LOG("%s: started.", __func__); - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = wfx_is_sta_connected(); - } - else - { - status = false; /* TODO */ - } - SILABS_LOG("%s: status: %d", __func__, status); - return status; + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return wfx_is_sta_connected(); } /**************************************************************************** @@ -1119,7 +1073,7 @@ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) *****************************************************************************/ sl_status_t wfx_sta_discon(void) { - SILABS_LOG("STA-Disconnecting"); + ChipLogProgress(DeviceLayer, "STA-Disconnecting"); int32_t status = sl_wfx_send_disconnect_command(); wifi_extra &= ~WE_ST_STA_CONN; xEventGroupSetBits(sl_wfx_event_group, SL_WFX_RETRY_CONNECT); @@ -1145,11 +1099,7 @@ bool wfx_is_sta_mode_enabled(void) bool wfx_is_sta_connected(void) { bool val; - val = (wifi_extra & WE_ST_STA_CONN) ? true : false; - - SILABS_LOG("WLAN: STA %s connected", (val ? "IS" : "NOT")); - return val; } @@ -1159,10 +1109,7 @@ bool wfx_is_sta_connected(void) * @return returns true if sucessful, * false otherwise *****************************************************************************/ -void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) -{ - SILABS_LOG("Setup-IP6: TODO"); /* It is automatically done when lwip link up */ -} +void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) {} /**************************************************************************** * @brief @@ -1170,7 +1117,7 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) * @return returns WIFI_MODE_NULL if sucessful, * WIFI_MODE_STA otherwise *****************************************************************************/ -wifi_mode_t wfx_get_wifi_mode() +wifi_mode_t wfx_get_wifi_mode(void) { if (wifiContext.state & SL_WFX_STARTED) return WIFI_MODE_STA; @@ -1234,22 +1181,16 @@ void wfx_enable_sta_mode(void) #ifdef SL_WFX_CONFIG_SCAN bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { - int sz; - - if (scan_cb) - return false; /* Already in progress */ + VerifyOrReturnError(scan_cb != nullptr, false); if (ssid) { - sz = strlen(ssid); - if ((scan_ssid = (char *) pvPortMalloc(sz + 1)) == (char *) 0) - { - return false; - } - strcpy(scan_ssid, ssid); + scan_ssid_length = strnlen(ssid, WFX_MAX_SSID_LENGTH); + scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(scan_ssid_length)); + VerifyOrReturnError(scan_ssid != nullptr, false); + Platform::CopyString(scan_ssid, scan_ssid_length, ssid); } scan_cb = callback; xEventGroupSetBits(sl_wfx_event_group, SL_WFX_SCAN_START); - return true; } @@ -1261,23 +1202,20 @@ void wfx_cancel_scan(void) { struct scan_result_holder *hp, *next; /* Not possible */ - if (!scan_cb) - { - return; - } + VerifyOrReturn(scan_cb != nullptr); sl_wfx_send_stop_scan_command(); for (hp = scan_save; hp; hp = next) { next = hp->next; - vPortFree(hp); + chip::Platform::MemoryFree(hp); } scan_save = (struct scan_result_holder *) 0; scan_count = 0; if (scan_ssid) { - vPortFree(scan_ssid); - scan_ssid = (char *) 0; + chip::Platform::MemoryFree(scan_ssid); + scan_ssid = nullptr; } - scan_cb = 0; + scan_cb = nullptr; } #endif /* SL_WFX_CONFIG_SCAN */ diff --git a/examples/platform/silabs/wfx_rsi.h b/examples/platform/silabs/wfx_rsi.h index 5e7358e0d02cb1..0e62cb78029a79 100644 --- a/examples/platform/silabs/wfx_rsi.h +++ b/examples/platform/silabs/wfx_rsi.h @@ -77,6 +77,7 @@ typedef struct wfx_rsi_s #ifdef SL_WFX_CONFIG_SCAN void (*scan_cb)(wfx_wifi_scan_result_t *); char * scan_ssid; /* Which one are we scanning for */ + size_t scan_ssid_length; #endif #ifdef SL_WFX_CONFIG_SOFTAP sl_wfx_mac_address_t softap_mac; diff --git a/examples/platform/silabs/wifi/wfx_notify.cpp b/examples/platform/silabs/wifi/wfx_notify.cpp index e1d3c81abf8504..de1becacb33b30 100644 --- a/examples/platform/silabs/wifi/wfx_notify.cpp +++ b/examples/platform/silabs/wifi/wfx_notify.cpp @@ -60,13 +60,13 @@ static void RetryConnectionTimerHandler(void * arg) } } /*********************************************************************************** - * @fn wfx_started_notify() + * @fn wfx_started_notify(void) * @brief * Wifi device started notification * @param[in]: None * @return None *************************************************************************************/ -void wfx_started_notify() +void wfx_started_notify(void) { sl_wfx_startup_ind_t evt; sl_wfx_mac_address_t mac; diff --git a/examples/platform/silabs/wifi/wfx_rsi_host.cpp b/examples/platform/silabs/wifi/wfx_rsi_host.cpp index 921ec82587fe77..130d9c90d19817 100644 --- a/examples/platform/silabs/wifi/wfx_rsi_host.cpp +++ b/examples/platform/silabs/wifi/wfx_rsi_host.cpp @@ -15,16 +15,20 @@ * limitations under the License. */ -#include "stdbool.h" +#include #include #include #include #include "FreeRTOS.h" #include "event_groups.h" -#include "silabs_utils.h" -#include "sl_status.h" #include "task.h" + +#include +#include +#include +#include + #include "wfx_host_events.h" #include "wfx_rsi.h" @@ -54,22 +58,15 @@ constexpr osThreadAttr_t kWlanTaskAttr = { .name = "wlan_rsi", ***********************************************************************/ sl_status_t wfx_wifi_start(void) { - if (wfx_rsi.dev_state & WFX_RSI_ST_STARTED) - { - return SL_STATUS_OK; - } - + VerifyOrReturnError(!(wfx_rsi.dev_state & WFX_RSI_ST_STARTED), SL_STATUS_OK); wfx_rsi.dev_state |= WFX_RSI_ST_STARTED; - SILABS_LOG("%s: starting..", __func__); - /* - * Create the Wifi driver task - */ // Creating a Wi-Fi driver thread sWlanThread = osThreadNew(wfx_rsi_task, NULL, &kWlanTaskAttr); VerifyOrReturnError(sWlanThread != NULL, SL_STATUS_FAIL); + ChipLogProgress(DeviceLayer, "wfx_rsi_task created successfully"); return SL_STATUS_OK; } @@ -110,14 +107,12 @@ bool wfx_is_sta_mode_enabled(void) ***********************************************************************/ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * addr) { - if (addr) - { + VerifyOrReturn(addr != nullptr); #ifdef SL_WFX_CONFIG_SOFTAP - *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; + *addr = (interface == SL_WFX_SOFTAP_INTERFACE) ? wfx_rsi.softap_mac : wfx_rsi.sta_mac; #else - *addr = wfx_rsi.sta_mac; + *addr = wfx_rsi.sta_mac; #endif - } } /********************************************************************* @@ -130,11 +125,9 @@ void wfx_get_wifi_mac_addr(sl_wfx_interface_t interface, sl_wfx_mac_address_t * ***********************************************************************/ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) { - if (cfg) - { - wfx_rsi.sec = *cfg; - wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED; - } + VerifyOrReturn(cfg != nullptr); + wfx_rsi.sec = *cfg; + wfx_rsi.dev_state |= WFX_RSI_ST_STA_PROVISIONED; } /********************************************************************* @@ -147,15 +140,10 @@ void wfx_set_wifi_provision(wfx_wifi_provision_t * cfg) ***********************************************************************/ bool wfx_get_wifi_provision(wfx_wifi_provision_t * wifiConfig) { - if (wifiConfig != NULL) - { - if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) - { - *wifiConfig = wfx_rsi.sec; - return true; - } - } - return false; + VerifyOrReturnError(wifiConfig != nullptr, false); + VerifyOrReturnError(wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, false); + *wifiConfig = wfx_rsi.sec; + return true; } /********************************************************************* @@ -169,7 +157,7 @@ void wfx_clear_wifi_provision(void) { memset(&wfx_rsi.sec, 0, sizeof(wfx_rsi.sec)); wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_PROVISIONED; - SILABS_LOG("%s: completed.", __func__); + ChipLogProgress(DeviceLayer, "Clear WiFi Provision"); } /************************************************************************* @@ -177,30 +165,25 @@ void wfx_clear_wifi_provision(void) * @brief * Start a JOIN command to the AP - Done by the wfx_rsi task * @param[in] None - * @return returns SL_STATUS_OK if successful, - * SL_STATUS_INVALID_CONFIGURATION otherwise + * @return returns SL_STATUS_OK if successful ****************************************************************************/ sl_status_t wfx_connect_to_ap(void) { + VerifyOrReturnError(wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED, SL_STATUS_INVALID_CONFIGURATION); + VerifyOrReturnError(wfx_rsi.sec.ssid_length, SL_STATUS_INVALID_CREDENTIALS); + VerifyOrReturnError(wfx_rsi.sec.ssid_length <= WFX_MAX_SSID_LENGTH, SL_STATUS_HAS_OVERFLOWED); + ChipLogProgress(DeviceLayer, "connect to access point: %s", wfx_rsi.sec.ssid); WfxEvent_t event; - if (wfx_rsi.dev_state & WFX_RSI_ST_STA_PROVISIONED) - { - SILABS_LOG("Connecting to access point -> SSID: %s", &wfx_rsi.sec.ssid[0]); - event.eventType = WFX_EVT_STA_START_JOIN; - WfxPostEvent(&event); - } - else - { - SILABS_LOG("Error: access point not provisioned."); - return SL_STATUS_INVALID_CONFIGURATION; - } + event.eventType = WFX_EVT_STA_START_JOIN; + WfxPostEvent(&event); return SL_STATUS_OK; } #if SL_ICD_ENABLED #if SLI_SI917 /********************************************************************* - * @fn sl_status_t wfx_power_save() + * @fn 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) * @brief * Implements the power save in sleepy application * @param[in] sl_si91x_ble_state : State to set for the BLE @@ -214,14 +197,14 @@ sl_status_t wfx_power_save(rsi_power_save_profile_mode_t sl_si91x_ble_state, sl_ } #else // For RS9116 /********************************************************************* - * @fn sl_status_t wfx_power_save() + * @fn sl_status_t wfx_power_save(void) * @brief * Implements the power save in sleepy application * @param[in] None * @return SL_STATUS_OK if successful, * SL_STATUS_FAIL otherwise ***********************************************************************/ -sl_status_t wfx_power_save() +sl_status_t wfx_power_save(void) { return (wfx_rsi_power_save() ? SL_STATUS_FAIL : SL_STATUS_OK); } @@ -241,7 +224,6 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) * TODO: Implement IPV6 setup, currently in wfx_rsi_task() * This is hooked with MATTER code. */ - SILABS_LOG("%s: warning: not implemented.", __func__); } /********************************************************************* @@ -255,19 +237,18 @@ void wfx_setup_ip6_link_local(sl_wfx_interface_t whichif) bool wfx_is_sta_connected(void) { bool status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0; - SILABS_LOG("%s: %s", __func__, (status ? "Connected" : "Disconnected")); return status; } /********************************************************************* - * @fn wifi_mode_t wfx_get_wifi_mode() + * @fn wifi_mode_t wfx_get_wifi_mode(void) * @brief * get the wifi mode * @param[in] None * @return return WIFI_MODE_NULL if successful, * WIFI_MODE_STA otherwise ***********************************************************************/ -wifi_mode_t wfx_get_wifi_mode() +wifi_mode_t wfx_get_wifi_mode(void) { if (wfx_rsi.dev_state & WFX_RSI_ST_DEV_READY) return WIFI_MODE_STA; @@ -284,11 +265,9 @@ wifi_mode_t wfx_get_wifi_mode() ***********************************************************************/ sl_status_t wfx_sta_discon(void) { - SILABS_LOG("%s: started.", __func__); - int32_t status; + sl_status_t status; status = wfx_rsi_disconnect(); wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTED; - SILABS_LOG("%s: completed.", __func__); return status; } #if CHIP_DEVICE_CONFIG_ENABLE_IPV4 @@ -302,17 +281,8 @@ sl_status_t wfx_sta_discon(void) ***********************************************************************/ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) { - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0; - } - else - { - status = false; /* TODO */ - } - SILABS_LOG("%s: status: %d", __func__, status); - return status; + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_DHCP_DONE) > 0); } #endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */ @@ -326,17 +296,9 @@ bool wfx_have_ipv4_addr(sl_wfx_interface_t which_if) ***********************************************************************/ bool wfx_have_ipv6_addr(sl_wfx_interface_t which_if) { - bool status = false; - if (which_if == SL_WFX_STA_INTERFACE) - { - status = (wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0; - } - else - { - status = false; /* TODO */ - } - SILABS_LOG("%s: %d", __func__, status); - return status; + VerifyOrReturnError(which_if == SL_WFX_STA_INTERFACE, false); + // TODO: WFX_RSI_ST_STA_CONNECTED does not guarantee SLAAC IPv6 LLA, maybe use a different FLAG + return ((wfx_rsi.dev_state & WFX_RSI_ST_STA_CONNECTED) > 0); } /********************************************************************* @@ -379,14 +341,14 @@ int32_t wfx_get_ap_ext(wfx_wifi_scan_ext_t * extra_info) } /*************************************************************************** - * @fn int32_t wfx_reset_counts(){ + * @fn int32_t wfx_reset_counts(void) * @brief * get the driver reset count * @param[in] None * @return * reset count *****************************************************************************/ -int32_t wfx_reset_counts() +int32_t wfx_reset_counts(void) { return wfx_rsi_reset_count(); } @@ -402,21 +364,17 @@ int32_t wfx_reset_counts() *******************************************************************************/ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) { - int sz; - WfxEvent_t event; - if (wfx_rsi.scan_cb) - return false; /* Already in progress */ - if (ssid) - { - sz = strlen(ssid); - if ((wfx_rsi.scan_ssid = (char *) pvPortMalloc(sz + 1)) == (char *) 0) - { - return false; - } - strcpy(wfx_rsi.scan_ssid, ssid); - } + // check if already in progress + VerifyOrReturnError(wfx_rsi.scan_cb != nullptr, false); wfx_rsi.scan_cb = callback; + VerifyOrReturnError(ssid != nullptr, false); + wfx_rsi.scan_ssid_length = strnlen(ssid, chip::min(sizeof(ssid), WFX_MAX_SSID_LENGTH)); + wfx_rsi.scan_ssid = reinterpret_cast(chip::Platform::MemoryAlloc(wfx_rsi.scan_ssid_length)); + VerifyOrReturnError(wfx_rsi.scan_ssid != nullptr, false); + chip::Platform::CopyString(wfx_rsi.scan_ssid, wfx_rsi.scan_ssid_length, ssid); + + WfxEvent_t event; event.eventType = WFX_EVT_SCAN; WfxPostEvent(&event); @@ -434,6 +392,6 @@ bool wfx_start_scan(char * ssid, void (*callback)(wfx_wifi_scan_result_t *)) void wfx_cancel_scan(void) { /* Not possible */ - SILABS_LOG("%s: cannot cancel scan", __func__); + ChipLogError(DeviceLayer, "cannot cancel scan"); } #endif /* SL_WFX_CONFIG_SCAN */ diff --git a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp index b5a9c1eb56a3f8..6e5470f7d05f26 100644 --- a/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp +++ b/src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp @@ -327,7 +327,7 @@ void ConnectivityManagerImpl::DriveStationState() ChipLogProgress(DeviceLayer, "Attempting to connect WiFi"); if ((serr = wfx_connect_to_ap()) != SL_STATUS_OK) { - ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed."); + ChipLogError(DeviceLayer, "wfx_connect_to_ap() failed: %" PRId32, serr); } SuccessOrExit(serr); diff --git a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp index 614a121280eaef..7f6240c32c5858 100644 --- a/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp +++ b/src/platform/silabs/NetworkCommissioningWiFiDriver.cpp @@ -147,10 +147,19 @@ CHIP_ERROR SlWiFiDriver::ConnectWiFiNetwork(const char * ssid, uint8_t ssidLen, } } ReturnErrorOnFailure(ConnectivityMgr().SetWiFiStationMode(ConnectivityManager::kWiFiStationMode_Disabled)); + // Set the wifi configuration - wfx_wifi_provision_t wifiConfig = {}; + wfx_wifi_provision_t wifiConfig; + memset(&wifiConfig, 0, sizeof(wifiConfig)); + + VerifyOrReturnError(ssidLen <= WFX_MAX_SSID_LENGTH, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(wifiConfig.ssid, ssid, ssidLen); + wifiConfig.ssid_length = ssidLen; + + VerifyOrReturnError(keyLen < WFX_MAX_PASSKEY_LENGTH, CHIP_ERROR_BUFFER_TOO_SMALL); memcpy(wifiConfig.passkey, key, keyLen); + wifiConfig.passkey_length = keyLen; + wifiConfig.security = WFX_SEC_WPA2; ChipLogProgress(NetworkProvisioning, "Setting up connection for WiFi SSID: %.*s", static_cast(ssidLen), ssid); diff --git a/src/platform/silabs/SiWx917/wifi/ethernetif.cpp b/src/platform/silabs/SiWx917/wifi/ethernetif.cpp index 72725102d6da48..2860b895ce7fae 100644 --- a/src/platform/silabs/SiWx917/wifi/ethernetif.cpp +++ b/src/platform/silabs/SiWx917/wifi/ethernetif.cpp @@ -44,7 +44,7 @@ extern "C" { #include "lwip/ethip6.h" #include "lwip/timeouts.h" #include "netif/etharp.h" -#include "silabs_utils.h" +#include StaticSemaphore_t xEthernetIfSemaBuffer; @@ -131,13 +131,13 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) (memcmp(netif->hwaddr, dst_mac, netif->hwaddr_len) != 0)) { #ifdef WIFI_DEBUG_ENABLED - SILABS_LOG("%s: DROP, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", __func__, + ChipLogDetail(DeviceLayer, "DROP: [%02x:%02x:%02x:%02x:%02x:%02x]->[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", - dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], + src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], - src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], + dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], - b[12], b[13]); + b[12], b[13]); #endif return; } @@ -153,14 +153,14 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) bufferoffset += q->len; } #ifdef WIFI_DEBUG_ENABLED - SILABS_LOG("%s: ACCEPT %d, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", __func__, - bufferoffset, + ChipLogDetail(DeviceLayer, "ACCEPT(%d): [%02x:%02x:%02x:%02x:%02x:%02x]->[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", + bufferoffset, - dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], + src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], - src_mac[0], src_mac[1], src_mac[2], src_mac[3], src_mac[4], src_mac[5], + dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], - b[12], b[13]); + b[12], b[13]); #endif if (netif->input(p, netif) != ERR_OK) diff --git a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h index 319a1c508e658d..42a5dfffc1c381 100644 --- a/src/platform/silabs/SiWx917/wifi/wfx_host_events.h +++ b/src/platform/silabs/SiWx917/wifi/wfx_host_events.h @@ -159,7 +159,9 @@ typedef enum typedef struct { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; char passkey[WFX_MAX_PASSKEY_LENGTH + 1]; + size_t passkey_length; wfx_sec_t security; } wfx_wifi_provision_t; @@ -175,6 +177,7 @@ typedef enum typedef struct wfx_wifi_scan_result { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; wfx_sec_t security; uint8_t bssid[BSSID_LEN]; uint8_t chan; diff --git a/src/platform/silabs/efr32/wifi/ethernetif.cpp b/src/platform/silabs/efr32/wifi/ethernetif.cpp index 0388337939a3e2..d0f0ec6daf47f7 100644 --- a/src/platform/silabs/efr32/wifi/ethernetif.cpp +++ b/src/platform/silabs/efr32/wifi/ethernetif.cpp @@ -148,8 +148,8 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) (memcmp(netif->hwaddr, dst_mac, netif->hwaddr_len) != 0)) { #ifdef WIFI_DEBUG_ENABLED - ChipLogProgress(DeviceLayer, "%s: DROP, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", - __func__, + ChipLogProgress(DeviceLayer, + "lwip_input: DROP, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], @@ -172,7 +172,7 @@ static void low_level_input(struct netif * netif, uint8_t * b, uint16_t len) } #ifdef WIFI_DEBUG_ENABLED ChipLogProgress(DeviceLayer, - "%s: ACCEPT %ld, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", __func__, + "lwip_input: ACCEPT %ld, [%02x:%02x:%02x:%02x:%02x:%02x]<-[%02x:%02x:%02x:%02x:%02x:%02x] type=%02x%02x", bufferoffset, dst_mac[0], dst_mac[1], dst_mac[2], dst_mac[3], dst_mac[4], dst_mac[5], diff --git a/src/platform/silabs/efr32/wifi/wfx_host_events.h b/src/platform/silabs/efr32/wifi/wfx_host_events.h index 51f96d7b9dbc73..4686931eafac4e 100644 --- a/src/platform/silabs/efr32/wifi/wfx_host_events.h +++ b/src/platform/silabs/efr32/wifi/wfx_host_events.h @@ -254,7 +254,9 @@ typedef enum typedef struct { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; char passkey[WFX_MAX_PASSKEY_LENGTH + 1]; + size_t passkey_length; wfx_sec_t security; } wfx_wifi_provision_t; @@ -270,6 +272,7 @@ typedef enum typedef struct wfx_wifi_scan_result { char ssid[WFX_MAX_SSID_LENGTH + 1]; + size_t ssid_length; wfx_sec_t security; uint8_t bssid[BSSID_LEN]; uint8_t chan;