hostapd: keep HE capability after channel switch in AP+STA/Mesh
[openwrt/openwrt.git] / package / network / services / hostapd / patches / 370-ap_sta_support.patch
1 --- a/wpa_supplicant/Makefile
2 +++ b/wpa_supplicant/Makefile
3 @@ -108,6 +108,8 @@ OBJS_c += ../src/utils/common.o
4 OBJS_c += ../src/common/cli.o
5 OBJS += wmm_ac.o
6
7 +OBJS += ../src/common/wpa_ctrl.o
8 +
9 ifndef CONFIG_OS
10 ifdef CONFIG_NATIVE_WINDOWS
11 CONFIG_OS=win32
12 --- a/wpa_supplicant/bss.c
13 +++ b/wpa_supplicant/bss.c
14 @@ -11,6 +11,7 @@
15 #include "utils/common.h"
16 #include "utils/eloop.h"
17 #include "common/ieee802_11_defs.h"
18 +#include "common/ieee802_11_common.h"
19 #include "drivers/driver.h"
20 #include "eap_peer/eap.h"
21 #include "wpa_supplicant_i.h"
22 @@ -282,6 +283,10 @@ void calculate_update_time(const struct
23 static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src,
24 struct os_reltime *fetch_time)
25 {
26 + struct ieee80211_ht_capabilities *capab;
27 + struct ieee80211_ht_operation *oper;
28 + struct ieee802_11_elems elems;
29 +
30 dst->flags = src->flags;
31 os_memcpy(dst->bssid, src->bssid, ETH_ALEN);
32 dst->freq = src->freq;
33 @@ -294,6 +299,15 @@ static void wpa_bss_copy_res(struct wpa_
34 dst->est_throughput = src->est_throughput;
35 dst->snr = src->snr;
36
37 + memset(&elems, 0, sizeof(elems));
38 + ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0);
39 + capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities;
40 + oper = (struct ieee80211_ht_operation *) elems.ht_operation;
41 + if (capab)
42 + dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
43 + if (oper)
44 + dst->ht_param = oper->ht_param;
45 +
46 calculate_update_time(fetch_time, src->age, &dst->last_update);
47 }
48
49 --- a/wpa_supplicant/bss.h
50 +++ b/wpa_supplicant/bss.h
51 @@ -94,6 +94,10 @@ struct wpa_bss {
52 u8 ssid[SSID_MAX_LEN];
53 /** Length of SSID */
54 size_t ssid_len;
55 + /** HT capabilities */
56 + u16 ht_capab;
57 + /* Five octets of HT Operation Information */
58 + u8 ht_param;
59 /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
60 int freq;
61 /** Beacon interval in TUs (host byte order) */
62 --- a/wpa_supplicant/main.c
63 +++ b/wpa_supplicant/main.c
64 @@ -34,7 +34,7 @@ static void usage(void)
65 "vW] [-P<pid file>] "
66 "[-g<global ctrl>] \\\n"
67 " [-G<group>] \\\n"
68 - " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] "
69 + " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>] "
70 "[-p<driver_param>] \\\n"
71 " [-b<br_ifname>] [-e<entropy file>]"
72 #ifdef CONFIG_DEBUG_FILE
73 @@ -74,6 +74,7 @@ static void usage(void)
74 " -g = global ctrl_interface\n"
75 " -G = global ctrl_interface group\n"
76 " -h = show this help text\n"
77 + " -H = connect to a hostapd instance to manage state changes\n"
78 " -i = interface name\n"
79 " -I = additional configuration file\n"
80 " -K = include keys (passwords, etc.) in debug output\n"
81 @@ -201,7 +202,7 @@ int main(int argc, char *argv[])
82
83 for (;;) {
84 c = getopt(argc, argv,
85 - "b:Bc:C:D:de:f:g:G:hi:I:KLMm:No:O:p:P:qsTtuvW");
86 + "b:Bc:C:D:de:f:g:G:hH:i:I:KLMm:No:O:p:P:qsTtuvW");
87 if (c < 0)
88 break;
89 switch (c) {
90 @@ -248,6 +249,9 @@ int main(int argc, char *argv[])
91 usage();
92 exitcode = 0;
93 goto out;
94 + case 'H':
95 + iface->hostapd_ctrl = optarg;
96 + break;
97 case 'i':
98 iface->ifname = optarg;
99 break;
100 --- a/wpa_supplicant/wpa_supplicant.c
101 +++ b/wpa_supplicant/wpa_supplicant.c
102 @@ -130,6 +130,54 @@ static void wpas_update_fils_connect_par
103 static void wpas_update_owe_connect_params(struct wpa_supplicant *wpa_s);
104 #endif /* CONFIG_OWE */
105
106 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
107 +{
108 + const char *cmd = "STOP_AP";
109 + char buf[256];
110 + size_t len = sizeof(buf);
111 +
112 + if (wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL) < 0) {
113 + wpa_printf(MSG_ERROR, "\nFailed to stop hostapd AP interfaces\n");
114 + return -1;
115 + }
116 + return 0;
117 +}
118 +
119 +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
120 +{
121 + char *cmd = NULL;
122 + char buf[256];
123 + size_t len = sizeof(buf);
124 + enum hostapd_hw_mode hw_mode;
125 + u8 channel;
126 + int sec_chan = 0;
127 + int ret;
128 +
129 + if (!bss)
130 + return -1;
131 +
132 + if (bss->ht_param & HT_INFO_HT_PARAM_STA_CHNL_WIDTH) {
133 + int sec = bss->ht_param & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK;
134 + if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE)
135 + sec_chan = 1;
136 + else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
137 + sec_chan = -1;
138 + }
139 +
140 + hw_mode = ieee80211_freq_to_chan(bss->freq, &channel);
141 + if (asprintf(&cmd, "UPDATE channel=%d sec_chan=%d hw_mode=%d",
142 + channel, sec_chan, hw_mode) < 0)
143 + return -1;
144 +
145 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
146 + free(cmd);
147 +
148 + if (ret < 0) {
149 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
150 + return -1;
151 + }
152 + return 0;
153 +}
154
155 #ifdef CONFIG_WEP
156 /* Configure default/group WEP keys for static WEP */
157 @@ -1007,6 +1055,8 @@ void wpa_supplicant_set_state(struct wpa
158
159 sme_sched_obss_scan(wpa_s, 1);
160
161 + if (wpa_s->hostapd)
162 + hostapd_reload(wpa_s, wpa_s->current_bss);
163 #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
164 if (!fils_hlp_sent && ssid && ssid->eap.erp)
165 update_fils_connect_params = true;
166 @@ -1017,6 +1067,8 @@ void wpa_supplicant_set_state(struct wpa
167 #endif /* CONFIG_OWE */
168 } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING ||
169 state == WPA_ASSOCIATED) {
170 + if (wpa_s->hostapd)
171 + hostapd_stop(wpa_s);
172 wpa_s->new_connection = 1;
173 wpa_drv_set_operstate(wpa_s, 0);
174 #ifndef IEEE8021X_EAPOL
175 @@ -2276,6 +2328,8 @@ void wpa_supplicant_associate(struct wpa
176 return;
177 }
178 wpa_s->current_bss = bss;
179 + if (wpa_s->hostapd)
180 + hostapd_reload(wpa_s, wpa_s->current_bss);
181 #else /* CONFIG_MESH */
182 wpa_msg(wpa_s, MSG_ERROR,
183 "mesh mode support not included in the build");
184 @@ -6426,6 +6480,16 @@ static int wpa_supplicant_init_iface(str
185 sizeof(wpa_s->bridge_ifname));
186 }
187
188 + if (iface->hostapd_ctrl) {
189 + wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl);
190 + if (!wpa_s->hostapd) {
191 + wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n");
192 + return -1;
193 + }
194 + if (hostapd_stop(wpa_s) < 0)
195 + return -1;
196 + }
197 +
198 /* RSNA Supplicant Key Management - INITIALIZE */
199 eapol_sm_notify_portEnabled(wpa_s->eapol, false);
200 eapol_sm_notify_portValid(wpa_s->eapol, false);
201 @@ -6763,6 +6827,11 @@ static void wpa_supplicant_deinit_iface(
202 if (terminate)
203 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
204
205 + if (wpa_s->hostapd) {
206 + wpa_ctrl_close(wpa_s->hostapd);
207 + wpa_s->hostapd = NULL;
208 + }
209 +
210 wpa_supplicant_ctrl_iface_deinit(wpa_s, wpa_s->ctrl_iface);
211 wpa_s->ctrl_iface = NULL;
212
213 --- a/wpa_supplicant/wpa_supplicant_i.h
214 +++ b/wpa_supplicant/wpa_supplicant_i.h
215 @@ -103,6 +103,11 @@ struct wpa_interface {
216 const char *ifname;
217
218 /**
219 + * hostapd_ctrl - path to hostapd control socket for notification
220 + */
221 + const char *hostapd_ctrl;
222 +
223 + /**
224 * bridge_ifname - Optional bridge interface name
225 *
226 * If the driver interface (ifname) is included in a Linux bridge
227 @@ -615,6 +620,8 @@ struct wpa_supplicant {
228 #endif /* CONFIG_CTRL_IFACE_BINDER */
229 char bridge_ifname[16];
230
231 + struct wpa_ctrl *hostapd;
232 +
233 char *confname;
234 char *confanother;
235
236 --- a/hostapd/ctrl_iface.c
237 +++ b/hostapd/ctrl_iface.c
238 @@ -2883,6 +2883,12 @@ static int hostapd_ctrl_iface_chan_switc
239 return 0;
240 }
241
242 + if (os_strstr(pos, " auto-ht")) {
243 + settings.freq_params.ht_enabled = iface->conf->ieee80211n;
244 + settings.freq_params.vht_enabled = iface->conf->ieee80211ac;
245 + settings.freq_params.he_enabled = iface->conf->ieee80211ax;
246 + }
247 +
248 for (i = 0; i < iface->num_bss; i++) {
249
250 /* Save CHAN_SWITCH VHT and HE config */
251 --- a/src/ap/beacon.c
252 +++ b/src/ap/beacon.c
253 @@ -1758,11 +1758,6 @@ int ieee802_11_set_beacon(struct hostapd
254 return -1;
255 }
256
257 - if (hapd->csa_in_progress) {
258 - wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
259 - return -1;
260 - }
261 -
262 hapd->beacon_set_done = 1;
263
264 if (ieee802_11_build_ap_params(hapd, &params) < 0)
265 --- a/wpa_supplicant/events.c
266 +++ b/wpa_supplicant/events.c
267 @@ -4665,6 +4665,60 @@ static void wpas_event_unprot_beacon(str
268 }
269
270
271 +static void
272 +supplicant_ch_switch_started(struct wpa_supplicant *wpa_s,
273 + union wpa_event_data *data)
274 +{
275 + char buf[256];
276 + size_t len = sizeof(buf);
277 + char *cmd = NULL;
278 + int width = 20;
279 + int ret;
280 +
281 + if (!wpa_s->hostapd)
282 + return;
283 +
284 + wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
285 + "count=%d freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
286 + data->ch_switch.count,
287 + data->ch_switch.freq,
288 + data->ch_switch.ht_enabled,
289 + data->ch_switch.ch_offset,
290 + channel_width_to_string(data->ch_switch.ch_width),
291 + data->ch_switch.cf1,
292 + data->ch_switch.cf2);
293 +
294 + switch (data->ch_switch.ch_width) {
295 + case CHAN_WIDTH_20_NOHT:
296 + case CHAN_WIDTH_20:
297 + width = 20;
298 + break;
299 + case CHAN_WIDTH_40:
300 + width = 40;
301 + break;
302 + case CHAN_WIDTH_80:
303 + width = 80;
304 + break;
305 + case CHAN_WIDTH_160:
306 + case CHAN_WIDTH_80P80:
307 + width = 160;
308 + break;
309 + }
310 +
311 + asprintf(&cmd, "CHAN_SWITCH %d %d sec_channel_offset=%d center_freq1=%d center_freq2=%d, bandwidth=%d auto-ht\n",
312 + data->ch_switch.count - 1,
313 + data->ch_switch.freq,
314 + data->ch_switch.ch_offset,
315 + data->ch_switch.cf1,
316 + data->ch_switch.cf2,
317 + width);
318 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
319 + free(cmd);
320 +
321 + if (ret < 0)
322 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
323 +}
324 +
325 void supplicant_event(void *ctx, enum wpa_event_type event,
326 union wpa_event_data *data)
327 {
328 @@ -4980,8 +5034,10 @@ void supplicant_event(void *ctx, enum wp
329 channel_width_to_string(data->ch_switch.ch_width),
330 data->ch_switch.cf1,
331 data->ch_switch.cf2);
332 - if (event == EVENT_CH_SWITCH_STARTED)
333 + if (event == EVENT_CH_SWITCH_STARTED) {
334 + supplicant_ch_switch_started(wpa_s, data);
335 break;
336 + }
337
338 wpa_s->assoc_freq = data->ch_switch.freq;
339 wpa_s->current_ssid->frequency = data->ch_switch.freq;
340 --- a/src/drivers/driver.h
341 +++ b/src/drivers/driver.h
342 @@ -5829,6 +5829,7 @@ union wpa_event_data {
343
344 /**
345 * struct ch_switch
346 + * @count: Count until channel switch activates
347 * @freq: Frequency of new channel in MHz
348 * @ht_enabled: Whether this is an HT channel
349 * @ch_offset: Secondary channel offset
350 @@ -5837,6 +5838,7 @@ union wpa_event_data {
351 * @cf2: Center frequency 2
352 */
353 struct ch_switch {
354 + int count;
355 int freq;
356 int ht_enabled;
357 int ch_offset;
358 --- a/src/drivers/driver_nl80211_event.c
359 +++ b/src/drivers/driver_nl80211_event.c
360 @@ -684,7 +684,7 @@ static void mlme_event_ch_switch(struct
361 struct nlattr *ifindex, struct nlattr *freq,
362 struct nlattr *type, struct nlattr *bw,
363 struct nlattr *cf1, struct nlattr *cf2,
364 - int finished)
365 + struct nlattr *count, int finished)
366 {
367 struct i802_bss *bss;
368 union wpa_event_data data;
369 @@ -745,6 +745,8 @@ static void mlme_event_ch_switch(struct
370 data.ch_switch.cf1 = nla_get_u32(cf1);
371 if (cf2)
372 data.ch_switch.cf2 = nla_get_u32(cf2);
373 + if (count)
374 + data.ch_switch.count = nla_get_u32(count);
375
376 if (finished)
377 bss->freq = data.ch_switch.freq;
378 @@ -3003,6 +3005,7 @@ static void do_process_drv_event(struct
379 tb[NL80211_ATTR_CHANNEL_WIDTH],
380 tb[NL80211_ATTR_CENTER_FREQ1],
381 tb[NL80211_ATTR_CENTER_FREQ2],
382 + tb[NL80211_ATTR_CH_SWITCH_COUNT],
383 0);
384 break;
385 case NL80211_CMD_CH_SWITCH_NOTIFY:
386 @@ -3013,6 +3016,7 @@ static void do_process_drv_event(struct
387 tb[NL80211_ATTR_CHANNEL_WIDTH],
388 tb[NL80211_ATTR_CENTER_FREQ1],
389 tb[NL80211_ATTR_CENTER_FREQ2],
390 + NULL,
391 1);
392 break;
393 case NL80211_CMD_DISCONNECT: