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