blob: 3198bd563b0c572893a507a5e0e7532062eae207 [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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070020#include "crypto/random.h"
21#include "p2p/p2p.h"
22#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080023#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070024#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070025#include "hostapd.h"
26#include "ieee802_11.h"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080027#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "sta_info.h"
29#include "accounting.h"
30#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070031#include "ieee802_1x.h"
32#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033#include "wps_hostapd.h"
34#include "ap_drv_ops.h"
35#include "ap_config.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070036#include "ap_mlme.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070037#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070038#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070039#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080040#include "mbo_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070041#include "dpp_hostapd.h"
42#include "fils_hlp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080043#include "neighbor_db.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070044
45
46#ifdef CONFIG_FILS
47void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
48 struct sta_info *sta)
49{
50 u16 reply_res = WLAN_STATUS_SUCCESS;
51 struct ieee802_11_elems elems;
52 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
53 int new_assoc;
54
55 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
56 __func__, MAC2STR(sta->addr));
57 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
58 if (!sta->fils_pending_assoc_req)
59 return;
60
61 ieee802_11_parse_elems(sta->fils_pending_assoc_req,
62 sta->fils_pending_assoc_req_len, &elems, 0);
63 if (!elems.fils_session) {
64 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
65 __func__);
66 return;
67 }
68
69 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
70 elems.fils_session,
71 sta->fils_hlp_resp);
72
73 reply_res = hostapd_sta_assoc(hapd, sta->addr,
74 sta->fils_pending_assoc_is_reassoc,
75 WLAN_STATUS_SUCCESS,
76 buf, p - buf);
77 ap_sta_set_authorized(hapd, sta, 1);
78 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
79 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
80 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
81 hostapd_set_sta_flags(hapd, sta);
82 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
83 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
84 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
85 os_free(sta->fils_pending_assoc_req);
86 sta->fils_pending_assoc_req = NULL;
87 sta->fils_pending_assoc_req_len = 0;
88 wpabuf_free(sta->fils_hlp_resp);
89 sta->fils_hlp_resp = NULL;
90 wpabuf_free(sta->hlp_dhcp_discover);
91 sta->hlp_dhcp_discover = NULL;
92 fils_hlp_deinit(hapd);
93
94 /*
95 * Remove the station in case transmission of a success response fails
96 * (the STA was added associated to the driver) or if the station was
97 * previously added unassociated.
98 */
99 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
100 hostapd_drv_sta_remove(hapd, sta->addr);
101 sta->added_unassoc = 0;
102 }
103}
104#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700105
106
107int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800108 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109{
110 struct sta_info *sta;
111 int new_assoc, res;
112 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800113 const u8 *ie;
114 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700115 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
116 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800117 u16 reason = WLAN_REASON_UNSPECIFIED;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700118 u16 status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700119 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700120
121 if (addr == NULL) {
122 /*
123 * This could potentially happen with unexpected event from the
124 * driver wrapper. This was seen at least in one case where the
125 * driver ended up being set to station mode while hostapd was
126 * running, so better make sure we stop processing such an
127 * event here.
128 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800129 wpa_printf(MSG_DEBUG,
130 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131 return -1;
132 }
Hai Shalomc3565922019-10-28 11:58:20 -0700133
134 if (is_multicast_ether_addr(addr) ||
135 is_zero_ether_addr(addr) ||
136 os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) {
137 /* Do not process any frames with unexpected/invalid SA so that
138 * we do not add any state for unexpected STA addresses or end
139 * up sending out frames to unexpected destination. */
140 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
141 " in received indication - ignore this indication silently",
142 __func__, MAC2STR(addr));
143 return 0;
144 }
145
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700146 random_add_randomness(addr, ETH_ALEN);
147
148 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
149 HOSTAPD_LEVEL_INFO, "associated");
150
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800151 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700152 if (elems.wps_ie) {
153 ie = elems.wps_ie - 2;
154 ielen = elems.wps_ie_len + 2;
155 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
156 } else if (elems.rsn_ie) {
157 ie = elems.rsn_ie - 2;
158 ielen = elems.rsn_ie_len + 2;
159 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
160 } else if (elems.wpa_ie) {
161 ie = elems.wpa_ie - 2;
162 ielen = elems.wpa_ie_len + 2;
163 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800164#ifdef CONFIG_HS20
165 } else if (elems.osen) {
166 ie = elems.osen - 2;
167 ielen = elems.osen_len + 2;
168 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
169#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 } else {
171 ie = NULL;
172 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800173 wpa_printf(MSG_DEBUG,
174 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700175 }
176
177 sta = ap_get_sta(hapd, addr);
178 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700179 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700181
182 /*
183 * Make sure that the previously registered inactivity timer
184 * will not remove the STA immediately.
185 */
186 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700187 } else {
188 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700189 if (sta == NULL) {
190 hostapd_drv_sta_disassoc(hapd, addr,
191 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700193 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700194 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800195 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700196
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700197 /*
198 * ACL configurations to the drivers (implementing AP SME and ACL
199 * offload) without hostapd's knowledge, can result in a disconnection
200 * though the driver accepts the connection. Skip the hostapd check for
201 * ACL if the driver supports ACL offload to avoid potentially
202 * conflicting ACL rules.
203 */
204 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
205 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800206 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
207 MAC2STR(addr));
208 reason = WLAN_REASON_UNSPECIFIED;
209 goto fail;
210 }
211
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212#ifdef CONFIG_P2P
213 if (elems.p2p) {
214 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800215 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700216 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700217 if (sta->p2p_ie)
218 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 }
220#endif /* CONFIG_P2P */
221
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700222#ifdef CONFIG_IEEE80211N
223#ifdef NEED_AP_MLME
224 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700225 (hapd->iface->conf->ht_capab &
226 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
227 struct ieee80211_ht_capabilities *ht_cap =
228 (struct ieee80211_ht_capabilities *)
229 elems.ht_capabilities;
230
231 if (le_to_host16(ht_cap->ht_capabilities_info) &
232 HT_CAP_INFO_40MHZ_INTOLERANT)
233 ht40_intolerant_add(hapd->iface, sta);
234 }
235#endif /* NEED_AP_MLME */
236#endif /* CONFIG_IEEE80211N */
237
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);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700327 if (res != WPA_IE_OK) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800328 wpa_printf(MSG_DEBUG,
329 "WPA/RSN information element rejected? (res %u)",
330 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700331 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700332 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800333 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700334 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
335 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800336 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700337 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
338 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800339 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700340 status = WLAN_STATUS_AKMP_NOT_VALID;
Hai Shalomc3565922019-10-28 11:58:20 -0700341 } else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800342 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700343 status = WLAN_STATUS_INVALID_IE;
344 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700345 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
346 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
Hai Shalomc3565922019-10-28 11:58:20 -0700347 } else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800348 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700349 status = WLAN_STATUS_INVALID_IE;
350 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800351 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 }
Hai Shalomc3565922019-10-28 11:58:20 -0700353
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800354 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
355 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
356 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700357 sta->sa_query_count > 0)
358 ap_check_sa_query_timeout(hapd, sta);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800359 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
360 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
361 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700362 (sta->auth_alg != WLAN_AUTH_FT)) {
363 /*
364 * STA has already been associated with MFP and SA
365 * Query timeout has not been reached. Reject the
366 * association attempt temporarily and start SA Query,
367 * if one is not pending.
368 */
369
370 if (sta->sa_query_count == 0)
371 ap_sta_start_sa_query(hapd, sta);
372
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700373 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
374
375 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
376
377 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
378 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700379 return 0;
380 }
381
382 if (wpa_auth_uses_mfp(sta->wpa_sm))
383 sta->flags |= WLAN_STA_MFP;
384 else
385 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700386
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800387#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700388 if (sta->auth_alg == WLAN_AUTH_FT) {
389 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
390 req_ies_len);
391 if (status != WLAN_STATUS_SUCCESS) {
392 if (status == WLAN_STATUS_INVALID_PMKID)
393 reason = WLAN_REASON_INVALID_IE;
394 if (status == WLAN_STATUS_INVALID_MDIE)
395 reason = WLAN_REASON_INVALID_IE;
396 if (status == WLAN_STATUS_INVALID_FTIE)
397 reason = WLAN_REASON_INVALID_IE;
398 goto fail;
399 }
400 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800401#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700402#ifdef CONFIG_SAE
403 if (hapd->conf->sae_pwe == 2 &&
404 sta->auth_alg == WLAN_AUTH_SAE &&
405 sta->sae && sta->sae->tmp && !sta->sae->tmp->h2e &&
406 elems.rsnxe && elems.rsnxe_len >= 1 &&
407 (elems.rsnxe[0] & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
408 wpa_printf(MSG_INFO, "SAE: " MACSTR
409 " indicates support for SAE H2E, but did not use it",
410 MAC2STR(sta->addr));
411 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
412 reason = WLAN_REASON_UNSPECIFIED;
413 goto fail;
414 }
415#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700416 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800417#ifdef CONFIG_WPS
418 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800419
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420 if (req_ies)
421 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800423 else
424 wps = NULL;
425#ifdef CONFIG_WPS_STRICT
426 if (wps && wps_validate_assoc_req(wps) < 0) {
427 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700428 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700429 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800430 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700431 }
432#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800433 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700434 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800435 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800436 wpa_printf(MSG_DEBUG,
437 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800438 sta->flags |= WLAN_STA_WPS2;
439 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 } else
441 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800442 wpabuf_free(wps);
443#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800444#ifdef CONFIG_HS20
445 } else if (hapd->conf->osen) {
446 if (elems.osen == NULL) {
447 hostapd_logger(
448 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
449 HOSTAPD_LEVEL_INFO,
450 "No HS 2.0 OSEN element in association request");
451 return WLAN_STATUS_INVALID_IE;
452 }
453
454 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
455 if (sta->wpa_sm == NULL)
456 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
457 sta->addr, NULL);
458 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800459 wpa_printf(MSG_WARNING,
460 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800461 return WLAN_STATUS_UNSPECIFIED_FAILURE;
462 }
463 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
464 elems.osen - 2, elems.osen_len + 2) < 0)
465 return WLAN_STATUS_INVALID_IE;
466#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700467 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800468
469#ifdef CONFIG_MBO
470 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
471 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
472 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
473 wpa_printf(MSG_INFO,
474 "MBO: Reject WPA2 association without PMF");
475 return WLAN_STATUS_UNSPECIFIED_FAILURE;
476 }
477#endif /* CONFIG_MBO */
478
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800479#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700480skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800481#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700482
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800483#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700484 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
485 sta->auth_alg, req_ies, req_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700486 if (!p) {
487 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
488 return WLAN_STATUS_UNSPECIFIED_FAILURE;
489 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700490#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700491
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700492#ifdef CONFIG_FILS
493 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
494 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
495 sta->auth_alg == WLAN_AUTH_FILS_PK) {
496 int delay_assoc = 0;
497
498 if (!req_ies)
499 return WLAN_STATUS_UNSPECIFIED_FAILURE;
500
501 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
502 req_ies_len,
503 sta->fils_session)) {
504 wpa_printf(MSG_DEBUG,
505 "FILS: Session validation failed");
506 return WLAN_STATUS_UNSPECIFIED_FAILURE;
507 }
508
509 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
510 req_ies_len);
511 if (res < 0) {
512 wpa_printf(MSG_DEBUG,
513 "FILS: Key Confirm validation failed");
514 return WLAN_STATUS_UNSPECIFIED_FAILURE;
515 }
516
517 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
518 wpa_printf(MSG_DEBUG,
519 "FILS: Delaying Assoc Response (HLP)");
520 delay_assoc = 1;
521 } else {
522 wpa_printf(MSG_DEBUG,
523 "FILS: Going ahead with Assoc Response (no HLP)");
524 }
525
526 if (sta) {
527 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
528 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
529 os_free(sta->fils_pending_assoc_req);
530 sta->fils_pending_assoc_req = NULL;
531 sta->fils_pending_assoc_req_len = 0;
532 wpabuf_free(sta->fils_hlp_resp);
533 sta->fils_hlp_resp = NULL;
534 sta->fils_drv_assoc_finish = 0;
535 }
536
537 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
538 u8 *req_tmp;
539
540 req_tmp = os_malloc(req_ies_len);
541 if (!req_tmp) {
542 wpa_printf(MSG_DEBUG,
543 "FILS: buffer allocation failed for assoc req");
544 goto fail;
545 }
546 os_memcpy(req_tmp, req_ies, req_ies_len);
547 sta->fils_pending_assoc_req = req_tmp;
548 sta->fils_pending_assoc_req_len = req_ies_len;
549 sta->fils_pending_assoc_is_reassoc = reassoc;
550 sta->fils_drv_assoc_finish = 1;
551 wpa_printf(MSG_DEBUG,
552 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
553 MACSTR, MAC2STR(sta->addr));
554 eloop_register_timeout(
555 0, hapd->conf->fils_hlp_wait_time * 1024,
556 fils_hlp_timeout, hapd, sta);
557 return 0;
558 }
559 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
560 elems.fils_session,
561 sta->fils_hlp_resp);
562 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
563 buf, p - buf);
564 }
565#endif /* CONFIG_FILS */
566
Roshan Pius3a1667e2018-07-03 15:17:14 -0700567#ifdef CONFIG_OWE
568 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
569 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
570 elems.owe_dh) {
571 u8 *npos;
572
573 npos = owe_assoc_req_process(hapd, sta,
574 elems.owe_dh, elems.owe_dh_len,
575 p, sizeof(buf) - (p - buf),
576 &reason);
577 if (npos)
578 p = npos;
579 if (!npos &&
580 reason == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
581 status = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
582 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
583 p - buf);
584 return 0;
585 }
586
587 if (!npos || reason != WLAN_STATUS_SUCCESS)
588 goto fail;
589 }
590#endif /* CONFIG_OWE */
591
Hai Shalom021b0b52019-04-10 11:17:58 -0700592#ifdef CONFIG_DPP2
593 dpp_pfs_free(sta->dpp_pfs);
594 sta->dpp_pfs = NULL;
595
596 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
597 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
598 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
599 elems.owe_dh) {
600 sta->dpp_pfs = dpp_pfs_init(
601 wpabuf_head(hapd->conf->dpp_netaccesskey),
602 wpabuf_len(hapd->conf->dpp_netaccesskey));
603 if (!sta->dpp_pfs) {
604 wpa_printf(MSG_DEBUG,
605 "DPP: Could not initialize PFS");
606 /* Try to continue without PFS */
607 goto pfs_fail;
608 }
609
610 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
611 elems.owe_dh_len) < 0) {
612 dpp_pfs_free(sta->dpp_pfs);
613 sta->dpp_pfs = NULL;
614 reason = WLAN_REASON_UNSPECIFIED;
615 goto fail;
616 }
617 }
618
619 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
620 sta->dpp_pfs->secret : NULL);
621 pfs_fail:
622#endif /* CONFIG_DPP2 */
623
Roshan Pius3a1667e2018-07-03 15:17:14 -0700624#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700625 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700626
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700627 if (sta->auth_alg == WLAN_AUTH_FT ||
628 sta->auth_alg == WLAN_AUTH_FILS_SK ||
629 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
630 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700631 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700632#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700633 /* Keep compiler silent about unused variables */
634 if (status) {
635 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700636#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700637
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700638 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
639 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800640 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700641
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700642 hostapd_set_sta_flags(hapd, sta);
643
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700644 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
645 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700646#ifdef CONFIG_FILS
647 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
648 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
649 sta->auth_alg == WLAN_AUTH_FILS_PK)
650 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
651#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700652 else
653 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700654
655 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
656
657 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
658
659#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800660 if (req_ies) {
661 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
662 req_ies, req_ies_len);
663 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664#endif /* CONFIG_P2P */
665
666 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800667
668fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800669#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700670 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800671#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800672 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
673 ap_free_sta(hapd, sta);
674 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700675}
676
677
678void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
679{
680 struct sta_info *sta;
681
682 if (addr == NULL) {
683 /*
684 * This could potentially happen with unexpected event from the
685 * driver wrapper. This was seen at least in one case where the
686 * driver ended up reporting a station mode event while hostapd
687 * was running, so better make sure we stop processing such an
688 * event here.
689 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800690 wpa_printf(MSG_DEBUG,
691 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700692 return;
693 }
694
695 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
696 HOSTAPD_LEVEL_INFO, "disassociated");
697
698 sta = ap_get_sta(hapd, addr);
699 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800700 wpa_printf(MSG_DEBUG,
701 "Disassociation notification for unknown STA "
702 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700703 return;
704 }
705
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800706 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700707 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700708 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
709 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
710 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
711 ap_free_sta(hapd, sta);
712}
713
714
715void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
716{
717 struct sta_info *sta = ap_get_sta(hapd, addr);
718
Roshan Pius3a1667e2018-07-03 15:17:14 -0700719 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700720 return;
721
722 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800723 HOSTAPD_LEVEL_INFO,
724 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700725 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800726 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727}
728
729
Roshan Pius3a1667e2018-07-03 15:17:14 -0700730void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
731 enum smps_mode smps_mode,
732 enum chan_width chan_width, u8 rx_nss)
733{
734 struct sta_info *sta = ap_get_sta(hapd, addr);
735 const char *txt;
736
737 if (!sta)
738 return;
739
740 switch (smps_mode) {
741 case SMPS_AUTOMATIC:
742 txt = "automatic";
743 break;
744 case SMPS_OFF:
745 txt = "off";
746 break;
747 case SMPS_DYNAMIC:
748 txt = "dynamic";
749 break;
750 case SMPS_STATIC:
751 txt = "static";
752 break;
753 default:
754 txt = NULL;
755 break;
756 }
757 if (txt) {
758 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
759 MACSTR " %s", MAC2STR(addr), txt);
760 }
761
762 switch (chan_width) {
763 case CHAN_WIDTH_20_NOHT:
764 txt = "20(no-HT)";
765 break;
766 case CHAN_WIDTH_20:
767 txt = "20";
768 break;
769 case CHAN_WIDTH_40:
770 txt = "40";
771 break;
772 case CHAN_WIDTH_80:
773 txt = "80";
774 break;
775 case CHAN_WIDTH_80P80:
776 txt = "80+80";
777 break;
778 case CHAN_WIDTH_160:
779 txt = "160";
780 break;
781 default:
782 txt = NULL;
783 break;
784 }
785 if (txt) {
786 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
787 MACSTR " %s", MAC2STR(addr), txt);
788 }
789
790 if (rx_nss != 0xff) {
791 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
792 MACSTR " %d", MAC2STR(addr), rx_nss);
793 }
794}
795
796
Dmitry Shmidt04949592012-07-19 12:16:46 -0700797void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -0700798 int offset, int width, int cf1, int cf2,
799 int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700800{
Hai Shalom74f70d42019-02-11 14:42:39 -0800801 /* TODO: If OCV is enabled deauth STAs that don't perform a SA Query */
802
Dmitry Shmidt04949592012-07-19 12:16:46 -0700803#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800804 int channel, chwidth, is_dfs;
805 u8 seg0_idx = 0, seg1_idx = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800806 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700807
808 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800809 HOSTAPD_LEVEL_INFO,
Hai Shalom81f62d82019-07-22 12:10:00 -0700810 "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
811 finished ? "had" : "starting",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700812 freq, ht, hapd->iconf->ch_switch_vht_config, offset,
813 width, channel_width_to_string(width), cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700814
Hai Shalom1dc4d202019-04-29 16:22:27 -0700815 if (!hapd->iface->current_mode) {
816 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
817 HOSTAPD_LEVEL_WARNING,
818 "ignore channel switch since the interface is not yet ready");
819 return;
820 }
821
Dmitry Shmidt04949592012-07-19 12:16:46 -0700822 hapd->iface->freq = freq;
823
824 channel = hostapd_hw_get_channel(hapd, freq);
825 if (!channel) {
826 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800827 HOSTAPD_LEVEL_WARNING,
828 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700829 return;
830 }
831
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800832 switch (width) {
833 case CHAN_WIDTH_80:
Hai Shalom81f62d82019-07-22 12:10:00 -0700834 chwidth = CHANWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800835 break;
836 case CHAN_WIDTH_80P80:
Hai Shalom81f62d82019-07-22 12:10:00 -0700837 chwidth = CHANWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800838 break;
839 case CHAN_WIDTH_160:
Hai Shalom81f62d82019-07-22 12:10:00 -0700840 chwidth = CHANWIDTH_160MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800841 break;
842 case CHAN_WIDTH_20_NOHT:
843 case CHAN_WIDTH_20:
844 case CHAN_WIDTH_40:
845 default:
Hai Shalom81f62d82019-07-22 12:10:00 -0700846 chwidth = CHANWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800847 break;
848 }
849
850 switch (hapd->iface->current_mode->mode) {
851 case HOSTAPD_MODE_IEEE80211A:
852 if (cf1 > 5000)
853 seg0_idx = (cf1 - 5000) / 5;
854 if (cf2 > 5000)
855 seg1_idx = (cf2 - 5000) / 5;
856 break;
857 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800858 ieee80211_freq_to_chan(cf1, &seg0_idx);
859 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800860 break;
861 }
862
Dmitry Shmidt04949592012-07-19 12:16:46 -0700863 hapd->iconf->channel = channel;
864 hapd->iconf->ieee80211n = ht;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700865 if (!ht) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800866 hapd->iconf->ieee80211ac = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700867 } else if (hapd->iconf->ch_switch_vht_config) {
868 /* CHAN_SWITCH VHT config */
869 if (hapd->iconf->ch_switch_vht_config &
870 CH_SWITCH_VHT_ENABLED)
871 hapd->iconf->ieee80211ac = 1;
872 else if (hapd->iconf->ch_switch_vht_config &
873 CH_SWITCH_VHT_DISABLED)
874 hapd->iconf->ieee80211ac = 0;
875 }
876 hapd->iconf->ch_switch_vht_config = 0;
877
Dmitry Shmidt04949592012-07-19 12:16:46 -0700878 hapd->iconf->secondary_channel = offset;
Hai Shalom81f62d82019-07-22 12:10:00 -0700879 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
880 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
881 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800882
Roshan Pius3a1667e2018-07-03 15:17:14 -0700883 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
884 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800885
Hai Shalom81f62d82019-07-22 12:10:00 -0700886 wpa_msg(hapd->msg_ctx, MSG_INFO,
887 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d",
888 finished ? WPA_EVENT_CHANNEL_SWITCH :
889 WPA_EVENT_CHANNEL_SWITCH_STARTED,
890 freq, ht, offset, channel_width_to_string(width),
891 cf1, cf2, is_dfs);
892 if (!finished)
893 return;
894
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700895 if (hapd->csa_in_progress &&
896 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800897 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700898 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800899
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800900 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
901 "freq=%d dfs=%d", freq, is_dfs);
902 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
903 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
904 "freq=%d dfs=%d", freq, is_dfs);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800905 }
Hai Shalom74f70d42019-02-11 14:42:39 -0800906
907 for (i = 0; i < hapd->iface->num_bss; i++)
908 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700909#endif /* NEED_AP_MLME */
910}
911
912
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800913void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
914 const u8 *addr, int reason_code)
915{
916 switch (reason_code) {
917 case MAX_CLIENT_REACHED:
918 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
919 MAC2STR(addr));
920 break;
921 case BLOCKED_CLIENT:
922 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
923 MAC2STR(addr));
924 break;
925 }
926}
927
928
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800929#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800930void hostapd_acs_channel_selected(struct hostapd_data *hapd,
931 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800932{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700933 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800934 int err = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800935
936 if (hapd->iconf->channel) {
937 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
938 hapd->iconf->channel);
939 return;
940 }
941
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700942 if (!hapd->iface->current_mode) {
943 for (i = 0; i < hapd->iface->num_hw_features; i++) {
944 struct hostapd_hw_modes *mode =
945 &hapd->iface->hw_features[i];
946
947 if (mode->mode == acs_res->hw_mode) {
948 hapd->iface->current_mode = mode;
949 break;
950 }
951 }
952 if (!hapd->iface->current_mode) {
953 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
954 HOSTAPD_LEVEL_WARNING,
955 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800956 err = 1;
957 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700958 }
959 }
960
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700961 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800962
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700963 if (!acs_res->pri_channel) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800964 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
965 HOSTAPD_LEVEL_WARNING,
966 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800967 err = 1;
968 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800969 }
970
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700971 hapd->iconf->channel = acs_res->pri_channel;
972 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800973
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700974 if (acs_res->sec_channel == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800975 hapd->iconf->secondary_channel = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700976 else if (acs_res->sec_channel < acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800977 hapd->iconf->secondary_channel = -1;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700978 else if (acs_res->sec_channel > acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800979 hapd->iconf->secondary_channel = 1;
980 else {
981 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800982 err = 1;
983 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800984 }
985
Hai Shalom81f62d82019-07-22 12:10:00 -0700986 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700987 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -0700988 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
989 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
990 hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_USE_HT);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700991 if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700992 hostapd_set_oper_centr_freq_seg0_idx(
993 hapd->iconf, acs_res->vht_seg0_center_ch);
994 hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700995 } else if (acs_res->ch_width == 160) {
996 if (acs_res->vht_seg1_center_ch == 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -0700997 hostapd_set_oper_centr_freq_seg0_idx(
998 hapd->iconf,
999 acs_res->vht_seg0_center_ch);
1000 hostapd_set_oper_chwidth(hapd->iconf,
1001 CHANWIDTH_160MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001002 } else {
Hai Shalom81f62d82019-07-22 12:10:00 -07001003 hostapd_set_oper_centr_freq_seg0_idx(
1004 hapd->iconf,
1005 acs_res->vht_seg0_center_ch);
1006 hostapd_set_oper_centr_freq_seg1_idx(
1007 hapd->iconf,
1008 acs_res->vht_seg1_center_ch);
1009 hostapd_set_oper_chwidth(hapd->iconf,
1010 CHANWIDTH_80P80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001011 }
1012 }
1013 }
1014
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001015out:
1016 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001017 if (ret) {
1018 wpa_printf(MSG_ERROR,
1019 "ACS: Possibly channel configuration is invalid");
1020 }
1021}
1022#endif /* CONFIG_ACS */
1023
1024
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001025int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001026 const u8 *bssid, const u8 *ie, size_t ie_len,
1027 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001028{
1029 size_t i;
1030 int ret = 0;
1031
1032 if (sa == NULL || ie == NULL)
1033 return -1;
1034
1035 random_add_randomness(sa, ETH_ALEN);
1036 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1037 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001038 sa, da, bssid, ie, ie_len,
1039 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001040 ret = 1;
1041 break;
1042 }
1043 }
1044 return ret;
1045}
1046
1047
1048#ifdef HOSTAPD
1049
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001050#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001051static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1052 const u8 *bssid,
1053 u16 auth_transaction, u16 status,
1054 const u8 *ies, size_t ies_len)
1055{
1056 struct hostapd_data *hapd = ctx;
1057 struct sta_info *sta;
1058
1059 sta = ap_get_sta(hapd, dst);
1060 if (sta == NULL)
1061 return;
1062
1063 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1064 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1065 sta->flags |= WLAN_STA_AUTH;
1066
1067 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1068}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001069#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001070
1071
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001072#ifdef CONFIG_FILS
1073static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1074 struct sta_info *sta, u16 resp,
1075 struct wpabuf *data, int pub)
1076{
1077 if (resp == WLAN_STATUS_SUCCESS) {
1078 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1079 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1080 sta->flags |= WLAN_STA_AUTH;
1081 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1082 sta->auth_alg = WLAN_AUTH_FILS_SK;
1083 mlme_authenticate_indication(hapd, sta);
1084 } else {
1085 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1086 HOSTAPD_LEVEL_DEBUG,
1087 "authentication failed (FILS)");
1088 }
1089
1090 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1091 data ? wpabuf_head(data) : NULL,
1092 data ? wpabuf_len(data) : 0);
1093 wpabuf_free(data);
1094}
1095#endif /* CONFIG_FILS */
1096
1097
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001098static void hostapd_notif_auth(struct hostapd_data *hapd,
1099 struct auth_info *rx_auth)
1100{
1101 struct sta_info *sta;
1102 u16 status = WLAN_STATUS_SUCCESS;
1103 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1104 size_t resp_ies_len = 0;
1105
1106 sta = ap_get_sta(hapd, rx_auth->peer);
1107 if (!sta) {
1108 sta = ap_sta_add(hapd, rx_auth->peer);
1109 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001110 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001111 goto fail;
1112 }
1113 }
1114 sta->flags &= ~WLAN_STA_PREAUTH;
1115 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001116#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001117 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1118 sta->auth_alg = WLAN_AUTH_FT;
1119 if (sta->wpa_sm == NULL)
1120 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001121 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001122 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001123 wpa_printf(MSG_DEBUG,
1124 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001125 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1126 goto fail;
1127 }
1128 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1129 rx_auth->auth_transaction, rx_auth->ies,
1130 rx_auth->ies_len,
1131 hostapd_notify_auth_ft_finish, hapd);
1132 return;
1133 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001134#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001135
1136#ifdef CONFIG_FILS
1137 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1138 sta->auth_alg = WLAN_AUTH_FILS_SK;
1139 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1140 rx_auth->auth_type, rx_auth->auth_transaction,
1141 rx_auth->status_code,
1142 hostapd_notify_auth_fils_finish);
1143 return;
1144 }
1145#endif /* CONFIG_FILS */
1146
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001147fail:
1148 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1149 status, resp_ies, resp_ies_len);
1150}
1151
1152
Hai Shalom021b0b52019-04-10 11:17:58 -07001153#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001154static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001155 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001156{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001157 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001158 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001159 size_t plen __maybe_unused;
1160 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001161 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001162
Hai Shalom74f70d42019-02-11 14:42:39 -08001163 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001164 return;
1165
Hai Shalom021b0b52019-04-10 11:17:58 -07001166 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001167
1168 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1169 fc = le_to_host16(mgmt->frame_control);
1170 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1171 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001172
Hai Shalom74f70d42019-02-11 14:42:39 -08001173 action = (u8 *) &mgmt->u.action.u;
1174 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1175 " da " MACSTR " plen %d",
1176 mgmt->u.action.category, *action,
1177 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001178
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001179 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001180 if (sta == NULL) {
1181 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1182 return;
1183 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001184#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001185 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001186 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1187 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001188 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001189#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001190 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001191 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001192 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001193 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001194#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001195 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1196 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001197 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001198 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001199#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001200#ifdef CONFIG_FST
1201 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1202 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1203 return;
1204 }
1205#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001206#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001207 if (plen >= 2 + 4 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001208 mgmt->u.action.u.vs_public_action.action ==
1209 WLAN_PA_VENDOR_SPECIFIC &&
1210 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1211 OUI_WFA &&
1212 mgmt->u.action.u.vs_public_action.variable[0] ==
1213 DPP_OUI_TYPE) {
1214 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001215
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001216 pos = mgmt->u.action.u.vs_public_action.oui;
1217 end = drv_mgmt->frame + drv_mgmt->frame_len;
1218 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1219 drv_mgmt->freq);
1220 return;
1221 }
1222#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001223}
Hai Shalom021b0b52019-04-10 11:17:58 -07001224#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001225
1226
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227#ifdef NEED_AP_MLME
1228
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1230
1231static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1232 const u8 *bssid)
1233{
1234 size_t i;
1235
1236 if (bssid == NULL)
1237 return NULL;
1238 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1239 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1240 return HAPD_BROADCAST;
1241
1242 for (i = 0; i < iface->num_bss; i++) {
1243 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1244 return iface->bss[i];
1245 }
1246
1247 return NULL;
1248}
1249
1250
1251static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001252 const u8 *bssid, const u8 *addr,
1253 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001254{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001255 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001256 if (hapd == NULL || hapd == HAPD_BROADCAST)
1257 return;
1258
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001259 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001260}
1261
1262
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001263static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001264{
1265 struct hostapd_iface *iface = hapd->iface;
1266 const struct ieee80211_hdr *hdr;
1267 const u8 *bssid;
1268 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001269 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001270
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001271#ifdef CONFIG_TESTING_OPTIONS
1272 if (hapd->ext_mgmt_frame_handling) {
1273 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1274 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001275
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001276 if (hex) {
1277 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1278 rx_mgmt->frame_len);
1279 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1280 os_free(hex);
1281 }
1282 return 1;
1283 }
1284#endif /* CONFIG_TESTING_OPTIONS */
1285
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001286 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1287 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1288 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001289 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001290
1291 hapd = get_hapd_bssid(iface, bssid);
1292 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001293 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001294
1295 /*
1296 * Drop frames to unknown BSSIDs except for Beacon frames which
1297 * could be used to update neighbor information.
1298 */
1299 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1300 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1301 hapd = iface->bss[0];
1302 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001303 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001304 }
1305
1306 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001307 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001308 fi.datarate = rx_mgmt->datarate;
1309 fi.ssi_signal = rx_mgmt->ssi_signal;
1310
1311 if (hapd == HAPD_BROADCAST) {
1312 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001313
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001314 ret = 0;
1315 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001316 /* if bss is set, driver will call this function for
1317 * each bss individually. */
1318 if (rx_mgmt->drv_priv &&
1319 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1320 continue;
1321
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001322 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1323 rx_mgmt->frame_len, &fi) > 0)
1324 ret = 1;
1325 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001326 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001327 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1328 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001329
1330 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001331
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001332 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001333}
1334
1335
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001336static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1337 size_t len, u16 stype, int ok)
1338{
1339 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001340 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001341
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001342 hdr = (struct ieee80211_hdr *) buf;
1343 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001344 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001345 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001346 if (hapd == HAPD_BROADCAST) {
1347 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1348 buf[24] != WLAN_ACTION_PUBLIC)
1349 return;
1350 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1351 if (!hapd || hapd == HAPD_BROADCAST)
1352 return;
1353 /*
1354 * Allow processing of TX status for a Public Action frame that
1355 * used wildcard BBSID.
1356 */
1357 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001358 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1359}
1360
1361#endif /* NEED_AP_MLME */
1362
1363
1364static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1365{
1366 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001367
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001368 if (sta)
1369 return 0;
1370
1371 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1372 " - adding a new STA", MAC2STR(addr));
1373 sta = ap_sta_add(hapd, addr);
1374 if (sta) {
1375 hostapd_new_assoc_sta(hapd, sta, 0);
1376 } else {
1377 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1378 MAC2STR(addr));
1379 return -1;
1380 }
1381
1382 return 0;
1383}
1384
1385
1386static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1387 const u8 *data, size_t data_len)
1388{
1389 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001390 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001391 size_t j;
1392
1393 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001394 sta = ap_get_sta(iface->bss[j], src);
1395 if (sta && sta->flags & WLAN_STA_ASSOC) {
1396 hapd = iface->bss[j];
1397 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001398 }
1399 }
1400
1401 ieee802_1x_receive(hapd, src, data, data_len);
1402}
1403
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001404#endif /* HOSTAPD */
1405
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001406
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001407static struct hostapd_channel_data * hostapd_get_mode_channel(
1408 struct hostapd_iface *iface, unsigned int freq)
1409{
1410 int i;
1411 struct hostapd_channel_data *chan;
1412
1413 for (i = 0; i < iface->current_mode->num_channels; i++) {
1414 chan = &iface->current_mode->channels[i];
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001415 if ((unsigned int) chan->freq == freq)
1416 return chan;
1417 }
1418
1419 return NULL;
1420}
1421
1422
1423static void hostapd_update_nf(struct hostapd_iface *iface,
1424 struct hostapd_channel_data *chan,
1425 struct freq_survey *survey)
1426{
1427 if (!iface->chans_surveyed) {
1428 chan->min_nf = survey->nf;
1429 iface->lowest_nf = survey->nf;
1430 } else {
1431 if (dl_list_empty(&chan->survey_list))
1432 chan->min_nf = survey->nf;
1433 else if (survey->nf < chan->min_nf)
1434 chan->min_nf = survey->nf;
1435 if (survey->nf < iface->lowest_nf)
1436 iface->lowest_nf = survey->nf;
1437 }
1438}
1439
1440
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001441static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1442 struct survey_results *survey_res)
1443{
1444 struct hostapd_channel_data *chan;
1445 struct freq_survey *survey;
1446 u64 divisor, dividend;
1447
1448 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1449 list);
1450 if (!survey || !survey->freq)
1451 return;
1452
1453 chan = hostapd_get_mode_channel(iface, survey->freq);
1454 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1455 return;
1456
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001457 wpa_printf(MSG_DEBUG,
1458 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001459 survey->freq,
1460 (unsigned long int) survey->channel_time,
1461 (unsigned long int) survey->channel_time_busy);
1462
1463 if (survey->channel_time > iface->last_channel_time &&
1464 survey->channel_time > survey->channel_time_busy) {
1465 dividend = survey->channel_time_busy -
1466 iface->last_channel_time_busy;
1467 divisor = survey->channel_time - iface->last_channel_time;
1468
1469 iface->channel_utilization = dividend * 255 / divisor;
1470 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1471 iface->channel_utilization);
1472 }
1473 iface->last_channel_time = survey->channel_time;
1474 iface->last_channel_time_busy = survey->channel_time_busy;
1475}
1476
1477
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001478void hostapd_event_get_survey(struct hostapd_iface *iface,
1479 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001480{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001481 struct freq_survey *survey, *tmp;
1482 struct hostapd_channel_data *chan;
1483
1484 if (dl_list_empty(&survey_results->survey_list)) {
1485 wpa_printf(MSG_DEBUG, "No survey data received");
1486 return;
1487 }
1488
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001489 if (survey_results->freq_filter) {
1490 hostapd_single_channel_get_survey(iface, survey_results);
1491 return;
1492 }
1493
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001494 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1495 struct freq_survey, list) {
1496 chan = hostapd_get_mode_channel(iface, survey->freq);
1497 if (!chan)
1498 continue;
1499 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1500 continue;
1501
1502 dl_list_del(&survey->list);
1503 dl_list_add_tail(&chan->survey_list, &survey->list);
1504
1505 hostapd_update_nf(iface, chan, survey);
1506
1507 iface->chans_surveyed++;
1508 }
1509}
1510
1511
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001512#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001513#ifdef NEED_AP_MLME
1514
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001515static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1516{
1517 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1518 hapd->conf->iface);
1519
1520 if (hapd->csa_in_progress) {
1521 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1522 hapd->conf->iface);
1523 hostapd_switch_channel_fallback(hapd->iface,
1524 &hapd->cs_freq_params);
1525 }
1526}
1527
1528
Dmitry Shmidt051af732013-10-22 13:52:46 -07001529static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1530 struct dfs_event *radar)
1531{
1532 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001533 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001534 radar->chan_offset, radar->chan_width,
1535 radar->cf1, radar->cf2);
1536}
1537
1538
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001539static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1540 struct dfs_event *radar)
1541{
1542 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1543 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1544 radar->chan_offset, radar->chan_width,
1545 radar->cf1, radar->cf2);
1546}
1547
1548
Dmitry Shmidt051af732013-10-22 13:52:46 -07001549static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1550 struct dfs_event *radar)
1551{
1552 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001553 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001554 radar->chan_offset, radar->chan_width,
1555 radar->cf1, radar->cf2);
1556}
1557
1558
1559static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1560 struct dfs_event *radar)
1561{
1562 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001563 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001564 radar->chan_offset, radar->chan_width,
1565 radar->cf1, radar->cf2);
1566}
1567
1568
1569static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1570 struct dfs_event *radar)
1571{
1572 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001573 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001574 radar->chan_offset, radar->chan_width,
1575 radar->cf1, radar->cf2);
1576}
1577
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001578
1579static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1580 struct dfs_event *radar)
1581{
1582 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1583 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1584 radar->chan_offset, radar->chan_width,
1585 radar->cf1, radar->cf2);
1586}
1587
Dmitry Shmidt051af732013-10-22 13:52:46 -07001588#endif /* NEED_AP_MLME */
1589
1590
Roshan Pius3a1667e2018-07-03 15:17:14 -07001591static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1592 int istatus,
1593 const char *ifname,
1594 const u8 *addr)
1595{
1596 struct sta_info *sta = ap_get_sta(hapd, addr);
1597
1598 if (sta) {
1599 os_free(sta->ifname_wds);
1600 if (istatus == INTERFACE_ADDED)
1601 sta->ifname_wds = os_strdup(ifname);
1602 else
1603 sta->ifname_wds = NULL;
1604 }
1605
1606 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1607 istatus == INTERFACE_ADDED ?
1608 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1609 ifname, MAC2STR(addr));
1610}
1611
1612
Hai Shalom81f62d82019-07-22 12:10:00 -07001613#ifdef CONFIG_OWE
1614static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
1615 const u8 *peer, const u8 *ie,
1616 size_t ie_len)
1617{
1618 u16 status;
1619 struct sta_info *sta;
1620 struct ieee802_11_elems elems;
1621
1622 if (!hapd || !hapd->wpa_auth) {
1623 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
1624 return -1;
1625 }
1626 if (!peer) {
1627 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
1628 return -1;
1629 }
1630 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
1631 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
1632 status = WLAN_STATUS_AKMP_NOT_VALID;
1633 goto err;
1634 }
1635 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
1636 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
1637 MACSTR, MAC2STR(peer));
1638 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1639 goto err;
1640 }
1641 status = owe_validate_request(hapd, peer, elems.rsn_ie,
1642 elems.rsn_ie_len,
1643 elems.owe_dh, elems.owe_dh_len);
1644 if (status != WLAN_STATUS_SUCCESS)
1645 goto err;
1646
1647 sta = ap_get_sta(hapd, peer);
1648 if (sta) {
1649 ap_sta_no_session_timeout(hapd, sta);
1650 accounting_sta_stop(hapd, sta);
1651
1652 /*
1653 * Make sure that the previously registered inactivity timer
1654 * will not remove the STA immediately.
1655 */
1656 sta->timeout_next = STA_NULLFUNC;
1657 } else {
1658 sta = ap_sta_add(hapd, peer);
1659 if (!sta) {
1660 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1661 goto err;
1662 }
1663 }
1664 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1665
1666 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
1667 elems.rsn_ie_len, elems.owe_dh,
1668 elems.owe_dh_len);
1669 if (status != WLAN_STATUS_SUCCESS)
1670 ap_free_sta(hapd, sta);
1671
1672 return 0;
1673err:
1674 hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0);
1675 return 0;
1676}
1677#endif /* CONFIG_OWE */
1678
1679
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001680void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1681 union wpa_event_data *data)
1682{
1683 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001684#ifndef CONFIG_NO_STDOUT_DEBUG
1685 int level = MSG_DEBUG;
1686
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001687 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001688 data->rx_mgmt.frame_len >= 24) {
1689 const struct ieee80211_hdr *hdr;
1690 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001691
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001692 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1693 fc = le_to_host16(hdr->frame_control);
1694 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1695 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1696 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001697 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1698 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1699 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001700 }
1701
1702 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1703 event_to_string(event), event);
1704#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001705
1706 switch (event) {
1707 case EVENT_MICHAEL_MIC_FAILURE:
1708 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1709 break;
1710 case EVENT_SCAN_RESULTS:
1711 if (hapd->iface->scan_cb)
1712 hapd->iface->scan_cb(hapd->iface);
1713 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001714 case EVENT_WPS_BUTTON_PUSHED:
1715 hostapd_wps_button_pushed(hapd, NULL);
1716 break;
1717#ifdef NEED_AP_MLME
1718 case EVENT_TX_STATUS:
1719 switch (data->tx_status.type) {
1720 case WLAN_FC_TYPE_MGMT:
1721 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1722 data->tx_status.data_len,
1723 data->tx_status.stype,
1724 data->tx_status.ack);
1725 break;
1726 case WLAN_FC_TYPE_DATA:
1727 hostapd_tx_status(hapd, data->tx_status.dst,
1728 data->tx_status.data,
1729 data->tx_status.data_len,
1730 data->tx_status.ack);
1731 break;
1732 }
1733 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001734 case EVENT_EAPOL_TX_STATUS:
1735 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1736 data->eapol_tx_status.data,
1737 data->eapol_tx_status.data_len,
1738 data->eapol_tx_status.ack);
1739 break;
1740 case EVENT_DRIVER_CLIENT_POLL_OK:
1741 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1742 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001743 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001744 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1745 data->rx_from_unknown.addr,
1746 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001747 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001748#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001749 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001750 if (!data->rx_mgmt.frame)
1751 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001752#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07001753 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
1754#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001755 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07001756#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001757 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001758 case EVENT_RX_PROBE_REQ:
1759 if (data->rx_probe_req.sa == NULL ||
1760 data->rx_probe_req.ie == NULL)
1761 break;
1762 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001763 data->rx_probe_req.da,
1764 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001765 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001766 data->rx_probe_req.ie_len,
1767 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001768 break;
1769 case EVENT_NEW_STA:
1770 hostapd_event_new_sta(hapd, data->new_sta.addr);
1771 break;
1772 case EVENT_EAPOL_RX:
1773 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1774 data->eapol_rx.data,
1775 data->eapol_rx.data_len);
1776 break;
1777 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001778 if (!data)
1779 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001780 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1781 data->assoc_info.req_ies,
1782 data->assoc_info.req_ies_len,
1783 data->assoc_info.reassoc);
1784 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001785#ifdef CONFIG_OWE
1786 case EVENT_UPDATE_DH:
1787 if (!data)
1788 return;
1789 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
1790 data->update_dh.ie,
1791 data->update_dh.ie_len);
1792 break;
1793#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001794 case EVENT_DISASSOC:
1795 if (data)
1796 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1797 break;
1798 case EVENT_DEAUTH:
1799 if (data)
1800 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1801 break;
1802 case EVENT_STATION_LOW_ACK:
1803 if (!data)
1804 break;
1805 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1806 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001807 case EVENT_AUTH:
1808 hostapd_notif_auth(hapd, &data->auth);
1809 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001810 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07001811 case EVENT_CH_SWITCH:
1812 if (!data)
1813 break;
1814 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1815 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001816 data->ch_switch.ch_offset,
1817 data->ch_switch.ch_width,
1818 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07001819 data->ch_switch.cf2,
1820 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001821 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001822 case EVENT_CONNECT_FAILED_REASON:
1823 if (!data)
1824 break;
1825 hostapd_event_connect_failed_reason(
1826 hapd, data->connect_failed_reason.addr,
1827 data->connect_failed_reason.code);
1828 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001829 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001830 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001831 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001832#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001833 case EVENT_INTERFACE_UNAVAILABLE:
1834 hostapd_event_iface_unavailable(hapd);
1835 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001836 case EVENT_DFS_RADAR_DETECTED:
1837 if (!data)
1838 break;
1839 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1840 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001841 case EVENT_DFS_PRE_CAC_EXPIRED:
1842 if (!data)
1843 break;
1844 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1845 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001846 case EVENT_DFS_CAC_FINISHED:
1847 if (!data)
1848 break;
1849 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1850 break;
1851 case EVENT_DFS_CAC_ABORTED:
1852 if (!data)
1853 break;
1854 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1855 break;
1856 case EVENT_DFS_NOP_FINISHED:
1857 if (!data)
1858 break;
1859 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1860 break;
1861 case EVENT_CHANNEL_LIST_CHANGED:
1862 /* channel list changed (regulatory?), update channel list */
1863 /* TODO: check this. hostapd_get_hw_features() initializes
1864 * too much stuff. */
1865 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001866 hostapd_channel_list_updated(
1867 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001868 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001869 case EVENT_DFS_CAC_STARTED:
1870 if (!data)
1871 break;
1872 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1873 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001874#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001875 case EVENT_INTERFACE_ENABLED:
1876 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001877 if (hapd->disabled && hapd->started) {
1878 hapd->disabled = 0;
1879 /*
1880 * Try to re-enable interface if the driver stopped it
1881 * when the interface got disabled.
1882 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07001883 if (hapd->wpa_auth)
1884 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1885 else
1886 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001887 hapd->reenable_beacon = 1;
1888 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08001889#ifdef NEED_AP_MLME
1890 } else if (hapd->disabled && hapd->iface->cac_started) {
1891 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
1892 hostapd_handle_dfs(hapd->iface);
1893#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001894 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001895 break;
1896 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001897 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001898 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001899 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001900 break;
1901#ifdef CONFIG_ACS
1902 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001903 hostapd_acs_channel_selected(hapd,
1904 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001905 break;
1906#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001907 case EVENT_STATION_OPMODE_CHANGED:
1908 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
1909 data->sta_opmode.smps_mode,
1910 data->sta_opmode.chan_width,
1911 data->sta_opmode.rx_nss);
1912 break;
1913 case EVENT_WDS_STA_INTERFACE_STATUS:
1914 hostapd_event_wds_sta_interface_status(
1915 hapd, data->wds_sta_interface.istatus,
1916 data->wds_sta_interface.ifname,
1917 data->wds_sta_interface.sta_addr);
1918 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001919 default:
1920 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1921 break;
1922 }
1923}
1924
Dmitry Shmidte4663042016-04-04 10:07:49 -07001925
1926void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
1927 union wpa_event_data *data)
1928{
1929 struct hapd_interfaces *interfaces = ctx;
1930 struct hostapd_data *hapd;
1931
1932 if (event != EVENT_INTERFACE_STATUS)
1933 return;
1934
1935 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
1936 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
1937 hapd->drv_priv) {
1938 unsigned int ifindex;
1939
1940 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
1941 if (ifindex != data->interface_status.ifindex) {
1942 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1943 "interface status ifindex %d mismatch (%d)",
1944 ifindex, data->interface_status.ifindex);
1945 return;
1946 }
1947 }
1948 if (hapd)
1949 wpa_supplicant_event(hapd, event, data);
1950}
1951
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001952#endif /* HOSTAPD */