Skip to content

Commit 5e0855b

Browse files
riwaghepull[bot]
authored andcommitted
[Silabs] Si917 SOC disconnection issue fix (#24248)
* Si917 SOC disconnection issue fix * Addressed PR comments
1 parent fb94ff8 commit 5e0855b

File tree

2 files changed

+77
-21
lines changed

2 files changed

+77
-21
lines changed

examples/platform/silabs/SiWx917/SiWx917/rsi_if.c

+69-21
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ StaticTask_t driverRsiTaskBuffer;
5757
/* Declare a variable to hold the data associated with the created event group. */
5858
StaticEventGroup_t rsiDriverEventGroup;
5959

60+
/* Declare a flag to differentiate between after boot-up first IP connection or reconnection */
61+
static bool is_wifi_disconnection_event = false;
62+
63+
/* Declare a variable to hold connection time intervals */
64+
static uint32_t retryInterval = WLAN_MIN_RETRY_TIMER_MS;
65+
6066
bool hasNotifiedIPV6 = false;
6167
#if (CHIP_DEVICE_CONFIG_ENABLE_IPV4)
6268
bool hasNotifiedIPV4 = false;
@@ -162,12 +168,9 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
162168
* We should enable retry.. (Need config variable for this)
163169
*/
164170
WFX_RSI_LOG("%s: failed. retry: %d", __func__, wfx_rsi.join_retries);
165-
#if (WFX_RSI_CONFIG_MAX_JOIN != 0)
166-
if (++wfx_rsi.join_retries < WFX_RSI_CONFIG_MAX_JOIN)
167-
#endif
168-
{
171+
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries++);
172+
if (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
169173
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
170-
}
171174
}
172175
else
173176
{
@@ -180,6 +183,10 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
180183
#else
181184
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_CONN);
182185
#endif
186+
wfx_rsi.join_retries = 0;
187+
retryInterval = WLAN_MIN_RETRY_TIMER_MS;
188+
if (is_wifi_disconnection_event)
189+
is_wifi_disconnection_event = false;
183190
}
184191
}
185192

@@ -195,9 +202,10 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
195202
*********************************************************************/
196203
static void wfx_rsi_join_fail_cb(uint16_t status, uint8_t * buf, uint32_t len)
197204
{
198-
WFX_RSI_LOG("%s: error: failed status: %02x on try %d", __func__, status, wfx_rsi.join_retries);
205+
WFX_RSI_LOG("%s: error: failed status: %02x", __func__, status);
199206
wfx_rsi.join_retries += 1;
200-
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
207+
wfx_rsi.dev_state &= ~(WFX_RSI_ST_STA_CONNECTING | WFX_RSI_ST_STA_CONNECTED);
208+
is_wifi_disconnection_event = true;
201209
xEventGroupSetBits(wfx_rsi.events, WFX_EVT_STA_START_JOIN);
202210
}
203211
#ifdef RS911X_SOCKETS
@@ -420,39 +428,37 @@ static void wfx_rsi_do_join(void)
420428
*/
421429
wfx_rsi.dev_state |= WFX_RSI_ST_STA_CONNECTING;
422430

431+
if ((status = rsi_wlan_register_callbacks(RSI_JOIN_FAIL_CB, wfx_rsi_join_fail_cb)) != RSI_SUCCESS)
432+
{
433+
WFX_RSI_LOG("%s: RSI callback register join failed with status: %02x", __func__, status);
434+
}
435+
423436
/* Try to connect Wifi with given Credentials
424-
* until there is a success or maximum number of tries allowed
437+
* untill there is a success or maximum number of tries allowed
425438
*/
426-
while (++wfx_rsi.join_retries < WFX_RSI_CONFIG_MAX_JOIN)
439+
while (is_wifi_disconnection_event || wfx_rsi.join_retries <= WFX_RSI_CONFIG_MAX_JOIN)
427440
{
428-
429441
/* Call rsi connect call with given ssid and password
430442
* And check there is a success
431443
*/
432-
433444
if ((status = rsi_wlan_connect_async((int8_t *) &wfx_rsi.sec.ssid[0], (rsi_security_mode_t) wfx_rsi.sec.security,
434445
&wfx_rsi.sec.passkey[0], wfx_rsi_join_cb)) != RSI_SUCCESS)
435446
{
436447

437448
wfx_rsi.dev_state &= ~WFX_RSI_ST_STA_CONNECTING;
438449
WFX_RSI_LOG("%s: rsi_wlan_connect_async failed with status: %02x on try %d", __func__, status,
439450
wfx_rsi.join_retries);
440-
vTaskDelay(400);
441-
/* TODO - Start a timer.. to retry */
451+
452+
wfx_retry_interval_handler(is_wifi_disconnection_event, wfx_rsi.join_retries);
453+
wfx_rsi.join_retries++;
442454
}
443455
else
444456
{
457+
WFX_RSI_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0],
458+
wfx_rsi.join_retries);
445459
break; // exit while loop
446460
}
447461
}
448-
if (wfx_rsi.join_retries == MAX_JOIN_RETRIES_COUNT)
449-
{
450-
WFX_RSI_LOG("Connect failed after %d tries", wfx_rsi.join_retries);
451-
}
452-
else
453-
{
454-
WFX_RSI_LOG("%s: starting JOIN to %s after %d tries\n", __func__, (char *) &wfx_rsi.sec.ssid[0], wfx_rsi.join_retries);
455-
}
456462
WFX_RSI_LOG("Returning the do join");
457463
}
458464
}
@@ -835,4 +841,46 @@ int32_t wfx_rsi_init_platform()
835841
return status;
836842
}
837843

