@@ -307,35 +307,91 @@ static void esp_wifi_handle_sta_connect_event(void *event_data)
307
307
#endif
308
308
}
309
309
310
- static void esp_wifi_handle_sta_disconnect_event ( void * event_data )
310
+ static int handle_disconnect_event_while_not_connected ( wifi_event_sta_disconnected_t * event )
311
311
{
312
- wifi_event_sta_disconnected_t * event = ( wifi_event_sta_disconnected_t * ) event_data ;
312
+ int status = 0 ;
313
313
314
- if (esp32_data .state == ESP32_STA_CONNECTED ) {
315
- #if defined(CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4 )
316
- net_dhcpv4_stop (esp32_wifi_iface );
317
- #endif
318
- wifi_mgmt_raise_disconnect_result_event (esp32_wifi_iface , 0 );
319
- } else {
320
- wifi_mgmt_raise_disconnect_result_event (esp32_wifi_iface , -1 );
321
- }
322
-
323
- LOG_DBG ("Disconnect reason: %d" , event -> reason );
324
314
switch (event -> reason ) {
325
- case WIFI_REASON_AUTH_EXPIRE :
315
+ case WIFI_REASON_ROAMING :
316
+ LOG_DBG ("Roaming" );
317
+ break ;
318
+ case WIFI_REASON_ASSOC_LEAVE :
319
+ LOG_DBG ("Disconnect Requested" );
320
+ break ;
326
321
case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT :
327
- case WIFI_REASON_AUTH_FAIL :
328
322
case WIFI_REASON_HANDSHAKE_TIMEOUT :
329
- case WIFI_REASON_MIC_FAILURE :
330
323
LOG_DBG ("STA Auth Error" );
324
+ status = WIFI_STATUS_CONN_WRONG_PASSWORD ;
325
+ break ;
326
+ case WIFI_REASON_DISCONN_INACTIVITY :
327
+ case WIFI_REASON_TIMEOUT :
328
+ LOG_DBG ("STA Connection Timeout" );
329
+ status = WIFI_STATUS_CONN_TIMEOUT ;
331
330
break ;
332
331
case WIFI_REASON_NO_AP_FOUND :
333
332
LOG_DBG ("AP Not found" );
333
+ status = WIFI_STATUS_CONN_AP_NOT_FOUND ;
334
+ break ;
335
+ default :
336
+ LOG_DBG ("Generic Failure" );
337
+ status = WIFI_STATUS_CONN_FAIL ;
338
+ break ;
339
+ }
340
+
341
+ return status ;
342
+ }
343
+
344
+ static int handle_disconnect_event_while_connected (wifi_event_sta_disconnected_t * event )
345
+ {
346
+ #if defined(CONFIG_ESP32_WIFI_STA_AUTO_DHCPV4 )
347
+ net_dhcpv4_stop (esp32_wifi_iface );
348
+ #endif
349
+
350
+ int status = 0 ;
351
+
352
+ switch (event -> reason ) {
353
+ case WIFI_REASON_ROAMING :
354
+ LOG_DBG ("Roaming" );
355
+ break ;
356
+ case WIFI_REASON_AUTH_LEAVE :
357
+ LOG_DBG ("AP Requested Disconnect" );
358
+ status = WIFI_REASON_DISCONN_AP_LEAVING ;
359
+ break ;
360
+ case WIFI_REASON_ASSOC_LEAVE :
361
+ LOG_DBG ("Disconnect Was Requested" );
362
+ status = WIFI_REASON_DISCONN_USER_REQUEST ;
363
+ break ;
364
+ case WIFI_REASON_AUTH_EXPIRE :
365
+ LOG_DBG ("AP not active" );
366
+ status = WIFI_REASON_DISCONN_INACTIVITY ;
334
367
break ;
335
368
default :
369
+ LOG_DBG ("Generic Failure" );
370
+ status = WIFI_REASON_DISCONN_UNSPECIFIED ;
336
371
break ;
337
372
}
338
373
374
+ return status ;
375
+ }
376
+
377
+ static void esp_wifi_handle_sta_disconnect_event (void * event_data )
378
+ {
379
+ wifi_event_sta_disconnected_t * event = (wifi_event_sta_disconnected_t * )event_data ;
380
+
381
+ LOG_DBG ("Disconnect reason: %d" , event -> reason );
382
+
383
+ int disconn_status = 0 ;
384
+
385
+ if (esp32_data .state == ESP32_STA_CONNECTED ) {
386
+ disconn_status = handle_disconnect_event_while_connected (event );
387
+ wifi_mgmt_raise_disconnect_result_event (esp32_wifi_iface , disconn_status );
388
+ } else {
389
+ disconn_status = handle_disconnect_event_while_not_connected (event );
390
+ wifi_mgmt_raise_connect_result_event (esp32_wifi_iface , disconn_status );
391
+ }
392
+
393
+ wifi_mgmt_raise_disconnect_complete_event (esp32_wifi_iface , WIFI_REASON_DISCONN_SUCCESS );
394
+
339
395
if (IS_ENABLED (CONFIG_ESP32_WIFI_STA_RECONNECT ) &&
340
396
(event -> reason != WIFI_REASON_ASSOC_LEAVE )) {
341
397
esp32_data .state = ESP32_STA_CONNECTING ;
0 commit comments