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