]> git.ipfire.org Git - thirdparty/hostap.git/blame - src/ap/drv_callbacks.c
Return only full network line in list_networks
[thirdparty/hostap.git] / src / ap / drv_callbacks.c
CommitLineData
b5b969e9
JM
1/*
2 * hostapd / Callback functions for driver wrappers
94ddef3e 3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
b5b969e9 4 *
0f3d578e
JM
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
b5b969e9
JM
7 */
8
6226e38d 9#include "utils/includes.h"
b5b969e9 10
6226e38d 11#include "utils/common.h"
9c47f6a2 12#include "utils/eloop.h"
b5b969e9 13#include "radius/radius.h"
6e6e8c31 14#include "drivers/driver.h"
81f4f619 15#include "common/ieee802_11_defs.h"
c41a1095 16#include "common/ieee802_11_common.h"
3140803b 17#include "common/wpa_ctrl.h"
bbb921da 18#include "crypto/random.h"
ef796391 19#include "p2p/p2p.h"
54f489be 20#include "wps/wps.h"
d32d94db 21#include "wnm_ap.h"
6226e38d
JM
22#include "hostapd.h"
23#include "ieee802_11.h"
24#include "sta_info.h"
25#include "accounting.h"
26#include "tkip_countermeasures.h"
6226e38d
JM
27#include "ieee802_1x.h"
28#include "wpa_auth.h"
6226e38d 29#include "wps_hostapd.h"
51e2a27a 30#include "ap_drv_ops.h"
8b06c1ed 31#include "ap_config.h"
1b487b8b 32#include "hw_features.h"
e76da505 33#include "dfs.h"
9c47f6a2 34#include "beacon.h"
b5b969e9
JM
35
36
b5b969e9 37int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
2bb20281 38 const u8 *req_ies, size_t req_ies_len, int reassoc)
b5b969e9
JM
39{
40 struct sta_info *sta;
41 int new_assoc, res;
c41a1095 42 struct ieee802_11_elems elems;
2bb20281
JM
43 const u8 *ie;
44 size_t ielen;
88b32a99
SP
45#ifdef CONFIG_IEEE80211R
46 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
47 u8 *p = buf;
48#endif /* CONFIG_IEEE80211R */
08a74e6a 49 u16 reason = WLAN_REASON_UNSPECIFIED;
88b32a99 50 u16 status = WLAN_STATUS_SUCCESS;
94ddef3e 51 const u8 *p2p_dev_addr = NULL;
b5b969e9 52
68532a9c
JM
53 if (addr == NULL) {
54 /*
55 * This could potentially happen with unexpected event from the
56 * driver wrapper. This was seen at least in one case where the
57 * driver ended up being set to station mode while hostapd was
58 * running, so better make sure we stop processing such an
59 * event here.
60 */
61 wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with "
62 "no address");
63 return -1;
64 }
bbb921da 65 random_add_randomness(addr, ETH_ALEN);
68532a9c 66
b5b969e9
JM
67 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
68 HOSTAPD_LEVEL_INFO, "associated");
69
2bb20281 70 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
c41a1095
JM
71 if (elems.wps_ie) {
72 ie = elems.wps_ie - 2;
73 ielen = elems.wps_ie_len + 2;
74 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
75 } else if (elems.rsn_ie) {
76 ie = elems.rsn_ie - 2;
77 ielen = elems.rsn_ie_len + 2;
78 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
79 } else if (elems.wpa_ie) {
80 ie = elems.wpa_ie - 2;
81 ielen = elems.wpa_ie_len + 2;
82 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
a14896e8
JM
83#ifdef CONFIG_HS20
84 } else if (elems.osen) {
85 ie = elems.osen - 2;
86 ielen = elems.osen_len + 2;
87 wpa_printf(MSG_DEBUG, "STA included OSEN IE in (Re)AssocReq");
88#endif /* CONFIG_HS20 */
c41a1095
JM
89 } else {
90 ie = NULL;
91 ielen = 0;
92 wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in "
93 "(Re)AssocReq");
94 }
95
b5b969e9
JM
96 sta = ap_get_sta(hapd, addr);
97 if (sta) {
4331263b 98 ap_sta_no_session_timeout(hapd, sta);
b5b969e9 99 accounting_sta_stop(hapd, sta);
c72bd6d4
JM
100
101 /*
102 * Make sure that the previously registered inactivity timer
103 * will not remove the STA immediately.
104 */
105 sta->timeout_next = STA_NULLFUNC;
b5b969e9
JM
106 } else {
107 sta = ap_sta_add(hapd, addr);
8bd0fc0e
JM
108 if (sta == NULL) {
109 hostapd_drv_sta_disassoc(hapd, addr,
110 WLAN_REASON_DISASSOC_AP_BUSY);
b5b969e9 111 return -1;
8bd0fc0e 112 }
b5b969e9 113 }
17f6b900 114 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
b5b969e9 115
b305c684
JM
116#ifdef CONFIG_P2P
117 if (elems.p2p) {
118 wpabuf_free(sta->p2p_ie);
2bb20281 119 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
b305c684 120 P2P_IE_VENDOR_TYPE);
94ddef3e
JM
121 if (sta->p2p_ie)
122 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
b305c684
JM
123 }
124#endif /* CONFIG_P2P */
125
9c47f6a2
PX
126#ifdef CONFIG_IEEE80211N
127#ifdef NEED_AP_MLME
128 if (elems.ht_capabilities &&
129 elems.ht_capabilities_len >=
130 sizeof(struct ieee80211_ht_capabilities) &&
131 (hapd->iface->conf->ht_capab &
132 HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) {
133 struct ieee80211_ht_capabilities *ht_cap =
134 (struct ieee80211_ht_capabilities *)
135 elems.ht_capabilities;
136
137 if (le_to_host16(ht_cap->ht_capabilities_info) &
138 HT_CAP_INFO_40MHZ_INTOLERANT)
139 ht40_intolerant_add(hapd->iface, sta);
140 }
141#endif /* NEED_AP_MLME */
142#endif /* CONFIG_IEEE80211N */
143
c551700f
KP
144#ifdef CONFIG_INTERWORKING
145 if (elems.ext_capab && elems.ext_capab_len > 4) {
146 if (elems.ext_capab[4] & 0x01)
147 sta->qos_map_enabled = 1;
148 }
149#endif /* CONFIG_INTERWORKING */
150
f403dcd6
JM
151#ifdef CONFIG_HS20
152 wpabuf_free(sta->hs20_ie);
153 if (elems.hs20 && elems.hs20_len > 4) {
154 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
155 elems.hs20_len - 4);
156 } else
157 sta->hs20_ie = NULL;
158#endif /* CONFIG_HS20 */
159
b5b969e9
JM
160 if (hapd->conf->wpa) {
161 if (ie == NULL || ielen == 0) {
633d4469 162#ifdef CONFIG_WPS
b5b969e9
JM
163 if (hapd->conf->wps_state) {
164 wpa_printf(MSG_DEBUG, "STA did not include "
165 "WPA/RSN IE in (Re)Association "
166 "Request - possible WPS use");
167 sta->flags |= WLAN_STA_MAYBE_WPS;
168 goto skip_wpa_check;
169 }
633d4469 170#endif /* CONFIG_WPS */
b5b969e9
JM
171
172 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
173 return -1;
174 }
633d4469 175#ifdef CONFIG_WPS
b5b969e9
JM
176 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
177 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
17f6b900 178 struct wpabuf *wps;
b5b969e9 179 sta->flags |= WLAN_STA_WPS;
17f6b900
JM
180 wps = ieee802_11_vendor_ie_concat(ie, ielen,
181 WPS_IE_VENDOR_TYPE);
182 if (wps) {
183 if (wps_is_20(wps)) {
184 wpa_printf(MSG_DEBUG, "WPS: STA "
185 "supports WPS 2.0");
186 sta->flags |= WLAN_STA_WPS2;
187 }
188 wpabuf_free(wps);
189 }
b5b969e9
JM
190 goto skip_wpa_check;
191 }
633d4469 192#endif /* CONFIG_WPS */
b5b969e9
JM
193
194 if (sta->wpa_sm == NULL)
195 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
94ddef3e
JM
196 sta->addr,
197 p2p_dev_addr);
b5b969e9
JM
198 if (sta->wpa_sm == NULL) {
199 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
200 "machine");
201 return -1;
202 }
203 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
88b32a99
SP
204 ie, ielen,
205 elems.mdie, elems.mdie_len);
b5b969e9
JM
206 if (res != WPA_IE_OK) {
207 wpa_printf(MSG_DEBUG, "WPA/RSN information element "
208 "rejected? (res %u)", res);
209 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
88b32a99 210 if (res == WPA_INVALID_GROUP) {
08a74e6a 211 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
88b32a99
SP
212 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
213 } else if (res == WPA_INVALID_PAIRWISE) {
08a74e6a 214 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
88b32a99
SP
215 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
216 } else if (res == WPA_INVALID_AKMP) {
08a74e6a 217 reason = WLAN_REASON_AKMP_NOT_VALID;
88b32a99
SP
218 status = WLAN_STATUS_AKMP_NOT_VALID;
219 }
355d36a7 220#ifdef CONFIG_IEEE80211W
88b32a99 221 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
08a74e6a 222 reason = WLAN_REASON_INVALID_IE;
88b32a99
SP
223 status = WLAN_STATUS_INVALID_IE;
224 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
08a74e6a 225 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
88b32a99
SP
226 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
227 }
355d36a7 228#endif /* CONFIG_IEEE80211W */
88b32a99 229 else {
08a74e6a 230 reason = WLAN_REASON_INVALID_IE;
88b32a99
SP
231 status = WLAN_STATUS_INVALID_IE;
232 }
08a74e6a 233 goto fail;
b5b969e9 234 }
7d9c0cd3
MP
235#ifdef CONFIG_IEEE80211W
236 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
237 sta->sa_query_count > 0)
238 ap_check_sa_query_timeout(hapd, sta);
239 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
240 (sta->auth_alg != WLAN_AUTH_FT)) {
241 /*
242 * STA has already been associated with MFP and SA
243 * Query timeout has not been reached. Reject the
244 * association attempt temporarily and start SA Query,
245 * if one is not pending.
246 */
247
248 if (sta->sa_query_count == 0)
249 ap_sta_start_sa_query(hapd, sta);
250
251#ifdef CONFIG_IEEE80211R
252 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
253
254 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
255
256 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
257 p - buf);
258#endif /* CONFIG_IEEE80211R */
259 return 0;
260 }
261
262 if (wpa_auth_uses_mfp(sta->wpa_sm))
263 sta->flags |= WLAN_STA_MFP;
264 else
265 sta->flags &= ~WLAN_STA_MFP;
266#endif /* CONFIG_IEEE80211W */
267
88b32a99
SP
268#ifdef CONFIG_IEEE80211R
269 if (sta->auth_alg == WLAN_AUTH_FT) {
270 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
271 req_ies_len);
272 if (status != WLAN_STATUS_SUCCESS) {
273 if (status == WLAN_STATUS_INVALID_PMKID)
274 reason = WLAN_REASON_INVALID_IE;
275 if (status == WLAN_STATUS_INVALID_MDIE)
276 reason = WLAN_REASON_INVALID_IE;
277 if (status == WLAN_STATUS_INVALID_FTIE)
278 reason = WLAN_REASON_INVALID_IE;
279 goto fail;
280 }
281 }
282#endif /* CONFIG_IEEE80211R */
a9aca28b 283 } else if (hapd->conf->wps_state) {
633d4469 284#ifdef CONFIG_WPS
17f6b900 285 struct wpabuf *wps;
2bb20281
JM
286 if (req_ies)
287 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
fa15d405
JM
288 WPS_IE_VENDOR_TYPE);
289 else
290 wps = NULL;
54f489be 291#ifdef CONFIG_WPS_STRICT
fa15d405 292 if (wps && wps_validate_assoc_req(wps) < 0) {
08a74e6a 293 reason = WLAN_REASON_INVALID_IE;
88b32a99 294 status = WLAN_STATUS_INVALID_IE;
fa15d405 295 wpabuf_free(wps);
08a74e6a 296 goto fail;
54f489be 297 }
54f489be 298#endif /* CONFIG_WPS_STRICT */
fa15d405 299 if (wps) {
a9aca28b 300 sta->flags |= WLAN_STA_WPS;
fa15d405 301 if (wps_is_20(wps)) {
17f6b900
JM
302 wpa_printf(MSG_DEBUG, "WPS: STA supports "
303 "WPS 2.0");
304 sta->flags |= WLAN_STA_WPS2;
305 }
a9aca28b
JM
306 } else
307 sta->flags |= WLAN_STA_MAYBE_WPS;
17f6b900 308 wpabuf_free(wps);
633d4469 309#endif /* CONFIG_WPS */
a14896e8
JM
310#ifdef CONFIG_HS20
311 } else if (hapd->conf->osen) {
312 if (elems.osen == NULL) {
313 hostapd_logger(
314 hapd, sta->addr, HOSTAPD_MODULE_IEEE80211,
315 HOSTAPD_LEVEL_INFO,
316 "No HS 2.0 OSEN element in association request");
317 return WLAN_STATUS_INVALID_IE;
318 }
319
320 wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association");
321 if (sta->wpa_sm == NULL)
322 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
323 sta->addr, NULL);
324 if (sta->wpa_sm == NULL) {
325 wpa_printf(MSG_WARNING, "Failed to initialize WPA "
326 "state machine");
327 return WLAN_STATUS_UNSPECIFIED_FAILURE;
328 }
329 if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm,
330 elems.osen - 2, elems.osen_len + 2) < 0)
331 return WLAN_STATUS_INVALID_IE;
332#endif /* CONFIG_HS20 */
b5b969e9 333 }
633d4469 334#ifdef CONFIG_WPS
b5b969e9 335skip_wpa_check:
633d4469 336#endif /* CONFIG_WPS */
b5b969e9 337
88b32a99
SP
338#ifdef CONFIG_IEEE80211R
339 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
340 sta->auth_alg, req_ies, req_ies_len);
341
342 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
e4474c1c
DPS
343
344 if (sta->auth_alg == WLAN_AUTH_FT)
345 ap_sta_set_authorized(hapd, sta, 1);
88b32a99
SP
346#else /* CONFIG_IEEE80211R */
347 /* Keep compiler silent about unused variables */
348 if (status) {
349 }
350#endif /* CONFIG_IEEE80211R */
351
b5b969e9
JM
352 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
353 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
3578e665 354 sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE;
88b32a99 355
e4474c1c
DPS
356 hostapd_set_sta_flags(hapd, sta);
357
88b32a99
SP
358 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
359 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
360 else
361 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
b5b969e9
JM
362
363 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
364
365 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
366
ef796391 367#ifdef CONFIG_P2P
99c01af9
JM
368 if (req_ies) {
369 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
370 req_ies, req_ies_len);
371 }
ef796391
JM
372#endif /* CONFIG_P2P */
373
b5b969e9 374 return 0;
08a74e6a
JM
375
376fail:
88b32a99
SP
377#ifdef CONFIG_IEEE80211R
378 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
379#endif /* CONFIG_IEEE80211R */
08a74e6a
JM
380 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
381 ap_free_sta(hapd, sta);
382 return -1;
b5b969e9
JM
383}
384
385
386void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
387{
388 struct sta_info *sta;
389
83e843e8
JM
390 if (addr == NULL) {
391 /*
392 * This could potentially happen with unexpected event from the
393 * driver wrapper. This was seen at least in one case where the
394 * driver ended up reporting a station mode event while hostapd
395 * was running, so better make sure we stop processing such an
396 * event here.
397 */
398 wpa_printf(MSG_DEBUG, "hostapd_notif_disassoc: Skip event "
399 "with no address");
1f4c7b6b 400 return;
83e843e8
JM
401 }
402
b5b969e9
JM
403 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
404 HOSTAPD_LEVEL_INFO, "disassociated");
405
406 sta = ap_get_sta(hapd, addr);
407 if (sta == NULL) {
408 wpa_printf(MSG_DEBUG, "Disassociation notification for "
409 "unknown STA " MACSTR, MAC2STR(addr));
410 return;
411 }
412
ae055af4 413 ap_sta_set_authorized(hapd, sta, 0);
b5b969e9
JM
414 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
415 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
416 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
417 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
418 ap_free_sta(hapd, sta);
419}
420
421
0d7e5a3a
JB
422void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
423{
424 struct sta_info *sta = ap_get_sta(hapd, addr);
425
426 if (!sta || !hapd->conf->disassoc_low_ack)
427 return;
428
429 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
430 HOSTAPD_LEVEL_INFO, "disconnected due to excessive "
431 "missing ACKs");
432 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
433 if (sta)
434 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
435}
436
437
1b487b8b 438void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
8d1fdde7 439 int offset, int width, int cf1, int cf2)
1b487b8b 440{
c7803a02 441#ifdef NEED_AP_MLME
8d1fdde7 442 int channel, chwidth, seg0_idx = 0, seg1_idx = 0;
1b487b8b
TP
443
444 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
2f06bcb3
JM
445 HOSTAPD_LEVEL_INFO,
446 "driver had channel switch: freq=%d, ht=%d, offset=%d, width=%d (%s), cf1=%d, cf2=%d",
447 freq, ht, offset, width, channel_width_to_string(width),
448 cf1, cf2);
1b487b8b
TP
449
450 hapd->iface->freq = freq;
451
452 channel = hostapd_hw_get_channel(hapd, freq);
453 if (!channel) {
454 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
455 HOSTAPD_LEVEL_WARNING, "driver switched to "
456 "bad channel!");
457 return;
458 }
459
8d1fdde7
JD
460 switch (width) {
461 case CHAN_WIDTH_80:
462 chwidth = VHT_CHANWIDTH_80MHZ;
463 break;
464 case CHAN_WIDTH_80P80:
465 chwidth = VHT_CHANWIDTH_80P80MHZ;
466 break;
467 case CHAN_WIDTH_160:
468 chwidth = VHT_CHANWIDTH_160MHZ;
469 break;
470 case CHAN_WIDTH_20_NOHT:
471 case CHAN_WIDTH_20:
472 case CHAN_WIDTH_40:
473 default:
474 chwidth = VHT_CHANWIDTH_USE_HT;
475 break;
476 }
477
478 switch (hapd->iface->current_mode->mode) {
479 case HOSTAPD_MODE_IEEE80211A:
480 if (cf1 > 5000)
481 seg0_idx = (cf1 - 5000) / 5;
482 if (cf2 > 5000)
483 seg1_idx = (cf2 - 5000) / 5;
484 break;
485 default:
486 seg0_idx = hostapd_hw_get_channel(hapd, cf1);
487 seg1_idx = hostapd_hw_get_channel(hapd, cf2);
488 break;
489 }
490
1b487b8b
TP
491 hapd->iconf->channel = channel;
492 hapd->iconf->ieee80211n = ht;
5de74818
JM
493 if (!ht)
494 hapd->iconf->ieee80211ac = 0;
1b487b8b 495 hapd->iconf->secondary_channel = offset;
8d1fdde7
JD
496 hapd->iconf->vht_oper_chwidth = chwidth;
497 hapd->iconf->vht_oper_centr_freq_seg0_idx = seg0_idx;
498 hapd->iconf->vht_oper_centr_freq_seg1_idx = seg1_idx;
bf281c12 499
6782b684
MK
500 if (hapd->csa_in_progress &&
501 freq == hapd->cs_freq_params.freq) {
bf281c12 502 hostapd_cleanup_cs_params(hapd);
6782b684 503 ieee802_11_set_beacon(hapd);
bf281c12
AO
504
505 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_CSA_FINISHED "freq=%d",
506 freq);
507 }
c7803a02 508#endif /* NEED_AP_MLME */
1b487b8b
TP
509}
510
511
3140803b
RM
512void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
513 const u8 *addr, int reason_code)
514{
515 switch (reason_code) {
516 case MAX_CLIENT_REACHED:
517 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
518 MAC2STR(addr));
519 break;
520 case BLOCKED_CLIENT:
521 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
522 MAC2STR(addr));
523 break;
524 }
525}
526
527
04a85e44 528int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
baf513d6
JB
529 const u8 *bssid, const u8 *ie, size_t ie_len,
530 int ssi_signal)
e67b55fb
JM
531{
532 size_t i;
533 int ret = 0;
534
b211f3eb
JM
535 if (sa == NULL || ie == NULL)
536 return -1;
537
538 random_add_randomness(sa, ETH_ALEN);
e67b55fb
JM
539 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
540 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
baf513d6
JB
541 sa, da, bssid, ie, ie_len,
542 ssi_signal) > 0) {
e67b55fb
JM
543 ret = 1;
544 break;
545 }
546 }
547 return ret;
548}
549
550
5c61a282
JM
551#ifdef HOSTAPD
552
88b32a99
SP
553#ifdef CONFIG_IEEE80211R
554static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
555 const u8 *bssid,
556 u16 auth_transaction, u16 status,
557 const u8 *ies, size_t ies_len)
558{
559 struct hostapd_data *hapd = ctx;
560 struct sta_info *sta;
561
562 sta = ap_get_sta(hapd, dst);
563 if (sta == NULL)
564 return;
565
566 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
567 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
568 sta->flags |= WLAN_STA_AUTH;
569
570 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
571}
572#endif /* CONFIG_IEEE80211R */
573
574
88b32a99
SP
575static void hostapd_notif_auth(struct hostapd_data *hapd,
576 struct auth_info *rx_auth)
577{
578 struct sta_info *sta;
579 u16 status = WLAN_STATUS_SUCCESS;
580 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
581 size_t resp_ies_len = 0;
582
583 sta = ap_get_sta(hapd, rx_auth->peer);
584 if (!sta) {
585 sta = ap_sta_add(hapd, rx_auth->peer);
586 if (sta == NULL) {
728d9717 587 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
88b32a99
SP
588 goto fail;
589 }
590 }
591 sta->flags &= ~WLAN_STA_PREAUTH;
592 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
593#ifdef CONFIG_IEEE80211R
594 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
595 sta->auth_alg = WLAN_AUTH_FT;
596 if (sta->wpa_sm == NULL)
597 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
94ddef3e 598 sta->addr, NULL);
88b32a99
SP
599 if (sta->wpa_sm == NULL) {
600 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
601 "state machine");
602 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
603 goto fail;
604 }
605 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
606 rx_auth->auth_transaction, rx_auth->ies,
607 rx_auth->ies_len,
608 hostapd_notify_auth_ft_finish, hapd);
609 return;
610 }
611#endif /* CONFIG_IEEE80211R */
612fail:
613 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
614 status, resp_ies, resp_ies_len);
615}
616
617
618static void hostapd_action_rx(struct hostapd_data *hapd,
dbfb8e82 619 struct rx_mgmt *drv_mgmt)
88b32a99 620{
dbfb8e82 621 struct ieee80211_mgmt *mgmt;
88b32a99 622 struct sta_info *sta;
dbfb8e82
JM
623 size_t plen __maybe_unused;
624 u16 fc;
625
626 if (drv_mgmt->frame_len < 24 + 1)
627 return;
628
629 plen = drv_mgmt->frame_len - 24 - 1;
630
631 mgmt = (struct ieee80211_mgmt *) drv_mgmt->frame;
632 fc = le_to_host16(mgmt->frame_control);
633 if (WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION)
634 return; /* handled by the driver */
88b32a99 635
7d9c0cd3 636 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
dbfb8e82 637 mgmt->u.action.category, (int) plen);
7d9c0cd3 638
dbfb8e82 639 sta = ap_get_sta(hapd, mgmt->sa);
88b32a99
SP
640 if (sta == NULL) {
641 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
642 return;
643 }
644#ifdef CONFIG_IEEE80211R
dbfb8e82
JM
645 if (mgmt->u.action.category == WLAN_ACTION_FT) {
646 const u8 *payload = drv_mgmt->frame + 24 + 1;
647 wpa_ft_action_rx(sta->wpa_sm, payload, plen);
88b32a99
SP
648 }
649#endif /* CONFIG_IEEE80211R */
7d9c0cd3 650#ifdef CONFIG_IEEE80211W
dbfb8e82
JM
651 if (mgmt->u.action.category == WLAN_ACTION_SA_QUERY && plen >= 4) {
652 ieee802_11_sa_query_action(
653 hapd, mgmt->sa,
654 mgmt->u.action.u.sa_query_resp.action,
655 mgmt->u.action.u.sa_query_resp.trans_id);
7d9c0cd3
MP
656 }
657#endif /* CONFIG_IEEE80211W */
ad3872a3 658#ifdef CONFIG_WNM
dbfb8e82
JM
659 if (mgmt->u.action.category == WLAN_ACTION_WNM) {
660 ieee802_11_rx_wnm_action_ap(hapd, mgmt, drv_mgmt->frame_len);
d32d94db 661 }
ad3872a3 662#endif /* CONFIG_WNM */
88b32a99
SP
663}
664
665
fe6bdb77 666#ifdef NEED_AP_MLME
f8b1f695 667
f8b1f695
JM
668#define HAPD_BROADCAST ((struct hostapd_data *) -1)
669
670static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
671 const u8 *bssid)
672{
673 size_t i;
674
675 if (bssid == NULL)
676 return NULL;
677 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
678 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
679 return HAPD_BROADCAST;
680
681 for (i = 0; i < iface->num_bss; i++) {
682 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
683 return iface->bss[i];
684 }
685
686 return NULL;
687}
688
689
690static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
9b90955e
JB
691 const u8 *bssid, const u8 *addr,
692 int wds)
f8b1f695 693{
9b90955e 694 hapd = get_hapd_bssid(hapd->iface, bssid);
f8b1f695
JM
695 if (hapd == NULL || hapd == HAPD_BROADCAST)
696 return;
697
9b90955e 698 ieee802_11_rx_from_unknown(hapd, addr, wds);
f8b1f695
JM
699}
700
701
912b34f0 702static int hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
b5b969e9 703{
4b9841d3 704 struct hostapd_iface *iface = hapd->iface;
b57e086c 705 const struct ieee80211_hdr *hdr;
4b9841d3 706 const u8 *bssid;
2a8b7416 707 struct hostapd_frame_info fi;
912b34f0 708 int ret;
4b9841d3 709
5f7e1c06
JM
710#ifdef CONFIG_TESTING_OPTIONS
711 if (hapd->ext_mgmt_frame_handling) {
712 size_t hex_len = 2 * rx_mgmt->frame_len + 1;
713 char *hex = os_malloc(hex_len);
714 if (hex) {
715 wpa_snprintf_hex(hex, hex_len, rx_mgmt->frame,
716 rx_mgmt->frame_len);
717 wpa_msg(hapd->msg_ctx, MSG_INFO, "MGMT-RX %s", hex);
718 os_free(hex);
719 }
720 return 1;
721 }
722#endif /* CONFIG_TESTING_OPTIONS */
723
2a8b7416
JM
724 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
725 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
4b9841d3 726 if (bssid == NULL)
912b34f0 727 return 0;
4b9841d3
JM
728
729 hapd = get_hapd_bssid(iface, bssid);
730 if (hapd == NULL) {
731 u16 fc;
732 fc = le_to_host16(hdr->frame_control);
733
734 /*
735 * Drop frames to unknown BSSIDs except for Beacon frames which
736 * could be used to update neighbor information.
737 */
738 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
739 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
740 hapd = iface->bss[0];
741 else
912b34f0 742 return 0;
4b9841d3
JM
743 }
744
2a8b7416
JM
745 os_memset(&fi, 0, sizeof(fi));
746 fi.datarate = rx_mgmt->datarate;
747 fi.ssi_signal = rx_mgmt->ssi_signal;
748
4b9841d3
JM
749 if (hapd == HAPD_BROADCAST) {
750 size_t i;
912b34f0
JM
751 ret = 0;
752 for (i = 0; i < iface->num_bss; i++) {
1d91f504
SW
753 /* if bss is set, driver will call this function for
754 * each bss individually. */
755 if (rx_mgmt->drv_priv &&
756 (iface->bss[i]->drv_priv != rx_mgmt->drv_priv))
757 continue;
758
912b34f0
JM
759 if (ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
760 rx_mgmt->frame_len, &fi) > 0)
761 ret = 1;
762 }
4b9841d3 763 } else
912b34f0
JM
764 ret = ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len,
765 &fi);
bbb921da
JM
766
767 random_add_randomness(&fi, sizeof(fi));
912b34f0
JM
768
769 return ret;
b5b969e9
JM
770}
771
772
f8b1f695
JM
773static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
774 size_t len, u16 stype, int ok)
b5b969e9 775{
4b9841d3
JM
776 struct ieee80211_hdr *hdr;
777 hdr = (struct ieee80211_hdr *) buf;
778 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
779 if (hapd == NULL || hapd == HAPD_BROADCAST)
780 return;
b5b969e9
JM
781 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
782}
f82ef4d8 783
f8b1f695 784#endif /* NEED_AP_MLME */
ad1e68e6
JM
785
786
a8e0505b
JM
787static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
788{
789 struct sta_info *sta = ap_get_sta(hapd, addr);
790 if (sta)
791 return 0;
792
793 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
794 " - adding a new STA", MAC2STR(addr));
795 sta = ap_sta_add(hapd, addr);
796 if (sta) {
797 hostapd_new_assoc_sta(hapd, sta, 0);
798 } else {
799 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
800 MAC2STR(addr));
801 return -1;
802 }
803
804 return 0;
805}
806
807
808static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
809 const u8 *data, size_t data_len)
810{
811 struct hostapd_iface *iface = hapd->iface;
f826635c 812 struct sta_info *sta;
a8e0505b
JM
813 size_t j;
814
815 for (j = 0; j < iface->num_bss; j++) {
f826635c
DB
816 if ((sta = ap_get_sta(iface->bss[j], src))) {
817 if (sta->flags & WLAN_STA_ASSOC) {
818 hapd = iface->bss[j];
819 break;
820 }
a8e0505b
JM
821 }
822 }
823
824 ieee802_1x_receive(hapd, src, data, data_len);
825}
826
827
0185007c
MK
828static struct hostapd_channel_data * hostapd_get_mode_channel(
829 struct hostapd_iface *iface, unsigned int freq)
830{
831 int i;
832 struct hostapd_channel_data *chan;
833
834 for (i = 0; i < iface->current_mode->num_channels; i++) {
835 chan = &iface->current_mode->channels[i];
836 if (!chan)
837 return NULL;
838 if ((unsigned int) chan->freq == freq)
839 return chan;
840 }
841
842 return NULL;
843}
844
845
846static void hostapd_update_nf(struct hostapd_iface *iface,
847 struct hostapd_channel_data *chan,
848 struct freq_survey *survey)
849{
850 if (!iface->chans_surveyed) {
851 chan->min_nf = survey->nf;
852 iface->lowest_nf = survey->nf;
853 } else {
854 if (dl_list_empty(&chan->survey_list))
855 chan->min_nf = survey->nf;
856 else if (survey->nf < chan->min_nf)
857 chan->min_nf = survey->nf;
858 if (survey->nf < iface->lowest_nf)
859 iface->lowest_nf = survey->nf;
860 }
861}
862
863
ec8f36af
KP
864static void hostapd_single_channel_get_survey(struct hostapd_iface *iface,
865 struct survey_results *survey_res)
866{
867 struct hostapd_channel_data *chan;
868 struct freq_survey *survey;
869 u64 divisor, dividend;
870
871 survey = dl_list_first(&survey_res->survey_list, struct freq_survey,
872 list);
873 if (!survey || !survey->freq)
874 return;
875
876 chan = hostapd_get_mode_channel(iface, survey->freq);
877 if (!chan || chan->flag & HOSTAPD_CHAN_DISABLED)
878 return;
879
880 wpa_printf(MSG_DEBUG, "Single Channel Survey: (freq=%d channel_time=%ld channel_time_busy=%ld)",
881 survey->freq,
882 (unsigned long int) survey->channel_time,
883 (unsigned long int) survey->channel_time_busy);
884
885 if (survey->channel_time > iface->last_channel_time &&
886 survey->channel_time > survey->channel_time_busy) {
887 dividend = survey->channel_time_busy -
888 iface->last_channel_time_busy;
889 divisor = survey->channel_time - iface->last_channel_time;
890
891 iface->channel_utilization = dividend * 255 / divisor;
892 wpa_printf(MSG_DEBUG, "Channel Utilization: %d",
893 iface->channel_utilization);
894 }
895 iface->last_channel_time = survey->channel_time;
896 iface->last_channel_time_busy = survey->channel_time_busy;
897}
898
899
0185007c
MK
900static void hostapd_event_get_survey(struct hostapd_data *hapd,
901 struct survey_results *survey_results)
902{
903 struct hostapd_iface *iface = hapd->iface;
904 struct freq_survey *survey, *tmp;
905 struct hostapd_channel_data *chan;
906
907 if (dl_list_empty(&survey_results->survey_list)) {
908 wpa_printf(MSG_DEBUG, "No survey data received");
909 return;
910 }
911
ec8f36af
KP
912 if (survey_results->freq_filter) {
913 hostapd_single_channel_get_survey(iface, survey_results);
914 return;
915 }
916
0185007c
MK
917 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
918 struct freq_survey, list) {
919 chan = hostapd_get_mode_channel(iface, survey->freq);
920 if (!chan)
921 continue;
922 if (chan->flag & HOSTAPD_CHAN_DISABLED)
923 continue;
924
925 dl_list_del(&survey->list);
926 dl_list_add_tail(&chan->survey_list, &survey->list);
927
928 hostapd_update_nf(iface, chan, survey);
929
930 iface->chans_surveyed++;
931 }
932}
933
934
e76da505
JD
935#ifdef NEED_AP_MLME
936
5841958f
MK
937static void hostapd_event_iface_unavailable(struct hostapd_data *hapd)
938{
939 wpa_printf(MSG_DEBUG, "Interface %s is unavailable -- stopped",
940 hapd->conf->iface);
941
942 if (hapd->csa_in_progress) {
943 wpa_printf(MSG_INFO, "CSA failed (%s was stopped)",
944 hapd->conf->iface);
945 hostapd_switch_channel_fallback(hapd->iface,
946 &hapd->cs_freq_params);
947 }
948}
949
950
e76da505
JD
951static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
952 struct dfs_event *radar)
953{
e76da505 954 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
dc036d9e 955 hostapd_dfs_radar_detected(hapd->iface, radar->freq, radar->ht_enabled,
58b73e3d
JD
956 radar->chan_offset, radar->chan_width,
957 radar->cf1, radar->cf2);
e76da505
JD
958}
959
960
961static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
962 struct dfs_event *radar)
963{
964 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
dc036d9e 965 hostapd_dfs_complete_cac(hapd->iface, 1, radar->freq, radar->ht_enabled,
58b73e3d
JD
966 radar->chan_offset, radar->chan_width,
967 radar->cf1, radar->cf2);
e76da505
JD
968}
969
970
971static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
972 struct dfs_event *radar)
973{
974 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
dc036d9e 975 hostapd_dfs_complete_cac(hapd->iface, 0, radar->freq, radar->ht_enabled,
58b73e3d
JD
976 radar->chan_offset, radar->chan_width,
977 radar->cf1, radar->cf2);
e76da505
JD
978}
979
980
981static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
982 struct dfs_event *radar)
983{
984 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
dc036d9e 985 hostapd_dfs_nop_finished(hapd->iface, radar->freq, radar->ht_enabled,
58b73e3d
JD
986 radar->chan_offset, radar->chan_width,
987 radar->cf1, radar->cf2);
e76da505
JD
988}
989
990#endif /* NEED_AP_MLME */
991
992
9646a8ab 993void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
ad1e68e6
JM
994 union wpa_event_data *data)
995{
996 struct hostapd_data *hapd = ctx;
74781dfc
JM
997#ifndef CONFIG_NO_STDOUT_DEBUG
998 int level = MSG_DEBUG;
ad1e68e6 999
34caf71a 1000 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
74781dfc
JM
1001 data->rx_mgmt.frame_len >= 24) {
1002 const struct ieee80211_hdr *hdr;
1003 u16 fc;
1004 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
1005 fc = le_to_host16(hdr->frame_control);
1006 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1007 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
1008 level = MSG_EXCESSIVE;
cc2ada86
JM
1009 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
1010 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
1011 level = MSG_EXCESSIVE;
74781dfc
JM
1012 }
1013
1014 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
e26cd1a1 1015 event_to_string(event), event);
74781dfc 1016#endif /* CONFIG_NO_STDOUT_DEBUG */
e26cd1a1 1017
ad1e68e6
JM
1018 switch (event) {
1019 case EVENT_MICHAEL_MIC_FAILURE:
1020 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
1021 break;
1022 case EVENT_SCAN_RESULTS:
1023 if (hapd->iface->scan_cb)
1024 hapd->iface->scan_cb(hapd->iface);
1025 break;
fcf0f87d 1026 case EVENT_WPS_BUTTON_PUSHED:
d601247c 1027 hostapd_wps_button_pushed(hapd, NULL);
fcf0f87d 1028 break;
f8b1f695
JM
1029#ifdef NEED_AP_MLME
1030 case EVENT_TX_STATUS:
1031 switch (data->tx_status.type) {
1032 case WLAN_FC_TYPE_MGMT:
1033 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
1034 data->tx_status.data_len,
1035 data->tx_status.stype,
1036 data->tx_status.ack);
1037 break;
1038 case WLAN_FC_TYPE_DATA:
1039 hostapd_tx_status(hapd, data->tx_status.dst,
1040 data->tx_status.data,
1041 data->tx_status.data_len,
1042 data->tx_status.ack);
1043 break;
1044 }
1045 break;
dd840f79
JB
1046 case EVENT_EAPOL_TX_STATUS:
1047 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
1048 data->eapol_tx_status.data,
1049 data->eapol_tx_status.data_len,
1050 data->eapol_tx_status.ack);
1051 break;
bcf24348
JB
1052 case EVENT_DRIVER_CLIENT_POLL_OK:
1053 hostapd_client_poll_ok(hapd, data->client_poll.addr);
1054 break;
f8b1f695 1055 case EVENT_RX_FROM_UNKNOWN:
9b90955e
JB
1056 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
1057 data->rx_from_unknown.addr,
1058 data->rx_from_unknown.wds);
f8b1f695 1059 break;
dbfb8e82 1060#endif /* NEED_AP_MLME */
f8b1f695 1061 case EVENT_RX_MGMT:
c0333c8d
JM
1062 if (!data->rx_mgmt.frame)
1063 break;
dbfb8e82
JM
1064#ifdef NEED_AP_MLME
1065 if (hostapd_mgmt_rx(hapd, &data->rx_mgmt) > 0)
1066 break;
f8b1f695 1067#endif /* NEED_AP_MLME */
dbfb8e82
JM
1068 hostapd_action_rx(hapd, &data->rx_mgmt);
1069 break;
a0e0d3bb 1070 case EVENT_RX_PROBE_REQ:
b211f3eb
JM
1071 if (data->rx_probe_req.sa == NULL ||
1072 data->rx_probe_req.ie == NULL)
1073 break;
a0e0d3bb 1074 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
04a85e44
JM
1075 data->rx_probe_req.da,
1076 data->rx_probe_req.bssid,
a0e0d3bb 1077 data->rx_probe_req.ie,
baf513d6
JB
1078 data->rx_probe_req.ie_len,
1079 data->rx_probe_req.ssi_signal);
a0e0d3bb 1080 break;
a70a5d6d 1081 case EVENT_NEW_STA:
a8e0505b
JM
1082 hostapd_event_new_sta(hapd, data->new_sta.addr);
1083 break;
1084 case EVENT_EAPOL_RX:
1085 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
1086 data->eapol_rx.data,
1087 data->eapol_rx.data_len);
1088 break;
1d041bec 1089 case EVENT_ASSOC:
04a258e7
JM
1090 if (!data)
1091 return;
1d041bec
JM
1092 hostapd_notif_assoc(hapd, data->assoc_info.addr,
1093 data->assoc_info.req_ies,
39b08b5f
SP
1094 data->assoc_info.req_ies_len,
1095 data->assoc_info.reassoc);
1d041bec
JM
1096 break;
1097 case EVENT_DISASSOC:
1098 if (data)
1099 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
1100 break;
1101 case EVENT_DEAUTH:
1102 if (data)
1103 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
1104 break;
0d7e5a3a
JB
1105 case EVENT_STATION_LOW_ACK:
1106 if (!data)
1107 break;
1108 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
1109 break;
88b32a99
SP
1110 case EVENT_AUTH:
1111 hostapd_notif_auth(hapd, &data->auth);
1112 break;
1b487b8b
TP
1113 case EVENT_CH_SWITCH:
1114 if (!data)
1115 break;
1116 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
1117 data->ch_switch.ht_enabled,
8d1fdde7
JD
1118 data->ch_switch.ch_offset,
1119 data->ch_switch.ch_width,
1120 data->ch_switch.cf1,
1121 data->ch_switch.cf2);
1b487b8b 1122 break;
3140803b
RM
1123 case EVENT_CONNECT_FAILED_REASON:
1124 if (!data)
1125 break;
1126 hostapd_event_connect_failed_reason(
1127 hapd, data->connect_failed_reason.addr,
1128 data->connect_failed_reason.code);
1129 break;
0185007c
MK
1130 case EVENT_SURVEY:
1131 hostapd_event_get_survey(hapd, &data->survey_results);
1132 break;
e76da505 1133#ifdef NEED_AP_MLME
5841958f
MK
1134 case EVENT_INTERFACE_UNAVAILABLE:
1135 hostapd_event_iface_unavailable(hapd);
1136 break;
e76da505
JD
1137 case EVENT_DFS_RADAR_DETECTED:
1138 if (!data)
1139 break;
1140 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
1141 break;
1142 case EVENT_DFS_CAC_FINISHED:
1143 if (!data)
1144 break;
1145 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
1146 break;
1147 case EVENT_DFS_CAC_ABORTED:
1148 if (!data)
1149 break;
1150 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1151 break;
1152 case EVENT_DFS_NOP_FINISHED:
1153 if (!data)
1154 break;
1155 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1156 break;
1157 case EVENT_CHANNEL_LIST_CHANGED:
1158 /* channel list changed (regulatory?), update channel list */
1159 /* TODO: check this. hostapd_get_hw_features() initializes
1160 * too much stuff. */
1161 /* hostapd_get_hw_features(hapd->iface); */
795baf77
AS
1162 hostapd_channel_list_updated(
1163 hapd->iface, data->channel_list_changed.initiator);
e76da505
JD
1164 break;
1165#endif /* NEED_AP_MLME */
ab93fdeb
JM
1166 case EVENT_INTERFACE_ENABLED:
1167 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_ENABLED);
1168 break;
1169 case EVENT_INTERFACE_DISABLED:
1170 wpa_msg(hapd->msg_ctx, MSG_INFO, INTERFACE_DISABLED);
1171 break;
ad1e68e6
JM
1172 default:
1173 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1174 break;
1175 }
1176}
f8b1f695
JM
1177
1178#endif /* HOSTAPD */