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 @@ -118,6 +122,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 @@ -83,6 +83,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 @@ -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 */
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");
167 /* Configure default/group WEP keys for static WEP */
168 @@ -991,6 +1039,8 @@ void wpa_supplicant_set_state(struct wpa
170 sme_sched_obss_scan(wpa_s, 1);
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 @@ -2229,6 +2281,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 @@ -6210,6 +6264,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 @@ -6543,6 +6607,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 @@ -104,6 +104,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 @@ -530,6 +535,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 @@ -2712,6 +2712,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 @@ -1468,11 +1468,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/wpa_supplicant/events.c
276 +++ b/wpa_supplicant/events.c
277 @@ -4579,6 +4579,60 @@ static void wpas_event_unprot_beacon(str
282 +supplicant_ch_switch_started(struct wpa_supplicant *wpa_s,
283 + union wpa_event_data *data)
286 + size_t len = sizeof(buf);
291 + if (!wpa_s->hostapd)
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);
304 + switch (data->ch_switch.ch_width) {
305 + case CHAN_WIDTH_20_NOHT:
306 + case CHAN_WIDTH_20:
309 + case CHAN_WIDTH_40:
312 + case CHAN_WIDTH_80:
315 + case CHAN_WIDTH_160:
316 + case CHAN_WIDTH_80P80:
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,
328 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
332 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
335 void supplicant_event(void *ctx, enum wpa_event_type event,
336 union wpa_event_data *data)
338 @@ -4881,8 +4935,10 @@ void supplicant_event(void *ctx, enum wp
339 channel_width_to_string(data->ch_switch.ch_width),
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);
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 {
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
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,
375 + struct nlattr *count, int finished)
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);
382 data.ch_switch.cf2 = nla_get_u32(cf2);
384 + data.ch_switch.count = nla_get_u32(count);
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],
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],
403 case NL80211_CMD_DISCONNECT: