blob: 702ee647964f9766321a438335791232336c4b1f [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 Shmidtd80a4012015-11-05 16:35:40 -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 Shmidtd80a4012015-11-05 16:35:40 -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 Shmidtd7ff03d2015-12-04 14:49:35 -0800119 res = hostapd_check_acl(hapd, addr, NULL);
120 if (res != HOSTAPD_ACL_ACCEPT) {
121 wpa_printf(MSG_INFO, "STA " MACSTR " not allowed to connect",
122 MAC2STR(addr));
123 reason = WLAN_REASON_UNSPECIFIED;
124 goto fail;
125 }
126
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700127#ifdef CONFIG_P2P
128 if (elems.p2p) {
129 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800130 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700131 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700132 if (sta->p2p_ie)
133 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700134 }
135#endif /* CONFIG_P2P */
136
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700137#ifdef CONFIG_IEEE80211N
138#ifdef NEED_AP_MLME
139 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700140 (hapd->iface->conf->ht_capab &
141 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
142 struct ieee80211_ht_capabilities *ht_cap =
143 (struct ieee80211_ht_capabilities *)
144 elems.ht_capabilities;
145
146 if (le_to_host16(ht_cap->ht_capabilities_info) &
147 HT_CAP_INFO_40MHZ_INTOLERANT)
148 ht40_intolerant_add(hapd->iface, sta);
149 }
150#endif /* NEED_AP_MLME */
151#endif /* CONFIG_IEEE80211N */
152
Dmitry Shmidt051af732013-10-22 13:52:46 -0700153#ifdef CONFIG_INTERWORKING
154 if (elems.ext_capab && elems.ext_capab_len > 4) {
155 if (elems.ext_capab[4] & 0x01)
156 sta->qos_map_enabled = 1;
157 }
158#endif /* CONFIG_INTERWORKING */
159
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800160#ifdef CONFIG_HS20
161 wpabuf_free(sta->hs20_ie);
162 if (elems.hs20 && elems.hs20_len > 4) {
163 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
164 elems.hs20_len - 4);
165 } else
166 sta->hs20_ie = NULL;
167#endif /* CONFIG_HS20 */
168
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800169#ifdef CONFIG_FST
170 wpabuf_free(sta->mb_ies);
171 if (hapd->iface->fst)
172 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
173 else
174 sta->mb_ies = NULL;
175#endif /* CONFIG_FST */
176
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800177 mbo_ap_check_sta_assoc(hapd, sta, &elems);
178
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700179 if (hapd->conf->wpa) {
180 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800181#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700182 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800183 wpa_printf(MSG_DEBUG,
184 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700185 sta->flags |= WLAN_STA_MAYBE_WPS;
186 goto skip_wpa_check;
187 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800188#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700189
190 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
191 return -1;
192 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800193#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700194 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
195 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800196 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800197
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700198 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800199 wps = ieee802_11_vendor_ie_concat(ie, ielen,
200 WPS_IE_VENDOR_TYPE);
201 if (wps) {
202 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800203 wpa_printf(MSG_DEBUG,
204 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800205 sta->flags |= WLAN_STA_WPS2;
206 }
207 wpabuf_free(wps);
208 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700209 goto skip_wpa_check;
210 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800211#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700212
213 if (sta->wpa_sm == NULL)
214 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700215 sta->addr,
216 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800218 wpa_printf(MSG_ERROR,
219 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700220 return -1;
221 }
222 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700223 ie, ielen,
224 elems.mdie, elems.mdie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700225 if (res != WPA_IE_OK) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800226 wpa_printf(MSG_DEBUG,
227 "WPA/RSN information element rejected? (res %u)",
228 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700229 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700230 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800231 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700232 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
233 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800234 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700235 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
236 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800237 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700238 status = WLAN_STATUS_AKMP_NOT_VALID;
239 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700240#ifdef CONFIG_IEEE80211W
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700241 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800242 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700243 status = WLAN_STATUS_INVALID_IE;
244 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800245 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700246 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
247 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700248#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700249 else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800250 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700251 status = WLAN_STATUS_INVALID_IE;
252 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800253 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700254 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700255#ifdef CONFIG_IEEE80211W
256 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
257 sta->sa_query_count > 0)
258 ap_check_sa_query_timeout(hapd, sta);
259 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
260 (sta->auth_alg != WLAN_AUTH_FT)) {
261 /*
262 * STA has already been associated with MFP and SA
263 * Query timeout has not been reached. Reject the
264 * association attempt temporarily and start SA Query,
265 * if one is not pending.
266 */
267
268 if (sta->sa_query_count == 0)
269 ap_sta_start_sa_query(hapd, sta);
270
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700271 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
272
273 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
274
275 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
276 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700277 return 0;
278 }
279
280 if (wpa_auth_uses_mfp(sta->wpa_sm))
281 sta->flags |= WLAN_STA_MFP;
282 else
283 sta->flags &= ~WLAN_STA_MFP;
284#endif /* CONFIG_IEEE80211W */
285
286#ifdef CONFIG_IEEE80211R
287 if (sta->auth_alg == WLAN_AUTH_FT) {
288 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
289 req_ies_len);
290 if (status != WLAN_STATUS_SUCCESS) {
291 if (status == WLAN_STATUS_INVALID_PMKID)
292 reason = WLAN_REASON_INVALID_IE;
293 if (status == WLAN_STATUS_INVALID_MDIE)
294 reason = WLAN_REASON_INVALID_IE;
295 if (status == WLAN_STATUS_INVALID_FTIE)
296 reason = WLAN_REASON_INVALID_IE;
297 goto fail;
298 }
299 }
300#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700301 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800302#ifdef CONFIG_WPS
303 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800304
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800305 if (req_ies)
306 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800308 else
309 wps = NULL;
310#ifdef CONFIG_WPS_STRICT
311 if (wps && wps_validate_assoc_req(wps) < 0) {
312 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700313 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700314 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800315 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700316 }
317#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800318 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700319 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800320 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800321 wpa_printf(MSG_DEBUG,
322 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800323 sta->flags |= WLAN_STA_WPS2;
324 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700325 } else
326 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800327 wpabuf_free(wps);
328#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800329#ifdef CONFIG_HS20
330 } else if (hapd->conf->osen) {
331 if (elems.osen == NULL) {
332 hostapd_logger(
333 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
334 HOSTAPD_LEVEL_INFO,
335 "No HS 2.0 OSEN element in association request");
336 return WLAN_STATUS_INVALID_IE;
337 }
338
339 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
340 if (sta->wpa_sm == NULL)
341 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
342 sta->addr, NULL);
343 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800344 wpa_printf(MSG_WARNING,
345 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800346 return WLAN_STATUS_UNSPECIFIED_FAILURE;
347 }
348 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
349 elems.osen - 2, elems.osen_len + 2) < 0)
350 return WLAN_STATUS_INVALID_IE;
351#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700352 }
Dmitry Shmidt57c2d392016-02-23 13:40:19 -0800353
354#ifdef CONFIG_MBO
355 if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) &&
356 elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) &&
357 hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) {
358 wpa_printf(MSG_INFO,
359 "MBO: Reject WPA2 association without PMF");
360 return WLAN_STATUS_UNSPECIFIED_FAILURE;
361 }
362#endif /* CONFIG_MBO */
363
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800364#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700365skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800366#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700367
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700368#ifdef CONFIG_IEEE80211R
369 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
370 sta->auth_alg, req_ies, req_ies_len);
371
372 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700373
374 if (sta->auth_alg == WLAN_AUTH_FT)
375 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700376#else /* CONFIG_IEEE80211R */
377 /* Keep compiler silent about unused variables */
378 if (status) {
379 }
380#endif /* CONFIG_IEEE80211R */
381
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700382 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
383 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800384 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700385
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700386 hostapd_set_sta_flags(hapd, sta);
387
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700388 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
389 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
390 else
391 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700392
393 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
394
395 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
396
397#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800398 if (req_ies) {
399 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
400 req_ies, req_ies_len);
401 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700402#endif /* CONFIG_P2P */
403
404 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800405
406fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700407#ifdef CONFIG_IEEE80211R
408 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
409#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800410 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
411 ap_free_sta(hapd, sta);
412 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700413}
414
415
416void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
417{
418 struct sta_info *sta;
419
420 if (addr == NULL) {
421 /*
422 * This could potentially happen with unexpected event from the
423 * driver wrapper. This was seen at least in one case where the
424 * driver ended up reporting a station mode event while hostapd
425 * was running, so better make sure we stop processing such an
426 * event here.
427 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800428 wpa_printf(MSG_DEBUG,
429 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700430 return;
431 }
432
433 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
434 HOSTAPD_LEVEL_INFO, "disassociated");
435
436 sta = ap_get_sta(hapd, addr);
437 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800438 wpa_printf(MSG_DEBUG,
439 "Disassociation notification for unknown STA "
440 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700441 return;
442 }
443
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800444 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700445 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700446 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
447 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
448 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
449 ap_free_sta(hapd, sta);
450}
451
452
453void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
454{
455 struct sta_info *sta = ap_get_sta(hapd, addr);
456
457 if (!sta || !hapd->conf->disassoc_low_ack)
458 return;
459
460 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800461 HOSTAPD_LEVEL_INFO,
462 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700463 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
464 if (sta)
465 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
466}
467
468
Dmitry Shmidt04949592012-07-19 12:16:46 -0700469void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800470 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700471{
472#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800473 int channel, chwidth, is_dfs;
474 u8 seg0_idx = 0, seg1_idx = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700475
476 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800477 HOSTAPD_LEVEL_INFO,
478 "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
479 freq, ht, offset, width, channel_width_to_string(width),
480 cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700481
482 hapd->iface->freq = freq;
483
484 channel = hostapd_hw_get_channel(hapd, freq);
485 if (!channel) {
486 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800487 HOSTAPD_LEVEL_WARNING,
488 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700489 return;
490 }
491
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800492 switch (width) {
493 case CHAN_WIDTH_80:
494 chwidth = VHT_CHANWIDTH_80MHZ;
495 break;
496 case CHAN_WIDTH_80P80:
497 chwidth = VHT_CHANWIDTH_80P80MHZ;
498 break;
499 case CHAN_WIDTH_160:
500 chwidth = VHT_CHANWIDTH_160MHZ;
501 break;
502 case CHAN_WIDTH_20_NOHT:
503 case CHAN_WIDTH_20:
504 case CHAN_WIDTH_40:
505 default:
506 chwidth = VHT_CHANWIDTH_USE_HT;
507 break;
508 }
509
510 switch (hapd->iface->current_mode->mode) {
511 case HOSTAPD_MODE_IEEE80211A:
512 if (cf1 > 5000)
513 seg0_idx = (cf1 - 5000) / 5;
514 if (cf2 > 5000)
515 seg1_idx = (cf2 - 5000) / 5;
516 break;
517 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800518 ieee80211_freq_to_chan(cf1, &seg0_idx);
519 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800520 break;
521 }
522
Dmitry Shmidt04949592012-07-19 12:16:46 -0700523 hapd->iconf->channel = channel;
524 hapd->iconf->ieee80211n = ht;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800525 if (!ht)
526 hapd->iconf->ieee80211ac = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700527 hapd->iconf->secondary_channel = offset;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800528 hapd->iconf->vht_oper_chwidth = chwidth;
529 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
530 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800531
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800532 is_dfs = ieee80211_is_dfs(freq);
533
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700534 if (hapd->csa_in_progress &&
535 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800536 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700537 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800538
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800539 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
540 "freq=%d dfs=%d", freq, is_dfs);
541 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
542 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
543 "freq=%d dfs=%d", freq, is_dfs);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800544 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700545#endif /* NEED_AP_MLME */
546}
547
548
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800549void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
550 const u8 *addr, int reason_code)
551{
552 switch (reason_code) {
553 case MAX_CLIENT_REACHED:
554 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
555 MAC2STR(addr));
556 break;
557 case BLOCKED_CLIENT:
558 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
559 MAC2STR(addr));
560 break;
561 }
562}
563
564
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800565#ifdef CONFIG_ACS
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800566void hostapd_acs_channel_selected(struct hostapd_data *hapd,
567 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800568{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700569 int ret, i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800570
571 if (hapd->iconf->channel) {
572 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
573 hapd->iconf->channel);
574 return;
575 }
576
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700577 if (!hapd->iface->current_mode) {
578 for (i = 0; i < hapd->iface->num_hw_features; i++) {
579 struct hostapd_hw_modes *mode =
580 &hapd->iface->hw_features[i];
581
582 if (mode->mode == acs_res->hw_mode) {
583 hapd->iface->current_mode = mode;
584 break;
585 }
586 }
587 if (!hapd->iface->current_mode) {
588 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
589 HOSTAPD_LEVEL_WARNING,
590 "driver selected to bad hw_mode");
591 return;
592 }
593 }
594
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700595 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800596
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700597 if (!acs_res->pri_channel) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800598 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
599 HOSTAPD_LEVEL_WARNING,
600 "driver switched to bad channel");
601 return;
602 }
603
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700604 hapd->iconf->channel = acs_res->pri_channel;
605 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800606
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700607 if (acs_res->sec_channel == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800608 hapd->iconf->secondary_channel = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700609 else if (acs_res->sec_channel < acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800610 hapd->iconf->secondary_channel = -1;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700611 else if (acs_res->sec_channel > acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800612 hapd->iconf->secondary_channel = 1;
613 else {
614 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
615 return;
616 }
617
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700618 if (hapd->iface->conf->ieee80211ac) {
619 /* set defaults for backwards compatibility */
620 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
621 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
622 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
623 if (acs_res->ch_width == 80) {
624 hapd->iconf->vht_oper_centr_freq_seg0_idx =
625 acs_res->vht_seg0_center_ch;
626 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
627 } else if (acs_res->ch_width == 160) {
628 if (acs_res->vht_seg1_center_ch == 0) {
629 hapd->iconf->vht_oper_centr_freq_seg0_idx =
630 acs_res->vht_seg0_center_ch;
631 hapd->iconf->vht_oper_chwidth =
632 VHT_CHANWIDTH_160MHZ;
633 } else {
634 hapd->iconf->vht_oper_centr_freq_seg0_idx =
635 acs_res->vht_seg0_center_ch;
636 hapd->iconf->vht_oper_centr_freq_seg1_idx =
637 acs_res->vht_seg1_center_ch;
638 hapd->iconf->vht_oper_chwidth =
639 VHT_CHANWIDTH_80P80MHZ;
640 }
641 }
642 }
643
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800644 ret = hostapd_acs_completed(hapd->iface, 0);
645 if (ret) {
646 wpa_printf(MSG_ERROR,
647 "ACS: Possibly channel configuration is invalid");
648 }
649}
650#endif /* CONFIG_ACS */
651
652
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800653int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700654 const u8 *bssid, const u8 *ie, size_t ie_len,
655 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700656{
657 size_t i;
658 int ret = 0;
659
660 if (sa == NULL || ie == NULL)
661 return -1;
662
663 random_add_randomness(sa, ETH_ALEN);
664 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
665 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700666 sa, da, bssid, ie, ie_len,
667 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700668 ret = 1;
669 break;
670 }
671 }
672 return ret;
673}
674
675
676#ifdef HOSTAPD
677
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700678#ifdef CONFIG_IEEE80211R
679static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
680 const u8 *bssid,
681 u16 auth_transaction, u16 status,
682 const u8 *ies, size_t ies_len)
683{
684 struct hostapd_data *hapd = ctx;
685 struct sta_info *sta;
686
687 sta = ap_get_sta(hapd, dst);
688 if (sta == NULL)
689 return;
690
691 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
692 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
693 sta->flags |= WLAN_STA_AUTH;
694
695 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
696}
697#endif /* CONFIG_IEEE80211R */
698
699
700static void hostapd_notif_auth(struct hostapd_data *hapd,
701 struct auth_info *rx_auth)
702{
703 struct sta_info *sta;
704 u16 status = WLAN_STATUS_SUCCESS;
705 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
706 size_t resp_ies_len = 0;
707
708 sta = ap_get_sta(hapd, rx_auth->peer);
709 if (!sta) {
710 sta = ap_sta_add(hapd, rx_auth->peer);
711 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700712 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700713 goto fail;
714 }
715 }
716 sta->flags &= ~WLAN_STA_PREAUTH;
717 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
718#ifdef CONFIG_IEEE80211R
719 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
720 sta->auth_alg = WLAN_AUTH_FT;
721 if (sta->wpa_sm == NULL)
722 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700723 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700724 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800725 wpa_printf(MSG_DEBUG,
726 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700727 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
728 goto fail;
729 }
730 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
731 rx_auth->auth_transaction, rx_auth->ies,
732 rx_auth->ies_len,
733 hostapd_notify_auth_ft_finish, hapd);
734 return;
735 }
736#endif /* CONFIG_IEEE80211R */
737fail:
738 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
739 status, resp_ies, resp_ies_len);
740}
741
742
743static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800744 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700745{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800746 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700747 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800748 size_t plen __maybe_unused;
749 u16 fc;
750
751 if (drv_mgmt->frame_len < 24 + 1)
752 return;
753
754 plen = drv_mgmt->frame_len - 24 - 1;
755
756 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
757 fc = le_to_host16(mgmt->frame_control);
758 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
759 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700760
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800761 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800762 mgmt->u.action.category, (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700763
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800764 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700765 if (sta == NULL) {
766 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
767 return;
768 }
769#ifdef CONFIG_IEEE80211R
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800770 if (mgmt->u.action.category == WLAN_ACTION_FT) {
771 const u8 *payload = drv_mgmt->frame + 24 + 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800772
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800773 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700774 }
775#endif /* CONFIG_IEEE80211R */
776#ifdef CONFIG_IEEE80211W
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800777 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
778 ieee802_11_sa_query_action(
779 hapd, mgmt->sa,
780 mgmt->u.action.u.sa_query_resp.action,
781 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700782 }
783#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800784#ifdef CONFIG_WNM
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800785 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
786 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700787 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800788#endif /* CONFIG_WNM */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800789#ifdef CONFIG_FST
790 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
791 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
792 return;
793 }
794#endif /* CONFIG_FST */
795
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700796}
797
798
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700799#ifdef NEED_AP_MLME
800
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700801#define HAPD_BROADCAST ((struct hostapd_data *) -1)
802
803static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
804 const u8 *bssid)
805{
806 size_t i;
807
808 if (bssid == NULL)
809 return NULL;
810 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
811 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
812 return HAPD_BROADCAST;
813
814 for (i = 0; i < iface->num_bss; i++) {
815 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
816 return iface->bss[i];
817 }
818
819 return NULL;
820}
821
822
823static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800824 const u8 *bssid, const u8 *addr,
825 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700826{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800827 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700828 if (hapd == NULL || hapd == HAPD_BROADCAST)
829 return;
830
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800831 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700832}
833
834
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800835static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700836{
837 struct hostapd_iface *iface = hapd->iface;
838 const struct ieee80211_hdr *hdr;
839 const u8 *bssid;
840 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800841 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700842
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800843#ifdef CONFIG_TESTING_OPTIONS
844 if (hapd->ext_mgmt_frame_handling) {
845 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
846 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800847
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800848 if (hex) {
849 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
850 rx_mgmt->frame_len);
851 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
852 os_free(hex);
853 }
854 return 1;
855 }
856#endif /* CONFIG_TESTING_OPTIONS */
857
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700858 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
859 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
860 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800861 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700862
863 hapd = get_hapd_bssid(iface, bssid);
864 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800865 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700866
867 /*
868 * Drop frames to unknown BSSIDs except for Beacon frames which
869 * could be used to update neighbor information.
870 */
871 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
872 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
873 hapd = iface->bss[0];
874 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800875 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700876 }
877
878 os_memset(&fi, 0, sizeof(fi));
879 fi.datarate = rx_mgmt->datarate;
880 fi.ssi_signal = rx_mgmt->ssi_signal;
881
882 if (hapd == HAPD_BROADCAST) {
883 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800884
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800885 ret = 0;
886 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -0700887 /* if bss is set, driver will call this function for
888 * each bss individually. */
889 if (rx_mgmt->drv_priv &&
890 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
891 continue;
892
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800893 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
894 rx_mgmt->frame_len, &fi) > 0)
895 ret = 1;
896 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700897 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800898 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
899 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700900
901 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700902
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800903 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700904}
905
906
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700907static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
908 size_t len, u16 stype, int ok)
909{
910 struct ieee80211_hdr *hdr;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800911
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700912 hdr = (struct ieee80211_hdr *) buf;
913 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
914 if (hapd == NULL || hapd == HAPD_BROADCAST)
915 return;
916 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
917}
918
919#endif /* NEED_AP_MLME */
920
921
922static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
923{
924 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800925
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926 if (sta)
927 return 0;
928
929 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
930 " - adding a new STA", MAC2STR(addr));
931 sta = ap_sta_add(hapd, addr);
932 if (sta) {
933 hostapd_new_assoc_sta(hapd, sta, 0);
934 } else {
935 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
936 MAC2STR(addr));
937 return -1;
938 }
939
940 return 0;
941}
942
943
944static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
945 const u8 *data, size_t data_len)
946{
947 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800948 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700949 size_t j;
950
951 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800952 sta = ap_get_sta(iface->bss[j], src);
953 if (sta && sta->flags & WLAN_STA_ASSOC) {
954 hapd = iface->bss[j];
955 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700956 }
957 }
958
959 ieee802_1x_receive(hapd, src, data, data_len);
960}
961
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -0800962#endif /* HOSTAPD */
963
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700964
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700965static struct hostapd_channel_data * hostapd_get_mode_channel(
966 struct hostapd_iface *iface, unsigned int freq)
967{
968 int i;
969 struct hostapd_channel_data *chan;
970
971 for (i = 0; i < iface->current_mode->num_channels; i++) {
972 chan = &iface->current_mode->channels[i];
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700973 if ((unsigned int) chan->freq == freq)
974 return chan;
975 }
976
977 return NULL;
978}
979
980
981static void hostapd_update_nf(struct hostapd_iface *iface,
982 struct hostapd_channel_data *chan,
983 struct freq_survey *survey)
984{
985 if (!iface->chans_surveyed) {
986 chan->min_nf = survey->nf;
987 iface->lowest_nf = survey->nf;
988 } else {
989 if (dl_list_empty(&chan->survey_list))
990 chan->min_nf = survey->nf;
991 else if (survey->nf < chan->min_nf)
992 chan->min_nf = survey->nf;
993 if (survey->nf < iface->lowest_nf)
994 iface->lowest_nf = survey->nf;
995 }
996}
997
998
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800999static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
1000 struct survey_results *survey_res)
1001{
1002 struct hostapd_channel_data *chan;
1003 struct freq_survey *survey;
1004 u64 divisor, dividend;
1005
1006 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
1007 list);
1008 if (!survey || !survey->freq)
1009 return;
1010
1011 chan = hostapd_get_mode_channel(iface, survey->freq);
1012 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
1013 return;
1014
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001015 wpa_printf(MSG_DEBUG,
1016 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001017 survey->freq,
1018 (unsigned long int) survey->channel_time,
1019 (unsigned long int) survey->channel_time_busy);
1020
1021 if (survey->channel_time > iface->last_channel_time &&
1022 survey->channel_time > survey->channel_time_busy) {
1023 dividend = survey->channel_time_busy -
1024 iface->last_channel_time_busy;
1025 divisor = survey->channel_time - iface->last_channel_time;
1026
1027 iface->channel_utilization = dividend * 255 / divisor;
1028 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1029 iface->channel_utilization);
1030 }
1031 iface->last_channel_time = survey->channel_time;
1032 iface->last_channel_time_busy = survey->channel_time_busy;
1033}
1034
1035
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001036void hostapd_event_get_survey(struct hostapd_iface *iface,
1037 struct survey_results *survey_results)
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001038{
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001039 struct freq_survey *survey, *tmp;
1040 struct hostapd_channel_data *chan;
1041
1042 if (dl_list_empty(&survey_results->survey_list)) {
1043 wpa_printf(MSG_DEBUG, "No survey data received");
1044 return;
1045 }
1046
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001047 if (survey_results->freq_filter) {
1048 hostapd_single_channel_get_survey(iface, survey_results);
1049 return;
1050 }
1051
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001052 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1053 struct freq_survey, list) {
1054 chan = hostapd_get_mode_channel(iface, survey->freq);
1055 if (!chan)
1056 continue;
1057 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1058 continue;
1059
1060 dl_list_del(&survey->list);
1061 dl_list_add_tail(&chan->survey_list, &survey->list);
1062
1063 hostapd_update_nf(iface, chan, survey);
1064
1065 iface->chans_surveyed++;
1066 }
1067}
1068
1069
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001070#ifdef HOSTAPD
Dmitry Shmidt051af732013-10-22 13:52:46 -07001071#ifdef NEED_AP_MLME
1072
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001073static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1074{
1075 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1076 hapd->conf->iface);
1077
1078 if (hapd->csa_in_progress) {
1079 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1080 hapd->conf->iface);
1081 hostapd_switch_channel_fallback(hapd->iface,
1082 &hapd->cs_freq_params);
1083 }
1084}
1085
1086
Dmitry Shmidt051af732013-10-22 13:52:46 -07001087static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1088 struct dfs_event *radar)
1089{
1090 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001091 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001092 radar->chan_offset, radar->chan_width,
1093 radar->cf1, radar->cf2);
1094}
1095
1096
1097static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1098 struct dfs_event *radar)
1099{
1100 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001101 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001102 radar->chan_offset, radar->chan_width,
1103 radar->cf1, radar->cf2);
1104}
1105
1106
1107static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1108 struct dfs_event *radar)
1109{
1110 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001111 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001112 radar->chan_offset, radar->chan_width,
1113 radar->cf1, radar->cf2);
1114}
1115
1116
1117static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1118 struct dfs_event *radar)
1119{
1120 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001121 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001122 radar->chan_offset, radar->chan_width,
1123 radar->cf1, radar->cf2);
1124}
1125
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001126
1127static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1128 struct dfs_event *radar)
1129{
1130 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1131 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1132 radar->chan_offset, radar->chan_width,
1133 radar->cf1, radar->cf2);
1134}
1135
Dmitry Shmidt051af732013-10-22 13:52:46 -07001136#endif /* NEED_AP_MLME */
1137
1138
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001139void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1140 union wpa_event_data *data)
1141{
1142 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001143#ifndef CONFIG_NO_STDOUT_DEBUG
1144 int level = MSG_DEBUG;
1145
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001146 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001147 data->rx_mgmt.frame_len >= 24) {
1148 const struct ieee80211_hdr *hdr;
1149 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001150
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001151 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1152 fc = le_to_host16(hdr->frame_control);
1153 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1154 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1155 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001156 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1157 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1158 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001159 }
1160
1161 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1162 event_to_string(event), event);
1163#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001164
1165 switch (event) {
1166 case EVENT_MICHAEL_MIC_FAILURE:
1167 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1168 break;
1169 case EVENT_SCAN_RESULTS:
1170 if (hapd->iface->scan_cb)
1171 hapd->iface->scan_cb(hapd->iface);
1172 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001173 case EVENT_WPS_BUTTON_PUSHED:
1174 hostapd_wps_button_pushed(hapd, NULL);
1175 break;
1176#ifdef NEED_AP_MLME
1177 case EVENT_TX_STATUS:
1178 switch (data->tx_status.type) {
1179 case WLAN_FC_TYPE_MGMT:
1180 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1181 data->tx_status.data_len,
1182 data->tx_status.stype,
1183 data->tx_status.ack);
1184 break;
1185 case WLAN_FC_TYPE_DATA:
1186 hostapd_tx_status(hapd, data->tx_status.dst,
1187 data->tx_status.data,
1188 data->tx_status.data_len,
1189 data->tx_status.ack);
1190 break;
1191 }
1192 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001193 case EVENT_EAPOL_TX_STATUS:
1194 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1195 data->eapol_tx_status.data,
1196 data->eapol_tx_status.data_len,
1197 data->eapol_tx_status.ack);
1198 break;
1199 case EVENT_DRIVER_CLIENT_POLL_OK:
1200 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1201 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001202 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001203 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1204 data->rx_from_unknown.addr,
1205 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001206 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001207#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001208 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001209 if (!data->rx_mgmt.frame)
1210 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001211#ifdef NEED_AP_MLME
1212 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1213 break;
1214#endif /* NEED_AP_MLME */
1215 hostapd_action_rx(hapd, &data->rx_mgmt);
1216 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001217 case EVENT_RX_PROBE_REQ:
1218 if (data->rx_probe_req.sa == NULL ||
1219 data->rx_probe_req.ie == NULL)
1220 break;
1221 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001222 data->rx_probe_req.da,
1223 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001224 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001225 data->rx_probe_req.ie_len,
1226 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001227 break;
1228 case EVENT_NEW_STA:
1229 hostapd_event_new_sta(hapd, data->new_sta.addr);
1230 break;
1231 case EVENT_EAPOL_RX:
1232 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1233 data->eapol_rx.data,
1234 data->eapol_rx.data_len);
1235 break;
1236 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001237 if (!data)
1238 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001239 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1240 data->assoc_info.req_ies,
1241 data->assoc_info.req_ies_len,
1242 data->assoc_info.reassoc);
1243 break;
1244 case EVENT_DISASSOC:
1245 if (data)
1246 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1247 break;
1248 case EVENT_DEAUTH:
1249 if (data)
1250 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1251 break;
1252 case EVENT_STATION_LOW_ACK:
1253 if (!data)
1254 break;
1255 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1256 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001257 case EVENT_AUTH:
1258 hostapd_notif_auth(hapd, &data->auth);
1259 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001260 case EVENT_CH_SWITCH:
1261 if (!data)
1262 break;
1263 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1264 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001265 data->ch_switch.ch_offset,
1266 data->ch_switch.ch_width,
1267 data->ch_switch.cf1,
1268 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001269 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001270 case EVENT_CONNECT_FAILED_REASON:
1271 if (!data)
1272 break;
1273 hostapd_event_connect_failed_reason(
1274 hapd, data->connect_failed_reason.addr,
1275 data->connect_failed_reason.code);
1276 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001277 case EVENT_SURVEY:
Dmitry Shmidt014a3ff2015-12-28 13:27:49 -08001278 hostapd_event_get_survey(hapd->iface, &data->survey_results);
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001279 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001280#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001281 case EVENT_INTERFACE_UNAVAILABLE:
1282 hostapd_event_iface_unavailable(hapd);
1283 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001284 case EVENT_DFS_RADAR_DETECTED:
1285 if (!data)
1286 break;
1287 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1288 break;
1289 case EVENT_DFS_CAC_FINISHED:
1290 if (!data)
1291 break;
1292 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1293 break;
1294 case EVENT_DFS_CAC_ABORTED:
1295 if (!data)
1296 break;
1297 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1298 break;
1299 case EVENT_DFS_NOP_FINISHED:
1300 if (!data)
1301 break;
1302 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1303 break;
1304 case EVENT_CHANNEL_LIST_CHANGED:
1305 /* channel list changed (regulatory?), update channel list */
1306 /* TODO: check this. hostapd_get_hw_features() initializes
1307 * too much stuff. */
1308 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001309 hostapd_channel_list_updated(
1310 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001311 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001312 case EVENT_DFS_CAC_STARTED:
1313 if (!data)
1314 break;
1315 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1316 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001317#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001318 case EVENT_INTERFACE_ENABLED:
1319 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001320 if (hapd->disabled && hapd->started) {
1321 hapd->disabled = 0;
1322 /*
1323 * Try to re-enable interface if the driver stopped it
1324 * when the interface got disabled.
1325 */
1326 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1327 hapd->reenable_beacon = 1;
1328 ieee802_11_set_beacon(hapd);
1329 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001330 break;
1331 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001332 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001333 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001334 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001335 break;
1336#ifdef CONFIG_ACS
1337 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001338 hostapd_acs_channel_selected(hapd,
1339 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001340 break;
1341#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001342 default:
1343 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1344 break;
1345 }
1346}
1347
1348#endif /* HOSTAPD */