diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 0dd226e3f16..0a714515672 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -7,6 +7,7 @@ #include #include +#include #include "includes.h" #include "common.h" @@ -400,6 +401,8 @@ static int wpas_disconnect_network(const struct device *dev) { int ret = 0; struct net_if *iface = net_if_lookup_by_dev(dev); + struct wpa_supplicant *wpa_s; + bool is_ap = false; if (!iface) { ret = -EINVAL; @@ -407,8 +410,19 @@ static int wpas_disconnect_network(const struct device *dev) goto out; } + wpa_s = get_wpa_s_handle(dev); + if (!wpa_s) { + ret = -1; + wpa_printf(MSG_ERROR, "Interface %s not found", dev->name); + goto out; + } + k_mutex_lock(&wpa_supplicant_mutex, K_FOREVER); + if (wpa_s->current_ssid && wpa_s->current_ssid->mode == WPAS_MODE_AP) { + is_ap = true; + } + wpa_supp_api_ctrl.dev = dev; wpa_supp_api_ctrl.requested_op = DISCONNECT; _wpa_cli_cmd_v("disconnect"); @@ -425,8 +439,16 @@ static int wpas_disconnect_network(const struct device *dev) wpa_supp_restart_status_work(); ret = wait_for_disconnect_complete(dev); - - wifi_mgmt_raise_disconnect_complete_event(iface, ret); +#ifdef CONFIG_AP + if (is_ap) { + send_wifi_mgmt_ap_status(wpa_s, NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT, + ret == 0 ? WIFI_STATUS_AP_SUCCESS : WIFI_STATUS_AP_FAIL); + } else { +#else + { +#endif /* CONFIG_AP */ + wifi_mgmt_raise_disconnect_complete_event(iface, ret); + } return ret; } diff --git a/modules/hostap/src/supp_events.c b/modules/hostap/src/supp_events.c index 1cd38cb7da7..0c7d9b69133 100644 --- a/modules/hostap/src/supp_events.c +++ b/modules/hostap/src/supp_events.c @@ -191,9 +191,20 @@ int send_wifi_mgmt_conn_event(void *ctx, int status_code) { struct wpa_supplicant *wpa_s = ctx; int status = wpas_to_wifi_mgmt_conn_status(status_code); + enum net_event_wifi_cmd event; + + if (!wpa_s || !wpa_s->current_ssid) { + return -EINVAL; + } + + if (wpa_s->current_ssid->mode == WPAS_MODE_AP) { + event = NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT; + } else { + event = NET_EVENT_WIFI_CMD_CONNECT_RESULT; + } return send_wifi_mgmt_event(wpa_s->ifname, - NET_EVENT_WIFI_CMD_CONNECT_RESULT, + event, (void *)&status, sizeof(int)); } @@ -204,10 +215,22 @@ int send_wifi_mgmt_disc_event(void *ctx, int reason_code) int status = wpas_to_wifi_mgmt_diconn_status(reason_code); enum net_event_wifi_cmd event; + if (!wpa_s || !wpa_s->current_ssid) { + return -EINVAL; + } + if (wpa_s->wpa_state >= WPA_COMPLETED) { - event = NET_EVENT_WIFI_CMD_DISCONNECT_RESULT; + if (wpa_s->current_ssid->mode == WPAS_MODE_AP) { + event = NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT; + } else { + event = NET_EVENT_WIFI_CMD_DISCONNECT_RESULT; + } } else { - event = NET_EVENT_WIFI_CMD_CONNECT_RESULT; + if (wpa_s->current_ssid->mode == WPAS_MODE_AP) { + event = NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT; + } else { + event = NET_EVENT_WIFI_CMD_CONNECT_RESULT; + } } return send_wifi_mgmt_event(wpa_s->ifname, @@ -216,6 +239,20 @@ int send_wifi_mgmt_disc_event(void *ctx, int reason_code) sizeof(int)); } +#ifdef CONFIG_AP +int send_wifi_mgmt_ap_status(void *ctx, + enum net_event_wifi_cmd event, enum wifi_ap_status ap_status) +{ + struct wpa_supplicant *wpa_s = ctx; + int status = ap_status; + + return send_wifi_mgmt_event(wpa_s->ifname, + event, + (void *)&status, + sizeof(int)); +} +#endif /* CONFIG_AP */ + int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event, void *wpa_supp_status, size_t len) { @@ -238,6 +275,16 @@ int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event, wifi_mgmt_raise_disconnect_result_event(iface, *(int *)wpa_supp_status); break; +#ifdef CONFIG_AP + case NET_EVENT_WIFI_CMD_AP_ENABLE_RESULT: + wifi_mgmt_raise_ap_enable_result_event(iface, + *(int *)wpa_supp_status); + break; + case NET_EVENT_WIFI_CMD_AP_DISABLE_RESULT: + wifi_mgmt_raise_ap_disable_result_event(iface, + *(int *)wpa_supp_status); + break; +#endif /* CONFIG_AP */ case NET_EVENT_WPA_SUPP_CMD_INT_EVENT: event_data.data = &data; if (wpa_supp_process_status(&event_data, (char *)wpa_supp_status) > 0) { diff --git a/modules/hostap/src/supp_events.h b/modules/hostap/src/supp_events.h index cc4d9591af7..a7dc60810a2 100644 --- a/modules/hostap/src/supp_events.h +++ b/modules/hostap/src/supp_events.h @@ -50,6 +50,10 @@ int send_wifi_mgmt_disc_event(void *ctx, int reason_code); int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event, void *status, size_t len); int generate_supp_state_event(const char *ifname, enum net_event_wpa_supp_cmd event, int status); +#ifdef CONFIG_AP +int send_wifi_mgmt_ap_status(void *ctx, + enum net_event_wifi_cmd event, enum wifi_ap_status); +#endif /* CONFIG_AP */ #define REASON_CODE_LEN 18 #define NM_WIFI_EVENT_STR_LEN 64