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