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