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