Skip to content

Commit 1259690

Browse files
riwaghepull[bot]
authored andcommitted
[Silabs] Disconnection issue fix (#23795)
* [Silabs] Disconnection issue fixed * Restyling the PR * addressing the comments - changed macro and variable names * addressing the comments - removed previous commented-out code * Restyling the PR * Added comments * Restyling the PR * Restyling the PR * Restyling the PR * Adressing the comments * Adressing the comments * Restyling the PR * Added comments * Create function for retry interval * Restyling the PR * Restyling the PR * Addressing the PR comments * Restyling the PR
1 parent bbc07e6 commit 1259690

File tree

5 files changed

+94
-23
lines changed

5 files changed

+94
-23
lines changed

examples/platform/silabs/efr32/rs911x/rsi_if.c

+25-19
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ bool hasNotifiedIPV4 = false;
6767
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
6868
bool hasNotifiedWifiConnectivity = false;
6969

70+
/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
71+
bool is_wifi_disconnection_event = false;
72+
73+
/* Declare a variable to hold connection time intervals */
74+
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
75+
7076
/*
7177
* This file implements the interface to the RSI SAPIs
7278
*/
@@ -195,12 +201,9 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
195201
* We should enable retry.. (Need config variable for this)
196202
*/
197203
WFX_RSI_LOG("%s: failed. retry: %d", __func__, wfx_rsi.join_retries);
198-
#if (WFX_RSI_CONFIG_MAX_JOIN != 0)
199-
if (++wfx_rsi.join_retries < WFX_RSI_CONFIG_MAX_JOIN)
200-
#endif
201-
{
204+
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
205+
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
202206
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
203-
}
204207
}
205208
else
206209
{
@@ -213,6 +216,8 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
213216
#else
214217
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_CONN);
215218
#endif
219+
wfx_rsi.join_retries = 0;
220+
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
216221
}
217222
}
218223

@@ -228,9 +233,10 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
228233
*********************************************************************/
229234
static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len)
230235
{
231-
WFX_RSI_LOG("%s: error: failed status: %02x on try %d", __func__, status, wfx_rsi.join_retries);
236+
WFX_RSI_LOG("%s: error: failed status: %02x", __func__, status);
232237
wfx_rsi.join_retries += 1;
233-
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
238+
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
239+
is_wifi_disconnection_event = true;
234240
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
235241
}
236242
#ifdef RS911X_SOCKETS
@@ -461,6 +467,7 @@ static void wfx_rsi_do_join(void)
461467
{
462468
WFX_RSI_LOG("%s: WLAN: connecting to %s==%s, sec=%d", __func__, &wfx_rsi.sec.ssid[0], &wfx_rsi.sec.passkey[0],
463469
wfx_rsi.sec.security);
470+
464471
/*
465472
* Join the network
466473
*/
@@ -469,12 +476,16 @@ static void wfx_rsi_do_join(void)
469476
*/
470477
wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING;
471478

479+
if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS)
480+
{
481+
WFX_RSI_LOG("%s: RSI callback register join failed with status: %02x", __func__, status);
482+
}
483+
472484
/* Try to connect Wifi with given Credentials
473485
* untill there is a success or maximum number of tries allowed
474486
*/
475-
while (++wfx_rsi.join_retries < WFX_RSI_CONFIG_MAX_JOIN)
487+
while (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
476488
{
477-
478489
/* Call rsi connect call with given ssid and password
479490
* And check there is a success
480491
*/
@@ -485,22 +496,17 @@ static void wfx_rsi_do_join(void)
485496
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
486497
WFX_RSI_LOG("%s: rsi_wlan_connect_async failed with status: %02x on try %d", __func__, status,
487498
wfx_rsi.join_retries);
488-
vTaskDelay(4000);
489-
/* TODO - Start a timer.. to retry */
499+
500+
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
501+
wfx_rsi.join_retries++;
490502
}
491503
else
492504
{
505+
WFX_RSI_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0],
506+
wfx_rsi.join_retries);
493507
break; // exit while loop
494508
}
495509
}
496-
if (wfx_rsi.join_retries == MAX_JOIN_RETRIES_COUNT)
497-
{
498-
WFX_RSI_LOG("Connect failed after %d tries", wfx_rsi.join_retries);
499-
}
500-
else
501-
{
502-
WFX_RSI_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0], wfx_rsi.join_retries);
503-
}
504510
}
505511
}
506512

