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