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