examples/platform/silabs/efr32/wf200/host_if.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ bool hasNotifiedWifiConnectivity = false;
9999
static uint8_t retryJoin = 0;
100100
bool retryInProgress = false;
101101

102+
/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
103+
bool is_wifi_disconnection_event = false;
104+
105+
/* Declare a variable to hold connection time intervals */
106+
uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
107+
102108
#ifdef SL_WFX_CONFIG_SCAN
103109
static struct scan_result_holder
104110
{
@@ -394,7 +400,7 @@ static void sl_wfx_connect_callback(sl_wfx_connect_ind_body_t connect_indication
394400
}
395401
}
396402

397-
if ((status != WFM_STATUS_SUCCESS) && retryJoin < MAX_JOIN_RETRIES_COUNT)
403+
if ((status != WFM_STATUS_SUCCESS) && (!is_wifi_disconnection_event ? (retryJoin < MAX_JOIN_RETRIES_COUNT) : true))
398404
{
399405
retryJoin += 1;
400406
retryInProgress = false;
@@ -417,7 +423,9 @@ static void sl_wfx_disconnect_callback(uint8_t * mac, uint16_t reason)
417423
SILABS_LOG("WFX Disconnected %d\r\n", reason);
418424
sl_wfx_context->state =
419425
static_cast<sl_wfx_state_t>(static_cast<int>(sl_wfx_context->state) & ~static_cast<int>(SL_WFX_STA_INTERFACE_CONNECTED));
420-
xEventGroupSetBits(sl_wfx_event_group, SL_WFX_DISCONNECT);
426+
retryInProgress = false;
427+
is_wifi_disconnection_event = true;
428+
xEventGroupSetBits(sl_wfx_event_group, SL_WFX_RETRY_CONNECT);
421429
}
422430

423431
#ifdef SL_WFX_CONFIG_SOFTAP
@@ -534,9 +542,10 @@ static void wfx_events_task(void * p_arg)
534542
{
535543
if (!retryInProgress)
536544
{
545+
retryInProgress = true;
546+
wfx_retry_interval_handler(is_wifi_disconnection_event, retryJoin);
537547
SILABS_LOG("WFX sending the connect command");
538548
wfx_connect_to_ap();
539-
retryInProgress = true;
540549
}
541550
}
542551

@@ -589,6 +598,8 @@ static void wfx_events_task(void * p_arg)
589598
hasNotifiedWifiConnectivity = false;
590599
SILABS_LOG("WIFI: Connected to AP");
591600
wifi_extra |= WE_ST_STA_CONN;
601+
retryJoin = 0;
602+
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
592603
wfx_lwip_set_sta_link_up();
593604
#ifdef SLEEP_ENABLED
594605
if (!(wfx_get_wifi_state() & SL_WFX_AP_INTERFACE_UP))

