blob: 54be3b52439c0bad1f85d3722554795d82989d42 [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"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070018#include "crypto/random.h"
19#include "p2p/p2p.h"
20#include "wps/wps.h"
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080021#include "fst/fst.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070022#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070023#include "hostapd.h"
24#include "ieee802_11.h"
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -080025#include "ieee802_11_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "sta_info.h"
27#include "accounting.h"
28#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070029#include "ieee802_1x.h"
30#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070031#include "wps_hostapd.h"
32#include "ap_drv_ops.h"
33#include "ap_config.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070034#include "ap_mlme.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070035#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070036#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070037#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080038#include "mbo_ap.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070039#include "dpp_hostapd.h"
40#include "fils_hlp.h"
Hai Shalom74f70d42019-02-11 14:42:39 -080041#include "neighbor_db.h"
Dmitry Shmidtd2986c22017-10-23 14:22:09 -070042
43
44#ifdef CONFIG_FILS
45void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
46 struct sta_info *sta)
47{
48 u16 reply_res = WLAN_STATUS_SUCCESS;
49 struct ieee802_11_elems elems;
50 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
51 int new_assoc;
52
53 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
54 __func__, MAC2STR(sta->addr));
55 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
56 if (!sta->fils_pending_assoc_req)
57 return;
58
59 ieee802_11_parse_elems(sta->fils_pending_assoc_req,
60 sta->fils_pending_assoc_req_len, &elems, 0);
61 if (!elems.fils_session) {
62 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
63 __func__);
64 return;
65 }
66
67 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
68 elems.fils_session,
69 sta->fils_hlp_resp);
70
71 reply_res = hostapd_sta_assoc(hapd, sta->addr,
72 sta->fils_pending_assoc_is_reassoc,
73 WLAN_STATUS_SUCCESS,
74 buf, p - buf);
75 ap_sta_set_authorized(hapd, sta, 1);
76 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
77 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
78 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
79 hostapd_set_sta_flags(hapd, sta);
80 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
81 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
82 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
83 os_free(sta->fils_pending_assoc_req);
84 sta->fils_pending_assoc_req = NULL;
85 sta->fils_pending_assoc_req_len = 0;
86 wpabuf_free(sta->fils_hlp_resp);
87 sta->fils_hlp_resp = NULL;
88 wpabuf_free(sta->hlp_dhcp_discover);
89 sta->hlp_dhcp_discover = NULL;
90 fils_hlp_deinit(hapd);
91
92 /*
93 * Remove the station in case transmission of a success response fails
94 * (the STA was added associated to the driver) or if the station was
95 * previously added unassociated.
96 */
97 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
98 hostapd_drv_sta_remove(hapd, sta->addr);
99 sta->added_unassoc = 0;
100 }
101}
102#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700103
104
105int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800106 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107{
108 struct sta_info *sta;
109 int new_assoc, res;
110 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800111 const u8 *ie;
112 size_t ielen;
Hai Shalomce48b4a2018-09-05 11:41:35 -0700113#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700114 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
115 u8 *p = buf;
Hai Shalomce48b4a2018-09-05 11:41:35 -0700116#endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W || CONFIG_FILS || CONFIG_OWE */
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 }
133 random_add_randomness(addr, ETH_ALEN);
134
135 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
136 HOSTAPD_LEVEL_INFO, "associated");
137
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800138 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700139 if (elems.wps_ie) {
140 ie = elems.wps_ie - 2;
141 ielen = elems.wps_ie_len + 2;
142 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
143 } else if (elems.rsn_ie) {
144 ie = elems.rsn_ie - 2;
145 ielen = elems.rsn_ie_len + 2;
146 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
147 } else if (elems.wpa_ie) {
148 ie = elems.wpa_ie - 2;
149 ielen = elems.wpa_ie_len + 2;
150 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800151#ifdef CONFIG_HS20
152 } else if (elems.osen) {
153 ie = elems.osen - 2;
154 ielen = elems.osen_len + 2;
155 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
156#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700157 } else {
158 ie = NULL;
159 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800160 wpa_printf(MSG_DEBUG,
161 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700162 }
163
164 sta = ap_get_sta(hapd, addr);
165 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700166 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700168
169 /*
170 * Make sure that the previously registered inactivity timer
171 * will not remove the STA immediately.
172 */
173 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700174 } else {
175 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700176 if (sta == NULL) {
177 hostapd_drv_sta_disassoc(hapd, addr,
178 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700179 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700180 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700181 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800182 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700183
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700184 /*
185 * ACL configurations to the drivers (implementing AP SME and ACL
186 * offload) without hostapd's knowledge, can result in a disconnection
187 * though the driver accepts the connection. Skip the hostapd check for
188 * ACL if the driver supports ACL offload to avoid potentially
189 * conflicting ACL rules.
190 */
191 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
192 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800193 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
194 MAC2STR(addr));
195 reason = WLAN_REASON_UNSPECIFIED;
196 goto fail;
197 }
198
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700199#ifdef CONFIG_P2P
200 if (elems.p2p) {
201 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800202 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700203 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700204 if (sta->p2p_ie)
205 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700206 }
207#endif /* CONFIG_P2P */
208
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700209#ifdef CONFIG_IEEE80211N
210#ifdef NEED_AP_MLME
211 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700212 (hapd->iface->conf->ht_capab &
213 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
214 struct ieee80211_ht_capabilities *ht_cap =
215 (struct ieee80211_ht_capabilities *)
216 elems.ht_capabilities;
217
218 if (le_to_host16(ht_cap->ht_capabilities_info) &
219 HT_CAP_INFO_40MHZ_INTOLERANT)
220 ht40_intolerant_add(hapd->iface, sta);
221 }
222#endif /* NEED_AP_MLME */
223#endif /* CONFIG_IEEE80211N */
224
Dmitry Shmidt051af732013-10-22 13:52:46 -0700225#ifdef CONFIG_INTERWORKING
226 if (elems.ext_capab && elems.ext_capab_len > 4) {
227 if (elems.ext_capab[4] & 0x01)
228 sta->qos_map_enabled = 1;
229 }
230#endif /* CONFIG_INTERWORKING */
231
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800232#ifdef CONFIG_HS20
233 wpabuf_free(sta->hs20_ie);
234 if (elems.hs20 && elems.hs20_len > 4) {
235 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
236 elems.hs20_len - 4);
237 } else
238 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700239
240 wpabuf_free(sta->roaming_consortium);
241 if (elems.roaming_cons_sel)
242 sta->roaming_consortium = wpabuf_alloc_copy(
243 elems.roaming_cons_sel + 4,
244 elems.roaming_cons_sel_len - 4);
245 else
246 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800247#endif /* CONFIG_HS20 */
248
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800249#ifdef CONFIG_FST
250 wpabuf_free(sta->mb_ies);
251 if (hapd->iface->fst)
252 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
253 else
254 sta->mb_ies = NULL;
255#endif /* CONFIG_FST */
256
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800257 mbo_ap_check_sta_assoc(hapd, sta, &elems);
258
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800259 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
260 elems.supp_op_classes_len);
261
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700262 if (hapd->conf->wpa) {
263 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700265 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800266 wpa_printf(MSG_DEBUG,
267 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 sta->flags |= WLAN_STA_MAYBE_WPS;
269 goto skip_wpa_check;
270 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800271#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700272
273 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700274 reason = WLAN_REASON_INVALID_IE;
275 status = WLAN_STATUS_INVALID_IE;
276 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800278#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700279 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
280 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800281 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800282
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700283 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800284 wps = ieee802_11_vendor_ie_concat(ie, ielen,
285 WPS_IE_VENDOR_TYPE);
286 if (wps) {
287 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800288 wpa_printf(MSG_DEBUG,
289 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800290 sta->flags |= WLAN_STA_WPS2;
291 }
292 wpabuf_free(wps);
293 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700294 goto skip_wpa_check;
295 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800296#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700297
298 if (sta->wpa_sm == NULL)
299 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700300 sta->addr,
301 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800303 wpa_printf(MSG_ERROR,
304 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700305 return -1;
306 }
307 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700308 ie, ielen,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700309 elems.mdie, elems.mdie_len,
310 elems.owe_dh, elems.owe_dh_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311 if (res != WPA_IE_OK) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800312 wpa_printf(MSG_DEBUG,
313 "WPA/RSN information element rejected? (res %u)",
314 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700316 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800317 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700318 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
319 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800320 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700321 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
322 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800323 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700324 status = WLAN_STATUS_AKMP_NOT_VALID;
325 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326#ifdef CONFIG_IEEE80211W
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700327 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700329 status = WLAN_STATUS_INVALID_IE;
330 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700331 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
332 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700333 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700334#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700335 else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800336 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700337 status = WLAN_STATUS_INVALID_IE;
338 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800339 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700341#ifdef CONFIG_IEEE80211W
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800342 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
343 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
344 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700345 sta->sa_query_count > 0)
346 ap_check_sa_query_timeout(hapd, sta);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800347 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
348 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
349 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700350 (sta->auth_alg != WLAN_AUTH_FT)) {
351 /*
352 * STA has already been associated with MFP and SA
353 * Query timeout has not been reached. Reject the
354 * association attempt temporarily and start SA Query,
355 * if one is not pending.
356 */
357
358 if (sta->sa_query_count == 0)
359 ap_sta_start_sa_query(hapd, sta);
360
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700361 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
362
363 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
364
365 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
366 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700367 return 0;
368 }
369
370 if (wpa_auth_uses_mfp(sta->wpa_sm))
371 sta->flags |= WLAN_STA_MFP;
372 else
373 sta->flags &= ~WLAN_STA_MFP;
374#endif /* CONFIG_IEEE80211W */
375
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800376#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700377 if (sta->auth_alg == WLAN_AUTH_FT) {
378 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
379 req_ies_len);
380 if (status != WLAN_STATUS_SUCCESS) {
381 if (status == WLAN_STATUS_INVALID_PMKID)
382 reason = WLAN_REASON_INVALID_IE;
383 if (status == WLAN_STATUS_INVALID_MDIE)
384 reason = WLAN_REASON_INVALID_IE;
385 if (status == WLAN_STATUS_INVALID_FTIE)
386 reason = WLAN_REASON_INVALID_IE;
387 goto fail;
388 }
389 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800390#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700391 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800392#ifdef CONFIG_WPS
393 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800394
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800395 if (req_ies)
396 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700397 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800398 else
399 wps = NULL;
400#ifdef CONFIG_WPS_STRICT
401 if (wps && wps_validate_assoc_req(wps) < 0) {
402 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700403 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700404 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800405 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700406 }
407#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800408 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700409 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800410 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800411 wpa_printf(MSG_DEBUG,
412 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800413 sta->flags |= WLAN_STA_WPS2;
414 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700415 } else
416 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800417 wpabuf_free(wps);
418#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800419#ifdef CONFIG_HS20
420 } else if (hapd->conf->osen) {
421 if (elems.osen == NULL) {
422 hostapd_logger(
423 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
424 HOSTAPD_LEVEL_INFO,
425 "No HS 2.0 OSEN element in association request");
426 return WLAN_STATUS_INVALID_IE;
427 }
428
429 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
430 if (sta->wpa_sm == NULL)
431 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
432 sta->addr, NULL);
433 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800434 wpa_printf(MSG_WARNING,
435 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800436 return WLAN_STATUS_UNSPECIFIED_FAILURE;
437 }
438 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
439 elems.osen - 2, elems.osen_len + 2) < 0)
440 return WLAN_STATUS_INVALID_IE;
441#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700442 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800443
444#ifdef CONFIG_MBO
445 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
446 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
447 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
448 wpa_printf(MSG_INFO,
449 "MBO: Reject WPA2 association without PMF");
450 return WLAN_STATUS_UNSPECIFIED_FAILURE;
451 }
452#endif /* CONFIG_MBO */
453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800456#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700457
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800458#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700459 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
460 sta->auth_alg, req_ies, req_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700461 if (!p) {
462 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
463 return WLAN_STATUS_UNSPECIFIED_FAILURE;
464 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700465#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700466
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700467#ifdef CONFIG_FILS
468 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
469 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
470 sta->auth_alg == WLAN_AUTH_FILS_PK) {
471 int delay_assoc = 0;
472
473 if (!req_ies)
474 return WLAN_STATUS_UNSPECIFIED_FAILURE;
475
476 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
477 req_ies_len,
478 sta->fils_session)) {
479 wpa_printf(MSG_DEBUG,
480 "FILS: Session validation failed");
481 return WLAN_STATUS_UNSPECIFIED_FAILURE;
482 }
483
484 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
485 req_ies_len);
486 if (res < 0) {
487 wpa_printf(MSG_DEBUG,
488 "FILS: Key Confirm validation failed");
489 return WLAN_STATUS_UNSPECIFIED_FAILURE;
490 }
491
492 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
493 wpa_printf(MSG_DEBUG,
494 "FILS: Delaying Assoc Response (HLP)");
495 delay_assoc = 1;
496 } else {
497 wpa_printf(MSG_DEBUG,
498 "FILS: Going ahead with Assoc Response (no HLP)");
499 }
500
501 if (sta) {
502 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
503 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
504 os_free(sta->fils_pending_assoc_req);
505 sta->fils_pending_assoc_req = NULL;
506 sta->fils_pending_assoc_req_len = 0;
507 wpabuf_free(sta->fils_hlp_resp);
508 sta->fils_hlp_resp = NULL;
509 sta->fils_drv_assoc_finish = 0;
510 }
511
512 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
513 u8 *req_tmp;
514
515 req_tmp = os_malloc(req_ies_len);
516 if (!req_tmp) {
517 wpa_printf(MSG_DEBUG,
518 "FILS: buffer allocation failed for assoc req");
519 goto fail;
520 }
521 os_memcpy(req_tmp, req_ies, req_ies_len);
522 sta->fils_pending_assoc_req = req_tmp;
523 sta->fils_pending_assoc_req_len = req_ies_len;
524 sta->fils_pending_assoc_is_reassoc = reassoc;
525 sta->fils_drv_assoc_finish = 1;
526 wpa_printf(MSG_DEBUG,
527 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
528 MACSTR, MAC2STR(sta->addr));
529 eloop_register_timeout(
530 0, hapd->conf->fils_hlp_wait_time * 1024,
531 fils_hlp_timeout, hapd, sta);
532 return 0;
533 }
534 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
535 elems.fils_session,
536 sta->fils_hlp_resp);
537 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
538 buf, p - buf);
539 }
540#endif /* CONFIG_FILS */
541
Roshan Pius3a1667e2018-07-03 15:17:14 -0700542#ifdef CONFIG_OWE
543 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
544 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
545 elems.owe_dh) {
546 u8 *npos;
547
548 npos = owe_assoc_req_process(hapd, sta,
549 elems.owe_dh, elems.owe_dh_len,
550 p, sizeof(buf) - (p - buf),
551 &reason);
552 if (npos)
553 p = npos;
554 if (!npos &&
555 reason == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
556 status = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
557 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
558 p - buf);
559 return 0;
560 }
561
562 if (!npos || reason != WLAN_STATUS_SUCCESS)
563 goto fail;
564 }
565#endif /* CONFIG_OWE */
566
567#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700568 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700569
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700570 if (sta->auth_alg == WLAN_AUTH_FT ||
571 sta->auth_alg == WLAN_AUTH_FILS_SK ||
572 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
573 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700574 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700575#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700576 /* Keep compiler silent about unused variables */
577 if (status) {
578 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700579#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700580
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700581 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
582 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800583 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700584
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700585 hostapd_set_sta_flags(hapd, sta);
586
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700587 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
588 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700589#ifdef CONFIG_FILS
590 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
591 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
592 sta->auth_alg == WLAN_AUTH_FILS_PK)
593 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
594#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700595 else
596 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700597
598 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
599
600 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
601
602#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800603 if (req_ies) {
604 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
605 req_ies, req_ies_len);
606 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700607#endif /* CONFIG_P2P */
608
609 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800610
611fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800612#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700613 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800614#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800615 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
616 ap_free_sta(hapd, sta);
617 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700618}
619
620
621void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
622{
623 struct sta_info *sta;
624
625 if (addr == NULL) {
626 /*
627 * This could potentially happen with unexpected event from the
628 * driver wrapper. This was seen at least in one case where the
629 * driver ended up reporting a station mode event while hostapd
630 * was running, so better make sure we stop processing such an
631 * event here.
632 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800633 wpa_printf(MSG_DEBUG,
634 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700635 return;
636 }
637
638 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
639 HOSTAPD_LEVEL_INFO, "disassociated");
640
641 sta = ap_get_sta(hapd, addr);
642 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800643 wpa_printf(MSG_DEBUG,
644 "Disassociation notification for unknown STA "
645 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700646 return;
647 }
648
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800649 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700651 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
652 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
653 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
654 ap_free_sta(hapd, sta);
655}
656
657
658void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
659{
660 struct sta_info *sta = ap_get_sta(hapd, addr);
661
Roshan Pius3a1667e2018-07-03 15:17:14 -0700662 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700663 return;
664
665 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800666 HOSTAPD_LEVEL_INFO,
667 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800669 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670}
671
672
Roshan Pius3a1667e2018-07-03 15:17:14 -0700673void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
674 enum smps_mode smps_mode,
675 enum chan_width chan_width, u8 rx_nss)
676{
677 struct sta_info *sta = ap_get_sta(hapd, addr);
678 const char *txt;
679
680 if (!sta)
681 return;
682
683 switch (smps_mode) {
684 case SMPS_AUTOMATIC:
685 txt = "automatic";
686 break;
687 case SMPS_OFF:
688 txt = "off";
689 break;
690 case SMPS_DYNAMIC:
691 txt = "dynamic";
692 break;
693 case SMPS_STATIC:
694 txt = "static";
695 break;
696 default:
697 txt = NULL;
698 break;
699 }
700 if (txt) {
701 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
702 MACSTR " %s", MAC2STR(addr), txt);
703 }
704
705 switch (chan_width) {
706 case CHAN_WIDTH_20_NOHT:
707 txt = "20(no-HT)";
708 break;
709 case CHAN_WIDTH_20:
710 txt = "20";
711 break;
712 case CHAN_WIDTH_40:
713 txt = "40";
714 break;
715 case CHAN_WIDTH_80:
716 txt = "80";
717 break;
718 case CHAN_WIDTH_80P80:
719 txt = "80+80";
720 break;
721 case CHAN_WIDTH_160:
722 txt = "160";
723 break;
724 default:
725 txt = NULL;
726 break;
727 }
728 if (txt) {
729 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
730 MACSTR " %s", MAC2STR(addr), txt);
731 }
732
733 if (rx_nss != 0xff) {
734 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
735 MACSTR " %d", MAC2STR(addr), rx_nss);
736 }
737}
738
739
Dmitry Shmidt04949592012-07-19 12:16:46 -0700740void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800741 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700742{
Hai Shalom74f70d42019-02-11 14:42:39 -0800743 /* TODO: If OCV is enabled deauth STAs that don't perform a SA Query */
744
Dmitry Shmidt04949592012-07-19 12:16:46 -0700745#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800746 int channel, chwidth, is_dfs;
747 u8 seg0_idx = 0, seg1_idx = 0;
Hai Shalom74f70d42019-02-11 14:42:39 -0800748 size_t i;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700749
750 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800751 HOSTAPD_LEVEL_INFO,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700752 "driver had channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
753 freq, ht, hapd->iconf->ch_switch_vht_config, offset,
754 width, channel_width_to_string(width), cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700755
756 hapd->iface->freq = freq;
757
758 channel = hostapd_hw_get_channel(hapd, freq);
759 if (!channel) {
760 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800761 HOSTAPD_LEVEL_WARNING,
762 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700763 return;
764 }
765
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800766 switch (width) {
767 case CHAN_WIDTH_80:
768 chwidth = VHT_CHANWIDTH_80MHZ;
769 break;
770 case CHAN_WIDTH_80P80:
771 chwidth = VHT_CHANWIDTH_80P80MHZ;
772 break;
773 case CHAN_WIDTH_160:
774 chwidth = VHT_CHANWIDTH_160MHZ;
775 break;
776 case CHAN_WIDTH_20_NOHT:
777 case CHAN_WIDTH_20:
778 case CHAN_WIDTH_40:
779 default:
780 chwidth = VHT_CHANWIDTH_USE_HT;
781 break;
782 }
783
784 switch (hapd->iface->current_mode->mode) {
785 case HOSTAPD_MODE_IEEE80211A:
786 if (cf1 > 5000)
787 seg0_idx = (cf1 - 5000) / 5;
788 if (cf2 > 5000)
789 seg1_idx = (cf2 - 5000) / 5;
790 break;
791 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800792 ieee80211_freq_to_chan(cf1, &seg0_idx);
793 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800794 break;
795 }
796
Dmitry Shmidt04949592012-07-19 12:16:46 -0700797 hapd->iconf->channel = channel;
798 hapd->iconf->ieee80211n = ht;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700799 if (!ht) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800800 hapd->iconf->ieee80211ac = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700801 } else if (hapd->iconf->ch_switch_vht_config) {
802 /* CHAN_SWITCH VHT config */
803 if (hapd->iconf->ch_switch_vht_config &
804 CH_SWITCH_VHT_ENABLED)
805 hapd->iconf->ieee80211ac = 1;
806 else if (hapd->iconf->ch_switch_vht_config &
807 CH_SWITCH_VHT_DISABLED)
808 hapd->iconf->ieee80211ac = 0;
809 }
810 hapd->iconf->ch_switch_vht_config = 0;
811
Dmitry Shmidt04949592012-07-19 12:16:46 -0700812 hapd->iconf->secondary_channel = offset;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800813 hapd->iconf->vht_oper_chwidth = chwidth;
814 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
815 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800816
Roshan Pius3a1667e2018-07-03 15:17:14 -0700817 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
818 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800819
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700820 if (hapd->csa_in_progress &&
821 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800822 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700823 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800824
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800825 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
826 "freq=%d dfs=%d", freq, is_dfs);
827 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
828 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
829 "freq=%d dfs=%d", freq, is_dfs);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800830 }
Hai Shalom74f70d42019-02-11 14:42:39 -0800831
832 for (i = 0; i < hapd->iface->num_bss; i++)
833 hostapd_neighbor_set_own_report(hapd->iface->bss[i]);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700834#endif /* NEED_AP_MLME */
835}
836
837
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800838void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
839 const u8 *addr, int reason_code)
840{
841 switch (reason_code) {
842 case MAX_CLIENT_REACHED:
843 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
844 MAC2STR(addr));
845 break;
846 case BLOCKED_CLIENT:
847 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
848 MAC2STR(addr));
849 break;
850 }
851}
852
853
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800854#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800855void hostapd_acs_channel_selected(struct hostapd_data *hapd,
856 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800857{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700858 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800859 int err = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800860
861 if (hapd->iconf->channel) {
862 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
863 hapd->iconf->channel);
864 return;
865 }
866
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700867 if (!hapd->iface->current_mode) {
868 for (i = 0; i < hapd->iface->num_hw_features; i++) {
869 struct hostapd_hw_modes *mode =
870 &hapd->iface->hw_features[i];
871
872 if (mode->mode == acs_res->hw_mode) {
873 hapd->iface->current_mode = mode;
874 break;
875 }
876 }
877 if (!hapd->iface->current_mode) {
878 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
879 HOSTAPD_LEVEL_WARNING,
880 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800881 err = 1;
882 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700883 }
884 }
885
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700886 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800887
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700888 if (!acs_res->pri_channel) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800889 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
890 HOSTAPD_LEVEL_WARNING,
891 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800892 err = 1;
893 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800894 }
895
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700896 hapd->iconf->channel = acs_res->pri_channel;
897 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800898
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700899 if (acs_res->sec_channel == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800900 hapd->iconf->secondary_channel = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700901 else if (acs_res->sec_channel < acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800902 hapd->iconf->secondary_channel = -1;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700903 else if (acs_res->sec_channel > acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800904 hapd->iconf->secondary_channel = 1;
905 else {
906 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800907 err = 1;
908 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800909 }
910
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700911 if (hapd->iface->conf->ieee80211ac) {
912 /* set defaults for backwards compatibility */
913 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
914 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
915 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
916 if (acs_res->ch_width == 80) {
917 hapd->iconf->vht_oper_centr_freq_seg0_idx =
918 acs_res->vht_seg0_center_ch;
919 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
920 } else if (acs_res->ch_width == 160) {
921 if (acs_res->vht_seg1_center_ch == 0) {
922 hapd->iconf->vht_oper_centr_freq_seg0_idx =
923 acs_res->vht_seg0_center_ch;
924 hapd->iconf->vht_oper_chwidth =
925 VHT_CHANWIDTH_160MHZ;
926 } else {
927 hapd->iconf->vht_oper_centr_freq_seg0_idx =
928 acs_res->vht_seg0_center_ch;
929 hapd->iconf->vht_oper_centr_freq_seg1_idx =
930 acs_res->vht_seg1_center_ch;
931 hapd->iconf->vht_oper_chwidth =
932 VHT_CHANWIDTH_80P80MHZ;
933 }
934 }
935 }
936
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800937out:
938 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800939 if (ret) {
940 wpa_printf(MSG_ERROR,
941 "ACS: Possibly channel configuration is invalid");
942 }
943}
944#endif /* CONFIG_ACS */
945
946
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800947int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700948 const u8 *bssid, const u8 *ie, size_t ie_len,
949 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700950{
951 size_t i;
952 int ret = 0;
953
954 if (sa == NULL || ie == NULL)
955 return -1;
956
957 random_add_randomness(sa, ETH_ALEN);
958 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
959 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700960 sa, da, bssid, ie, ie_len,
961 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700962 ret = 1;
963 break;
964 }
965 }
966 return ret;
967}
968
969
970#ifdef HOSTAPD
971
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800972#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700973static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
974 const u8 *bssid,
975 u16 auth_transaction, u16 status,
976 const u8 *ies, size_t ies_len)
977{
978 struct hostapd_data *hapd = ctx;
979 struct sta_info *sta;
980
981 sta = ap_get_sta(hapd, dst);
982 if (sta == NULL)
983 return;
984
985 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
986 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
987 sta->flags |= WLAN_STA_AUTH;
988
989 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
990}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800991#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700992
993
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700994#ifdef CONFIG_FILS
995static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
996 struct sta_info *sta, u16 resp,
997 struct wpabuf *data, int pub)
998{
999 if (resp == WLAN_STATUS_SUCCESS) {
1000 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1001 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
1002 sta->flags |= WLAN_STA_AUTH;
1003 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
1004 sta->auth_alg = WLAN_AUTH_FILS_SK;
1005 mlme_authenticate_indication(hapd, sta);
1006 } else {
1007 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1008 HOSTAPD_LEVEL_DEBUG,
1009 "authentication failed (FILS)");
1010 }
1011
1012 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1013 data ? wpabuf_head(data) : NULL,
1014 data ? wpabuf_len(data) : 0);
1015 wpabuf_free(data);
1016}
1017#endif /* CONFIG_FILS */
1018
1019
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001020static void hostapd_notif_auth(struct hostapd_data *hapd,
1021 struct auth_info *rx_auth)
1022{
1023 struct sta_info *sta;
1024 u16 status = WLAN_STATUS_SUCCESS;
1025 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1026 size_t resp_ies_len = 0;
1027
1028 sta = ap_get_sta(hapd, rx_auth->peer);
1029 if (!sta) {
1030 sta = ap_sta_add(hapd, rx_auth->peer);
1031 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001032 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001033 goto fail;
1034 }
1035 }
1036 sta->flags &= ~WLAN_STA_PREAUTH;
1037 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001038#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001039 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1040 sta->auth_alg = WLAN_AUTH_FT;
1041 if (sta->wpa_sm == NULL)
1042 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001043 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001044 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001045 wpa_printf(MSG_DEBUG,
1046 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001047 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1048 goto fail;
1049 }
1050 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1051 rx_auth->auth_transaction, rx_auth->ies,
1052 rx_auth->ies_len,
1053 hostapd_notify_auth_ft_finish, hapd);
1054 return;
1055 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001056#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001057
1058#ifdef CONFIG_FILS
1059 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1060 sta->auth_alg = WLAN_AUTH_FILS_SK;
1061 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1062 rx_auth->auth_type, rx_auth->auth_transaction,
1063 rx_auth->status_code,
1064 hostapd_notify_auth_fils_finish);
1065 return;
1066 }
1067#endif /* CONFIG_FILS */
1068
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001069fail:
1070 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1071 status, resp_ies, resp_ies_len);
1072}
1073
1074
1075static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001076 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001077{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001078 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001079 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001080 size_t plen __maybe_unused;
1081 u16 fc;
Hai Shalom74f70d42019-02-11 14:42:39 -08001082 u8 *action __maybe_unused;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001083
Hai Shalom74f70d42019-02-11 14:42:39 -08001084 if (drv_mgmt->frame_len < IEEE80211_HDRLEN + 2 + 1)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001085 return;
1086
Hai Shalom74f70d42019-02-11 14:42:39 -08001087 plen = drv_mgmt->frame_len - IEEE80211_HDRLEN - 1;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001088
1089 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1090 fc = le_to_host16(mgmt->frame_control);
1091 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1092 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001093
Hai Shalom74f70d42019-02-11 14:42:39 -08001094 action = (u8 *) &mgmt->u.action.u;
1095 wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR
1096 " da " MACSTR " plen %d",
1097 mgmt->u.action.category, *action,
1098 MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001099
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001100 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001101 if (sta == NULL) {
1102 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1103 return;
1104 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001105#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001106 if (mgmt->u.action.category == WLAN_ACTION_FT) {
1107 const u8 *payload = drv_mgmt->frame + 24 + 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001108
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001109 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001110 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001111#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001112#ifdef CONFIG_IEEE80211W
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001113 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
Hai Shalom74f70d42019-02-11 14:42:39 -08001114 ieee802_11_sa_query_action(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001115 }
1116#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001117#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001118 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1119 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001120 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001121#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001122#ifdef CONFIG_FST
1123 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1124 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1125 return;
1126 }
1127#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001128#ifdef CONFIG_DPP
1129 if (plen >= 1 + 4 &&
1130 mgmt->u.action.u.vs_public_action.action ==
1131 WLAN_PA_VENDOR_SPECIFIC &&
1132 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1133 OUI_WFA &&
1134 mgmt->u.action.u.vs_public_action.variable[0] ==
1135 DPP_OUI_TYPE) {
1136 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001137
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001138 pos = mgmt->u.action.u.vs_public_action.oui;
1139 end = drv_mgmt->frame + drv_mgmt->frame_len;
1140 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1141 drv_mgmt->freq);
1142 return;
1143 }
1144#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001145}
1146
1147
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001148#ifdef NEED_AP_MLME
1149
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1151
1152static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1153 const u8 *bssid)
1154{
1155 size_t i;
1156
1157 if (bssid == NULL)
1158 return NULL;
1159 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1160 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1161 return HAPD_BROADCAST;
1162
1163 for (i = 0; i < iface->num_bss; i++) {
1164 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1165 return iface->bss[i];
1166 }
1167
1168 return NULL;
1169}
1170
1171
1172static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001173 const u8 *bssid, const u8 *addr,
1174 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001175{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001176 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177 if (hapd == NULL || hapd == HAPD_BROADCAST)
1178 return;
1179
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001180 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001181}
1182
1183
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001184static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001185{
1186 struct hostapd_iface *iface = hapd->iface;
1187 const struct ieee80211_hdr *hdr;
1188 const u8 *bssid;
1189 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001190 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001191
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001192#ifdef CONFIG_TESTING_OPTIONS
1193 if (hapd->ext_mgmt_frame_handling) {
1194 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1195 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001196
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001197 if (hex) {
1198 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1199 rx_mgmt->frame_len);
1200 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1201 os_free(hex);
1202 }
1203 return 1;
1204 }
1205#endif /* CONFIG_TESTING_OPTIONS */
1206
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1208 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1209 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001210 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001211
1212 hapd = get_hapd_bssid(iface, bssid);
1213 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001214 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001215
1216 /*
1217 * Drop frames to unknown BSSIDs except for Beacon frames which
1218 * could be used to update neighbor information.
1219 */
1220 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1221 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1222 hapd = iface->bss[0];
1223 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001224 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001225 }
1226
1227 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001228 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001229 fi.datarate = rx_mgmt->datarate;
1230 fi.ssi_signal = rx_mgmt->ssi_signal;
1231
1232 if (hapd == HAPD_BROADCAST) {
1233 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001234
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001235 ret = 0;
1236 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001237 /* if bss is set, driver will call this function for
1238 * each bss individually. */
1239 if (rx_mgmt->drv_priv &&
1240 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1241 continue;
1242
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001243 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1244 rx_mgmt->frame_len, &fi) > 0)
1245 ret = 1;
1246 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001247 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001248 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1249 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001250
1251 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001253 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001254}
1255
1256
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001257static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1258 size_t len, u16 stype, int ok)
1259{
1260 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001261 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001262
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001263 hdr = (struct ieee80211_hdr *) buf;
1264 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001265 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001266 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001267 if (hapd == HAPD_BROADCAST) {
1268 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1269 buf[24] != WLAN_ACTION_PUBLIC)
1270 return;
1271 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1272 if (!hapd || hapd == HAPD_BROADCAST)
1273 return;
1274 /*
1275 * Allow processing of TX status for a Public Action frame that
1276 * used wildcard BBSID.
1277 */
1278 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001279 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1280}
1281
1282#endif /* NEED_AP_MLME */
1283
1284
1285static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1286{
1287 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001288
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001289 if (sta)
1290 return 0;
1291
1292 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1293 " - adding a new STA", MAC2STR(addr));
1294 sta = ap_sta_add(hapd, addr);
1295 if (sta) {
1296 hostapd_new_assoc_sta(hapd, sta, 0);
1297 } else {
1298 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1299 MAC2STR(addr));
1300 return -1;
1301 }
1302
1303 return 0;
1304}
1305
1306
1307static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1308 const u8 *data, size_t data_len)
1309{
1310 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001311 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001312 size_t j;
1313
1314 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001315 sta = ap_get_sta(iface->bss[j], src);
1316 if (sta && sta->flags & WLAN_STA_ASSOC) {
1317 hapd = iface->bss[j];
1318 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319 }
1320 }
1321
1322 ieee802_1x_receive(hapd, src, data, data_len);
1323}
1324
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001325#endif /* HOSTAPD */
1326
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001327
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001328static struct hostapd_channel_data * hostapd_get_mode_channel(
1329 struct hostapd_iface *iface, unsigned int freq)
1330{
1331 int i;
1332 struct hostapd_channel_data *chan;
1333
1334 for (i = 0; i < iface->current_mode->num_channels; i++) {
1335 chan = &iface->current_mode->channels[i];
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001336 if ((unsigned int) chan->freq == freq)
1337 return chan;
1338 }
1339
1340 return NULL;
1341}
1342
1343
1344static void hostapd_update_nf(struct hostapd_iface *iface,
1345 struct hostapd_channel_data *chan,
1346 struct freq_survey *survey)
1347{
1348 if (!iface->chans_surveyed) {
1349 chan->min_nf = survey->nf;
1350 iface->lowest_nf = survey->nf;
1351 } else {
1352 if (dl_list_empty(&chan->survey_list))
1353 chan->min_nf = survey->nf;
1354 else if (survey->nf < chan->min_nf)
1355 chan->min_nf = survey->nf;
1356 if (survey->nf < iface->lowest_nf)
1357 iface->lowest_nf = survey->nf;
1358 }
1359}
1360
1361
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001362static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1363 struct survey_results *survey_res)
1364{
1365 struct hostapd_channel_data *chan;
1366 struct freq_survey *survey;
1367 u64 divisor, dividend;
1368
1369 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1370 list);
1371 if (!survey || !survey->freq)
1372 return;
1373
1374 chan = hostapd_get_mode_channel(iface, survey->freq);
1375 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1376 return;
1377
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001378 wpa_printf(MSG_DEBUG,
1379 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001380 survey->freq,
1381 (unsigned long int) survey->channel_time,
1382 (unsigned long int) survey->channel_time_busy);
1383
1384 if (survey->channel_time > iface->last_channel_time &&
1385 survey->channel_time > survey->channel_time_busy) {
1386 dividend = survey->channel_time_busy -
1387 iface->last_channel_time_busy;
1388 divisor = survey->channel_time - iface->last_channel_time;
1389
1390 iface->channel_utilization = dividend * 255 / divisor;
1391 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1392 iface->channel_utilization);
1393 }
1394 iface->last_channel_time = survey->channel_time;
1395 iface->last_channel_time_busy = survey->channel_time_busy;
1396}
1397
1398
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001399void hostapd_event_get_survey(struct hostapd_iface *iface,
1400 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001401{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001402 struct freq_survey *survey, *tmp;
1403 struct hostapd_channel_data *chan;
1404
1405 if (dl_list_empty(&survey_results->survey_list)) {
1406 wpa_printf(MSG_DEBUG, "No survey data received");
1407 return;
1408 }
1409
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001410 if (survey_results->freq_filter) {
1411 hostapd_single_channel_get_survey(iface, survey_results);
1412 return;
1413 }
1414
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001415 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1416 struct freq_survey, list) {
1417 chan = hostapd_get_mode_channel(iface, survey->freq);
1418 if (!chan)
1419 continue;
1420 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1421 continue;
1422
1423 dl_list_del(&survey->list);
1424 dl_list_add_tail(&chan->survey_list, &survey->list);
1425
1426 hostapd_update_nf(iface, chan, survey);
1427
1428 iface->chans_surveyed++;
1429 }
1430}
1431
1432
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001433#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001434#ifdef NEED_AP_MLME
1435
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001436static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1437{
1438 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1439 hapd->conf->iface);
1440
1441 if (hapd->csa_in_progress) {
1442 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1443 hapd->conf->iface);
1444 hostapd_switch_channel_fallback(hapd->iface,
1445 &hapd->cs_freq_params);
1446 }
1447}
1448
1449
Dmitry Shmidt051af732013-10-22 13:52:46 -07001450static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1451 struct dfs_event *radar)
1452{
1453 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001454 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001455 radar->chan_offset, radar->chan_width,
1456 radar->cf1, radar->cf2);
1457}
1458
1459
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001460static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1461 struct dfs_event *radar)
1462{
1463 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1464 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1465 radar->chan_offset, radar->chan_width,
1466 radar->cf1, radar->cf2);
1467}
1468
1469
Dmitry Shmidt051af732013-10-22 13:52:46 -07001470static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1471 struct dfs_event *radar)
1472{
1473 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001474 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001475 radar->chan_offset, radar->chan_width,
1476 radar->cf1, radar->cf2);
1477}
1478
1479
1480static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1481 struct dfs_event *radar)
1482{
1483 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001484 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001485 radar->chan_offset, radar->chan_width,
1486 radar->cf1, radar->cf2);
1487}
1488
1489
1490static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1491 struct dfs_event *radar)
1492{
1493 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001494 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001495 radar->chan_offset, radar->chan_width,
1496 radar->cf1, radar->cf2);
1497}
1498
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001499
1500static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1501 struct dfs_event *radar)
1502{
1503 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1504 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1505 radar->chan_offset, radar->chan_width,
1506 radar->cf1, radar->cf2);
1507}
1508
Dmitry Shmidt051af732013-10-22 13:52:46 -07001509#endif /* NEED_AP_MLME */
1510
1511
Roshan Pius3a1667e2018-07-03 15:17:14 -07001512static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1513 int istatus,
1514 const char *ifname,
1515 const u8 *addr)
1516{
1517 struct sta_info *sta = ap_get_sta(hapd, addr);
1518
1519 if (sta) {
1520 os_free(sta->ifname_wds);
1521 if (istatus == INTERFACE_ADDED)
1522 sta->ifname_wds = os_strdup(ifname);
1523 else
1524 sta->ifname_wds = NULL;
1525 }
1526
1527 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1528 istatus == INTERFACE_ADDED ?
1529 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1530 ifname, MAC2STR(addr));
1531}
1532
1533
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001534void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1535 union wpa_event_data *data)
1536{
1537 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001538#ifndef CONFIG_NO_STDOUT_DEBUG
1539 int level = MSG_DEBUG;
1540
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001541 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001542 data->rx_mgmt.frame_len >= 24) {
1543 const struct ieee80211_hdr *hdr;
1544 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001545
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001546 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1547 fc = le_to_host16(hdr->frame_control);
1548 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1549 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1550 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001551 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1552 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1553 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001554 }
1555
1556 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1557 event_to_string(event), event);
1558#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001559
1560 switch (event) {
1561 case EVENT_MICHAEL_MIC_FAILURE:
1562 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1563 break;
1564 case EVENT_SCAN_RESULTS:
1565 if (hapd->iface->scan_cb)
1566 hapd->iface->scan_cb(hapd->iface);
1567 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001568 case EVENT_WPS_BUTTON_PUSHED:
1569 hostapd_wps_button_pushed(hapd, NULL);
1570 break;
1571#ifdef NEED_AP_MLME
1572 case EVENT_TX_STATUS:
1573 switch (data->tx_status.type) {
1574 case WLAN_FC_TYPE_MGMT:
1575 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1576 data->tx_status.data_len,
1577 data->tx_status.stype,
1578 data->tx_status.ack);
1579 break;
1580 case WLAN_FC_TYPE_DATA:
1581 hostapd_tx_status(hapd, data->tx_status.dst,
1582 data->tx_status.data,
1583 data->tx_status.data_len,
1584 data->tx_status.ack);
1585 break;
1586 }
1587 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001588 case EVENT_EAPOL_TX_STATUS:
1589 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1590 data->eapol_tx_status.data,
1591 data->eapol_tx_status.data_len,
1592 data->eapol_tx_status.ack);
1593 break;
1594 case EVENT_DRIVER_CLIENT_POLL_OK:
1595 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1596 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001597 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001598 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1599 data->rx_from_unknown.addr,
1600 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001601 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001602#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001603 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001604 if (!data->rx_mgmt.frame)
1605 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001606#ifdef NEED_AP_MLME
1607 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1608 break;
1609#endif /* NEED_AP_MLME */
1610 hostapd_action_rx(hapd, &data->rx_mgmt);
1611 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001612 case EVENT_RX_PROBE_REQ:
1613 if (data->rx_probe_req.sa == NULL ||
1614 data->rx_probe_req.ie == NULL)
1615 break;
1616 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001617 data->rx_probe_req.da,
1618 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001619 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001620 data->rx_probe_req.ie_len,
1621 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001622 break;
1623 case EVENT_NEW_STA:
1624 hostapd_event_new_sta(hapd, data->new_sta.addr);
1625 break;
1626 case EVENT_EAPOL_RX:
1627 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1628 data->eapol_rx.data,
1629 data->eapol_rx.data_len);
1630 break;
1631 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001632 if (!data)
1633 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001634 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1635 data->assoc_info.req_ies,
1636 data->assoc_info.req_ies_len,
1637 data->assoc_info.reassoc);
1638 break;
1639 case EVENT_DISASSOC:
1640 if (data)
1641 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1642 break;
1643 case EVENT_DEAUTH:
1644 if (data)
1645 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1646 break;
1647 case EVENT_STATION_LOW_ACK:
1648 if (!data)
1649 break;
1650 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1651 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001652 case EVENT_AUTH:
1653 hostapd_notif_auth(hapd, &data->auth);
1654 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001655 case EVENT_CH_SWITCH:
1656 if (!data)
1657 break;
1658 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1659 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001660 data->ch_switch.ch_offset,
1661 data->ch_switch.ch_width,
1662 data->ch_switch.cf1,
1663 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001664 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001665 case EVENT_CONNECT_FAILED_REASON:
1666 if (!data)
1667 break;
1668 hostapd_event_connect_failed_reason(
1669 hapd, data->connect_failed_reason.addr,
1670 data->connect_failed_reason.code);
1671 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001672 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001673 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001674 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001675#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001676 case EVENT_INTERFACE_UNAVAILABLE:
1677 hostapd_event_iface_unavailable(hapd);
1678 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001679 case EVENT_DFS_RADAR_DETECTED:
1680 if (!data)
1681 break;
1682 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1683 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001684 case EVENT_DFS_PRE_CAC_EXPIRED:
1685 if (!data)
1686 break;
1687 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1688 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001689 case EVENT_DFS_CAC_FINISHED:
1690 if (!data)
1691 break;
1692 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1693 break;
1694 case EVENT_DFS_CAC_ABORTED:
1695 if (!data)
1696 break;
1697 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1698 break;
1699 case EVENT_DFS_NOP_FINISHED:
1700 if (!data)
1701 break;
1702 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1703 break;
1704 case EVENT_CHANNEL_LIST_CHANGED:
1705 /* channel list changed (regulatory?), update channel list */
1706 /* TODO: check this. hostapd_get_hw_features() initializes
1707 * too much stuff. */
1708 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001709 hostapd_channel_list_updated(
1710 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001711 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001712 case EVENT_DFS_CAC_STARTED:
1713 if (!data)
1714 break;
1715 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1716 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001717#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001718 case EVENT_INTERFACE_ENABLED:
1719 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001720 if (hapd->disabled && hapd->started) {
1721 hapd->disabled = 0;
1722 /*
1723 * Try to re-enable interface if the driver stopped it
1724 * when the interface got disabled.
1725 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07001726 if (hapd->wpa_auth)
1727 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1728 else
1729 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001730 hapd->reenable_beacon = 1;
1731 ieee802_11_set_beacon(hapd);
Hai Shalom74f70d42019-02-11 14:42:39 -08001732#ifdef NEED_AP_MLME
1733 } else if (hapd->disabled && hapd->iface->cac_started) {
1734 wpa_printf(MSG_DEBUG, "DFS: restarting pending CAC");
1735 hostapd_handle_dfs(hapd->iface);
1736#endif /* NEED_AP_MLME */
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001737 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001738 break;
1739 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001740 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001741 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001742 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001743 break;
1744#ifdef CONFIG_ACS
1745 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001746 hostapd_acs_channel_selected(hapd,
1747 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001748 break;
1749#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001750 case EVENT_STATION_OPMODE_CHANGED:
1751 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
1752 data->sta_opmode.smps_mode,
1753 data->sta_opmode.chan_width,
1754 data->sta_opmode.rx_nss);
1755 break;
1756 case EVENT_WDS_STA_INTERFACE_STATUS:
1757 hostapd_event_wds_sta_interface_status(
1758 hapd, data->wds_sta_interface.istatus,
1759 data->wds_sta_interface.ifname,
1760 data->wds_sta_interface.sta_addr);
1761 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001762 default:
1763 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1764 break;
1765 }
1766}
1767
Dmitry Shmidte4663042016-04-04 10:07:49 -07001768
1769void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
1770 union wpa_event_data *data)
1771{
1772 struct hapd_interfaces *interfaces = ctx;
1773 struct hostapd_data *hapd;
1774
1775 if (event != EVENT_INTERFACE_STATUS)
1776 return;
1777
1778 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
1779 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
1780 hapd->drv_priv) {
1781 unsigned int ifindex;
1782
1783 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
1784 if (ifindex != data->interface_status.ifindex) {
1785 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1786 "interface status ifindex %d mismatch (%d)",
1787 ifindex, data->interface_status.ifindex);
1788 return;
1789 }
1790 }
1791 if (hapd)
1792 wpa_supplicant_event(hapd, event, data);
1793}
1794
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001795#endif /* HOSTAPD */