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