src/platform/silabs/ConnectivityManagerImpl_WIFI.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,10 @@ void ConnectivityManagerImpl::DriveStationState()
263263
// disconnect the station from the AP, unless the WiFi station mode is currently
264264
// under application control.
265265
#ifndef CHIP_ONNETWORK_PAIRING
266+
// Incase of station interface disabled & provisioned, wifi_station should not be disconnected.
267+
// Device will try to reconnect.
266268
if (mWiFiStationMode != kWiFiStationMode_ApplicationControlled &&
267-
(mWiFiStationMode != kWiFiStationMode_Enabled || !IsWiFiStationProvisioned()))
269+
(mWiFiStationMode != kWiFiStationMode_Enabled && !IsWiFiStationProvisioned()))
268270
{
269271
ChipLogProgress(DeviceLayer, "Disconnecting WiFi station interface");
270272
serr = wfx_sta_discon();

src/platform/silabs/EFR32/wifi/wfx_host_events.h

+9
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ typedef struct __attribute__((__packed__)) sl_wfx_mib_req_s
141141
#define MAX_JOIN_RETRIES_COUNT 5
142142
#endif
143143

144+
// WLAN retry time intervals in milli seconds
145+
#define WLAN_MAX_RETRY_TIMER_MS 30000
146+
#define WLAN_MIN_RETRY_TIMER_MS 1000
147+
#define WLAN_RETRY_TIMER_MS 5000
148+
#define CONVERT_MS_TO_SEC(TimeInMS) (TimeInMS / 1000)
149+
144150
// WLAN related Macros
145151
#define ETH_FRAME 0
146152
#define CMP_SUCCESS 0
@@ -370,6 +376,9 @@ sl_status_t get_all_counters(void);
370376
void sl_wfx_host_gpio_init(void);
371377
sl_status_t sl_wfx_host_process_event(sl_wfx_generic_message_t * event_payload);
372378
#endif
379+
380+
void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin);
381+
373382
#ifdef __cplusplus
374383
}
375384
#endif

src/platform/silabs/EFR32/wifi/wfx_notify.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
using namespace ::chip;
4747
using namespace ::chip::DeviceLayer;
4848

49+
extern uint32_t retryInterval;
50+
4951
/*
5052
* Notifications to the upper-layer
5153
* All done in the context of the RSI/WiFi task (rsi_if.c)
@@ -187,3 +189,44 @@ void wfx_ip_changed_notify(int got_ip)
187189
chip::DeviceLayer::PlatformMgr().UnlockChipStack();
188190
}
189191
}
192+
193+
/**************************************************************************************
194+
* @fn void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin)
195+
* @brief
196+
* Based on condition will delay for a certain period of time.
197+
* @param[in] is_wifi_disconnection_event, retryJoin
198+
* @return None
199+
********************************************************************************************/
200+
void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin)
201+
{
202+
if (!is_wifi_disconnection_event)
203+
{
204+
/* After the reboot or a commissioning time device failed to connect with AP.
205+
* Device will retry to connect with AP upto WFX_RSI_CONFIG_MAX_JOIN retries.
206+
*/
207+
if (retryJoin < MAX_JOIN_RETRIES_COUNT)
208+
{
209+
SILABS_LOG("%s: Next attempt after %d Seconds", __func__, CONVERT_MS_TO_SEC(WLAN_RETRY_TIMER_MS));
210+
vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS));
211+
}
212+
else
213+
{
214+
SILABS_LOG("Connect failed after max %d tries", retryJoin);
215+
}
216+
}
217+
else
218+
{
219+
/* After disconnection
220+
* At the telescopic time interval device try to reconnect with AP, upto WLAN_MAX_RETRY_TIMER_MS intervals
221+
* are telescopic. If interval exceed WLAN_MAX_RETRY_TIMER_MS then it will try to reconnect at
222+
* WLAN_MAX_RETRY_TIMER_MS intervals.
223+
*/
224+
if (retryInterval > WLAN_MAX_RETRY_TIMER_MS)
225+
{
226+
retryInterval = WLAN_MAX_RETRY_TIMER_MS;
227+
}
228+
SILABS_LOG("%s: Next attempt after %d Seconds", __func__, CONVERT_MS_TO_SEC(retryInterval));
229+
vTaskDelay(pdMS_TO_TICKS(retryInterval));
230+
retryInterval += retryInterval;
231+
}
232+
}

0 commit comments

Comments
 (0)