Skip to content

Commit

Permalink
modules: hostap: Add a connect/disconnect event helpers
Browse files Browse the repository at this point in the history
These can be abstracted from the core WPA supplicant.

Signed-off-by: Chaitanya Tata <[email protected]>
  • Loading branch information
krish2718 authored and nordicjm committed Jan 8, 2024
1 parent a18f1bb commit 075ca49
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 32 additions & 2 deletions modules/hostap/src/supp_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "includes.h"
#include "common.h"
#include "common/ieee802_11_defs.h"
#include "wpa_supplicant_i.h"

#include <zephyr/net/wifi_mgmt.h>

Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions modules/hostap/src/supp_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 075ca49

Please sign in to comment.