Skip to content

Commit

Permalink
modules: hostap: Implement AP connected station events
Browse files Browse the repository at this point in the history
These are to intimate the applications about connected Stations.

Implements SHEL-2345.

Signed-off-by: Chaitanya Tata <[email protected]>
  • Loading branch information
krish2718 authored and nordicjm committed Jan 8, 2024
1 parent 15a9a26 commit 5025f81
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
63 changes: 63 additions & 0 deletions modules/hostap/src/supp_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
#include "common/ieee802_11_defs.h"
#include "wpa_supplicant_i.h"

#ifdef CONFIG_AP
#include "ap/sta_info.h"
#include "ap/ieee802_11.h"
#include "ap/hostapd.h"
#endif /* CONFIG_AP */

#include <zephyr/net/wifi_mgmt.h>

/* Re-defines MAC2STR with address of the element */
Expand Down Expand Up @@ -240,6 +246,31 @@ int send_wifi_mgmt_disc_event(void *ctx, int reason_code)
}

#ifdef CONFIG_AP

static enum wifi_link_mode get_sta_link_mode(struct wpa_supplicant *wpa_s, struct sta_info *sta)
{
if (sta->flags & WLAN_STA_HE) {
return WIFI_6;
} else if (sta->flags & WLAN_STA_VHT) {
return WIFI_5;
} else if (sta->flags & WLAN_STA_HT) {
return WIFI_4;
} else if (sta->flags & WLAN_STA_NONERP) {
return WIFI_1;
} else if (wpa_s->assoc_freq > 4000) {
return WIFI_2;
} else if (wpa_s->assoc_freq > 2000) {
return WIFI_3;
} else {
return WIFI_LINK_MODE_UNKNOWN;
}
}

static bool is_twt_capable(struct wpa_supplicant *wpa_s, struct sta_info *sta)
{
return hostapd_get_he_twt_responder(wpa_s->ap_iface->bss[0], IEEE80211_MODE_AP);
}

int send_wifi_mgmt_ap_status(void *ctx,
enum net_event_wifi_cmd event, enum wifi_ap_status ap_status)
{
Expand All @@ -251,6 +282,30 @@ int send_wifi_mgmt_ap_status(void *ctx,
(void *)&status,
sizeof(int));
}

int send_wifi_mgmt_ap_sta_event(void *ctx,
enum net_event_wifi_cmd event, void *data)
{
struct sta_info *sta = data;
struct wpa_supplicant *wpa_s = ctx;
struct wifi_ap_sta_info sta_info = { 0 };

if (!wpa_s || !sta) {
return -EINVAL;
}

memcpy(sta_info.mac, sta->addr, sizeof(sta_info.mac));

if (event == NET_EVENT_WIFI_CMD_AP_STA_CONNECTED) {
sta_info.link_mode = get_sta_link_mode(wpa_s, sta);
sta_info.twt_capable = is_twt_capable(wpa_s, sta);
}

return send_wifi_mgmt_event(wpa_s->ifname,
event,
(void *)&sta_info,
sizeof(sta_info));
}
#endif /* CONFIG_AP */

int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event,
Expand Down Expand Up @@ -284,6 +339,14 @@ int send_wifi_mgmt_event(const char *ifname, enum net_event_wifi_cmd event,
wifi_mgmt_raise_ap_disable_result_event(iface,
*(int *)wpa_supp_status);
break;
case NET_EVENT_WIFI_CMD_AP_STA_CONNECTED:
wifi_mgmt_raise_ap_sta_connected_event(iface,
(struct wifi_ap_sta_info *)wpa_supp_status);
break;
case NET_EVENT_WIFI_CMD_AP_STA_DISCONNECTED:
wifi_mgmt_raise_ap_sta_disconnected_event(iface,
(struct wifi_ap_sta_info *)wpa_supp_status);
break;
#endif /* CONFIG_AP */
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 @@ -53,6 +53,8 @@ int generate_supp_state_event(const char *ifname, enum net_event_wpa_supp_cmd ev
#ifdef CONFIG_AP
int send_wifi_mgmt_ap_status(void *ctx,
enum net_event_wifi_cmd event, enum wifi_ap_status);
int send_wifi_mgmt_ap_sta_event(void *ctx,
enum net_event_wifi_cmd event, void *data);
#endif /* CONFIG_AP */

#define REASON_CODE_LEN 18
Expand Down

0 comments on commit 5025f81

Please sign in to comment.