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