844+
/********************************************************************************************
845+
* @fn void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin)
846+
* @brief
847+
* Based on condition will delay for a certain period of time.
848+
* @param[in] is_wifi_disconnection_event
849+
* @param[in] retryJoin
850+
* @return None
851+
********************************************************************************************/
852+
void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin)
853+
{
854+
if (!is_wifi_disconnection_event)
855+
{
856+
/* After the reboot or a commissioning time device failed to connect with AP.
857+
* Device will retry to connect with AP upto WFX_RSI_CONFIG_MAX_JOIN retries.
858+
*/
859+
if (retryJoin < MAX_JOIN_RETRIES_COUNT)
860+
{
861+
SILABS_LOG("%s: Next attempt after %d Seconds", __func__, CONVERT_MS_TO_SEC(WLAN_RETRY_TIMER_MS));
862+
vTaskDelay(pdMS_TO_TICKS(WLAN_RETRY_TIMER_MS));
863+
}
864+
else
865+
{
866+
SILABS_LOG("Connect failed after max %d tries", retryJoin);
867+
}
868+
}
869+
else
870+
{
871+
/* After disconnection
872+
* At the telescopic time interval device try to reconnect with AP, upto WLAN_MAX_RETRY_TIMER_MS intervals
873+
* are telescopic. If interval exceed WLAN_MAX_RETRY_TIMER_MS then it will try to reconnect at
874+
* WLAN_MAX_RETRY_TIMER_MS intervals.
875+
*/
876+
if (retryInterval > WLAN_MAX_RETRY_TIMER_MS)
877+
{
878+
retryInterval = WLAN_MAX_RETRY_TIMER_MS;
879+
}
880+
SILABS_LOG("%s: Next attempt after %d Seconds", __func__, CONVERT_MS_TO_SEC(retryInterval));
881+
vTaskDelay(pdMS_TO_TICKS(retryInterval));
882+
retryInterval += retryInterval;
883+
}
884+
}
885+
838886
struct wfx_rsi wfx_rsi;

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

+8
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
#define WLAN_DRIVER_TASK_PRIORITY 2
5454
#define MAX_JOIN_RETRIES_COUNT 5
5555

56+
// WLAN retry time intervals in milli seconds
57+
#define WLAN_MAX_RETRY_TIMER_MS 30000
58+
#define WLAN_MIN_RETRY_TIMER_MS 1000
59+
#define WLAN_RETRY_TIMER_MS 5000
60+
#define CONVERT_MS_TO_SEC(TimeInMS) (TimeInMS / 1000)
61+
5662
// WLAN related Macros
5763
#define ETH_FRAME 0
5864
#define CMP_SUCCESS 0
@@ -277,6 +283,8 @@ void wfx_rsi_pkt_add_data(void * p, uint8_t * buf, uint16_t len, uint16_t off);
277283
int32_t wfx_rsi_send_data(void * p, uint16_t len);
278284
#endif /* RS911X_WIFI */
279285

286+
void wfx_retry_interval_handler(bool is_wifi_disconnection_event, uint16_t retryJoin);
287+
280288
#ifdef __cplusplus
281289
}
282290
#endif

0 commit comments

Comments
 (0)