-From 53f8fdb534d5222a0e852e38afde3f49832ace06 Mon Sep 17 00:00:00 2001
+From 4a7e0ac26839424e6a91d38fd126160b18a30a60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <raphael.melotte@mind.be>
-Date: Thu, 26 Nov 2020 09:27:40 +0100
-Subject: [PATCH] hostapd: Add an option to notify management frames on
- ctrl_iface
+Date: Mon, 30 Nov 2020 12:10:46 +0100
+Subject: hostapd: Add an option to notify management frames on ctrl_iface
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
-In some contexts (e.g. Multi-AP) it can be useful to have access to
-some of the management frames in upper layers (e.g. to be able to
+In some contexts (e.g., Multi-AP) it can be useful to have access to
+some of the management frames in upper layers (e.g., to be able to
process the content of association requests externally).
Add 'notify_mgmt_frames'. When enabled, it will notify the ctrl_iface
-when a management frame arrives using 'AP_MGMT_FRAME_RECEIVED'.
+when a management frame arrives using the AP-MGMT-FRAME-RECEIVED event
+message.
Note that to avoid completely flooding the ctrl_iface, not all
-management frames are included (e.g. beacons are excluded).
+management frames are included (e.g., Beacon and Probe Request frames
+are excluded).
Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
---
hostapd/config_file.c | 2 ++
hostapd/hostapd.conf | 4 ++++
src/ap/ap_config.h | 2 ++
- src/ap/ieee802_11.c | 25 +++++++++++++++++++++++++
+ src/ap/ieee802_11.c | 28 ++++++++++++++++++++++++++++
src/common/wpa_ctrl.h | 3 +++
- 5 files changed, 36 insertions(+)
+ 5 files changed, 39 insertions(+)
--- a/hostapd/config_file.c
+++ b/hostapd/config_file.c
} else if (os_strcmp(buf, "broadcast_deauth") == 0) {
bss->broadcast_deauth = atoi(pos);
+ } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
-+ conf->notify_mgmt_frames = atoi(pos);
++ bss->notify_mgmt_frames = atoi(pos);
#ifdef CONFIG_DPP
} else if (os_strcmp(buf, "dpp_name") == 0) {
os_free(bss->dpp_name);
# Default: 1 (enabled)
#broadcast_deauth=1
-+# Get notifications for management frames:
++# Get notifications for received Management frames on control interface
+# Default: 0 (disabled)
+#notify_mgmt_frames=0
+
# ieee80211n: Whether IEEE 802.11n (HT) is enabled
--- a/src/ap/ap_config.h
+++ b/src/ap/ap_config.h
-@@ -1060,6 +1060,8 @@ struct hostapd_config {
- unsigned int airtime_update_interval;
- #define AIRTIME_MODE_MAX (__AIRTIME_MODE_MAX - 1)
- #endif /* CONFIG_AIRTIME_POLICY */
-+
-+ u8 notify_mgmt_frames;
- };
+@@ -745,6 +745,8 @@ struct hostapd_bss_config {
+ int broadcast_deauth;
++ int notify_mgmt_frames;
++
+ #ifdef CONFIG_DPP
+ char *dpp_name;
+ char *dpp_mud_url;
--- a/src/ap/ieee802_11.c
+++ b/src/ap/ieee802_11.c
-@@ -4878,6 +4878,28 @@ static int handle_action(struct hostapd_
- return 1;
- }
+@@ -4880,6 +4880,31 @@ static int handle_action(struct hostapd_
-+/**
-+ * notify_mgmt_frame - notify of management frames on the control interface.
-+ * @hapd: hostapd BSS data structure (the BSS to which the management frame was
+
+ /**
++ * notify_mgmt_frame - Notify of Management frames on the control interface
++ * @hapd: hostapd BSS data structure (the BSS to which the Management frame was
+ * sent to)
-+ * @buf: management frame data (starting from IEEE 802.11 header)
-+ * @len: length of frame data in octets
++ * @buf: Management frame data (starting from the IEEE 802.11 header)
++ * @len: Length of frame data in octets
+ *
-+ * Notify the control interface of any management frame.
++ * Notify the control interface of any received Management frame.
+ */
+static void notify_mgmt_frame(struct hostapd_data *hapd, const u8 *buf,
+ size_t len)
+
+ if (hex) {
+ wpa_snprintf_hex(hex, hex_len, buf, len);
-+ wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, AP_MGMT_FRAME_RECEIVED "buf=%s", hex);
++ wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO,
++ AP_MGMT_FRAME_RECEIVED "buf=%s", hex);
+ os_free(hex);
+ }
+}
-
- /**
++
++
++/**
* ieee802_11_mgmt - process incoming IEEE 802.11 management frames
-@@ -4969,6 +4991,9 @@ int ieee802_11_mgmt(struct hostapd_data
+ * @hapd: hostapd BSS data structure (the BSS to which the management frame was
+ * sent to)
+@@ -4969,6 +4994,9 @@ int ieee802_11_mgmt(struct hostapd_data
if (hapd->iconf->track_sta_max_num)
sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
-+ if (hapd->iconf->notify_mgmt_frames)
++ if (hapd->conf->notify_mgmt_frames)
+ notify_mgmt_frame(hapd, buf, len);
+
switch (stype) {
wpa_printf(MSG_DEBUG, "mgmt::auth");
--- a/src/common/wpa_ctrl.h
+++ b/src/common/wpa_ctrl.h
-@@ -396,6 +396,9 @@ extern "C" {
- #define BIT(x) (1U << (x))
- #endif
+@@ -392,6 +392,9 @@ extern "C" {
+ * frame=<saqueryreq/saqueryresp> error=<error string> */
+ #define OCV_FAILURE "OCV-FAILURE "
+/* Event triggered for received management frame */
+#define AP_MGMT_FRAME_RECEIVED "AP-MGMT-FRAME-RECEIVED "
+
- /* BSS command information masks */
-
- #define WPA_BSS_MASK_ALL 0xFFFDFFFF
+ #ifndef BIT
+ #define BIT(x) (1U << (x))
+ #endif