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
7 +OBJS += ../src/common/wpa_ctrl.o
10 ifdef CONFIG_NATIVE_WINDOWS
12 --- a/wpa_supplicant/bss.c
13 +++ b/wpa_supplicant/bss.c
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)
26 + struct ieee80211_ht_capabilities *capab;
27 + struct ieee80211_ht_operation *oper;
28 + struct ieee802_11_elems elems;
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;
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;
42 + dst->ht_capab = le_to_host16(capab->ht_capabilities_info);
44 + dst->ht_param = oper->ht_param;
46 calculate_update_time(fetch_time, src->age, &dst->last_update);
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];
55 + /** HT capabilities */
57 + /* Five octets of HT Operation Information */
59 /** Frequency of the channel in MHz (e.g., 2412 = channel 1) */
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)
66 "[-g<global ctrl>] \\\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[])
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");
90 @@ -248,6 +249,9 @@ int main(int argc, char *argv[])
95 + iface->hostapd_ctrl = optarg;
98 iface->ifname = optarg;
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 */
106 +static int hostapd_stop(struct wpa_supplicant *wpa_s)
108 + const char *cmd = "STOP_AP";
110 + size_t len = sizeof(buf);
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");
119 +static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss)
123 + size_t len = sizeof(buf);
124 + enum hostapd_hw_mode hw_mode;
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)
136 + else if (sec == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW)
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)
145 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
149 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
156 /* Configure default/group WEP keys for static WEP */
157 @@ -1007,6 +1055,8 @@ void wpa_supplicant_set_state(struct wpa
159 sme_sched_obss_scan(wpa_s, 1);
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
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));
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");
194 + if (hostapd_stop(wpa_s) < 0)
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(
203 wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_TERMINATING);
205 + if (wpa_s->hostapd) {
206 + wpa_ctrl_close(wpa_s->hostapd);
207 + wpa_s->hostapd = NULL;
210 wpa_supplicant_ctrl_iface_deinit(wpa_s, wpa_s->ctrl_iface);
211 wpa_s->ctrl_iface = NULL;
213 --- a/wpa_supplicant/wpa_supplicant_i.h
214 +++ b/wpa_supplicant/wpa_supplicant_i.h
215 @@ -103,6 +103,11 @@ struct wpa_interface {
219 + * hostapd_ctrl - path to hostapd control socket for notification
221 + const char *hostapd_ctrl;
224 * bridge_ifname - Optional bridge interface name
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];
231 + struct wpa_ctrl *hostapd;
236 --- a/hostapd/ctrl_iface.c
237 +++ b/hostapd/ctrl_iface.c
238 @@ -2883,6 +2883,12 @@ static int hostapd_ctrl_iface_chan_switc
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;
248 for (i = 0; i < iface->num_bss; i++) {
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
257 - if (hapd->csa_in_progress) {
258 - wpa_printf(MSG_ERROR, "Cannot set beacons during CSA period");
262 hapd->beacon_set_done = 1;
264 if (ieee802_11_build_ap_params(hapd, ¶ms) < 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
272 +supplicant_ch_switch_started(struct wpa_supplicant *wpa_s,
273 + union wpa_event_data *data)
276 + size_t len = sizeof(buf);
281 + if (!wpa_s->hostapd)
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);
294 + switch (data->ch_switch.ch_width) {
295 + case CHAN_WIDTH_20_NOHT:
296 + case CHAN_WIDTH_20:
299 + case CHAN_WIDTH_40:
302 + case CHAN_WIDTH_80:
305 + case CHAN_WIDTH_160:
306 + case CHAN_WIDTH_80P80:
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,
318 + ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL);
322 + wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n");
325 void supplicant_event(void *ctx, enum wpa_event_type event,
326 union wpa_event_data *data)
328 @@ -4980,8 +5034,10 @@ void supplicant_event(void *ctx, enum wp
329 channel_width_to_string(data->ch_switch.ch_width),
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);
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 {
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
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,
365 + struct nlattr *count, int finished)
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);
372 data.ch_switch.cf2 = nla_get_u32(cf2);
374 + data.ch_switch.count = nla_get_u32(count);
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],
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],
393 case NL80211_CMD_DISCONNECT: