blob: 37537b3c649b0ae7f35e4955122aa2abfb781acd [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"
25#include "sta_info.h"
26#include "accounting.h"
27#include "tkip_countermeasures.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070028#include "ieee802_1x.h"
29#include "wpa_auth.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070030#include "wps_hostapd.h"
31#include "ap_drv_ops.h"
32#include "ap_config.h"
Dmitry Shmidt04949592012-07-19 12:16:46 -070033#include "hw_features.h"
Dmitry Shmidt051af732013-10-22 13:52:46 -070034#include "dfs.h"
Dmitry Shmidt7832adb2014-04-29 10:53:02 -070035#include "beacon.h"
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070036
37
38int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080039 const u8 *req_ies, size_t req_ies_len, int reassoc)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070040{
41 struct sta_info *sta;
42 int new_assoc, res;
43 struct ieee802_11_elems elems;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080044 const u8 *ie;
45 size_t ielen;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080046#if defined(CONFIG_IEEE80211R) || defined(CONFIG_IEEE80211W)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070047 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
48 u8 *p = buf;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080049#endif /* CONFIG_IEEE80211R || CONFIG_IEEE80211W */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080050 u16 reason = WLAN_REASON_UNSPECIFIED;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -070051 u16 status = WLAN_STATUS_SUCCESS;
Dmitry Shmidt391c59f2013-09-03 12:16:28 -070052 const u8 *p2p_dev_addr = NULL;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070053
54 if (addr == NULL) {
55 /*
56 * This could potentially happen with unexpected event from the
57 * driver wrapper. This was seen at least in one case where the
58 * driver ended up being set to station mode while hostapd was
59 * running, so better make sure we stop processing such an
60 * event here.
61 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080062 wpa_printf(MSG_DEBUG,
63 "hostapd_notif_assoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070064 return -1;
65 }
66 random_add_randomness(addr, ETH_ALEN);
67
68 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
69 HOSTAPD_LEVEL_INFO, "associated");
70
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -080071 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070072 if (elems.wps_ie) {
73 ie = elems.wps_ie - 2;
74 ielen = elems.wps_ie_len + 2;
75 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
76 } else if (elems.rsn_ie) {
77 ie = elems.rsn_ie - 2;
78 ielen = elems.rsn_ie_len + 2;
79 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
80 } else if (elems.wpa_ie) {
81 ie = elems.wpa_ie - 2;
82 ielen = elems.wpa_ie_len + 2;
83 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -080084#ifdef CONFIG_HS20
85 } else if (elems.osen) {
86 ie = elems.osen - 2;
87 ielen = elems.osen_len + 2;
88 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
89#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070090 } else {
91 ie = NULL;
92 ielen = 0;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -080093 wpa_printf(MSG_DEBUG,
94 "STA did not include WPS/RSN/WPA IE in (Re)AssocReq");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -070095 }
96
97 sta = ap_get_sta(hapd, addr);
98 if (sta) {
Dmitry Shmidt34af3062013-07-11 10:46:32 -070099 ap_sta_no_session_timeout(hapd, sta);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700100 accounting_sta_stop(hapd, sta);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700101
102 /*
103 * Make sure that the previously registered inactivity timer
104 * will not remove the STA immediately.
105 */
106 sta->timeout_next = STA_NULLFUNC;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700107 } else {
108 sta = ap_sta_add(hapd, addr);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700109 if (sta == NULL) {
110 hostapd_drv_sta_disassoc(hapd, addr,
111 WLAN_REASON_DISASSOC_AP_BUSY);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700112 return -1;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700113 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700114 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800115 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700116
117#ifdef CONFIG_P2P
118 if (elems.p2p) {
119 wpabuf_free(sta->p2p_ie);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800120 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700121 P2P_IE_VENDOR_TYPE);
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700122 if (sta->p2p_ie)
123 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700124 }
125#endif /* CONFIG_P2P */
126
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700127#ifdef CONFIG_IEEE80211N
128#ifdef NEED_AP_MLME
129 if (elems.ht_capabilities &&
Dmitry Shmidt7832adb2014-04-29 10:53:02 -0700130 (hapd->iface->conf->ht_capab &
131 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
132 struct ieee80211_ht_capabilities *ht_cap =
133 (struct ieee80211_ht_capabilities *)
134 elems.ht_capabilities;
135
136 if (le_to_host16(ht_cap->ht_capabilities_info) &
137 HT_CAP_INFO_40MHZ_INTOLERANT)
138 ht40_intolerant_add(hapd->iface, sta);
139 }
140#endif /* NEED_AP_MLME */
141#endif /* CONFIG_IEEE80211N */
142
Dmitry Shmidt051af732013-10-22 13:52:46 -0700143#ifdef CONFIG_INTERWORKING
144 if (elems.ext_capab && elems.ext_capab_len > 4) {
145 if (elems.ext_capab[4] & 0x01)
146 sta->qos_map_enabled = 1;
147 }
148#endif /* CONFIG_INTERWORKING */
149
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800150#ifdef CONFIG_HS20
151 wpabuf_free(sta->hs20_ie);
152 if (elems.hs20 && elems.hs20_len > 4) {
153 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
154 elems.hs20_len - 4);
155 } else
156 sta->hs20_ie = NULL;
157#endif /* CONFIG_HS20 */
158
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800159#ifdef CONFIG_FST
160 wpabuf_free(sta->mb_ies);
161 if (hapd->iface->fst)
162 sta->mb_ies = mb_ies_by_info(&elems.mb_ies);
163 else
164 sta->mb_ies = NULL;
165#endif /* CONFIG_FST */
166
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700167 if (hapd->conf->wpa) {
168 if (ie == NULL || ielen == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800169#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700170 if (hapd->conf->wps_state) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800171 wpa_printf(MSG_DEBUG,
172 "STA did not include WPA/RSN IE in (Re)Association Request - possible WPS use");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700173 sta->flags |= WLAN_STA_MAYBE_WPS;
174 goto skip_wpa_check;
175 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800176#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700177
178 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
179 return -1;
180 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800181#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700182 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
183 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800184 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800185
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700186 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800187 wps = ieee802_11_vendor_ie_concat(ie, ielen,
188 WPS_IE_VENDOR_TYPE);
189 if (wps) {
190 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800191 wpa_printf(MSG_DEBUG,
192 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800193 sta->flags |= WLAN_STA_WPS2;
194 }
195 wpabuf_free(wps);
196 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700197 goto skip_wpa_check;
198 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800199#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700200
201 if (sta->wpa_sm == NULL)
202 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700203 sta->addr,
204 p2p_dev_addr);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700205 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800206 wpa_printf(MSG_ERROR,
207 "Failed to initialize WPA state machine");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700208 return -1;
209 }
210 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700211 ie, ielen,
212 elems.mdie, elems.mdie_len);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700213 if (res != WPA_IE_OK) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800214 wpa_printf(MSG_DEBUG,
215 "WPA/RSN information element rejected? (res %u)",
216 res);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700217 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700218 if (res == WPA_INVALID_GROUP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800219 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700220 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
221 } else if (res == WPA_INVALID_PAIRWISE) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800222 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700223 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
224 } else if (res == WPA_INVALID_AKMP) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800225 reason = WLAN_REASON_AKMP_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700226 status = WLAN_STATUS_AKMP_NOT_VALID;
227 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700228#ifdef CONFIG_IEEE80211W
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700229 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800230 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700231 status = WLAN_STATUS_INVALID_IE;
232 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800233 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700234 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
235 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700236#endif /* CONFIG_IEEE80211W */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700237 else {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800238 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700239 status = WLAN_STATUS_INVALID_IE;
240 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800241 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700242 }
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700243#ifdef CONFIG_IEEE80211W
244 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
245 sta->sa_query_count > 0)
246 ap_check_sa_query_timeout(hapd, sta);
247 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
248 (sta->auth_alg != WLAN_AUTH_FT)) {
249 /*
250 * STA has already been associated with MFP and SA
251 * Query timeout has not been reached. Reject the
252 * association attempt temporarily and start SA Query,
253 * if one is not pending.
254 */
255
256 if (sta->sa_query_count == 0)
257 ap_sta_start_sa_query(hapd, sta);
258
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700259 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
260
261 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
262
263 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
264 p - buf);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700265 return 0;
266 }
267
268 if (wpa_auth_uses_mfp(sta->wpa_sm))
269 sta->flags |= WLAN_STA_MFP;
270 else
271 sta->flags &= ~WLAN_STA_MFP;
272#endif /* CONFIG_IEEE80211W */
273
274#ifdef CONFIG_IEEE80211R
275 if (sta->auth_alg == WLAN_AUTH_FT) {
276 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
277 req_ies_len);
278 if (status != WLAN_STATUS_SUCCESS) {
279 if (status == WLAN_STATUS_INVALID_PMKID)
280 reason = WLAN_REASON_INVALID_IE;
281 if (status == WLAN_STATUS_INVALID_MDIE)
282 reason = WLAN_REASON_INVALID_IE;
283 if (status == WLAN_STATUS_INVALID_FTIE)
284 reason = WLAN_REASON_INVALID_IE;
285 goto fail;
286 }
287 }
288#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700289 } else if (hapd->conf->wps_state) {
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800290#ifdef CONFIG_WPS
291 struct wpabuf *wps;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800292
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800293 if (req_ies)
294 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700295 WPS_IE_VENDOR_TYPE);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800296 else
297 wps = NULL;
298#ifdef CONFIG_WPS_STRICT
299 if (wps && wps_validate_assoc_req(wps) < 0) {
300 reason = WLAN_REASON_INVALID_IE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700301 status = WLAN_STATUS_INVALID_IE;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700302 wpabuf_free(wps);
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800303 goto fail;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700304 }
305#endif /* CONFIG_WPS_STRICT */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800306 if (wps) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700307 sta->flags |= WLAN_STA_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800308 if (wps_is_20(wps)) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800309 wpa_printf(MSG_DEBUG,
310 "WPS: STA supports WPS 2.0");
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800311 sta->flags |= WLAN_STA_WPS2;
312 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700313 } else
314 sta->flags |= WLAN_STA_MAYBE_WPS;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800315 wpabuf_free(wps);
316#endif /* CONFIG_WPS */
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800317#ifdef CONFIG_HS20
318 } else if (hapd->conf->osen) {
319 if (elems.osen == NULL) {
320 hostapd_logger(
321 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
322 HOSTAPD_LEVEL_INFO,
323 "No HS 2.0 OSEN element in association request");
324 return WLAN_STATUS_INVALID_IE;
325 }
326
327 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
328 if (sta->wpa_sm == NULL)
329 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
330 sta->addr, NULL);
331 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800332 wpa_printf(MSG_WARNING,
333 "Failed to initialize WPA state machine");
Dmitry Shmidtf21452a2014-02-26 10:55:25 -0800334 return WLAN_STATUS_UNSPECIFIED_FAILURE;
335 }
336 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
337 elems.osen - 2, elems.osen_len + 2) < 0)
338 return WLAN_STATUS_INVALID_IE;
339#endif /* CONFIG_HS20 */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700340 }
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800341#ifdef CONFIG_WPS
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700342skip_wpa_check:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800343#endif /* CONFIG_WPS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700344
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700345#ifdef CONFIG_IEEE80211R
346 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
347 sta->auth_alg, req_ies, req_ies_len);
348
349 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700350
351 if (sta->auth_alg == WLAN_AUTH_FT)
352 ap_sta_set_authorized(hapd, sta, 1);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700353#else /* CONFIG_IEEE80211R */
354 /* Keep compiler silent about unused variables */
355 if (status) {
356 }
357#endif /* CONFIG_IEEE80211R */
358
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700359 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
360 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800361 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700362
Dmitry Shmidt661b4f72014-09-29 14:58:27 -0700363 hostapd_set_sta_flags(hapd, sta);
364
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700365 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
366 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
367 else
368 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700369
370 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
371
372 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
373
374#ifdef CONFIG_P2P
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800375 if (req_ies) {
376 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
377 req_ies, req_ies_len);
378 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700379#endif /* CONFIG_P2P */
380
381 return 0;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800382
383fail:
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700384#ifdef CONFIG_IEEE80211R
385 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
386#endif /* CONFIG_IEEE80211R */
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800387 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
388 ap_free_sta(hapd, sta);
389 return -1;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700390}
391
392
393void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
394{
395 struct sta_info *sta;
396
397 if (addr == NULL) {
398 /*
399 * This could potentially happen with unexpected event from the
400 * driver wrapper. This was seen at least in one case where the
401 * driver ended up reporting a station mode event while hostapd
402 * was running, so better make sure we stop processing such an
403 * event here.
404 */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800405 wpa_printf(MSG_DEBUG,
406 "hostapd_notif_disassoc: Skip event with no address");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700407 return;
408 }
409
410 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
411 HOSTAPD_LEVEL_INFO, "disassociated");
412
413 sta = ap_get_sta(hapd, addr);
414 if (sta == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800415 wpa_printf(MSG_DEBUG,
416 "Disassociation notification for unknown STA "
417 MACSTR, MAC2STR(addr));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700418 return;
419 }
420
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800421 ap_sta_set_authorized(hapd, sta, 0);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700422 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700423 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
424 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
425 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
426 ap_free_sta(hapd, sta);
427}
428
429
430void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
431{
432 struct sta_info *sta = ap_get_sta(hapd, addr);
433
434 if (!sta || !hapd->conf->disassoc_low_ack)
435 return;
436
437 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800438 HOSTAPD_LEVEL_INFO,
439 "disconnected due to excessive missing ACKs");
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700440 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
441 if (sta)
442 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
443}
444
445
Dmitry Shmidt04949592012-07-19 12:16:46 -0700446void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800447 int offset, int width, int cf1, int cf2)
Dmitry Shmidt04949592012-07-19 12:16:46 -0700448{
449#ifdef NEED_AP_MLME
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800450 int channel, chwidth, is_dfs;
451 u8 seg0_idx = 0, seg1_idx = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700452
453 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800454 HOSTAPD_LEVEL_INFO,
455 "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
456 freq, ht, offset, width, channel_width_to_string(width),
457 cf1, cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -0700458
459 hapd->iface->freq = freq;
460
461 channel = hostapd_hw_get_channel(hapd, freq);
462 if (!channel) {
463 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800464 HOSTAPD_LEVEL_WARNING,
465 "driver switched to bad channel!");
Dmitry Shmidt04949592012-07-19 12:16:46 -0700466 return;
467 }
468
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800469 switch (width) {
470 case CHAN_WIDTH_80:
471 chwidth = VHT_CHANWIDTH_80MHZ;
472 break;
473 case CHAN_WIDTH_80P80:
474 chwidth = VHT_CHANWIDTH_80P80MHZ;
475 break;
476 case CHAN_WIDTH_160:
477 chwidth = VHT_CHANWIDTH_160MHZ;
478 break;
479 case CHAN_WIDTH_20_NOHT:
480 case CHAN_WIDTH_20:
481 case CHAN_WIDTH_40:
482 default:
483 chwidth = VHT_CHANWIDTH_USE_HT;
484 break;
485 }
486
487 switch (hapd->iface->current_mode->mode) {
488 case HOSTAPD_MODE_IEEE80211A:
489 if (cf1 > 5000)
490 seg0_idx = (cf1 - 5000) / 5;
491 if (cf2 > 5000)
492 seg1_idx = (cf2 - 5000) / 5;
493 break;
494 default:
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800495 ieee80211_freq_to_chan(cf1, &seg0_idx);
496 ieee80211_freq_to_chan(cf2, &seg1_idx);
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800497 break;
498 }
499
Dmitry Shmidt04949592012-07-19 12:16:46 -0700500 hapd->iconf->channel = channel;
501 hapd->iconf->ieee80211n = ht;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800502 if (!ht)
503 hapd->iconf->ieee80211ac = 0;
Dmitry Shmidt04949592012-07-19 12:16:46 -0700504 hapd->iconf->secondary_channel = offset;
Dmitry Shmidt04f534e2013-12-09 15:50:16 -0800505 hapd->iconf->vht_oper_chwidth = chwidth;
506 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
507 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800508
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800509 is_dfs = ieee80211_is_dfs(freq);
510
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700511 if (hapd->csa_in_progress &&
512 freq == hapd->cs_freq_params.freq) {
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800513 hostapd_cleanup_cs_params(hapd);
Dmitry Shmidtd30ac602014-06-30 09:54:22 -0700514 ieee802_11_set_beacon(hapd);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800515
Dmitry Shmidt203eadb2015-03-05 14:16:04 -0800516 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
517 "freq=%d dfs=%d", freq, is_dfs);
518 } else if (hapd->iface->drv_flags & WPA_DRIVER_FLAGS_DFS_OFFLOAD) {
519 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED
520 "freq=%d dfs=%d", freq, is_dfs);
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -0800521 }
Dmitry Shmidt04949592012-07-19 12:16:46 -0700522#endif /* NEED_AP_MLME */
523}
524
525
Dmitry Shmidtf8623282013-02-20 14:34:59 -0800526void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
527 const u8 *addr, int reason_code)
528{
529 switch (reason_code) {
530 case MAX_CLIENT_REACHED:
531 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
532 MAC2STR(addr));
533 break;
534 case BLOCKED_CLIENT:
535 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
536 MAC2STR(addr));
537 break;
538 }
539}
540
541
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800542#ifdef CONFIG_ACS
543static void hostapd_acs_channel_selected(struct hostapd_data *hapd,
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700544 struct acs_selected_channels *acs_res)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800545{
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700546 int ret, i;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800547
548 if (hapd->iconf->channel) {
549 wpa_printf(MSG_INFO, "ACS: Channel was already set to %d",
550 hapd->iconf->channel);
551 return;
552 }
553
Dmitry Shmidtb1e52102015-05-29 12:36:29 -0700554 if (!hapd->iface->current_mode) {
555 for (i = 0; i < hapd->iface->num_hw_features; i++) {
556 struct hostapd_hw_modes *mode =
557 &hapd->iface->hw_features[i];
558
559 if (mode->mode == acs_res->hw_mode) {
560 hapd->iface->current_mode = mode;
561 break;
562 }
563 }
564 if (!hapd->iface->current_mode) {
565 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
566 HOSTAPD_LEVEL_WARNING,
567 "driver selected to bad hw_mode");
568 return;
569 }
570 }
571
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700572 hapd->iface->freq = hostapd_hw_get_freq(hapd, acs_res->pri_channel);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800573
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700574 if (!acs_res->pri_channel) {
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800575 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
576 HOSTAPD_LEVEL_WARNING,
577 "driver switched to bad channel");
578 return;
579 }
580
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700581 hapd->iconf->channel = acs_res->pri_channel;
582 hapd->iconf->acs = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800583
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700584 if (acs_res->sec_channel == 0)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800585 hapd->iconf->secondary_channel = 0;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700586 else if (acs_res->sec_channel < acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800587 hapd->iconf->secondary_channel = -1;
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700588 else if (acs_res->sec_channel > acs_res->pri_channel)
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800589 hapd->iconf->secondary_channel = 1;
590 else {
591 wpa_printf(MSG_ERROR, "Invalid secondary channel!");
592 return;
593 }
594
Dmitry Shmidtdda10c22015-03-24 16:05:01 -0700595 if (hapd->iface->conf->ieee80211ac) {
596 /* set defaults for backwards compatibility */
597 hapd->iconf->vht_oper_centr_freq_seg1_idx = 0;
598 hapd->iconf->vht_oper_centr_freq_seg0_idx = 0;
599 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_USE_HT;
600 if (acs_res->ch_width == 80) {
601 hapd->iconf->vht_oper_centr_freq_seg0_idx =
602 acs_res->vht_seg0_center_ch;
603 hapd->iconf->vht_oper_chwidth = VHT_CHANWIDTH_80MHZ;
604 } else if (acs_res->ch_width == 160) {
605 if (acs_res->vht_seg1_center_ch == 0) {
606 hapd->iconf->vht_oper_centr_freq_seg0_idx =
607 acs_res->vht_seg0_center_ch;
608 hapd->iconf->vht_oper_chwidth =
609 VHT_CHANWIDTH_160MHZ;
610 } else {
611 hapd->iconf->vht_oper_centr_freq_seg0_idx =
612 acs_res->vht_seg0_center_ch;
613 hapd->iconf->vht_oper_centr_freq_seg1_idx =
614 acs_res->vht_seg1_center_ch;
615 hapd->iconf->vht_oper_chwidth =
616 VHT_CHANWIDTH_80P80MHZ;
617 }
618 }
619 }
620
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800621 ret = hostapd_acs_completed(hapd->iface, 0);
622 if (ret) {
623 wpa_printf(MSG_ERROR,
624 "ACS: Possibly channel configuration is invalid");
625 }
626}
627#endif /* CONFIG_ACS */
628
629
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800630int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700631 const u8 *bssid, const u8 *ie, size_t ie_len,
632 int ssi_signal)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700633{
634 size_t i;
635 int ret = 0;
636
637 if (sa == NULL || ie == NULL)
638 return -1;
639
640 random_add_randomness(sa, ETH_ALEN);
641 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
642 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
Dmitry Shmidt04949592012-07-19 12:16:46 -0700643 sa, da, bssid, ie, ie_len,
644 ssi_signal) > 0) {
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700645 ret = 1;
646 break;
647 }
648 }
649 return ret;
650}
651
652
653#ifdef HOSTAPD
654
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700655#ifdef CONFIG_IEEE80211R
656static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
657 const u8 *bssid,
658 u16 auth_transaction, u16 status,
659 const u8 *ies, size_t ies_len)
660{
661 struct hostapd_data *hapd = ctx;
662 struct sta_info *sta;
663
664 sta = ap_get_sta(hapd, dst);
665 if (sta == NULL)
666 return;
667
668 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
669 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
670 sta->flags |= WLAN_STA_AUTH;
671
672 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
673}
674#endif /* CONFIG_IEEE80211R */
675
676
677static void hostapd_notif_auth(struct hostapd_data *hapd,
678 struct auth_info *rx_auth)
679{
680 struct sta_info *sta;
681 u16 status = WLAN_STATUS_SUCCESS;
682 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
683 size_t resp_ies_len = 0;
684
685 sta = ap_get_sta(hapd, rx_auth->peer);
686 if (!sta) {
687 sta = ap_sta_add(hapd, rx_auth->peer);
688 if (sta == NULL) {
Dmitry Shmidt4b060592013-04-29 16:42:49 -0700689 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700690 goto fail;
691 }
692 }
693 sta->flags &= ~WLAN_STA_PREAUTH;
694 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
695#ifdef CONFIG_IEEE80211R
696 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
697 sta->auth_alg = WLAN_AUTH_FT;
698 if (sta->wpa_sm == NULL)
699 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
Dmitry Shmidt391c59f2013-09-03 12:16:28 -0700700 sta->addr, NULL);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700701 if (sta->wpa_sm == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800702 wpa_printf(MSG_DEBUG,
703 "FT: Failed to initialize WPA state machine");
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700704 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
705 goto fail;
706 }
707 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
708 rx_auth->auth_transaction, rx_auth->ies,
709 rx_auth->ies_len,
710 hostapd_notify_auth_ft_finish, hapd);
711 return;
712 }
713#endif /* CONFIG_IEEE80211R */
714fail:
715 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
716 status, resp_ies, resp_ies_len);
717}
718
719
720static void hostapd_action_rx(struct hostapd_data *hapd,
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800721 struct rx_mgmt *drv_mgmt)
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700722{
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800723 struct ieee80211_mgmt *mgmt;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700724 struct sta_info *sta;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800725 size_t plen __maybe_unused;
726 u16 fc;
727
728 if (drv_mgmt->frame_len < 24 + 1)
729 return;
730
731 plen = drv_mgmt->frame_len - 24 - 1;
732
733 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
734 fc = le_to_host16(mgmt->frame_control);
735 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
736 return; /* handled by the driver */
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700737
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800738 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800739 mgmt->u.action.category, (int) plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700740
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800741 sta = ap_get_sta(hapd, mgmt->sa);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700742 if (sta == NULL) {
743 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
744 return;
745 }
746#ifdef CONFIG_IEEE80211R
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800747 if (mgmt->u.action.category == WLAN_ACTION_FT) {
748 const u8 *payload = drv_mgmt->frame + 24 + 1;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800749
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800750 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700751 }
752#endif /* CONFIG_IEEE80211R */
753#ifdef CONFIG_IEEE80211W
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800754 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
755 ieee802_11_sa_query_action(
756 hapd, mgmt->sa,
757 mgmt->u.action.u.sa_query_resp.action,
758 mgmt->u.action.u.sa_query_resp.trans_id);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700759 }
760#endif /* CONFIG_IEEE80211W */
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800761#ifdef CONFIG_WNM
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800762 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
763 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700764 }
Dmitry Shmidta54fa5f2013-01-15 13:53:35 -0800765#endif /* CONFIG_WNM */
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800766#ifdef CONFIG_FST
767 if (mgmt->u.action.category == WLAN_ACTION_FST && hapd->iface->fst) {
768 fst_rx_action(hapd->iface->fst, mgmt, drv_mgmt->frame_len);
769 return;
770 }
771#endif /* CONFIG_FST */
772
Dmitry Shmidt61d9df32012-08-29 16:22:06 -0700773}
774
775
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700776#ifdef NEED_AP_MLME
777
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700778#define HAPD_BROADCAST ((struct hostapd_data *) -1)
779
780static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
781 const u8 *bssid)
782{
783 size_t i;
784
785 if (bssid == NULL)
786 return NULL;
787 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
788 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
789 return HAPD_BROADCAST;
790
791 for (i = 0; i < iface->num_bss; i++) {
792 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
793 return iface->bss[i];
794 }
795
796 return NULL;
797}
798
799
800static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800801 const u8 *bssid, const u8 *addr,
802 int wds)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700803{
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800804 hapd = get_hapd_bssid(hapd->iface, bssid);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700805 if (hapd == NULL || hapd == HAPD_BROADCAST)
806 return;
807
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -0800808 ieee802_11_rx_from_unknown(hapd, addr, wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700809}
810
811
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800812static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700813{
814 struct hostapd_iface *iface = hapd->iface;
815 const struct ieee80211_hdr *hdr;
816 const u8 *bssid;
817 struct hostapd_frame_info fi;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800818 int ret;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700819
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800820#ifdef CONFIG_TESTING_OPTIONS
821 if (hapd->ext_mgmt_frame_handling) {
822 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
823 char *hex = os_malloc(hex_len);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800824
Dmitry Shmidt7d5c8f22014-03-03 13:53:28 -0800825 if (hex) {
826 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
827 rx_mgmt->frame_len);
828 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
829 os_free(hex);
830 }
831 return 1;
832 }
833#endif /* CONFIG_TESTING_OPTIONS */
834
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700835 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
836 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
837 if (bssid == NULL)
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800838 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700839
840 hapd = get_hapd_bssid(iface, bssid);
841 if (hapd == NULL) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800842 u16 fc = le_to_host16(hdr->frame_control);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700843
844 /*
845 * Drop frames to unknown BSSIDs except for Beacon frames which
846 * could be used to update neighbor information.
847 */
848 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
849 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
850 hapd = iface->bss[0];
851 else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800852 return 0;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700853 }
854
855 os_memset(&fi, 0, sizeof(fi));
856 fi.datarate = rx_mgmt->datarate;
857 fi.ssi_signal = rx_mgmt->ssi_signal;
858
859 if (hapd == HAPD_BROADCAST) {
860 size_t i;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800861
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800862 ret = 0;
863 for (i = 0; i < iface->num_bss; i++) {
Dmitry Shmidt98660862014-03-11 17:26:21 -0700864 /* if bss is set, driver will call this function for
865 * each bss individually. */
866 if (rx_mgmt->drv_priv &&
867 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
868 continue;
869
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800870 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
871 rx_mgmt->frame_len, &fi) > 0)
872 ret = 1;
873 }
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700874 } else
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800875 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
876 &fi);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700877
878 random_add_randomness(&fi, sizeof(fi));
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700879
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -0800880 return ret;
Jouni Malinen75ecf522011-06-27 15:19:46 -0700881}
882
883
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700884static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
885 size_t len, u16 stype, int ok)
886{
887 struct ieee80211_hdr *hdr;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800888
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700889 hdr = (struct ieee80211_hdr *) buf;
890 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
891 if (hapd == NULL || hapd == HAPD_BROADCAST)
892 return;
893 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
894}
895
896#endif /* NEED_AP_MLME */
897
898
899static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
900{
901 struct sta_info *sta = ap_get_sta(hapd, addr);
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800902
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700903 if (sta)
904 return 0;
905
906 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
907 " - adding a new STA", MAC2STR(addr));
908 sta = ap_sta_add(hapd, addr);
909 if (sta) {
910 hostapd_new_assoc_sta(hapd, sta, 0);
911 } else {
912 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
913 MAC2STR(addr));
914 return -1;
915 }
916
917 return 0;
918}
919
920
921static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
922 const u8 *data, size_t data_len)
923{
924 struct hostapd_iface *iface = hapd->iface;
Dmitry Shmidtd5e49232012-12-03 15:08:10 -0800925 struct sta_info *sta;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700926 size_t j;
927
928 for (j = 0; j < iface->num_bss; j++) {
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800929 sta = ap_get_sta(iface->bss[j], src);
930 if (sta && sta->flags & WLAN_STA_ASSOC) {
931 hapd = iface->bss[j];
932 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -0700933 }
934 }
935
936 ieee802_1x_receive(hapd, src, data, data_len);
937}
938
939
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -0700940static struct hostapd_channel_data * hostapd_get_mode_channel(
941 struct hostapd_iface *iface, unsigned int freq)
942{
943 int i;
944 struct hostapd_channel_data *chan;
945
946 for (i = 0; i < iface->current_mode->num_channels; i++) {
947 chan = &iface->current_mode->channels[i];
948 if (!chan)
949 return NULL;
950 if ((unsigned int) chan->freq == freq)
951 return chan;
952 }
953
954 return NULL;
955}
956
957
958static void hostapd_update_nf(struct hostapd_iface *iface,
959 struct hostapd_channel_data *chan,
960 struct freq_survey *survey)
961{
962 if (!iface->chans_surveyed) {
963 chan->min_nf = survey->nf;
964 iface->lowest_nf = survey->nf;
965 } else {
966 if (dl_list_empty(&chan->survey_list))
967 chan->min_nf = survey->nf;
968 else if (survey->nf < chan->min_nf)
969 chan->min_nf = survey->nf;
970 if (survey->nf < iface->lowest_nf)
971 iface->lowest_nf = survey->nf;
972 }
973}
974
975
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800976static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
977 struct survey_results *survey_res)
978{
979 struct hostapd_channel_data *chan;
980 struct freq_survey *survey;
981 u64 divisor, dividend;
982
983 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
984 list);
985 if (!survey || !survey->freq)
986 return;
987
988 chan = hostapd_get_mode_channel(iface, survey->freq);
989 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
990 return;
991
Dmitry Shmidtd80a4012015-11-05 16:35:40 -0800992 wpa_printf(MSG_DEBUG,
993 "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -0800994 survey->freq,
995 (unsigned long int) survey->channel_time,
996 (unsigned long int) survey->channel_time_busy);
997
998 if (survey->channel_time > iface->last_channel_time &&
999 survey->channel_time > survey->channel_time_busy) {
1000 dividend = survey->channel_time_busy -
1001 iface->last_channel_time_busy;
1002 divisor = survey->channel_time - iface->last_channel_time;
1003
1004 iface->channel_utilization = dividend * 255 / divisor;
1005 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
1006 iface->channel_utilization);
1007 }
1008 iface->last_channel_time = survey->channel_time;
1009 iface->last_channel_time_busy = survey->channel_time_busy;
1010}
1011
1012
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001013static void hostapd_event_get_survey(struct hostapd_data *hapd,
1014 struct survey_results *survey_results)
1015{
1016 struct hostapd_iface *iface = hapd->iface;
1017 struct freq_survey *survey, *tmp;
1018 struct hostapd_channel_data *chan;
1019
1020 if (dl_list_empty(&survey_results->survey_list)) {
1021 wpa_printf(MSG_DEBUG, "No survey data received");
1022 return;
1023 }
1024
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001025 if (survey_results->freq_filter) {
1026 hostapd_single_channel_get_survey(iface, survey_results);
1027 return;
1028 }
1029
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001030 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
1031 struct freq_survey, list) {
1032 chan = hostapd_get_mode_channel(iface, survey->freq);
1033 if (!chan)
1034 continue;
1035 if (chan->flag & HOSTAPD_CHAN_DISABLED)
1036 continue;
1037
1038 dl_list_del(&survey->list);
1039 dl_list_add_tail(&chan->survey_list, &survey->list);
1040
1041 hostapd_update_nf(iface, chan, survey);
1042
1043 iface->chans_surveyed++;
1044 }
1045}
1046
1047
Dmitry Shmidt051af732013-10-22 13:52:46 -07001048#ifdef NEED_AP_MLME
1049
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001050static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
1051{
1052 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
1053 hapd->conf->iface);
1054
1055 if (hapd->csa_in_progress) {
1056 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
1057 hapd->conf->iface);
1058 hostapd_switch_channel_fallback(hapd->iface,
1059 &hapd->cs_freq_params);
1060 }
1061}
1062
1063
Dmitry Shmidt051af732013-10-22 13:52:46 -07001064static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
1065 struct dfs_event *radar)
1066{
1067 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001068 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001069 radar->chan_offset, radar->chan_width,
1070 radar->cf1, radar->cf2);
1071}
1072
1073
1074static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
1075 struct dfs_event *radar)
1076{
1077 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001078 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001079 radar->chan_offset, radar->chan_width,
1080 radar->cf1, radar->cf2);
1081}
1082
1083
1084static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
1085 struct dfs_event *radar)
1086{
1087 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001088 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001089 radar->chan_offset, radar->chan_width,
1090 radar->cf1, radar->cf2);
1091}
1092
1093
1094static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
1095 struct dfs_event *radar)
1096{
1097 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
Dmitry Shmidtcce06662013-11-04 18:44:24 -08001098 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
Dmitry Shmidt051af732013-10-22 13:52:46 -07001099 radar->chan_offset, radar->chan_width,
1100 radar->cf1, radar->cf2);
1101}
1102
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001103
1104static void hostapd_event_dfs_cac_started(struct hostapd_data *hapd,
1105 struct dfs_event *radar)
1106{
1107 wpa_printf(MSG_DEBUG, "DFS offload CAC started on %d MHz", radar->freq);
1108 hostapd_dfs_start_cac(hapd->iface, radar->freq, radar->ht_enabled,
1109 radar->chan_offset, radar->chan_width,
1110 radar->cf1, radar->cf2);
1111}
1112
Dmitry Shmidt051af732013-10-22 13:52:46 -07001113#endif /* NEED_AP_MLME */
1114
1115
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001116void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
1117 union wpa_event_data *data)
1118{
1119 struct hostapd_data *hapd = ctx;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001120#ifndef CONFIG_NO_STDOUT_DEBUG
1121 int level = MSG_DEBUG;
1122
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001123 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001124 data->rx_mgmt.frame_len >= 24) {
1125 const struct ieee80211_hdr *hdr;
1126 u16 fc;
Dmitry Shmidtd80a4012015-11-05 16:35:40 -08001127
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001128 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1129 fc = le_to_host16(hdr->frame_control);
1130 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1131 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1132 level = MSG_EXCESSIVE;
Dmitry Shmidt8da800a2013-04-24 12:57:01 -07001133 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1134 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1135 level = MSG_EXCESSIVE;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001136 }
1137
1138 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
1139 event_to_string(event), event);
1140#endif /* CONFIG_NO_STDOUT_DEBUG */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001141
1142 switch (event) {
1143 case EVENT_MICHAEL_MIC_FAILURE:
1144 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1145 break;
1146 case EVENT_SCAN_RESULTS:
1147 if (hapd->iface->scan_cb)
1148 hapd->iface->scan_cb(hapd->iface);
1149 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001150 case EVENT_WPS_BUTTON_PUSHED:
1151 hostapd_wps_button_pushed(hapd, NULL);
1152 break;
1153#ifdef NEED_AP_MLME
1154 case EVENT_TX_STATUS:
1155 switch (data->tx_status.type) {
1156 case WLAN_FC_TYPE_MGMT:
1157 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1158 data->tx_status.data_len,
1159 data->tx_status.stype,
1160 data->tx_status.ack);
1161 break;
1162 case WLAN_FC_TYPE_DATA:
1163 hostapd_tx_status(hapd, data->tx_status.dst,
1164 data->tx_status.data,
1165 data->tx_status.data_len,
1166 data->tx_status.ack);
1167 break;
1168 }
1169 break;
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001170 case EVENT_EAPOL_TX_STATUS:
1171 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1172 data->eapol_tx_status.data,
1173 data->eapol_tx_status.data_len,
1174 data->eapol_tx_status.ack);
1175 break;
1176 case EVENT_DRIVER_CLIENT_POLL_OK:
1177 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1178 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001179 case EVENT_RX_FROM_UNKNOWN:
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001180 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1181 data->rx_from_unknown.addr,
1182 data->rx_from_unknown.wds);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001183 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001184#endif /* NEED_AP_MLME */
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001185 case EVENT_RX_MGMT:
Dmitry Shmidt7832adb2014-04-29 10:53:02 -07001186 if (!data->rx_mgmt.frame)
1187 break;
Dmitry Shmidtfb79edc2014-01-10 10:45:54 -08001188#ifdef NEED_AP_MLME
1189 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1190 break;
1191#endif /* NEED_AP_MLME */
1192 hostapd_action_rx(hapd, &data->rx_mgmt);
1193 break;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001194 case EVENT_RX_PROBE_REQ:
1195 if (data->rx_probe_req.sa == NULL ||
1196 data->rx_probe_req.ie == NULL)
1197 break;
1198 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
Dmitry Shmidt1f69aa52012-01-24 16:10:04 -08001199 data->rx_probe_req.da,
1200 data->rx_probe_req.bssid,
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001201 data->rx_probe_req.ie,
Dmitry Shmidt04949592012-07-19 12:16:46 -07001202 data->rx_probe_req.ie_len,
1203 data->rx_probe_req.ssi_signal);
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001204 break;
1205 case EVENT_NEW_STA:
1206 hostapd_event_new_sta(hapd, data->new_sta.addr);
1207 break;
1208 case EVENT_EAPOL_RX:
1209 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1210 data->eapol_rx.data,
1211 data->eapol_rx.data_len);
1212 break;
1213 case EVENT_ASSOC:
Dmitry Shmidt661b4f72014-09-29 14:58:27 -07001214 if (!data)
1215 return;
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001216 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1217 data->assoc_info.req_ies,
1218 data->assoc_info.req_ies_len,
1219 data->assoc_info.reassoc);
1220 break;
1221 case EVENT_DISASSOC:
1222 if (data)
1223 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1224 break;
1225 case EVENT_DEAUTH:
1226 if (data)
1227 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1228 break;
1229 case EVENT_STATION_LOW_ACK:
1230 if (!data)
1231 break;
1232 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1233 break;
Dmitry Shmidt61d9df32012-08-29 16:22:06 -07001234 case EVENT_AUTH:
1235 hostapd_notif_auth(hapd, &data->auth);
1236 break;
Dmitry Shmidt04949592012-07-19 12:16:46 -07001237 case EVENT_CH_SWITCH:
1238 if (!data)
1239 break;
1240 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1241 data->ch_switch.ht_enabled,
Dmitry Shmidt04f534e2013-12-09 15:50:16 -08001242 data->ch_switch.ch_offset,
1243 data->ch_switch.ch_width,
1244 data->ch_switch.cf1,
1245 data->ch_switch.cf2);
Dmitry Shmidt04949592012-07-19 12:16:46 -07001246 break;
Dmitry Shmidtf8623282013-02-20 14:34:59 -08001247 case EVENT_CONNECT_FAILED_REASON:
1248 if (!data)
1249 break;
1250 hostapd_event_connect_failed_reason(
1251 hapd, data->connect_failed_reason.addr,
1252 data->connect_failed_reason.code);
1253 break;
Dmitry Shmidtb7b4d0e2013-08-26 12:09:05 -07001254 case EVENT_SURVEY:
1255 hostapd_event_get_survey(hapd, &data->survey_results);
1256 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001257#ifdef NEED_AP_MLME
Dmitry Shmidtd30ac602014-06-30 09:54:22 -07001258 case EVENT_INTERFACE_UNAVAILABLE:
1259 hostapd_event_iface_unavailable(hapd);
1260 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001261 case EVENT_DFS_RADAR_DETECTED:
1262 if (!data)
1263 break;
1264 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1265 break;
1266 case EVENT_DFS_CAC_FINISHED:
1267 if (!data)
1268 break;
1269 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1270 break;
1271 case EVENT_DFS_CAC_ABORTED:
1272 if (!data)
1273 break;
1274 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1275 break;
1276 case EVENT_DFS_NOP_FINISHED:
1277 if (!data)
1278 break;
1279 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1280 break;
1281 case EVENT_CHANNEL_LIST_CHANGED:
1282 /* channel list changed (regulatory?), update channel list */
1283 /* TODO: check this. hostapd_get_hw_features() initializes
1284 * too much stuff. */
1285 /* hostapd_get_hw_features(hapd->iface); */
Dmitry Shmidte0e48dc2013-11-18 12:00:06 -08001286 hostapd_channel_list_updated(
1287 hapd->iface, data->channel_list_changed.initiator);
Dmitry Shmidt051af732013-10-22 13:52:46 -07001288 break;
Dmitry Shmidt203eadb2015-03-05 14:16:04 -08001289 case EVENT_DFS_CAC_STARTED:
1290 if (!data)
1291 break;
1292 hostapd_event_dfs_cac_started(hapd, &data->dfs_event);
1293 break;
Dmitry Shmidt051af732013-10-22 13:52:46 -07001294#endif /* NEED_AP_MLME */
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001295 case EVENT_INTERFACE_ENABLED:
1296 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001297 if (hapd->disabled && hapd->started) {
1298 hapd->disabled = 0;
1299 /*
1300 * Try to re-enable interface if the driver stopped it
1301 * when the interface got disabled.
1302 */
1303 wpa_auth_reconfig_group_keys(hapd->wpa_auth);
1304 hapd->reenable_beacon = 1;
1305 ieee802_11_set_beacon(hapd);
1306 }
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001307 break;
1308 case EVENT_INTERFACE_DISABLED:
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001309 hostapd_free_stas(hapd);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001310 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
Dmitry Shmidt7f656022015-02-25 14:36:37 -08001311 hapd->disabled = 1;
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001312 break;
1313#ifdef CONFIG_ACS
1314 case EVENT_ACS_CHANNEL_SELECTED:
Dmitry Shmidtdda10c22015-03-24 16:05:01 -07001315 hostapd_acs_channel_selected(hapd,
1316 &data->acs_selected_channels);
Dmitry Shmidt6c0da2b2015-01-05 13:08:17 -08001317 break;
1318#endif /* CONFIG_ACS */
Dmitry Shmidt8d520ff2011-05-09 14:06:53 -07001319 default:
1320 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1321 break;
1322 }
1323}
1324
1325#endif /* HOSTAPD */