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)
12 -include $(if $(MULTICALL),../hostapd/.config)
14 @@ -116,6 +120,8 @@ OBJS_c += ../src/utils/common.o
15 OBJS_c += ../src/common/cli.o
18 +OBJS += ../src/common/wpa_ctrl.o
21 ifdef CONFIG_NATIVE_WINDOWS
23 --- a/wpa_supplicant/bss.c
24 +++ b/wpa_supplicant/bss.c
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)
37 + struct ieee80211_ht_capabilities *capab;
38 + struct ieee80211_ht_operation *oper;
39 + struct ieee802_11_elems elems;
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;
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;
53 + dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
55 + dst->ht_param = oper->ht_param;
57 calculate_update_time(fetch_time, src->age, &dst->last_update);
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];
66 + /** HT capabilities */
68 + /* Five octets of HT Operation Information */
70 /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
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)
77 "[-g<global ctrl>] \\\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[])
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");
101 @@ -248,6 +249,9 @@ int main(int argc, char *argv[])
106 + iface->hostapd_ctrl = optarg;
109 iface->ifname = optarg;
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 */
117 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
119 + const char *cmd = "STOP_AP";
121 + size_t len = sizeof(buf);
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");
130 +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
134 + size_t len = sizeof(buf);
135 + enum hostapd_hw_mode hw_mode;
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)
147 + else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
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)
156 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
160 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
166 /* Configure default/group WEP keys for static WEP */
167 int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid)
169 @@ -940,12 +989,16 @@ void wpa_supplicant_set_state(struct wpa
171 sme_sched_obss_scan(wpa_s, 1);
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),
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));
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");
205 + if (hostapd_stop(wpa_s) < 0)
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(
214 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
216 + if (wpa_s->hostapd) {
217 + wpa_ctrl_close(wpa_s->hostapd);
218 + wpa_s->hostapd = NULL;
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 {
230 + * hostapd_ctrl - path to hostapd control socket for notification
232 + const char *hostapd_ctrl;
235 * bridge_ifname - Optional bridge interface name
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];
242 + struct wpa_ctrl *hostapd;
247 --- a/hostapd/ctrl_iface.c
248 +++ b/hostapd/ctrl_iface.c
249 @@ -2385,6 +2385,11 @@ static int hostapd_ctrl_iface_chan_switc
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;
258 for (i = 0; i < iface->num_bss; i++) {
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;
267 - if (hapd->csa_in_progress) {
268 - wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
272 hapd->beacon_set_done = 1;
274 if (ieee802_11_build_ap_params(hapd, ¶ms) < 0)
275 --- a/src/drivers/driver.h
276 +++ b/src/drivers/driver.h
277 @@ -4544,6 +4544,13 @@ enum wpa_event_type {
281 + * EVENT_CH_SWITCH - AP or GO will switch channels soon
283 + * Described in wpa_event_data.ch_switch
285 + EVENT_CH_SWITCH_STARTED,
288 * EVENT_WNM - Request WNM operation
290 * This event can be used to request a WNM operation to be performed.
291 @@ -5381,6 +5388,7 @@ union wpa_event_data {
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
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)
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);
322 data.ch_switch.cf2 = nla_get_u32(cf2);
324 + data.ch_switch.count = nla_get_u32(count);
326 bss->freq = data.ch_switch.freq;
327 drv->assoc_freq = data.ch_switch.freq;
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,
336 @@ -2508,6 +2513,7 @@ static void do_process_drv_event(struct
337 tb[NL80211_ATTR_PMK],
338 tb[NL80211_ATTR_PMKID]);
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]);
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
361 +supplicant_ch_switch_started(struct wpa_supplicant *wpa_s,
362 + union wpa_event_data *data)
365 + size_t len = sizeof(buf);
370 + if (!wpa_s->hostapd)
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);
383 + switch (data->ch_switch.ch_width) {
384 + case CHAN_WIDTH_20_NOHT:
385 + case CHAN_WIDTH_20:
388 + case CHAN_WIDTH_40:
391 + case CHAN_WIDTH_80:
394 + case CHAN_WIDTH_160:
395 + case CHAN_WIDTH_80P80:
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,
407 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
411 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
414 void supplicant_event(void *ctx, enum wpa_event_type event,
415 union wpa_event_data *data)
417 @@ -4461,6 +4515,10 @@ void supplicant_event(void *ctx, enum wp
418 data->rx_from_unknown.wds);
420 #endif /* CONFIG_AP */
421 + case EVENT_CH_SWITCH_STARTED:
422 + supplicant_ch_switch_started(wpa_s, data);
425 case EVENT_CH_SWITCH:
426 if (!data || !wpa_s->current_ssid)