9e187253d4ccd290784c2871af8b366dff9dfd6f
[openwrt/staging/ynezz.git] / package / network / services / hostapd / patches / 110-notify-mgmt-frames.patch
1 From 53f8fdb534d5222a0e852e38afde3f49832ace06 Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rapha=C3=ABl=20M=C3=A9lotte?= <raphael.melotte@mind.be>
3 Date: Thu, 26 Nov 2020 09:27:40 +0100
4 Subject: [PATCH] hostapd: Add an option to notify management frames on
5 ctrl_iface
6 MIME-Version: 1.0
7 Content-Type: text/plain; charset=UTF-8
8 Content-Transfer-Encoding: 8bit
9
10 In some contexts (e.g. Multi-AP) it can be useful to have access to
11 some of the management frames in upper layers (e.g. to be able to
12 process the content of association requests externally).
13
14 Add 'notify_mgmt_frames'. When enabled, it will notify the ctrl_iface
15 when a management frame arrives using 'AP_MGMT_FRAME_RECEIVED'.
16
17 Note that to avoid completely flooding the ctrl_iface, not all
18 management frames are included (e.g. beacons are excluded).
19
20 Signed-off-by: Raphaël Mélotte <raphael.melotte@mind.be>
21 ---
22 hostapd/config_file.c | 2 ++
23 hostapd/hostapd.conf | 4 ++++
24 src/ap/ap_config.h | 2 ++
25 src/ap/ieee802_11.c | 25 +++++++++++++++++++++++++
26 src/common/wpa_ctrl.h | 3 +++
27 5 files changed, 36 insertions(+)
28
29 --- a/hostapd/config_file.c
30 +++ b/hostapd/config_file.c
31 @@ -4456,6 +4456,8 @@ static int hostapd_config_fill(struct ho
32 bss->multicast_to_unicast = atoi(pos);
33 } else if (os_strcmp(buf, "broadcast_deauth") == 0) {
34 bss->broadcast_deauth = atoi(pos);
35 + } else if (os_strcmp(buf, "notify_mgmt_frames") == 0) {
36 + conf->notify_mgmt_frames = atoi(pos);
37 #ifdef CONFIG_DPP
38 } else if (os_strcmp(buf, "dpp_name") == 0) {
39 os_free(bss->dpp_name);
40 --- a/hostapd/hostapd.conf
41 +++ b/hostapd/hostapd.conf
42 @@ -571,6 +571,10 @@ wmm_ac_vo_acm=0
43 # Default: 1 (enabled)
44 #broadcast_deauth=1
45
46 +# Get notifications for management frames:
47 +# Default: 0 (disabled)
48 +#notify_mgmt_frames=0
49 +
50 ##### IEEE 802.11n related configuration ######################################
51
52 # ieee80211n: Whether IEEE 802.11n (HT) is enabled
53 --- a/src/ap/ap_config.h
54 +++ b/src/ap/ap_config.h
55 @@ -1060,6 +1060,8 @@ struct hostapd_config {
56 unsigned int airtime_update_interval;
57 #define AIRTIME_MODE_MAX (__AIRTIME_MODE_MAX - 1)
58 #endif /* CONFIG_AIRTIME_POLICY */
59 +
60 + u8 notify_mgmt_frames;
61 };
62
63
64 --- a/src/ap/ieee802_11.c
65 +++ b/src/ap/ieee802_11.c
66 @@ -4878,6 +4878,28 @@ static int handle_action(struct hostapd_
67 return 1;
68 }
69
70 +/**
71 + * notify_mgmt_frame - notify of management frames on the control interface.
72 + * @hapd: hostapd BSS data structure (the BSS to which the management frame was
73 + * sent to)
74 + * @buf: management frame data (starting from IEEE 802.11 header)
75 + * @len: length of frame data in octets
76 + *
77 + * Notify the control interface of any management frame.
78 + */
79 +static void notify_mgmt_frame(struct hostapd_data *hapd, const u8 *buf,
80 + size_t len)
81 +{
82 +
83 + int hex_len = len * 2 + 1;
84 + char *hex = os_malloc(hex_len);
85 +
86 + if (hex) {
87 + wpa_snprintf_hex(hex, hex_len, buf, len);
88 + wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, AP_MGMT_FRAME_RECEIVED "buf=%s", hex);
89 + os_free(hex);
90 + }
91 +}
92
93 /**
94 * ieee802_11_mgmt - process incoming IEEE 802.11 management frames
95 @@ -4969,6 +4991,9 @@ int ieee802_11_mgmt(struct hostapd_data
96 if (hapd->iconf->track_sta_max_num)
97 sta_track_add(hapd->iface, mgmt->sa, ssi_signal);
98
99 + if (hapd->iconf->notify_mgmt_frames)
100 + notify_mgmt_frame(hapd, buf, len);
101 +
102 switch (stype) {
103 case WLAN_FC_STYPE_AUTH:
104 wpa_printf(MSG_DEBUG, "mgmt::auth");
105 --- a/src/common/wpa_ctrl.h
106 +++ b/src/common/wpa_ctrl.h
107 @@ -396,6 +396,9 @@ extern "C" {
108 #define BIT(x) (1U << (x))
109 #endif
110
111 +/* Event triggered for received management frame */
112 +#define AP_MGMT_FRAME_RECEIVED "AP-MGMT-FRAME-RECEIVED "
113 +
114 /* BSS command information masks */
115
116 #define WPA_BSS_MASK_ALL 0xFFFDFFFF