blob: 0194dccd19b1f3b413e8ce5a42d996ac8d1b6b1f [file] [log] [blame]
developer8eb72a32023-03-30 08:32:07 +08001From 66531c560a9d292b18cc2d3574427fbb0a32f8f4 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
developer8eb72a32023-03-30 08:32:07 +08004Subject: [PATCH 03/25] hostapd: mtk: add support for runtime set in-band
developerc41fcd32022-09-20 22:09:06 +08005 discovery
developer2c9b8e92022-05-13 17:50:31 +08006
7Usage:
8hostapd_cli unsolic_probe_resp [tx_type] [interval]
9
100: disable all in-band discovery
111: enable unsolicited probe response
122: enable FILS discovery
13
14Signed-off-by: MeiChia Chiu <MeiChia.Chiu@mediatek.com>
15---
developer9fe31132022-05-31 21:21:20 +080016 hostapd/ctrl_iface.c | 66 ++++++++++++++++++++++++++++++++++++
17 hostapd/hostapd_cli.c | 20 +++++++++++
developer2c9b8e92022-05-13 17:50:31 +080018 src/ap/beacon.c | 5 ++-
developer34178a82022-06-23 17:44:15 +080019 src/drivers/driver_nl80211.c | 10 ++++--
developer2c9b8e92022-05-13 17:50:31 +080020 src/drivers/nl80211_copy.h | 1 +
developer34178a82022-06-23 17:44:15 +080021 5 files changed, 98 insertions(+), 4 deletions(-)
developer2c9b8e92022-05-13 17:50:31 +080022
23diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
developer81939a52023-03-25 15:31:11 +080024index bc690c5..bb8c74f 100644
developer2c9b8e92022-05-13 17:50:31 +080025--- a/hostapd/ctrl_iface.c
26+++ b/hostapd/ctrl_iface.c
developerc41fcd32022-09-20 22:09:06 +080027@@ -826,6 +826,69 @@ static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +080028
29 #endif /* CONFIG_INTERWORKING */
30
31+static int hostapd_ctrl_iface_inband_discovery(struct hostapd_data *hapd,
32+ const char *cmd)
33+{
34+ struct hostapd_bss_config *conf = hapd->conf;
35+ const char *pos = cmd;
36+ int tx_type, interval, ret;
37+
38+ tx_type = atoi(pos);
39+ if (tx_type < 0 || tx_type > 2) {
40+ wpa_printf(MSG_ERROR, "Invalid tx type\n");
41+ return -1;
42+ }
43+
44+ pos = os_strchr(pos, ' ');
45+ if(!pos)
46+ return -1;
47+ pos++;
48+ interval = atoi(pos);
49+ if (interval < 0 || interval > 20) {
50+ wpa_printf(MSG_ERROR, "Invalid interval value\n");
51+ return -1;
52+ }
53+
54+ wpa_printf(MSG_ERROR, "Set inband discovery type:%d, interval:%d\n",
55+ tx_type, interval);
56+
57+#define DISABLE_INBAND_DISC 0
58+#define UNSOL_PROBE_RESP 1
59+#define FILS_DISCOVERY 2
60+
developer9fe31132022-05-31 21:21:20 +080061+#ifdef CONFIG_FILS
developer2c9b8e92022-05-13 17:50:31 +080062+ conf->fils_discovery_max_int = 0;
63+ conf->fils_discovery_min_int = 0;
developer9fe31132022-05-31 21:21:20 +080064+#endif /* CONFIG_FILS */
developer2c9b8e92022-05-13 17:50:31 +080065+ conf->unsol_bcast_probe_resp_interval = 0;
66+
67+ switch (tx_type) {
68+ case DISABLE_INBAND_DISC:
69+ default:
70+ /* Disable both Unsolicited probe response and FILS discovery*/
71+ break;
72+ case UNSOL_PROBE_RESP:
73+ /* Enable Unsolicited probe response */
74+ conf->unsol_bcast_probe_resp_interval = interval;
75+ break;
developer9fe31132022-05-31 21:21:20 +080076+#ifdef CONFIG_FILS
developer2c9b8e92022-05-13 17:50:31 +080077+ case FILS_DISCOVERY:
78+ /* Enable FILS discovery */
79+ conf->fils_discovery_min_int = interval;
80+ conf->fils_discovery_max_int = interval;
81+ break;
developer9fe31132022-05-31 21:21:20 +080082+#endif /* CONFIG_FILS */
developer2c9b8e92022-05-13 17:50:31 +080083+ }
84+
85+ ret = ieee802_11_update_beacons(hapd->iface);
86+ if(ret) {
87+ wpa_printf(MSG_DEBUG,
88+ "Failed to update with inband discovery parameters\n");
89+ return -1;
90+ }
91+
92+ return 0;
93+}
94
95 #ifdef CONFIG_WNM_AP
96
developerc41fcd32022-09-20 22:09:06 +080097@@ -3434,6 +3497,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +080098 if (hostapd_ctrl_iface_coloc_intf_req(hapd, buf + 15))
99 reply_len = -1;
100 #endif /* CONFIG_WNM_AP */
101+ } else if (os_strncmp(buf, "INBAND_DISCOVERY ", 17) == 0) {
102+ if (hostapd_ctrl_iface_inband_discovery(hapd, buf + 17))
103+ reply_len = -1;
104 } else if (os_strcmp(buf, "GET_CONFIG") == 0) {
105 reply_len = hostapd_ctrl_iface_get_config(hapd, reply,
106 reply_size);
107diff --git a/hostapd/hostapd_cli.c b/hostapd/hostapd_cli.c
developer81939a52023-03-25 15:31:11 +0800108index 85c41d0..db21258 100644
developer2c9b8e92022-05-13 17:50:31 +0800109--- a/hostapd/hostapd_cli.c
110+++ b/hostapd/hostapd_cli.c
developerc41fcd32022-09-20 22:09:06 +0800111@@ -642,6 +642,24 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
112 return wpa_ctrl_command(ctrl, buf);
developer2c9b8e92022-05-13 17:50:31 +0800113 }
developer2c9b8e92022-05-13 17:50:31 +0800114
115+static int hostapd_cli_cmd_inband_discovery(struct wpa_ctrl *ctrl, int argc,
116+ char *argv[])
117+{
118+ char buf[300];
119+ int res;
120+
121+ if (argc < 2) {
122+ printf("Invalid 'inband_discovery' command - two arguments"
123+ "tx_type interval\n");
124+ return -1;
125+ }
126+
127+ res = os_snprintf(buf, sizeof(buf), "INBAND_DISCOVERY %s %s",
128+ argv[0], argv[1]);
129+ if (os_snprintf_error(sizeof(buf), res))
130+ return -1;
131+ return wpa_ctrl_command(ctrl, buf);
132+}
133
134 static int hostapd_cli_cmd_disassoc_imminent(struct wpa_ctrl *ctrl, int argc,
135 char *argv[])
developerc41fcd32022-09-20 22:09:06 +0800136@@ -1749,6 +1767,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
developer2c9b8e92022-05-13 17:50:31 +0800137 { "driver", hostapd_cli_cmd_driver, NULL,
138 "<driver sub command> [<hex formatted data>] = send driver command data" },
139 #endif /* ANDROID */
140+ { "inband_discovery", hostapd_cli_cmd_inband_discovery, NULL,
141+ "<tx type(0/1/2)> <interval> = runtime set inband discovery" },
142 { NULL, NULL, NULL, NULL }
143 };
144
145diff --git a/src/ap/beacon.c b/src/ap/beacon.c
developer81939a52023-03-25 15:31:11 +0800146index 814e86e..1a26f11 100644
developer2c9b8e92022-05-13 17:50:31 +0800147--- a/src/ap/beacon.c
148+++ b/src/ap/beacon.c
developerc41fcd32022-09-20 22:09:06 +0800149@@ -1497,6 +1497,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +0800150 struct wpa_driver_ap_params *params)
151 {
152 params->fd_max_int = hapd->conf->fils_discovery_max_int;
153+ params->unsol_bcast_probe_resp_interval =
154+ hapd->conf->unsol_bcast_probe_resp_interval;
155 if (is_6ghz_op_class(hapd->iconf->op_class) &&
156 params->fd_max_int > FD_MAX_INTERVAL_6GHZ)
157 params->fd_max_int = FD_MAX_INTERVAL_6GHZ;
developerc41fcd32022-09-20 22:09:06 +0800158@@ -1505,7 +1507,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
developer2c9b8e92022-05-13 17:50:31 +0800159 if (params->fd_min_int > params->fd_max_int)
160 params->fd_min_int = params->fd_max_int;
161
162- if (params->fd_max_int)
developer34178a82022-06-23 17:44:15 +0800163+ if (params->fd_max_int || (is_6ghz_op_class(hapd->iconf->op_class) &&
164+ !params->unsol_bcast_probe_resp_interval))
developer2c9b8e92022-05-13 17:50:31 +0800165 return hostapd_gen_fils_discovery(hapd,
166 &params->fd_frame_tmpl_len);
167
168diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
developer81939a52023-03-25 15:31:11 +0800169index 1fa7dd8..c695263 100644
developer2c9b8e92022-05-13 17:50:31 +0800170--- a/src/drivers/driver_nl80211.c
171+++ b/src/drivers/driver_nl80211.c
developerc41fcd32022-09-20 22:09:06 +0800172@@ -4498,9 +4498,10 @@ static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg,
developer2c9b8e92022-05-13 17:50:31 +0800173 params->fd_max_int) ||
174 (params->fd_frame_tmpl &&
175 nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL,
176- params->fd_frame_tmpl_len, params->fd_frame_tmpl)))
177+ params->fd_frame_tmpl_len, params->fd_frame_tmpl)) ||
178+ nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE,
179+ params->unsol_bcast_probe_resp_interval))
180 return -1;
181-
182 nla_nest_end(msg, attr);
183 return 0;
184 }
developerc41fcd32022-09-20 22:09:06 +0800185@@ -4844,7 +4845,10 @@ static int wpa_driver_nl80211_set_ap(void *priv,
developer2c9b8e92022-05-13 17:50:31 +0800186 #endif /* CONFIG_SAE */
187
188 #ifdef CONFIG_FILS
189- if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0)
developer34178a82022-06-23 17:44:15 +0800190+ if ((params->fd_max_int ||
191+ ((params->freq->freq > 5950 && params->freq->freq <= 7115) &&
192+ !(params->unsol_bcast_probe_resp_interval))) &&
developer2c9b8e92022-05-13 17:50:31 +0800193+ nl80211_fils_discovery(bss, msg, params) < 0)
194 goto fail;
195 #endif /* CONFIG_FILS */
196
197diff --git a/src/drivers/nl80211_copy.h b/src/drivers/nl80211_copy.h
developer81939a52023-03-25 15:31:11 +0800198index 0568a79..c4bf3ad 100644
developer2c9b8e92022-05-13 17:50:31 +0800199--- a/src/drivers/nl80211_copy.h
200+++ b/src/drivers/nl80211_copy.h
developer34178a82022-06-23 17:44:15 +0800201@@ -7379,6 +7379,7 @@ enum nl80211_fils_discovery_attributes {
developer2c9b8e92022-05-13 17:50:31 +0800202 NL80211_FILS_DISCOVERY_ATTR_INT_MIN,
203 NL80211_FILS_DISCOVERY_ATTR_INT_MAX,
204 NL80211_FILS_DISCOVERY_ATTR_TMPL,
205+ NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INTE,
206
207 /* keep last */
208 __NL80211_FILS_DISCOVERY_ATTR_LAST,
209--
developer81939a52023-03-25 15:31:11 +08002102.18.0
developer2c9b8e92022-05-13 17:50:31 +0800211