blob: 1135aea33ac6e74bc6d57f32674a679701fe96ae [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"
41
42
43#ifdef CONFIG_FILS
44void hostapd_notify_assoc_fils_finish(struct hostapd_data *hapd,
45 struct sta_info *sta)
46{
47 u16 reply_res = WLAN_STATUS_SUCCESS;
48 struct ieee802_11_elems elems;
49 u8 buf[IEEE80211_MAX_MMPDU_SIZE], *p = buf;
50 int new_assoc;
51
52 wpa_printf(MSG_DEBUG, "%s FILS: Finish association with " MACSTR,
53 __func__, MAC2STR(sta->addr));
54 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
55 if (!sta->fils_pending_assoc_req)
56 return;
57
58 ieee802_11_parse_elems(sta->fils_pending_assoc_req,
59 sta->fils_pending_assoc_req_len, &elems, 0);
60 if (!elems.fils_session) {
61 wpa_printf(MSG_DEBUG, "%s failed to find FILS Session element",
62 __func__);
63 return;
64 }
65
66 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
67 elems.fils_session,
68 sta->fils_hlp_resp);
69
70 reply_res = hostapd_sta_assoc(hapd, sta->addr,
71 sta->fils_pending_assoc_is_reassoc,
72 WLAN_STATUS_SUCCESS,
73 buf, p - buf);
74 ap_sta_set_authorized(hapd, sta, 1);
75 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
76 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
77 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
78 hostapd_set_sta_flags(hapd, sta);
79 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
80 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
81 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
82 os_free(sta->fils_pending_assoc_req);
83 sta->fils_pending_assoc_req = NULL;
84 sta->fils_pending_assoc_req_len = 0;
85 wpabuf_free(sta->fils_hlp_resp);
86 sta->fils_hlp_resp = NULL;
87 wpabuf_free(sta->hlp_dhcp_discover);
88 sta->hlp_dhcp_discover = NULL;
89 fils_hlp_deinit(hapd);
90
91 /*
92 * Remove the station in case transmission of a success response fails
93 * (the STA was added associated to the driver) or if the station was
94 * previously added unassociated.
95 */
96 if (reply_res != WLAN_STATUS_SUCCESS || sta->added_unassoc) {
97 hostapd_drv_sta_remove(hapd, sta->addr);
98 sta->added_unassoc = 0;
99 }
100}
101#endif /* CONFIG_FILS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102
103
104int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800105 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700106{
107 struct sta_info *sta;
108 int new_assoc, res;
109 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800110 const u8 *ie;
111 size_t ielen;
Hai Shalomce48b4a2018-09-05 11:41:35 -0700112#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_IEEE80211W) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700113 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
114 u8 *p = buf;
Hai Shalomce48b4a2018-09-05 11:41:35 -0700115#endif /* CONFIG_IEEE80211R_AP || CONFIG_IEEE80211W || CONFIG_FILS || CONFIG_OWE */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800116 u16 reason = WLAN_REASON_UNSPECIFIED;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700117 u16 status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700118 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700119
120 if (addr == NULL) {
121 /*
122 * This could potentially happen with unexpected event from the
123 * driver wrapper. This was seen at least in one case where the
124 * driver ended up being set to station mode while hostapd was
125 * running, so better make sure we stop processing such an
126 * event here.
127 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800128 wpa_printf(MSG_DEBUG,
129 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700130 return -1;
131 }
132 random_add_randomness(addr, ETH_ALEN);
133
134 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
135 HOSTAPD_LEVEL_INFO, "associated");
136
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800137 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700138 if (elems.wps_ie) {
139 ie = elems.wps_ie - 2;
140 ielen = elems.wps_ie_len + 2;
141 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
142 } else if (elems.rsn_ie) {
143 ie = elems.rsn_ie - 2;
144 ielen = elems.rsn_ie_len + 2;
145 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
146 } else if (elems.wpa_ie) {
147 ie = elems.wpa_ie - 2;
148 ielen = elems.wpa_ie_len + 2;
149 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800150#ifdef CONFIG_HS20
151 } else if (elems.osen) {
152 ie = elems.osen - 2;
153 ielen = elems.osen_len + 2;
154 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
155#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700156 } else {
157 ie = NULL;
158 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800159 wpa_printf(MSG_DEBUG,
160 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700161 }
162
163 sta = ap_get_sta(hapd, addr);
164 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700165 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700166 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700167
168 /*
169 * Make sure that the previously registered inactivity timer
170 * will not remove the STA immediately.
171 */
172 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173 } else {
174 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700175 if (sta == NULL) {
176 hostapd_drv_sta_disassoc(hapd, addr,
177 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700179 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700180 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800181 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700182
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700183 /*
184 * ACL configurations to the drivers (implementing AP SME and ACL
185 * offload) without hostapd's knowledge, can result in a disconnection
186 * though the driver accepts the connection. Skip the hostapd check for
187 * ACL if the driver supports ACL offload to avoid potentially
188 * conflicting ACL rules.
189 */
190 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
191 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800192 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
193 MAC2STR(addr));
194 reason = WLAN_REASON_UNSPECIFIED;
195 goto fail;
196 }
197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198#ifdef CONFIG_P2P
199 if (elems.p2p) {
200 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800201 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700202 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700203 if (sta->p2p_ie)
204 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 }
206#endif /* CONFIG_P2P */
207
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700208#ifdef CONFIG_IEEE80211N
209#ifdef NEED_AP_MLME
210 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700211 (hapd->iface->conf->ht_capab &
212 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
213 struct ieee80211_ht_capabilities *ht_cap =
214 (struct ieee80211_ht_capabilities *)
215 elems.ht_capabilities;
216
217 if (le_to_host16(ht_cap->ht_capabilities_info) &
218 HT_CAP_INFO_40MHZ_INTOLERANT)
219 ht40_intolerant_add(hapd->iface, sta);
220 }
221#endif /* NEED_AP_MLME */
222#endif /* CONFIG_IEEE80211N */
223
Dmitry Shmidt051af732013-10-22 13:52:46 -0700224#ifdef CONFIG_INTERWORKING
225 if (elems.ext_capab && elems.ext_capab_len > 4) {
226 if (elems.ext_capab[4] & 0x01)
227 sta->qos_map_enabled = 1;
228 }
229#endif /* CONFIG_INTERWORKING */
230
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800231#ifdef CONFIG_HS20
232 wpabuf_free(sta->hs20_ie);
233 if (elems.hs20 && elems.hs20_len > 4) {
234 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
235 elems.hs20_len - 4);
236 } else
237 sta->hs20_ie = NULL;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700238
239 wpabuf_free(sta->roaming_consortium);
240 if (elems.roaming_cons_sel)
241 sta->roaming_consortium = wpabuf_alloc_copy(
242 elems.roaming_cons_sel + 4,
243 elems.roaming_cons_sel_len - 4);
244 else
245 sta->roaming_consortium = NULL;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800246#endif /* CONFIG_HS20 */
247
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800248#ifdef CONFIG_FST
249 wpabuf_free(sta->mb_ies);
250 if (hapd->iface->fst)
251 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
252 else
253 sta->mb_ies = NULL;
254#endif /* CONFIG_FST */
255
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800256 mbo_ap_check_sta_assoc(hapd, sta, &elems);
257
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800258 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
259 elems.supp_op_classes_len);
260
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700261 if (hapd->conf->wpa) {
262 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800263#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800265 wpa_printf(MSG_DEBUG,
266 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700267 sta->flags |= WLAN_STA_MAYBE_WPS;
268 goto skip_wpa_check;
269 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800270#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700271
272 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
Roshan Pius3a1667e2018-07-03 15:17:14 -0700273 reason = WLAN_REASON_INVALID_IE;
274 status = WLAN_STATUS_INVALID_IE;
275 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700276 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800277#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700278 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
279 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800280 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800281
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700282 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800283 wps = ieee802_11_vendor_ie_concat(ie, ielen,
284 WPS_IE_VENDOR_TYPE);
285 if (wps) {
286 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800287 wpa_printf(MSG_DEBUG,
288 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800289 sta->flags |= WLAN_STA_WPS2;
290 }
291 wpabuf_free(wps);
292 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700293 goto skip_wpa_check;
294 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800295#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700296
297 if (sta->wpa_sm == NULL)
298 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700299 sta->addr,
300 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800302 wpa_printf(MSG_ERROR,
303 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 return -1;
305 }
306 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700307 ie, ielen,
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700308 elems.mdie, elems.mdie_len,
309 elems.owe_dh, elems.owe_dh_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700310 if (res != WPA_IE_OK) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800311 wpa_printf(MSG_DEBUG,
312 "WPA/RSN information element rejected? (res %u)",
313 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700315 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800316 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700317 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
318 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800319 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700320 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
321 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800322 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700323 status = WLAN_STATUS_AKMP_NOT_VALID;
324 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325#ifdef CONFIG_IEEE80211W
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700326 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800327 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700328 status = WLAN_STATUS_INVALID_IE;
329 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Roshan Pius3a1667e2018-07-03 15:17:14 -0700330 reason = WLAN_REASON_CIPHER_SUITE_REJECTED;
331 status = WLAN_STATUS_CIPHER_REJECTED_PER_POLICY;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700332 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700333#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700334 else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800335 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700336 status = WLAN_STATUS_INVALID_IE;
337 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800338 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700339 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700340#ifdef CONFIG_IEEE80211W
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800341 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
342 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
343 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700344 sta->sa_query_count > 0)
345 ap_check_sa_query_timeout(hapd, sta);
Hai Shalom39ba6fc2019-01-22 12:40:38 -0800346 if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) ==
347 (WLAN_STA_ASSOC | WLAN_STA_MFP) &&
348 !sta->sa_query_timed_out &&
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700349 (sta->auth_alg != WLAN_AUTH_FT)) {
350 /*
351 * STA has already been associated with MFP and SA
352 * Query timeout has not been reached. Reject the
353 * association attempt temporarily and start SA Query,
354 * if one is not pending.
355 */
356
357 if (sta->sa_query_count == 0)
358 ap_sta_start_sa_query(hapd, sta);
359
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700360 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
361
362 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
363
364 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
365 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700366 return 0;
367 }
368
369 if (wpa_auth_uses_mfp(sta->wpa_sm))
370 sta->flags |= WLAN_STA_MFP;
371 else
372 sta->flags &= ~WLAN_STA_MFP;
373#endif /* CONFIG_IEEE80211W */
374
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800375#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700376 if (sta->auth_alg == WLAN_AUTH_FT) {
377 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
378 req_ies_len);
379 if (status != WLAN_STATUS_SUCCESS) {
380 if (status == WLAN_STATUS_INVALID_PMKID)
381 reason = WLAN_REASON_INVALID_IE;
382 if (status == WLAN_STATUS_INVALID_MDIE)
383 reason = WLAN_REASON_INVALID_IE;
384 if (status == WLAN_STATUS_INVALID_FTIE)
385 reason = WLAN_REASON_INVALID_IE;
386 goto fail;
387 }
388 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800389#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800391#ifdef CONFIG_WPS
392 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800393
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800394 if (req_ies)
395 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700396 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800397 else
398 wps = NULL;
399#ifdef CONFIG_WPS_STRICT
400 if (wps && wps_validate_assoc_req(wps) < 0) {
401 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700402 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700403 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800404 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700405 }
406#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800407 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700408 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800409 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800410 wpa_printf(MSG_DEBUG,
411 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800412 sta->flags |= WLAN_STA_WPS2;
413 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700414 } else
415 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800416 wpabuf_free(wps);
417#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800418#ifdef CONFIG_HS20
419 } else if (hapd->conf->osen) {
420 if (elems.osen == NULL) {
421 hostapd_logger(
422 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
423 HOSTAPD_LEVEL_INFO,
424 "No HS 2.0 OSEN element in association request");
425 return WLAN_STATUS_INVALID_IE;
426 }
427
428 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
429 if (sta->wpa_sm == NULL)
430 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
431 sta->addr, NULL);
432 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800433 wpa_printf(MSG_WARNING,
434 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800435 return WLAN_STATUS_UNSPECIFIED_FAILURE;
436 }
437 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
438 elems.osen - 2, elems.osen_len + 2) < 0)
439 return WLAN_STATUS_INVALID_IE;
440#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800442
443#ifdef CONFIG_MBO
444 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
445 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
446 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
447 wpa_printf(MSG_INFO,
448 "MBO: Reject WPA2 association without PMF");
449 return WLAN_STATUS_UNSPECIFIED_FAILURE;
450 }
451#endif /* CONFIG_MBO */
452
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800453#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700454skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800455#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800457#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700458 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
459 sta->auth_alg, req_ies, req_ies_len);
Roshan Pius3a1667e2018-07-03 15:17:14 -0700460 if (!p) {
461 wpa_printf(MSG_DEBUG, "FT: Failed to write AssocResp IEs");
462 return WLAN_STATUS_UNSPECIFIED_FAILURE;
463 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700464#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700465
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700466#ifdef CONFIG_FILS
467 if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
468 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
469 sta->auth_alg == WLAN_AUTH_FILS_PK) {
470 int delay_assoc = 0;
471
472 if (!req_ies)
473 return WLAN_STATUS_UNSPECIFIED_FAILURE;
474
475 if (!wpa_fils_validate_fils_session(sta->wpa_sm, req_ies,
476 req_ies_len,
477 sta->fils_session)) {
478 wpa_printf(MSG_DEBUG,
479 "FILS: Session validation failed");
480 return WLAN_STATUS_UNSPECIFIED_FAILURE;
481 }
482
483 res = wpa_fils_validate_key_confirm(sta->wpa_sm, req_ies,
484 req_ies_len);
485 if (res < 0) {
486 wpa_printf(MSG_DEBUG,
487 "FILS: Key Confirm validation failed");
488 return WLAN_STATUS_UNSPECIFIED_FAILURE;
489 }
490
491 if (fils_process_hlp(hapd, sta, req_ies, req_ies_len) > 0) {
492 wpa_printf(MSG_DEBUG,
493 "FILS: Delaying Assoc Response (HLP)");
494 delay_assoc = 1;
495 } else {
496 wpa_printf(MSG_DEBUG,
497 "FILS: Going ahead with Assoc Response (no HLP)");
498 }
499
500 if (sta) {
501 wpa_printf(MSG_DEBUG, "FILS: HLP callback cleanup");
502 eloop_cancel_timeout(fils_hlp_timeout, hapd, sta);
503 os_free(sta->fils_pending_assoc_req);
504 sta->fils_pending_assoc_req = NULL;
505 sta->fils_pending_assoc_req_len = 0;
506 wpabuf_free(sta->fils_hlp_resp);
507 sta->fils_hlp_resp = NULL;
508 sta->fils_drv_assoc_finish = 0;
509 }
510
511 if (sta && delay_assoc && status == WLAN_STATUS_SUCCESS) {
512 u8 *req_tmp;
513
514 req_tmp = os_malloc(req_ies_len);
515 if (!req_tmp) {
516 wpa_printf(MSG_DEBUG,
517 "FILS: buffer allocation failed for assoc req");
518 goto fail;
519 }
520 os_memcpy(req_tmp, req_ies, req_ies_len);
521 sta->fils_pending_assoc_req = req_tmp;
522 sta->fils_pending_assoc_req_len = req_ies_len;
523 sta->fils_pending_assoc_is_reassoc = reassoc;
524 sta->fils_drv_assoc_finish = 1;
525 wpa_printf(MSG_DEBUG,
526 "FILS: Waiting for HLP processing before sending (Re)Association Response frame to "
527 MACSTR, MAC2STR(sta->addr));
528 eloop_register_timeout(
529 0, hapd->conf->fils_hlp_wait_time * 1024,
530 fils_hlp_timeout, hapd, sta);
531 return 0;
532 }
533 p = hostapd_eid_assoc_fils_session(sta->wpa_sm, p,
534 elems.fils_session,
535 sta->fils_hlp_resp);
536 wpa_hexdump(MSG_DEBUG, "FILS Assoc Resp BUF (IEs)",
537 buf, p - buf);
538 }
539#endif /* CONFIG_FILS */
540
Roshan Pius3a1667e2018-07-03 15:17:14 -0700541#ifdef CONFIG_OWE
542 if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) &&
543 wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE &&
544 elems.owe_dh) {
545 u8 *npos;
546
547 npos = owe_assoc_req_process(hapd, sta,
548 elems.owe_dh, elems.owe_dh_len,
549 p, sizeof(buf) - (p - buf),
550 &reason);
551 if (npos)
552 p = npos;
553 if (!npos &&
554 reason == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) {
555 status = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED;
556 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
557 p - buf);
558 return 0;
559 }
560
561 if (!npos || reason != WLAN_STATUS_SUCCESS)
562 goto fail;
563 }
564#endif /* CONFIG_OWE */
565
566#if defined(CONFIG_IEEE80211R_AP) || defined(CONFIG_FILS) || defined(CONFIG_OWE)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700567 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700568
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700569 if (sta->auth_alg == WLAN_AUTH_FT ||
570 sta->auth_alg == WLAN_AUTH_FILS_SK ||
571 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
572 sta->auth_alg == WLAN_AUTH_FILS_PK)
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700573 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700574#else /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700575 /* Keep compiler silent about unused variables */
576 if (status) {
577 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700578#endif /* CONFIG_IEEE80211R_AP || CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700579
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700580 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
581 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800582 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700583
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700584 hostapd_set_sta_flags(hapd, sta);
585
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700586 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
587 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700588#ifdef CONFIG_FILS
589 else if (sta->auth_alg == WLAN_AUTH_FILS_SK ||
590 sta->auth_alg == WLAN_AUTH_FILS_SK_PFS ||
591 sta->auth_alg == WLAN_AUTH_FILS_PK)
592 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FILS);
593#endif /* CONFIG_FILS */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700594 else
595 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700596
597 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
598
599 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
600
601#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800602 if (req_ies) {
603 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
604 req_ies, req_ies_len);
605 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700606#endif /* CONFIG_P2P */
607
608 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800609
610fail:
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800611#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700612 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800613#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800614 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
615 ap_free_sta(hapd, sta);
616 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700617}
618
619
620void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
621{
622 struct sta_info *sta;
623
624 if (addr == NULL) {
625 /*
626 * This could potentially happen with unexpected event from the
627 * driver wrapper. This was seen at least in one case where the
628 * driver ended up reporting a station mode event while hostapd
629 * was running, so better make sure we stop processing such an
630 * event here.
631 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800632 wpa_printf(MSG_DEBUG,
633 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700634 return;
635 }
636
637 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
638 HOSTAPD_LEVEL_INFO, "disassociated");
639
640 sta = ap_get_sta(hapd, addr);
641 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800642 wpa_printf(MSG_DEBUG,
643 "Disassociation notification for unknown STA "
644 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 return;
646 }
647
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800648 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700649 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700650 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
651 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
652 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
653 ap_free_sta(hapd, sta);
654}
655
656
657void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
658{
659 struct sta_info *sta = ap_get_sta(hapd, addr);
660
Roshan Pius3a1667e2018-07-03 15:17:14 -0700661 if (!sta || !hapd->conf->disassoc_low_ack || sta->agreed_to_steer)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700662 return;
663
664 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800665 HOSTAPD_LEVEL_INFO,
666 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700667 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800668 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700669}
670
671
Roshan Pius3a1667e2018-07-03 15:17:14 -0700672void hostapd_event_sta_opmode_changed(struct hostapd_data *hapd, const u8 *addr,
673 enum smps_mode smps_mode,
674 enum chan_width chan_width, u8 rx_nss)
675{
676 struct sta_info *sta = ap_get_sta(hapd, addr);
677 const char *txt;
678
679 if (!sta)
680 return;
681
682 switch (smps_mode) {
683 case SMPS_AUTOMATIC:
684 txt = "automatic";
685 break;
686 case SMPS_OFF:
687 txt = "off";
688 break;
689 case SMPS_DYNAMIC:
690 txt = "dynamic";
691 break;
692 case SMPS_STATIC:
693 txt = "static";
694 break;
695 default:
696 txt = NULL;
697 break;
698 }
699 if (txt) {
700 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_SMPS_MODE_CHANGED
701 MACSTR " %s", MAC2STR(addr), txt);
702 }
703
704 switch (chan_width) {
705 case CHAN_WIDTH_20_NOHT:
706 txt = "20(no-HT)";
707 break;
708 case CHAN_WIDTH_20:
709 txt = "20";
710 break;
711 case CHAN_WIDTH_40:
712 txt = "40";
713 break;
714 case CHAN_WIDTH_80:
715 txt = "80";
716 break;
717 case CHAN_WIDTH_80P80:
718 txt = "80+80";
719 break;
720 case CHAN_WIDTH_160:
721 txt = "160";
722 break;
723 default:
724 txt = NULL;
725 break;
726 }
727 if (txt) {
728 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_MAX_BW_CHANGED
729 MACSTR " %s", MAC2STR(addr), txt);
730 }
731
732 if (rx_nss != 0xff) {
733 wpa_msg(hapd->msg_ctx, MSG_INFO, STA_OPMODE_N_SS_CHANGED
734 MACSTR " %d", MAC2STR(addr), rx_nss);
735 }
736}
737
738
Dmitry Shmidt04949592012-07-19 12:16:46 -0700739void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800740 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700741{
742#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800743 int channel, chwidth, is_dfs;
744 u8 seg0_idx = 0, seg1_idx = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700745
746 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800747 HOSTAPD_LEVEL_INFO,
Roshan Pius3a1667e2018-07-03 15:17:14 -0700748 "driver had channel switch: freq=%d, ht=%d, vht_ch=0x%x, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
749 freq, ht, hapd->iconf->ch_switch_vht_config, offset,
750 width, channel_width_to_string(width), cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700751
752 hapd->iface->freq = freq;
753
754 channel = hostapd_hw_get_channel(hapd, freq);
755 if (!channel) {
756 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800757 HOSTAPD_LEVEL_WARNING,
758 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700759 return;
760 }
761
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800762 switch (width) {
763 case CHAN_WIDTH_80:
764 chwidth = VHT_CHANWIDTH_80MHZ;
765 break;
766 case CHAN_WIDTH_80P80:
767 chwidth = VHT_CHANWIDTH_80P80MHZ;
768 break;
769 case CHAN_WIDTH_160:
770 chwidth = VHT_CHANWIDTH_160MHZ;
771 break;
772 case CHAN_WIDTH_20_NOHT:
773 case CHAN_WIDTH_20:
774 case CHAN_WIDTH_40:
775 default:
776 chwidth = VHT_CHANWIDTH_USE_HT;
777 break;
778 }
779
780 switch (hapd->iface->current_mode->mode) {
781 case HOSTAPD_MODE_IEEE80211A:
782 if (cf1 > 5000)
783 seg0_idx = (cf1 - 5000) / 5;
784 if (cf2 > 5000)
785 seg1_idx = (cf2 - 5000) / 5;
786 break;
787 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800788 ieee80211_freq_to_chan(cf1, &seg0_idx);
789 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800790 break;
791 }
792
Dmitry Shmidt04949592012-07-19 12:16:46 -0700793 hapd->iconf->channel = channel;
794 hapd->iconf->ieee80211n = ht;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700795 if (!ht) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800796 hapd->iconf->ieee80211ac = 0;
Roshan Pius3a1667e2018-07-03 15:17:14 -0700797 } else if (hapd->iconf->ch_switch_vht_config) {
798 /* CHAN_SWITCH VHT config */
799 if (hapd->iconf->ch_switch_vht_config &
800 CH_SWITCH_VHT_ENABLED)
801 hapd->iconf->ieee80211ac = 1;
802 else if (hapd->iconf->ch_switch_vht_config &
803 CH_SWITCH_VHT_DISABLED)
804 hapd->iconf->ieee80211ac = 0;
805 }
806 hapd->iconf->ch_switch_vht_config = 0;
807
Dmitry Shmidt04949592012-07-19 12:16:46 -0700808 hapd->iconf->secondary_channel = offset;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800809 hapd->iconf->vht_oper_chwidth = chwidth;
810 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
811 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800812
Roshan Pius3a1667e2018-07-03 15:17:14 -0700813 is_dfs = ieee80211_is_dfs(freq, hapd->iface->hw_features,
814 hapd->iface->num_hw_features);
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800815
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700816 if (hapd->csa_in_progress &&
817 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800818 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700819 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800820
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800821 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
822 "freq=%d dfs=%d", freq, is_dfs);
823 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
824 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
825 "freq=%d dfs=%d", freq, is_dfs);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800826 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700827#endif /* NEED_AP_MLME */
828}
829
830
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800831void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
832 const u8 *addr, int reason_code)
833{
834 switch (reason_code) {
835 case MAX_CLIENT_REACHED:
836 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
837 MAC2STR(addr));
838 break;
839 case BLOCKED_CLIENT:
840 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
841 MAC2STR(addr));
842 break;
843 }
844}
845
846
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800847#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800848void hostapd_acs_channel_selected(struct hostapd_data *hapd,
849 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800850{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700851 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800852 int err = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800853
854 if (hapd->iconf->channel) {
855 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
856 hapd->iconf->channel);
857 return;
858 }
859
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700860 if (!hapd->iface->current_mode) {
861 for (i = 0; i < hapd->iface->num_hw_features; i++) {
862 struct hostapd_hw_modes *mode =
863 &hapd->iface->hw_features[i];
864
865 if (mode->mode == acs_res->hw_mode) {
866 hapd->iface->current_mode = mode;
867 break;
868 }
869 }
870 if (!hapd->iface->current_mode) {
871 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
872 HOSTAPD_LEVEL_WARNING,
873 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800874 err = 1;
875 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700876 }
877 }
878
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700879 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800880
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700881 if (!acs_res->pri_channel) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800882 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
883 HOSTAPD_LEVEL_WARNING,
884 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800885 err = 1;
886 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800887 }
888
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700889 hapd->iconf->channel = acs_res->pri_channel;
890 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800891
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700892 if (acs_res->sec_channel == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800893 hapd->iconf->secondary_channel = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700894 else if (acs_res->sec_channel < acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800895 hapd->iconf->secondary_channel = -1;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700896 else if (acs_res->sec_channel > acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800897 hapd->iconf->secondary_channel = 1;
898 else {
899 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800900 err = 1;
901 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800902 }
903
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700904 if (hapd->iface->conf->ieee80211ac) {
905 /* set defaults for backwards compatibility */
906 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
907 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
908 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
909 if (acs_res->ch_width == 80) {
910 hapd->iconf->vht_oper_centr_freq_seg0_idx =
911 acs_res->vht_seg0_center_ch;
912 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
913 } else if (acs_res->ch_width == 160) {
914 if (acs_res->vht_seg1_center_ch == 0) {
915 hapd->iconf->vht_oper_centr_freq_seg0_idx =
916 acs_res->vht_seg0_center_ch;
917 hapd->iconf->vht_oper_chwidth =
918 VHT_CHANWIDTH_160MHZ;
919 } else {
920 hapd->iconf->vht_oper_centr_freq_seg0_idx =
921 acs_res->vht_seg0_center_ch;
922 hapd->iconf->vht_oper_centr_freq_seg1_idx =
923 acs_res->vht_seg1_center_ch;
924 hapd->iconf->vht_oper_chwidth =
925 VHT_CHANWIDTH_80P80MHZ;
926 }
927 }
928 }
929
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800930out:
931 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800932 if (ret) {
933 wpa_printf(MSG_ERROR,
934 "ACS: Possibly channel configuration is invalid");
935 }
936}
937#endif /* CONFIG_ACS */
938
939
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800940int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700941 const u8 *bssid, const u8 *ie, size_t ie_len,
942 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700943{
944 size_t i;
945 int ret = 0;
946
947 if (sa == NULL || ie == NULL)
948 return -1;
949
950 random_add_randomness(sa, ETH_ALEN);
951 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
952 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700953 sa, da, bssid, ie, ie_len,
954 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700955 ret = 1;
956 break;
957 }
958 }
959 return ret;
960}
961
962
963#ifdef HOSTAPD
964
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800965#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700966static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
967 const u8 *bssid,
968 u16 auth_transaction, u16 status,
969 const u8 *ies, size_t ies_len)
970{
971 struct hostapd_data *hapd = ctx;
972 struct sta_info *sta;
973
974 sta = ap_get_sta(hapd, dst);
975 if (sta == NULL)
976 return;
977
978 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
979 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
980 sta->flags |= WLAN_STA_AUTH;
981
982 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
983}
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -0800984#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700985
986
Dmitry Shmidtd2986c22017-10-23 14:22:09 -0700987#ifdef CONFIG_FILS
988static void hostapd_notify_auth_fils_finish(struct hostapd_data *hapd,
989 struct sta_info *sta, u16 resp,
990 struct wpabuf *data, int pub)
991{
992 if (resp == WLAN_STATUS_SUCCESS) {
993 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
994 HOSTAPD_LEVEL_DEBUG, "authentication OK (FILS)");
995 sta->flags |= WLAN_STA_AUTH;
996 wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH);
997 sta->auth_alg = WLAN_AUTH_FILS_SK;
998 mlme_authenticate_indication(hapd, sta);
999 } else {
1000 hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
1001 HOSTAPD_LEVEL_DEBUG,
1002 "authentication failed (FILS)");
1003 }
1004
1005 hostapd_sta_auth(hapd, sta->addr, 2, resp,
1006 data ? wpabuf_head(data) : NULL,
1007 data ? wpabuf_len(data) : 0);
1008 wpabuf_free(data);
1009}
1010#endif /* CONFIG_FILS */
1011
1012
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001013static void hostapd_notif_auth(struct hostapd_data *hapd,
1014 struct auth_info *rx_auth)
1015{
1016 struct sta_info *sta;
1017 u16 status = WLAN_STATUS_SUCCESS;
1018 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
1019 size_t resp_ies_len = 0;
1020
1021 sta = ap_get_sta(hapd, rx_auth->peer);
1022 if (!sta) {
1023 sta = ap_sta_add(hapd, rx_auth->peer);
1024 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -07001025 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001026 goto fail;
1027 }
1028 }
1029 sta->flags &= ~WLAN_STA_PREAUTH;
1030 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001031#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001032 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
1033 sta->auth_alg = WLAN_AUTH_FT;
1034 if (sta->wpa_sm == NULL)
1035 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -07001036 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001037 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001038 wpa_printf(MSG_DEBUG,
1039 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001040 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
1041 goto fail;
1042 }
1043 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
1044 rx_auth->auth_transaction, rx_auth->ies,
1045 rx_auth->ies_len,
1046 hostapd_notify_auth_ft_finish, hapd);
1047 return;
1048 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001049#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001050
1051#ifdef CONFIG_FILS
1052 if (rx_auth->auth_type == WLAN_AUTH_FILS_SK) {
1053 sta->auth_alg = WLAN_AUTH_FILS_SK;
1054 handle_auth_fils(hapd, sta, rx_auth->ies, rx_auth->ies_len,
1055 rx_auth->auth_type, rx_auth->auth_transaction,
1056 rx_auth->status_code,
1057 hostapd_notify_auth_fils_finish);
1058 return;
1059 }
1060#endif /* CONFIG_FILS */
1061
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001062fail:
1063 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
1064 status, resp_ies, resp_ies_len);
1065}
1066
1067
1068static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001069 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001070{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001071 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001072 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001073 size_t plen __maybe_unused;
1074 u16 fc;
1075
1076 if (drv_mgmt->frame_len < 24 + 1)
1077 return;
1078
1079 plen = drv_mgmt->frame_len - 24 - 1;
1080
1081 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
1082 fc = le_to_host16(mgmt->frame_control);
1083 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
1084 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001085
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001086 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001087 mgmt->u.action.category, (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001088
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001089 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001090 if (sta == NULL) {
1091 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
1092 return;
1093 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001094#ifdef CONFIG_IEEE80211R_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001095 if (mgmt->u.action.category == WLAN_ACTION_FT) {
1096 const u8 *payload = drv_mgmt->frame + 24 + 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001097
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001098 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001099 }
Dmitry Shmidt9839ecd2016-11-07 11:05:47 -08001100#endif /* CONFIG_IEEE80211R_AP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001101#ifdef CONFIG_IEEE80211W
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001102 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
1103 ieee802_11_sa_query_action(
1104 hapd, mgmt->sa,
1105 mgmt->u.action.u.sa_query_resp.action,
1106 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001107 }
1108#endif /* CONFIG_IEEE80211W */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001109#ifdef CONFIG_WNM_AP
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001110 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
1111 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001112 }
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001113#endif /* CONFIG_WNM_AP */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001114#ifdef CONFIG_FST
1115 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
1116 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
1117 return;
1118 }
1119#endif /* CONFIG_FST */
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001120#ifdef CONFIG_DPP
1121 if (plen >= 1 + 4 &&
1122 mgmt->u.action.u.vs_public_action.action ==
1123 WLAN_PA_VENDOR_SPECIFIC &&
1124 WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) ==
1125 OUI_WFA &&
1126 mgmt->u.action.u.vs_public_action.variable[0] ==
1127 DPP_OUI_TYPE) {
1128 const u8 *pos, *end;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001129
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001130 pos = mgmt->u.action.u.vs_public_action.oui;
1131 end = drv_mgmt->frame + drv_mgmt->frame_len;
1132 hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos,
1133 drv_mgmt->freq);
1134 return;
1135 }
1136#endif /* CONFIG_DPP */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001137}
1138
1139
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001140#ifdef NEED_AP_MLME
1141
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001142#define HAPD_BROADCAST ((struct hostapd_data *) -1)
1143
1144static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
1145 const u8 *bssid)
1146{
1147 size_t i;
1148
1149 if (bssid == NULL)
1150 return NULL;
1151 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
1152 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
1153 return HAPD_BROADCAST;
1154
1155 for (i = 0; i < iface->num_bss; i++) {
1156 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
1157 return iface->bss[i];
1158 }
1159
1160 return NULL;
1161}
1162
1163
1164static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001165 const u8 *bssid, const u8 *addr,
1166 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001168 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001169 if (hapd == NULL || hapd == HAPD_BROADCAST)
1170 return;
1171
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001172 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001173}
1174
1175
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001176static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001177{
1178 struct hostapd_iface *iface = hapd->iface;
1179 const struct ieee80211_hdr *hdr;
1180 const u8 *bssid;
1181 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001182 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001184#ifdef CONFIG_TESTING_OPTIONS
1185 if (hapd->ext_mgmt_frame_handling) {
1186 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
1187 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001188
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -08001189 if (hex) {
1190 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
1191 rx_mgmt->frame_len);
1192 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
1193 os_free(hex);
1194 }
1195 return 1;
1196 }
1197#endif /* CONFIG_TESTING_OPTIONS */
1198
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001199 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
1200 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
1201 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001202 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001203
1204 hapd = get_hapd_bssid(iface, bssid);
1205 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001206 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207
1208 /*
1209 * Drop frames to unknown BSSIDs except for Beacon frames which
1210 * could be used to update neighbor information.
1211 */
1212 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1213 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1214 hapd = iface->bss[0];
1215 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001216 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 }
1218
1219 os_memset(&fi, 0, sizeof(fi));
Roshan Pius3a1667e2018-07-03 15:17:14 -07001220 fi.freq = rx_mgmt->freq;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001221 fi.datarate = rx_mgmt->datarate;
1222 fi.ssi_signal = rx_mgmt->ssi_signal;
1223
1224 if (hapd == HAPD_BROADCAST) {
1225 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001226
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001227 ret = 0;
1228 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -07001229 /* if bss is set, driver will call this function for
1230 * each bss individually. */
1231 if (rx_mgmt->drv_priv &&
1232 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
1233 continue;
1234
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001235 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
1236 rx_mgmt->frame_len, &fi) > 0)
1237 ret = 1;
1238 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001240 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
1241 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001242
1243 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001244
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001245 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -07001246}
1247
1248
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001249static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
1250 size_t len, u16 stype, int ok)
1251{
1252 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001253 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001254
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 hdr = (struct ieee80211_hdr *) buf;
1256 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001257 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001258 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -07001259 if (hapd == HAPD_BROADCAST) {
1260 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
1261 buf[24] != WLAN_ACTION_PUBLIC)
1262 return;
1263 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
1264 if (!hapd || hapd == HAPD_BROADCAST)
1265 return;
1266 /*
1267 * Allow processing of TX status for a Public Action frame that
1268 * used wildcard BBSID.
1269 */
1270 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001271 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
1272}
1273
1274#endif /* NEED_AP_MLME */
1275
1276
1277static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
1278{
1279 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001280
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001281 if (sta)
1282 return 0;
1283
1284 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
1285 " - adding a new STA", MAC2STR(addr));
1286 sta = ap_sta_add(hapd, addr);
1287 if (sta) {
1288 hostapd_new_assoc_sta(hapd, sta, 0);
1289 } else {
1290 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
1291 MAC2STR(addr));
1292 return -1;
1293 }
1294
1295 return 0;
1296}
1297
1298
1299static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
1300 const u8 *data, size_t data_len)
1301{
1302 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -08001303 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001304 size_t j;
1305
1306 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001307 sta = ap_get_sta(iface->bss[j], src);
1308 if (sta && sta->flags & WLAN_STA_ASSOC) {
1309 hapd = iface->bss[j];
1310 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001311 }
1312 }
1313
1314 ieee802_1x_receive(hapd, src, data, data_len);
1315}
1316
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001317#endif /* HOSTAPD */
1318
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001320static struct hostapd_channel_data * hostapd_get_mode_channel(
1321 struct hostapd_iface *iface, unsigned int freq)
1322{
1323 int i;
1324 struct hostapd_channel_data *chan;
1325
1326 for (i = 0; i < iface->current_mode->num_channels; i++) {
1327 chan = &iface->current_mode->channels[i];
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001328 if ((unsigned int) chan->freq == freq)
1329 return chan;
1330 }
1331
1332 return NULL;
1333}
1334
1335
1336static void hostapd_update_nf(struct hostapd_iface *iface,
1337 struct hostapd_channel_data *chan,
1338 struct freq_survey *survey)
1339{
1340 if (!iface->chans_surveyed) {
1341 chan->min_nf = survey->nf;
1342 iface->lowest_nf = survey->nf;
1343 } else {
1344 if (dl_list_empty(&chan->survey_list))
1345 chan->min_nf = survey->nf;
1346 else if (survey->nf < chan->min_nf)
1347 chan->min_nf = survey->nf;
1348 if (survey->nf < iface->lowest_nf)
1349 iface->lowest_nf = survey->nf;
1350 }
1351}
1352
1353
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001354static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1355 struct survey_results *survey_res)
1356{
1357 struct hostapd_channel_data *chan;
1358 struct freq_survey *survey;
1359 u64 divisor, dividend;
1360
1361 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1362 list);
1363 if (!survey || !survey->freq)
1364 return;
1365
1366 chan = hostapd_get_mode_channel(iface, survey->freq);
1367 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1368 return;
1369
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001370 wpa_printf(MSG_DEBUG,
1371 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001372 survey->freq,
1373 (unsigned long int) survey->channel_time,
1374 (unsigned long int) survey->channel_time_busy);
1375
1376 if (survey->channel_time > iface->last_channel_time &&
1377 survey->channel_time > survey->channel_time_busy) {
1378 dividend = survey->channel_time_busy -
1379 iface->last_channel_time_busy;
1380 divisor = survey->channel_time - iface->last_channel_time;
1381
1382 iface->channel_utilization = dividend * 255 / divisor;
1383 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1384 iface->channel_utilization);
1385 }
1386 iface->last_channel_time = survey->channel_time;
1387 iface->last_channel_time_busy = survey->channel_time_busy;
1388}
1389
1390
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001391void hostapd_event_get_survey(struct hostapd_iface *iface,
1392 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001393{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001394 struct freq_survey *survey, *tmp;
1395 struct hostapd_channel_data *chan;
1396
1397 if (dl_list_empty(&survey_results->survey_list)) {
1398 wpa_printf(MSG_DEBUG, "No survey data received");
1399 return;
1400 }
1401
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001402 if (survey_results->freq_filter) {
1403 hostapd_single_channel_get_survey(iface, survey_results);
1404 return;
1405 }
1406
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001407 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1408 struct freq_survey, list) {
1409 chan = hostapd_get_mode_channel(iface, survey->freq);
1410 if (!chan)
1411 continue;
1412 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1413 continue;
1414
1415 dl_list_del(&survey->list);
1416 dl_list_add_tail(&chan->survey_list, &survey->list);
1417
1418 hostapd_update_nf(iface, chan, survey);
1419
1420 iface->chans_surveyed++;
1421 }
1422}
1423
1424
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001425#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001426#ifdef NEED_AP_MLME
1427
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001428static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1429{
1430 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1431 hapd->conf->iface);
1432
1433 if (hapd->csa_in_progress) {
1434 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1435 hapd->conf->iface);
1436 hostapd_switch_channel_fallback(hapd->iface,
1437 &hapd->cs_freq_params);
1438 }
1439}
1440
1441
Dmitry Shmidt051af732013-10-22 13:52:46 -07001442static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1443 struct dfs_event *radar)
1444{
1445 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001446 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001447 radar->chan_offset, radar->chan_width,
1448 radar->cf1, radar->cf2);
1449}
1450
1451
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001452static void hostapd_event_dfs_pre_cac_expired(struct hostapd_data *hapd,
1453 struct dfs_event *radar)
1454{
1455 wpa_printf(MSG_DEBUG, "DFS Pre-CAC expired on %d MHz", radar->freq);
1456 hostapd_dfs_pre_cac_expired(hapd->iface, radar->freq, radar->ht_enabled,
1457 radar->chan_offset, radar->chan_width,
1458 radar->cf1, radar->cf2);
1459}
1460
1461
Dmitry Shmidt051af732013-10-22 13:52:46 -07001462static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1463 struct dfs_event *radar)
1464{
1465 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001466 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001467 radar->chan_offset, radar->chan_width,
1468 radar->cf1, radar->cf2);
1469}
1470
1471
1472static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1473 struct dfs_event *radar)
1474{
1475 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001476 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001477 radar->chan_offset, radar->chan_width,
1478 radar->cf1, radar->cf2);
1479}
1480
1481
1482static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1483 struct dfs_event *radar)
1484{
1485 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001486 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001487 radar->chan_offset, radar->chan_width,
1488 radar->cf1, radar->cf2);
1489}
1490
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001491
1492static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1493 struct dfs_event *radar)
1494{
1495 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1496 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1497 radar->chan_offset, radar->chan_width,
1498 radar->cf1, radar->cf2);
1499}
1500
Dmitry Shmidt051af732013-10-22 13:52:46 -07001501#endif /* NEED_AP_MLME */
1502
1503
Roshan Pius3a1667e2018-07-03 15:17:14 -07001504static void hostapd_event_wds_sta_interface_status(struct hostapd_data *hapd,
1505 int istatus,
1506 const char *ifname,
1507 const u8 *addr)
1508{
1509 struct sta_info *sta = ap_get_sta(hapd, addr);
1510
1511 if (sta) {
1512 os_free(sta->ifname_wds);
1513 if (istatus == INTERFACE_ADDED)
1514 sta->ifname_wds = os_strdup(ifname);
1515 else
1516 sta->ifname_wds = NULL;
1517 }
1518
1519 wpa_msg(hapd->msg_ctx, MSG_INFO, "%sifname=%s sta_addr=" MACSTR,
1520 istatus == INTERFACE_ADDED ?
1521 WDS_STA_INTERFACE_ADDED : WDS_STA_INTERFACE_REMOVED,
1522 ifname, MAC2STR(addr));
1523}
1524
1525
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001526void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1527 union wpa_event_data *data)
1528{
1529 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001530#ifndef CONFIG_NO_STDOUT_DEBUG
1531 int level = MSG_DEBUG;
1532
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001533 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001534 data->rx_mgmt.frame_len >= 24) {
1535 const struct ieee80211_hdr *hdr;
1536 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001537
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001538 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1539 fc = le_to_host16(hdr->frame_control);
1540 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1541 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1542 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001543 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1544 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1545 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001546 }
1547
1548 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1549 event_to_string(event), event);
1550#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001551
1552 switch (event) {
1553 case EVENT_MICHAEL_MIC_FAILURE:
1554 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1555 break;
1556 case EVENT_SCAN_RESULTS:
1557 if (hapd->iface->scan_cb)
1558 hapd->iface->scan_cb(hapd->iface);
1559 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001560 case EVENT_WPS_BUTTON_PUSHED:
1561 hostapd_wps_button_pushed(hapd, NULL);
1562 break;
1563#ifdef NEED_AP_MLME
1564 case EVENT_TX_STATUS:
1565 switch (data->tx_status.type) {
1566 case WLAN_FC_TYPE_MGMT:
1567 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1568 data->tx_status.data_len,
1569 data->tx_status.stype,
1570 data->tx_status.ack);
1571 break;
1572 case WLAN_FC_TYPE_DATA:
1573 hostapd_tx_status(hapd, data->tx_status.dst,
1574 data->tx_status.data,
1575 data->tx_status.data_len,
1576 data->tx_status.ack);
1577 break;
1578 }
1579 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001580 case EVENT_EAPOL_TX_STATUS:
1581 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1582 data->eapol_tx_status.data,
1583 data->eapol_tx_status.data_len,
1584 data->eapol_tx_status.ack);
1585 break;
1586 case EVENT_DRIVER_CLIENT_POLL_OK:
1587 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1588 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001589 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001590 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1591 data->rx_from_unknown.addr,
1592 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001593 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001594#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001595 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001596 if (!data->rx_mgmt.frame)
1597 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001598#ifdef NEED_AP_MLME
1599 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1600 break;
1601#endif /* NEED_AP_MLME */
1602 hostapd_action_rx(hapd, &data->rx_mgmt);
1603 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001604 case EVENT_RX_PROBE_REQ:
1605 if (data->rx_probe_req.sa == NULL ||
1606 data->rx_probe_req.ie == NULL)
1607 break;
1608 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001609 data->rx_probe_req.da,
1610 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001611 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001612 data->rx_probe_req.ie_len,
1613 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001614 break;
1615 case EVENT_NEW_STA:
1616 hostapd_event_new_sta(hapd, data->new_sta.addr);
1617 break;
1618 case EVENT_EAPOL_RX:
1619 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1620 data->eapol_rx.data,
1621 data->eapol_rx.data_len);
1622 break;
1623 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001624 if (!data)
1625 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001626 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1627 data->assoc_info.req_ies,
1628 data->assoc_info.req_ies_len,
1629 data->assoc_info.reassoc);
1630 break;
1631 case EVENT_DISASSOC:
1632 if (data)
1633 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1634 break;
1635 case EVENT_DEAUTH:
1636 if (data)
1637 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1638 break;
1639 case EVENT_STATION_LOW_ACK:
1640 if (!data)
1641 break;
1642 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1643 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001644 case EVENT_AUTH:
1645 hostapd_notif_auth(hapd, &data->auth);
1646 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001647 case EVENT_CH_SWITCH:
1648 if (!data)
1649 break;
1650 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1651 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001652 data->ch_switch.ch_offset,
1653 data->ch_switch.ch_width,
1654 data->ch_switch.cf1,
1655 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001656 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001657 case EVENT_CONNECT_FAILED_REASON:
1658 if (!data)
1659 break;
1660 hostapd_event_connect_failed_reason(
1661 hapd, data->connect_failed_reason.addr,
1662 data->connect_failed_reason.code);
1663 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001664 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001665 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001666 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001667#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001668 case EVENT_INTERFACE_UNAVAILABLE:
1669 hostapd_event_iface_unavailable(hapd);
1670 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001671 case EVENT_DFS_RADAR_DETECTED:
1672 if (!data)
1673 break;
1674 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1675 break;
Dmitry Shmidtd2986c22017-10-23 14:22:09 -07001676 case EVENT_DFS_PRE_CAC_EXPIRED:
1677 if (!data)
1678 break;
1679 hostapd_event_dfs_pre_cac_expired(hapd, &data->dfs_event);
1680 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001681 case EVENT_DFS_CAC_FINISHED:
1682 if (!data)
1683 break;
1684 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1685 break;
1686 case EVENT_DFS_CAC_ABORTED:
1687 if (!data)
1688 break;
1689 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1690 break;
1691 case EVENT_DFS_NOP_FINISHED:
1692 if (!data)
1693 break;
1694 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1695 break;
1696 case EVENT_CHANNEL_LIST_CHANGED:
1697 /* channel list changed (regulatory?), update channel list */
1698 /* TODO: check this. hostapd_get_hw_features() initializes
1699 * too much stuff. */
1700 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001701 hostapd_channel_list_updated(
1702 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001703 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001704 case EVENT_DFS_CAC_STARTED:
1705 if (!data)
1706 break;
1707 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1708 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001709#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001710 case EVENT_INTERFACE_ENABLED:
1711 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001712 if (hapd->disabled && hapd->started) {
1713 hapd->disabled = 0;
1714 /*
1715 * Try to re-enable interface if the driver stopped it
1716 * when the interface got disabled.
1717 */
Hai Shalomce48b4a2018-09-05 11:41:35 -07001718 if (hapd->wpa_auth)
1719 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1720 else
1721 hostapd_reconfig_encryption(hapd);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001722 hapd->reenable_beacon = 1;
1723 ieee802_11_set_beacon(hapd);
1724 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001725 break;
1726 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001727 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001728 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001729 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001730 break;
1731#ifdef CONFIG_ACS
1732 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001733 hostapd_acs_channel_selected(hapd,
1734 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001735 break;
1736#endif /* CONFIG_ACS */
Roshan Pius3a1667e2018-07-03 15:17:14 -07001737 case EVENT_STATION_OPMODE_CHANGED:
1738 hostapd_event_sta_opmode_changed(hapd, data->sta_opmode.addr,
1739 data->sta_opmode.smps_mode,
1740 data->sta_opmode.chan_width,
1741 data->sta_opmode.rx_nss);
1742 break;
1743 case EVENT_WDS_STA_INTERFACE_STATUS:
1744 hostapd_event_wds_sta_interface_status(
1745 hapd, data->wds_sta_interface.istatus,
1746 data->wds_sta_interface.ifname,
1747 data->wds_sta_interface.sta_addr);
1748 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001749 default:
1750 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1751 break;
1752 }
1753}
1754
Dmitry Shmidte4663042016-04-04 10:07:49 -07001755
1756void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
1757 union wpa_event_data *data)
1758{
1759 struct hapd_interfaces *interfaces = ctx;
1760 struct hostapd_data *hapd;
1761
1762 if (event != EVENT_INTERFACE_STATUS)
1763 return;
1764
1765 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
1766 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
1767 hapd->drv_priv) {
1768 unsigned int ifindex;
1769
1770 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
1771 if (ifindex != data->interface_status.ifindex) {
1772 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1773 "interface status ifindex %d mismatch (%d)",
1774 ifindex, data->interface_status.ifindex);
1775 return;
1776 }
1777 }
1778 if (hapd)
1779 wpa_supplicant_event(hapd, event, data);
1780}
1781
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001782#endif /* HOSTAPD */