blob: 524a15132b8ad9a10a530f48b9c6403dd0788ccf [file] [log] [blame]
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001/*
2 * hostapd / Callback functions for driver wrappers
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07003 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07004 *
Dmitry Shmidtc5ec7f52012-03-06 16:33:24 -08005 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07007 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070012#include "utils/eloop.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070013#include "radius/radius.h"
14#include "drivers/driver.h"
15#include "common/ieee802_11_defs.h"
16#include "common/ieee802_11_common.h"
Dmitry Shmidtf8623282013-02-20 14:34:59 -080017#include "common/wpa_ctrl.h"
Hai Shalom021b0b52019-04-10 11:17:58 -070018#include "common/dpp.h"
Hai Shalomc3565922019-10-28 11:58:20 -070019#include "common/sae.h"
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -080020#include "common/hw_features_common.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "crypto/random.h"
22#include "p2p/p2p.h"
23#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080024#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070025#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "hostapd.h"
27#include "ieee802_11.h"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080028#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "sta_info.h"
30#include "accounting.h"
31#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070032#include "ieee802_1x.h"
33#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070034#include "wps_hostapd.h"
35#include "ap_drv_ops.h"
36#include "ap_config.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070037#include "ap_mlme.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070038#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070039#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070040#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080041#include "mbo_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070042#include "dpp_hostapd.h"
43#include "fils_hlp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080044#include "neighbor_db.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070045
46
47#ifdef CONFIG_FILS
48void 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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106
107
108int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800109 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700110{
111 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700112 int new_assoc;
113 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800115 const u8 *ie;
116 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700117 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
118 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800119 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700120 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700121 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700122
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 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800131 wpa_printf(MSG_DEBUG,
132 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700133 return -1;
134 }
Hai Shalomc3565922019-10-28 11:58:20 -0700135
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
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148 random_add_randomness(addr, ETH_ALEN);
149
150 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
151 HOSTAPD_LEVEL_INFO, "associated");
152
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800153 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700154 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");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800166#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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700172 } else {
173 ie = NULL;
174 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800175 wpa_printf(MSG_DEBUG,
176 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177 }
178
179 sta = ap_get_sta(hapd, addr);
180 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700181 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700182 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700183
184 /*
185 * Make sure that the previously registered inactivity timer
186 * will not remove the STA immediately.
187 */
188 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 } else {
190 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700191 if (sta == NULL) {
192 hostapd_drv_sta_disassoc(hapd, addr,
193 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700194 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700195 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800197 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700199 /*
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) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800208 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
209 MAC2STR(addr));
210 reason = WLAN_REASON_UNSPECIFIED;
211 goto fail;
212 }
213
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214#ifdef CONFIG_P2P
215 if (elems.p2p) {
216 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800217 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700218 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700219 if (sta->p2p_ie)
220 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700221 }
222#endif /* CONFIG_P2P */
223
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700224#ifdef NEED_AP_MLME
225 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700226 (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 */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700237
Dmitry Shmidt051af732013-10-22 13:52:46 -0700238#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
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800245#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;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700252
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;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800260#endif /* CONFIG_HS20 */
261
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800262#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
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800270 mbo_ap_check_sta_assoc(hapd, sta, &elems);
271
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800272 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
273 elems.supp_op_classes_len);
274
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275 if (hapd->conf->wpa) {
276 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800277#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700278 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800279 wpa_printf(MSG_DEBUG,
280 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700281 sta->flags |= WLAN_STA_MAYBE_WPS;
282 goto skip_wpa_check;
283 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800284#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700285
286 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700287 reason = WLAN_REASON_INVALID_IE;
288 status = WLAN_STATUS_INVALID_IE;
289 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700290 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800291#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700292 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
293 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800294 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800295
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800297 wps = ieee802_11_vendor_ie_concat(ie, ielen,
298 WPS_IE_VENDOR_TYPE);
299 if (wps) {
300 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800301 wpa_printf(MSG_DEBUG,
302 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800303 sta->flags |= WLAN_STA_WPS2;
304 }
305 wpabuf_free(wps);
306 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 goto skip_wpa_check;
308 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800309#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310
311 if (sta->wpa_sm == NULL)
312 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700313 sta->addr,
314 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800316 wpa_printf(MSG_ERROR,
317 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 return -1;
319 }
320 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700321 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700322 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700323 elems.rsnxe ? elems.rsnxe - 2 : NULL,
324 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700325 elems.mdie, elems.mdie_len,
326 elems.owe_dh, elems.owe_dh_len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700327 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) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800384 wpa_printf(MSG_DEBUG,
385 "WPA/RSN information element rejected? (res %u)",
386 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700387 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800388 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700389 }
Hai Shalomc3565922019-10-28 11:58:20 -0700390
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800391 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
392 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
393 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700394 sta->sa_query_count > 0)
395 ap_check_sa_query_timeout(hapd, sta);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800396 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
397 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
398 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700399 (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
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700410 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);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700416 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;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700423
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800424#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700425 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 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800438#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700439#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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700453 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454#ifdef CONFIG_WPS
455 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800456
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800457 if (req_ies)
458 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700459 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800460 else
461 wps = NULL;
462#ifdef CONFIG_WPS_STRICT
463 if (wps && wps_validate_assoc_req(wps) < 0) {
464 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700465 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700466 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800467 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700468 }
469#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800470 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700471 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800472 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800473 wpa_printf(MSG_DEBUG,
474 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800475 sta->flags |= WLAN_STA_WPS2;
476 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700477 } else
478 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800479 wpabuf_free(wps);
480#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800481#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) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800496 wpa_printf(MSG_WARNING,
497 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800498 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 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700504 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700505#ifdef CONFIG_WPS
506skip_wpa_check:
507#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800508
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
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800519#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700520 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700521 sta->auth_alg, req_ies, req_ies_len,
522 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700523 if (!p) {
524 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
525 return WLAN_STATUS_UNSPECIFIED_FAILURE;
526 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700527#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700528
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700529#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
Roshan Pius3a1667e2018-07-03 15:17:14 -0700604#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;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700609 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700610
611 npos = owe_assoc_req_process(hapd, sta,
612 elems.owe_dh, elems.owe_dh_len,
613 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700614 &ret_status);
615 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700616 if (npos)
617 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700618
Roshan Pius3a1667e2018-07-03 15:17:14 -0700619 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700620 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700621 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700622 p - buf);
623 return 0;
624 }
625
Hai Shalomfdcde762020-04-02 11:19:20 -0700626 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700627 goto fail;
628 }
629#endif /* CONFIG_OWE */
630
Hai Shalom021b0b52019-04-10 11:17:58 -0700631#ifdef CONFIG_DPP2
632 dpp_pfs_free(sta->dpp_pfs);
633 sta->dpp_pfs = NULL;
634
635 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
636 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
637 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
638 elems.owe_dh) {
639 sta->dpp_pfs = dpp_pfs_init(
640 wpabuf_head(hapd->conf->dpp_netaccesskey),
641 wpabuf_len(hapd->conf->dpp_netaccesskey));
642 if (!sta->dpp_pfs) {
643 wpa_printf(MSG_DEBUG,
644 "DPP: Could not initialize PFS");
645 /* Try to continue without PFS */
646 goto pfs_fail;
647 }
648
649 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
650 elems.owe_dh_len) < 0) {
651 dpp_pfs_free(sta->dpp_pfs);
652 sta->dpp_pfs = NULL;
653 reason = WLAN_REASON_UNSPECIFIED;
654 goto fail;
655 }
656 }
657
658 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
659 sta->dpp_pfs->secret : NULL);
660 pfs_fail:
661#endif /* CONFIG_DPP2 */
662
Hai Shalomfdcde762020-04-02 11:19:20 -0700663 if (elems.rrm_enabled &&
664 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
665 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
666 sizeof(sta->rrm_enabled_capa));
667
Roshan Pius3a1667e2018-07-03 15:17:14 -0700668#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700669 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700670
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700671 if (sta->auth_alg == WLAN_AUTH_FT ||
672 sta->auth_alg == WLAN_AUTH_FILS_SK ||
673 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
674 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700675 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700676#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700677 /* Keep compiler silent about unused variables */
678 if (status) {
679 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700680#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700681
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700682 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
683 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800684 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700685
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700686 hostapd_set_sta_flags(hapd, sta);
687
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700688 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
689 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700690#ifdef CONFIG_FILS
691 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
692 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
693 sta->auth_alg == WLAN_AUTH_FILS_PK)
694 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
695#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700696 else
697 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700698
699 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
700
701 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
702
703#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800704 if (req_ies) {
705 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
706 req_ies, req_ies_len);
707 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708#endif /* CONFIG_P2P */
709
710 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800711
712fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800713#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700714 if (status >= 0)
715 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800716#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800717 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
718 ap_free_sta(hapd, sta);
719 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720}
721
722
723void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
724{
725 struct sta_info *sta;
726
727 if (addr == NULL) {
728 /*
729 * This could potentially happen with unexpected event from the
730 * driver wrapper. This was seen at least in one case where the
731 * driver ended up reporting a station mode event while hostapd
732 * was running, so better make sure we stop processing such an
733 * event here.
734 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800735 wpa_printf(MSG_DEBUG,
736 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737 return;
738 }
739
740 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
741 HOSTAPD_LEVEL_INFO, "disassociated");
742
743 sta = ap_get_sta(hapd, addr);
744 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800745 wpa_printf(MSG_DEBUG,
746 "Disassociation notification for unknown STA "
747 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700748 return;
749 }
750
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800751 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700752 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Hai Shalomfdcde762020-04-02 11:19:20 -0700753 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700754 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
755 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
756 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
757 ap_free_sta(hapd, sta);
758}
759
760
761void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
762{
763 struct sta_info *sta = ap_get_sta(hapd, addr);
764
Roshan Pius3a1667e2018-07-03 15:17:14 -0700765 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700766 return;
767
768 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800769 HOSTAPD_LEVEL_INFO,
770 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800772 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773}
774
775
Roshan Pius3a1667e2018-07-03 15:17:14 -0700776void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
777 enum smps_mode smps_mode,
778 enum chan_width chan_width, u8 rx_nss)
779{
780 struct sta_info *sta = ap_get_sta(hapd, addr);
781 const char *txt;
782
783 if (!sta)
784 return;
785
786 switch (smps_mode) {
787 case SMPS_AUTOMATIC:
788 txt = "automatic";
789 break;
790 case SMPS_OFF:
791 txt = "off";
792 break;
793 case SMPS_DYNAMIC:
794 txt = "dynamic";
795 break;
796 case SMPS_STATIC:
797 txt = "static";
798 break;
799 default:
800 txt = NULL;
801 break;
802 }
803 if (txt) {
804 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
805 MACSTR " %s", MAC2STR(addr), txt);
806 }
807
808 switch (chan_width) {
809 case CHAN_WIDTH_20_NOHT:
810 txt = "20(no-HT)";
811 break;
812 case CHAN_WIDTH_20:
813 txt = "20";
814 break;
815 case CHAN_WIDTH_40:
816 txt = "40";
817 break;
818 case CHAN_WIDTH_80:
819 txt = "80";
820 break;
821 case CHAN_WIDTH_80P80:
822 txt = "80+80";
823 break;
824 case CHAN_WIDTH_160:
825 txt = "160";
826 break;
827 default:
828 txt = NULL;
829 break;
830 }
831 if (txt) {
832 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
833 MACSTR " %s", MAC2STR(addr), txt);
834 }
835
836 if (rx_nss != 0xff) {
837 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
838 MACSTR " %d", MAC2STR(addr), rx_nss);
839 }
840}
841
842
Dmitry Shmidt04949592012-07-19 12:16:46 -0700843void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -0700844 int offset, int width, int cf1, int cf2,
845 int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700846{
Hai Shalom74f70d42019-02-11 14:42:39 -0800847 /* TODO: If OCV is enabled deauth STAs that don't perform a SA Query */
848
Dmitry Shmidt04949592012-07-19 12:16:46 -0700849#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800850 int channel, chwidth, is_dfs;
851 u8 seg0_idx = 0, seg1_idx = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800852 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700853
854 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800855 HOSTAPD_LEVEL_INFO,
Hai Shalom81f62d82019-07-22 12:10:00 -0700856 "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
857 finished ? "had" : "starting",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700858 freq, ht, hapd->iconf->ch_switch_vht_config, offset,
859 width, channel_width_to_string(width), cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700860
Hai Shalom1dc4d202019-04-29 16:22:27 -0700861 if (!hapd->iface->current_mode) {
862 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
863 HOSTAPD_LEVEL_WARNING,
864 "ignore channel switch since the interface is not yet ready");
865 return;
866 }
867
Dmitry Shmidt04949592012-07-19 12:16:46 -0700868 hapd->iface->freq = freq;
869
870 channel = hostapd_hw_get_channel(hapd, freq);
871 if (!channel) {
872 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800873 HOSTAPD_LEVEL_WARNING,
874 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700875 return;
876 }
877
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800878 switch (width) {
879 case CHAN_WIDTH_80:
Hai Shalom81f62d82019-07-22 12:10:00 -0700880 chwidth = CHANWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800881 break;
882 case CHAN_WIDTH_80P80:
Hai Shalom81f62d82019-07-22 12:10:00 -0700883 chwidth = CHANWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800884 break;
885 case CHAN_WIDTH_160:
Hai Shalom81f62d82019-07-22 12:10:00 -0700886 chwidth = CHANWIDTH_160MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800887 break;
888 case CHAN_WIDTH_20_NOHT:
889 case CHAN_WIDTH_20:
890 case CHAN_WIDTH_40:
891 default:
Hai Shalom81f62d82019-07-22 12:10:00 -0700892 chwidth = CHANWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800893 break;
894 }
895
896 switch (hapd->iface->current_mode->mode) {
897 case HOSTAPD_MODE_IEEE80211A:
898 if (cf1 > 5000)
899 seg0_idx = (cf1 - 5000) / 5;
900 if (cf2 > 5000)
901 seg1_idx = (cf2 - 5000) / 5;
902 break;
903 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800904 ieee80211_freq_to_chan(cf1, &seg0_idx);
905 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800906 break;
907 }
908
Dmitry Shmidt04949592012-07-19 12:16:46 -0700909 hapd->iconf->channel = channel;
910 hapd->iconf->ieee80211n = ht;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700911 if (!ht) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800912 hapd->iconf->ieee80211ac = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700913 } else if (hapd->iconf->ch_switch_vht_config) {
914 /* CHAN_SWITCH VHT config */
915 if (hapd->iconf->ch_switch_vht_config &
916 CH_SWITCH_VHT_ENABLED)
917 hapd->iconf->ieee80211ac = 1;
918 else if (hapd->iconf->ch_switch_vht_config &
919 CH_SWITCH_VHT_DISABLED)
920 hapd->iconf->ieee80211ac = 0;
921 }
922 hapd->iconf->ch_switch_vht_config = 0;
923
Dmitry Shmidt04949592012-07-19 12:16:46 -0700924 hapd->iconf->secondary_channel = offset;
Hai Shalom81f62d82019-07-22 12:10:00 -0700925 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
926 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
927 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800928
Roshan Pius3a1667e2018-07-03 15:17:14 -0700929 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
930 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800931
Hai Shalom81f62d82019-07-22 12:10:00 -0700932 wpa_msg(hapd->msg_ctx, MSG_INFO,
933 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d",
934 finished ? WPA_EVENT_CHANNEL_SWITCH :
935 WPA_EVENT_CHANNEL_SWITCH_STARTED,
936 freq, ht, offset, channel_width_to_string(width),
937 cf1, cf2, is_dfs);
938 if (!finished)
939 return;
940
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700941 if (hapd->csa_in_progress &&
942 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800943 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700944 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800945
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800946 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
947 "freq=%d dfs=%d", freq, is_dfs);
948 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
949 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
950 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -0700951 } else if (is_dfs &&
952 hostapd_is_dfs_required(hapd->iface) &&
953 !hostapd_is_dfs_chan_available(hapd->iface) &&
954 !hapd->iface->cac_started) {
955 hostapd_disable_iface(hapd->iface);
956 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800957 }
Hai Shalom74f70d42019-02-11 14:42:39 -0800958
959 for (i = 0; i < hapd->iface->num_bss; i++)
960 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700961#endif /* NEED_AP_MLME */
962}
963
964
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800965void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
966 const u8 *addr, int reason_code)
967{
968 switch (reason_code) {
969 case MAX_CLIENT_REACHED:
970 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
971 MAC2STR(addr));
972 break;
973 case BLOCKED_CLIENT:
974 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
975 MAC2STR(addr));
976 break;
977 }
978}
979
980
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800981#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800982void hostapd_acs_channel_selected(struct hostapd_data *hapd,
983 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800984{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700985 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800986 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800987 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800988
989 if (hapd->iconf->channel) {
990 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
991 hapd->iconf->channel);
992 return;
993 }
994
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -0800995 hapd->iface->freq = acs_res->pri_freq;
996
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700997 if (!hapd->iface->current_mode) {
998 for (i = 0; i < hapd->iface->num_hw_features; i++) {
999 struct hostapd_hw_modes *mode =
1000 &hapd->iface->hw_features[i];
1001
1002 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001003 if (hapd->iface->freq > 0 &&
1004 !hw_get_chan(mode->mode,
1005 hapd->iface->freq,
1006 hapd->iface->hw_features,
1007 hapd->iface->num_hw_features))
1008 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001009 hapd->iface->current_mode = mode;
1010 break;
1011 }
1012 }
1013 if (!hapd->iface->current_mode) {
1014 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1015 HOSTAPD_LEVEL_WARNING,
1016 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001017 err = 1;
1018 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001019 }
1020 }
1021
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001022 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001023 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1024 HOSTAPD_LEVEL_WARNING,
1025 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001026 err = 1;
1027 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001028 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001029 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1030 acs_res->pri_freq, NULL,
1031 hapd->iface->hw_features,
1032 hapd->iface->num_hw_features);
1033 if (!pri_chan) {
1034 wpa_printf(MSG_ERROR,
1035 "ACS: Could not determine primary channel number from pri_freq %u",
1036 acs_res->pri_freq);
1037 err = 1;
1038 goto out;
1039 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001040
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001041 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001042 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001043
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001044 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001045 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001046 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001047 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001048 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001049 hapd->iconf->secondary_channel = 1;
1050 else {
1051 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001052 err = 1;
1053 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001054 }
1055
Hai Shalomfdcde762020-04-02 11:19:20 -07001056 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1057
Hai Shalom81f62d82019-07-22 12:10:00 -07001058 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001059 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001060 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1061 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
1062 hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001063 if (acs_res->ch_width == 40) {
1064 if (is_6ghz_freq(acs_res->pri_freq))
1065 hostapd_set_oper_centr_freq_seg0_idx(
1066 hapd->iconf,
1067 acs_res->vht_seg0_center_ch);
1068 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001069 hostapd_set_oper_centr_freq_seg0_idx(
1070 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001071 if (acs_res->vht_seg1_center_ch == 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001072 hostapd_set_oper_chwidth(hapd->iconf,
Hai Shalomfdcde762020-04-02 11:19:20 -07001073 CHANWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001074 } else {
Hai Shalomfdcde762020-04-02 11:19:20 -07001075 hostapd_set_oper_chwidth(hapd->iconf,
1076 CHANWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001077 hostapd_set_oper_centr_freq_seg1_idx(
1078 hapd->iconf,
1079 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001080 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001081 } else if (acs_res->ch_width == 160) {
1082 hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_160MHZ);
1083 hostapd_set_oper_centr_freq_seg0_idx(
1084 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001085 }
1086 }
1087
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001088out:
1089 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001090 if (ret) {
1091 wpa_printf(MSG_ERROR,
1092 "ACS: Possibly channel configuration is invalid");
1093 }
1094}
1095#endif /* CONFIG_ACS */
1096
1097
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001098int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001099 const u8 *bssid, const u8 *ie, size_t ie_len,
1100 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001101{
1102 size_t i;
1103 int ret = 0;
1104
1105 if (sa == NULL || ie == NULL)
1106 return -1;
1107
1108 random_add_randomness(sa, ETH_ALEN);
1109 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1110 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001111 sa, da, bssid, ie, ie_len,
1112 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001113 ret = 1;
1114 break;
1115 }
1116 }
1117 return ret;
1118}
1119
1120
1121#ifdef HOSTAPD
1122
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001123#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001124static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1125 const u8 *bssid,
1126 u16 auth_transaction, u16 status,
1127 const u8 *ies, size_t ies_len)
1128{
1129 struct hostapd_data *hapd = ctx;
1130 struct sta_info *sta;
1131
1132 sta = ap_get_sta(hapd, dst);
1133 if (sta == NULL)
1134 return;
1135
1136 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1137 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1138 sta->flags |= WLAN_STA_AUTH;
1139
1140 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1141}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001142#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001143
1144
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001145#ifdef CONFIG_FILS
1146static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1147 struct sta_info *sta, u16 resp,
1148 struct wpabuf *data, int pub)
1149{
1150 if (resp == WLAN_STATUS_SUCCESS) {
1151 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1152 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1153 sta->flags |= WLAN_STA_AUTH;
1154 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1155 sta->auth_alg = WLAN_AUTH_FILS_SK;
1156 mlme_authenticate_indication(hapd, sta);
1157 } else {
1158 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1159 HOSTAPD_LEVEL_DEBUG,
1160 "authentication failed (FILS)");
1161 }
1162
1163 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1164 data ? wpabuf_head(data) : NULL,
1165 data ? wpabuf_len(data) : 0);
1166 wpabuf_free(data);
1167}
1168#endif /* CONFIG_FILS */
1169
1170
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001171static void hostapd_notif_auth(struct hostapd_data *hapd,
1172 struct auth_info *rx_auth)
1173{
1174 struct sta_info *sta;
1175 u16 status = WLAN_STATUS_SUCCESS;
1176 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1177 size_t resp_ies_len = 0;
1178
1179 sta = ap_get_sta(hapd, rx_auth->peer);
1180 if (!sta) {
1181 sta = ap_sta_add(hapd, rx_auth->peer);
1182 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001183 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001184 goto fail;
1185 }
1186 }
1187 sta->flags &= ~WLAN_STA_PREAUTH;
1188 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001189#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001190 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1191 sta->auth_alg = WLAN_AUTH_FT;
1192 if (sta->wpa_sm == NULL)
1193 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001194 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001195 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001196 wpa_printf(MSG_DEBUG,
1197 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001198 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1199 goto fail;
1200 }
1201 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1202 rx_auth->auth_transaction, rx_auth->ies,
1203 rx_auth->ies_len,
1204 hostapd_notify_auth_ft_finish, hapd);
1205 return;
1206 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001207#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001208
1209#ifdef CONFIG_FILS
1210 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1211 sta->auth_alg = WLAN_AUTH_FILS_SK;
1212 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1213 rx_auth->auth_type, rx_auth->auth_transaction,
1214 rx_auth->status_code,
1215 hostapd_notify_auth_fils_finish);
1216 return;
1217 }
1218#endif /* CONFIG_FILS */
1219
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001220fail:
1221 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1222 status, resp_ies, resp_ies_len);
1223}
1224
1225
Hai Shalom021b0b52019-04-10 11:17:58 -07001226#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001227static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001228 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001229{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001230 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001231 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001232 size_t plen __maybe_unused;
1233 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001234 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001235
Hai Shalom74f70d42019-02-11 14:42:39 -08001236 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001237 return;
1238
Hai Shalom021b0b52019-04-10 11:17:58 -07001239 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001240
1241 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1242 fc = le_to_host16(mgmt->frame_control);
1243 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1244 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001245
Hai Shalom74f70d42019-02-11 14:42:39 -08001246 action = (u8 *) &mgmt->u.action.u;
1247 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1248 " da " MACSTR " plen %d",
1249 mgmt->u.action.category, *action,
1250 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001251
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001252 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001253 if (sta == NULL) {
1254 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1255 return;
1256 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001257#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001258 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001259 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1260 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001261 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001262#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001263 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001264 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001265 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001266 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001267#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001268 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1269 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001270 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001271 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001272#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001273#ifdef CONFIG_FST
1274 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1275 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1276 return;
1277 }
1278#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001279#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001280 if (plen >= 2 + 4 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001281 mgmt->u.action.u.vs_public_action.action ==
1282 WLAN_PA_VENDOR_SPECIFIC &&
1283 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1284 OUI_WFA &&
1285 mgmt->u.action.u.vs_public_action.variable[0] ==
1286 DPP_OUI_TYPE) {
1287 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001288
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001289 pos = mgmt->u.action.u.vs_public_action.oui;
1290 end = drv_mgmt->frame + drv_mgmt->frame_len;
1291 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1292 drv_mgmt->freq);
1293 return;
1294 }
1295#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001296}
Hai Shalom021b0b52019-04-10 11:17:58 -07001297#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001298
1299
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001300#ifdef NEED_AP_MLME
1301
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001302#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1303
1304static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1305 const u8 *bssid)
1306{
1307 size_t i;
1308
1309 if (bssid == NULL)
1310 return NULL;
1311 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1312 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1313 return HAPD_BROADCAST;
1314
1315 for (i = 0; i < iface->num_bss; i++) {
1316 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1317 return iface->bss[i];
1318 }
1319
1320 return NULL;
1321}
1322
1323
1324static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001325 const u8 *bssid, const u8 *addr,
1326 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001327{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001328 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329 if (hapd == NULL || hapd == HAPD_BROADCAST)
1330 return;
1331
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001332 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001333}
1334
1335
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001336static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001337{
1338 struct hostapd_iface *iface = hapd->iface;
1339 const struct ieee80211_hdr *hdr;
1340 const u8 *bssid;
1341 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001342 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001343
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001344#ifdef CONFIG_TESTING_OPTIONS
1345 if (hapd->ext_mgmt_frame_handling) {
1346 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1347 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001348
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001349 if (hex) {
1350 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1351 rx_mgmt->frame_len);
1352 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1353 os_free(hex);
1354 }
1355 return 1;
1356 }
1357#endif /* CONFIG_TESTING_OPTIONS */
1358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001359 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1360 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1361 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001362 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001363
1364 hapd = get_hapd_bssid(iface, bssid);
1365 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001366 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001367
1368 /*
1369 * Drop frames to unknown BSSIDs except for Beacon frames which
1370 * could be used to update neighbor information.
1371 */
1372 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1373 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1374 hapd = iface->bss[0];
1375 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001376 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001377 }
1378
1379 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001380 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001381 fi.datarate = rx_mgmt->datarate;
1382 fi.ssi_signal = rx_mgmt->ssi_signal;
1383
1384 if (hapd == HAPD_BROADCAST) {
1385 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001386
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001387 ret = 0;
1388 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001389 /* if bss is set, driver will call this function for
1390 * each bss individually. */
1391 if (rx_mgmt->drv_priv &&
1392 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1393 continue;
1394
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001395 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1396 rx_mgmt->frame_len, &fi) > 0)
1397 ret = 1;
1398 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001399 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001400 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1401 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001402
1403 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001404
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001405 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001406}
1407
1408
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001409static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1410 size_t len, u16 stype, int ok)
1411{
1412 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001413 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001414
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001415 hdr = (struct ieee80211_hdr *) buf;
1416 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001417 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001418 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001419 if (hapd == HAPD_BROADCAST) {
1420 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1421 buf[24] != WLAN_ACTION_PUBLIC)
1422 return;
1423 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1424 if (!hapd || hapd == HAPD_BROADCAST)
1425 return;
1426 /*
1427 * Allow processing of TX status for a Public Action frame that
1428 * used wildcard BBSID.
1429 */
1430 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001431 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1432}
1433
1434#endif /* NEED_AP_MLME */
1435
1436
1437static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1438{
1439 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001440
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001441 if (sta)
1442 return 0;
1443
1444 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1445 " - adding a new STA", MAC2STR(addr));
1446 sta = ap_sta_add(hapd, addr);
1447 if (sta) {
1448 hostapd_new_assoc_sta(hapd, sta, 0);
1449 } else {
1450 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1451 MAC2STR(addr));
1452 return -1;
1453 }
1454
1455 return 0;
1456}
1457
1458
1459static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1460 const u8 *data, size_t data_len)
1461{
1462 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001463 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001464 size_t j;
1465
1466 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001467 sta = ap_get_sta(iface->bss[j], src);
1468 if (sta && sta->flags & WLAN_STA_ASSOC) {
1469 hapd = iface->bss[j];
1470 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001471 }
1472 }
1473
1474 ieee802_1x_receive(hapd, src, data, data_len);
1475}
1476
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001477#endif /* HOSTAPD */
1478
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001479
Hai Shalomfdcde762020-04-02 11:19:20 -07001480static struct hostapd_channel_data *
1481hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
1482{
1483 int i;
1484 struct hostapd_channel_data *chan;
1485
1486 for (i = 0; i < mode->num_channels; i++) {
1487 chan = &mode->channels[i];
1488 if ((unsigned int) chan->freq == freq)
1489 return chan;
1490 }
1491
1492 return NULL;
1493}
1494
1495
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001496static struct hostapd_channel_data * hostapd_get_mode_channel(
1497 struct hostapd_iface *iface, unsigned int freq)
1498{
1499 int i;
1500 struct hostapd_channel_data *chan;
1501
Hai Shalomfdcde762020-04-02 11:19:20 -07001502 for (i = 0; i < iface->num_hw_features; i++) {
1503 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
1504 continue;
1505 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
1506 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001507 return chan;
1508 }
1509
1510 return NULL;
1511}
1512
1513
1514static void hostapd_update_nf(struct hostapd_iface *iface,
1515 struct hostapd_channel_data *chan,
1516 struct freq_survey *survey)
1517{
1518 if (!iface->chans_surveyed) {
1519 chan->min_nf = survey->nf;
1520 iface->lowest_nf = survey->nf;
1521 } else {
1522 if (dl_list_empty(&chan->survey_list))
1523 chan->min_nf = survey->nf;
1524 else if (survey->nf < chan->min_nf)
1525 chan->min_nf = survey->nf;
1526 if (survey->nf < iface->lowest_nf)
1527 iface->lowest_nf = survey->nf;
1528 }
1529}
1530
1531
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001532static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1533 struct survey_results *survey_res)
1534{
1535 struct hostapd_channel_data *chan;
1536 struct freq_survey *survey;
1537 u64 divisor, dividend;
1538
1539 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1540 list);
1541 if (!survey || !survey->freq)
1542 return;
1543
1544 chan = hostapd_get_mode_channel(iface, survey->freq);
1545 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1546 return;
1547
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001548 wpa_printf(MSG_DEBUG,
1549 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001550 survey->freq,
1551 (unsigned long int) survey->channel_time,
1552 (unsigned long int) survey->channel_time_busy);
1553
1554 if (survey->channel_time > iface->last_channel_time &&
1555 survey->channel_time > survey->channel_time_busy) {
1556 dividend = survey->channel_time_busy -
1557 iface->last_channel_time_busy;
1558 divisor = survey->channel_time - iface->last_channel_time;
1559
1560 iface->channel_utilization = dividend * 255 / divisor;
1561 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1562 iface->channel_utilization);
1563 }
1564 iface->last_channel_time = survey->channel_time;
1565 iface->last_channel_time_busy = survey->channel_time_busy;
1566}
1567
1568
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001569void hostapd_event_get_survey(struct hostapd_iface *iface,
1570 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001571{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001572 struct freq_survey *survey, *tmp;
1573 struct hostapd_channel_data *chan;
1574
1575 if (dl_list_empty(&survey_results->survey_list)) {
1576 wpa_printf(MSG_DEBUG, "No survey data received");
1577 return;
1578 }
1579
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001580 if (survey_results->freq_filter) {
1581 hostapd_single_channel_get_survey(iface, survey_results);
1582 return;
1583 }
1584
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001585 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1586 struct freq_survey, list) {
1587 chan = hostapd_get_mode_channel(iface, survey->freq);
1588 if (!chan)
1589 continue;
1590 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1591 continue;
1592
1593 dl_list_del(&survey->list);
1594 dl_list_add_tail(&chan->survey_list, &survey->list);
1595
1596 hostapd_update_nf(iface, chan, survey);
1597
1598 iface->chans_surveyed++;
1599 }
1600}
1601
1602
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001603#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001604#ifdef NEED_AP_MLME
1605
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001606static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1607{
1608 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1609 hapd->conf->iface);
1610
1611 if (hapd->csa_in_progress) {
1612 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1613 hapd->conf->iface);
1614 hostapd_switch_channel_fallback(hapd->iface,
1615 &hapd->cs_freq_params);
1616 }
1617}
1618
1619
Dmitry Shmidt051af732013-10-22 13:52:46 -07001620static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1621 struct dfs_event *radar)
1622{
1623 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001624 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001625 radar->chan_offset, radar->chan_width,
1626 radar->cf1, radar->cf2);
1627}
1628
1629
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001630static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1631 struct dfs_event *radar)
1632{
1633 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1634 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1635 radar->chan_offset, radar->chan_width,
1636 radar->cf1, radar->cf2);
1637}
1638
1639
Dmitry Shmidt051af732013-10-22 13:52:46 -07001640static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1641 struct dfs_event *radar)
1642{
1643 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001644 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001645 radar->chan_offset, radar->chan_width,
1646 radar->cf1, radar->cf2);
1647}
1648
1649
1650static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1651 struct dfs_event *radar)
1652{
1653 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001654 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001655 radar->chan_offset, radar->chan_width,
1656 radar->cf1, radar->cf2);
1657}
1658
1659
1660static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1661 struct dfs_event *radar)
1662{
1663 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001664 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001665 radar->chan_offset, radar->chan_width,
1666 radar->cf1, radar->cf2);
1667}
1668
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001669
1670static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1671 struct dfs_event *radar)
1672{
1673 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1674 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1675 radar->chan_offset, radar->chan_width,
1676 radar->cf1, radar->cf2);
1677}
1678
Dmitry Shmidt051af732013-10-22 13:52:46 -07001679#endif /* NEED_AP_MLME */
1680
1681
Roshan Pius3a1667e2018-07-03 15:17:14 -07001682static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1683 int istatus,
1684 const char *ifname,
1685 const u8 *addr)
1686{
1687 struct sta_info *sta = ap_get_sta(hapd, addr);
1688
1689 if (sta) {
1690 os_free(sta->ifname_wds);
1691 if (istatus == INTERFACE_ADDED)
1692 sta->ifname_wds = os_strdup(ifname);
1693 else
1694 sta->ifname_wds = NULL;
1695 }
1696
1697 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1698 istatus == INTERFACE_ADDED ?
1699 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1700 ifname, MAC2STR(addr));
1701}
1702
1703
Hai Shalom81f62d82019-07-22 12:10:00 -07001704#ifdef CONFIG_OWE
1705static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
1706 const u8 *peer, const u8 *ie,
1707 size_t ie_len)
1708{
1709 u16 status;
1710 struct sta_info *sta;
1711 struct ieee802_11_elems elems;
1712
1713 if (!hapd || !hapd->wpa_auth) {
1714 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
1715 return -1;
1716 }
1717 if (!peer) {
1718 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
1719 return -1;
1720 }
1721 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
1722 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
1723 status = WLAN_STATUS_AKMP_NOT_VALID;
1724 goto err;
1725 }
1726 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
1727 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
1728 MACSTR, MAC2STR(peer));
1729 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1730 goto err;
1731 }
1732 status = owe_validate_request(hapd, peer, elems.rsn_ie,
1733 elems.rsn_ie_len,
1734 elems.owe_dh, elems.owe_dh_len);
1735 if (status != WLAN_STATUS_SUCCESS)
1736 goto err;
1737
1738 sta = ap_get_sta(hapd, peer);
1739 if (sta) {
1740 ap_sta_no_session_timeout(hapd, sta);
1741 accounting_sta_stop(hapd, sta);
1742
1743 /*
1744 * Make sure that the previously registered inactivity timer
1745 * will not remove the STA immediately.
1746 */
1747 sta->timeout_next = STA_NULLFUNC;
1748 } else {
1749 sta = ap_sta_add(hapd, peer);
1750 if (!sta) {
1751 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1752 goto err;
1753 }
1754 }
1755 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1756
1757 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
1758 elems.rsn_ie_len, elems.owe_dh,
1759 elems.owe_dh_len);
1760 if (status != WLAN_STATUS_SUCCESS)
1761 ap_free_sta(hapd, sta);
1762
1763 return 0;
1764err:
1765 hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0);
1766 return 0;
1767}
1768#endif /* CONFIG_OWE */
1769
1770
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001771void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1772 union wpa_event_data *data)
1773{
1774 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001775#ifndef CONFIG_NO_STDOUT_DEBUG
1776 int level = MSG_DEBUG;
1777
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001778 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001779 data->rx_mgmt.frame_len >= 24) {
1780 const struct ieee80211_hdr *hdr;
1781 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001782
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001783 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1784 fc = le_to_host16(hdr->frame_control);
1785 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1786 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1787 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001788 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1789 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1790 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001791 }
1792
1793 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1794 event_to_string(event), event);
1795#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001796
1797 switch (event) {
1798 case EVENT_MICHAEL_MIC_FAILURE:
1799 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1800 break;
1801 case EVENT_SCAN_RESULTS:
1802 if (hapd->iface->scan_cb)
1803 hapd->iface->scan_cb(hapd->iface);
1804 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001805 case EVENT_WPS_BUTTON_PUSHED:
1806 hostapd_wps_button_pushed(hapd, NULL);
1807 break;
1808#ifdef NEED_AP_MLME
1809 case EVENT_TX_STATUS:
1810 switch (data->tx_status.type) {
1811 case WLAN_FC_TYPE_MGMT:
1812 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1813 data->tx_status.data_len,
1814 data->tx_status.stype,
1815 data->tx_status.ack);
1816 break;
1817 case WLAN_FC_TYPE_DATA:
1818 hostapd_tx_status(hapd, data->tx_status.dst,
1819 data->tx_status.data,
1820 data->tx_status.data_len,
1821 data->tx_status.ack);
1822 break;
1823 }
1824 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001825 case EVENT_EAPOL_TX_STATUS:
1826 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1827 data->eapol_tx_status.data,
1828 data->eapol_tx_status.data_len,
1829 data->eapol_tx_status.ack);
1830 break;
1831 case EVENT_DRIVER_CLIENT_POLL_OK:
1832 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1833 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001834 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001835 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1836 data->rx_from_unknown.addr,
1837 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001838 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001839#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001840 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001841 if (!data->rx_mgmt.frame)
1842 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001843#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07001844 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
1845#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001846 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07001847#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001848 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001849 case EVENT_RX_PROBE_REQ:
1850 if (data->rx_probe_req.sa == NULL ||
1851 data->rx_probe_req.ie == NULL)
1852 break;
1853 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001854 data->rx_probe_req.da,
1855 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001856 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001857 data->rx_probe_req.ie_len,
1858 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001859 break;
1860 case EVENT_NEW_STA:
1861 hostapd_event_new_sta(hapd, data->new_sta.addr);
1862 break;
1863 case EVENT_EAPOL_RX:
1864 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1865 data->eapol_rx.data,
1866 data->eapol_rx.data_len);
1867 break;
1868 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001869 if (!data)
1870 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001871 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1872 data->assoc_info.req_ies,
1873 data->assoc_info.req_ies_len,
1874 data->assoc_info.reassoc);
1875 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001876#ifdef CONFIG_OWE
1877 case EVENT_UPDATE_DH:
1878 if (!data)
1879 return;
1880 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
1881 data->update_dh.ie,
1882 data->update_dh.ie_len);
1883 break;
1884#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001885 case EVENT_DISASSOC:
1886 if (data)
1887 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1888 break;
1889 case EVENT_DEAUTH:
1890 if (data)
1891 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1892 break;
1893 case EVENT_STATION_LOW_ACK:
1894 if (!data)
1895 break;
1896 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1897 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001898 case EVENT_AUTH:
1899 hostapd_notif_auth(hapd, &data->auth);
1900 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001901 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07001902 case EVENT_CH_SWITCH:
1903 if (!data)
1904 break;
1905 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1906 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001907 data->ch_switch.ch_offset,
1908 data->ch_switch.ch_width,
1909 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07001910 data->ch_switch.cf2,
1911 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001912 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001913 case EVENT_CONNECT_FAILED_REASON:
1914 if (!data)
1915 break;
1916 hostapd_event_connect_failed_reason(
1917 hapd, data->connect_failed_reason.addr,
1918 data->connect_failed_reason.code);
1919 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001920 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001921 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001922 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001923#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001924 case EVENT_INTERFACE_UNAVAILABLE:
1925 hostapd_event_iface_unavailable(hapd);
1926 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001927 case EVENT_DFS_RADAR_DETECTED:
1928 if (!data)
1929 break;
1930 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1931 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001932 case EVENT_DFS_PRE_CAC_EXPIRED:
1933 if (!data)
1934 break;
1935 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1936 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001937 case EVENT_DFS_CAC_FINISHED:
1938 if (!data)
1939 break;
1940 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1941 break;
1942 case EVENT_DFS_CAC_ABORTED:
1943 if (!data)
1944 break;
1945 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1946 break;
1947 case EVENT_DFS_NOP_FINISHED:
1948 if (!data)
1949 break;
1950 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1951 break;
1952 case EVENT_CHANNEL_LIST_CHANGED:
1953 /* channel list changed (regulatory?), update channel list */
1954 /* TODO: check this. hostapd_get_hw_features() initializes
1955 * too much stuff. */
1956 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001957 hostapd_channel_list_updated(
1958 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001959 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001960 case EVENT_DFS_CAC_STARTED:
1961 if (!data)
1962 break;
1963 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1964 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001965#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001966 case EVENT_INTERFACE_ENABLED:
1967 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001968 if (hapd->disabled && hapd->started) {
1969 hapd->disabled = 0;
1970 /*
1971 * Try to re-enable interface if the driver stopped it
1972 * when the interface got disabled.
1973 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07001974 if (hapd->wpa_auth)
1975 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1976 else
1977 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001978 hapd->reenable_beacon = 1;
1979 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08001980#ifdef NEED_AP_MLME
1981 } else if (hapd->disabled && hapd->iface->cac_started) {
1982 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
1983 hostapd_handle_dfs(hapd->iface);
1984#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001985 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001986 break;
1987 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001988 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001989 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001990 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001991 break;
1992#ifdef CONFIG_ACS
1993 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001994 hostapd_acs_channel_selected(hapd,
1995 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001996 break;
1997#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001998 case EVENT_STATION_OPMODE_CHANGED:
1999 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2000 data->sta_opmode.smps_mode,
2001 data->sta_opmode.chan_width,
2002 data->sta_opmode.rx_nss);
2003 break;
2004 case EVENT_WDS_STA_INTERFACE_STATUS:
2005 hostapd_event_wds_sta_interface_status(
2006 hapd, data->wds_sta_interface.istatus,
2007 data->wds_sta_interface.ifname,
2008 data->wds_sta_interface.sta_addr);
2009 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002010 default:
2011 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2012 break;
2013 }
2014}
2015
Dmitry Shmidte4663042016-04-04 10:07:49 -07002016
2017void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2018 union wpa_event_data *data)
2019{
2020 struct hapd_interfaces *interfaces = ctx;
2021 struct hostapd_data *hapd;
2022
2023 if (event != EVENT_INTERFACE_STATUS)
2024 return;
2025
2026 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2027 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2028 hapd->drv_priv) {
2029 unsigned int ifindex;
2030
2031 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2032 if (ifindex != data->interface_status.ifindex) {
2033 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2034 "interface status ifindex %d mismatch (%d)",
2035 ifindex, data->interface_status.ifindex);
2036 return;
2037 }
2038 }
2039 if (hapd)
2040 wpa_supplicant_event(hapd, event, data);
2041}
2042
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002043#endif /* HOSTAPD */