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