]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/drv_callbacks.c
nl80211: Add support for STA opmode change events
[thirdparty/hostap.git] / src / ap / drv_callbacks.c
CommitLineData
b5b969e9
JM
1/*
2 * hostapd / Callback functions for driver wrappers
94ddef3e 3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
b5b969e9 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
b5b969e9
JM
7 */
8
6226e38d 9#include "utils/includes.h"
b5b969e9 10
6226e38d 11#include "utils/common.h"
9c47f6a2 12#include "utils/eloop.h"
b5b969e9 13#include "radius/radius.h"
6e6e8c31 14#include "drivers/driver.h"
81f4f619 15#include "common/ieee802_11_defs.h"
c41a1095 16#include "common/ieee802_11_common.h"
3140803b 17#include "common/wpa_ctrl.h"
bbb921da 18#include "crypto/random.h"
ef796391 19#include "p2p/p2p.h"
54f489be 20#include "wps/wps.h"
037378ff 21#include "fst/fst.h"
d32d94db 22#include "wnm_ap.h"
6226e38d
JM
23#include "hostapd.h"
24#include "ieee802_11.h"
0603bcb7 25#include "ieee802_11_auth.h"
6226e38d
JM
26#include "sta_info.h"
27#include "accounting.h"
28#include "tkip_countermeasures.h"
6226e38d
JM
29#include "ieee802_1x.h"
30#include "wpa_auth.h"
6226e38d 31#include "wps_hostapd.h"
51e2a27a 32#include "ap_drv_ops.h"
8b06c1ed 33#include "ap_config.h"
fa61bff6 34#include "ap_mlme.h"
1b487b8b 35#include "hw_features.h"
e76da505 36#include "dfs.h"
9c47f6a2 37#include "beacon.h"
6332aaf3 38#include "mbo_ap.h"
9c2b8204 39#include "dpp_hostapd.h"
8b5ddda5
JM
40#include "fils_hlp.h"
41
42
43#ifdef CONFIG_FILS
44void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
45 struct sta_info *sta)
46{
47 u16 reply_res = WLAN_STATUS_SUCCESS;
48 struct ieee802_11_elems elems;
49 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
50 int new_assoc;
51
52 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
53 __func__, MAC2STR(sta->addr));
54 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
55 if (!sta->fils_pending_assoc_req)
56 return;
57
58 ieee802_11_parse_elems(sta->fils_pending_assoc_req,
59 sta->fils_pending_assoc_req_len, &elems, 0);
60 if (!elems.fils_session) {
61 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
62 __func__);
63 return;
64 }
65
66 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
67 elems.fils_session,
68 sta->fils_hlp_resp);
69
70 reply_res = hostapd_sta_assoc(hapd, sta->addr,
71 sta->fils_pending_assoc_is_reassoc,
72 WLAN_STATUS_SUCCESS,
73 buf, p - buf);
74 ap_sta_set_authorized(hapd, sta, 1);
75 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
76 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
77 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
78 hostapd_set_sta_flags(hapd, sta);
79 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
80 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
81 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
82 os_free(sta->fils_pending_assoc_req);
83 sta->fils_pending_assoc_req = NULL;
84 sta->fils_pending_assoc_req_len = 0;
85 wpabuf_free(sta->fils_hlp_resp);
86 sta->fils_hlp_resp = NULL;
87 wpabuf_free(sta->hlp_dhcp_discover);
88 sta->hlp_dhcp_discover = NULL;
89 fils_hlp_deinit(hapd);
90
91 /*
92 * Remove the station in case transmission of a success response fails
93 * (the STA was added associated to the driver) or if the station was
94 * previously added unassociated.
95 */
96 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
97 hostapd_drv_sta_remove(hapd, sta->addr);
98 sta->added_unassoc = 0;
99 }
100}
101#endif /* CONFIG_FILS */
b5b969e9
JM
102
103
b5b969e9 104int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
2bb20281 105 const u8 *req_ies, size_t req_ies_len, int reassoc)
b5b969e9
JM
106{
107 struct sta_info *sta;
108 int new_assoc, res;
c41a1095 109 struct ieee802_11_elems elems;
2bb20281
JM
110 const u8 *ie;
111 size_t ielen;
7475e80f 112#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS)
88b32a99
SP
113 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
114 u8 *p = buf;
7475e80f 115#endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W || CONFIG_FILS */
08a74e6a 116 u16 reason = WLAN_REASON_UNSPECIFIED;
88b32a99 117 u16 status = WLAN_STATUS_SUCCESS;
94ddef3e 118 const u8 *p2p_dev_addr = NULL;
b5b969e9 119
68532a9c
JM
120 if (addr == NULL) {
121 /*
122 * This could potentially happen with unexpected event from the
123 * driver wrapper. This was seen at least in one case where the
124 * driver ended up being set to station mode while hostapd was
125 * running, so better make sure we stop processing such an
126 * event here.
127 */
48b06c17
JM
128 wpa_printf(MSG_DEBUG,
129 "hostapd_notif_assoc: Skip event with no address");
68532a9c
JM
130 return -1;
131 }
bbb921da 132 random_add_randomness(addr, ETH_ALEN);
68532a9c 133
b5b969e9
JM
134 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
135 HOSTAPD_LEVEL_INFO, "associated");
136
2bb20281 137 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
c41a1095
JM
138 if (elems.wps_ie) {
139 ie = elems.wps_ie - 2;
140 ielen = elems.wps_ie_len + 2;
141 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
142 } else if (elems.rsn_ie) {
143 ie = elems.rsn_ie - 2;
144 ielen = elems.rsn_ie_len + 2;
145 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
146 } else if (elems.wpa_ie) {
147 ie = elems.wpa_ie - 2;
148 ielen = elems.wpa_ie_len + 2;
149 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
a14896e8
JM
150#ifdef CONFIG_HS20
151 } else if (elems.osen) {
152 ie = elems.osen - 2;
153 ielen = elems.osen_len + 2;
154 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
155#endif /* CONFIG_HS20 */
c41a1095
JM
156 } else {
157 ie = NULL;
158 ielen = 0;
48b06c17
JM
159 wpa_printf(MSG_DEBUG,
160 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
c41a1095
JM
161 }
162
b5b969e9
JM
163 sta = ap_get_sta(hapd, addr);
164 if (sta) {
4331263b 165 ap_sta_no_session_timeout(hapd, sta);
b5b969e9 166 accounting_sta_stop(hapd, sta);
c72bd6d4
JM
167
168 /*
169 * Make sure that the previously registered inactivity timer
170 * will not remove the STA immediately.
171 */
172 sta->timeout_next = STA_NULLFUNC;
b5b969e9
JM
173 } else {
174 sta = ap_sta_add(hapd, addr);
8bd0fc0e
JM
175 if (sta == NULL) {
176 hostapd_drv_sta_disassoc(hapd, addr,
177 WLAN_REASON_DISASSOC_AP_BUSY);
b5b969e9 178 return -1;
8bd0fc0e 179 }
b5b969e9 180 }
17f6b900 181 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
b5b969e9 182
bb4e19e3
SD
183 /*
184 * ACL configurations to the drivers (implementing AP SME and ACL
185 * offload) without hostapd's knowledge, can result in a disconnection
186 * though the driver accepts the connection. Skip the hostapd check for
187 * ACL if the driver supports ACL offload to avoid potentially
188 * conflicting ACL rules.
189 */
190 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
191 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
0603bcb7
AN
192 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
193 MAC2STR(addr));
194 reason = WLAN_REASON_UNSPECIFIED;
195 goto fail;
196 }
197
b305c684
JM
198#ifdef CONFIG_P2P
199 if (elems.p2p) {
200 wpabuf_free(sta->p2p_ie);
2bb20281 201 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
b305c684 202 P2P_IE_VENDOR_TYPE);
94ddef3e
JM
203 if (sta->p2p_ie)
204 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
b305c684
JM
205 }
206#endif /* CONFIG_P2P */
207
9c47f6a2
PX
208#ifdef CONFIG_IEEE80211N
209#ifdef NEED_AP_MLME
210 if (elems.ht_capabilities &&
9c47f6a2
PX
211 (hapd->iface->conf->ht_capab &
212 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
213 struct ieee80211_ht_capabilities *ht_cap =
214 (struct ieee80211_ht_capabilities *)
215 elems.ht_capabilities;
216
217 if (le_to_host16(ht_cap->ht_capabilities_info) &
218 HT_CAP_INFO_40MHZ_INTOLERANT)
219 ht40_intolerant_add(hapd->iface, sta);
220 }
221#endif /* NEED_AP_MLME */
222#endif /* CONFIG_IEEE80211N */
223
c551700f
KP
224#ifdef CONFIG_INTERWORKING
225 if (elems.ext_capab && elems.ext_capab_len > 4) {
226 if (elems.ext_capab[4] & 0x01)
227 sta->qos_map_enabled = 1;
228 }
229#endif /* CONFIG_INTERWORKING */
230
f403dcd6
JM
231#ifdef CONFIG_HS20
232 wpabuf_free(sta->hs20_ie);
233 if (elems.hs20 && elems.hs20_len > 4) {
234 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
235 elems.hs20_len - 4);
236 } else
237 sta->hs20_ie = NULL;
238#endif /* CONFIG_HS20 */
239
ae667c08
AN
240#ifdef CONFIG_FST
241 wpabuf_free(sta->mb_ies);
242 if (hapd->iface->fst)
243 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
244 else
245 sta->mb_ies = NULL;
246#endif /* CONFIG_FST */
247
6332aaf3
JM
248 mbo_ap_check_sta_assoc(hapd, sta, &elems);
249
adf0478e
JM
250 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
251 elems.supp_op_classes_len);
252
b5b969e9
JM
253 if (hapd->conf->wpa) {
254 if (ie == NULL || ielen == 0) {
633d4469 255#ifdef CONFIG_WPS
b5b969e9 256 if (hapd->conf->wps_state) {
48b06c17
JM
257 wpa_printf(MSG_DEBUG,
258 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
b5b969e9
JM
259 sta->flags |= WLAN_STA_MAYBE_WPS;
260 goto skip_wpa_check;
261 }
633d4469 262#endif /* CONFIG_WPS */
b5b969e9
JM
263
264 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
63dc0f9c
HW
265 reason = WLAN_REASON_INVALID_IE;
266 status = WLAN_STATUS_INVALID_IE;
267 goto fail;
b5b969e9 268 }
633d4469 269#ifdef CONFIG_WPS
b5b969e9
JM
270 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
271 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
17f6b900 272 struct wpabuf *wps;
48b06c17 273
b5b969e9 274 sta->flags |= WLAN_STA_WPS;
17f6b900
JM
275 wps = ieee802_11_vendor_ie_concat(ie, ielen,
276 WPS_IE_VENDOR_TYPE);
277 if (wps) {
278 if (wps_is_20(wps)) {
48b06c17
JM
279 wpa_printf(MSG_DEBUG,
280 "WPS: STA supports WPS 2.0");
17f6b900
JM
281 sta->flags |= WLAN_STA_WPS2;
282 }
283 wpabuf_free(wps);
284 }
b5b969e9
JM
285 goto skip_wpa_check;
286 }
633d4469 287#endif /* CONFIG_WPS */
b5b969e9
JM
288
289 if (sta->wpa_sm == NULL)
290 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
94ddef3e
JM
291 sta->addr,
292 p2p_dev_addr);
b5b969e9 293 if (sta->wpa_sm == NULL) {
48b06c17
JM
294 wpa_printf(MSG_ERROR,
295 "Failed to initialize WPA state machine");
b5b969e9
JM
296 return -1;
297 }
298 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
88b32a99 299 ie, ielen,
09368515
JM
300 elems.mdie, elems.mdie_len,
301 elems.owe_dh, elems.owe_dh_len);
b5b969e9 302 if (res != WPA_IE_OK) {
48b06c17
JM
303 wpa_printf(MSG_DEBUG,
304 "WPA/RSN information element rejected? (res %u)",
305 res);
b5b969e9 306 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
88b32a99 307 if (res == WPA_INVALID_GROUP) {
08a74e6a 308 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
88b32a99
SP
309 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
310 } else if (res == WPA_INVALID_PAIRWISE) {
08a74e6a 311 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
88b32a99
SP
312 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
313 } else if (res == WPA_INVALID_AKMP) {
08a74e6a 314 reason = WLAN_REASON_AKMP_NOT_VALID;
88b32a99
SP
315 status = WLAN_STATUS_AKMP_NOT_VALID;
316 }
355d36a7 317#ifdef CONFIG_IEEE80211W
88b32a99 318 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
08a74e6a 319 reason = WLAN_REASON_INVALID_IE;
88b32a99
SP
320 status = WLAN_STATUS_INVALID_IE;
321 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
feba5848
JM
322 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
323 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
88b32a99 324 }
355d36a7 325#endif /* CONFIG_IEEE80211W */
88b32a99 326 else {
08a74e6a 327 reason = WLAN_REASON_INVALID_IE;
88b32a99
SP
328 status = WLAN_STATUS_INVALID_IE;
329 }
08a74e6a 330 goto fail;
b5b969e9 331 }
7d9c0cd3
MP
332#ifdef CONFIG_IEEE80211W
333 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
334 sta->sa_query_count > 0)
335 ap_check_sa_query_timeout(hapd, sta);
336 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
337 (sta->auth_alg != WLAN_AUTH_FT)) {
338 /*
339 * STA has already been associated with MFP and SA
340 * Query timeout has not been reached. Reject the
341 * association attempt temporarily and start SA Query,
342 * if one is not pending.
343 */
344
345 if (sta->sa_query_count == 0)
346 ap_sta_start_sa_query(hapd, sta);
347
7d9c0cd3
MP
348 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
349
350 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
351
352 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
353 p - buf);
7d9c0cd3
MP
354 return 0;
355 }
356
357 if (wpa_auth_uses_mfp(sta->wpa_sm))
358 sta->flags |= WLAN_STA_MFP;
359 else
360 sta->flags &= ~WLAN_STA_MFP;
361#endif /* CONFIG_IEEE80211W */
362
4ec1fd8e 363#ifdef CONFIG_IEEE80211R_AP
88b32a99
SP
364 if (sta->auth_alg == WLAN_AUTH_FT) {
365 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
366 req_ies_len);
367 if (status != WLAN_STATUS_SUCCESS) {
368 if (status == WLAN_STATUS_INVALID_PMKID)
369 reason = WLAN_REASON_INVALID_IE;
370 if (status == WLAN_STATUS_INVALID_MDIE)
371 reason = WLAN_REASON_INVALID_IE;
372 if (status == WLAN_STATUS_INVALID_FTIE)
373 reason = WLAN_REASON_INVALID_IE;
374 goto fail;
375 }
376 }
4ec1fd8e 377#endif /* CONFIG_IEEE80211R_AP */
a9aca28b 378 } else if (hapd->conf->wps_state) {
633d4469 379#ifdef CONFIG_WPS
17f6b900 380 struct wpabuf *wps;
48b06c17 381
2bb20281
JM
382 if (req_ies)
383 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
fa15d405
JM
384 WPS_IE_VENDOR_TYPE);
385 else
386 wps = NULL;
54f489be 387#ifdef CONFIG_WPS_STRICT
fa15d405 388 if (wps && wps_validate_assoc_req(wps) < 0) {
08a74e6a 389 reason = WLAN_REASON_INVALID_IE;
88b32a99 390 status = WLAN_STATUS_INVALID_IE;
fa15d405 391 wpabuf_free(wps);
08a74e6a 392 goto fail;
54f489be 393 }
54f489be 394#endif /* CONFIG_WPS_STRICT */
fa15d405 395 if (wps) {
a9aca28b 396 sta->flags |= WLAN_STA_WPS;
fa15d405 397 if (wps_is_20(wps)) {
48b06c17
JM
398 wpa_printf(MSG_DEBUG,
399 "WPS: STA supports WPS 2.0");
17f6b900
JM
400 sta->flags |= WLAN_STA_WPS2;
401 }
a9aca28b
JM
402 } else
403 sta->flags |= WLAN_STA_MAYBE_WPS;
17f6b900 404 wpabuf_free(wps);
633d4469 405#endif /* CONFIG_WPS */
a14896e8
JM
406#ifdef CONFIG_HS20
407 } else if (hapd->conf->osen) {
408 if (elems.osen == NULL) {
409 hostapd_logger(
410 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
411 HOSTAPD_LEVEL_INFO,
412 "No HS 2.0 OSEN element in association request");
413 return WLAN_STATUS_INVALID_IE;
414 }
415
416 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
417 if (sta->wpa_sm == NULL)
418 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
419 sta->addr, NULL);
420 if (sta->wpa_sm == NULL) {
48b06c17
JM
421 wpa_printf(MSG_WARNING,
422 "Failed to initialize WPA state machine");
a14896e8
JM
423 return WLAN_STATUS_UNSPECIFIED_FAILURE;
424 }
425 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
426 elems.osen - 2, elems.osen_len + 2) < 0)
427 return WLAN_STATUS_INVALID_IE;
428#endif /* CONFIG_HS20 */
b5b969e9 429 }
4c572281
JM
430
431#ifdef CONFIG_MBO
432 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
433 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
434 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
435 wpa_printf(MSG_INFO,
436 "MBO: Reject WPA2 association without PMF");
437 return WLAN_STATUS_UNSPECIFIED_FAILURE;
438 }
439#endif /* CONFIG_MBO */
440
633d4469 441#ifdef CONFIG_WPS
b5b969e9 442skip_wpa_check:
633d4469 443#endif /* CONFIG_WPS */
b5b969e9 444
4ec1fd8e 445#ifdef CONFIG_IEEE80211R_AP
88b32a99
SP
446 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
447 sta->auth_alg, req_ies, req_ies_len);
cc20edc9 448#endif /* CONFIG_IEEE80211R_AP */
88b32a99 449
fa61bff6
JM
450#ifdef CONFIG_FILS
451 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
452 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
453 sta->auth_alg == WLAN_AUTH_FILS_PK) {
8b5ddda5
JM
454 int delay_assoc = 0;
455
3de1566d
PX
456 if (!req_ies)
457 return WLAN_STATUS_UNSPECIFIED_FAILURE;
458
fa61bff6
JM
459 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
460 req_ies_len,
461 sta->fils_session)) {
462 wpa_printf(MSG_DEBUG,
463 "FILS: Session validation failed");
464 return WLAN_STATUS_UNSPECIFIED_FAILURE;
465 }
466
467 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
468 req_ies_len);
469 if (res < 0) {
470 wpa_printf(MSG_DEBUG,
471 "FILS: Key Confirm validation failed");
472 return WLAN_STATUS_UNSPECIFIED_FAILURE;
473 }
474
8b5ddda5 475 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
fa61bff6 476 wpa_printf(MSG_DEBUG,
8b5ddda5
JM
477 "FILS: Delaying Assoc Response (HLP)");
478 delay_assoc = 1;
479 } else {
480 wpa_printf(MSG_DEBUG,
481 "FILS: Going ahead with Assoc Response (no HLP)");
482 }
483
484 if (sta) {
485 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
486 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
487 os_free(sta->fils_pending_assoc_req);
488 sta->fils_pending_assoc_req = NULL;
489 sta->fils_pending_assoc_req_len = 0;
490 wpabuf_free(sta->fils_hlp_resp);
491 sta->fils_hlp_resp = NULL;
492 sta->fils_drv_assoc_finish = 0;
fa61bff6
JM
493 }
494
8b5ddda5
JM
495 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
496 u8 *req_tmp;
497
498 req_tmp = os_malloc(req_ies_len);
499 if (!req_tmp) {
500 wpa_printf(MSG_DEBUG,
501 "FILS: buffer allocation failed for assoc req");
502 goto fail;
503 }
504 os_memcpy(req_tmp, req_ies, req_ies_len);
505 sta->fils_pending_assoc_req = req_tmp;
506 sta->fils_pending_assoc_req_len = req_ies_len;
507 sta->fils_pending_assoc_is_reassoc = reassoc;
508 sta->fils_drv_assoc_finish = 1;
509 wpa_printf(MSG_DEBUG,
510 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
511 MACSTR, MAC2STR(sta->addr));
512 eloop_register_timeout(
513 0, hapd->conf->fils_hlp_wait_time * 1024,
514 fils_hlp_timeout, hapd, sta);
515 return 0;
516 }
fa61bff6 517 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
8b5ddda5
JM
518 elems.fils_session,
519 sta->fils_hlp_resp);
fa61bff6
JM
520 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
521 buf, p - buf);
522 }
523#endif /* CONFIG_FILS */
524
33c8bbd8
AKP
525#ifdef CONFIG_OWE
526 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
527 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
528 elems.owe_dh) {
04ded82e
JM
529 u8 *npos;
530
79ce2d51
AP
531 npos = owe_assoc_req_process(hapd, sta,
532 elems.owe_dh, elems.owe_dh_len,
533 p, sizeof(buf) - (p - buf),
534 &reason);
a4668c68
AP
535 if (npos)
536 p = npos;
537 if (!npos &&
538 reason == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
539 status = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
540 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
541 p - buf);
542 return 0;
543 }
544
545 if (!npos || reason != WLAN_STATUS_SUCCESS)
33c8bbd8
AKP
546 goto fail;
547 }
548#endif /* CONFIG_OWE */
549
550#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
88b32a99 551 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
e4474c1c 552
cc20edc9
JM
553 if (sta->auth_alg == WLAN_AUTH_FT ||
554 sta->auth_alg == WLAN_AUTH_FILS_SK ||
555 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
556 sta->auth_alg == WLAN_AUTH_FILS_PK)
e4474c1c 557 ap_sta_set_authorized(hapd, sta, 1);
cc20edc9 558#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
88b32a99
SP
559 /* Keep compiler silent about unused variables */
560 if (status) {
561 }
cc20edc9 562#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
88b32a99 563
b5b969e9
JM
564 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
565 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
3578e665 566 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
88b32a99 567
e4474c1c
DPS
568 hostapd_set_sta_flags(hapd, sta);
569
88b32a99
SP
570 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
571 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
957bff83
JM
572#ifdef CONFIG_FILS
573 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
574 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
575 sta->auth_alg == WLAN_AUTH_FILS_PK)
576 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
577#endif /* CONFIG_FILS */
88b32a99
SP
578 else
579 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
b5b969e9
JM
580
581 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
582
583 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
584
ef796391 585#ifdef CONFIG_P2P
99c01af9
JM
586 if (req_ies) {
587 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
588 req_ies, req_ies_len);
589 }
ef796391
JM
590#endif /* CONFIG_P2P */
591
b5b969e9 592 return 0;
08a74e6a
JM
593
594fail:
4ec1fd8e 595#ifdef CONFIG_IEEE80211R_AP
88b32a99 596 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
4ec1fd8e 597#endif /* CONFIG_IEEE80211R_AP */
08a74e6a
JM
598 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
599 ap_free_sta(hapd, sta);
600 return -1;
b5b969e9
JM
601}
602
603
604void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
605{
606 struct sta_info *sta;
607
83e843e8
JM
608 if (addr == NULL) {
609 /*
610 * This could potentially happen with unexpected event from the
611 * driver wrapper. This was seen at least in one case where the
612 * driver ended up reporting a station mode event while hostapd
613 * was running, so better make sure we stop processing such an
614 * event here.
615 */
48b06c17
JM
616 wpa_printf(MSG_DEBUG,
617 "hostapd_notif_disassoc: Skip event with no address");
1f4c7b6b 618 return;
83e843e8
JM
619 }
620
b5b969e9
JM
621 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
622 HOSTAPD_LEVEL_INFO, "disassociated");
623
624 sta = ap_get_sta(hapd, addr);
625 if (sta == NULL) {
48b06c17
JM
626 wpa_printf(MSG_DEBUG,
627 "Disassociation notification for unknown STA "
628 MACSTR, MAC2STR(addr));
b5b969e9
JM
629 return;
630 }
631
ae055af4 632 ap_sta_set_authorized(hapd, sta, 0);
b5b969e9
JM
633 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
634 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
635 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
636 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
637 ap_free_sta(hapd, sta);
638}
639
640
0d7e5a3a
JB
641void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
642{
643 struct sta_info *sta = ap_get_sta(hapd, addr);
644
645 if (!sta || !hapd->conf->disassoc_low_ack)
646 return;
647
648 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
48b06c17
JM
649 HOSTAPD_LEVEL_INFO,
650 "disconnected due to excessive missing ACKs");
0d7e5a3a 651 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
5f99d962 652 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
0d7e5a3a
JB
653}
654
655
1b487b8b 656void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
8d1fdde7 657 int offset, int width, int cf1, int cf2)
1b487b8b 658{
c7803a02 659#ifdef NEED_AP_MLME
d308a44f
LC
660 int channel, chwidth, is_dfs;
661 u8 seg0_idx = 0, seg1_idx = 0;
1b487b8b
TP
662
663 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
2f06bcb3
JM
664 HOSTAPD_LEVEL_INFO,
665 "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
666 freq, ht, offset, width, channel_width_to_string(width),
667 cf1, cf2);
1b487b8b
TP
668
669 hapd->iface->freq = freq;
670
671 channel = hostapd_hw_get_channel(hapd, freq);
672 if (!channel) {
673 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
48b06c17
JM
674 HOSTAPD_LEVEL_WARNING,
675 "driver switched to bad channel!");
1b487b8b
TP
676 return;
677 }
678
8d1fdde7
JD
679 switch (width) {
680 case CHAN_WIDTH_80:
681 chwidth = VHT_CHANWIDTH_80MHZ;
682 break;
683 case CHAN_WIDTH_80P80:
684 chwidth = VHT_CHANWIDTH_80P80MHZ;
685 break;
686 case CHAN_WIDTH_160:
687 chwidth = VHT_CHANWIDTH_160MHZ;
688 break;
689 case CHAN_WIDTH_20_NOHT:
690 case CHAN_WIDTH_20:
691 case CHAN_WIDTH_40:
692 default:
693 chwidth = VHT_CHANWIDTH_USE_HT;
694 break;
695 }
696
697 switch (hapd->iface->current_mode->mode) {
698 case HOSTAPD_MODE_IEEE80211A:
699 if (cf1 > 5000)
700 seg0_idx = (cf1 - 5000) / 5;
701 if (cf2 > 5000)
702 seg1_idx = (cf2 - 5000) / 5;
703 break;
704 default:
d308a44f
LC
705 ieee80211_freq_to_chan(cf1, &seg0_idx);
706 ieee80211_freq_to_chan(cf2, &seg1_idx);
8d1fdde7
JD
707 break;
708 }
709
1b487b8b
TP
710 hapd->iconf->channel = channel;
711 hapd->iconf->ieee80211n = ht;
5de74818
JM
712 if (!ht)
713 hapd->iconf->ieee80211ac = 0;
1b487b8b 714 hapd->iconf->secondary_channel = offset;
8d1fdde7
JD
715 hapd->iconf->vht_oper_chwidth = chwidth;
716 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
717 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
bf281c12 718
1e2aaffb
AK
719 is_dfs = ieee80211_is_dfs(freq);
720
6782b684
MK
721 if (hapd->csa_in_progress &&
722 freq == hapd->cs_freq_params.freq) {
bf281c12 723 hostapd_cleanup_cs_params(hapd);
6782b684 724 ieee802_11_set_beacon(hapd);
bf281c12 725
1e2aaffb
AK
726 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
727 "freq=%d dfs=%d", freq, is_dfs);
728 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
729 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
730 "freq=%d dfs=%d", freq, is_dfs);
bf281c12 731 }
c7803a02 732#endif /* NEED_AP_MLME */
1b487b8b
TP
733}
734
735
3140803b
RM
736void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
737 const u8 *addr, int reason_code)
738{
739 switch (reason_code) {
740 case MAX_CLIENT_REACHED:
741 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
742 MAC2STR(addr));
743 break;
744 case BLOCKED_CLIENT:
745 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
746 MAC2STR(addr));
747 break;
748 }
749}
750
751
16689c7c 752#ifdef CONFIG_ACS
d9909717
TB
753void hostapd_acs_channel_selected(struct hostapd_data *hapd,
754 struct acs_selected_channels *acs_res)
16689c7c 755{
3784c058 756 int ret, i;
e1d00d47 757 int err = 0;
16689c7c
PX
758
759 if (hapd->iconf->channel) {
760 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
761 hapd->iconf->channel);
762 return;
763 }
764
3784c058
PX
765 if (!hapd->iface->current_mode) {
766 for (i = 0; i < hapd->iface->num_hw_features; i++) {
767 struct hostapd_hw_modes *mode =
768 &hapd->iface->hw_features[i];
769
770 if (mode->mode == acs_res->hw_mode) {
771 hapd->iface->current_mode = mode;
772 break;
773 }
774 }
775 if (!hapd->iface->current_mode) {
776 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
777 HOSTAPD_LEVEL_WARNING,
778 "driver selected to bad hw_mode");
e1d00d47
PX
779 err = 1;
780 goto out;
3784c058
PX
781 }
782 }
783
857d9422 784 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
16689c7c 785
857d9422 786 if (!acs_res->pri_channel) {
16689c7c
PX
787 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
788 HOSTAPD_LEVEL_WARNING,
789 "driver switched to bad channel");
e1d00d47
PX
790 err = 1;
791 goto out;
16689c7c
PX
792 }
793
857d9422
MM
794 hapd->iconf->channel = acs_res->pri_channel;
795 hapd->iconf->acs = 1;
16689c7c 796
857d9422 797 if (acs_res->sec_channel == 0)
16689c7c 798 hapd->iconf->secondary_channel = 0;
857d9422 799 else if (acs_res->sec_channel < acs_res->pri_channel)
16689c7c 800 hapd->iconf->secondary_channel = -1;
857d9422 801 else if (acs_res->sec_channel > acs_res->pri_channel)
16689c7c
PX
802 hapd->iconf->secondary_channel = 1;
803 else {
804 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
e1d00d47
PX
805 err = 1;
806 goto out;
16689c7c
PX
807 }
808
857d9422
MM
809 if (hapd->iface->conf->ieee80211ac) {
810 /* set defaults for backwards compatibility */
811 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
812 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
813 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
814 if (acs_res->ch_width == 80) {
815 hapd->iconf->vht_oper_centr_freq_seg0_idx =
816 acs_res->vht_seg0_center_ch;
817 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
818 } else if (acs_res->ch_width == 160) {
819 if (acs_res->vht_seg1_center_ch == 0) {
820 hapd->iconf->vht_oper_centr_freq_seg0_idx =
821 acs_res->vht_seg0_center_ch;
822 hapd->iconf->vht_oper_chwidth =
823 VHT_CHANWIDTH_160MHZ;
824 } else {
825 hapd->iconf->vht_oper_centr_freq_seg0_idx =
826 acs_res->vht_seg0_center_ch;
827 hapd->iconf->vht_oper_centr_freq_seg1_idx =
828 acs_res->vht_seg1_center_ch;
829 hapd->iconf->vht_oper_chwidth =
830 VHT_CHANWIDTH_80P80MHZ;
831 }
832 }
833 }
834
e1d00d47
PX
835out:
836 ret = hostapd_acs_completed(hapd->iface, err);
16689c7c
PX
837 if (ret) {
838 wpa_printf(MSG_ERROR,
839 "ACS: Possibly channel configuration is invalid");
840 }
841}
842#endif /* CONFIG_ACS */
843
844
04a85e44 845int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
baf513d6
JB
846 const u8 *bssid, const u8 *ie, size_t ie_len,
847 int ssi_signal)
e67b55fb
JM
848{
849 size_t i;
850 int ret = 0;
851
b211f3eb
JM
852 if (sa == NULL || ie == NULL)
853 return -1;
854
855 random_add_randomness(sa, ETH_ALEN);
e67b55fb
JM
856 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
857 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
baf513d6
JB
858 sa, da, bssid, ie, ie_len,
859 ssi_signal) > 0) {
e67b55fb
JM
860 ret = 1;
861 break;
862 }
863 }
864 return ret;
865}
866
867
5c61a282
JM
868#ifdef HOSTAPD
869
4ec1fd8e 870#ifdef CONFIG_IEEE80211R_AP
88b32a99
SP
871static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
872 const u8 *bssid,
873 u16 auth_transaction, u16 status,
874 const u8 *ies, size_t ies_len)
875{
876 struct hostapd_data *hapd = ctx;
877 struct sta_info *sta;
878
879 sta = ap_get_sta(hapd, dst);
880 if (sta == NULL)
881 return;
882
883 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
884 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
885 sta->flags |= WLAN_STA_AUTH;
886
887 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
888}
4ec1fd8e 889#endif /* CONFIG_IEEE80211R_AP */
88b32a99
SP
890
891
fa61bff6
JM
892#ifdef CONFIG_FILS
893static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
894 struct sta_info *sta, u16 resp,
895 struct wpabuf *data, int pub)
896{
897 if (resp == WLAN_STATUS_SUCCESS) {
898 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
899 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
900 sta->flags |= WLAN_STA_AUTH;
901 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
902 sta->auth_alg = WLAN_AUTH_FILS_SK;
903 mlme_authenticate_indication(hapd, sta);
904 } else {
905 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
906 HOSTAPD_LEVEL_DEBUG,
907 "authentication failed (FILS)");
908 }
909
910 hostapd_sta_auth(hapd, sta->addr, 2, resp,
911 data ? wpabuf_head(data) : NULL,
912 data ? wpabuf_len(data) : 0);
913 wpabuf_free(data);
914}
915#endif /* CONFIG_FILS */
916
917
88b32a99
SP
918static void hostapd_notif_auth(struct hostapd_data *hapd,
919 struct auth_info *rx_auth)
920{
921 struct sta_info *sta;
922 u16 status = WLAN_STATUS_SUCCESS;
923 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
924 size_t resp_ies_len = 0;
925
926 sta = ap_get_sta(hapd, rx_auth->peer);
927 if (!sta) {
928 sta = ap_sta_add(hapd, rx_auth->peer);
929 if (sta == NULL) {
728d9717 930 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
88b32a99
SP
931 goto fail;
932 }
933 }
934 sta->flags &= ~WLAN_STA_PREAUTH;
935 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
4ec1fd8e 936#ifdef CONFIG_IEEE80211R_AP
88b32a99
SP
937 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
938 sta->auth_alg = WLAN_AUTH_FT;
939 if (sta->wpa_sm == NULL)
940 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
94ddef3e 941 sta->addr, NULL);
88b32a99 942 if (sta->wpa_sm == NULL) {
48b06c17
JM
943 wpa_printf(MSG_DEBUG,
944 "FT: Failed to initialize WPA state machine");
88b32a99
SP
945 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
946 goto fail;
947 }
948 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
949 rx_auth->auth_transaction, rx_auth->ies,
950 rx_auth->ies_len,
951 hostapd_notify_auth_ft_finish, hapd);
952 return;
953 }
4ec1fd8e 954#endif /* CONFIG_IEEE80211R_AP */
fa61bff6
JM
955
956#ifdef CONFIG_FILS
957 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
958 sta->auth_alg = WLAN_AUTH_FILS_SK;
959 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
960 rx_auth->auth_type, rx_auth->auth_transaction,
961 rx_auth->status_code,
962 hostapd_notify_auth_fils_finish);
963 return;
964 }
965#endif /* CONFIG_FILS */
966
88b32a99
SP
967fail:
968 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
969 status, resp_ies, resp_ies_len);
970}
971
972
973static void hostapd_action_rx(struct hostapd_data *hapd,
dbfb8e82 974 struct rx_mgmt *drv_mgmt)
88b32a99 975{
dbfb8e82 976 struct ieee80211_mgmt *mgmt;
88b32a99 977 struct sta_info *sta;
dbfb8e82
JM
978 size_t plen __maybe_unused;
979 u16 fc;
980
981 if (drv_mgmt->frame_len < 24 + 1)
982 return;
983
984 plen = drv_mgmt->frame_len - 24 - 1;
985
986 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
987 fc = le_to_host16(mgmt->frame_control);
988 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
989 return; /* handled by the driver */
88b32a99 990
48b06c17 991 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
dbfb8e82 992 mgmt->u.action.category, (int) plen);
7d9c0cd3 993
dbfb8e82 994 sta = ap_get_sta(hapd, mgmt->sa);
88b32a99
SP
995 if (sta == NULL) {
996 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
997 return;
998 }
4ec1fd8e 999#ifdef CONFIG_IEEE80211R_AP
dbfb8e82
JM
1000 if (mgmt->u.action.category == WLAN_ACTION_FT) {
1001 const u8 *payload = drv_mgmt->frame + 24 + 1;
48b06c17 1002
dbfb8e82 1003 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
88b32a99 1004 }
4ec1fd8e 1005#endif /* CONFIG_IEEE80211R_AP */
7d9c0cd3 1006#ifdef CONFIG_IEEE80211W
dbfb8e82
JM
1007 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
1008 ieee802_11_sa_query_action(
1009 hapd, mgmt->sa,
1010 mgmt->u.action.u.sa_query_resp.action,
1011 mgmt->u.action.u.sa_query_resp.trans_id);
7d9c0cd3
MP
1012 }
1013#endif /* CONFIG_IEEE80211W */
b5bf84ba 1014#ifdef CONFIG_WNM_AP
dbfb8e82
JM
1015 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1016 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
d32d94db 1017 }
b5bf84ba 1018#endif /* CONFIG_WNM_AP */
037378ff
AN
1019#ifdef CONFIG_FST
1020 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1021 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1022 return;
1023 }
1024#endif /* CONFIG_FST */
9c2b8204
JM
1025#ifdef CONFIG_DPP
1026 if (plen >= 1 + 4 &&
1027 mgmt->u.action.u.vs_public_action.action ==
1028 WLAN_PA_VENDOR_SPECIFIC &&
1029 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1030 OUI_WFA &&
1031 mgmt->u.action.u.vs_public_action.variable[0] ==
1032 DPP_OUI_TYPE) {
1033 const u8 *pos, *end;
1034
dc4d271c 1035 pos = mgmt->u.action.u.vs_public_action.oui;
9c2b8204
JM
1036 end = drv_mgmt->frame + drv_mgmt->frame_len;
1037 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1038 drv_mgmt->freq);
1039 return;
1040 }
1041#endif /* CONFIG_DPP */
88b32a99
SP
1042}
1043
1044
fe6bdb77 1045#ifdef NEED_AP_MLME
f8b1f695 1046
f8b1f695
JM
1047#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1048
1049static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1050 const u8 *bssid)
1051{
1052 size_t i;
1053
1054 if (bssid == NULL)
1055 return NULL;
1056 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1057 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1058 return HAPD_BROADCAST;
1059
1060 for (i = 0; i < iface->num_bss; i++) {
1061 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1062 return iface->bss[i];
1063 }
1064
1065 return NULL;
1066}
1067
1068
1069static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
9b90955e
JB
1070 const u8 *bssid, const u8 *addr,
1071 int wds)
f8b1f695 1072{
9b90955e 1073 hapd = get_hapd_bssid(hapd->iface, bssid);
f8b1f695
JM
1074 if (hapd == NULL || hapd == HAPD_BROADCAST)
1075 return;
1076
9b90955e 1077 ieee802_11_rx_from_unknown(hapd, addr, wds);
f8b1f695
JM
1078}
1079
1080
912b34f0 1081static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
b5b969e9 1082{
4b9841d3 1083 struct hostapd_iface *iface = hapd->iface;
b57e086c 1084 const struct ieee80211_hdr *hdr;
4b9841d3 1085 const u8 *bssid;
2a8b7416 1086 struct hostapd_frame_info fi;
912b34f0 1087 int ret;
4b9841d3 1088
5f7e1c06
JM
1089#ifdef CONFIG_TESTING_OPTIONS
1090 if (hapd->ext_mgmt_frame_handling) {
1091 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1092 char *hex = os_malloc(hex_len);
48b06c17 1093
5f7e1c06
JM
1094 if (hex) {
1095 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1096 rx_mgmt->frame_len);
1097 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1098 os_free(hex);
1099 }
1100 return 1;
1101 }
1102#endif /* CONFIG_TESTING_OPTIONS */
1103
2a8b7416
JM
1104 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1105 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
4b9841d3 1106 if (bssid == NULL)
912b34f0 1107 return 0;
4b9841d3
JM
1108
1109 hapd = get_hapd_bssid(iface, bssid);
1110 if (hapd == NULL) {
48b06c17 1111 u16 fc = le_to_host16(hdr->frame_control);
4b9841d3
JM
1112
1113 /*
1114 * Drop frames to unknown BSSIDs except for Beacon frames which
1115 * could be used to update neighbor information.
1116 */
1117 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1118 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1119 hapd = iface->bss[0];
1120 else
912b34f0 1121 return 0;
4b9841d3
JM
1122 }
1123
2a8b7416 1124 os_memset(&fi, 0, sizeof(fi));
c5cc7a59 1125 fi.freq = rx_mgmt->freq;
2a8b7416
JM
1126 fi.datarate = rx_mgmt->datarate;
1127 fi.ssi_signal = rx_mgmt->ssi_signal;
1128
4b9841d3
JM
1129 if (hapd == HAPD_BROADCAST) {
1130 size_t i;
48b06c17 1131
912b34f0
JM
1132 ret = 0;
1133 for (i = 0; i < iface->num_bss; i++) {
1d91f504
SW
1134 /* if bss is set, driver will call this function for
1135 * each bss individually. */
1136 if (rx_mgmt->drv_priv &&
1137 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1138 continue;
1139
912b34f0
JM
1140 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1141 rx_mgmt->frame_len, &fi) > 0)
1142 ret = 1;
1143 }
4b9841d3 1144 } else
912b34f0
JM
1145 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1146 &fi);
bbb921da
JM
1147
1148 random_add_randomness(&fi, sizeof(fi));
912b34f0
JM
1149
1150 return ret;
b5b969e9
JM
1151}
1152
1153
f8b1f695
JM
1154static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1155 size_t len, u16 stype, int ok)
b5b969e9 1156{
4b9841d3 1157 struct ieee80211_hdr *hdr;
6996ff7b 1158 struct hostapd_data *orig_hapd = hapd;
48b06c17 1159
4b9841d3
JM
1160 hdr = (struct ieee80211_hdr *) buf;
1161 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
6996ff7b 1162 if (!hapd)
4b9841d3 1163 return;
6996ff7b
JM
1164 if (hapd == HAPD_BROADCAST) {
1165 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1166 buf[24] != WLAN_ACTION_PUBLIC)
1167 return;
1168 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1169 if (!hapd || hapd == HAPD_BROADCAST)
1170 return;
1171 /*
1172 * Allow processing of TX status for a Public Action frame that
1173 * used wildcard BBSID.
1174 */
1175 }
b5b969e9
JM
1176 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1177}
f82ef4d8 1178
f8b1f695 1179#endif /* NEED_AP_MLME */
ad1e68e6
JM
1180
1181
a8e0505b
JM
1182static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1183{
1184 struct sta_info *sta = ap_get_sta(hapd, addr);
48b06c17 1185
a8e0505b
JM
1186 if (sta)
1187 return 0;
1188
1189 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1190 " - adding a new STA", MAC2STR(addr));
1191 sta = ap_sta_add(hapd, addr);
1192 if (sta) {
1193 hostapd_new_assoc_sta(hapd, sta, 0);
1194 } else {
1195 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1196 MAC2STR(addr));
1197 return -1;
1198 }
1199
1200 return 0;
1201}
1202
1203
1204static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1205 const u8 *data, size_t data_len)
1206{
1207 struct hostapd_iface *iface = hapd->iface;
f826635c 1208 struct sta_info *sta;
a8e0505b
JM
1209 size_t j;
1210
1211 for (j = 0; j < iface->num_bss; j++) {
48b06c17
JM
1212 sta = ap_get_sta(iface->bss[j], src);
1213 if (sta && sta->flags & WLAN_STA_ASSOC) {
1214 hapd = iface->bss[j];
1215 break;
a8e0505b
JM
1216 }
1217 }
1218
1219 ieee802_1x_receive(hapd, src, data, data_len);
1220}
1221
96bc5086
TB
1222#endif /* HOSTAPD */
1223
a8e0505b 1224
0185007c
MK
1225static struct hostapd_channel_data * hostapd_get_mode_channel(
1226 struct hostapd_iface *iface, unsigned int freq)
1227{
1228 int i;
1229 struct hostapd_channel_data *chan;
1230
1231 for (i = 0; i < iface->current_mode->num_channels; i++) {
1232 chan = &iface->current_mode->channels[i];
0185007c
MK
1233 if ((unsigned int) chan->freq == freq)
1234 return chan;
1235 }
1236
1237 return NULL;
1238}
1239
1240
1241static void hostapd_update_nf(struct hostapd_iface *iface,
1242 struct hostapd_channel_data *chan,
1243 struct freq_survey *survey)
1244{
1245 if (!iface->chans_surveyed) {
1246 chan->min_nf = survey->nf;
1247 iface->lowest_nf = survey->nf;
1248 } else {
1249 if (dl_list_empty(&chan->survey_list))
1250 chan->min_nf = survey->nf;
1251 else if (survey->nf < chan->min_nf)
1252 chan->min_nf = survey->nf;
1253 if (survey->nf < iface->lowest_nf)
1254 iface->lowest_nf = survey->nf;
1255 }
1256}
1257
1258
ec8f36af
KP
1259static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1260 struct survey_results *survey_res)
1261{
1262 struct hostapd_channel_data *chan;
1263 struct freq_survey *survey;
1264 u64 divisor, dividend;
1265
1266 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1267 list);
1268 if (!survey || !survey->freq)
1269 return;
1270
1271 chan = hostapd_get_mode_channel(iface, survey->freq);
1272 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1273 return;
1274
48b06c17
JM
1275 wpa_printf(MSG_DEBUG,
1276 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
ec8f36af
KP
1277 survey->freq,
1278 (unsigned long int) survey->channel_time,
1279 (unsigned long int) survey->channel_time_busy);
1280
1281 if (survey->channel_time > iface->last_channel_time &&
1282 survey->channel_time > survey->channel_time_busy) {
1283 dividend = survey->channel_time_busy -
1284 iface->last_channel_time_busy;
1285 divisor = survey->channel_time - iface->last_channel_time;
1286
1287 iface->channel_utilization = dividend * 255 / divisor;
1288 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1289 iface->channel_utilization);
1290 }
1291 iface->last_channel_time = survey->channel_time;
1292 iface->last_channel_time_busy = survey->channel_time_busy;
1293}
1294
1295
96bc5086
TB
1296void hostapd_event_get_survey(struct hostapd_iface *iface,
1297 struct survey_results *survey_results)
0185007c 1298{
0185007c
MK
1299 struct freq_survey *survey, *tmp;
1300 struct hostapd_channel_data *chan;
1301
1302 if (dl_list_empty(&survey_results->survey_list)) {
1303 wpa_printf(MSG_DEBUG, "No survey data received");
1304 return;
1305 }
1306
ec8f36af
KP
1307 if (survey_results->freq_filter) {
1308 hostapd_single_channel_get_survey(iface, survey_results);
1309 return;
1310 }
1311
0185007c
MK
1312 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1313 struct freq_survey, list) {
1314 chan = hostapd_get_mode_channel(iface, survey->freq);
1315 if (!chan)
1316 continue;
1317 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1318 continue;
1319
1320 dl_list_del(&survey->list);
1321 dl_list_add_tail(&chan->survey_list, &survey->list);
1322
1323 hostapd_update_nf(iface, chan, survey);
1324
1325 iface->chans_surveyed++;
1326 }
1327}
1328
1329
96bc5086 1330#ifdef HOSTAPD
e76da505
JD
1331#ifdef NEED_AP_MLME
1332
5841958f
MK
1333static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1334{
1335 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1336 hapd->conf->iface);
1337
1338 if (hapd->csa_in_progress) {
1339 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1340 hapd->conf->iface);
1341 hostapd_switch_channel_fallback(hapd->iface,
1342 &hapd->cs_freq_params);
1343 }
1344}
1345
1346
e76da505
JD
1347static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1348 struct dfs_event *radar)
1349{
e76da505 1350 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
dc036d9e 1351 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
58b73e3d
JD
1352 radar->chan_offset, radar->chan_width,
1353 radar->cf1, radar->cf2);
e76da505
JD
1354}
1355
1356
7cbb5f1a
VT
1357static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1358 struct dfs_event *radar)
1359{
1360 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1361 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1362 radar->chan_offset, radar->chan_width,
1363 radar->cf1, radar->cf2);
1364}
1365
1366
e76da505
JD
1367static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1368 struct dfs_event *radar)
1369{
1370 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
dc036d9e 1371 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
58b73e3d
JD
1372 radar->chan_offset, radar->chan_width,
1373 radar->cf1, radar->cf2);
e76da505
JD
1374}
1375
1376
1377static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1378 struct dfs_event *radar)
1379{
1380 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
dc036d9e 1381 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
58b73e3d
JD
1382 radar->chan_offset, radar->chan_width,
1383 radar->cf1, radar->cf2);
e76da505
JD
1384}
1385
1386
1387static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1388 struct dfs_event *radar)
1389{
1390 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
dc036d9e 1391 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
58b73e3d
JD
1392 radar->chan_offset, radar->chan_width,
1393 radar->cf1, radar->cf2);
e76da505
JD
1394}
1395
c13578c3
AK
1396
1397static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1398 struct dfs_event *radar)
1399{
1400 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1401 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1402 radar->chan_offset, radar->chan_width,
1403 radar->cf1, radar->cf2);
1404}
1405
e76da505
JD
1406#endif /* NEED_AP_MLME */
1407
1408
9646a8ab 1409void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
ad1e68e6
JM
1410 union wpa_event_data *data)
1411{
1412 struct hostapd_data *hapd = ctx;
74781dfc
JM
1413#ifndef CONFIG_NO_STDOUT_DEBUG
1414 int level = MSG_DEBUG;
ad1e68e6 1415
34caf71a 1416 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
74781dfc
JM
1417 data->rx_mgmt.frame_len >= 24) {
1418 const struct ieee80211_hdr *hdr;
1419 u16 fc;
48b06c17 1420
74781dfc
JM
1421 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1422 fc = le_to_host16(hdr->frame_control);
1423 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1424 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1425 level = MSG_EXCESSIVE;
cc2ada86
JM
1426 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1427 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1428 level = MSG_EXCESSIVE;
74781dfc
JM
1429 }
1430
1431 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
e26cd1a1 1432 event_to_string(event), event);
74781dfc 1433#endif /* CONFIG_NO_STDOUT_DEBUG */
e26cd1a1 1434
ad1e68e6
JM
1435 switch (event) {
1436 case EVENT_MICHAEL_MIC_FAILURE:
1437 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1438 break;
1439 case EVENT_SCAN_RESULTS:
1440 if (hapd->iface->scan_cb)
1441 hapd->iface->scan_cb(hapd->iface);
1442 break;
fcf0f87d 1443 case EVENT_WPS_BUTTON_PUSHED:
d601247c 1444 hostapd_wps_button_pushed(hapd, NULL);
fcf0f87d 1445 break;
f8b1f695
JM
1446#ifdef NEED_AP_MLME
1447 case EVENT_TX_STATUS:
1448 switch (data->tx_status.type) {
1449 case WLAN_FC_TYPE_MGMT:
1450 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1451 data->tx_status.data_len,
1452 data->tx_status.stype,
1453 data->tx_status.ack);
1454 break;
1455 case WLAN_FC_TYPE_DATA:
1456 hostapd_tx_status(hapd, data->tx_status.dst,
1457 data->tx_status.data,
1458 data->tx_status.data_len,
1459 data->tx_status.ack);
1460 break;
1461 }
1462 break;
dd840f79
JB
1463 case EVENT_EAPOL_TX_STATUS:
1464 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1465 data->eapol_tx_status.data,
1466 data->eapol_tx_status.data_len,
1467 data->eapol_tx_status.ack);
1468 break;
bcf24348
JB
1469 case EVENT_DRIVER_CLIENT_POLL_OK:
1470 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1471 break;
f8b1f695 1472 case EVENT_RX_FROM_UNKNOWN:
9b90955e
JB
1473 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1474 data->rx_from_unknown.addr,
1475 data->rx_from_unknown.wds);
f8b1f695 1476 break;
dbfb8e82 1477#endif /* NEED_AP_MLME */
f8b1f695 1478 case EVENT_RX_MGMT:
c0333c8d
JM
1479 if (!data->rx_mgmt.frame)
1480 break;
dbfb8e82
JM
1481#ifdef NEED_AP_MLME
1482 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1483 break;
f8b1f695 1484#endif /* NEED_AP_MLME */
dbfb8e82
JM
1485 hostapd_action_rx(hapd, &data->rx_mgmt);
1486 break;
a0e0d3bb 1487 case EVENT_RX_PROBE_REQ:
b211f3eb
JM
1488 if (data->rx_probe_req.sa == NULL ||
1489 data->rx_probe_req.ie == NULL)
1490 break;
a0e0d3bb 1491 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
04a85e44
JM
1492 data->rx_probe_req.da,
1493 data->rx_probe_req.bssid,
a0e0d3bb 1494 data->rx_probe_req.ie,
baf513d6
JB
1495 data->rx_probe_req.ie_len,
1496 data->rx_probe_req.ssi_signal);
a0e0d3bb 1497 break;
a70a5d6d 1498 case EVENT_NEW_STA:
a8e0505b
JM
1499 hostapd_event_new_sta(hapd, data->new_sta.addr);
1500 break;
1501 case EVENT_EAPOL_RX:
1502 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1503 data->eapol_rx.data,
1504 data->eapol_rx.data_len);
1505 break;
1d041bec 1506 case EVENT_ASSOC:
04a258e7
JM
1507 if (!data)
1508 return;
1d041bec
JM
1509 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1510 data->assoc_info.req_ies,
39b08b5f
SP
1511 data->assoc_info.req_ies_len,
1512 data->assoc_info.reassoc);
1d041bec
JM
1513 break;
1514 case EVENT_DISASSOC:
1515 if (data)
1516 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1517 break;
1518 case EVENT_DEAUTH:
1519 if (data)
1520 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1521 break;
0d7e5a3a
JB
1522 case EVENT_STATION_LOW_ACK:
1523 if (!data)
1524 break;
1525 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1526 break;
88b32a99
SP
1527 case EVENT_AUTH:
1528 hostapd_notif_auth(hapd, &data->auth);
1529 break;
1b487b8b
TP
1530 case EVENT_CH_SWITCH:
1531 if (!data)
1532 break;
1533 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1534 data->ch_switch.ht_enabled,
8d1fdde7
JD
1535 data->ch_switch.ch_offset,
1536 data->ch_switch.ch_width,
1537 data->ch_switch.cf1,
1538 data->ch_switch.cf2);
1b487b8b 1539 break;
3140803b
RM
1540 case EVENT_CONNECT_FAILED_REASON:
1541 if (!data)
1542 break;
1543 hostapd_event_connect_failed_reason(
1544 hapd, data->connect_failed_reason.addr,
1545 data->connect_failed_reason.code);
1546 break;
0185007c 1547 case EVENT_SURVEY:
96bc5086 1548 hostapd_event_get_survey(hapd->iface, &data->survey_results);
0185007c 1549 break;
e76da505 1550#ifdef NEED_AP_MLME
5841958f
MK
1551 case EVENT_INTERFACE_UNAVAILABLE:
1552 hostapd_event_iface_unavailable(hapd);
1553 break;
e76da505
JD
1554 case EVENT_DFS_RADAR_DETECTED:
1555 if (!data)
1556 break;
1557 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1558 break;
7cbb5f1a
VT
1559 case EVENT_DFS_PRE_CAC_EXPIRED:
1560 if (!data)
1561 break;
1562 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1563 break;
e76da505
JD
1564 case EVENT_DFS_CAC_FINISHED:
1565 if (!data)
1566 break;
1567 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1568 break;
1569 case EVENT_DFS_CAC_ABORTED:
1570 if (!data)
1571 break;
1572 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1573 break;
1574 case EVENT_DFS_NOP_FINISHED:
1575 if (!data)
1576 break;
1577 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1578 break;
1579 case EVENT_CHANNEL_LIST_CHANGED:
1580 /* channel list changed (regulatory?), update channel list */
1581 /* TODO: check this. hostapd_get_hw_features() initializes
1582 * too much stuff. */
1583 /* hostapd_get_hw_features(hapd->iface); */
795baf77
AS
1584 hostapd_channel_list_updated(
1585 hapd->iface, data->channel_list_changed.initiator);
e76da505 1586 break;
c13578c3
AK
1587 case EVENT_DFS_CAC_STARTED:
1588 if (!data)
1589 break;
1590 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1591 break;
e76da505 1592#endif /* NEED_AP_MLME */
ab93fdeb
JM
1593 case EVENT_INTERFACE_ENABLED:
1594 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
f33c8606
JM
1595 if (hapd->disabled && hapd->started) {
1596 hapd->disabled = 0;
1597 /*
1598 * Try to re-enable interface if the driver stopped it
1599 * when the interface got disabled.
1600 */
34782730 1601 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
f33c8606
JM
1602 hapd->reenable_beacon = 1;
1603 ieee802_11_set_beacon(hapd);
1604 }
ab93fdeb
JM
1605 break;
1606 case EVENT_INTERFACE_DISABLED:
c165cb40 1607 hostapd_free_stas(hapd);
ab93fdeb 1608 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
f33c8606 1609 hapd->disabled = 1;
ab93fdeb 1610 break;
16689c7c
PX
1611#ifdef CONFIG_ACS
1612 case EVENT_ACS_CHANNEL_SELECTED:
857d9422
MM
1613 hostapd_acs_channel_selected(hapd,
1614 &data->acs_selected_channels);
16689c7c
PX
1615 break;
1616#endif /* CONFIG_ACS */
ad1e68e6
JM
1617 default:
1618 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1619 break;
1620 }
1621}
f8b1f695 1622
45e3fc72
RM
1623
1624void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
1625 union wpa_event_data *data)
1626{
1627 struct hapd_interfaces *interfaces = ctx;
1628 struct hostapd_data *hapd;
1629
1630 if (event != EVENT_INTERFACE_STATUS)
1631 return;
1632
1633 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
1634 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
1635 hapd->drv_priv) {
1636 unsigned int ifindex;
1637
1638 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
1639 if (ifindex != data->interface_status.ifindex) {
1640 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1641 "interface status ifindex %d mismatch (%d)",
1642 ifindex, data->interface_status.ifindex);
1643 return;
1644 }
1645 }
1646 if (hapd)
1647 wpa_supplicant_event(hapd, event, data);
1648}
1649
f8b1f695 1650#endif /* HOSTAPD */