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] [WiFi] Fixing the retry logic for the WiFi Devices #34225

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
18 changes: 11 additions & 7 deletions examples/platform/silabs/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,10 @@ Identify gIdentify = {
#endif // MATTER_DM_PLUGIN_IDENTIFY_SERVER
} // namespace

bool BaseApplication::sIsProvisioned = false;
bool BaseApplication::sIsFactoryResetTriggered = false;
LEDWidget * BaseApplication::sAppActionLed = nullptr;
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
bool BaseApplication::sIsProvisioned = false;
bool BaseApplication::sIsFactoryResetTriggered = false;
LEDWidget * BaseApplication::sAppActionLed = nullptr;
BaseApplicationDelegate BaseApplication::sAppDelegate = BaseApplicationDelegate();
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

#ifdef DIC_ENABLE
namespace {
Expand All @@ -181,7 +179,6 @@ void AppSpecificConnectivityEventCallback(const ChipDeviceEvent * event, intptr_
} // namespace
#endif // DIC_ENABLE

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
void BaseApplicationDelegate::OnCommissioningSessionStarted()
{
isComissioningStarted = true;
Expand All @@ -192,6 +189,7 @@ void BaseApplicationDelegate::OnCommissioningSessionStopped()
}
void BaseApplicationDelegate::OnCommissioningWindowClosed()
{
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
if (!BaseApplication::GetProvisionStatus() && !isComissioningStarted)
{
int32_t status = wfx_power_save(RSI_SLEEP_MODE_8, STANDBY_POWER_SAVE_WITH_RAM_RETENTION);
Expand All @@ -200,8 +198,14 @@ void BaseApplicationDelegate::OnCommissioningWindowClosed()
ChipLogError(DeviceLayer, "Failed to enable the TA Deep Sleep");
}
}
}
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
if (BaseApplication::GetProvisionStatus())
{
// After the device is provisioned and the commissioning passed
// resetting the isCommissioningStarted to false
isComissioningStarted = false;
}
}

/**********************************************************
* AppTask Definitions
Expand Down
10 changes: 5 additions & 5 deletions examples/platform/silabs/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,18 @@
#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05)
#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06)

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
class BaseApplicationDelegate : public AppDelegate
{
public:
bool isCommissioningInProgress() { return isComissioningStarted; }

private:
bool isComissioningStarted;
// AppDelegate
bool isComissioningStarted = false;
void OnCommissioningSessionStarted() override;
void OnCommissioningSessionStopped() override;
void OnCommissioningWindowClosed() override;
};
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**********************************************************
* BaseApplication Declaration
Expand All @@ -86,9 +88,7 @@ class BaseApplication
static bool sIsProvisioned;
static bool sIsFactoryResetTriggered;
static LEDWidget * sAppActionLed;
#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
static BaseApplicationDelegate sAppDelegate;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

/**
* @brief Create AppTask task and Event Queue
Expand Down
3 changes: 1 addition & 2 deletions examples/platform/silabs/MatterConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
initParams.endpointNativeParams = static_cast<void *>(&nativeParams);
#endif

#if CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917
initParams.appDelegate = &BaseApplication::sAppDelegate;
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER && SLI_SI917

// Init Matter Server and Start Event Loop
err = chip::Server::GetInstance().Init(initParams);

Expand Down
4 changes: 1 addition & 3 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ declare_args() {

# Sanity check
assert(chip_enable_wifi)

silabs_common_plat_dir = "${chip_root}/examples/platform/silabs"
silabs_plat_si91x_wifi_dir = "${chip_root}/src/platform/silabs/SiWx917/wifi"
import("${silabs_common_plat_dir}/args.gni")

Expand Down Expand Up @@ -201,10 +199,10 @@ source_set("siwx917-common") {
"${silabs_common_plat_dir}/provision/ProvisionStorageFlash.cpp",
"${silabs_common_plat_dir}/silabs_utils.cpp",
"${silabs_common_plat_dir}/syscalls_stubs.cpp",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
"${silabs_plat_si91x_wifi_dir}/dhcp_client.cpp",
"${silabs_plat_si91x_wifi_dir}/ethernetif.cpp",
"${silabs_plat_si91x_wifi_dir}/lwip_netif.cpp",
"${silabs_plat_si91x_wifi_dir}/wfx_notify.cpp",
"SiWx917/sl_wifi_if.cpp",
"SiWx917/wfx_rsi_host.cpp",
]
Expand Down
22 changes: 4 additions & 18 deletions examples/platform/silabs/SiWx917/SiWx917/sl_wifi_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ bool hasNotifiedIPV4 = false;
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
bool hasNotifiedWifiConnectivity = false;

/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
bool is_wifi_disconnection_event = false;

/* Declare a variable to hold connection time intervals */
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
volatile bool scan_results_complete = false;
volatile bool bg_scan_results_complete = false;

Expand Down Expand Up @@ -249,12 +244,7 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
callback_status = *(sl_status_t *) result;
ChipLogError(DeviceLayer, "join_callback_handler: failed: 0x%lx", static_cast<uint32_t>(callback_status));
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTED);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
WfxEvent.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&WfxEvent);
}
wfx_retry_connection(++wfx_rsi.join_retries);
return SL_STATUS_FAIL;
}
/*
Expand All @@ -266,10 +256,7 @@ sl_status_t join_callback_handler(sl_wifi_event_t event, char * result, uint32_t
WfxEvent.eventType = WFX_EVT_STA_CONN;
WfxPostEvent(&WfxEvent);
wfx_rsi.join_retries = 0;
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
// Once the join passes setting the disconnection event to true to differentiate between the first connection and reconnection
is_wifi_disconnection_event = true;
callback_status = SL_STATUS_OK;
callback_status = SL_STATUS_OK;
return SL_STATUS_OK;
}

Expand Down Expand Up @@ -694,12 +681,11 @@ static sl_status_t wfx_rsi_do_join(void)

// failure only happens when the firmware returns an error
ChipLogError(DeviceLayer, "wfx_rsi_do_join: sl_wifi_connect failed: 0x%lx", static_cast<uint32_t>(status));
VerifyOrReturnError((is_wifi_disconnection_event || wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status);
VerifyOrReturnError((wfx_rsi.join_retries <= MAX_JOIN_RETRIES_COUNT), status);

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_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
wfx_rsi.join_retries++;
wfx_retry_connection(++wfx_rsi.join_retries);
event.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&event);
return status;
Expand Down
2 changes: 0 additions & 2 deletions examples/platform/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ declare_args() {
sl_test_event_trigger_enable_key = "00112233445566778899AABBCCDDEEFF"
}

silabs_common_plat_dir = "${chip_root}/examples/platform/silabs"

import("${silabs_common_plat_dir}/args.gni")

# Sanity check
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/efr32/rs911x/rs9117.gni
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rs911x_src_plat = [
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_interrupt.c",
"${examples_plat_dir}/rs911x/hal/sl_si91x_ncp_utility.c",
"${examples_plat_dir}/rs911x/hal/efx32_ncp_host.c",
"${silabs_plat_efr32_wifi_dir}/wfx_notify.cpp",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
]

rs9117_inc_plat = [
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/efr32/rs911x/rs911x.gni
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rs911x_src_plat = [
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_ioports.c",
"${examples_plat_dir}/rs911x/hal/rsi_hal_mcu_timer.c",
"${examples_plat_dir}/rs911x/hal/efx_spi.c",
"${silabs_plat_efr32_wifi_dir}/wfx_notify.cpp",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
]

#
Expand Down
46 changes: 11 additions & 35 deletions examples/platform/silabs/efr32/rs911x/rsi_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ bool hasNotifiedIPV4 = false;
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
bool hasNotifiedWifiConnectivity = false;

/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
bool is_wifi_disconnection_event = false;

/* Declare a variable to hold connection time intervals */
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;

#if (RSI_BLE_ENABLE)
extern rsi_semaphore_handle_t sl_rs_ble_init_sem;
#endif
Expand Down Expand Up @@ -280,12 +274,7 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
* We should enable retry.. (Need config variable for this)
*/
SILABS_LOG("%s: failed. retry: %d", __func__, wfx_rsi.join_retries);
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
{
WfxEvent.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&WfxEvent);
}
wfx_retry_connection(++wfx_rsi.join_retries);
}
else
{
Expand All @@ -297,7 +286,6 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
WfxEvent.eventType = WFX_EVT_STA_CONN;
WfxPostEvent(&WfxEvent);
wfx_rsi.join_retries = 0;
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
}
}

Expand All @@ -317,8 +305,7 @@ static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len)
WfxEvent_t WfxEvent;
wfx_rsi.join_retries += 1;
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
is_wifi_disconnection_event = true;
WfxEvent.eventType = WFX_EVT_STA_START_JOIN;
WfxEvent.eventType = WFX_EVT_STA_START_JOIN;
WfxPostEvent(&WfxEvent);
}
/*************************************************************************************
Expand Down Expand Up @@ -586,27 +573,16 @@ static void wfx_rsi_do_join(void)
/* Try to connect Wifi with given Credentials
* untill there is a success or maximum number of tries allowed
*/
while (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
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)
{
/* Call rsi connect call with given ssid and password
* And check there is a success
*/
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("%s: rsi_wlan_connect_async failed with status: %02x on try %d", __func__, status, wfx_rsi.join_retries);

wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
wfx_rsi.join_retries++;
}
else
{
SILABS_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0],
wfx_rsi.join_retries);
break; // exit while loop
}
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
SILABS_LOG("%s: rsi_wlan_connect_async failed with status: %02x on try %d", __func__, status, wfx_rsi.join_retries);
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
wfx_retry_connection(++wfx_rsi.join_retries);
}
else
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
{
SILABS_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0], wfx_rsi.join_retries);
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
Expand Down
28 changes: 8 additions & 20 deletions examples/platform/silabs/efr32/wf200/host_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,6 @@ bool hasNotifiedWifiConnectivity = false;
static uint8_t retryJoin = 0;
bool retryInProgress = false;

