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