blob: 29b4c03160ba8c90f376ede61899d2693294f6a2 [file] [log] [blame]
developerd243af02023-12-21 14:49:33 +08001From 55220dcc0fcd43270edf583720e0b36e453dc2d7 Mon Sep 17 00:00:00 2001
developer1c2c7d42023-01-18 18:20:58 +08002From: MeiChia Chiu <meichia.chiu@mediatek.com>
3Date: Tue, 31 May 2022 21:15:54 +0800
developerd243af02023-12-21 14:49:33 +08004Subject: [PATCH 03/54] mtk: hostapd: add support for runtime set in-band
developer1c2c7d42023-01-18 18:20:58 +08005 discovery
6
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---
16 hostapd/ctrl_iface.c | 66 ++++++++++++++++++++++++++++++++++++
17 hostapd/hostapd_cli.c | 20 +++++++++++
18 src/ap/beacon.c | 5 ++-
19 src/drivers/driver_nl80211.c | 10 ++++--
20 src/drivers/nl80211_copy.h | 1 +
21 5 files changed, 98 insertions(+), 4 deletions(-)
22
23diff --git a/hostapd/ctrl_iface.c b/hostapd/ctrl_iface.c
developerd243af02023-12-21 14:49:33 +080024index c03e6f608..ee6d492f8 100644
developer1c2c7d42023-01-18 18:20:58 +080025--- a/hostapd/ctrl_iface.c
26+++ b/hostapd/ctrl_iface.c
developerdfb50982023-09-11 13:34:36 +080027@@ -770,6 +770,69 @@ static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
developer1c2c7d42023-01-18 18:20:58 +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+
61+#ifdef CONFIG_FILS
62+ conf->fils_discovery_max_int = 0;
63+ conf->fils_discovery_min_int = 0;
64+#endif /* CONFIG_FILS */
65+ 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;
76+#ifdef CONFIG_FILS
77+ case FILS_DISCOVERY:
78+ /* Enable FILS discovery */
79+ conf->fils_discovery_min_int = interval;
80+ conf->fils_discovery_max_int = interval;
81+ break;
82+#endif /* CONFIG_FILS */
83+ }
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
developerdfb50982023-09-11 13:34:36 +080097@@ -3483,6 +3546,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
developer1c2c7d42023-01-18 18:20:58 +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
developerd243af02023-12-21 14:49:33 +0800108index 61f8cba12..dfc996d49 100644
developer1c2c7d42023-01-18 18:20:58 +0800109--- a/hostapd/hostapd_cli.c
110+++ b/hostapd/hostapd_cli.c
developer505c9432023-05-12 18:58:17 +0800111@@ -655,6 +655,24 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
developer1c2c7d42023-01-18 18:20:58 +0800112 return wpa_ctrl_command(ctrl, buf);
113 }
114
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[])
developer505c9432023-05-12 18:58:17 +0800136@@ -1773,6 +1791,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
developer1c2c7d42023-01-18 18:20:58 +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
developerd243af02023-12-21 14:49:33 +0800146index 6366d77f0..d160675cb 100644
developer1c2c7d42023-01-18 18:20:58 +0800147--- a/src/ap/beacon.c
148+++ b/src/ap/beacon.c
developer8bff6472023-07-17 11:11:44 +0800149@@ -1648,6 +1648,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
developer1c2c7d42023-01-18 18:20:58 +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;
developer8bff6472023-07-17 11:11:44 +0800158@@ -1656,7 +1658,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
developer1c2c7d42023-01-18 18:20:58 +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)
163+ if (params->fd_max_int || (is_6ghz_op_class(hapd->iconf->op_class) &&
164+ !params->unsol_bcast_probe_resp_interval))
165 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
developerd243af02023-12-21 14:49:33 +0800169index 98510f1cf..a3e436e95 100644
developer1c2c7d42023-01-18 18:20:58 +0800170--- a/src/drivers/driver_nl80211.c
171+++ b/src/drivers/driver_nl80211.c
developerd243af02023-12-21 14:49:33 +0800172@@ -4706,9 +4706,10 @@ static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg,
developer1c2c7d42023-01-18 18:20:58 +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 }
developerd243af02023-12-21 14:49:33 +0800185@@ -5320,7 +5321,10 @@ static int wpa_driver_nl80211_set_ap(void *priv,
developer1c2c7d42023-01-18 18:20:58 +0800186 #endif /* CONFIG_SAE */
187
188 #ifdef CONFIG_FILS
189- if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0)
190+ if ((params->fd_max_int ||
191+ ((params->freq->freq > 5950 && params->freq->freq <= 7115) &&
192+ !(params->unsol_bcast_probe_resp_interval))) &&
193+ 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
developerd243af02023-12-21 14:49:33 +0800198index c59fec406..82860ae32 100644
developer1c2c7d42023-01-18 18:20:58 +0800199--- a/src/drivers/nl80211_copy.h
200+++ b/src/drivers/nl80211_copy.h
developer8bff6472023-07-17 11:11:44 +0800201@@ -7591,6 +7591,7 @@ enum nl80211_fils_discovery_attributes {
developer1c2c7d42023-01-18 18:20:58 +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--
developerdfb50982023-09-11 13:34:36 +08002102.18.0
developer1c2c7d42023-01-18 18:20:58 +0800211