blob: a8c24ebdf800f7c79ec48075f0591148eadc6b12 [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"
12#include "radius/radius.h"
13#include "drivers/driver.h"
14#include "common/ieee802_11_defs.h"
15#include "common/ieee802_11_common.h"
Dmitry Shmidtf8623282013-02-20 14:34:59 -080016#include "common/wpa_ctrl.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070017#include "crypto/random.h"
18#include "p2p/p2p.h"
19#include "wps/wps.h"
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070020#include "wnm_ap.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070021#include "hostapd.h"
22#include "ieee802_11.h"
23#include "sta_info.h"
24#include "accounting.h"
25#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070026#include "ieee802_1x.h"
27#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "wps_hostapd.h"
29#include "ap_drv_ops.h"
30#include "ap_config.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070031#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070032#include "dfs.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070033
34
35int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080036 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070037{
38 struct sta_info *sta;
39 int new_assoc, res;
40 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080041 const u8 *ie;
42 size_t ielen;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070043#ifdef CONFIG_IEEE80211R
44 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
45 u8 *p = buf;
46#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080047 u16 reason = WLAN_REASON_UNSPECIFIED;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070048 u16 status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070049 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070050
51 if (addr == NULL) {
52 /*
53 * This could potentially happen with unexpected event from the
54 * driver wrapper. This was seen at least in one case where the
55 * driver ended up being set to station mode while hostapd was
56 * running, so better make sure we stop processing such an
57 * event here.
58 */
59 wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with "
60 "no address");
61 return -1;
62 }
63 random_add_randomness(addr, ETH_ALEN);
64
65 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
66 HOSTAPD_LEVEL_INFO, "associated");
67
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080068 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070069 if (elems.wps_ie) {
70 ie = elems.wps_ie - 2;
71 ielen = elems.wps_ie_len + 2;
72 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
73 } else if (elems.rsn_ie) {
74 ie = elems.rsn_ie - 2;
75 ielen = elems.rsn_ie_len + 2;
76 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
77 } else if (elems.wpa_ie) {
78 ie = elems.wpa_ie - 2;
79 ielen = elems.wpa_ie_len + 2;
80 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080081#ifdef CONFIG_HS20
82 } else if (elems.osen) {
83 ie = elems.osen - 2;
84 ielen = elems.osen_len + 2;
85 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
86#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070087 } else {
88 ie = NULL;
89 ielen = 0;
90 wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in "
91 "(Re)AssocReq");
92 }
93
94 sta = ap_get_sta(hapd, addr);
95 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -070096 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070097 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -070098
99 /*
100 * Make sure that the previously registered inactivity timer
101 * will not remove the STA immediately.
102 */
103 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700104 } else {
105 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700106 if (sta == NULL) {
107 hostapd_drv_sta_disassoc(hapd, addr,
108 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700109 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700110 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700111 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800112 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700113
114#ifdef CONFIG_P2P
115 if (elems.p2p) {
116 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800117 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700118 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700119 if (sta->p2p_ie)
120 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121 }
122#endif /* CONFIG_P2P */
123
Dmitry Shmidt051af732013-10-22 13:52:46 -0700124#ifdef CONFIG_INTERWORKING
125 if (elems.ext_capab && elems.ext_capab_len > 4) {
126 if (elems.ext_capab[4] & 0x01)
127 sta->qos_map_enabled = 1;
128 }
129#endif /* CONFIG_INTERWORKING */
130
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800131#ifdef CONFIG_HS20
132 wpabuf_free(sta->hs20_ie);
133 if (elems.hs20 && elems.hs20_len > 4) {
134 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
135 elems.hs20_len - 4);
136 } else
137 sta->hs20_ie = NULL;
138#endif /* CONFIG_HS20 */
139
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700140 if (hapd->conf->wpa) {
141 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800142#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700143 if (hapd->conf->wps_state) {
144 wpa_printf(MSG_DEBUG, "STA did not include "
145 "WPA/RSN IE in (Re)Association "
146 "Request - possible WPS use");
147 sta->flags |= WLAN_STA_MAYBE_WPS;
148 goto skip_wpa_check;
149 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800150#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700151
152 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
153 return -1;
154 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800155#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700156 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
157 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800158 struct wpabuf *wps;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700159 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800160 wps = ieee802_11_vendor_ie_concat(ie, ielen,
161 WPS_IE_VENDOR_TYPE);
162 if (wps) {
163 if (wps_is_20(wps)) {
164 wpa_printf(MSG_DEBUG, "WPS: STA "
165 "supports WPS 2.0");
166 sta->flags |= WLAN_STA_WPS2;
167 }
168 wpabuf_free(wps);
169 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 goto skip_wpa_check;
171 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800172#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173
174 if (sta->wpa_sm == NULL)
175 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700176 sta->addr,
177 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700178 if (sta->wpa_sm == NULL) {
179 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
180 "machine");
181 return -1;
182 }
183 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700184 ie, ielen,
185 elems.mdie, elems.mdie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186 if (res != WPA_IE_OK) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700187 wpa_printf(MSG_DEBUG, "WPA/RSN information element "
188 "rejected? (res %u)", res);
189 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700190 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800191 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700192 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
193 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800194 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700195 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
196 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800197 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700198 status = WLAN_STATUS_AKMP_NOT_VALID;
199 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700200#ifdef CONFIG_IEEE80211W
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700201 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800202 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700203 status = WLAN_STATUS_INVALID_IE;
204 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800205 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700206 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
207 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700209 else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800210 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700211 status = WLAN_STATUS_INVALID_IE;
212 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800213 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700214 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700215#ifdef CONFIG_IEEE80211W
216 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
217 sta->sa_query_count > 0)
218 ap_check_sa_query_timeout(hapd, sta);
219 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
220 (sta->auth_alg != WLAN_AUTH_FT)) {
221 /*
222 * STA has already been associated with MFP and SA
223 * Query timeout has not been reached. Reject the
224 * association attempt temporarily and start SA Query,
225 * if one is not pending.
226 */
227
228 if (sta->sa_query_count == 0)
229 ap_sta_start_sa_query(hapd, sta);
230
231#ifdef CONFIG_IEEE80211R
232 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
233
234 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
235
236 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
237 p - buf);
238#endif /* CONFIG_IEEE80211R */
239 return 0;
240 }
241
242 if (wpa_auth_uses_mfp(sta->wpa_sm))
243 sta->flags |= WLAN_STA_MFP;
244 else
245 sta->flags &= ~WLAN_STA_MFP;
246#endif /* CONFIG_IEEE80211W */
247
248#ifdef CONFIG_IEEE80211R
249 if (sta->auth_alg == WLAN_AUTH_FT) {
250 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
251 req_ies_len);
252 if (status != WLAN_STATUS_SUCCESS) {
253 if (status == WLAN_STATUS_INVALID_PMKID)
254 reason = WLAN_REASON_INVALID_IE;
255 if (status == WLAN_STATUS_INVALID_MDIE)
256 reason = WLAN_REASON_INVALID_IE;
257 if (status == WLAN_STATUS_INVALID_FTIE)
258 reason = WLAN_REASON_INVALID_IE;
259 goto fail;
260 }
261 }
262#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700263 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800264#ifdef CONFIG_WPS
265 struct wpabuf *wps;
266 if (req_ies)
267 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700268 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800269 else
270 wps = NULL;
271#ifdef CONFIG_WPS_STRICT
272 if (wps && wps_validate_assoc_req(wps) < 0) {
273 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700274 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700275 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800276 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700277 }
278#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800279 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700280 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800281 if (wps_is_20(wps)) {
282 wpa_printf(MSG_DEBUG, "WPS: STA supports "
283 "WPS 2.0");
284 sta->flags |= WLAN_STA_WPS2;
285 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700286 } else
287 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800288 wpabuf_free(wps);
289#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800290#ifdef CONFIG_HS20
291 } else if (hapd->conf->osen) {
292 if (elems.osen == NULL) {
293 hostapd_logger(
294 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
295 HOSTAPD_LEVEL_INFO,
296 "No HS 2.0 OSEN element in association request");
297 return WLAN_STATUS_INVALID_IE;
298 }
299
300 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
301 if (sta->wpa_sm == NULL)
302 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
303 sta->addr, NULL);
304 if (sta->wpa_sm == NULL) {
305 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
306 "state machine");
307 return WLAN_STATUS_UNSPECIFIED_FAILURE;
308 }
309 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
310 elems.osen - 2, elems.osen_len + 2) < 0)
311 return WLAN_STATUS_INVALID_IE;
312#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800314#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700315skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800316#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700317
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700318#ifdef CONFIG_IEEE80211R
319 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
320 sta->auth_alg, req_ies, req_ies_len);
321
322 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
323#else /* CONFIG_IEEE80211R */
324 /* Keep compiler silent about unused variables */
325 if (status) {
326 }
327#endif /* CONFIG_IEEE80211R */
328
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700329 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
330 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800331 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700332
333 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
334 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
335 else
336 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700337
338 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
339
340 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
341
342#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800343 if (req_ies) {
344 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
345 req_ies, req_ies_len);
346 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700347#endif /* CONFIG_P2P */
348
349 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800350
351fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700352#ifdef CONFIG_IEEE80211R
353 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
354#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800355 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
356 ap_free_sta(hapd, sta);
357 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700358}
359
360
361void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
362{
363 struct sta_info *sta;
364
365 if (addr == NULL) {
366 /*
367 * This could potentially happen with unexpected event from the
368 * driver wrapper. This was seen at least in one case where the
369 * driver ended up reporting a station mode event while hostapd
370 * was running, so better make sure we stop processing such an
371 * event here.
372 */
373 wpa_printf(MSG_DEBUG, "hostapd_notif_disassoc: Skip event "
374 "with no address");
375 return;
376 }
377
378 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
379 HOSTAPD_LEVEL_INFO, "disassociated");
380
381 sta = ap_get_sta(hapd, addr);
382 if (sta == NULL) {
383 wpa_printf(MSG_DEBUG, "Disassociation notification for "
384 "unknown STA " MACSTR, MAC2STR(addr));
385 return;
386 }
387
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800388 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700389 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
391 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
392 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
393 ap_free_sta(hapd, sta);
394}
395
396
397void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
398{
399 struct sta_info *sta = ap_get_sta(hapd, addr);
400
401 if (!sta || !hapd->conf->disassoc_low_ack)
402 return;
403
404 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
405 HOSTAPD_LEVEL_INFO, "disconnected due to excessive "
406 "missing ACKs");
407 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
408 if (sta)
409 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
410}
411
412
Dmitry Shmidt04949592012-07-19 12:16:46 -0700413void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800414 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700415{
416#ifdef NEED_AP_MLME
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800417 int channel, chwidth, seg0_idx = 0, seg1_idx = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700418
419 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
420 HOSTAPD_LEVEL_INFO, "driver had channel switch: "
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800421 "freq=%d, ht=%d, offset=%d, width=%d, cf1=%d, cf2=%d",
422 freq, ht, offset, width, cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700423
424 hapd->iface->freq = freq;
425
426 channel = hostapd_hw_get_channel(hapd, freq);
427 if (!channel) {
428 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
429 HOSTAPD_LEVEL_WARNING, "driver switched to "
430 "bad channel!");
431 return;
432 }
433
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800434 switch (width) {
435 case CHAN_WIDTH_80:
436 chwidth = VHT_CHANWIDTH_80MHZ;
437 break;
438 case CHAN_WIDTH_80P80:
439 chwidth = VHT_CHANWIDTH_80P80MHZ;
440 break;
441 case CHAN_WIDTH_160:
442 chwidth = VHT_CHANWIDTH_160MHZ;
443 break;
444 case CHAN_WIDTH_20_NOHT:
445 case CHAN_WIDTH_20:
446 case CHAN_WIDTH_40:
447 default:
448 chwidth = VHT_CHANWIDTH_USE_HT;
449 break;
450 }
451
452 switch (hapd->iface->current_mode->mode) {
453 case HOSTAPD_MODE_IEEE80211A:
454 if (cf1 > 5000)
455 seg0_idx = (cf1 - 5000) / 5;
456 if (cf2 > 5000)
457 seg1_idx = (cf2 - 5000) / 5;
458 break;
459 default:
460 seg0_idx = hostapd_hw_get_channel(hapd, cf1);
461 seg1_idx = hostapd_hw_get_channel(hapd, cf2);
462 break;
463 }
464
Dmitry Shmidt04949592012-07-19 12:16:46 -0700465 hapd->iconf->channel = channel;
466 hapd->iconf->ieee80211n = ht;
467 hapd->iconf->secondary_channel = offset;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800468 hapd->iconf->vht_oper_chwidth = chwidth;
469 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
470 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800471
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800472 if (hapd->iface->csa_in_progress &&
473 freq == hapd->iface->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800474 hostapd_cleanup_cs_params(hapd);
475
476 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED "freq=%d",
477 freq);
478 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700479#endif /* NEED_AP_MLME */
480}
481
482
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800483void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
484 const u8 *addr, int reason_code)
485{
486 switch (reason_code) {
487 case MAX_CLIENT_REACHED:
488 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
489 MAC2STR(addr));
490 break;
491 case BLOCKED_CLIENT:
492 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
493 MAC2STR(addr));
494 break;
495 }
496}
497
498
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800499int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700500 const u8 *bssid, const u8 *ie, size_t ie_len,
501 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700502{
503 size_t i;
504 int ret = 0;
505
506 if (sa == NULL || ie == NULL)
507 return -1;
508
509 random_add_randomness(sa, ETH_ALEN);
510 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
511 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700512 sa, da, bssid, ie, ie_len,
513 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700514 ret = 1;
515 break;
516 }
517 }
518 return ret;
519}
520
521
522#ifdef HOSTAPD
523
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700524#ifdef CONFIG_IEEE80211R
525static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
526 const u8 *bssid,
527 u16 auth_transaction, u16 status,
528 const u8 *ies, size_t ies_len)
529{
530 struct hostapd_data *hapd = ctx;
531 struct sta_info *sta;
532
533 sta = ap_get_sta(hapd, dst);
534 if (sta == NULL)
535 return;
536
537 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
538 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
539 sta->flags |= WLAN_STA_AUTH;
540
541 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
542}
543#endif /* CONFIG_IEEE80211R */
544
545
546static void hostapd_notif_auth(struct hostapd_data *hapd,
547 struct auth_info *rx_auth)
548{
549 struct sta_info *sta;
550 u16 status = WLAN_STATUS_SUCCESS;
551 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
552 size_t resp_ies_len = 0;
553
554 sta = ap_get_sta(hapd, rx_auth->peer);
555 if (!sta) {
556 sta = ap_sta_add(hapd, rx_auth->peer);
557 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700558 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700559 goto fail;
560 }
561 }
562 sta->flags &= ~WLAN_STA_PREAUTH;
563 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
564#ifdef CONFIG_IEEE80211R
565 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
566 sta->auth_alg = WLAN_AUTH_FT;
567 if (sta->wpa_sm == NULL)
568 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700569 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700570 if (sta->wpa_sm == NULL) {
571 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
572 "state machine");
573 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
574 goto fail;
575 }
576 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
577 rx_auth->auth_transaction, rx_auth->ies,
578 rx_auth->ies_len,
579 hostapd_notify_auth_ft_finish, hapd);
580 return;
581 }
582#endif /* CONFIG_IEEE80211R */
583fail:
584 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
585 status, resp_ies, resp_ies_len);
586}
587
588
589static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800590 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700591{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800592 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700593 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800594 size_t plen __maybe_unused;
595 u16 fc;
596
597 if (drv_mgmt->frame_len < 24 + 1)
598 return;
599
600 plen = drv_mgmt->frame_len - 24 - 1;
601
602 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
603 fc = le_to_host16(mgmt->frame_control);
604 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
605 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700606
607 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800608 mgmt->u.action.category, (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700609
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800610 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700611 if (sta == NULL) {
612 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
613 return;
614 }
615#ifdef CONFIG_IEEE80211R
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800616 if (mgmt->u.action.category == WLAN_ACTION_FT) {
617 const u8 *payload = drv_mgmt->frame + 24 + 1;
618 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700619 }
620#endif /* CONFIG_IEEE80211R */
621#ifdef CONFIG_IEEE80211W
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800622 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
623 ieee802_11_sa_query_action(
624 hapd, mgmt->sa,
625 mgmt->u.action.u.sa_query_resp.action,
626 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700627 }
628#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800629#ifdef CONFIG_WNM
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800630 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
631 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700632 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800633#endif /* CONFIG_WNM */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700634}
635
636
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700637#ifdef NEED_AP_MLME
638
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700639#define HAPD_BROADCAST ((struct hostapd_data *) -1)
640
641static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
642 const u8 *bssid)
643{
644 size_t i;
645
646 if (bssid == NULL)
647 return NULL;
648 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
649 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
650 return HAPD_BROADCAST;
651
652 for (i = 0; i < iface->num_bss; i++) {
653 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
654 return iface->bss[i];
655 }
656
657 return NULL;
658}
659
660
661static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800662 const u8 *bssid, const u8 *addr,
663 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700664{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800665 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700666 if (hapd == NULL || hapd == HAPD_BROADCAST)
667 return;
668
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800669 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700670}
671
672
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800673static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700674{
675 struct hostapd_iface *iface = hapd->iface;
676 const struct ieee80211_hdr *hdr;
677 const u8 *bssid;
678 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800679 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700680
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800681#ifdef CONFIG_TESTING_OPTIONS
682 if (hapd->ext_mgmt_frame_handling) {
683 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
684 char *hex = os_malloc(hex_len);
685 if (hex) {
686 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
687 rx_mgmt->frame_len);
688 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
689 os_free(hex);
690 }
691 return 1;
692 }
693#endif /* CONFIG_TESTING_OPTIONS */
694
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700695 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
696 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
697 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800698 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700699
700 hapd = get_hapd_bssid(iface, bssid);
701 if (hapd == NULL) {
702 u16 fc;
703 fc = le_to_host16(hdr->frame_control);
704
705 /*
706 * Drop frames to unknown BSSIDs except for Beacon frames which
707 * could be used to update neighbor information.
708 */
709 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
710 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
711 hapd = iface->bss[0];
712 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800713 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700714 }
715
716 os_memset(&fi, 0, sizeof(fi));
717 fi.datarate = rx_mgmt->datarate;
718 fi.ssi_signal = rx_mgmt->ssi_signal;
719
720 if (hapd == HAPD_BROADCAST) {
721 size_t i;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800722 ret = 0;
723 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -0700724 /* if bss is set, driver will call this function for
725 * each bss individually. */
726 if (rx_mgmt->drv_priv &&
727 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
728 continue;
729
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800730 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
731 rx_mgmt->frame_len, &fi) > 0)
732 ret = 1;
733 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700734 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800735 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
736 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700737
738 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700739
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800740 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700741}
742
743
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700744static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
745 size_t len, u16 stype, int ok)
746{
747 struct ieee80211_hdr *hdr;
748 hdr = (struct ieee80211_hdr *) buf;
749 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
750 if (hapd == NULL || hapd == HAPD_BROADCAST)
751 return;
752 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
753}
754
755#endif /* NEED_AP_MLME */
756
757
758static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
759{
760 struct sta_info *sta = ap_get_sta(hapd, addr);
761 if (sta)
762 return 0;
763
764 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
765 " - adding a new STA", MAC2STR(addr));
766 sta = ap_sta_add(hapd, addr);
767 if (sta) {
768 hostapd_new_assoc_sta(hapd, sta, 0);
769 } else {
770 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
771 MAC2STR(addr));
772 return -1;
773 }
774
775 return 0;
776}
777
778
779static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
780 const u8 *data, size_t data_len)
781{
782 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800783 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700784 size_t j;
785
786 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800787 if ((sta = ap_get_sta(iface->bss[j], src))) {
788 if (sta->flags & WLAN_STA_ASSOC) {
789 hapd = iface->bss[j];
790 break;
791 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700792 }
793 }
794
795 ieee802_1x_receive(hapd, src, data, data_len);
796}
797
798
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700799static struct hostapd_channel_data * hostapd_get_mode_channel(
800 struct hostapd_iface *iface, unsigned int freq)
801{
802 int i;
803 struct hostapd_channel_data *chan;
804
805 for (i = 0; i < iface->current_mode->num_channels; i++) {
806 chan = &iface->current_mode->channels[i];
807 if (!chan)
808 return NULL;
809 if ((unsigned int) chan->freq == freq)
810 return chan;
811 }
812
813 return NULL;
814}
815
816
817static void hostapd_update_nf(struct hostapd_iface *iface,
818 struct hostapd_channel_data *chan,
819 struct freq_survey *survey)
820{
821 if (!iface->chans_surveyed) {
822 chan->min_nf = survey->nf;
823 iface->lowest_nf = survey->nf;
824 } else {
825 if (dl_list_empty(&chan->survey_list))
826 chan->min_nf = survey->nf;
827 else if (survey->nf < chan->min_nf)
828 chan->min_nf = survey->nf;
829 if (survey->nf < iface->lowest_nf)
830 iface->lowest_nf = survey->nf;
831 }
832}
833
834
835static void hostapd_event_get_survey(struct hostapd_data *hapd,
836 struct survey_results *survey_results)
837{
838 struct hostapd_iface *iface = hapd->iface;
839 struct freq_survey *survey, *tmp;
840 struct hostapd_channel_data *chan;
841
842 if (dl_list_empty(&survey_results->survey_list)) {
843 wpa_printf(MSG_DEBUG, "No survey data received");
844 return;
845 }
846
847 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
848 struct freq_survey, list) {
849 chan = hostapd_get_mode_channel(iface, survey->freq);
850 if (!chan)
851 continue;
852 if (chan->flag & HOSTAPD_CHAN_DISABLED)
853 continue;
854
855 dl_list_del(&survey->list);
856 dl_list_add_tail(&chan->survey_list, &survey->list);
857
858 hostapd_update_nf(iface, chan, survey);
859
860 iface->chans_surveyed++;
861 }
862}
863
864
Dmitry Shmidt051af732013-10-22 13:52:46 -0700865#ifdef NEED_AP_MLME
866
867static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
868 struct dfs_event *radar)
869{
870 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800871 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700872 radar->chan_offset, radar->chan_width,
873 radar->cf1, radar->cf2);
874}
875
876
877static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
878 struct dfs_event *radar)
879{
880 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800881 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700882 radar->chan_offset, radar->chan_width,
883 radar->cf1, radar->cf2);
884}
885
886
887static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
888 struct dfs_event *radar)
889{
890 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800891 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700892 radar->chan_offset, radar->chan_width,
893 radar->cf1, radar->cf2);
894}
895
896
897static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
898 struct dfs_event *radar)
899{
900 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -0800901 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -0700902 radar->chan_offset, radar->chan_width,
903 radar->cf1, radar->cf2);
904}
905
906#endif /* NEED_AP_MLME */
907
908
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700909void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
910 union wpa_event_data *data)
911{
912 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800913#ifndef CONFIG_NO_STDOUT_DEBUG
914 int level = MSG_DEBUG;
915
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700916 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800917 data->rx_mgmt.frame_len >= 24) {
918 const struct ieee80211_hdr *hdr;
919 u16 fc;
920 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
921 fc = le_to_host16(hdr->frame_control);
922 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
923 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
924 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -0700925 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
926 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
927 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800928 }
929
930 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
931 event_to_string(event), event);
932#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933
934 switch (event) {
935 case EVENT_MICHAEL_MIC_FAILURE:
936 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
937 break;
938 case EVENT_SCAN_RESULTS:
939 if (hapd->iface->scan_cb)
940 hapd->iface->scan_cb(hapd->iface);
941 break;
942#ifdef CONFIG_IEEE80211R
943 case EVENT_FT_RRB_RX:
944 wpa_ft_rrb_rx(hapd->wpa_auth, data->ft_rrb_rx.src,
945 data->ft_rrb_rx.data, data->ft_rrb_rx.data_len);
946 break;
947#endif /* CONFIG_IEEE80211R */
948 case EVENT_WPS_BUTTON_PUSHED:
949 hostapd_wps_button_pushed(hapd, NULL);
950 break;
951#ifdef NEED_AP_MLME
952 case EVENT_TX_STATUS:
953 switch (data->tx_status.type) {
954 case WLAN_FC_TYPE_MGMT:
955 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
956 data->tx_status.data_len,
957 data->tx_status.stype,
958 data->tx_status.ack);
959 break;
960 case WLAN_FC_TYPE_DATA:
961 hostapd_tx_status(hapd, data->tx_status.dst,
962 data->tx_status.data,
963 data->tx_status.data_len,
964 data->tx_status.ack);
965 break;
966 }
967 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800968 case EVENT_EAPOL_TX_STATUS:
969 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
970 data->eapol_tx_status.data,
971 data->eapol_tx_status.data_len,
972 data->eapol_tx_status.ack);
973 break;
974 case EVENT_DRIVER_CLIENT_POLL_OK:
975 hostapd_client_poll_ok(hapd, data->client_poll.addr);
976 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700977 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800978 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
979 data->rx_from_unknown.addr,
980 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700981 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700982#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800983 case EVENT_RX_MGMT:
984#ifdef NEED_AP_MLME
985 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
986 break;
987#endif /* NEED_AP_MLME */
988 hostapd_action_rx(hapd, &data->rx_mgmt);
989 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700990 case EVENT_RX_PROBE_REQ:
991 if (data->rx_probe_req.sa == NULL ||
992 data->rx_probe_req.ie == NULL)
993 break;
994 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800995 data->rx_probe_req.da,
996 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700997 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700998 data->rx_probe_req.ie_len,
999 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001000 break;
1001 case EVENT_NEW_STA:
1002 hostapd_event_new_sta(hapd, data->new_sta.addr);
1003 break;
1004 case EVENT_EAPOL_RX:
1005 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1006 data->eapol_rx.data,
1007 data->eapol_rx.data_len);
1008 break;
1009 case EVENT_ASSOC:
1010 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1011 data->assoc_info.req_ies,
1012 data->assoc_info.req_ies_len,
1013 data->assoc_info.reassoc);
1014 break;
1015 case EVENT_DISASSOC:
1016 if (data)
1017 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1018 break;
1019 case EVENT_DEAUTH:
1020 if (data)
1021 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1022 break;
1023 case EVENT_STATION_LOW_ACK:
1024 if (!data)
1025 break;
1026 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1027 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001028 case EVENT_AUTH:
1029 hostapd_notif_auth(hapd, &data->auth);
1030 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001031 case EVENT_CH_SWITCH:
1032 if (!data)
1033 break;
1034 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1035 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001036 data->ch_switch.ch_offset,
1037 data->ch_switch.ch_width,
1038 data->ch_switch.cf1,
1039 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001040 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001041 case EVENT_CONNECT_FAILED_REASON:
1042 if (!data)
1043 break;
1044 hostapd_event_connect_failed_reason(
1045 hapd, data->connect_failed_reason.addr,
1046 data->connect_failed_reason.code);
1047 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001048 case EVENT_SURVEY:
1049 hostapd_event_get_survey(hapd, &data->survey_results);
1050 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001051#ifdef NEED_AP_MLME
1052 case EVENT_DFS_RADAR_DETECTED:
1053 if (!data)
1054 break;
1055 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1056 break;
1057 case EVENT_DFS_CAC_FINISHED:
1058 if (!data)
1059 break;
1060 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1061 break;
1062 case EVENT_DFS_CAC_ABORTED:
1063 if (!data)
1064 break;
1065 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1066 break;
1067 case EVENT_DFS_NOP_FINISHED:
1068 if (!data)
1069 break;
1070 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1071 break;
1072 case EVENT_CHANNEL_LIST_CHANGED:
1073 /* channel list changed (regulatory?), update channel list */
1074 /* TODO: check this. hostapd_get_hw_features() initializes
1075 * too much stuff. */
1076 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001077 hostapd_channel_list_updated(
1078 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001079 break;
1080#endif /* NEED_AP_MLME */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001081 default:
1082 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1083 break;
1084 }
1085}
1086
1087#endif /* HOSTAPD */