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