blob: 3552b3e0d53b6ee9388d3c8437201e0cf67cbbe0 [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 Shmidt04949592012-07-19 12:16:46 -070034#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070035#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070036#include "beacon.h"
Dmitry Shmidt57c2d392016-02-23 13:40:19 -080037#include "mbo_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070038
39
40int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070042{
43 struct sta_info *sta;
44 int new_assoc, res;
45 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080046 const u8 *ie;
47 size_t ielen;
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -080048#if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070049 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
50 u8 *p = buf;
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -080051#endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080052 u16 reason = WLAN_REASON_UNSPECIFIED;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070053 u16 status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070054 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070055
56 if (addr == NULL) {
57 /*
58 * This could potentially happen with unexpected event from the
59 * driver wrapper. This was seen at least in one case where the
60 * driver ended up being set to station mode while hostapd was
61 * running, so better make sure we stop processing such an
62 * event here.
63 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080064 wpa_printf(MSG_DEBUG,
65 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070066 return -1;
67 }
68 random_add_randomness(addr, ETH_ALEN);
69
70 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
71 HOSTAPD_LEVEL_INFO, "associated");
72
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080073 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070074 if (elems.wps_ie) {
75 ie = elems.wps_ie - 2;
76 ielen = elems.wps_ie_len + 2;
77 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
78 } else if (elems.rsn_ie) {
79 ie = elems.rsn_ie - 2;
80 ielen = elems.rsn_ie_len + 2;
81 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
82 } else if (elems.wpa_ie) {
83 ie = elems.wpa_ie - 2;
84 ielen = elems.wpa_ie_len + 2;
85 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080086#ifdef CONFIG_HS20
87 } else if (elems.osen) {
88 ie = elems.osen - 2;
89 ielen = elems.osen_len + 2;
90 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
91#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070092 } else {
93 ie = NULL;
94 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080095 wpa_printf(MSG_DEBUG,
96 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 }
98
99 sta = ap_get_sta(hapd, addr);
100 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -0700101 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700102 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700103
104 /*
105 * Make sure that the previously registered inactivity timer
106 * will not remove the STA immediately.
107 */
108 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 } else {
110 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700111 if (sta == NULL) {
112 hostapd_drv_sta_disassoc(hapd, addr,
113 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700115 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700116 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800117 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700118
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700119 /*
120 * ACL configurations to the drivers (implementing AP SME and ACL
121 * offload) without hostapd's knowledge, can result in a disconnection
122 * though the driver accepts the connection. Skip the hostapd check for
123 * ACL if the driver supports ACL offload to avoid potentially
124 * conflicting ACL rules.
125 */
126 if (hapd->iface->drv_max_acl_mac_addrs == 0 &&
127 hostapd_check_acl(hapd, addr, NULL) != HOSTAPD_ACL_ACCEPT) {
Dmitry Shmidtd7ff03d2015-12-04 14:49:35 -0800128 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
129 MAC2STR(addr));
130 reason = WLAN_REASON_UNSPECIFIED;
131 goto fail;
132 }
133
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134#ifdef CONFIG_P2P
135 if (elems.p2p) {
136 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800137 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700138 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700139 if (sta->p2p_ie)
140 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700141 }
142#endif /* CONFIG_P2P */
143
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700144#ifdef CONFIG_IEEE80211N
145#ifdef NEED_AP_MLME
146 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700147 (hapd->iface->conf->ht_capab &
148 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
149 struct ieee80211_ht_capabilities *ht_cap =
150 (struct ieee80211_ht_capabilities *)
151 elems.ht_capabilities;
152
153 if (le_to_host16(ht_cap->ht_capabilities_info) &
154 HT_CAP_INFO_40MHZ_INTOLERANT)
155 ht40_intolerant_add(hapd->iface, sta);
156 }
157#endif /* NEED_AP_MLME */
158#endif /* CONFIG_IEEE80211N */
159
Dmitry Shmidt051af732013-10-22 13:52:46 -0700160#ifdef CONFIG_INTERWORKING
161 if (elems.ext_capab && elems.ext_capab_len > 4) {
162 if (elems.ext_capab[4] & 0x01)
163 sta->qos_map_enabled = 1;
164 }
165#endif /* CONFIG_INTERWORKING */
166
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800167#ifdef CONFIG_HS20
168 wpabuf_free(sta->hs20_ie);
169 if (elems.hs20 && elems.hs20_len > 4) {
170 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
171 elems.hs20_len - 4);
172 } else
173 sta->hs20_ie = NULL;
174#endif /* CONFIG_HS20 */
175
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800176#ifdef CONFIG_FST
177 wpabuf_free(sta->mb_ies);
178 if (hapd->iface->fst)
179 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
180 else
181 sta->mb_ies = NULL;
182#endif /* CONFIG_FST */
183
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800184 mbo_ap_check_sta_assoc(hapd, sta, &elems);
185
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800186 ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes,
187 elems.supp_op_classes_len);
188
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189 if (hapd->conf->wpa) {
190 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800191#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700192 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800193 wpa_printf(MSG_DEBUG,
194 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700195 sta->flags |= WLAN_STA_MAYBE_WPS;
196 goto skip_wpa_check;
197 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800198#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700199
200 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
201 return -1;
202 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800203#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700204 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
205 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800206 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800207
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800209 wps = ieee802_11_vendor_ie_concat(ie, ielen,
210 WPS_IE_VENDOR_TYPE);
211 if (wps) {
212 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800213 wpa_printf(MSG_DEBUG,
214 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800215 sta->flags |= WLAN_STA_WPS2;
216 }
217 wpabuf_free(wps);
218 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700219 goto skip_wpa_check;
220 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800221#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700222
223 if (sta->wpa_sm == NULL)
224 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700225 sta->addr,
226 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700227 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800228 wpa_printf(MSG_ERROR,
229 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700230 return -1;
231 }
232 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700233 ie, ielen,
234 elems.mdie, elems.mdie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700235 if (res != WPA_IE_OK) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800236 wpa_printf(MSG_DEBUG,
237 "WPA/RSN information element rejected? (res %u)",
238 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700239 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700240 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800241 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700242 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
243 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800244 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700245 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
246 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800247 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700248 status = WLAN_STATUS_AKMP_NOT_VALID;
249 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700250#ifdef CONFIG_IEEE80211W
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700251 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800252 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700253 status = WLAN_STATUS_INVALID_IE;
254 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800255 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700256 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
257 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700258#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700259 else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800260 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700261 status = WLAN_STATUS_INVALID_IE;
262 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800263 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700264 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700265#ifdef CONFIG_IEEE80211W
266 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
267 sta->sa_query_count > 0)
268 ap_check_sa_query_timeout(hapd, sta);
269 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
270 (sta->auth_alg != WLAN_AUTH_FT)) {
271 /*
272 * STA has already been associated with MFP and SA
273 * Query timeout has not been reached. Reject the
274 * association attempt temporarily and start SA Query,
275 * if one is not pending.
276 */
277
278 if (sta->sa_query_count == 0)
279 ap_sta_start_sa_query(hapd, sta);
280
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700281 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
282
283 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
284
285 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
286 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700287 return 0;
288 }
289
290 if (wpa_auth_uses_mfp(sta->wpa_sm))
291 sta->flags |= WLAN_STA_MFP;
292 else
293 sta->flags &= ~WLAN_STA_MFP;
294#endif /* CONFIG_IEEE80211W */
295
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800296#ifdef CONFIG_IEEE80211R
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700297 if (sta->auth_alg == WLAN_AUTH_FT) {
298 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
299 req_ies_len);
300 if (status != WLAN_STATUS_SUCCESS) {
301 if (status == WLAN_STATUS_INVALID_PMKID)
302 reason = WLAN_REASON_INVALID_IE;
303 if (status == WLAN_STATUS_INVALID_MDIE)
304 reason = WLAN_REASON_INVALID_IE;
305 if (status == WLAN_STATUS_INVALID_FTIE)
306 reason = WLAN_REASON_INVALID_IE;
307 goto fail;
308 }
309 }
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800310#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700311 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800312#ifdef CONFIG_WPS
313 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800314
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800315 if (req_ies)
316 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800318 else
319 wps = NULL;
320#ifdef CONFIG_WPS_STRICT
321 if (wps && wps_validate_assoc_req(wps) < 0) {
322 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700323 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700324 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800325 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700326 }
327#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800328 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800330 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800331 wpa_printf(MSG_DEBUG,
332 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800333 sta->flags |= WLAN_STA_WPS2;
334 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700335 } else
336 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800337 wpabuf_free(wps);
338#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800339#ifdef CONFIG_HS20
340 } else if (hapd->conf->osen) {
341 if (elems.osen == NULL) {
342 hostapd_logger(
343 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
344 HOSTAPD_LEVEL_INFO,
345 "No HS 2.0 OSEN element in association request");
346 return WLAN_STATUS_INVALID_IE;
347 }
348
349 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
350 if (sta->wpa_sm == NULL)
351 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
352 sta->addr, NULL);
353 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800354 wpa_printf(MSG_WARNING,
355 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800356 return WLAN_STATUS_UNSPECIFIED_FAILURE;
357 }
358 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
359 elems.osen - 2, elems.osen_len + 2) < 0)
360 return WLAN_STATUS_INVALID_IE;
361#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700362 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800363
364#ifdef CONFIG_MBO
365 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
366 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
367 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
368 wpa_printf(MSG_INFO,
369 "MBO: Reject WPA2 association without PMF");
370 return WLAN_STATUS_UNSPECIFIED_FAILURE;
371 }
372#endif /* CONFIG_MBO */
373
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800374#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700375skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800376#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700377
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800378#ifdef CONFIG_IEEE80211R
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700379 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
380 sta->auth_alg, req_ies, req_ies_len);
381
382 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700383
384 if (sta->auth_alg == WLAN_AUTH_FT)
385 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800386#else /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700387 /* Keep compiler silent about unused variables */
388 if (status) {
389 }
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800390#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700391
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
393 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800394 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700395
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700396 hostapd_set_sta_flags(hapd, sta);
397
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700398 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
399 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
400 else
401 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402
403 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
404
405 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
406
407#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800408 if (req_ies) {
409 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
410 req_ies, req_ies_len);
411 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700412#endif /* CONFIG_P2P */
413
414 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800415
416fail:
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800417#ifdef CONFIG_IEEE80211R
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700418 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800419#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800420 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
421 ap_free_sta(hapd, sta);
422 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423}
424
425
426void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
427{
428 struct sta_info *sta;
429
430 if (addr == NULL) {
431 /*
432 * This could potentially happen with unexpected event from the
433 * driver wrapper. This was seen at least in one case where the
434 * driver ended up reporting a station mode event while hostapd
435 * was running, so better make sure we stop processing such an
436 * event here.
437 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800438 wpa_printf(MSG_DEBUG,
439 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 return;
441 }
442
443 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
444 HOSTAPD_LEVEL_INFO, "disassociated");
445
446 sta = ap_get_sta(hapd, addr);
447 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800448 wpa_printf(MSG_DEBUG,
449 "Disassociation notification for unknown STA "
450 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700451 return;
452 }
453
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800454 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700455 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700456 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
457 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
458 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
459 ap_free_sta(hapd, sta);
460}
461
462
463void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
464{
465 struct sta_info *sta = ap_get_sta(hapd, addr);
466
467 if (!sta || !hapd->conf->disassoc_low_ack)
468 return;
469
470 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800471 HOSTAPD_LEVEL_INFO,
472 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700473 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800474 if (sta)
475 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700476}
477
478
Dmitry Shmidt04949592012-07-19 12:16:46 -0700479void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800480 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700481{
482#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800483 int channel, chwidth, is_dfs;
484 u8 seg0_idx = 0, seg1_idx = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700485
486 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800487 HOSTAPD_LEVEL_INFO,
488 "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
489 freq, ht, offset, width, channel_width_to_string(width),
490 cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700491
492 hapd->iface->freq = freq;
493
494 channel = hostapd_hw_get_channel(hapd, freq);
495 if (!channel) {
496 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800497 HOSTAPD_LEVEL_WARNING,
498 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700499 return;
500 }
501
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800502 switch (width) {
503 case CHAN_WIDTH_80:
504 chwidth = VHT_CHANWIDTH_80MHZ;
505 break;
506 case CHAN_WIDTH_80P80:
507 chwidth = VHT_CHANWIDTH_80P80MHZ;
508 break;
509 case CHAN_WIDTH_160:
510 chwidth = VHT_CHANWIDTH_160MHZ;
511 break;
512 case CHAN_WIDTH_20_NOHT:
513 case CHAN_WIDTH_20:
514 case CHAN_WIDTH_40:
515 default:
516 chwidth = VHT_CHANWIDTH_USE_HT;
517 break;
518 }
519
520 switch (hapd->iface->current_mode->mode) {
521 case HOSTAPD_MODE_IEEE80211A:
522 if (cf1 > 5000)
523 seg0_idx = (cf1 - 5000) / 5;
524 if (cf2 > 5000)
525 seg1_idx = (cf2 - 5000) / 5;
526 break;
527 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800528 ieee80211_freq_to_chan(cf1, &seg0_idx);
529 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800530 break;
531 }
532
Dmitry Shmidt04949592012-07-19 12:16:46 -0700533 hapd->iconf->channel = channel;
534 hapd->iconf->ieee80211n = ht;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800535 if (!ht)
536 hapd->iconf->ieee80211ac = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700537 hapd->iconf->secondary_channel = offset;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800538 hapd->iconf->vht_oper_chwidth = chwidth;
539 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
540 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800541
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800542 is_dfs = ieee80211_is_dfs(freq);
543
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700544 if (hapd->csa_in_progress &&
545 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800546 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700547 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800548
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800549 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
550 "freq=%d dfs=%d", freq, is_dfs);
551 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
552 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
553 "freq=%d dfs=%d", freq, is_dfs);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800554 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700555#endif /* NEED_AP_MLME */
556}
557
558
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800559void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
560 const u8 *addr, int reason_code)
561{
562 switch (reason_code) {
563 case MAX_CLIENT_REACHED:
564 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
565 MAC2STR(addr));
566 break;
567 case BLOCKED_CLIENT:
568 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
569 MAC2STR(addr));
570 break;
571 }
572}
573
574
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800575#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800576void hostapd_acs_channel_selected(struct hostapd_data *hapd,
577 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800578{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700579 int ret, i;
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800580 int err = 0;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800581
582 if (hapd->iconf->channel) {
583 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
584 hapd->iconf->channel);
585 return;
586 }
587
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700588 if (!hapd->iface->current_mode) {
589 for (i = 0; i < hapd->iface->num_hw_features; i++) {
590 struct hostapd_hw_modes *mode =
591 &hapd->iface->hw_features[i];
592
593 if (mode->mode == acs_res->hw_mode) {
594 hapd->iface->current_mode = mode;
595 break;
596 }
597 }
598 if (!hapd->iface->current_mode) {
599 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
600 HOSTAPD_LEVEL_WARNING,
601 "driver selected to bad hw_mode");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800602 err = 1;
603 goto out;
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700604 }
605 }
606
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700607 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800608
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700609 if (!acs_res->pri_channel) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800610 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
611 HOSTAPD_LEVEL_WARNING,
612 "driver switched to bad channel");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800613 err = 1;
614 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800615 }
616
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700617 hapd->iconf->channel = acs_res->pri_channel;
618 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800619
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700620 if (acs_res->sec_channel == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800621 hapd->iconf->secondary_channel = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700622 else if (acs_res->sec_channel < acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800623 hapd->iconf->secondary_channel = -1;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700624 else if (acs_res->sec_channel > acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800625 hapd->iconf->secondary_channel = 1;
626 else {
627 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800628 err = 1;
629 goto out;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800630 }
631
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700632 if (hapd->iface->conf->ieee80211ac) {
633 /* set defaults for backwards compatibility */
634 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
635 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
636 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
637 if (acs_res->ch_width == 80) {
638 hapd->iconf->vht_oper_centr_freq_seg0_idx =
639 acs_res->vht_seg0_center_ch;
640 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
641 } else if (acs_res->ch_width == 160) {
642 if (acs_res->vht_seg1_center_ch == 0) {
643 hapd->iconf->vht_oper_centr_freq_seg0_idx =
644 acs_res->vht_seg0_center_ch;
645 hapd->iconf->vht_oper_chwidth =
646 VHT_CHANWIDTH_160MHZ;
647 } else {
648 hapd->iconf->vht_oper_centr_freq_seg0_idx =
649 acs_res->vht_seg0_center_ch;
650 hapd->iconf->vht_oper_centr_freq_seg1_idx =
651 acs_res->vht_seg1_center_ch;
652 hapd->iconf->vht_oper_chwidth =
653 VHT_CHANWIDTH_80P80MHZ;
654 }
655 }
656 }
657
Dmitry Shmidt9c175262016-03-03 10:20:07 -0800658out:
659 ret = hostapd_acs_completed(hapd->iface, err);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800660 if (ret) {
661 wpa_printf(MSG_ERROR,
662 "ACS: Possibly channel configuration is invalid");
663 }
664}
665#endif /* CONFIG_ACS */
666
667
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800668int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700669 const u8 *bssid, const u8 *ie, size_t ie_len,
670 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700671{
672 size_t i;
673 int ret = 0;
674
675 if (sa == NULL || ie == NULL)
676 return -1;
677
678 random_add_randomness(sa, ETH_ALEN);
679 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
680 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700681 sa, da, bssid, ie, ie_len,
682 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700683 ret = 1;
684 break;
685 }
686 }
687 return ret;
688}
689
690
691#ifdef HOSTAPD
692
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800693#ifdef CONFIG_IEEE80211R
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700694static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
695 const u8 *bssid,
696 u16 auth_transaction, u16 status,
697 const u8 *ies, size_t ies_len)
698{
699 struct hostapd_data *hapd = ctx;
700 struct sta_info *sta;
701
702 sta = ap_get_sta(hapd, dst);
703 if (sta == NULL)
704 return;
705
706 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
707 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
708 sta->flags |= WLAN_STA_AUTH;
709
710 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
711}
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800712#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700713
714
715static void hostapd_notif_auth(struct hostapd_data *hapd,
716 struct auth_info *rx_auth)
717{
718 struct sta_info *sta;
719 u16 status = WLAN_STATUS_SUCCESS;
720 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
721 size_t resp_ies_len = 0;
722
723 sta = ap_get_sta(hapd, rx_auth->peer);
724 if (!sta) {
725 sta = ap_sta_add(hapd, rx_auth->peer);
726 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700727 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700728 goto fail;
729 }
730 }
731 sta->flags &= ~WLAN_STA_PREAUTH;
732 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800733#ifdef CONFIG_IEEE80211R
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700734 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
735 sta->auth_alg = WLAN_AUTH_FT;
736 if (sta->wpa_sm == NULL)
737 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700738 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700739 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800740 wpa_printf(MSG_DEBUG,
741 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700742 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
743 goto fail;
744 }
745 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
746 rx_auth->auth_transaction, rx_auth->ies,
747 rx_auth->ies_len,
748 hostapd_notify_auth_ft_finish, hapd);
749 return;
750 }
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800751#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700752fail:
753 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
754 status, resp_ies, resp_ies_len);
755}
756
757
758static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800759 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700760{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800761 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700762 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800763 size_t plen __maybe_unused;
764 u16 fc;
765
766 if (drv_mgmt->frame_len < 24 + 1)
767 return;
768
769 plen = drv_mgmt->frame_len - 24 - 1;
770
771 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
772 fc = le_to_host16(mgmt->frame_control);
773 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
774 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700775
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800776 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800777 mgmt->u.action.category, (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700778
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800779 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700780 if (sta == NULL) {
781 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
782 return;
783 }
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800784#ifdef CONFIG_IEEE80211R
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800785 if (mgmt->u.action.category == WLAN_ACTION_FT) {
786 const u8 *payload = drv_mgmt->frame + 24 + 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800787
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800788 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700789 }
Dmitry Shmidtfe31a9a2016-11-09 13:43:31 -0800790#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700791#ifdef CONFIG_IEEE80211W
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800792 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
793 ieee802_11_sa_query_action(
794 hapd, mgmt->sa,
795 mgmt->u.action.u.sa_query_resp.action,
796 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700797 }
798#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800799#ifdef CONFIG_WNM
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800800 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
801 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700802 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800803#endif /* CONFIG_WNM */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800804#ifdef CONFIG_FST
805 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
806 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
807 return;
808 }
809#endif /* CONFIG_FST */
810
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700811}
812
813
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700814#ifdef NEED_AP_MLME
815
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700816#define HAPD_BROADCAST ((struct hostapd_data *) -1)
817
818static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
819 const u8 *bssid)
820{
821 size_t i;
822
823 if (bssid == NULL)
824 return NULL;
825 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
826 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
827 return HAPD_BROADCAST;
828
829 for (i = 0; i < iface->num_bss; i++) {
830 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
831 return iface->bss[i];
832 }
833
834 return NULL;
835}
836
837
838static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800839 const u8 *bssid, const u8 *addr,
840 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700841{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800842 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843 if (hapd == NULL || hapd == HAPD_BROADCAST)
844 return;
845
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800846 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700847}
848
849
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800850static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700851{
852 struct hostapd_iface *iface = hapd->iface;
853 const struct ieee80211_hdr *hdr;
854 const u8 *bssid;
855 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800856 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700857
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800858#ifdef CONFIG_TESTING_OPTIONS
859 if (hapd->ext_mgmt_frame_handling) {
860 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
861 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800862
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800863 if (hex) {
864 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
865 rx_mgmt->frame_len);
866 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
867 os_free(hex);
868 }
869 return 1;
870 }
871#endif /* CONFIG_TESTING_OPTIONS */
872
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700873 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
874 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
875 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800876 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877
878 hapd = get_hapd_bssid(iface, bssid);
879 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800880 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700881
882 /*
883 * Drop frames to unknown BSSIDs except for Beacon frames which
884 * could be used to update neighbor information.
885 */
886 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
887 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
888 hapd = iface->bss[0];
889 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800890 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700891 }
892
893 os_memset(&fi, 0, sizeof(fi));
894 fi.datarate = rx_mgmt->datarate;
895 fi.ssi_signal = rx_mgmt->ssi_signal;
896
897 if (hapd == HAPD_BROADCAST) {
898 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800899
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800900 ret = 0;
901 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -0700902 /* if bss is set, driver will call this function for
903 * each bss individually. */
904 if (rx_mgmt->drv_priv &&
905 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
906 continue;
907
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800908 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
909 rx_mgmt->frame_len, &fi) > 0)
910 ret = 1;
911 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800913 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
914 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700915
916 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700917
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800918 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700919}
920
921
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700922static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
923 size_t len, u16 stype, int ok)
924{
925 struct ieee80211_hdr *hdr;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700926 struct hostapd_data *orig_hapd = hapd;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800927
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700928 hdr = (struct ieee80211_hdr *) buf;
929 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700930 if (!hapd)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700931 return;
Dmitry Shmidtd5ab1b52016-06-21 12:38:41 -0700932 if (hapd == HAPD_BROADCAST) {
933 if (stype != WLAN_FC_STYPE_ACTION || len <= 25 ||
934 buf[24] != WLAN_ACTION_PUBLIC)
935 return;
936 hapd = get_hapd_bssid(orig_hapd->iface, hdr->addr2);
937 if (!hapd || hapd == HAPD_BROADCAST)
938 return;
939 /*
940 * Allow processing of TX status for a Public Action frame that
941 * used wildcard BBSID.
942 */
943 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700944 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
945}
946
947#endif /* NEED_AP_MLME */
948
949
950static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
951{
952 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800953
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700954 if (sta)
955 return 0;
956
957 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
958 " - adding a new STA", MAC2STR(addr));
959 sta = ap_sta_add(hapd, addr);
960 if (sta) {
961 hostapd_new_assoc_sta(hapd, sta, 0);
962 } else {
963 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
964 MAC2STR(addr));
965 return -1;
966 }
967
968 return 0;
969}
970
971
972static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
973 const u8 *data, size_t data_len)
974{
975 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800976 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 size_t j;
978
979 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800980 sta = ap_get_sta(iface->bss[j], src);
981 if (sta && sta->flags & WLAN_STA_ASSOC) {
982 hapd = iface->bss[j];
983 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700984 }
985 }
986
987 ieee802_1x_receive(hapd, src, data, data_len);
988}
989
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800990#endif /* HOSTAPD */
991
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700992
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700993static struct hostapd_channel_data * hostapd_get_mode_channel(
994 struct hostapd_iface *iface, unsigned int freq)
995{
996 int i;
997 struct hostapd_channel_data *chan;
998
999 for (i = 0; i < iface->current_mode->num_channels; i++) {
1000 chan = &iface->current_mode->channels[i];
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001001 if ((unsigned int) chan->freq == freq)
1002 return chan;
1003 }
1004
1005 return NULL;
1006}
1007
1008
1009static void hostapd_update_nf(struct hostapd_iface *iface,
1010 struct hostapd_channel_data *chan,
1011 struct freq_survey *survey)
1012{
1013 if (!iface->chans_surveyed) {
1014 chan->min_nf = survey->nf;
1015 iface->lowest_nf = survey->nf;
1016 } else {
1017 if (dl_list_empty(&chan->survey_list))
1018 chan->min_nf = survey->nf;
1019 else if (survey->nf < chan->min_nf)
1020 chan->min_nf = survey->nf;
1021 if (survey->nf < iface->lowest_nf)
1022 iface->lowest_nf = survey->nf;
1023 }
1024}
1025
1026
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001027static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1028 struct survey_results *survey_res)
1029{
1030 struct hostapd_channel_data *chan;
1031 struct freq_survey *survey;
1032 u64 divisor, dividend;
1033
1034 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1035 list);
1036 if (!survey || !survey->freq)
1037 return;
1038
1039 chan = hostapd_get_mode_channel(iface, survey->freq);
1040 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1041 return;
1042
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001043 wpa_printf(MSG_DEBUG,
1044 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001045 survey->freq,
1046 (unsigned long int) survey->channel_time,
1047 (unsigned long int) survey->channel_time_busy);
1048
1049 if (survey->channel_time > iface->last_channel_time &&
1050 survey->channel_time > survey->channel_time_busy) {
1051 dividend = survey->channel_time_busy -
1052 iface->last_channel_time_busy;
1053 divisor = survey->channel_time - iface->last_channel_time;
1054
1055 iface->channel_utilization = dividend * 255 / divisor;
1056 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1057 iface->channel_utilization);
1058 }
1059 iface->last_channel_time = survey->channel_time;
1060 iface->last_channel_time_busy = survey->channel_time_busy;
1061}
1062
1063
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001064void hostapd_event_get_survey(struct hostapd_iface *iface,
1065 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001066{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001067 struct freq_survey *survey, *tmp;
1068 struct hostapd_channel_data *chan;
1069
1070 if (dl_list_empty(&survey_results->survey_list)) {
1071 wpa_printf(MSG_DEBUG, "No survey data received");
1072 return;
1073 }
1074
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001075 if (survey_results->freq_filter) {
1076 hostapd_single_channel_get_survey(iface, survey_results);
1077 return;
1078 }
1079
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001080 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1081 struct freq_survey, list) {
1082 chan = hostapd_get_mode_channel(iface, survey->freq);
1083 if (!chan)
1084 continue;
1085 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1086 continue;
1087
1088 dl_list_del(&survey->list);
1089 dl_list_add_tail(&chan->survey_list, &survey->list);
1090
1091 hostapd_update_nf(iface, chan, survey);
1092
1093 iface->chans_surveyed++;
1094 }
1095}
1096
1097
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001098#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001099#ifdef NEED_AP_MLME
1100
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001101static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1102{
1103 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1104 hapd->conf->iface);
1105
1106 if (hapd->csa_in_progress) {
1107 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1108 hapd->conf->iface);
1109 hostapd_switch_channel_fallback(hapd->iface,
1110 &hapd->cs_freq_params);
1111 }
1112}
1113
1114
Dmitry Shmidt051af732013-10-22 13:52:46 -07001115static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1116 struct dfs_event *radar)
1117{
1118 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001119 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001120 radar->chan_offset, radar->chan_width,
1121 radar->cf1, radar->cf2);
1122}
1123
1124
1125static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1126 struct dfs_event *radar)
1127{
1128 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001129 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001130 radar->chan_offset, radar->chan_width,
1131 radar->cf1, radar->cf2);
1132}
1133
1134
1135static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1136 struct dfs_event *radar)
1137{
1138 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001139 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001140 radar->chan_offset, radar->chan_width,
1141 radar->cf1, radar->cf2);
1142}
1143
1144
1145static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1146 struct dfs_event *radar)
1147{
1148 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001149 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001150 radar->chan_offset, radar->chan_width,
1151 radar->cf1, radar->cf2);
1152}
1153
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001154
1155static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1156 struct dfs_event *radar)
1157{
1158 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1159 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1160 radar->chan_offset, radar->chan_width,
1161 radar->cf1, radar->cf2);
1162}
1163
Dmitry Shmidt051af732013-10-22 13:52:46 -07001164#endif /* NEED_AP_MLME */
1165
1166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001167void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1168 union wpa_event_data *data)
1169{
1170 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001171#ifndef CONFIG_NO_STDOUT_DEBUG
1172 int level = MSG_DEBUG;
1173
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001174 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001175 data->rx_mgmt.frame_len >= 24) {
1176 const struct ieee80211_hdr *hdr;
1177 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001178
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001179 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1180 fc = le_to_host16(hdr->frame_control);
1181 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1182 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1183 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001184 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1185 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1186 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001187 }
1188
1189 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1190 event_to_string(event), event);
1191#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001192
1193 switch (event) {
1194 case EVENT_MICHAEL_MIC_FAILURE:
1195 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1196 break;
1197 case EVENT_SCAN_RESULTS:
1198 if (hapd->iface->scan_cb)
1199 hapd->iface->scan_cb(hapd->iface);
1200 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 case EVENT_WPS_BUTTON_PUSHED:
1202 hostapd_wps_button_pushed(hapd, NULL);
1203 break;
1204#ifdef NEED_AP_MLME
1205 case EVENT_TX_STATUS:
1206 switch (data->tx_status.type) {
1207 case WLAN_FC_TYPE_MGMT:
1208 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1209 data->tx_status.data_len,
1210 data->tx_status.stype,
1211 data->tx_status.ack);
1212 break;
1213 case WLAN_FC_TYPE_DATA:
1214 hostapd_tx_status(hapd, data->tx_status.dst,
1215 data->tx_status.data,
1216 data->tx_status.data_len,
1217 data->tx_status.ack);
1218 break;
1219 }
1220 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001221 case EVENT_EAPOL_TX_STATUS:
1222 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1223 data->eapol_tx_status.data,
1224 data->eapol_tx_status.data_len,
1225 data->eapol_tx_status.ack);
1226 break;
1227 case EVENT_DRIVER_CLIENT_POLL_OK:
1228 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1229 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001230 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001231 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1232 data->rx_from_unknown.addr,
1233 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001234 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001235#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001236 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001237 if (!data->rx_mgmt.frame)
1238 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001239#ifdef NEED_AP_MLME
1240 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1241 break;
1242#endif /* NEED_AP_MLME */
1243 hostapd_action_rx(hapd, &data->rx_mgmt);
1244 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001245 case EVENT_RX_PROBE_REQ:
1246 if (data->rx_probe_req.sa == NULL ||
1247 data->rx_probe_req.ie == NULL)
1248 break;
1249 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001250 data->rx_probe_req.da,
1251 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001252 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001253 data->rx_probe_req.ie_len,
1254 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001255 break;
1256 case EVENT_NEW_STA:
1257 hostapd_event_new_sta(hapd, data->new_sta.addr);
1258 break;
1259 case EVENT_EAPOL_RX:
1260 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1261 data->eapol_rx.data,
1262 data->eapol_rx.data_len);
1263 break;
1264 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001265 if (!data)
1266 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001267 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1268 data->assoc_info.req_ies,
1269 data->assoc_info.req_ies_len,
1270 data->assoc_info.reassoc);
1271 break;
1272 case EVENT_DISASSOC:
1273 if (data)
1274 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1275 break;
1276 case EVENT_DEAUTH:
1277 if (data)
1278 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1279 break;
1280 case EVENT_STATION_LOW_ACK:
1281 if (!data)
1282 break;
1283 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1284 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001285 case EVENT_AUTH:
1286 hostapd_notif_auth(hapd, &data->auth);
1287 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001288 case EVENT_CH_SWITCH:
1289 if (!data)
1290 break;
1291 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1292 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001293 data->ch_switch.ch_offset,
1294 data->ch_switch.ch_width,
1295 data->ch_switch.cf1,
1296 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001297 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001298 case EVENT_CONNECT_FAILED_REASON:
1299 if (!data)
1300 break;
1301 hostapd_event_connect_failed_reason(
1302 hapd, data->connect_failed_reason.addr,
1303 data->connect_failed_reason.code);
1304 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001305 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001306 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001307 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001308#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001309 case EVENT_INTERFACE_UNAVAILABLE:
1310 hostapd_event_iface_unavailable(hapd);
1311 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001312 case EVENT_DFS_RADAR_DETECTED:
1313 if (!data)
1314 break;
1315 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1316 break;
1317 case EVENT_DFS_CAC_FINISHED:
1318 if (!data)
1319 break;
1320 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1321 break;
1322 case EVENT_DFS_CAC_ABORTED:
1323 if (!data)
1324 break;
1325 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1326 break;
1327 case EVENT_DFS_NOP_FINISHED:
1328 if (!data)
1329 break;
1330 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1331 break;
1332 case EVENT_CHANNEL_LIST_CHANGED:
1333 /* channel list changed (regulatory?), update channel list */
1334 /* TODO: check this. hostapd_get_hw_features() initializes
1335 * too much stuff. */
1336 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001337 hostapd_channel_list_updated(
1338 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001339 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001340 case EVENT_DFS_CAC_STARTED:
1341 if (!data)
1342 break;
1343 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1344 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001345#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001346 case EVENT_INTERFACE_ENABLED:
1347 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001348 if (hapd->disabled && hapd->started) {
1349 hapd->disabled = 0;
1350 /*
1351 * Try to re-enable interface if the driver stopped it
1352 * when the interface got disabled.
1353 */
1354 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1355 hapd->reenable_beacon = 1;
1356 ieee802_11_set_beacon(hapd);
1357 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001358 break;
1359 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001360 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001361 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001362 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001363 break;
1364#ifdef CONFIG_ACS
1365 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001366 hostapd_acs_channel_selected(hapd,
1367 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001368 break;
1369#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001370 default:
1371 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1372 break;
1373 }
1374}
1375
Dmitry Shmidte4663042016-04-04 10:07:49 -07001376
1377void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event,
1378 union wpa_event_data *data)
1379{
1380 struct hapd_interfaces *interfaces = ctx;
1381 struct hostapd_data *hapd;
1382
1383 if (event != EVENT_INTERFACE_STATUS)
1384 return;
1385
1386 hapd = hostapd_get_iface(interfaces, data->interface_status.ifname);
1387 if (hapd && hapd->driver && hapd->driver->get_ifindex &&
1388 hapd->drv_priv) {
1389 unsigned int ifindex;
1390
1391 ifindex = hapd->driver->get_ifindex(hapd->drv_priv);
1392 if (ifindex != data->interface_status.ifindex) {
1393 wpa_dbg(hapd->msg_ctx, MSG_DEBUG,
1394 "interface status ifindex %d mismatch (%d)",
1395 ifindex, data->interface_status.ifindex);
1396 return;
1397 }
1398 }
1399 if (hapd)
1400 wpa_supplicant_event(hapd, event, data);
1401}
1402
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001403#endif /* HOSTAPD */