@@ -67,6 +67,12 @@ bool hasNotifiedIPV4 = false;
67
67
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
68
68
bool hasNotifiedWifiConnectivity = false;
69
69
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
+
70
76
/*
71
77
* This file implements the interface to the RSI SAPIs
72
78
*/
@@ -195,12 +201,9 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
195
201
* We should enable retry.. (Need config variable for this)
196
202
*/
197
203
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 )
202
206
xEventGroupSetBits (wfx_rsi .events , WFX_EVT_STA_START_JOIN );
203
- }
204
207
}
205
208
else
206
209
{
@@ -213,6 +216,8 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
213
216
#else
214
217
xEventGroupSetBits (wfx_rsi .events , WFX_EVT_STA_CONN );
215
218
#endif
219
+ wfx_rsi .join_retries = 0 ;
220
+ retryInterval = WLAN_MIN_RETRY_TIMER_MS ;
216
221
}
217
222
}
218
223
@@ -228,9 +233,10 @@ static void wfx_rsi_join_cb(uint16_t status, const uint8_t * buf, const uint16_t
228
233
*********************************************************************/
229
234
static void wfx_rsi_join_fail_cb (uint16_t status , uint8_t * buf , uint32_t len )
230
235
{
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 );
232
237
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;
234
240
xEventGroupSetBits (wfx_rsi .events , WFX_EVT_STA_START_JOIN );
235
241
}
236
242
#ifdef RS911X_SOCKETS
@@ -461,6 +467,7 @@ static void wfx_rsi_do_join(void)
461
467
{
462
468
WFX_RSI_LOG ("%s: WLAN: connecting to %s==%s, sec=%d" , __func__ , & wfx_rsi .sec .ssid [0 ], & wfx_rsi .sec .passkey [0 ],
463
469
wfx_rsi .sec .security );
470
+
464
471
/*
465
472
* Join the network
466
473
*/
@@ -469,12 +476,16 @@ static void wfx_rsi_do_join(void)
469
476
*/
470
477
wfx_rsi .dev_state |= WFX_RSI_ST_STA_CONNECTING ;
471
478
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
+
472
484
/* Try to connect Wifi with given Credentials
473
485
* untill there is a success or maximum number of tries allowed
474
486
*/
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 )
476
488
{
477
-
478
489
/* Call rsi connect call with given ssid and password
479
490
* And check there is a success
480
491
*/
@@ -485,22 +496,17 @@ static void wfx_rsi_do_join(void)
485
496
wfx_rsi .dev_state &= ~WFX_RSI_ST_STA_CONNECTING ;
486
497
WFX_RSI_LOG ("%s: rsi_wlan_connect_async failed with status: %02x on try %d" , __func__ , status ,
487
498
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 ++ ;
490
502
}
491
503
else
492
504
{
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 );
493
507
break ; // exit while loop
494
508
}
495
509
}
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
- }
504
510
}
505
511
}
506
512
0 commit comments