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