blob: 94bc2b97253c0e700a4b7c20f9344e7964c6f781 [file] [log] [blame]
developer683be522023-05-11 14:24:50 +08001From c7e5ad8609443c3e484ea06df88755de55f5bda0 Mon Sep 17 00:00:00 2001
2From: MeiChia Chiu <meichia.chiu@mediatek.com>
3Date: Tue, 31 May 2022 21:15:54 +0800
4Subject: [PATCH 03/28] hostapd: mtk: add support for runtime set in-band
5 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
24index 8e8a1a7..c4e344e 100644
25--- a/hostapd/ctrl_iface.c
26+++ b/hostapd/ctrl_iface.c
27@@ -827,6 +827,69 @@ static int hostapd_ctrl_iface_send_qos_map_conf(struct hostapd_data *hapd,
28
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
97@@ -3511,6 +3574,9 @@ static int hostapd_ctrl_iface_receive_process(struct hostapd_data *hapd,
98 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
108index bc8993f..05ac5ac 100644
109--- a/hostapd/hostapd_cli.c
110+++ b/hostapd/hostapd_cli.c
111@@ -655,6 +655,24 @@ static int hostapd_cli_cmd_wps_config(struct wpa_ctrl *ctrl, int argc,
112 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[])
136@@ -1773,6 +1791,8 @@ static const struct hostapd_cli_cmd hostapd_cli_commands[] = {
137 { "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
146index 73ab31c..ddb5d03 100644
147--- a/src/ap/beacon.c
148+++ b/src/ap/beacon.c
149@@ -1618,6 +1618,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
150 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;
158@@ -1626,7 +1628,8 @@ static u8 * hostapd_fils_discovery(struct hostapd_data *hapd,
159 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
169index 4377165..d79929b 100644
170--- a/src/drivers/driver_nl80211.c
171+++ b/src/drivers/driver_nl80211.c
172@@ -4631,9 +4631,10 @@ static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg,
173 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 }
185@@ -5038,7 +5039,10 @@ static int wpa_driver_nl80211_set_ap(void *priv,
186 #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
198index 9a0ac03..12fc6a9 100644
199--- a/src/drivers/nl80211_copy.h
200+++ b/src/drivers/nl80211_copy.h
201@@ -7569,6 +7569,7 @@ enum nl80211_fils_discovery_attributes {
202 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--
2102.18.0
211