From 4680cd6f4e445bfb1dff2682d10cfc6ad95faf2f Mon Sep 17 00:00:00 2001 From: senthil kumar E K Date: Tue, 21 Jan 2025 23:44:11 +0530 Subject: [PATCH 1/4] added join callback handler --- .../silabs/wifi/SiWx/WifiInterfaceImpl.cpp | 44 ++++++++++++++++--- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp index 1477418ddd9412..7a200feed4a4ab 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp @@ -327,14 +327,18 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res sl_status_t status = SL_STATUS_OK; if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) { - ChipLogError(DeviceLayer, "Scan Netwrok Failed: 0x%lx", *reinterpret_cast(status)); + if (scan_result != nullptr) + { + status = *reinterpret_cast(scan_result); + ChipLogError(DeviceLayer, "ScanCallback: failed: 0x%lx", static_cast(status)); + } + #if WIFI_ENABLE_SECURITY_WPA3_TRANSITION security = SL_WIFI_WPA3; #else security = SL_WIFI_WPA_WPA2_MIXED; #endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ - status = SL_STATUS_FAIL; } else { @@ -434,6 +438,35 @@ sl_status_t SetWifiConfigurations() return status; } +/** + * @brief Callback function for the SL_WIFI_JOIN_EVENTS group + * + * This callback handler will be invoked when any event within join event group occurs, providing the event details and any + * associated data The callback doesn't get called when we join a network using the sl net APIs + * + * @note In case of failure, the 'result' parameter will be of type sl_status_t, and the 'resultLenght' parameter should be ignored + * + * @param[in] event sl_wifi_event_t that triggered the callback + * @param[in] result Pointer to the response data received + * @param[in] result_length Length of the data received in bytes + * @param[in] arg Optional user provided argument + * + * @return sl_status_t Returns the status of the operation + */ +sl_status_t JoinCallback(sl_wifi_event_t event, char * result, uint32_t resultLenght, void * arg) +{ + sl_status_t status = SL_STATUS_OK; + wfx_rsi.dev_state.Clear(WifiState::kStationConnecting); + if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) + { + status = *reinterpret_cast(result); + ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", static_cast(status)); + wfx_rsi.dev_state.Clear(WifiState::kStationConnected); + wfx_retry_connection(++wfx_rsi.join_retries); + } + + return status; +} sl_status_t JoinWifiNetwork(void) { VerifyOrReturnError(!wfx_rsi.dev_state.HasAny(WifiState::kStationConnecting, WifiState::kStationConnected), @@ -446,6 +479,9 @@ sl_status_t JoinWifiNetwork(void) status = SetWifiConfigurations(); VerifyOrReturnError(status == SL_STATUS_OK, status, ChipLogError(DeviceLayer, "Failure to set the Wifi Configurations!")); + status = sl_wifi_set_join_callback(JoinCallback, nullptr); + VerifyOrReturnError(status == SL_STATUS_OK, status); + status = sl_net_up((sl_net_interface_t) SL_NET_WIFI_CLIENT_INTERFACE, SL_NET_DEFAULT_WIFI_CLIENT_PROFILE_ID); if (status == SL_STATUS_OK || status == SL_STATUS_IN_PROGRESS) @@ -457,16 +493,12 @@ sl_status_t JoinWifiNetwork(void) // failure only happens when the firmware returns an error ChipLogError(DeviceLayer, "sl_wifi_connect failed: 0x%lx", static_cast(status)); - VerifyOrReturnError((wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status); wfx_rsi.dev_state.Clear(WifiState::kStationConnecting).Clear(WifiState::kStationConnected); ChipLogProgress(DeviceLayer, "Connection retry attempt %d", wfx_rsi.join_retries); wfx_retry_connection(++wfx_rsi.join_retries); - WifiPlatformEvent event = WifiPlatformEvent::kStationStartJoin; - PostWifiPlatformEvent(event); - return status; } From 8be6af28e24425a6a54f87222c7f0b8e3821b6cd Mon Sep 17 00:00:00 2001 From: senthil kumar E K Date: Tue, 21 Jan 2025 23:54:58 +0530 Subject: [PATCH 2/4] fix restyled issue --- src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp index 7a200feed4a4ab..9d036bf5965673 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp @@ -338,7 +338,6 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res #else security = SL_WIFI_WPA_WPA2_MIXED; #endif /* WIFI_ENABLE_SECURITY_WPA3_TRANSITION */ - } else { From 0bdccbf1cdb6adaab2b902c48fdd52a05ba70e7f Mon Sep 17 00:00:00 2001 From: senthil kumar E K Date: Thu, 23 Jan 2025 16:31:33 +0530 Subject: [PATCH 3/4] remove reinterpret casting for scan/join failure status --- src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp index 9d036bf5965673..4cc9cc701611c4 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp @@ -329,7 +329,7 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res { if (scan_result != nullptr) { - status = *reinterpret_cast(scan_result); + status = *(sl_status_t *)scan_result; ChipLogError(DeviceLayer, "ScanCallback: failed: 0x%lx", static_cast(status)); } @@ -458,7 +458,7 @@ sl_status_t JoinCallback(sl_wifi_event_t event, char * result, uint32_t resultLe wfx_rsi.dev_state.Clear(WifiState::kStationConnecting); if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) { - status = *reinterpret_cast(result); + status = *(sl_status_t *)result; ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", static_cast(status)); wfx_rsi.dev_state.Clear(WifiState::kStationConnected); wfx_retry_connection(++wfx_rsi.join_retries); From 7ff9f527c49afa7b90fcd57f3a3cbfb61b339a49 Mon Sep 17 00:00:00 2001 From: senthil kumar E K Date: Fri, 24 Jan 2025 17:09:04 +0530 Subject: [PATCH 4/4] removed c typecast and updated with c++ type casting --- src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp index 4cc9cc701611c4..096b75b9c64dde 100644 --- a/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp +++ b/src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp @@ -329,8 +329,8 @@ sl_status_t ScanCallback(sl_wifi_event_t event, sl_wifi_scan_result_t * scan_res { if (scan_result != nullptr) { - status = *(sl_status_t *)scan_result; - ChipLogError(DeviceLayer, "ScanCallback: failed: 0x%lx", static_cast(status)); + status = *reinterpret_cast(scan_result); + ChipLogError(DeviceLayer, "ScanCallback: failed: 0x%lx", status); } #if WIFI_ENABLE_SECURITY_WPA3_TRANSITION @@ -458,8 +458,8 @@ sl_status_t JoinCallback(sl_wifi_event_t event, char * result, uint32_t resultLe wfx_rsi.dev_state.Clear(WifiState::kStationConnecting); if (SL_WIFI_CHECK_IF_EVENT_FAILED(event)) { - status = *(sl_status_t *)result; - ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", static_cast(status)); + status = *reinterpret_cast(result); + ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", status); wfx_rsi.dev_state.Clear(WifiState::kStationConnected); wfx_retry_connection(++wfx_rsi.join_retries); }