2 * hostapd / Callback functions for driver wrappers
3 * Copyright (c) 2002-2013, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "radius/radius.h"
13 #include "drivers/driver.h"
14 #include "common/ieee802_11_defs.h"
15 #include "common/ieee802_11_common.h"
16 #include "common/wpa_ctrl.h"
17 #include "crypto/random.h"
22 #include "ieee802_11.h"
24 #include "accounting.h"
25 #include "tkip_countermeasures.h"
26 #include "ieee802_1x.h"
28 #include "wps_hostapd.h"
29 #include "ap_drv_ops.h"
30 #include "ap_config.h"
31 #include "hw_features.h"
35 int hostapd_notif_assoc(struct hostapd_data *hapd, const u8 *addr,
36 const u8 *req_ies, size_t req_ies_len, int reassoc)
40 struct ieee802_11_elems elems;
43 #ifdef CONFIG_IEEE80211R
44 u8 buf[sizeof(struct ieee80211_mgmt) + 1024];
46 #endif /* CONFIG_IEEE80211R */
47 u16 reason = WLAN_REASON_UNSPECIFIED;
48 u16 status = WLAN_STATUS_SUCCESS;
49 const u8 *p2p_dev_addr = NULL;
53 * This could potentially happen with unexpected event from the
54 * driver wrapper. This was seen at least in one case where the
55 * driver ended up being set to station mode while hostapd was
56 * running, so better make sure we stop processing such an
59 wpa_printf(MSG_DEBUG, "hostapd_notif_assoc: Skip event with "
63 random_add_randomness(addr, ETH_ALEN);
65 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
66 HOSTAPD_LEVEL_INFO, "associated");
68 ieee802_11_parse_elems(req_ies, req_ies_len, &elems, 0);
70 ie = elems.wps_ie - 2;
71 ielen = elems.wps_ie_len + 2;
72 wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)AssocReq");
73 } else if (elems.rsn_ie) {
74 ie = elems.rsn_ie - 2;
75 ielen = elems.rsn_ie_len + 2;
76 wpa_printf(MSG_DEBUG, "STA included RSN IE in (Re)AssocReq");
77 } else if (elems.wpa_ie) {
78 ie = elems.wpa_ie - 2;
79 ielen = elems.wpa_ie_len + 2;
80 wpa_printf(MSG_DEBUG, "STA included WPA IE in (Re)AssocReq");
84 wpa_printf(MSG_DEBUG, "STA did not include WPS/RSN/WPA IE in "
88 sta = ap_get_sta(hapd, addr);
90 ap_sta_no_session_timeout(hapd, sta);
91 accounting_sta_stop(hapd, sta);
94 * Make sure that the previously registered inactivity timer
95 * will not remove the STA immediately.
97 sta->timeout_next = STA_NULLFUNC;
99 sta = ap_sta_add(hapd, addr);
101 hostapd_drv_sta_disassoc(hapd, addr,
102 WLAN_REASON_DISASSOC_AP_BUSY);
106 sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2);
110 wpabuf_free(sta->p2p_ie);
111 sta->p2p_ie = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
114 p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie);
116 #endif /* CONFIG_P2P */
119 wpabuf_free(sta->hs20_ie);
120 if (elems.hs20 && elems.hs20_len > 4) {
121 sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4,
125 #endif /* CONFIG_HS20 */
127 if (hapd->conf->wpa) {
128 if (ie == NULL || ielen == 0) {
130 if (hapd->conf->wps_state) {
131 wpa_printf(MSG_DEBUG, "STA did not include "
132 "WPA/RSN IE in (Re)Association "
133 "Request - possible WPS use");
134 sta->flags |= WLAN_STA_MAYBE_WPS;
137 #endif /* CONFIG_WPS */
139 wpa_printf(MSG_DEBUG, "No WPA/RSN IE from STA");
143 if (hapd->conf->wps_state && ie[0] == 0xdd && ie[1] >= 4 &&
144 os_memcmp(ie + 2, "\x00\x50\xf2\x04", 4) == 0) {
146 sta->flags |= WLAN_STA_WPS;
147 wps = ieee802_11_vendor_ie_concat(ie, ielen,
150 if (wps_is_20(wps)) {
151 wpa_printf(MSG_DEBUG, "WPS: STA "
153 sta->flags |= WLAN_STA_WPS2;
159 #endif /* CONFIG_WPS */
161 if (sta->wpa_sm == NULL)
162 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
165 if (sta->wpa_sm == NULL) {
166 wpa_printf(MSG_ERROR, "Failed to initialize WPA state "
170 res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm,
172 elems.mdie, elems.mdie_len);
173 if (res != WPA_IE_OK) {
174 wpa_printf(MSG_DEBUG, "WPA/RSN information element "
175 "rejected? (res %u)", res);
176 wpa_hexdump(MSG_DEBUG, "IE", ie, ielen);
177 if (res == WPA_INVALID_GROUP) {
178 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
179 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
180 } else if (res == WPA_INVALID_PAIRWISE) {
181 reason = WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID;
182 status = WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID;
183 } else if (res == WPA_INVALID_AKMP) {
184 reason = WLAN_REASON_AKMP_NOT_VALID;
185 status = WLAN_STATUS_AKMP_NOT_VALID;
187 #ifdef CONFIG_IEEE80211W
188 else if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) {
189 reason = WLAN_REASON_INVALID_IE;
190 status = WLAN_STATUS_INVALID_IE;
191 } else if (res == WPA_INVALID_MGMT_GROUP_CIPHER) {
192 reason = WLAN_REASON_GROUP_CIPHER_NOT_VALID;
193 status = WLAN_STATUS_GROUP_CIPHER_NOT_VALID;
195 #endif /* CONFIG_IEEE80211W */
197 reason = WLAN_REASON_INVALID_IE;
198 status = WLAN_STATUS_INVALID_IE;
202 #ifdef CONFIG_IEEE80211W
203 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
204 sta->sa_query_count > 0)
205 ap_check_sa_query_timeout(hapd, sta);
206 if ((sta->flags & WLAN_STA_MFP) && !sta->sa_query_timed_out &&
207 (sta->auth_alg != WLAN_AUTH_FT)) {
209 * STA has already been associated with MFP and SA
210 * Query timeout has not been reached. Reject the
211 * association attempt temporarily and start SA Query,
212 * if one is not pending.
215 if (sta->sa_query_count == 0)
216 ap_sta_start_sa_query(hapd, sta);
218 #ifdef CONFIG_IEEE80211R
219 status = WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY;
221 p = hostapd_eid_assoc_comeback_time(hapd, sta, p);
223 hostapd_sta_assoc(hapd, addr, reassoc, status, buf,
225 #endif /* CONFIG_IEEE80211R */
229 if (wpa_auth_uses_mfp(sta->wpa_sm))
230 sta->flags |= WLAN_STA_MFP;
232 sta->flags &= ~WLAN_STA_MFP;
233 #endif /* CONFIG_IEEE80211W */
235 #ifdef CONFIG_IEEE80211R
236 if (sta->auth_alg == WLAN_AUTH_FT) {
237 status = wpa_ft_validate_reassoc(sta->wpa_sm, req_ies,
239 if (status != WLAN_STATUS_SUCCESS) {
240 if (status == WLAN_STATUS_INVALID_PMKID)
241 reason = WLAN_REASON_INVALID_IE;
242 if (status == WLAN_STATUS_INVALID_MDIE)
243 reason = WLAN_REASON_INVALID_IE;
244 if (status == WLAN_STATUS_INVALID_FTIE)
245 reason = WLAN_REASON_INVALID_IE;
249 #endif /* CONFIG_IEEE80211R */
250 } else if (hapd->conf->wps_state) {
254 wps = ieee802_11_vendor_ie_concat(req_ies, req_ies_len,
258 #ifdef CONFIG_WPS_STRICT
259 if (wps && wps_validate_assoc_req(wps) < 0) {
260 reason = WLAN_REASON_INVALID_IE;
261 status = WLAN_STATUS_INVALID_IE;
265 #endif /* CONFIG_WPS_STRICT */
267 sta->flags |= WLAN_STA_WPS;
268 if (wps_is_20(wps)) {
269 wpa_printf(MSG_DEBUG, "WPS: STA supports "
271 sta->flags |= WLAN_STA_WPS2;
274 sta->flags |= WLAN_STA_MAYBE_WPS;
276 #endif /* CONFIG_WPS */
280 #endif /* CONFIG_WPS */
282 #ifdef CONFIG_IEEE80211R
283 p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, buf, sizeof(buf),
284 sta->auth_alg, req_ies, req_ies_len);
286 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
287 #else /* CONFIG_IEEE80211R */
288 /* Keep compiler silent about unused variables */
291 #endif /* CONFIG_IEEE80211R */
293 new_assoc = (sta->flags & WLAN_STA_ASSOC) == 0;
294 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
296 if (reassoc && (sta->auth_alg == WLAN_AUTH_FT))
297 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT);
299 wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC);
301 hostapd_new_assoc_sta(hapd, sta, !new_assoc);
303 ieee802_1x_notify_port_enabled(sta->eapol_sm, 1);
307 p2p_group_notif_assoc(hapd->p2p_group, sta->addr,
308 req_ies, req_ies_len);
310 #endif /* CONFIG_P2P */
315 #ifdef CONFIG_IEEE80211R
316 hostapd_sta_assoc(hapd, addr, reassoc, status, buf, p - buf);
317 #endif /* CONFIG_IEEE80211R */
318 hostapd_drv_sta_disassoc(hapd, sta->addr, reason);
319 ap_free_sta(hapd, sta);
324 void hostapd_notif_disassoc(struct hostapd_data *hapd, const u8 *addr)
326 struct sta_info *sta;
330 * This could potentially happen with unexpected event from the
331 * driver wrapper. This was seen at least in one case where the
332 * driver ended up reporting a station mode event while hostapd
333 * was running, so better make sure we stop processing such an
336 wpa_printf(MSG_DEBUG, "hostapd_notif_disassoc: Skip event "
341 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
342 HOSTAPD_LEVEL_INFO, "disassociated");
344 sta = ap_get_sta(hapd, addr);
346 wpa_printf(MSG_DEBUG, "Disassociation notification for "
347 "unknown STA " MACSTR, MAC2STR(addr));
351 ap_sta_set_authorized(hapd, sta, 0);
352 sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC);
353 wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC);
354 sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST;
355 ieee802_1x_notify_port_enabled(sta->eapol_sm, 0);
356 ap_free_sta(hapd, sta);
360 void hostapd_event_sta_low_ack(struct hostapd_data *hapd, const u8 *addr)
362 struct sta_info *sta = ap_get_sta(hapd, addr);
364 if (!sta || !hapd->conf->disassoc_low_ack)
367 hostapd_logger(hapd, addr, HOSTAPD_MODULE_IEEE80211,
368 HOSTAPD_LEVEL_INFO, "disconnected due to excessive "
370 hostapd_drv_sta_disassoc(hapd, addr, WLAN_REASON_DISASSOC_LOW_ACK);
372 ap_sta_disassociate(hapd, sta, WLAN_REASON_DISASSOC_LOW_ACK);
376 void hostapd_event_ch_switch(struct hostapd_data *hapd, int freq, int ht,
382 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
383 HOSTAPD_LEVEL_INFO, "driver had channel switch: "
384 "freq=%d, ht=%d, offset=%d", freq, ht, offset);
386 hapd->iface->freq = freq;
388 channel = hostapd_hw_get_channel(hapd, freq);
390 hostapd_logger(hapd, NULL, HOSTAPD_MODULE_IEEE80211,
391 HOSTAPD_LEVEL_WARNING, "driver switched to "
396 hapd->iconf->channel = channel;
397 hapd->iconf->ieee80211n = ht;
398 hapd->iconf->secondary_channel = offset;
399 #endif /* NEED_AP_MLME */
403 void hostapd_event_connect_failed_reason(struct hostapd_data *hapd,
404 const u8 *addr, int reason_code)
406 switch (reason_code) {
407 case MAX_CLIENT_REACHED:
408 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_MAX_STA MACSTR,
412 wpa_msg(hapd->msg_ctx, MSG_INFO, AP_REJECTED_BLOCKED_STA MACSTR,
419 int hostapd_probe_req_rx(struct hostapd_data *hapd, const u8 *sa, const u8 *da,
420 const u8 *bssid, const u8 *ie, size_t ie_len,
426 if (sa == NULL || ie == NULL)
429 random_add_randomness(sa, ETH_ALEN);
430 for (i = 0; hapd->probereq_cb && i < hapd->num_probereq_cb; i++) {
431 if (hapd->probereq_cb[i].cb(hapd->probereq_cb[i].ctx,
432 sa, da, bssid, ie, ie_len,
444 #ifdef CONFIG_IEEE80211R
445 static void hostapd_notify_auth_ft_finish(void *ctx, const u8 *dst,
447 u16 auth_transaction, u16 status,
448 const u8 *ies, size_t ies_len)
450 struct hostapd_data *hapd = ctx;
451 struct sta_info *sta;
453 sta = ap_get_sta(hapd, dst);
457 hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211,
458 HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)");
459 sta->flags |= WLAN_STA_AUTH;
461 hostapd_sta_auth(hapd, dst, auth_transaction, status, ies, ies_len);
463 #endif /* CONFIG_IEEE80211R */
466 static void hostapd_notif_auth(struct hostapd_data *hapd,
467 struct auth_info *rx_auth)
469 struct sta_info *sta;
470 u16 status = WLAN_STATUS_SUCCESS;
471 u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN];
472 size_t resp_ies_len = 0;
474 sta = ap_get_sta(hapd, rx_auth->peer);
476 sta = ap_sta_add(hapd, rx_auth->peer);
478 status = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA;
482 sta->flags &= ~WLAN_STA_PREAUTH;
483 ieee802_1x_notify_pre_auth(sta->eapol_sm, 0);
484 #ifdef CONFIG_IEEE80211R
485 if (rx_auth->auth_type == WLAN_AUTH_FT && hapd->wpa_auth) {
486 sta->auth_alg = WLAN_AUTH_FT;
487 if (sta->wpa_sm == NULL)
488 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
490 if (sta->wpa_sm == NULL) {
491 wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA "
493 status = WLAN_STATUS_UNSPECIFIED_FAILURE;
496 wpa_ft_process_auth(sta->wpa_sm, rx_auth->bssid,
497 rx_auth->auth_transaction, rx_auth->ies,
499 hostapd_notify_auth_ft_finish, hapd);
502 #endif /* CONFIG_IEEE80211R */
504 hostapd_sta_auth(hapd, rx_auth->peer, rx_auth->auth_transaction + 1,
505 status, resp_ies, resp_ies_len);
509 static void hostapd_action_rx(struct hostapd_data *hapd,
510 struct rx_action *action)
512 struct sta_info *sta;
514 wpa_printf(MSG_DEBUG, "RX_ACTION cat %d action plen %d",
515 action->category, (int) action->len);
517 sta = ap_get_sta(hapd, action->sa);
519 wpa_printf(MSG_DEBUG, "%s: station not found", __func__);
522 #ifdef CONFIG_IEEE80211R
523 if (action->category == WLAN_ACTION_FT) {
524 wpa_printf(MSG_DEBUG, "%s: FT_ACTION length %d",
525 __func__, (int) action->len);
526 wpa_ft_action_rx(sta->wpa_sm, action->data, action->len);
528 #endif /* CONFIG_IEEE80211R */
529 #ifdef CONFIG_IEEE80211W
530 if (action->category == WLAN_ACTION_SA_QUERY && action->len >= 4) {
531 wpa_printf(MSG_DEBUG, "%s: SA_QUERY_ACTION length %d",
532 __func__, (int) action->len);
533 ieee802_11_sa_query_action(hapd, action->sa,
537 #endif /* CONFIG_IEEE80211W */
539 if (action->category == WLAN_ACTION_WNM) {
540 wpa_printf(MSG_DEBUG, "%s: WNM_ACTION length %d",
541 __func__, (int) action->len);
542 ieee802_11_rx_wnm_action_ap(hapd, action);
544 #endif /* CONFIG_WNM */
550 #define HAPD_BROADCAST ((struct hostapd_data *) -1)
552 static struct hostapd_data * get_hapd_bssid(struct hostapd_iface *iface,
559 if (bssid[0] == 0xff && bssid[1] == 0xff && bssid[2] == 0xff &&
560 bssid[3] == 0xff && bssid[4] == 0xff && bssid[5] == 0xff)
561 return HAPD_BROADCAST;
563 for (i = 0; i < iface->num_bss; i++) {
564 if (os_memcmp(bssid, iface->bss[i]->own_addr, ETH_ALEN) == 0)
565 return iface->bss[i];
572 static void hostapd_rx_from_unknown_sta(struct hostapd_data *hapd,
573 const u8 *bssid, const u8 *addr,
576 hapd = get_hapd_bssid(hapd->iface, bssid);
577 if (hapd == NULL || hapd == HAPD_BROADCAST)
580 ieee802_11_rx_from_unknown(hapd, addr, wds);
584 static void hostapd_mgmt_rx(struct hostapd_data *hapd, struct rx_mgmt *rx_mgmt)
586 struct hostapd_iface *iface = hapd->iface;
587 const struct ieee80211_hdr *hdr;
589 struct hostapd_frame_info fi;
591 hdr = (const struct ieee80211_hdr *) rx_mgmt->frame;
592 bssid = get_hdr_bssid(hdr, rx_mgmt->frame_len);
596 hapd = get_hapd_bssid(iface, bssid);
599 fc = le_to_host16(hdr->frame_control);
602 * Drop frames to unknown BSSIDs except for Beacon frames which
603 * could be used to update neighbor information.
605 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
606 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
607 hapd = iface->bss[0];
612 os_memset(&fi, 0, sizeof(fi));
613 fi.datarate = rx_mgmt->datarate;
614 fi.ssi_signal = rx_mgmt->ssi_signal;
616 if (hapd == HAPD_BROADCAST) {
618 for (i = 0; i < iface->num_bss; i++)
619 ieee802_11_mgmt(iface->bss[i], rx_mgmt->frame,
620 rx_mgmt->frame_len, &fi);
622 ieee802_11_mgmt(hapd, rx_mgmt->frame, rx_mgmt->frame_len, &fi);
624 random_add_randomness(&fi, sizeof(fi));
628 static void hostapd_rx_action(struct hostapd_data *hapd,
629 struct rx_action *rx_action)
631 struct rx_mgmt rx_mgmt;
633 struct ieee80211_hdr *hdr;
635 wpa_printf(MSG_DEBUG, "EVENT_RX_ACTION DA=" MACSTR " SA=" MACSTR
636 " BSSID=" MACSTR " category=%u",
637 MAC2STR(rx_action->da), MAC2STR(rx_action->sa),
638 MAC2STR(rx_action->bssid), rx_action->category);
639 wpa_hexdump(MSG_MSGDUMP, "Received action frame contents",
640 rx_action->data, rx_action->len);
642 buf = os_zalloc(24 + 1 + rx_action->len);
645 hdr = (struct ieee80211_hdr *) buf;
646 hdr->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
647 WLAN_FC_STYPE_ACTION);
648 if (rx_action->category == WLAN_ACTION_SA_QUERY) {
650 * Assume frame was protected; it would have been dropped if
653 hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
655 os_memcpy(hdr->addr1, rx_action->da, ETH_ALEN);
656 os_memcpy(hdr->addr2, rx_action->sa, ETH_ALEN);
657 os_memcpy(hdr->addr3, rx_action->bssid, ETH_ALEN);
658 buf[24] = rx_action->category;
659 os_memcpy(buf + 24 + 1, rx_action->data, rx_action->len);
660 os_memset(&rx_mgmt, 0, sizeof(rx_mgmt));
662 rx_mgmt.frame_len = 24 + 1 + rx_action->len;
663 hostapd_mgmt_rx(hapd, &rx_mgmt);
668 static void hostapd_mgmt_tx_cb(struct hostapd_data *hapd, const u8 *buf,
669 size_t len, u16 stype, int ok)
671 struct ieee80211_hdr *hdr;
672 hdr = (struct ieee80211_hdr *) buf;
673 hapd = get_hapd_bssid(hapd->iface, get_hdr_bssid(hdr, len));
674 if (hapd == NULL || hapd == HAPD_BROADCAST)
676 ieee802_11_mgmt_cb(hapd, buf, len, stype, ok);
679 #endif /* NEED_AP_MLME */
682 static int hostapd_event_new_sta(struct hostapd_data *hapd, const u8 *addr)
684 struct sta_info *sta = ap_get_sta(hapd, addr);
688 wpa_printf(MSG_DEBUG, "Data frame from unknown STA " MACSTR
689 " - adding a new STA", MAC2STR(addr));
690 sta = ap_sta_add(hapd, addr);
692 hostapd_new_assoc_sta(hapd, sta, 0);
694 wpa_printf(MSG_DEBUG, "Failed to add STA entry for " MACSTR,
703 static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src,
704 const u8 *data, size_t data_len)
706 struct hostapd_iface *iface = hapd->iface;
707 struct sta_info *sta;
710 for (j = 0; j < iface->num_bss; j++) {
711 if ((sta = ap_get_sta(iface->bss[j], src))) {
712 if (sta->flags & WLAN_STA_ASSOC) {
713 hapd = iface->bss[j];
719 ieee802_1x_receive(hapd, src, data, data_len);
723 static struct hostapd_channel_data * hostapd_get_mode_channel(
724 struct hostapd_iface *iface, unsigned int freq)
727 struct hostapd_channel_data *chan;
729 for (i = 0; i < iface->current_mode->num_channels; i++) {
730 chan = &iface->current_mode->channels[i];
733 if ((unsigned int) chan->freq == freq)
741 static void hostapd_update_nf(struct hostapd_iface *iface,
742 struct hostapd_channel_data *chan,
743 struct freq_survey *survey)
745 if (!iface->chans_surveyed) {
746 chan->min_nf = survey->nf;
747 iface->lowest_nf = survey->nf;
749 if (dl_list_empty(&chan->survey_list))
750 chan->min_nf = survey->nf;
751 else if (survey->nf < chan->min_nf)
752 chan->min_nf = survey->nf;
753 if (survey->nf < iface->lowest_nf)
754 iface->lowest_nf = survey->nf;
759 static void hostapd_event_get_survey(struct hostapd_data *hapd,
760 struct survey_results *survey_results)
762 struct hostapd_iface *iface = hapd->iface;
763 struct freq_survey *survey, *tmp;
764 struct hostapd_channel_data *chan;
766 if (dl_list_empty(&survey_results->survey_list)) {
767 wpa_printf(MSG_DEBUG, "No survey data received");
771 dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
772 struct freq_survey, list) {
773 chan = hostapd_get_mode_channel(iface, survey->freq);
776 if (chan->flag & HOSTAPD_CHAN_DISABLED)
779 dl_list_del(&survey->list);
780 dl_list_add_tail(&chan->survey_list, &survey->list);
782 hostapd_update_nf(iface, chan, survey);
784 iface->chans_surveyed++;
791 static void hostapd_event_dfs_radar_detected(struct hostapd_data *hapd,
792 struct dfs_event *radar)
796 wpa_printf(MSG_DEBUG, "DFS radar detected on %d MHz", radar->freq);
798 if (!hapd->iconf->ieee80211h)
801 /* mark radar frequency as invalid */
802 res = ieee802_11_set_dfs_state(hapd, radar->freq,
803 HOSTAPD_CHAN_DFS_UNAVAILABLE);
805 /* other frequency, just mark it and return. */
806 if (hapd->iface->freq != radar->freq)
809 /* we are working on non-DFS channel - skip event */
813 /* radar detected while operating, switch the channel. */
814 ieee802_11_start_channel_switch(hapd);
818 static void hostapd_event_dfs_cac_finished(struct hostapd_data *hapd,
819 struct dfs_event *radar)
821 wpa_printf(MSG_DEBUG, "DFS CAC finished on %d MHz", radar->freq);
822 ieee802_11_complete_cac(hapd, 1, radar->freq);
826 static void hostapd_event_dfs_cac_aborted(struct hostapd_data *hapd,
827 struct dfs_event *radar)
829 wpa_printf(MSG_DEBUG, "DFS CAC aborted on %d MHz", radar->freq);
830 ieee802_11_complete_cac(hapd, 0, radar->freq);
834 static void hostapd_event_dfs_nop_finished(struct hostapd_data *hapd,
835 struct dfs_event *radar)
837 wpa_printf(MSG_DEBUG, "DFS NOP finished on %d MHz", radar->freq);
838 ieee802_11_set_dfs_state(hapd, radar->freq, HOSTAPD_CHAN_DFS_USABLE);
841 #endif /* NEED_AP_MLME */
844 void wpa_supplicant_event(void *ctx, enum wpa_event_type event,
845 union wpa_event_data *data)
847 struct hostapd_data *hapd = ctx;
848 #ifndef CONFIG_NO_STDOUT_DEBUG
849 int level = MSG_DEBUG;
851 if (event == EVENT_RX_MGMT && data->rx_mgmt.frame &&
852 data->rx_mgmt.frame_len >= 24) {
853 const struct ieee80211_hdr *hdr;
855 hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame;
856 fc = le_to_host16(hdr->frame_control);
857 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
858 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON)
859 level = MSG_EXCESSIVE;
860 if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
861 WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_REQ)
862 level = MSG_EXCESSIVE;
865 wpa_dbg(hapd->msg_ctx, level, "Event %s (%d) received",
866 event_to_string(event), event);
867 #endif /* CONFIG_NO_STDOUT_DEBUG */
870 case EVENT_MICHAEL_MIC_FAILURE:
871 michael_mic_failure(hapd, data->michael_mic_failure.src, 1);
873 case EVENT_SCAN_RESULTS:
874 if (hapd->iface->scan_cb)
875 hapd->iface->scan_cb(hapd->iface);
877 #ifdef CONFIG_IEEE80211R
878 case EVENT_FT_RRB_RX:
879 wpa_ft_rrb_rx(hapd->wpa_auth, data->ft_rrb_rx.src,
880 data->ft_rrb_rx.data, data->ft_rrb_rx.data_len);
882 #endif /* CONFIG_IEEE80211R */
883 case EVENT_WPS_BUTTON_PUSHED:
884 hostapd_wps_button_pushed(hapd, NULL);
887 case EVENT_TX_STATUS:
888 switch (data->tx_status.type) {
889 case WLAN_FC_TYPE_MGMT:
890 hostapd_mgmt_tx_cb(hapd, data->tx_status.data,
891 data->tx_status.data_len,
892 data->tx_status.stype,
893 data->tx_status.ack);
895 case WLAN_FC_TYPE_DATA:
896 hostapd_tx_status(hapd, data->tx_status.dst,
897 data->tx_status.data,
898 data->tx_status.data_len,
899 data->tx_status.ack);
903 case EVENT_EAPOL_TX_STATUS:
904 hostapd_eapol_tx_status(hapd, data->eapol_tx_status.dst,
905 data->eapol_tx_status.data,
906 data->eapol_tx_status.data_len,
907 data->eapol_tx_status.ack);
909 case EVENT_DRIVER_CLIENT_POLL_OK:
910 hostapd_client_poll_ok(hapd, data->client_poll.addr);
912 case EVENT_RX_FROM_UNKNOWN:
913 hostapd_rx_from_unknown_sta(hapd, data->rx_from_unknown.bssid,
914 data->rx_from_unknown.addr,
915 data->rx_from_unknown.wds);
918 hostapd_mgmt_rx(hapd, &data->rx_mgmt);
920 #endif /* NEED_AP_MLME */
921 case EVENT_RX_PROBE_REQ:
922 if (data->rx_probe_req.sa == NULL ||
923 data->rx_probe_req.ie == NULL)
925 hostapd_probe_req_rx(hapd, data->rx_probe_req.sa,
926 data->rx_probe_req.da,
927 data->rx_probe_req.bssid,
928 data->rx_probe_req.ie,
929 data->rx_probe_req.ie_len,
930 data->rx_probe_req.ssi_signal);
933 hostapd_event_new_sta(hapd, data->new_sta.addr);
936 hostapd_event_eapol_rx(hapd, data->eapol_rx.src,
938 data->eapol_rx.data_len);
941 hostapd_notif_assoc(hapd, data->assoc_info.addr,
942 data->assoc_info.req_ies,
943 data->assoc_info.req_ies_len,
944 data->assoc_info.reassoc);
948 hostapd_notif_disassoc(hapd, data->disassoc_info.addr);
952 hostapd_notif_disassoc(hapd, data->deauth_info.addr);
954 case EVENT_STATION_LOW_ACK:
957 hostapd_event_sta_low_ack(hapd, data->low_ack.addr);
959 case EVENT_RX_ACTION:
960 if (data->rx_action.da == NULL || data->rx_action.sa == NULL ||
961 data->rx_action.bssid == NULL)
964 hostapd_rx_action(hapd, &data->rx_action);
965 #endif /* NEED_AP_MLME */
966 hostapd_action_rx(hapd, &data->rx_action);
969 hostapd_notif_auth(hapd, &data->auth);
971 case EVENT_CH_SWITCH:
974 hostapd_event_ch_switch(hapd, data->ch_switch.freq,
975 data->ch_switch.ht_enabled,
976 data->ch_switch.ch_offset);
978 case EVENT_CONNECT_FAILED_REASON:
981 hostapd_event_connect_failed_reason(
982 hapd, data->connect_failed_reason.addr,
983 data->connect_failed_reason.code);
986 hostapd_event_get_survey(hapd, &data->survey_results);
989 case EVENT_DFS_RADAR_DETECTED:
992 hostapd_event_dfs_radar_detected(hapd, &data->dfs_event);
994 case EVENT_DFS_CAC_FINISHED:
997 hostapd_event_dfs_cac_finished(hapd, &data->dfs_event);
999 case EVENT_DFS_CAC_ABORTED:
1002 hostapd_event_dfs_cac_aborted(hapd, &data->dfs_event);
1004 case EVENT_DFS_NOP_FINISHED:
1007 hostapd_event_dfs_nop_finished(hapd, &data->dfs_event);
1009 case EVENT_CHANNEL_LIST_CHANGED:
1010 /* channel list changed (regulatory?), update channel list */
1011 /* TODO: check this. hostapd_get_hw_features() initializes
1012 * too much stuff. */
1013 /* hostapd_get_hw_features(hapd->iface); */
1015 #endif /* NEED_AP_MLME */
1017 wpa_printf(MSG_DEBUG, "Unknown event %d", event);
1022 #endif /* HOSTAPD */