/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
bool is_wifi_disconnection_event = false;

/* Declare a variable to hold connection time intervals */
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;

#ifdef SL_WFX_CONFIG_SCAN
static struct scan_result_holder
{
Expand Down Expand Up @@ -401,14 +395,14 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication
}
}

if ((status != WFM_STATUS_SUCCESS) && (!is_wifi_disconnection_event ? (retryJoin < MAX_JOIN_RETRIES_COUNT) : true))
if (status != WFM_STATUS_SUCCESS)
{
retryJoin += 1;
retryInProgress = false;
SILABS_LOG("WFX Retry to connect to network count: %d", retryJoin);
sl_wfx_context->state =
static_cast<sl_wfx_state_t>(static_cast<int>(sl_wfx_context->state) & ~static_cast<int>(SL_WFX_STARTED));
xEventGroupSetBits(sl_wfx_event_group, SL_WFX_RETRY_CONNECT);
wfx_retry_connection(retryJoin);
}
}

Expand All @@ -424,9 +418,8 @@ static void sl_wfx_disconnect_callback(uint8_t * mac, uint16_t reason)
SILABS_LOG("WFX Disconnected %d\r\n", reason);
sl_wfx_context->state =
static_cast<sl_wfx_state_t>(static_cast<int>(sl_wfx_context->state) & ~static_cast<int>(SL_WFX_STA_INTERFACE_CONNECTED));
retryInProgress = false;
is_wifi_disconnection_event = true;
xEventGroupSetBits(sl_wfx_event_group, SL_WFX_RETRY_CONNECT);
retryInProgress = false;
wfx_retry_connection(retryJoin);
}

#ifdef SL_WFX_CONFIG_SOFTAP
Expand Down Expand Up @@ -541,13 +534,8 @@ 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)
{
if (!retryInProgress)
{
retryInProgress = true;
wfx_retry_interval_handler(is_wifi_disconnection_event, retryJoin);
SILABS_LOG("WFX sending the connect command");
wfx_connect_to_ap();
}
SILABS_LOG("WFX sending the connect command");
chirag-silabs marked this conversation as resolved.
Show resolved Hide resolved
wfx_connect_to_ap();
}

if (wifi_extra & WE_ST_STA_CONN)
Expand Down Expand Up @@ -599,8 +587,7 @@ static void wfx_events_task(void * p_arg)
hasNotifiedWifiConnectivity = false;
SILABS_LOG("WIFI: Connected to AP");
wifi_extra |= WE_ST_STA_CONN;
retryJoin = 0;
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
retryJoin = 0;
wfx_lwip_set_sta_link_up();
#if CHIP_CONFIG_ENABLE_ICD_SERVER
if (!(wfx_get_wifi_state() & SL_WFX_AP_INTERFACE_UP))
Expand Down Expand Up @@ -750,6 +737,7 @@ static void wfx_wifi_hw_start(void)
/* Initialize the LwIP stack */
SILABS_LOG("WF200:Start LWIP");
wfx_lwip_start();
wfx_started_notify();
wifiContext.state = SL_WFX_STARTED; /* Really this is a bit mask */
SILABS_LOG("WF200:ready..");
}
Expand Down
2 changes: 1 addition & 1 deletion examples/platform/silabs/efr32/wf200/wf200.gni
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import("${efr32_sdk_build_root}/efr32_sdk.gni")

wf200_plat_incs = [ "${examples_plat_dir}/wf200" ]
wf200_plat_src = [
"${silabs_plat_efr32_wifi_dir}/wfx_notify.cpp",
"${silabs_common_plat_dir}/wifi/wfx_notify.cpp",
"${examples_plat_dir}/wf200/sl_wfx_task.c",
"${examples_plat_dir}/wf200/wf200_init.c",
"${examples_plat_dir}/wf200/efr_spi.c",
Expand Down
1 change: 0 additions & 1 deletion examples/platform/silabs/wfx_rsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#define WFX_RSI_WLAN_TASK_SZ (1024 + 512 + 256) /* Stack for the WLAN task */
#define WFX_RSI_TASK_SZ (1024 + 1024) /* Stack for the WFX/RSI task */
#define WFX_RSI_BUF_SZ (1024 * 10) /* May need tweak */
#define WFX_RSI_CONFIG_MAX_JOIN (5) /* Max join retries */
// TODO: Default values are usually in minutes, but this is in ms. Confirm if this is correct
#define WFX_RSI_DHCP_POLL_INTERVAL (250) /* Poll interval in ms for DHCP */
#define WFX_RSI_NUM_TIMERS (2) /* Number of RSI timers to alloc */
Expand Down
Loading
Loading