Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Silabs] Added join callback handler to fix rejoin issue #37145

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,17 @@ 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<sl_status_t *>(status));
if (scan_result != nullptr)
{
status = *reinterpret_cast<sl_status_t *>(scan_result);
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
ChipLogError(DeviceLayer, "ScanCallback: failed: 0x%lx", static_cast<uint32_t>(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
{
Expand Down Expand Up @@ -434,6 +437,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<sl_status_t *>(result);
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved
ChipLogError(DeviceLayer, "JoinCallback: failed: 0x%lx", static_cast<uint32_t>(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),
Expand All @@ -446,6 +478,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)
Expand All @@ -457,16 +492,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<uint32_t>(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;
}

Expand Down
Loading