blob: 9af5445e28ffc78cee67b788e00c8654f9e3e146 [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
Hai Shalom899fcc72020-10-19 14:38:18 -0700108static bool check_sa_query_need(struct hostapd_data *hapd, struct sta_info *sta)
109{
110 if ((sta->flags &
111 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) !=
112 (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED))
113 return false;
114
115 if (!sta->sa_query_timed_out && sta->sa_query_count > 0)
116 ap_check_sa_query_timeout(hapd, sta);
117
118 if (!sta->sa_query_timed_out && (sta->auth_alg != WLAN_AUTH_FT)) {
119 /*
120 * STA has already been associated with MFP and SA Query timeout
121 * has not been reached. Reject the association attempt
122 * temporarily and start SA Query, if one is not pending.
123 */
124 if (sta->sa_query_count == 0)
125 ap_sta_start_sa_query(hapd, sta);
126
127 return true;
128 }
129
130 return false;
131}
132
133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800135 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700136{
137 struct sta_info *sta;
Hai Shalomfdcde762020-04-02 11:19:20 -0700138 int new_assoc;
139 enum wpa_validate_result res;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700140 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800141 const u8 *ie;
142 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700143 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
144 u8 *p = buf;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800145 u16 reason = WLAN_REASON_UNSPECIFIED;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700146 int status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700147 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700148
149 if (addr == NULL) {
150 /*
151 * This could potentially happen with unexpected event from the
152 * driver wrapper. This was seen at least in one case where the
153 * driver ended up being set to station mode while hostapd was
154 * running, so better make sure we stop processing such an
155 * event here.
156 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800157 wpa_printf(MSG_DEBUG,
158 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 return -1;
160 }
Hai Shalomc3565922019-10-28 11:58:20 -0700161
162 if (is_multicast_ether_addr(addr) ||
163 is_zero_ether_addr(addr) ||
164 os_memcmp(addr, hapd->own_addr, ETH_ALEN) == 0) {
165 /* Do not process any frames with unexpected/invalid SA so that
166 * we do not add any state for unexpected STA addresses or end
167 * up sending out frames to unexpected destination. */
168 wpa_printf(MSG_DEBUG, "%s: Invalid SA=" MACSTR
169 " in received indication - ignore this indication silently",
170 __func__, MAC2STR(addr));
171 return 0;
172 }
173
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174 random_add_randomness(addr, ETH_ALEN);
175
176 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
177 HOSTAPD_LEVEL_INFO, "associated");
178
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800179 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 if (elems.wps_ie) {
181 ie = elems.wps_ie - 2;
182 ielen = elems.wps_ie_len + 2;
183 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
184 } else if (elems.rsn_ie) {
185 ie = elems.rsn_ie - 2;
186 ielen = elems.rsn_ie_len + 2;
187 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
188 } else if (elems.wpa_ie) {
189 ie = elems.wpa_ie - 2;
190 ielen = elems.wpa_ie_len + 2;
191 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800192#ifdef CONFIG_HS20
193 } else if (elems.osen) {
194 ie = elems.osen - 2;
195 ielen = elems.osen_len + 2;
196 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
197#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 } else {
199 ie = NULL;
200 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800201 wpa_printf(MSG_DEBUG,
202 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 }
204
205 sta = ap_get_sta(hapd, addr);
206 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700207 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700209
210 /*
211 * Make sure that the previously registered inactivity timer
212 * will not remove the STA immediately.
213 */
214 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700215 } else {
216 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700217 if (sta == NULL) {
218 hostapd_drv_sta_disassoc(hapd, addr,
219 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700221 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800223 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700224
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700225 /*
226 * ACL configurations to the drivers (implementing AP SME and ACL
227 * offload) without hostapd's knowledge, can result in a disconnection
228 * though the driver accepts the connection. Skip the hostapd check for
229 * ACL if the driver supports ACL offload to avoid potentially
230 * conflicting ACL rules.
231 */
232 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
233 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800234 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
235 MAC2STR(addr));
236 reason = WLAN_REASON_UNSPECIFIED;
237 goto fail;
238 }
239
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240#ifdef CONFIG_P2P
241 if (elems.p2p) {
242 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800243 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700244 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700245 if (sta->p2p_ie)
246 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700247 }
248#endif /* CONFIG_P2P */
249
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700250#ifdef NEED_AP_MLME
251 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700252 (hapd->iface->conf->ht_capab &
253 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
254 struct ieee80211_ht_capabilities *ht_cap =
255 (struct ieee80211_ht_capabilities *)
256 elems.ht_capabilities;
257
258 if (le_to_host16(ht_cap->ht_capabilities_info) &
259 HT_CAP_INFO_40MHZ_INTOLERANT)
260 ht40_intolerant_add(hapd->iface, sta);
261 }
262#endif /* NEED_AP_MLME */
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700263
Dmitry Shmidt051af732013-10-22 13:52:46 -0700264#ifdef CONFIG_INTERWORKING
265 if (elems.ext_capab && elems.ext_capab_len > 4) {
266 if (elems.ext_capab[4] & 0x01)
267 sta->qos_map_enabled = 1;
268 }
269#endif /* CONFIG_INTERWORKING */
270
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800271#ifdef CONFIG_HS20
272 wpabuf_free(sta->hs20_ie);
273 if (elems.hs20 && elems.hs20_len > 4) {
274 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
275 elems.hs20_len - 4);
276 } else
277 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700278
279 wpabuf_free(sta->roaming_consortium);
280 if (elems.roaming_cons_sel)
281 sta->roaming_consortium = wpabuf_alloc_copy(
282 elems.roaming_cons_sel + 4,
283 elems.roaming_cons_sel_len - 4);
284 else
285 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800286#endif /* CONFIG_HS20 */
287
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800288#ifdef CONFIG_FST
289 wpabuf_free(sta->mb_ies);
290 if (hapd->iface->fst)
291 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
292 else
293 sta->mb_ies = NULL;
294#endif /* CONFIG_FST */
295
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800296 mbo_ap_check_sta_assoc(hapd, sta, &elems);
297
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800298 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
299 elems.supp_op_classes_len);
300
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 if (hapd->conf->wpa) {
302 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800303#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800305 wpa_printf(MSG_DEBUG,
306 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 sta->flags |= WLAN_STA_MAYBE_WPS;
308 goto skip_wpa_check;
309 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800310#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311
312 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700313 reason = WLAN_REASON_INVALID_IE;
314 status = WLAN_STATUS_INVALID_IE;
315 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800317#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700318 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
319 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800320 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800321
Hai Shalom899fcc72020-10-19 14:38:18 -0700322 if (check_sa_query_need(hapd, sta)) {
323 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
324
325 p = hostapd_eid_assoc_comeback_time(hapd, sta,
326 p);
327
328 hostapd_sta_assoc(hapd, addr, reassoc, status,
329 buf, p - buf);
330 return 0;
331 }
332
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800334 wps = ieee802_11_vendor_ie_concat(ie, ielen,
335 WPS_IE_VENDOR_TYPE);
336 if (wps) {
337 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800338 wpa_printf(MSG_DEBUG,
339 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800340 sta->flags |= WLAN_STA_WPS2;
341 }
342 wpabuf_free(wps);
343 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344 goto skip_wpa_check;
345 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800346#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347
348 if (sta->wpa_sm == NULL)
349 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700350 sta->addr,
351 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800353 wpa_printf(MSG_ERROR,
354 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700355 return -1;
356 }
357 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Hai Shalom021b0b52019-04-10 11:17:58 -0700358 hapd->iface->freq,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700359 ie, ielen,
Hai Shalomc3565922019-10-28 11:58:20 -0700360 elems.rsnxe ? elems.rsnxe - 2 : NULL,
361 elems.rsnxe ? elems.rsnxe_len + 2 : 0,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700362 elems.mdie, elems.mdie_len,
363 elems.owe_dh, elems.owe_dh_len);
Hai Shalomfdcde762020-04-02 11:19:20 -0700364 reason = WLAN_REASON_INVALID_IE;
365 status = WLAN_STATUS_INVALID_IE;
366 switch (res) {
367 case WPA_IE_OK:
368 reason = WLAN_REASON_UNSPECIFIED;
369 status = WLAN_STATUS_SUCCESS;
370 break;
371 case WPA_INVALID_IE:
372 reason = WLAN_REASON_INVALID_IE;
373 status = WLAN_STATUS_INVALID_IE;
374 break;
375 case WPA_INVALID_GROUP:
376 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
377 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
378 break;
379 case WPA_INVALID_PAIRWISE:
380 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
381 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
382 break;
383 case WPA_INVALID_AKMP:
384 reason = WLAN_REASON_AKMP_NOT_VALID;
385 status = WLAN_STATUS_AKMP_NOT_VALID;
386 break;
387 case WPA_NOT_ENABLED:
388 reason = WLAN_REASON_INVALID_IE;
389 status = WLAN_STATUS_INVALID_IE;
390 break;
391 case WPA_ALLOC_FAIL:
392 reason = WLAN_REASON_UNSPECIFIED;
393 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
394 break;
395 case WPA_MGMT_FRAME_PROTECTION_VIOLATION:
396 reason = WLAN_REASON_INVALID_IE;
397 status = WLAN_STATUS_INVALID_IE;
398 break;
399 case WPA_INVALID_MGMT_GROUP_CIPHER:
400 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
401 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
402 break;
403 case WPA_INVALID_MDIE:
404 reason = WLAN_REASON_INVALID_MDE;
405 status = WLAN_STATUS_INVALID_MDIE;
406 break;
407 case WPA_INVALID_PROTO:
408 reason = WLAN_REASON_INVALID_IE;
409 status = WLAN_STATUS_INVALID_IE;
410 break;
411 case WPA_INVALID_PMKID:
412 reason = WLAN_REASON_INVALID_PMKID;
413 status = WLAN_STATUS_INVALID_PMKID;
414 break;
415 case WPA_DENIED_OTHER_REASON:
416 reason = WLAN_REASON_UNSPECIFIED;
417 status = WLAN_STATUS_ASSOC_DENIED_UNSPEC;
418 break;
419 }
420 if (status != WLAN_STATUS_SUCCESS) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800421 wpa_printf(MSG_DEBUG,
422 "WPA/RSN information element rejected? (res %u)",
423 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700424 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800425 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700426 }
Hai Shalomc3565922019-10-28 11:58:20 -0700427
Hai Shalom899fcc72020-10-19 14:38:18 -0700428 if (check_sa_query_need(hapd, sta)) {
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700429 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
430
431 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
432
433 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
434 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700435 return 0;
436 }
437
438 if (wpa_auth_uses_mfp(sta->wpa_sm))
439 sta->flags |= WLAN_STA_MFP;
440 else
441 sta->flags &= ~WLAN_STA_MFP;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700442
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800443#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700444 if (sta->auth_alg == WLAN_AUTH_FT) {
445 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
446 req_ies_len);
447 if (status != WLAN_STATUS_SUCCESS) {
448 if (status == WLAN_STATUS_INVALID_PMKID)
449 reason = WLAN_REASON_INVALID_IE;
450 if (status == WLAN_STATUS_INVALID_MDIE)
451 reason = WLAN_REASON_INVALID_IE;
452 if (status == WLAN_STATUS_INVALID_FTIE)
453 reason = WLAN_REASON_INVALID_IE;
454 goto fail;
455 }
456 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800457#endif /* CONFIG_IEEE80211R_AP */
Hai Shalomc3565922019-10-28 11:58:20 -0700458#ifdef CONFIG_SAE
459 if (hapd->conf->sae_pwe == 2 &&
460 sta->auth_alg == WLAN_AUTH_SAE &&
Hai Shalom899fcc72020-10-19 14:38:18 -0700461 sta->sae && !sta->sae->h2e &&
Hai Shalomc3565922019-10-28 11:58:20 -0700462 elems.rsnxe && elems.rsnxe_len >= 1 &&
463 (elems.rsnxe[0] & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) {
464 wpa_printf(MSG_INFO, "SAE: " MACSTR
465 " indicates support for SAE H2E, but did not use it",
466 MAC2STR(sta->addr));
467 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
468 reason = WLAN_REASON_UNSPECIFIED;
469 goto fail;
470 }
471#endif /* CONFIG_SAE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700472 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800473#ifdef CONFIG_WPS
474 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800475
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800476 if (req_ies)
477 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700478 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800479 else
480 wps = NULL;
481#ifdef CONFIG_WPS_STRICT
482 if (wps && wps_validate_assoc_req(wps) < 0) {
483 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700484 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700485 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800486 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700487 }
488#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800489 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700490 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800491 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800492 wpa_printf(MSG_DEBUG,
493 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800494 sta->flags |= WLAN_STA_WPS2;
495 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700496 } else
497 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800498 wpabuf_free(wps);
499#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800500#ifdef CONFIG_HS20
501 } else if (hapd->conf->osen) {
502 if (elems.osen == NULL) {
503 hostapd_logger(
504 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
505 HOSTAPD_LEVEL_INFO,
506 "No HS 2.0 OSEN element in association request");
507 return WLAN_STATUS_INVALID_IE;
508 }
509
510 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
511 if (sta->wpa_sm == NULL)
512 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
513 sta->addr, NULL);
514 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800515 wpa_printf(MSG_WARNING,
516 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800517 return WLAN_STATUS_UNSPECIFIED_FAILURE;
518 }
519 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
520 elems.osen - 2, elems.osen_len + 2) < 0)
521 return WLAN_STATUS_INVALID_IE;
522#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700523 }
Hai Shalomfdcde762020-04-02 11:19:20 -0700524#ifdef CONFIG_WPS
525skip_wpa_check:
526#endif /* CONFIG_WPS */
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800527
528#ifdef CONFIG_MBO
529 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
530 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
531 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
532 wpa_printf(MSG_INFO,
533 "MBO: Reject WPA2 association without PMF");
534 return WLAN_STATUS_UNSPECIFIED_FAILURE;
535 }
536#endif /* CONFIG_MBO */
537
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800538#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700539 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
Hai Shalomfdcde762020-04-02 11:19:20 -0700540 sta->auth_alg, req_ies, req_ies_len,
541 !elems.rsnxe);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700542 if (!p) {
543 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
544 return WLAN_STATUS_UNSPECIFIED_FAILURE;
545 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700546#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700547
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700548#ifdef CONFIG_FILS
549 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
550 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
551 sta->auth_alg == WLAN_AUTH_FILS_PK) {
552 int delay_assoc = 0;
553
554 if (!req_ies)
555 return WLAN_STATUS_UNSPECIFIED_FAILURE;
556
557 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
558 req_ies_len,
559 sta->fils_session)) {
560 wpa_printf(MSG_DEBUG,
561 "FILS: Session validation failed");
562 return WLAN_STATUS_UNSPECIFIED_FAILURE;
563 }
564
565 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
566 req_ies_len);
567 if (res < 0) {
568 wpa_printf(MSG_DEBUG,
569 "FILS: Key Confirm validation failed");
570 return WLAN_STATUS_UNSPECIFIED_FAILURE;
571 }
572
573 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
574 wpa_printf(MSG_DEBUG,
575 "FILS: Delaying Assoc Response (HLP)");
576 delay_assoc = 1;
577 } else {
578 wpa_printf(MSG_DEBUG,
579 "FILS: Going ahead with Assoc Response (no HLP)");
580 }
581
582 if (sta) {
583 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
584 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
585 os_free(sta->fils_pending_assoc_req);
586 sta->fils_pending_assoc_req = NULL;
587 sta->fils_pending_assoc_req_len = 0;
588 wpabuf_free(sta->fils_hlp_resp);
589 sta->fils_hlp_resp = NULL;
590 sta->fils_drv_assoc_finish = 0;
591 }
592
593 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
594 u8 *req_tmp;
595
596 req_tmp = os_malloc(req_ies_len);
597 if (!req_tmp) {
598 wpa_printf(MSG_DEBUG,
599 "FILS: buffer allocation failed for assoc req");
600 goto fail;
601 }
602 os_memcpy(req_tmp, req_ies, req_ies_len);
603 sta->fils_pending_assoc_req = req_tmp;
604 sta->fils_pending_assoc_req_len = req_ies_len;
605 sta->fils_pending_assoc_is_reassoc = reassoc;
606 sta->fils_drv_assoc_finish = 1;
607 wpa_printf(MSG_DEBUG,
608 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
609 MACSTR, MAC2STR(sta->addr));
610 eloop_register_timeout(
611 0, hapd->conf->fils_hlp_wait_time * 1024,
612 fils_hlp_timeout, hapd, sta);
613 return 0;
614 }
615 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
616 elems.fils_session,
617 sta->fils_hlp_resp);
618 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
619 buf, p - buf);
620 }
621#endif /* CONFIG_FILS */
622
Roshan Pius3a1667e2018-07-03 15:17:14 -0700623#ifdef CONFIG_OWE
624 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
625 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
626 elems.owe_dh) {
627 u8 *npos;
Hai Shalomb755a2a2020-04-23 21:49:02 -0700628 u16 ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700629
630 npos = owe_assoc_req_process(hapd, sta,
631 elems.owe_dh, elems.owe_dh_len,
632 p, sizeof(buf) - (p - buf),
Hai Shalomb755a2a2020-04-23 21:49:02 -0700633 &ret_status);
634 status = ret_status;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700635 if (npos)
636 p = npos;
Hai Shalomfdcde762020-04-02 11:19:20 -0700637
Roshan Pius3a1667e2018-07-03 15:17:14 -0700638 if (!npos &&
Hai Shalomfdcde762020-04-02 11:19:20 -0700639 status == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
Hai Shalomb755a2a2020-04-23 21:49:02 -0700640 hostapd_sta_assoc(hapd, addr, reassoc, ret_status, buf,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700641 p - buf);
642 return 0;
643 }
644
Hai Shalomfdcde762020-04-02 11:19:20 -0700645 if (!npos || status != WLAN_STATUS_SUCCESS)
Roshan Pius3a1667e2018-07-03 15:17:14 -0700646 goto fail;
647 }
648#endif /* CONFIG_OWE */
649
Hai Shalom021b0b52019-04-10 11:17:58 -0700650#ifdef CONFIG_DPP2
651 dpp_pfs_free(sta->dpp_pfs);
652 sta->dpp_pfs = NULL;
653
654 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) &&
655 hapd->conf->dpp_netaccesskey && sta->wpa_sm &&
656 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP &&
657 elems.owe_dh) {
658 sta->dpp_pfs = dpp_pfs_init(
659 wpabuf_head(hapd->conf->dpp_netaccesskey),
660 wpabuf_len(hapd->conf->dpp_netaccesskey));
661 if (!sta->dpp_pfs) {
662 wpa_printf(MSG_DEBUG,
663 "DPP: Could not initialize PFS");
664 /* Try to continue without PFS */
665 goto pfs_fail;
666 }
667
668 if (dpp_pfs_process(sta->dpp_pfs, elems.owe_dh,
669 elems.owe_dh_len) < 0) {
670 dpp_pfs_free(sta->dpp_pfs);
671 sta->dpp_pfs = NULL;
672 reason = WLAN_REASON_UNSPECIFIED;
673 goto fail;
674 }
675 }
676
677 wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ?
678 sta->dpp_pfs->secret : NULL);
679 pfs_fail:
680#endif /* CONFIG_DPP2 */
681
Hai Shalomfdcde762020-04-02 11:19:20 -0700682 if (elems.rrm_enabled &&
683 elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa))
684 os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled,
685 sizeof(sta->rrm_enabled_capa));
686
Roshan Pius3a1667e2018-07-03 15:17:14 -0700687#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700688 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700689
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700690 if (sta->auth_alg == WLAN_AUTH_FT ||
691 sta->auth_alg == WLAN_AUTH_FILS_SK ||
692 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
693 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700694 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700695#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700696 /* Keep compiler silent about unused variables */
697 if (status) {
698 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700699#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700700
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700701 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
702 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800703 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700704
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700705 hostapd_set_sta_flags(hapd, sta);
706
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700707 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
708 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700709#ifdef CONFIG_FILS
710 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
711 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
712 sta->auth_alg == WLAN_AUTH_FILS_PK)
713 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
714#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700715 else
716 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700717
718 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
719
720 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
721
722#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800723 if (req_ies) {
724 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
725 req_ies, req_ies_len);
726 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700727#endif /* CONFIG_P2P */
728
729 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800730
731fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800732#ifdef CONFIG_IEEE80211R_AP
Hai Shalomb755a2a2020-04-23 21:49:02 -0700733 if (status >= 0)
734 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800735#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800736 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
737 ap_free_sta(hapd, sta);
738 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739}
740
741
742void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
743{
744 struct sta_info *sta;
745
746 if (addr == NULL) {
747 /*
748 * This could potentially happen with unexpected event from the
749 * driver wrapper. This was seen at least in one case where the
750 * driver ended up reporting a station mode event while hostapd
751 * was running, so better make sure we stop processing such an
752 * event here.
753 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800754 wpa_printf(MSG_DEBUG,
755 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700756 return;
757 }
758
759 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
760 HOSTAPD_LEVEL_INFO, "disassociated");
761
762 sta = ap_get_sta(hapd, addr);
763 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800764 wpa_printf(MSG_DEBUG,
765 "Disassociation notification for unknown STA "
766 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700767 return;
768 }
769
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800770 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700771 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Hai Shalomfdcde762020-04-02 11:19:20 -0700772 hostapd_set_sta_flags(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700773 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
774 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
775 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
776 ap_free_sta(hapd, sta);
777}
778
779
780void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
781{
782 struct sta_info *sta = ap_get_sta(hapd, addr);
783
Roshan Pius3a1667e2018-07-03 15:17:14 -0700784 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700785 return;
786
787 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800788 HOSTAPD_LEVEL_INFO,
789 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700790 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800791 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792}
793
794
Roshan Pius3a1667e2018-07-03 15:17:14 -0700795void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
796 enum smps_mode smps_mode,
797 enum chan_width chan_width, u8 rx_nss)
798{
799 struct sta_info *sta = ap_get_sta(hapd, addr);
800 const char *txt;
801
802 if (!sta)
803 return;
804
805 switch (smps_mode) {
806 case SMPS_AUTOMATIC:
807 txt = "automatic";
808 break;
809 case SMPS_OFF:
810 txt = "off";
811 break;
812 case SMPS_DYNAMIC:
813 txt = "dynamic";
814 break;
815 case SMPS_STATIC:
816 txt = "static";
817 break;
818 default:
819 txt = NULL;
820 break;
821 }
822 if (txt) {
823 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
824 MACSTR " %s", MAC2STR(addr), txt);
825 }
826
827 switch (chan_width) {
828 case CHAN_WIDTH_20_NOHT:
829 txt = "20(no-HT)";
830 break;
831 case CHAN_WIDTH_20:
832 txt = "20";
833 break;
834 case CHAN_WIDTH_40:
835 txt = "40";
836 break;
837 case CHAN_WIDTH_80:
838 txt = "80";
839 break;
840 case CHAN_WIDTH_80P80:
841 txt = "80+80";
842 break;
843 case CHAN_WIDTH_160:
844 txt = "160";
845 break;
846 default:
847 txt = NULL;
848 break;
849 }
850 if (txt) {
851 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
852 MACSTR " %s", MAC2STR(addr), txt);
853 }
854
855 if (rx_nss != 0xff) {
856 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
857 MACSTR " %d", MAC2STR(addr), rx_nss);
858 }
859}
860
861
Dmitry Shmidt04949592012-07-19 12:16:46 -0700862void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Hai Shalom81f62d82019-07-22 12:10:00 -0700863 int offset, int width, int cf1, int cf2,
864 int finished)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700865{
866#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800867 int channel, chwidth, is_dfs;
868 u8 seg0_idx = 0, seg1_idx = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800869 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700870
871 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800872 HOSTAPD_LEVEL_INFO,
Hai Shalom81f62d82019-07-22 12:10:00 -0700873 "driver %s channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
874 finished ? "had" : "starting",
Roshan Pius3a1667e2018-07-03 15:17:14 -0700875 freq, ht, hapd->iconf->ch_switch_vht_config, offset,
876 width, channel_width_to_string(width), cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700877
Hai Shalom1dc4d202019-04-29 16:22:27 -0700878 if (!hapd->iface->current_mode) {
879 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
880 HOSTAPD_LEVEL_WARNING,
881 "ignore channel switch since the interface is not yet ready");
882 return;
883 }
884
Dmitry Shmidt04949592012-07-19 12:16:46 -0700885 hapd->iface->freq = freq;
886
887 channel = hostapd_hw_get_channel(hapd, freq);
888 if (!channel) {
889 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800890 HOSTAPD_LEVEL_WARNING,
891 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700892 return;
893 }
894
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800895 switch (width) {
896 case CHAN_WIDTH_80:
Hai Shalom81f62d82019-07-22 12:10:00 -0700897 chwidth = CHANWIDTH_80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800898 break;
899 case CHAN_WIDTH_80P80:
Hai Shalom81f62d82019-07-22 12:10:00 -0700900 chwidth = CHANWIDTH_80P80MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800901 break;
902 case CHAN_WIDTH_160:
Hai Shalom81f62d82019-07-22 12:10:00 -0700903 chwidth = CHANWIDTH_160MHZ;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800904 break;
905 case CHAN_WIDTH_20_NOHT:
906 case CHAN_WIDTH_20:
907 case CHAN_WIDTH_40:
908 default:
Hai Shalom81f62d82019-07-22 12:10:00 -0700909 chwidth = CHANWIDTH_USE_HT;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800910 break;
911 }
912
913 switch (hapd->iface->current_mode->mode) {
914 case HOSTAPD_MODE_IEEE80211A:
Hai Shalom899fcc72020-10-19 14:38:18 -0700915 if (cf1 == 5935)
916 seg0_idx = (cf1 - 5925) / 5;
917 else if (cf1 > 5950)
918 seg0_idx = (cf1 - 5950) / 5;
919 else if (cf1 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800920 seg0_idx = (cf1 - 5000) / 5;
Hai Shalom899fcc72020-10-19 14:38:18 -0700921
922 if (cf2 == 5935)
923 seg1_idx = (cf2 - 5925) / 5;
924 else if (cf2 > 5950)
925 seg1_idx = (cf2 - 5950) / 5;
926 else if (cf2 > 5000)
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800927 seg1_idx = (cf2 - 5000) / 5;
928 break;
929 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800930 ieee80211_freq_to_chan(cf1, &seg0_idx);
931 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800932 break;
933 }
934
Dmitry Shmidt04949592012-07-19 12:16:46 -0700935 hapd->iconf->channel = channel;
936 hapd->iconf->ieee80211n = ht;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700937 if (!ht) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800938 hapd->iconf->ieee80211ac = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700939 } else if (hapd->iconf->ch_switch_vht_config) {
940 /* CHAN_SWITCH VHT config */
941 if (hapd->iconf->ch_switch_vht_config &
942 CH_SWITCH_VHT_ENABLED)
943 hapd->iconf->ieee80211ac = 1;
944 else if (hapd->iconf->ch_switch_vht_config &
945 CH_SWITCH_VHT_DISABLED)
946 hapd->iconf->ieee80211ac = 0;
947 }
948 hapd->iconf->ch_switch_vht_config = 0;
949
Dmitry Shmidt04949592012-07-19 12:16:46 -0700950 hapd->iconf->secondary_channel = offset;
Hai Shalom81f62d82019-07-22 12:10:00 -0700951 hostapd_set_oper_chwidth(hapd->iconf, chwidth);
952 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, seg0_idx);
953 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, seg1_idx);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800954
Roshan Pius3a1667e2018-07-03 15:17:14 -0700955 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
956 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800957
Hai Shalom81f62d82019-07-22 12:10:00 -0700958 wpa_msg(hapd->msg_ctx, MSG_INFO,
959 "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d dfs=%d",
960 finished ? WPA_EVENT_CHANNEL_SWITCH :
961 WPA_EVENT_CHANNEL_SWITCH_STARTED,
962 freq, ht, offset, channel_width_to_string(width),
963 cf1, cf2, is_dfs);
964 if (!finished)
965 return;
966
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700967 if (hapd->csa_in_progress &&
968 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800969 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700970 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800971
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800972 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
973 "freq=%d dfs=%d", freq, is_dfs);
974 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
975 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
976 "freq=%d dfs=%d", freq, is_dfs);
Hai Shalomfdcde762020-04-02 11:19:20 -0700977 } else if (is_dfs &&
978 hostapd_is_dfs_required(hapd->iface) &&
979 !hostapd_is_dfs_chan_available(hapd->iface) &&
980 !hapd->iface->cac_started) {
981 hostapd_disable_iface(hapd->iface);
982 hostapd_enable_iface(hapd->iface);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800983 }
Hai Shalom74f70d42019-02-11 14:42:39 -0800984
985 for (i = 0; i < hapd->iface->num_bss; i++)
986 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Hai Shalom899fcc72020-10-19 14:38:18 -0700987
988#ifdef CONFIG_OCV
989 if (hapd->conf->ocv) {
990 struct sta_info *sta;
991 bool check_sa_query = false;
992
993 for (sta = hapd->sta_list; sta; sta = sta->next) {
994 if (wpa_auth_uses_ocv(sta->wpa_sm) &&
995 !(sta->flags & WLAN_STA_WNM_SLEEP_MODE)) {
996 sta->post_csa_sa_query = 1;
997 check_sa_query = true;
998 }
999 }
1000
1001 if (check_sa_query) {
1002 wpa_printf(MSG_DEBUG,
1003 "OCV: Check post-CSA SA Query initiation in 15 seconds");
1004 eloop_register_timeout(15, 0,
1005 hostapd_ocv_check_csa_sa_query,
1006 hapd, NULL);
1007 }
1008 }
1009#endif /* CONFIG_OCV */
Dmitry Shmidt04949592012-07-19 12:16:46 -07001010#endif /* NEED_AP_MLME */
1011}
1012
1013
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001014void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
1015 const u8 *addr, int reason_code)
1016{
1017 switch (reason_code) {
1018 case MAX_CLIENT_REACHED:
1019 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
1020 MAC2STR(addr));
1021 break;
1022 case BLOCKED_CLIENT:
1023 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
1024 MAC2STR(addr));
1025 break;
1026 }
1027}
1028
1029
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001030#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001031void hostapd_acs_channel_selected(struct hostapd_data *hapd,
1032 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001033{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001034 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001035 int err = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001036 struct hostapd_channel_data *pri_chan;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001037
1038 if (hapd->iconf->channel) {
1039 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
1040 hapd->iconf->channel);
1041 return;
1042 }
1043
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001044 hapd->iface->freq = acs_res->pri_freq;
1045
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001046 if (!hapd->iface->current_mode) {
1047 for (i = 0; i < hapd->iface->num_hw_features; i++) {
1048 struct hostapd_hw_modes *mode =
1049 &hapd->iface->hw_features[i];
1050
1051 if (mode->mode == acs_res->hw_mode) {
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001052 if (hapd->iface->freq > 0 &&
1053 !hw_get_chan(mode->mode,
1054 hapd->iface->freq,
1055 hapd->iface->hw_features,
1056 hapd->iface->num_hw_features))
1057 continue;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001058 hapd->iface->current_mode = mode;
1059 break;
1060 }
1061 }
1062 if (!hapd->iface->current_mode) {
1063 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1064 HOSTAPD_LEVEL_WARNING,
1065 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001066 err = 1;
1067 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -07001068 }
1069 }
1070
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001071 if (!acs_res->pri_freq) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001072 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
1073 HOSTAPD_LEVEL_WARNING,
1074 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001075 err = 1;
1076 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001077 }
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001078 pri_chan = hw_get_channel_freq(hapd->iface->current_mode->mode,
1079 acs_res->pri_freq, NULL,
1080 hapd->iface->hw_features,
1081 hapd->iface->num_hw_features);
1082 if (!pri_chan) {
1083 wpa_printf(MSG_ERROR,
1084 "ACS: Could not determine primary channel number from pri_freq %u",
1085 acs_res->pri_freq);
1086 err = 1;
1087 goto out;
1088 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001089
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001090 hapd->iconf->channel = pri_chan->chan;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001091 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001092
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001093 if (acs_res->sec_freq == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001094 hapd->iconf->secondary_channel = 0;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001095 else if (acs_res->sec_freq < acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001096 hapd->iconf->secondary_channel = -1;
Ahmed ElArabawy0ff61c52019-12-26 12:38:39 -08001097 else if (acs_res->sec_freq > acs_res->pri_freq)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001098 hapd->iconf->secondary_channel = 1;
1099 else {
1100 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001101 err = 1;
1102 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001103 }
1104
Hai Shalomfdcde762020-04-02 11:19:20 -07001105 hapd->iconf->edmg_channel = acs_res->edmg_channel;
1106
Hai Shalom81f62d82019-07-22 12:10:00 -07001107 if (hapd->iface->conf->ieee80211ac || hapd->iface->conf->ieee80211ax) {
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001108 /* set defaults for backwards compatibility */
Hai Shalom81f62d82019-07-22 12:10:00 -07001109 hostapd_set_oper_centr_freq_seg1_idx(hapd->iconf, 0);
1110 hostapd_set_oper_centr_freq_seg0_idx(hapd->iconf, 0);
1111 hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_USE_HT);
Hai Shalomfdcde762020-04-02 11:19:20 -07001112 if (acs_res->ch_width == 40) {
1113 if (is_6ghz_freq(acs_res->pri_freq))
1114 hostapd_set_oper_centr_freq_seg0_idx(
1115 hapd->iconf,
1116 acs_res->vht_seg0_center_ch);
1117 } else if (acs_res->ch_width == 80) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001118 hostapd_set_oper_centr_freq_seg0_idx(
1119 hapd->iconf, acs_res->vht_seg0_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001120 if (acs_res->vht_seg1_center_ch == 0) {
Hai Shalom81f62d82019-07-22 12:10:00 -07001121 hostapd_set_oper_chwidth(hapd->iconf,
Hai Shalomfdcde762020-04-02 11:19:20 -07001122 CHANWIDTH_80MHZ);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001123 } else {
Hai Shalomfdcde762020-04-02 11:19:20 -07001124 hostapd_set_oper_chwidth(hapd->iconf,
1125 CHANWIDTH_80P80MHZ);
Hai Shalom81f62d82019-07-22 12:10:00 -07001126 hostapd_set_oper_centr_freq_seg1_idx(
1127 hapd->iconf,
1128 acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001129 }
Hai Shalomfdcde762020-04-02 11:19:20 -07001130 } else if (acs_res->ch_width == 160) {
1131 hostapd_set_oper_chwidth(hapd->iconf, CHANWIDTH_160MHZ);
1132 hostapd_set_oper_centr_freq_seg0_idx(
1133 hapd->iconf, acs_res->vht_seg1_center_ch);
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001134 }
1135 }
1136
Dmitry Shmidt9c175262016-03-03 10:20:07 -08001137out:
1138 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001139 if (ret) {
1140 wpa_printf(MSG_ERROR,
1141 "ACS: Possibly channel configuration is invalid");
1142 }
1143}
1144#endif /* CONFIG_ACS */
1145
1146
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001147int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001148 const u8 *bssid, const u8 *ie, size_t ie_len,
1149 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150{
1151 size_t i;
1152 int ret = 0;
1153
1154 if (sa == NULL || ie == NULL)
1155 return -1;
1156
1157 random_add_randomness(sa, ETH_ALEN);
1158 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
1159 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001160 sa, da, bssid, ie, ie_len,
1161 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001162 ret = 1;
1163 break;
1164 }
1165 }
1166 return ret;
1167}
1168
1169
1170#ifdef HOSTAPD
1171
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001172#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001173static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
1174 const u8 *bssid,
1175 u16 auth_transaction, u16 status,
1176 const u8 *ies, size_t ies_len)
1177{
1178 struct hostapd_data *hapd = ctx;
1179 struct sta_info *sta;
1180
1181 sta = ap_get_sta(hapd, dst);
1182 if (sta == NULL)
1183 return;
1184
1185 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
1186 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
1187 sta->flags |= WLAN_STA_AUTH;
1188
1189 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
1190}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001191#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001192
1193
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001194#ifdef CONFIG_FILS
1195static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
1196 struct sta_info *sta, u16 resp,
1197 struct wpabuf *data, int pub)
1198{
1199 if (resp == WLAN_STATUS_SUCCESS) {
1200 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1201 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1202 sta->flags |= WLAN_STA_AUTH;
1203 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1204 sta->auth_alg = WLAN_AUTH_FILS_SK;
1205 mlme_authenticate_indication(hapd, sta);
1206 } else {
1207 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1208 HOSTAPD_LEVEL_DEBUG,
1209 "authentication failed (FILS)");
1210 }
1211
1212 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1213 data ? wpabuf_head(data) : NULL,
1214 data ? wpabuf_len(data) : 0);
1215 wpabuf_free(data);
1216}
1217#endif /* CONFIG_FILS */
1218
1219
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001220static void hostapd_notif_auth(struct hostapd_data *hapd,
1221 struct auth_info *rx_auth)
1222{
1223 struct sta_info *sta;
1224 u16 status = WLAN_STATUS_SUCCESS;
1225 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1226 size_t resp_ies_len = 0;
1227
1228 sta = ap_get_sta(hapd, rx_auth->peer);
1229 if (!sta) {
1230 sta = ap_sta_add(hapd, rx_auth->peer);
1231 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001232 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001233 goto fail;
1234 }
1235 }
1236 sta->flags &= ~WLAN_STA_PREAUTH;
1237 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001238#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001239 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1240 sta->auth_alg = WLAN_AUTH_FT;
1241 if (sta->wpa_sm == NULL)
1242 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001243 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001244 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001245 wpa_printf(MSG_DEBUG,
1246 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001247 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1248 goto fail;
1249 }
1250 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1251 rx_auth->auth_transaction, rx_auth->ies,
1252 rx_auth->ies_len,
1253 hostapd_notify_auth_ft_finish, hapd);
1254 return;
1255 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001256#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001257
1258#ifdef CONFIG_FILS
1259 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1260 sta->auth_alg = WLAN_AUTH_FILS_SK;
1261 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1262 rx_auth->auth_type, rx_auth->auth_transaction,
1263 rx_auth->status_code,
1264 hostapd_notify_auth_fils_finish);
1265 return;
1266 }
1267#endif /* CONFIG_FILS */
1268
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001269fail:
1270 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1271 status, resp_ies, resp_ies_len);
1272}
1273
1274
Hai Shalom021b0b52019-04-10 11:17:58 -07001275#ifndef NEED_AP_MLME
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001276static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001277 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001278{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001279 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001280 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001281 size_t plen __maybe_unused;
1282 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001283 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001284
Hai Shalom74f70d42019-02-11 14:42:39 -08001285 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001286 return;
1287
Hai Shalom021b0b52019-04-10 11:17:58 -07001288 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001289
1290 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1291 fc = le_to_host16(mgmt->frame_control);
1292 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1293 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001294
Hai Shalom74f70d42019-02-11 14:42:39 -08001295 action = (u8 *) &mgmt->u.action.u;
1296 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1297 " da " MACSTR " plen %d",
1298 mgmt->u.action.category, *action,
1299 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001300
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001301 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001302 if (sta == NULL) {
1303 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1304 return;
1305 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001306#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001307 if (mgmt->u.action.category == WLAN_ACTION_FT) {
Hai Shalom021b0b52019-04-10 11:17:58 -07001308 wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, plen);
1309 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001310 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001311#endif /* CONFIG_IEEE80211R_AP */
Hai Shalom021b0b52019-04-10 11:17:58 -07001312 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001313 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001314 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001315 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001316#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001317 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1318 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Hai Shalom021b0b52019-04-10 11:17:58 -07001319 return;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001320 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001321#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001322#ifdef CONFIG_FST
1323 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1324 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1325 return;
1326 }
1327#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001328#ifdef CONFIG_DPP
Hai Shalom021b0b52019-04-10 11:17:58 -07001329 if (plen >= 2 + 4 &&
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001330 mgmt->u.action.u.vs_public_action.action ==
1331 WLAN_PA_VENDOR_SPECIFIC &&
1332 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1333 OUI_WFA &&
1334 mgmt->u.action.u.vs_public_action.variable[0] ==
1335 DPP_OUI_TYPE) {
1336 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001337
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001338 pos = mgmt->u.action.u.vs_public_action.oui;
1339 end = drv_mgmt->frame + drv_mgmt->frame_len;
1340 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1341 drv_mgmt->freq);
1342 return;
1343 }
1344#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001345}
Hai Shalom021b0b52019-04-10 11:17:58 -07001346#endif /* NEED_AP_MLME */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001347
1348
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001349#ifdef NEED_AP_MLME
1350
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001351#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1352
1353static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1354 const u8 *bssid)
1355{
1356 size_t i;
1357
1358 if (bssid == NULL)
1359 return NULL;
1360 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1361 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1362 return HAPD_BROADCAST;
1363
1364 for (i = 0; i < iface->num_bss; i++) {
1365 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1366 return iface->bss[i];
1367 }
1368
1369 return NULL;
1370}
1371
1372
1373static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001374 const u8 *bssid, const u8 *addr,
1375 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001376{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001377 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001378 if (hapd == NULL || hapd == HAPD_BROADCAST)
1379 return;
1380
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001381 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001382}
1383
1384
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001385static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001386{
1387 struct hostapd_iface *iface = hapd->iface;
1388 const struct ieee80211_hdr *hdr;
1389 const u8 *bssid;
1390 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001391 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001392
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001393#ifdef CONFIG_TESTING_OPTIONS
1394 if (hapd->ext_mgmt_frame_handling) {
1395 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1396 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001397
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001398 if (hex) {
1399 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1400 rx_mgmt->frame_len);
1401 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1402 os_free(hex);
1403 }
1404 return 1;
1405 }
1406#endif /* CONFIG_TESTING_OPTIONS */
1407
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001408 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1409 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1410 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001411 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001412
1413 hapd = get_hapd_bssid(iface, bssid);
1414 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001415 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001416
1417 /*
1418 * Drop frames to unknown BSSIDs except for Beacon frames which
1419 * could be used to update neighbor information.
1420 */
1421 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1422 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1423 hapd = iface->bss[0];
1424 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001425 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001426 }
1427
1428 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001429 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001430 fi.datarate = rx_mgmt->datarate;
1431 fi.ssi_signal = rx_mgmt->ssi_signal;
1432
1433 if (hapd == HAPD_BROADCAST) {
1434 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001435
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001436 ret = 0;
1437 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001438 /* if bss is set, driver will call this function for
1439 * each bss individually. */
1440 if (rx_mgmt->drv_priv &&
1441 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1442 continue;
1443
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001444 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1445 rx_mgmt->frame_len, &fi) > 0)
1446 ret = 1;
1447 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001448 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001449 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1450 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001451
1452 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001453
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001454 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001455}
1456
1457
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001458static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1459 size_t len, u16 stype, int ok)
1460{
1461 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001462 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001463
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001464 hdr = (struct ieee80211_hdr *) buf;
1465 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001466 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001467 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001468 if (hapd == HAPD_BROADCAST) {
1469 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1470 buf[24] != WLAN_ACTION_PUBLIC)
1471 return;
1472 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1473 if (!hapd || hapd == HAPD_BROADCAST)
1474 return;
1475 /*
1476 * Allow processing of TX status for a Public Action frame that
1477 * used wildcard BBSID.
1478 */
1479 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001480 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1481}
1482
1483#endif /* NEED_AP_MLME */
1484
1485
1486static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1487{
1488 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001489
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001490 if (sta)
1491 return 0;
1492
1493 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1494 " - adding a new STA", MAC2STR(addr));
1495 sta = ap_sta_add(hapd, addr);
1496 if (sta) {
1497 hostapd_new_assoc_sta(hapd, sta, 0);
1498 } else {
1499 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1500 MAC2STR(addr));
1501 return -1;
1502 }
1503
1504 return 0;
1505}
1506
1507
1508static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1509 const u8 *data, size_t data_len)
1510{
1511 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001512 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001513 size_t j;
1514
1515 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001516 sta = ap_get_sta(iface->bss[j], src);
1517 if (sta && sta->flags & WLAN_STA_ASSOC) {
1518 hapd = iface->bss[j];
1519 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001520 }
1521 }
1522
1523 ieee802_1x_receive(hapd, src, data, data_len);
1524}
1525
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001526#endif /* HOSTAPD */
1527
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001528
Hai Shalomfdcde762020-04-02 11:19:20 -07001529static struct hostapd_channel_data *
1530hostapd_get_mode_chan(struct hostapd_hw_modes *mode, unsigned int freq)
1531{
1532 int i;
1533 struct hostapd_channel_data *chan;
1534
1535 for (i = 0; i < mode->num_channels; i++) {
1536 chan = &mode->channels[i];
1537 if ((unsigned int) chan->freq == freq)
1538 return chan;
1539 }
1540
1541 return NULL;
1542}
1543
1544
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001545static struct hostapd_channel_data * hostapd_get_mode_channel(
1546 struct hostapd_iface *iface, unsigned int freq)
1547{
1548 int i;
1549 struct hostapd_channel_data *chan;
1550
Hai Shalomfdcde762020-04-02 11:19:20 -07001551 for (i = 0; i < iface->num_hw_features; i++) {
1552 if (hostapd_hw_skip_mode(iface, &iface->hw_features[i]))
1553 continue;
1554 chan = hostapd_get_mode_chan(&iface->hw_features[i], freq);
1555 if (chan)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001556 return chan;
1557 }
1558
1559 return NULL;
1560}
1561
1562
1563static void hostapd_update_nf(struct hostapd_iface *iface,
1564 struct hostapd_channel_data *chan,
1565 struct freq_survey *survey)
1566{
1567 if (!iface->chans_surveyed) {
1568 chan->min_nf = survey->nf;
1569 iface->lowest_nf = survey->nf;
1570 } else {
1571 if (dl_list_empty(&chan->survey_list))
1572 chan->min_nf = survey->nf;
1573 else if (survey->nf < chan->min_nf)
1574 chan->min_nf = survey->nf;
1575 if (survey->nf < iface->lowest_nf)
1576 iface->lowest_nf = survey->nf;
1577 }
1578}
1579
1580
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001581static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1582 struct survey_results *survey_res)
1583{
1584 struct hostapd_channel_data *chan;
1585 struct freq_survey *survey;
1586 u64 divisor, dividend;
1587
1588 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1589 list);
1590 if (!survey || !survey->freq)
1591 return;
1592
1593 chan = hostapd_get_mode_channel(iface, survey->freq);
1594 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1595 return;
1596
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001597 wpa_printf(MSG_DEBUG,
1598 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001599 survey->freq,
1600 (unsigned long int) survey->channel_time,
1601 (unsigned long int) survey->channel_time_busy);
1602
1603 if (survey->channel_time > iface->last_channel_time &&
1604 survey->channel_time > survey->channel_time_busy) {
1605 dividend = survey->channel_time_busy -
1606 iface->last_channel_time_busy;
1607 divisor = survey->channel_time - iface->last_channel_time;
1608
1609 iface->channel_utilization = dividend * 255 / divisor;
1610 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1611 iface->channel_utilization);
1612 }
1613 iface->last_channel_time = survey->channel_time;
1614 iface->last_channel_time_busy = survey->channel_time_busy;
1615}
1616
1617
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001618void hostapd_event_get_survey(struct hostapd_iface *iface,
1619 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001620{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001621 struct freq_survey *survey, *tmp;
1622 struct hostapd_channel_data *chan;
1623
1624 if (dl_list_empty(&survey_results->survey_list)) {
1625 wpa_printf(MSG_DEBUG, "No survey data received");
1626 return;
1627 }
1628
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001629 if (survey_results->freq_filter) {
1630 hostapd_single_channel_get_survey(iface, survey_results);
1631 return;
1632 }
1633
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001634 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1635 struct freq_survey, list) {
1636 chan = hostapd_get_mode_channel(iface, survey->freq);
1637 if (!chan)
1638 continue;
1639 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1640 continue;
1641
1642 dl_list_del(&survey->list);
1643 dl_list_add_tail(&chan->survey_list, &survey->list);
1644
1645 hostapd_update_nf(iface, chan, survey);
1646
1647 iface->chans_surveyed++;
1648 }
1649}
1650
1651
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001652#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001653#ifdef NEED_AP_MLME
1654
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001655static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1656{
1657 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1658 hapd->conf->iface);
1659
1660 if (hapd->csa_in_progress) {
1661 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1662 hapd->conf->iface);
1663 hostapd_switch_channel_fallback(hapd->iface,
1664 &hapd->cs_freq_params);
1665 }
1666}
1667
1668
Dmitry Shmidt051af732013-10-22 13:52:46 -07001669static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1670 struct dfs_event *radar)
1671{
1672 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001673 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001674 radar->chan_offset, radar->chan_width,
1675 radar->cf1, radar->cf2);
1676}
1677
1678
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001679static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1680 struct dfs_event *radar)
1681{
1682 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1683 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1684 radar->chan_offset, radar->chan_width,
1685 radar->cf1, radar->cf2);
1686}
1687
1688
Dmitry Shmidt051af732013-10-22 13:52:46 -07001689static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1690 struct dfs_event *radar)
1691{
1692 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001693 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001694 radar->chan_offset, radar->chan_width,
1695 radar->cf1, radar->cf2);
1696}
1697
1698
1699static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1700 struct dfs_event *radar)
1701{
1702 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001703 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001704 radar->chan_offset, radar->chan_width,
1705 radar->cf1, radar->cf2);
1706}
1707
1708
1709static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1710 struct dfs_event *radar)
1711{
1712 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001713 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001714 radar->chan_offset, radar->chan_width,
1715 radar->cf1, radar->cf2);
1716}
1717
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001718
1719static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1720 struct dfs_event *radar)
1721{
1722 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1723 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1724 radar->chan_offset, radar->chan_width,
1725 radar->cf1, radar->cf2);
1726}
1727
Dmitry Shmidt051af732013-10-22 13:52:46 -07001728#endif /* NEED_AP_MLME */
1729
1730
Roshan Pius3a1667e2018-07-03 15:17:14 -07001731static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1732 int istatus,
1733 const char *ifname,
1734 const u8 *addr)
1735{
1736 struct sta_info *sta = ap_get_sta(hapd, addr);
1737
1738 if (sta) {
1739 os_free(sta->ifname_wds);
1740 if (istatus == INTERFACE_ADDED)
1741 sta->ifname_wds = os_strdup(ifname);
1742 else
1743 sta->ifname_wds = NULL;
1744 }
1745
1746 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1747 istatus == INTERFACE_ADDED ?
1748 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1749 ifname, MAC2STR(addr));
1750}
1751
1752
Hai Shalom81f62d82019-07-22 12:10:00 -07001753#ifdef CONFIG_OWE
1754static int hostapd_notif_update_dh_ie(struct hostapd_data *hapd,
1755 const u8 *peer, const u8 *ie,
1756 size_t ie_len)
1757{
1758 u16 status;
1759 struct sta_info *sta;
1760 struct ieee802_11_elems elems;
1761
1762 if (!hapd || !hapd->wpa_auth) {
1763 wpa_printf(MSG_DEBUG, "OWE: Invalid hapd context");
1764 return -1;
1765 }
1766 if (!peer) {
1767 wpa_printf(MSG_DEBUG, "OWE: Peer unknown");
1768 return -1;
1769 }
1770 if (!(hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) {
1771 wpa_printf(MSG_DEBUG, "OWE: No OWE AKM configured");
1772 status = WLAN_STATUS_AKMP_NOT_VALID;
1773 goto err;
1774 }
1775 if (ieee802_11_parse_elems(ie, ie_len, &elems, 1) == ParseFailed) {
1776 wpa_printf(MSG_DEBUG, "OWE: Failed to parse OWE IE for "
1777 MACSTR, MAC2STR(peer));
1778 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1779 goto err;
1780 }
1781 status = owe_validate_request(hapd, peer, elems.rsn_ie,
1782 elems.rsn_ie_len,
1783 elems.owe_dh, elems.owe_dh_len);
1784 if (status != WLAN_STATUS_SUCCESS)
1785 goto err;
1786
1787 sta = ap_get_sta(hapd, peer);
1788 if (sta) {
1789 ap_sta_no_session_timeout(hapd, sta);
1790 accounting_sta_stop(hapd, sta);
1791
1792 /*
1793 * Make sure that the previously registered inactivity timer
1794 * will not remove the STA immediately.
1795 */
1796 sta->timeout_next = STA_NULLFUNC;
1797 } else {
1798 sta = ap_sta_add(hapd, peer);
1799 if (!sta) {
1800 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1801 goto err;
1802 }
1803 }
1804 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
1805
1806 status = owe_process_rsn_ie(hapd, sta, elems.rsn_ie,
1807 elems.rsn_ie_len, elems.owe_dh,
1808 elems.owe_dh_len);
1809 if (status != WLAN_STATUS_SUCCESS)
1810 ap_free_sta(hapd, sta);
1811
1812 return 0;
1813err:
1814 hostapd_drv_update_dh_ie(hapd, peer, status, NULL, 0);
1815 return 0;
1816}
1817#endif /* CONFIG_OWE */
1818
1819
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001820void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1821 union wpa_event_data *data)
1822{
1823 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001824#ifndef CONFIG_NO_STDOUT_DEBUG
1825 int level = MSG_DEBUG;
1826
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001827 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001828 data->rx_mgmt.frame_len >= 24) {
1829 const struct ieee80211_hdr *hdr;
1830 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001831
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001832 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1833 fc = le_to_host16(hdr->frame_control);
1834 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1835 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1836 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001837 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1838 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1839 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001840 }
1841
1842 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1843 event_to_string(event), event);
1844#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001845
1846 switch (event) {
1847 case EVENT_MICHAEL_MIC_FAILURE:
1848 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1849 break;
1850 case EVENT_SCAN_RESULTS:
1851 if (hapd->iface->scan_cb)
1852 hapd->iface->scan_cb(hapd->iface);
1853 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001854 case EVENT_WPS_BUTTON_PUSHED:
1855 hostapd_wps_button_pushed(hapd, NULL);
1856 break;
1857#ifdef NEED_AP_MLME
1858 case EVENT_TX_STATUS:
1859 switch (data->tx_status.type) {
1860 case WLAN_FC_TYPE_MGMT:
1861 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1862 data->tx_status.data_len,
1863 data->tx_status.stype,
1864 data->tx_status.ack);
1865 break;
1866 case WLAN_FC_TYPE_DATA:
1867 hostapd_tx_status(hapd, data->tx_status.dst,
1868 data->tx_status.data,
1869 data->tx_status.data_len,
1870 data->tx_status.ack);
1871 break;
1872 }
1873 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001874 case EVENT_EAPOL_TX_STATUS:
1875 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1876 data->eapol_tx_status.data,
1877 data->eapol_tx_status.data_len,
1878 data->eapol_tx_status.ack);
1879 break;
1880 case EVENT_DRIVER_CLIENT_POLL_OK:
1881 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1882 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001883 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001884 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1885 data->rx_from_unknown.addr,
1886 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001887 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001888#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001889 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001890 if (!data->rx_mgmt.frame)
1891 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001892#ifdef NEED_AP_MLME
Hai Shalom021b0b52019-04-10 11:17:58 -07001893 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
1894#else /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001895 hostapd_action_rx(hapd, &data->rx_mgmt);
Hai Shalom021b0b52019-04-10 11:17:58 -07001896#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001897 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001898 case EVENT_RX_PROBE_REQ:
1899 if (data->rx_probe_req.sa == NULL ||
1900 data->rx_probe_req.ie == NULL)
1901 break;
1902 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001903 data->rx_probe_req.da,
1904 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001905 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001906 data->rx_probe_req.ie_len,
1907 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001908 break;
1909 case EVENT_NEW_STA:
1910 hostapd_event_new_sta(hapd, data->new_sta.addr);
1911 break;
1912 case EVENT_EAPOL_RX:
1913 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1914 data->eapol_rx.data,
1915 data->eapol_rx.data_len);
1916 break;
1917 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001918 if (!data)
1919 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001920 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1921 data->assoc_info.req_ies,
1922 data->assoc_info.req_ies_len,
1923 data->assoc_info.reassoc);
1924 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001925#ifdef CONFIG_OWE
1926 case EVENT_UPDATE_DH:
1927 if (!data)
1928 return;
1929 hostapd_notif_update_dh_ie(hapd, data->update_dh.peer,
1930 data->update_dh.ie,
1931 data->update_dh.ie_len);
1932 break;
1933#endif /* CONFIG_OWE */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001934 case EVENT_DISASSOC:
1935 if (data)
1936 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1937 break;
1938 case EVENT_DEAUTH:
1939 if (data)
1940 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1941 break;
1942 case EVENT_STATION_LOW_ACK:
1943 if (!data)
1944 break;
1945 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1946 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001947 case EVENT_AUTH:
1948 hostapd_notif_auth(hapd, &data->auth);
1949 break;
Hai Shalom81f62d82019-07-22 12:10:00 -07001950 case EVENT_CH_SWITCH_STARTED:
Dmitry Shmidt04949592012-07-19 12:16:46 -07001951 case EVENT_CH_SWITCH:
1952 if (!data)
1953 break;
1954 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1955 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001956 data->ch_switch.ch_offset,
1957 data->ch_switch.ch_width,
1958 data->ch_switch.cf1,
Hai Shalom81f62d82019-07-22 12:10:00 -07001959 data->ch_switch.cf2,
1960 event == EVENT_CH_SWITCH);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001961 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001962 case EVENT_CONNECT_FAILED_REASON:
1963 if (!data)
1964 break;
1965 hostapd_event_connect_failed_reason(
1966 hapd, data->connect_failed_reason.addr,
1967 data->connect_failed_reason.code);
1968 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001969 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001970 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001971 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001972#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001973 case EVENT_INTERFACE_UNAVAILABLE:
1974 hostapd_event_iface_unavailable(hapd);
1975 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001976 case EVENT_DFS_RADAR_DETECTED:
1977 if (!data)
1978 break;
1979 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1980 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001981 case EVENT_DFS_PRE_CAC_EXPIRED:
1982 if (!data)
1983 break;
1984 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1985 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001986 case EVENT_DFS_CAC_FINISHED:
1987 if (!data)
1988 break;
1989 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1990 break;
1991 case EVENT_DFS_CAC_ABORTED:
1992 if (!data)
1993 break;
1994 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1995 break;
1996 case EVENT_DFS_NOP_FINISHED:
1997 if (!data)
1998 break;
1999 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
2000 break;
2001 case EVENT_CHANNEL_LIST_CHANGED:
2002 /* channel list changed (regulatory?), update channel list */
2003 /* TODO: check this. hostapd_get_hw_features() initializes
2004 * too much stuff. */
2005 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08002006 hostapd_channel_list_updated(
2007 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07002008 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08002009 case EVENT_DFS_CAC_STARTED:
2010 if (!data)
2011 break;
2012 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
2013 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07002014#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002015 case EVENT_INTERFACE_ENABLED:
2016 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002017 if (hapd->disabled && hapd->started) {
2018 hapd->disabled = 0;
2019 /*
2020 * Try to re-enable interface if the driver stopped it
2021 * when the interface got disabled.
2022 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07002023 if (hapd->wpa_auth)
2024 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
2025 else
2026 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002027 hapd->reenable_beacon = 1;
2028 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08002029#ifdef NEED_AP_MLME
2030 } else if (hapd->disabled && hapd->iface->cac_started) {
2031 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
2032 hostapd_handle_dfs(hapd->iface);
2033#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002034 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002035 break;
2036 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002037 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002038 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08002039 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002040 break;
2041#ifdef CONFIG_ACS
2042 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07002043 hostapd_acs_channel_selected(hapd,
2044 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08002045 break;
2046#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07002047 case EVENT_STATION_OPMODE_CHANGED:
2048 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
2049 data->sta_opmode.smps_mode,
2050 data->sta_opmode.chan_width,
2051 data->sta_opmode.rx_nss);
2052 break;
2053 case EVENT_WDS_STA_INTERFACE_STATUS:
2054 hostapd_event_wds_sta_interface_status(
2055 hapd, data->wds_sta_interface.istatus,
2056 data->wds_sta_interface.ifname,
2057 data->wds_sta_interface.sta_addr);
2058 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002059 default:
2060 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
2061 break;
2062 }
2063}
2064
Dmitry Shmidte4663042016-04-04 10:07:49 -07002065
2066void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
2067 union wpa_event_data *data)
2068{
2069 struct hapd_interfaces *interfaces = ctx;
2070 struct hostapd_data *hapd;
2071
2072 if (event != EVENT_INTERFACE_STATUS)
2073 return;
2074
2075 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
2076 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
2077 hapd->drv_priv) {
2078 unsigned int ifindex;
2079
2080 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
2081 if (ifindex != data->interface_status.ifindex) {
2082 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
2083 "interface status ifindex %d mismatch (%d)",
2084 ifindex, data->interface_status.ifindex);
2085 return;
2086 }
2087 }
2088 if (hapd)
2089 wpa_supplicant_event(hapd, event, data);
2090}
2091
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07002092#endif /* HOSTAPD */