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