blob: dcbe915a5d71f7e18e9843a801f83e148ac6b916 [file] [log] [blame]
developer34178a82022-06-23 17:44:15 +08001From 76d110deecc1705295b3154ce91d046fb6115c66 Mon Sep 17 00:00:00 2001
developer2c9b8e92022-05-13 17:50:31 +08002From: MeiChia Chiu <meichia.chiu@mediatek.com>
developer9fe31132022-05-31 21:21:20 +08003Date: Tue, 31 May 2022 21:15:54 +0800
4Subject: [PATCH] hostapd: add support for runtime set in-band discovery
developer2c9b8e92022-05-13 17:50:31 +08005
6Usage:
7hostapd_cli unsolic_probe_resp [tx_type] [interval]
8
90: disable all in-band discovery
101: enable unsolicited probe response
112: enable FILS discovery
12
13Signed-off-by: MeiChia Chiu <MeiChia.Chiu@mediatek.com>
14---
developer9fe31132022-05-31 21:21:20 +080015 hostapd/ctrl_iface.c | 66 ++++++++++++++++++++++++++++++++++++
16 hostapd/hostapd_cli.c | 20 +++++++++++
developer2c9b8e92022-05-13 17:50:31 +080017 src/ap/beacon.c | 5 ++-
developer34178a82022-06-23 17:44:15 +080018 src/drivers/driver_nl80211.c | 10 ++++--
developer2c9b8e92022-05-13 17:50:31 +080019 src/drivers/nl80211_copy.h | 1 +
developer34178a82022-06-23 17:44:15 +080020 5 files changed, 98 insertions(+), 4 deletions(-)
developer2c9b8e92022-05-13 17:50:31 +080021
22diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
developer34178a82022-06-23 17:44:15 +080023index 664c59df7..e6a2d4203 100644
developer2c9b8e92022-05-13 17:50:31 +080024--- a/hostapd/ctrl_iface.c
25+++ b/hostapd/ctrl_iface.c
developer9fe31132022-05-31 21:21:20 +080026@@ -769,6 +769,69 @@ static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +080027
28 #endif /* CONFIG_INTERWORKING */
29
30+static int hostapd_ctrl_iface_inband_discovery(struct hostapd_data *hapd,
31+ const char *cmd)
32+{
33+ struct hostapd_bss_config *conf = hapd->conf;
34+ const char *pos = cmd;
35+ int tx_type, interval, ret;
36+
37+ tx_type = atoi(pos);
38+ if (tx_type < 0 || tx_type > 2) {
39+ wpa_printf(MSG_ERROR, "Invalid tx type\n");
40+ return -1;
41+ }
42+
43+ pos = os_strchr(pos, ' ');
44+ if(!pos)
45+ return -1;
46+ pos++;
47+ interval = atoi(pos);
48+ if (interval < 0 || interval > 20) {
49+ wpa_printf(MSG_ERROR, "Invalid interval value\n");
50+ return -1;
51+ }
52+
53+ wpa_printf(MSG_ERROR, "Set inband discovery type:%d, interval:%d\n",
54+ tx_type, interval);
55+
56+#define DISABLE_INBAND_DISC 0
57+#define UNSOL_PROBE_RESP 1
58+#define FILS_DISCOVERY 2
59+
developer9fe31132022-05-31 21:21:20 +080060+#ifdef CONFIG_FILS
developer2c9b8e92022-05-13 17:50:31 +080061+ conf->fils_discovery_max_int = 0;
62+ conf->fils_discovery_min_int = 0;
developer9fe31132022-05-31 21:21:20 +080063+#endif /* CONFIG_FILS */
developer2c9b8e92022-05-13 17:50:31 +080064+ conf->unsol_bcast_probe_resp_interval = 0;
65+
66+ switch (tx_type) {
67+ case DISABLE_INBAND_DISC:
68+ default:
69+ /* Disable both Unsolicited probe response and FILS discovery*/
70+ break;
71+ case UNSOL_PROBE_RESP:
72+ /* Enable Unsolicited probe response */
73+ conf->unsol_bcast_probe_resp_interval = interval;
74+ break;
developer9fe31132022-05-31 21:21:20 +080075+#ifdef CONFIG_FILS
developer2c9b8e92022-05-13 17:50:31 +080076+ case FILS_DISCOVERY:
77+ /* Enable FILS discovery */
78+ conf->fils_discovery_min_int = interval;
79+ conf->fils_discovery_max_int = interval;
80+ break;
developer9fe31132022-05-31 21:21:20 +080081+#endif /* CONFIG_FILS */
developer2c9b8e92022-05-13 17:50:31 +080082+ }
83+
84+ ret = ieee802_11_update_beacons(hapd->iface);
85+ if(ret) {
86+ wpa_printf(MSG_DEBUG,
87+ "Failed to update with inband discovery parameters\n");
88+ return -1;
89+ }
90+
91+ return 0;
92+}
93
94 #ifdef CONFIG_WNM_AP
95
developer34178a82022-06-23 17:44:15 +080096@@ -3336,6 +3399,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +080097 if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15))
98 reply_len = -1;
99 #endif /* CONFIG_WNM_AP */
100+ } else if (os_strncmp(buf, "INBAND_DISCOVERY ", 17) == 0) {
101+ if (hostapd_ctrl_iface_inband_discovery(hapd, buf + 17))
102+ reply_len = -1;
103 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
104 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
105 reply_size);
106diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
developer34178a82022-06-23 17:44:15 +0800107index 60396f3da..4c4c82c9a 100644
developer2c9b8e92022-05-13 17:50:31 +0800108--- a/hostapd/hostapd_cli.c
109+++ b/hostapd/hostapd_cli.c
110@@ -646,6 +646,24 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
111 }
112 #endif /* CONFIG_WPS */
113
114+static int hostapd_cli_cmd_inband_discovery(struct wpa_ctrl *ctrl, int argc,
115+ char *argv[])
116+{
117+ char buf[300];
118+ int res;
119+
120+ if (argc < 2) {
121+ printf("Invalid 'inband_discovery' command - two arguments"
122+ "tx_type interval\n");
123+ return -1;
124+ }
125+
126+ res = os_snprintf(buf, sizeof(buf), "INBAND_DISCOVERY %s %s",
127+ argv[0], argv[1]);
128+ if (os_snprintf_error(sizeof(buf), res))
129+ return -1;
130+ return wpa_ctrl_command(ctrl, buf);
131+}
132
133 static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc,
134 char *argv[])
135@@ -1744,6 +1762,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
136 { "driver", hostapd_cli_cmd_driver, NULL,
137 "<driver sub command> [<hex formatted data>] = send driver command data" },
138 #endif /* ANDROID */
139+ { "inband_discovery", hostapd_cli_cmd_inband_discovery, NULL,
140+ "<tx type(0/1/2)> <interval> = runtime set inband discovery" },
141 { NULL, NULL, NULL, NULL }
142 };
143
144diff --git a/src/ap/beacon.c b/src/ap/beacon.c
developer34178a82022-06-23 17:44:15 +0800145index 58872bfda..c8db86c6e 100644
developer2c9b8e92022-05-13 17:50:31 +0800146--- a/src/ap/beacon.c
147+++ b/src/ap/beacon.c
developer34178a82022-06-23 17:44:15 +0800148@@ -1483,6 +1483,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +0800149 struct wpa_driver_ap_params *params)
150 {
151 params->fd_max_int = hapd->conf->fils_discovery_max_int;
152+ params->unsol_bcast_probe_resp_interval =
153+ hapd->conf->unsol_bcast_probe_resp_interval;
154 if (is_6ghz_op_class(hapd->iconf->op_class) &&
155 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
156 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
developer34178a82022-06-23 17:44:15 +0800157@@ -1491,7 +1493,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +0800158 if (params->fd_min_int > params->fd_max_int)
159 params->fd_min_int = params->fd_max_int;
160
161- if (params->fd_max_int)
developer34178a82022-06-23 17:44:15 +0800162+ if (params->fd_max_int || (is_6ghz_op_class(hapd->iconf->op_class) &&
163+ !params->unsol_bcast_probe_resp_interval))
developer2c9b8e92022-05-13 17:50:31 +0800164 return hostapd_gen_fils_discovery(hapd,
165 &params->fd_frame_tmpl_len);
166
167diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developer34178a82022-06-23 17:44:15 +0800168index 0127a6be2..ee763990f 100644
developer2c9b8e92022-05-13 17:50:31 +0800169--- a/src/drivers/driver_nl80211.c
170+++ b/src/drivers/driver_nl80211.c
developer34178a82022-06-23 17:44:15 +0800171@@ -4493,9 +4493,10 @@ static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg,
developer2c9b8e92022-05-13 17:50:31 +0800172 params->fd_max_int) ||
173 (params->fd_frame_tmpl &&
174 nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL,
175- params->fd_frame_tmpl_len, params->fd_frame_tmpl)))
176+ params->fd_frame_tmpl_len, params->fd_frame_tmpl)) ||
177+ nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE,
178+ params->unsol_bcast_probe_resp_interval))
179 return -1;
180-
181 nla_nest_end(msg, attr);
182 return 0;
183 }
developer34178a82022-06-23 17:44:15 +0800184@@ -4839,7 +4840,10 @@ static int wpa_driver_nl80211_set_ap(void *priv,
developer2c9b8e92022-05-13 17:50:31 +0800185 #endif /* CONFIG_SAE */
186
187 #ifdef CONFIG_FILS
188- if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0)
developer34178a82022-06-23 17:44:15 +0800189+ if ((params->fd_max_int ||
190+ ((params->freq->freq > 5950 && params->freq->freq <= 7115) &&
191+ !(params->unsol_bcast_probe_resp_interval))) &&
developer2c9b8e92022-05-13 17:50:31 +0800192+ nl80211_fils_discovery(bss, msg, params) < 0)
193 goto fail;
194 #endif /* CONFIG_FILS */
195
196diff --git a/src/drivers/nl80211_copy.h b/src/drivers/nl80211_copy.h
developer34178a82022-06-23 17:44:15 +0800197index 0568a7909..c4bf3ad35 100644
developer2c9b8e92022-05-13 17:50:31 +0800198--- a/src/drivers/nl80211_copy.h
199+++ b/src/drivers/nl80211_copy.h
developer34178a82022-06-23 17:44:15 +0800200@@ -7379,6 +7379,7 @@ enum nl80211_fils_discovery_attributes {
developer2c9b8e92022-05-13 17:50:31 +0800201 NL80211_FILS_DISCOVERY_ATTR_INT_MIN,
202 NL80211_FILS_DISCOVERY_ATTR_INT_MAX,
203 NL80211_FILS_DISCOVERY_ATTR_TMPL,
204+ NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE,
205
206 /* keep last */
207 __NL80211_FILS_DISCOVERY_ATTR_LAST,
208--
developer34178a82022-06-23 17:44:15 +08002092.36.1
developer2c9b8e92022-05-13 17:50:31 +0800210