hostapd: Update to version 2.8 (2019-04-21)
[oweals/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 @@ -116,6 +120,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 @@ -82,6 +82,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 @@ -126,6 +126,55 @@ static void wpas_update_fils_connect_par
114  #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
115  
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  /* Configure default/group WEP keys for static WEP */
167  int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
168  {
169 @@ -940,12 +989,16 @@ void wpa_supplicant_set_state(struct wpa
170  
171                 sme_sched_obss_scan(wpa_s, 1);
172  
173 +               if (wpa_s->hostapd)
174 +                       hostapd_reload(wpa_s, wpa_s->current_bss);
175  #if defined(CONFIG_FILS) && defined(IEEE8021X_EAPOL)
176                 if (!fils_hlp_sent && ssid && ssid->eap.erp)
177                         wpas_update_fils_connect_params(wpa_s);
178  #endif /* CONFIG_FILS && IEEE8021X_EAPOL */
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 @@ -2035,6 +2088,8 @@ void wpa_supplicant_associate(struct wpa
187                         wpa_ssid_txt(ssid->ssid, ssid->ssid_len),
188                         ssid->id);
189                 wpas_notify_mesh_group_started(wpa_s, ssid);
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 @@ -5707,6 +5762,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 @@ -6034,6 +6099,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 @@ -101,6 +101,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 @@ -516,6 +521,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 @@ -2385,6 +2385,11 @@ static int hostapd_ctrl_iface_chan_switc
250         if (ret)
251                 return ret;
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 @@ -1397,11 +1397,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/src/drivers/driver.h
276 +++ b/src/drivers/driver.h
277 @@ -4544,6 +4544,13 @@ enum wpa_event_type {
278         EVENT_CH_SWITCH,
279  
280         /**
281 +        * EVENT_CH_SWITCH - AP or GO will switch channels soon
282 +        *
283 +        * Described in wpa_event_data.ch_switch
284 +        * */
285 +       EVENT_CH_SWITCH_STARTED,
286 +
287 +       /**
288          * EVENT_WNM - Request WNM operation
289          *
290          * This event can be used to request a WNM operation to be performed.
291 @@ -5381,6 +5388,7 @@ union wpa_event_data {
292  
293         /**
294          * struct ch_switch
295 +        * @count: countdown until channel switch
296          * @freq: Frequency of new channel in MHz
297          * @ht_enabled: Whether this is an HT channel
298          * @ch_offset: Secondary channel offset
299 @@ -5389,6 +5397,7 @@ union wpa_event_data {
300          * @cf2: Center frequency 2
301          */
302         struct ch_switch {
303 +               int count;
304                 int freq;
305                 int ht_enabled;
306                 int ch_offset;
307 --- a/src/drivers/driver_nl80211_event.c
308 +++ b/src/drivers/driver_nl80211_event.c
309 @@ -534,7 +534,8 @@ static int calculate_chan_offset(int wid
310  static void mlme_event_ch_switch(struct wpa_driver_nl80211_data *drv,
311                                  struct nlattr *ifindex, struct nlattr *freq,
312                                  struct nlattr *type, struct nlattr *bw,
313 -                                struct nlattr *cf1, struct nlattr *cf2)
314 +                                struct nlattr *cf1, struct nlattr *cf2,
315 +                                struct nlattr *count)
316  {
317         struct i802_bss *bss;
318         union wpa_event_data data;
319 @@ -592,11 +593,15 @@ static void mlme_event_ch_switch(struct
320                 data.ch_switch.cf1 = nla_get_u32(cf1);
321         if (cf2)
322                 data.ch_switch.cf2 = nla_get_u32(cf2);
323 +       if (count)
324 +               data.ch_switch.count = nla_get_u32(count);
325  
326         bss->freq = data.ch_switch.freq;
327         drv->assoc_freq = data.ch_switch.freq;
328  
329 -       wpa_supplicant_event(bss->ctx, EVENT_CH_SWITCH, &data);
330 +       wpa_supplicant_event(bss->ctx,
331 +                            count ? EVENT_CH_SWITCH_STARTED : EVENT_CH_SWITCH,
332 +                            &data);
333  }
334  
335  
336 @@ -2508,6 +2513,7 @@ static void do_process_drv_event(struct
337                                    tb[NL80211_ATTR_PMK],
338                                    tb[NL80211_ATTR_PMKID]);
339                 break;
340 +       case NL80211_CMD_CH_SWITCH_STARTED_NOTIFY:
341         case NL80211_CMD_CH_SWITCH_NOTIFY:
342                 mlme_event_ch_switch(drv,
343                                      tb[NL80211_ATTR_IFINDEX],
344 @@ -2515,7 +2521,8 @@ static void do_process_drv_event(struct
345                                      tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE],
346                                      tb[NL80211_ATTR_CHANNEL_WIDTH],
347                                      tb[NL80211_ATTR_CENTER_FREQ1],
348 -                                    tb[NL80211_ATTR_CENTER_FREQ2]);
349 +                                    tb[NL80211_ATTR_CENTER_FREQ2],
350 +                                    tb[NL80211_ATTR_CH_SWITCH_COUNT]);
351                 break;
352         case NL80211_CMD_DISCONNECT:
353                 mlme_event_disconnect(drv, tb[NL80211_ATTR_REASON_CODE],
354 --- a/wpa_supplicant/events.c
355 +++ b/wpa_supplicant/events.c
356 @@ -4176,6 +4176,60 @@ static void wpas_event_assoc_reject(stru
357  }
358  
359  
360 +static void
361 +supplicant_ch_switch_started(struct wpa_supplicant *wpa_s,
362 +                           union wpa_event_data *data)
363 +{
364 +       char buf[256];
365 +       size_t len = sizeof(buf);
366 +       char *cmd = NULL;
367 +       int width = 20;
368 +       int ret;
369 +
370 +       if (!wpa_s->hostapd)
371 +               return;
372 +
373 +       wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_CHANNEL_SWITCH
374 +               "count=%d freq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d",
375 +               data->ch_switch.count,
376 +               data->ch_switch.freq,
377 +               data->ch_switch.ht_enabled,
378 +               data->ch_switch.ch_offset,
379 +               channel_width_to_string(data->ch_switch.ch_width),
380 +               data->ch_switch.cf1,
381 +               data->ch_switch.cf2);
382 +
383 +       switch (data->ch_switch.ch_width) {
384 +       case CHAN_WIDTH_20_NOHT:
385 +       case CHAN_WIDTH_20:
386 +               width = 20;
387 +               break;
388 +       case CHAN_WIDTH_40:
389 +               width = 40;
390 +               break;
391 +       case CHAN_WIDTH_80:
392 +               width = 80;
393 +               break;
394 +       case CHAN_WIDTH_160:
395 +       case CHAN_WIDTH_80P80:
396 +               width = 160;
397 +               break;
398 +       }
399 +
400 +       asprintf(&cmd, "CHAN_SWITCH %d %d sec_channel_offset=%d center_freq1=%d center_freq2=%d, bandwidth=%d auto-ht\n",
401 +               data->ch_switch.count - 1,
402 +               data->ch_switch.freq,
403 +               data->ch_switch.ch_offset,
404 +               data->ch_switch.cf1,
405 +               data->ch_switch.cf2,
406 +               width);
407 +       ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
408 +       free(cmd);
409 +
410 +       if (ret < 0)
411 +               wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
412 +}
413 +
414  void supplicant_event(void *ctx, enum wpa_event_type event,
415                       union wpa_event_data *data)
416  {
417 @@ -4461,6 +4515,10 @@ void supplicant_event(void *ctx, enum wp
418                                        data->rx_from_unknown.wds);
419                 break;
420  #endif /* CONFIG_AP */
421 +       case EVENT_CH_SWITCH_STARTED:
422 +               supplicant_ch_switch_started(wpa_s, data);
423 +               break;
424 +
425         case EVENT_CH_SWITCH:
426                 if (!data || !wpa_s->current_ssid)
427                         break;