From 075ca4928acf7563b95a65a7d06cffa3f2b5a591 Mon Sep 17 00:00:00 2001 From: Chaitanya Tata Date: Tue, 26 Dec 2023 01:00:21 +0530 Subject: [PATCH] modules: hostap: Add a connect/disconnect event helpers These can be abstracted from the core WPA supplicant. Signed-off-by: Chaitanya Tata --- modules/hostap/src/supp_events.c | 34 ++++++++++++++++++++++++++++++-- modules/hostap/src/supp_events.h | 2 ++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/modules/hostap/src/supp_events.c b/modules/hostap/src/supp_events.c index a17fff855a6..1cd38cb7da7 100644 --- a/modules/hostap/src/supp_events.c +++ b/modules/hostap/src/supp_events.c @@ -9,6 +9,7 @@ #include "includes.h" #include "common.h" #include "common/ieee802_11_defs.h" +#include "wpa_supplicant_i.h" #include @@ -186,6 +187,35 @@ static int wpa_supp_process_status(struct supp_int_event_data *event_data, char return ret; } +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); + + return send_wifi_mgmt_event(wpa_s->ifname, + NET_EVENT_WIFI_CMD_CONNECT_RESULT, + (void *)&status, + sizeof(int)); +} + +int send_wifi_mgmt_disc_event(void *ctx, int reason_code) +{ + struct wpa_supplicant *wpa_s = ctx; + int status = wpas_to_wifi_mgmt_diconn_status(reason_code); + enum net_event_wifi_cmd event; + + if (wpa_s->wpa_state >= WPA_COMPLETED) { + event = NET_EVENT_WIFI_CMD_DISCONNECT_RESULT; + } else { + event = NET_EVENT_WIFI_CMD_CONNECT_RESULT; + } + + return send_wifi_mgmt_event(wpa_s->ifname, + event, + (void *)&status, + sizeof(int)); +} + int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event, void *wpa_supp_status, size_t len) { @@ -202,11 +232,11 @@ int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event, switch (event) { case NET_EVENT_WIFI_CMD_CONNECT_RESULT: wifi_mgmt_raise_connect_result_event(iface, - wpas_to_wifi_mgmt_conn_status(*(int *)wpa_supp_status)); + *(int *)wpa_supp_status); break; case NET_EVENT_WIFI_CMD_DISCONNECT_RESULT: wifi_mgmt_raise_disconnect_result_event(iface, - wpas_to_wifi_mgmt_diconn_status(*(int *)wpa_supp_status)); + *(int *)wpa_supp_status); break; case NET_EVENT_WPA_SUPP_CMD_INT_EVENT: event_data.data = &data; diff --git a/modules/hostap/src/supp_events.h b/modules/hostap/src/supp_events.h index 86d8fe0e225..cc4d9591af7 100644 --- a/modules/hostap/src/supp_events.h +++ b/modules/hostap/src/supp_events.h @@ -45,6 +45,8 @@ enum net_event_wpa_supp_cmd { #define NET_EVENT_WPA_SUPP_INT_EVENT \ (_NET_MGMT_WPA_SUPP_EVENT | NET_EVENT_WPA_SUPP_CMD_INT_EVENT) +int send_wifi_mgmt_conn_event(void *ctx, int status_code); +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);