Skip to content

Commit 5dc7d84

Browse files
committed
drivers: wifi: esp32: Add WiFi events for station connect and disconnect
Added events for when the station iface is used to connect and disconnect. These events will feed the NET_EVENT_WIFI_CONNECT_RESULT and NET_EVENT_WIFI_DISCONNECT_RESULT events to send information to applications making use of them Signed-off-by: Humphrey Chiramba <[email protected]>
1 parent b8d4a6a commit 5dc7d84

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

drivers/wifi/esp32/src/esp_wifi_drv.c

+70-6
Original file line numberDiff line numberDiff line change
@@ -307,20 +307,84 @@ static void esp_wifi_handle_sta_connect_event(void *event_data)
307307
#endif
308308
}
309309

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+
310374
static void esp_wifi_handle_sta_disconnect_event(void *event_data)
311375
{
312376
wifi_event_sta_disconnected_t *event = (wifi_event_sta_disconnected_t *)event_data;
313377

378+
LOG_DBG("Disconnect reason: %d", event->reason);
379+
314380
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);
319382
} else {
320-
wifi_mgmt_raise_disconnect_result_event(esp32_wifi_iface, -1);
383+
handle_disconnect_event_while_not_connected(event);
321384
}
322385

323-
LOG_DBG("Disconnect reason: %d", event->reason);
386+
wifi_mgmt_raise_disconnect_result_event(esp32_wifi_iface, WIFI_REASON_DISCONN_SUCCESS);
387+
324388
switch (event->reason) {
325389
case WIFI_REASON_AUTH_EXPIRE:
326390
case WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT:

0 commit comments

Comments
 (0)