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