Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hostapd / IEEE 802.11 Management |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2017, 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 | #ifndef CONFIG_NATIVE_WINDOWS |
| 12 | |
| 13 | #include "utils/common.h" |
| 14 | #include "utils/eloop.h" |
| 15 | #include "crypto/crypto.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 16 | #include "crypto/sha256.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 17 | #include "crypto/sha384.h" |
| 18 | #include "crypto/sha512.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 19 | #include "crypto/random.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 20 | #include "common/ieee802_11_defs.h" |
| 21 | #include "common/ieee802_11_common.h" |
| 22 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 23 | #include "common/sae.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 24 | #include "radius/radius.h" |
| 25 | #include "radius/radius_client.h" |
| 26 | #include "p2p/p2p.h" |
| 27 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 28 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 29 | #include "hostapd.h" |
| 30 | #include "beacon.h" |
| 31 | #include "ieee802_11_auth.h" |
| 32 | #include "sta_info.h" |
| 33 | #include "ieee802_1x.h" |
| 34 | #include "wpa_auth.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 35 | #include "pmksa_cache_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "wmm.h" |
| 37 | #include "ap_list.h" |
| 38 | #include "accounting.h" |
| 39 | #include "ap_config.h" |
| 40 | #include "ap_mlme.h" |
| 41 | #include "p2p_hostapd.h" |
| 42 | #include "ap_drv_ops.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 43 | #include "wnm_ap.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 44 | #include "hw_features.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 45 | #include "ieee802_11.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 46 | #include "dfs.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 47 | #include "mbo_ap.h" |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 48 | #include "rrm.h" |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 49 | #include "taxonomy.h" |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 50 | #include "fils_hlp.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 51 | #include "dpp_hostapd.h" |
| 52 | #include "gas_query_ap.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 53 | |
| 54 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 55 | #ifdef CONFIG_FILS |
| 56 | static struct wpabuf * |
| 57 | prepare_auth_resp_fils(struct hostapd_data *hapd, |
| 58 | struct sta_info *sta, u16 *resp, |
| 59 | struct rsn_pmksa_cache_entry *pmksa, |
| 60 | struct wpabuf *erp_resp, |
| 61 | const u8 *msk, size_t msk_len, |
| 62 | int *is_pub); |
| 63 | #endif /* CONFIG_FILS */ |
| 64 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 65 | u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 66 | { |
| 67 | u8 *pos = eid; |
| 68 | int i, num, count; |
| 69 | |
| 70 | if (hapd->iface->current_rates == NULL) |
| 71 | return eid; |
| 72 | |
| 73 | *pos++ = WLAN_EID_SUPP_RATES; |
| 74 | num = hapd->iface->num_rates; |
| 75 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 76 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 77 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 78 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 79 | if (num > 8) { |
| 80 | /* rest of the rates are encoded in Extended supported |
| 81 | * rates element */ |
| 82 | num = 8; |
| 83 | } |
| 84 | |
| 85 | *pos++ = num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 86 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num; |
| 87 | i++) { |
| 88 | count++; |
| 89 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 90 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 91 | *pos |= 0x80; |
| 92 | pos++; |
| 93 | } |
| 94 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 95 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) { |
| 96 | count++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 97 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) { |
| 101 | count++; |
| 102 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 103 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 104 | |
| 105 | return pos; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 110 | { |
| 111 | u8 *pos = eid; |
| 112 | int i, num, count; |
| 113 | |
| 114 | if (hapd->iface->current_rates == NULL) |
| 115 | return eid; |
| 116 | |
| 117 | num = hapd->iface->num_rates; |
| 118 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 119 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 120 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 121 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 122 | if (num <= 8) |
| 123 | return eid; |
| 124 | num -= 8; |
| 125 | |
| 126 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 127 | *pos++ = num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 128 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8; |
| 129 | i++) { |
| 130 | count++; |
| 131 | if (count <= 8) |
| 132 | continue; /* already in SuppRates IE */ |
| 133 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 134 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 135 | *pos |= 0x80; |
| 136 | pos++; |
| 137 | } |
| 138 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 139 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) { |
| 140 | count++; |
| 141 | if (count > 8) |
| 142 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
| 143 | } |
| 144 | |
| 145 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) { |
| 146 | count++; |
| 147 | if (count > 8) |
| 148 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 149 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 150 | |
| 151 | return pos; |
| 152 | } |
| 153 | |
| 154 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 155 | u16 hostapd_own_capab_info(struct hostapd_data *hapd) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 156 | { |
| 157 | int capab = WLAN_CAPABILITY_ESS; |
| 158 | int privacy; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 159 | int dfs; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 160 | int i; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 161 | |
| 162 | /* Check if any of configured channels require DFS */ |
| 163 | dfs = hostapd_is_dfs_required(hapd->iface); |
| 164 | if (dfs < 0) { |
| 165 | wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", |
| 166 | dfs); |
| 167 | dfs = 0; |
| 168 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 169 | |
| 170 | if (hapd->iface->num_sta_no_short_preamble == 0 && |
| 171 | hapd->iconf->preamble == SHORT_PREAMBLE) |
| 172 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 173 | |
| 174 | privacy = hapd->conf->ssid.wep.keys_set; |
| 175 | |
| 176 | if (hapd->conf->ieee802_1x && |
| 177 | (hapd->conf->default_wep_key_len || |
| 178 | hapd->conf->individual_wep_key_len)) |
| 179 | privacy = 1; |
| 180 | |
| 181 | if (hapd->conf->wpa) |
| 182 | privacy = 1; |
| 183 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 184 | #ifdef CONFIG_HS20 |
| 185 | if (hapd->conf->osen) |
| 186 | privacy = 1; |
| 187 | #endif /* CONFIG_HS20 */ |
| 188 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | if (privacy) |
| 190 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 191 | |
| 192 | if (hapd->iface->current_mode && |
| 193 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G && |
| 194 | hapd->iface->num_sta_no_short_slot_time == 0) |
| 195 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 196 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 197 | /* |
| 198 | * Currently, Spectrum Management capability bit is set when directly |
| 199 | * requested in configuration by spectrum_mgmt_required or when AP is |
| 200 | * running on DFS channel. |
| 201 | * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit |
| 202 | */ |
| 203 | if (hapd->iface->current_mode && |
| 204 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A && |
| 205 | (hapd->iconf->spectrum_mgmt_required || dfs)) |
| 206 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 207 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 208 | for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) { |
| 209 | if (hapd->conf->radio_measurements[i]) { |
| 210 | capab |= IEEE80211_CAP_RRM; |
| 211 | break; |
| 212 | } |
| 213 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 214 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 215 | return capab; |
| 216 | } |
| 217 | |
| 218 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 219 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 220 | static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta, |
| 221 | u16 auth_transaction, const u8 *challenge, |
| 222 | int iswep) |
| 223 | { |
| 224 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 225 | HOSTAPD_LEVEL_DEBUG, |
| 226 | "authentication (shared key, transaction %d)", |
| 227 | auth_transaction); |
| 228 | |
| 229 | if (auth_transaction == 1) { |
| 230 | if (!sta->challenge) { |
| 231 | /* Generate a pseudo-random challenge */ |
| 232 | u8 key[8]; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 233 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 234 | sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN); |
| 235 | if (sta->challenge == NULL) |
| 236 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 237 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 238 | if (os_get_random(key, sizeof(key)) < 0) { |
| 239 | os_free(sta->challenge); |
| 240 | sta->challenge = NULL; |
| 241 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 242 | } |
| 243 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 244 | rc4_skip(key, sizeof(key), 0, |
| 245 | sta->challenge, WLAN_AUTH_CHALLENGE_LEN); |
| 246 | } |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | if (auth_transaction != 3) |
| 251 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 252 | |
| 253 | /* Transaction 3 */ |
| 254 | if (!iswep || !sta->challenge || !challenge || |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 255 | os_memcmp_const(sta->challenge, challenge, |
| 256 | WLAN_AUTH_CHALLENGE_LEN)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 257 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 258 | HOSTAPD_LEVEL_INFO, |
| 259 | "shared key authentication - invalid " |
| 260 | "challenge-response"); |
| 261 | return WLAN_STATUS_CHALLENGE_FAIL; |
| 262 | } |
| 263 | |
| 264 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 265 | HOSTAPD_LEVEL_DEBUG, |
| 266 | "authentication OK (shared key)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 267 | sta->flags |= WLAN_STA_AUTH; |
| 268 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 269 | os_free(sta->challenge); |
| 270 | sta->challenge = NULL; |
| 271 | |
| 272 | return 0; |
| 273 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 274 | #endif /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 275 | |
| 276 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 277 | static int send_auth_reply(struct hostapd_data *hapd, |
| 278 | const u8 *dst, const u8 *bssid, |
| 279 | u16 auth_alg, u16 auth_transaction, u16 resp, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 280 | const u8 *ies, size_t ies_len, const char *dbg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 281 | { |
| 282 | struct ieee80211_mgmt *reply; |
| 283 | u8 *buf; |
| 284 | size_t rlen; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 285 | int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 286 | |
| 287 | rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len; |
| 288 | buf = os_zalloc(rlen); |
| 289 | if (buf == NULL) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 290 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | |
| 292 | reply = (struct ieee80211_mgmt *) buf; |
| 293 | reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 294 | WLAN_FC_STYPE_AUTH); |
| 295 | os_memcpy(reply->da, dst, ETH_ALEN); |
| 296 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 297 | os_memcpy(reply->bssid, bssid, ETH_ALEN); |
| 298 | |
| 299 | reply->u.auth.auth_alg = host_to_le16(auth_alg); |
| 300 | reply->u.auth.auth_transaction = host_to_le16(auth_transaction); |
| 301 | reply->u.auth.status_code = host_to_le16(resp); |
| 302 | |
| 303 | if (ies && ies_len) |
| 304 | os_memcpy(reply->u.auth.variable, ies, ies_len); |
| 305 | |
| 306 | wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 307 | " auth_alg=%d auth_transaction=%d resp=%d (IE len=%lu) (dbg=%s)", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 308 | MAC2STR(dst), auth_alg, auth_transaction, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 309 | resp, (unsigned long) ies_len, dbg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 310 | if (hostapd_drv_send_mlme(hapd, reply, rlen, 0) < 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 311 | wpa_printf(MSG_INFO, "send_auth_reply: send failed"); |
| 312 | else |
| 313 | reply_res = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 314 | |
| 315 | os_free(buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 316 | |
| 317 | return reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 321 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid, |
| 323 | u16 auth_transaction, u16 status, |
| 324 | const u8 *ies, size_t ies_len) |
| 325 | { |
| 326 | struct hostapd_data *hapd = ctx; |
| 327 | struct sta_info *sta; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 328 | int reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 330 | reply_res = send_auth_reply(hapd, dst, bssid, WLAN_AUTH_FT, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 331 | auth_transaction, status, ies, ies_len, |
| 332 | "auth-ft-finish"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 333 | |
| 334 | sta = ap_get_sta(hapd, dst); |
| 335 | if (sta == NULL) |
| 336 | return; |
| 337 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 338 | if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS || |
| 339 | status != WLAN_STATUS_SUCCESS)) { |
| 340 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 341 | sta->added_unassoc = 0; |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | if (status != WLAN_STATUS_SUCCESS) |
| 346 | return; |
| 347 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 348 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |
| 349 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |
| 350 | sta->flags |= WLAN_STA_AUTH; |
| 351 | mlme_authenticate_indication(hapd, sta); |
| 352 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 353 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | |
| 355 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 356 | #ifdef CONFIG_SAE |
| 357 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 358 | static void sae_set_state(struct sta_info *sta, enum sae_state state, |
| 359 | const char *reason) |
| 360 | { |
| 361 | wpa_printf(MSG_DEBUG, "SAE: State %s -> %s for peer " MACSTR " (%s)", |
| 362 | sae_state_txt(sta->sae->state), sae_state_txt(state), |
| 363 | MAC2STR(sta->addr), reason); |
| 364 | sta->sae->state = state; |
| 365 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 366 | |
| 367 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 368 | static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd, |
| 369 | struct sta_info *sta, int update) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 370 | { |
| 371 | struct wpabuf *buf; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 372 | const char *password = NULL; |
| 373 | struct sae_password_entry *pw; |
| 374 | const char *rx_id = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 375 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 376 | if (sta->sae->tmp) |
| 377 | rx_id = sta->sae->tmp->pw_id; |
| 378 | |
| 379 | for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) { |
| 380 | if (!is_broadcast_ether_addr(pw->peer_addr) && |
| 381 | os_memcmp(pw->peer_addr, sta->addr, ETH_ALEN) != 0) |
| 382 | continue; |
| 383 | if ((rx_id && !pw->identifier) || (!rx_id && pw->identifier)) |
| 384 | continue; |
| 385 | if (rx_id && pw->identifier && |
| 386 | os_strcmp(rx_id, pw->identifier) != 0) |
| 387 | continue; |
| 388 | password = pw->password; |
| 389 | break; |
| 390 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 391 | if (!password) |
| 392 | password = hapd->conf->ssid.wpa_passphrase; |
| 393 | if (!password) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 394 | wpa_printf(MSG_DEBUG, "SAE: No password available"); |
| 395 | return NULL; |
| 396 | } |
| 397 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 398 | if (update && |
| 399 | sae_prepare_commit(hapd->own_addr, sta->addr, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 400 | (u8 *) password, os_strlen(password), rx_id, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 401 | sta->sae) < 0) { |
| 402 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); |
| 403 | return NULL; |
| 404 | } |
| 405 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 406 | buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN + |
| 407 | (rx_id ? 3 + os_strlen(rx_id) : 0)); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 408 | if (buf == NULL) |
| 409 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 410 | sae_write_commit(sta->sae, buf, sta->sae->tmp ? |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 411 | sta->sae->tmp->anti_clogging_token : NULL, rx_id); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 412 | |
| 413 | return buf; |
| 414 | } |
| 415 | |
| 416 | |
| 417 | static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd, |
| 418 | struct sta_info *sta) |
| 419 | { |
| 420 | struct wpabuf *buf; |
| 421 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 422 | buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 423 | if (buf == NULL) |
| 424 | return NULL; |
| 425 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 426 | sae_write_confirm(sta->sae, buf); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 427 | |
| 428 | return buf; |
| 429 | } |
| 430 | |
| 431 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 432 | static int auth_sae_send_commit(struct hostapd_data *hapd, |
| 433 | struct sta_info *sta, |
| 434 | const u8 *bssid, int update) |
| 435 | { |
| 436 | struct wpabuf *data; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 437 | int reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 438 | |
| 439 | data = auth_build_sae_commit(hapd, sta, update); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 440 | if (!data && sta->sae->tmp && sta->sae->tmp->pw_id) |
| 441 | return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 442 | if (data == NULL) |
| 443 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 444 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 445 | reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 1, |
| 446 | WLAN_STATUS_SUCCESS, wpabuf_head(data), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 447 | wpabuf_len(data), "sae-send-commit"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 448 | |
| 449 | wpabuf_free(data); |
| 450 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 451 | return reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | |
| 455 | static int auth_sae_send_confirm(struct hostapd_data *hapd, |
| 456 | struct sta_info *sta, |
| 457 | const u8 *bssid) |
| 458 | { |
| 459 | struct wpabuf *data; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 460 | int reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 461 | |
| 462 | data = auth_build_sae_confirm(hapd, sta); |
| 463 | if (data == NULL) |
| 464 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 465 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 466 | reply_res = send_auth_reply(hapd, sta->addr, bssid, WLAN_AUTH_SAE, 2, |
| 467 | WLAN_STATUS_SUCCESS, wpabuf_head(data), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 468 | wpabuf_len(data), "sae-send-confirm"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 469 | |
| 470 | wpabuf_free(data); |
| 471 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 472 | return reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 476 | static int use_sae_anti_clogging(struct hostapd_data *hapd) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 477 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 478 | struct sta_info *sta; |
| 479 | unsigned int open = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 480 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 481 | if (hapd->conf->sae_anti_clogging_threshold == 0) |
| 482 | return 1; |
| 483 | |
| 484 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
| 485 | if (!sta->sae) |
| 486 | continue; |
| 487 | if (sta->sae->state != SAE_COMMITTED && |
| 488 | sta->sae->state != SAE_CONFIRMED) |
| 489 | continue; |
| 490 | open++; |
| 491 | if (open >= hapd->conf->sae_anti_clogging_threshold) |
| 492 | return 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 495 | return 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 499 | static int check_sae_token(struct hostapd_data *hapd, const u8 *addr, |
| 500 | const u8 *token, size_t token_len) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 501 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 502 | u8 mac[SHA256_MAC_LEN]; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 503 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 504 | if (token_len != SHA256_MAC_LEN) |
| 505 | return -1; |
| 506 | if (hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), |
| 507 | addr, ETH_ALEN, mac) < 0 || |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 508 | os_memcmp_const(token, mac, SHA256_MAC_LEN) != 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 509 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 510 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 511 | return 0; |
| 512 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 513 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 514 | |
| 515 | static struct wpabuf * auth_build_token_req(struct hostapd_data *hapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 516 | int group, const u8 *addr) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 517 | { |
| 518 | struct wpabuf *buf; |
| 519 | u8 *token; |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 520 | struct os_reltime now; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 521 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 522 | os_get_reltime(&now); |
| 523 | if (!os_reltime_initialized(&hapd->last_sae_token_key_update) || |
| 524 | os_reltime_expired(&now, &hapd->last_sae_token_key_update, 60)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 525 | if (random_get_bytes(hapd->sae_token_key, |
| 526 | sizeof(hapd->sae_token_key)) < 0) |
| 527 | return NULL; |
| 528 | wpa_hexdump(MSG_DEBUG, "SAE: Updated token key", |
| 529 | hapd->sae_token_key, sizeof(hapd->sae_token_key)); |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 530 | hapd->last_sae_token_key_update = now; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 531 | } |
| 532 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 533 | buf = wpabuf_alloc(sizeof(le16) + SHA256_MAC_LEN); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 534 | if (buf == NULL) |
| 535 | return NULL; |
| 536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 537 | wpabuf_put_le16(buf, group); /* Finite Cyclic Group */ |
| 538 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 539 | token = wpabuf_put(buf, SHA256_MAC_LEN); |
| 540 | hmac_sha256(hapd->sae_token_key, sizeof(hapd->sae_token_key), |
| 541 | addr, ETH_ALEN, token); |
| 542 | |
| 543 | return buf; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 544 | } |
| 545 | |
| 546 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 547 | static int sae_check_big_sync(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 548 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 549 | if (sta->sae->sync > hapd->conf->sae_sync) { |
| 550 | sae_set_state(sta, SAE_NOTHING, "Sync > dot11RSNASAESync"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 551 | sta->sae->sync = 0; |
| 552 | return -1; |
| 553 | } |
| 554 | return 0; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data) |
| 559 | { |
| 560 | struct hostapd_data *hapd = eloop_ctx; |
| 561 | struct sta_info *sta = eloop_data; |
| 562 | int ret; |
| 563 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 564 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 565 | return; |
| 566 | sta->sae->sync++; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 567 | wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 568 | " (sync=%d state=%s)", |
| 569 | MAC2STR(sta->addr), sta->sae->sync, |
| 570 | sae_state_txt(sta->sae->state)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 571 | |
| 572 | switch (sta->sae->state) { |
| 573 | case SAE_COMMITTED: |
| 574 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 575 | eloop_register_timeout(0, |
| 576 | hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 577 | auth_sae_retransmit_timer, hapd, sta); |
| 578 | break; |
| 579 | case SAE_CONFIRMED: |
| 580 | ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 581 | eloop_register_timeout(0, |
| 582 | hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 583 | auth_sae_retransmit_timer, hapd, sta); |
| 584 | break; |
| 585 | default: |
| 586 | ret = -1; |
| 587 | break; |
| 588 | } |
| 589 | |
| 590 | if (ret != WLAN_STATUS_SUCCESS) |
| 591 | wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret); |
| 592 | } |
| 593 | |
| 594 | |
| 595 | void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta) |
| 596 | { |
| 597 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); |
| 598 | } |
| 599 | |
| 600 | |
| 601 | static void sae_set_retransmit_timer(struct hostapd_data *hapd, |
| 602 | struct sta_info *sta) |
| 603 | { |
| 604 | if (!(hapd->conf->mesh & MESH_ENABLED)) |
| 605 | return; |
| 606 | |
| 607 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 608 | eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 609 | auth_sae_retransmit_timer, hapd, sta); |
| 610 | } |
| 611 | |
| 612 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 613 | void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 614 | { |
| 615 | sta->flags |= WLAN_STA_AUTH; |
| 616 | sta->auth_alg = WLAN_AUTH_SAE; |
| 617 | mlme_authenticate_indication(hapd, sta); |
| 618 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 619 | sae_set_state(sta, SAE_ACCEPTED, "Accept Confirm"); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 620 | wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr, |
| 621 | sta->sae->pmk, sta->sae->pmkid); |
| 622 | } |
| 623 | |
| 624 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 625 | static int sae_sm_step(struct hostapd_data *hapd, struct sta_info *sta, |
| 626 | const u8 *bssid, u8 auth_transaction) |
| 627 | { |
| 628 | int ret; |
| 629 | |
| 630 | if (auth_transaction != 1 && auth_transaction != 2) |
| 631 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 632 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 633 | wpa_printf(MSG_DEBUG, "SAE: Peer " MACSTR " state=%s auth_trans=%u", |
| 634 | MAC2STR(sta->addr), sae_state_txt(sta->sae->state), |
| 635 | auth_transaction); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 636 | switch (sta->sae->state) { |
| 637 | case SAE_NOTHING: |
| 638 | if (auth_transaction == 1) { |
| 639 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
| 640 | if (ret) |
| 641 | return ret; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 642 | sae_set_state(sta, SAE_COMMITTED, "Sent Commit"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 643 | |
| 644 | if (sae_process_commit(sta->sae) < 0) |
| 645 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 646 | |
| 647 | /* |
| 648 | * In mesh case, both Commit and Confirm can be sent |
| 649 | * immediately. In infrastructure BSS, only a single |
| 650 | * Authentication frame (Commit) is expected from the AP |
| 651 | * here and the second one (Confirm) will be sent once |
| 652 | * the STA has sent its second Authentication frame |
| 653 | * (Confirm). |
| 654 | */ |
| 655 | if (hapd->conf->mesh & MESH_ENABLED) { |
| 656 | /* |
| 657 | * Send both Commit and Confirm immediately |
| 658 | * based on SAE finite state machine |
| 659 | * Nothing -> Confirm transition. |
| 660 | */ |
| 661 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 662 | if (ret) |
| 663 | return ret; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 664 | sae_set_state(sta, SAE_CONFIRMED, |
| 665 | "Sent Confirm (mesh)"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 666 | } else { |
| 667 | /* |
| 668 | * For infrastructure BSS, send only the Commit |
| 669 | * message now to get alternating sequence of |
| 670 | * Authentication frames between the AP and STA. |
| 671 | * Confirm will be sent in |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 672 | * Committed -> Confirmed/Accepted transition |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 673 | * when receiving Confirm from STA. |
| 674 | */ |
| 675 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 676 | sta->sae->sync = 0; |
| 677 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 678 | } else { |
| 679 | hostapd_logger(hapd, sta->addr, |
| 680 | HOSTAPD_MODULE_IEEE80211, |
| 681 | HOSTAPD_LEVEL_DEBUG, |
| 682 | "SAE confirm before commit"); |
| 683 | } |
| 684 | break; |
| 685 | case SAE_COMMITTED: |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 686 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 687 | if (auth_transaction == 1) { |
| 688 | if (sae_process_commit(sta->sae) < 0) |
| 689 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 690 | |
| 691 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 692 | if (ret) |
| 693 | return ret; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 694 | sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 695 | sta->sae->sync = 0; |
| 696 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 697 | } else if (hapd->conf->mesh & MESH_ENABLED) { |
| 698 | /* |
| 699 | * In mesh case, follow SAE finite state machine and |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 700 | * send Commit now, if sync count allows. |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 701 | */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 702 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 703 | return WLAN_STATUS_SUCCESS; |
| 704 | sta->sae->sync++; |
| 705 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 706 | ret = auth_sae_send_commit(hapd, sta, bssid, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 707 | if (ret) |
| 708 | return ret; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 709 | |
| 710 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 711 | } else { |
| 712 | /* |
| 713 | * For instructure BSS, send the postponed Confirm from |
| 714 | * Nothing -> Confirmed transition that was reduced to |
| 715 | * Nothing -> Committed above. |
| 716 | */ |
| 717 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 718 | if (ret) |
| 719 | return ret; |
| 720 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 721 | sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 722 | |
| 723 | /* |
| 724 | * Since this was triggered on Confirm RX, run another |
| 725 | * step to get to Accepted without waiting for |
| 726 | * additional events. |
| 727 | */ |
| 728 | return sae_sm_step(hapd, sta, bssid, auth_transaction); |
| 729 | } |
| 730 | break; |
| 731 | case SAE_CONFIRMED: |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 732 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 733 | if (auth_transaction == 1) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 734 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 735 | return WLAN_STATUS_SUCCESS; |
| 736 | sta->sae->sync++; |
| 737 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 738 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
| 739 | if (ret) |
| 740 | return ret; |
| 741 | |
| 742 | if (sae_process_commit(sta->sae) < 0) |
| 743 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 744 | |
| 745 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 746 | if (ret) |
| 747 | return ret; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 748 | |
| 749 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 750 | } else { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 751 | sta->sae->send_confirm = 0xffff; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 752 | sae_accept_sta(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 753 | } |
| 754 | break; |
| 755 | case SAE_ACCEPTED: |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 756 | if (auth_transaction == 1 && |
| 757 | (hapd->conf->mesh & MESH_ENABLED)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 758 | wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR |
| 759 | ") doing reauthentication", |
| 760 | MAC2STR(sta->addr)); |
| 761 | ap_free_sta(hapd, sta); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 762 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 763 | } else if (auth_transaction == 1) { |
| 764 | wpa_printf(MSG_DEBUG, "SAE: Start reauthentication"); |
| 765 | ret = auth_sae_send_commit(hapd, sta, bssid, 1); |
| 766 | if (ret) |
| 767 | return ret; |
| 768 | sae_set_state(sta, SAE_COMMITTED, "Sent Commit"); |
| 769 | |
| 770 | if (sae_process_commit(sta->sae) < 0) |
| 771 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 772 | sta->sae->sync = 0; |
| 773 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 774 | } else { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 775 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 776 | return WLAN_STATUS_SUCCESS; |
| 777 | sta->sae->sync++; |
| 778 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 779 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 780 | sae_clear_temp_data(sta->sae); |
| 781 | if (ret) |
| 782 | return ret; |
| 783 | } |
| 784 | break; |
| 785 | default: |
| 786 | wpa_printf(MSG_ERROR, "SAE: invalid state %d", |
| 787 | sta->sae->state); |
| 788 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 789 | } |
| 790 | return WLAN_STATUS_SUCCESS; |
| 791 | } |
| 792 | |
| 793 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 794 | static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta) |
| 795 | { |
| 796 | struct sae_data *sae = sta->sae; |
| 797 | int i, *groups = hapd->conf->sae_groups; |
| 798 | |
| 799 | if (sae->state != SAE_COMMITTED) |
| 800 | return; |
| 801 | |
| 802 | wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group); |
| 803 | |
| 804 | for (i = 0; groups && groups[i] > 0; i++) { |
| 805 | if (sae->group == groups[i]) |
| 806 | break; |
| 807 | } |
| 808 | |
| 809 | if (!groups || groups[i] <= 0) { |
| 810 | wpa_printf(MSG_DEBUG, |
| 811 | "SAE: Previously selected group not found from the current configuration"); |
| 812 | return; |
| 813 | } |
| 814 | |
| 815 | for (;;) { |
| 816 | i++; |
| 817 | if (groups[i] <= 0) { |
| 818 | wpa_printf(MSG_DEBUG, |
| 819 | "SAE: No alternative group enabled"); |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | if (sae_set_group(sae, groups[i]) < 0) |
| 824 | continue; |
| 825 | |
| 826 | break; |
| 827 | } |
| 828 | wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]); |
| 829 | } |
| 830 | |
| 831 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 832 | static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta, |
| 833 | const struct ieee80211_mgmt *mgmt, size_t len, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 834 | u16 auth_transaction, u16 status_code) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 835 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 836 | int resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 837 | struct wpabuf *data = NULL; |
| 838 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 839 | #ifdef CONFIG_TESTING_OPTIONS |
| 840 | if (hapd->conf->sae_reflection_attack && auth_transaction == 1) { |
| 841 | const u8 *pos, *end; |
| 842 | |
| 843 | wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack"); |
| 844 | pos = mgmt->u.auth.variable; |
| 845 | end = ((const u8 *) mgmt) + len; |
| 846 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 847 | auth_transaction, resp, pos, end - pos, |
| 848 | "auth-sae-reflection-attack"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 849 | goto remove_sta; |
| 850 | } |
| 851 | |
| 852 | if (hapd->conf->sae_commit_override && auth_transaction == 1) { |
| 853 | wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override"); |
| 854 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
| 855 | auth_transaction, resp, |
| 856 | wpabuf_head(hapd->conf->sae_commit_override), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 857 | wpabuf_len(hapd->conf->sae_commit_override), |
| 858 | "sae-commit-override"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 859 | goto remove_sta; |
| 860 | } |
| 861 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 862 | if (!sta->sae) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 863 | if (auth_transaction != 1 || |
| 864 | status_code != WLAN_STATUS_SUCCESS) { |
| 865 | resp = -1; |
| 866 | goto remove_sta; |
| 867 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 868 | sta->sae = os_zalloc(sizeof(*sta->sae)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 869 | if (!sta->sae) { |
| 870 | resp = -1; |
| 871 | goto remove_sta; |
| 872 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 873 | sae_set_state(sta, SAE_NOTHING, "Init"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 874 | sta->sae->sync = 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 875 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 876 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 877 | if (sta->mesh_sae_pmksa_caching) { |
| 878 | wpa_printf(MSG_DEBUG, |
| 879 | "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication"); |
| 880 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
| 881 | sta->mesh_sae_pmksa_caching = 0; |
| 882 | } |
| 883 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 884 | if (auth_transaction == 1) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 885 | const u8 *token = NULL, *pos, *end; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 886 | size_t token_len = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 887 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 888 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 889 | "start SAE authentication (RX commit, status=%u)", |
| 890 | status_code); |
| 891 | |
| 892 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 893 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && |
| 894 | sta->sae->tmp) { |
| 895 | pos = mgmt->u.auth.variable; |
| 896 | end = ((const u8 *) mgmt) + len; |
| 897 | if (pos + sizeof(le16) > end) { |
| 898 | wpa_printf(MSG_ERROR, |
| 899 | "SAE: Too short anti-clogging token request"); |
| 900 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 901 | goto reply; |
| 902 | } |
| 903 | resp = sae_group_allowed(sta->sae, |
| 904 | hapd->conf->sae_groups, |
| 905 | WPA_GET_LE16(pos)); |
| 906 | if (resp != WLAN_STATUS_SUCCESS) { |
| 907 | wpa_printf(MSG_ERROR, |
| 908 | "SAE: Invalid group in anti-clogging token request"); |
| 909 | goto reply; |
| 910 | } |
| 911 | pos += sizeof(le16); |
| 912 | |
| 913 | wpabuf_free(sta->sae->tmp->anti_clogging_token); |
| 914 | sta->sae->tmp->anti_clogging_token = |
| 915 | wpabuf_alloc_copy(pos, end - pos); |
| 916 | if (sta->sae->tmp->anti_clogging_token == NULL) { |
| 917 | wpa_printf(MSG_ERROR, |
| 918 | "SAE: Failed to alloc for anti-clogging token"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 919 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 920 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | /* |
| 924 | * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code |
| 925 | * is 76, a new Commit Message shall be constructed |
| 926 | * with the Anti-Clogging Token from the received |
| 927 | * Authentication frame, and the commit-scalar and |
| 928 | * COMMIT-ELEMENT previously sent. |
| 929 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 930 | resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0); |
| 931 | if (resp != WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 932 | wpa_printf(MSG_ERROR, |
| 933 | "SAE: Failed to send commit message"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 934 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 935 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 936 | sae_set_state(sta, SAE_COMMITTED, |
| 937 | "Sent Commit (anti-clogging token case in mesh)"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 938 | sta->sae->sync = 0; |
| 939 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 940 | return; |
| 941 | } |
| 942 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 943 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 944 | status_code == |
| 945 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && |
| 946 | sta->sae->tmp) { |
| 947 | wpa_printf(MSG_DEBUG, |
| 948 | "SAE: Peer did not accept our SAE group"); |
| 949 | sae_pick_next_group(hapd, sta); |
| 950 | goto remove_sta; |
| 951 | } |
| 952 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 953 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 954 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 955 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 956 | if (!(hapd->conf->mesh & MESH_ENABLED) && |
| 957 | sta->sae->state == SAE_COMMITTED) { |
| 958 | /* This is needed in the infrastructure BSS case to |
| 959 | * address a sequence where a STA entry may remain in |
| 960 | * hostapd across two attempts to do SAE authentication |
| 961 | * by the same STA. The second attempt may end up trying |
| 962 | * to use a different group and that would not be |
| 963 | * allowed if we remain in Committed state with the |
| 964 | * previously set parameters. */ |
| 965 | sae_set_state(sta, SAE_NOTHING, |
| 966 | "Clear existing state to allow restart"); |
| 967 | sae_clear_data(sta->sae); |
| 968 | } |
| 969 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 970 | resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable, |
| 971 | ((const u8 *) mgmt) + len - |
| 972 | mgmt->u.auth.variable, &token, |
| 973 | &token_len, hapd->conf->sae_groups); |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 974 | if (resp == SAE_SILENTLY_DISCARD) { |
| 975 | wpa_printf(MSG_DEBUG, |
| 976 | "SAE: Drop commit message from " MACSTR " due to reflection attack", |
| 977 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 978 | goto remove_sta; |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 979 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 980 | |
| 981 | if (resp == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) { |
| 982 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
| 983 | WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER |
| 984 | MACSTR, MAC2STR(sta->addr)); |
| 985 | sae_clear_retransmit_timer(hapd, sta); |
| 986 | sae_set_state(sta, SAE_NOTHING, |
| 987 | "Unknown Password Identifier"); |
| 988 | goto remove_sta; |
| 989 | } |
| 990 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 991 | if (token && check_sae_token(hapd, sta->addr, token, token_len) |
| 992 | < 0) { |
| 993 | wpa_printf(MSG_DEBUG, "SAE: Drop commit message with " |
| 994 | "incorrect token from " MACSTR, |
| 995 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 996 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 997 | goto remove_sta; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 998 | } |
| 999 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1000 | if (resp != WLAN_STATUS_SUCCESS) |
| 1001 | goto reply; |
| 1002 | |
| 1003 | if (!token && use_sae_anti_clogging(hapd)) { |
| 1004 | wpa_printf(MSG_DEBUG, |
| 1005 | "SAE: Request anti-clogging token from " |
| 1006 | MACSTR, MAC2STR(sta->addr)); |
| 1007 | data = auth_build_token_req(hapd, sta->sae->group, |
| 1008 | sta->addr); |
| 1009 | resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ; |
| 1010 | if (hapd->conf->mesh & MESH_ENABLED) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1011 | sae_set_state(sta, SAE_NOTHING, |
| 1012 | "Request anti-clogging token case in mesh"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1013 | goto reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1014 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1015 | |
| 1016 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1017 | } else if (auth_transaction == 2) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1018 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1019 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1020 | "SAE authentication (RX confirm, status=%u)", |
| 1021 | status_code); |
| 1022 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1023 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1024 | if (sta->sae->state >= SAE_CONFIRMED || |
| 1025 | !(hapd->conf->mesh & MESH_ENABLED)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1026 | const u8 *var; |
| 1027 | size_t var_len; |
| 1028 | u16 peer_send_confirm; |
| 1029 | |
| 1030 | var = mgmt->u.auth.variable; |
| 1031 | var_len = ((u8 *) mgmt) + len - mgmt->u.auth.variable; |
| 1032 | if (var_len < 2) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1033 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1034 | goto reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1035 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1036 | |
| 1037 | peer_send_confirm = WPA_GET_LE16(var); |
| 1038 | |
| 1039 | if (sta->sae->state == SAE_ACCEPTED && |
| 1040 | (peer_send_confirm <= sta->sae->rc || |
| 1041 | peer_send_confirm == 0xffff)) { |
| 1042 | wpa_printf(MSG_DEBUG, |
| 1043 | "SAE: Silently ignore unexpected Confirm from peer " |
| 1044 | MACSTR |
| 1045 | " (peer-send-confirm=%u Rc=%u)", |
| 1046 | MAC2STR(sta->addr), |
| 1047 | peer_send_confirm, sta->sae->rc); |
| 1048 | return; |
| 1049 | } |
| 1050 | |
| 1051 | if (sae_check_confirm(sta->sae, var, var_len) < 0) { |
| 1052 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1053 | goto reply; |
| 1054 | } |
| 1055 | sta->sae->rc = peer_send_confirm; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1056 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1057 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1058 | } else { |
| 1059 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1060 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1061 | "unexpected SAE authentication transaction %u (status=%u)", |
| 1062 | auth_transaction, status_code); |
| 1063 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1064 | goto remove_sta; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1065 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 1066 | } |
| 1067 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1068 | reply: |
| 1069 | if (resp != WLAN_STATUS_SUCCESS) { |
| 1070 | send_auth_reply(hapd, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
| 1071 | auth_transaction, resp, |
| 1072 | data ? wpabuf_head(data) : (u8 *) "", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1073 | data ? wpabuf_len(data) : 0, "auth-sae"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1074 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1075 | |
| 1076 | remove_sta: |
| 1077 | if (sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS || |
| 1078 | status_code != WLAN_STATUS_SUCCESS)) { |
| 1079 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1080 | sta->added_unassoc = 0; |
| 1081 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1082 | wpabuf_free(data); |
| 1083 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1084 | |
| 1085 | |
| 1086 | /** |
| 1087 | * auth_sae_init_committed - Send COMMIT and start SAE in committed state |
| 1088 | * @hapd: BSS data for the device initiating the authentication |
| 1089 | * @sta: the peer to which commit authentication frame is sent |
| 1090 | * |
| 1091 | * This function implements Init event handling (IEEE Std 802.11-2012, |
| 1092 | * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the |
| 1093 | * sta->sae structure should be initialized appropriately via a call to |
| 1094 | * sae_prepare_commit(). |
| 1095 | */ |
| 1096 | int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta) |
| 1097 | { |
| 1098 | int ret; |
| 1099 | |
| 1100 | if (!sta->sae || !sta->sae->tmp) |
| 1101 | return -1; |
| 1102 | |
| 1103 | if (sta->sae->state != SAE_NOTHING) |
| 1104 | return -1; |
| 1105 | |
| 1106 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0); |
| 1107 | if (ret) |
| 1108 | return -1; |
| 1109 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1110 | sae_set_state(sta, SAE_COMMITTED, "Init and sent commit"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1111 | sta->sae->sync = 0; |
| 1112 | sae_set_retransmit_timer(hapd, sta); |
| 1113 | |
| 1114 | return 0; |
| 1115 | } |
| 1116 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1117 | #endif /* CONFIG_SAE */ |
| 1118 | |
| 1119 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1120 | static u16 wpa_res_to_status_code(int res) |
| 1121 | { |
| 1122 | if (res == WPA_INVALID_GROUP) |
| 1123 | return WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
| 1124 | if (res == WPA_INVALID_PAIRWISE) |
| 1125 | return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
| 1126 | if (res == WPA_INVALID_AKMP) |
| 1127 | return WLAN_STATUS_AKMP_NOT_VALID; |
| 1128 | if (res == WPA_ALLOC_FAIL) |
| 1129 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1130 | #ifdef CONFIG_IEEE80211W |
| 1131 | if (res == WPA_MGMT_FRAME_PROTECTION_VIOLATION) |
| 1132 | return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 1133 | if (res == WPA_INVALID_MGMT_GROUP_CIPHER) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1134 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1135 | #endif /* CONFIG_IEEE80211W */ |
| 1136 | if (res == WPA_INVALID_MDIE) |
| 1137 | return WLAN_STATUS_INVALID_MDIE; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1138 | if (res == WPA_INVALID_PMKID) |
| 1139 | return WLAN_STATUS_INVALID_PMKID; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1140 | if (res != WPA_IE_OK) |
| 1141 | return WLAN_STATUS_INVALID_IE; |
| 1142 | return WLAN_STATUS_SUCCESS; |
| 1143 | } |
| 1144 | |
| 1145 | |
| 1146 | #ifdef CONFIG_FILS |
| 1147 | |
| 1148 | static void handle_auth_fils_finish(struct hostapd_data *hapd, |
| 1149 | struct sta_info *sta, u16 resp, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1150 | struct wpabuf *data, int pub); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1151 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1152 | void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta, |
| 1153 | const u8 *pos, size_t len, u16 auth_alg, |
| 1154 | u16 auth_transaction, u16 status_code, |
| 1155 | void (*cb)(struct hostapd_data *hapd, |
| 1156 | struct sta_info *sta, u16 resp, |
| 1157 | struct wpabuf *data, int pub)) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1158 | { |
| 1159 | u16 resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1160 | const u8 *end; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1161 | struct ieee802_11_elems elems; |
| 1162 | int res; |
| 1163 | struct wpa_ie_data rsn; |
| 1164 | struct rsn_pmksa_cache_entry *pmksa = NULL; |
| 1165 | |
| 1166 | if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS) |
| 1167 | return; |
| 1168 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1169 | end = pos + len; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1170 | |
| 1171 | wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields", |
| 1172 | pos, end - pos); |
| 1173 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1174 | /* TODO: FILS PK */ |
| 1175 | #ifdef CONFIG_FILS_SK_PFS |
| 1176 | if (auth_alg == WLAN_AUTH_FILS_SK_PFS) { |
| 1177 | u16 group; |
| 1178 | struct wpabuf *pub; |
| 1179 | size_t elem_len; |
| 1180 | |
| 1181 | /* Using FILS PFS */ |
| 1182 | |
| 1183 | /* Finite Cyclic Group */ |
| 1184 | if (end - pos < 2) { |
| 1185 | wpa_printf(MSG_DEBUG, |
| 1186 | "FILS: No room for Finite Cyclic Group"); |
| 1187 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1188 | goto fail; |
| 1189 | } |
| 1190 | group = WPA_GET_LE16(pos); |
| 1191 | pos += 2; |
| 1192 | if (group != hapd->conf->fils_dh_group) { |
| 1193 | wpa_printf(MSG_DEBUG, |
| 1194 | "FILS: Unsupported Finite Cyclic Group: %u (expected %u)", |
| 1195 | group, hapd->conf->fils_dh_group); |
| 1196 | resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 1197 | goto fail; |
| 1198 | } |
| 1199 | |
| 1200 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 1201 | sta->fils_ecdh = crypto_ecdh_init(group); |
| 1202 | if (!sta->fils_ecdh) { |
| 1203 | wpa_printf(MSG_INFO, |
| 1204 | "FILS: Could not initialize ECDH with group %d", |
| 1205 | group); |
| 1206 | resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 1207 | goto fail; |
| 1208 | } |
| 1209 | |
| 1210 | pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1); |
| 1211 | if (!pub) { |
| 1212 | wpa_printf(MSG_DEBUG, |
| 1213 | "FILS: Failed to derive ECDH public key"); |
| 1214 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1215 | goto fail; |
| 1216 | } |
| 1217 | elem_len = wpabuf_len(pub); |
| 1218 | wpabuf_free(pub); |
| 1219 | |
| 1220 | /* Element */ |
| 1221 | if ((size_t) (end - pos) < elem_len) { |
| 1222 | wpa_printf(MSG_DEBUG, "FILS: No room for Element"); |
| 1223 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1224 | goto fail; |
| 1225 | } |
| 1226 | |
| 1227 | wpabuf_free(sta->fils_g_sta); |
| 1228 | sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len); |
| 1229 | wpabuf_clear_free(sta->fils_dh_ss); |
| 1230 | sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1, |
| 1231 | pos, elem_len); |
| 1232 | if (!sta->fils_dh_ss) { |
| 1233 | wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed"); |
| 1234 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1235 | goto fail; |
| 1236 | } |
| 1237 | wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss); |
| 1238 | pos += elem_len; |
| 1239 | } else { |
| 1240 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 1241 | sta->fils_ecdh = NULL; |
| 1242 | wpabuf_clear_free(sta->fils_dh_ss); |
| 1243 | sta->fils_dh_ss = NULL; |
| 1244 | } |
| 1245 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1246 | |
| 1247 | wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos); |
| 1248 | if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) { |
| 1249 | wpa_printf(MSG_DEBUG, "FILS: Could not parse elements"); |
| 1250 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1251 | goto fail; |
| 1252 | } |
| 1253 | |
| 1254 | /* RSNE */ |
| 1255 | wpa_hexdump(MSG_DEBUG, "FILS: RSN element", |
| 1256 | elems.rsn_ie, elems.rsn_ie_len); |
| 1257 | if (!elems.rsn_ie || |
| 1258 | wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
| 1259 | &rsn) < 0) { |
| 1260 | wpa_printf(MSG_DEBUG, "FILS: No valid RSN element"); |
| 1261 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1262 | goto fail; |
| 1263 | } |
| 1264 | |
| 1265 | if (!sta->wpa_sm) |
| 1266 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, |
| 1267 | NULL); |
| 1268 | if (!sta->wpa_sm) { |
| 1269 | wpa_printf(MSG_DEBUG, |
| 1270 | "FILS: Failed to initialize RSN state machine"); |
| 1271 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1272 | goto fail; |
| 1273 | } |
| 1274 | |
| 1275 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
| 1276 | elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1277 | elems.mdie, elems.mdie_len, NULL, 0); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1278 | resp = wpa_res_to_status_code(res); |
| 1279 | if (resp != WLAN_STATUS_SUCCESS) |
| 1280 | goto fail; |
| 1281 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1282 | if (!elems.fils_nonce) { |
| 1283 | wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field"); |
| 1284 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1285 | goto fail; |
| 1286 | } |
| 1287 | wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce, |
| 1288 | FILS_NONCE_LEN); |
| 1289 | os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN); |
| 1290 | |
| 1291 | /* PMKID List */ |
| 1292 | if (rsn.pmkid && rsn.num_pmkid > 0) { |
| 1293 | u8 num; |
| 1294 | const u8 *pmkid; |
| 1295 | |
| 1296 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID List", |
| 1297 | rsn.pmkid, rsn.num_pmkid * PMKID_LEN); |
| 1298 | |
| 1299 | pmkid = rsn.pmkid; |
| 1300 | num = rsn.num_pmkid; |
| 1301 | while (num) { |
| 1302 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN); |
| 1303 | pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr, |
| 1304 | pmkid); |
| 1305 | if (pmksa) |
| 1306 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1307 | pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth, |
| 1308 | sta->addr, |
| 1309 | pmkid); |
| 1310 | if (pmksa) |
| 1311 | break; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1312 | pmkid += PMKID_LEN; |
| 1313 | num--; |
| 1314 | } |
| 1315 | } |
| 1316 | if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) { |
| 1317 | wpa_printf(MSG_DEBUG, |
| 1318 | "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore", |
| 1319 | wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp); |
| 1320 | pmksa = NULL; |
| 1321 | } |
| 1322 | if (pmksa) |
| 1323 | wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry"); |
| 1324 | |
| 1325 | /* FILS Session */ |
| 1326 | if (!elems.fils_session) { |
| 1327 | wpa_printf(MSG_DEBUG, "FILS: No FILS Session element"); |
| 1328 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1329 | goto fail; |
| 1330 | } |
| 1331 | wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session, |
| 1332 | FILS_SESSION_LEN); |
| 1333 | os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN); |
| 1334 | |
| 1335 | /* FILS Wrapped Data */ |
| 1336 | if (elems.fils_wrapped_data) { |
| 1337 | wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data", |
| 1338 | elems.fils_wrapped_data, |
| 1339 | elems.fils_wrapped_data_len); |
| 1340 | if (!pmksa) { |
| 1341 | #ifndef CONFIG_NO_RADIUS |
| 1342 | if (!sta->eapol_sm) { |
| 1343 | sta->eapol_sm = |
| 1344 | ieee802_1x_alloc_eapol_sm(hapd, sta); |
| 1345 | } |
| 1346 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1347 | "FILS: Forward EAP-Initiate/Re-auth to authentication server"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1348 | ieee802_1x_encapsulate_radius( |
| 1349 | hapd, sta, elems.fils_wrapped_data, |
| 1350 | elems.fils_wrapped_data_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1351 | sta->fils_pending_cb = cb; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1352 | wpa_printf(MSG_DEBUG, |
| 1353 | "FILS: Will send Authentication frame once the response from authentication server is available"); |
| 1354 | sta->flags |= WLAN_STA_PENDING_FILS_ERP; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1355 | /* Calculate pending PMKID here so that we do not need |
| 1356 | * to maintain a copy of the EAP-Initiate/Reauth |
| 1357 | * message. */ |
| 1358 | if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm), |
| 1359 | elems.fils_wrapped_data, |
| 1360 | elems.fils_wrapped_data_len, |
| 1361 | sta->fils_erp_pmkid) == 0) |
| 1362 | sta->fils_erp_pmkid_set = 1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1363 | return; |
| 1364 | #else /* CONFIG_NO_RADIUS */ |
| 1365 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1366 | goto fail; |
| 1367 | #endif /* CONFIG_NO_RADIUS */ |
| 1368 | } |
| 1369 | } |
| 1370 | |
| 1371 | fail: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1372 | if (cb) { |
| 1373 | struct wpabuf *data; |
| 1374 | int pub = 0; |
| 1375 | |
| 1376 | data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL, |
| 1377 | NULL, 0, &pub); |
| 1378 | if (!data) { |
| 1379 | wpa_printf(MSG_DEBUG, |
| 1380 | "%s: prepare_auth_resp_fils() returned failure", |
| 1381 | __func__); |
| 1382 | } |
| 1383 | |
| 1384 | cb(hapd, sta, resp, data, pub); |
| 1385 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1389 | static struct wpabuf * |
| 1390 | prepare_auth_resp_fils(struct hostapd_data *hapd, |
| 1391 | struct sta_info *sta, u16 *resp, |
| 1392 | struct rsn_pmksa_cache_entry *pmksa, |
| 1393 | struct wpabuf *erp_resp, |
| 1394 | const u8 *msk, size_t msk_len, |
| 1395 | int *is_pub) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1396 | { |
| 1397 | u8 fils_nonce[FILS_NONCE_LEN]; |
| 1398 | size_t ielen; |
| 1399 | struct wpabuf *data = NULL; |
| 1400 | const u8 *ie; |
| 1401 | u8 *ie_buf = NULL; |
| 1402 | const u8 *pmk = NULL; |
| 1403 | size_t pmk_len = 0; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1404 | u8 pmk_buf[PMK_LEN_MAX]; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1405 | struct wpabuf *pub = NULL; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1406 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1407 | if (*resp != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1408 | goto fail; |
| 1409 | |
| 1410 | ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen); |
| 1411 | if (!ie) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1412 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1413 | goto fail; |
| 1414 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1415 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1416 | if (pmksa) { |
| 1417 | /* Add PMKID of the selected PMKSA into RSNE */ |
| 1418 | ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN); |
| 1419 | if (!ie_buf) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1420 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1421 | goto fail; |
| 1422 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1423 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1424 | os_memcpy(ie_buf, ie, ielen); |
| 1425 | if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1426 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1427 | goto fail; |
| 1428 | } |
| 1429 | ie = ie_buf; |
| 1430 | } |
| 1431 | |
| 1432 | if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1433 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1434 | goto fail; |
| 1435 | } |
| 1436 | wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce", |
| 1437 | fils_nonce, FILS_NONCE_LEN); |
| 1438 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1439 | #ifdef CONFIG_FILS_SK_PFS |
| 1440 | if (sta->fils_dh_ss && sta->fils_ecdh) { |
| 1441 | pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1); |
| 1442 | if (!pub) { |
| 1443 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1444 | goto fail; |
| 1445 | } |
| 1446 | } |
| 1447 | #endif /* CONFIG_FILS_SK_PFS */ |
| 1448 | |
| 1449 | data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1450 | if (!data) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1451 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1452 | goto fail; |
| 1453 | } |
| 1454 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1455 | /* TODO: FILS PK */ |
| 1456 | #ifdef CONFIG_FILS_SK_PFS |
| 1457 | if (pub) { |
| 1458 | /* Finite Cyclic Group */ |
| 1459 | wpabuf_put_le16(data, hapd->conf->fils_dh_group); |
| 1460 | |
| 1461 | /* Element */ |
| 1462 | wpabuf_put_buf(data, pub); |
| 1463 | } |
| 1464 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1465 | |
| 1466 | /* RSNE */ |
| 1467 | wpabuf_put_data(data, ie, ielen); |
| 1468 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1469 | /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */ |
| 1470 | |
| 1471 | #ifdef CONFIG_IEEE80211R_AP |
| 1472 | if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) { |
| 1473 | /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */ |
| 1474 | int res; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1475 | int use_sha384 = wpa_key_mgmt_sha384( |
| 1476 | wpa_auth_sta_key_mgmt(sta->wpa_sm)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1477 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1478 | res = wpa_auth_write_fte(hapd->wpa_auth, use_sha384, |
| 1479 | wpabuf_put(data, 0), |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1480 | wpabuf_tailroom(data)); |
| 1481 | if (res < 0) { |
| 1482 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1483 | goto fail; |
| 1484 | } |
| 1485 | wpabuf_put(data, res); |
| 1486 | } |
| 1487 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1488 | |
| 1489 | /* FILS Nonce */ |
| 1490 | wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */ |
| 1491 | wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */ |
| 1492 | /* Element ID Extension */ |
| 1493 | wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE); |
| 1494 | wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN); |
| 1495 | |
| 1496 | /* FILS Session */ |
| 1497 | wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */ |
| 1498 | wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */ |
| 1499 | /* Element ID Extension */ |
| 1500 | wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION); |
| 1501 | wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN); |
| 1502 | |
| 1503 | /* FILS Wrapped Data */ |
| 1504 | if (!pmksa && erp_resp) { |
| 1505 | wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */ |
| 1506 | wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */ |
| 1507 | /* Element ID Extension */ |
| 1508 | wpabuf_put_u8(data, WLAN_EID_EXT_FILS_WRAPPED_DATA); |
| 1509 | wpabuf_put_buf(data, erp_resp); |
| 1510 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1511 | if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm), |
| 1512 | msk, msk_len, sta->fils_snonce, fils_nonce, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1513 | sta->fils_dh_ss ? |
| 1514 | wpabuf_head(sta->fils_dh_ss) : NULL, |
| 1515 | sta->fils_dh_ss ? |
| 1516 | wpabuf_len(sta->fils_dh_ss) : 0, |
| 1517 | pmk_buf, &pmk_len)) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1518 | wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1519 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1520 | wpabuf_free(data); |
| 1521 | data = NULL; |
| 1522 | goto fail; |
| 1523 | } |
| 1524 | pmk = pmk_buf; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1525 | |
| 1526 | /* Don't use DHss in PTK derivation if PMKSA caching is not |
| 1527 | * used. */ |
| 1528 | wpabuf_clear_free(sta->fils_dh_ss); |
| 1529 | sta->fils_dh_ss = NULL; |
| 1530 | |
| 1531 | if (sta->fils_erp_pmkid_set) { |
| 1532 | /* TODO: get PMKLifetime from WPA parameters */ |
| 1533 | unsigned int dot11RSNAConfigPMKLifetime = 43200; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1534 | int session_timeout; |
| 1535 | |
| 1536 | session_timeout = dot11RSNAConfigPMKLifetime; |
| 1537 | if (sta->session_timeout_set) { |
| 1538 | struct os_reltime now, diff; |
| 1539 | |
| 1540 | os_get_reltime(&now); |
| 1541 | os_reltime_sub(&sta->session_timeout, &now, |
| 1542 | &diff); |
| 1543 | session_timeout = diff.sec; |
| 1544 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1545 | |
| 1546 | sta->fils_erp_pmkid_set = 0; |
| 1547 | if (wpa_auth_pmksa_add2( |
| 1548 | hapd->wpa_auth, sta->addr, |
| 1549 | pmk, pmk_len, |
| 1550 | sta->fils_erp_pmkid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1551 | session_timeout, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1552 | wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) { |
| 1553 | wpa_printf(MSG_ERROR, |
| 1554 | "FILS: Failed to add PMKSA cache entry based on ERP"); |
| 1555 | } |
| 1556 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1557 | } else if (pmksa) { |
| 1558 | pmk = pmksa->pmk; |
| 1559 | pmk_len = pmksa->pmk_len; |
| 1560 | } |
| 1561 | |
| 1562 | if (!pmk) { |
| 1563 | wpa_printf(MSG_DEBUG, "FILS: No PMK available"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1564 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1565 | wpabuf_free(data); |
| 1566 | data = NULL; |
| 1567 | goto fail; |
| 1568 | } |
| 1569 | |
| 1570 | if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1571 | sta->fils_snonce, fils_nonce, |
| 1572 | sta->fils_dh_ss ? |
| 1573 | wpabuf_head(sta->fils_dh_ss) : NULL, |
| 1574 | sta->fils_dh_ss ? |
| 1575 | wpabuf_len(sta->fils_dh_ss) : 0, |
| 1576 | sta->fils_g_sta, pub) < 0) { |
| 1577 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1578 | wpabuf_free(data); |
| 1579 | data = NULL; |
| 1580 | goto fail; |
| 1581 | } |
| 1582 | |
| 1583 | fail: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1584 | if (is_pub) |
| 1585 | *is_pub = pub != NULL; |
| 1586 | os_free(ie_buf); |
| 1587 | wpabuf_free(pub); |
| 1588 | wpabuf_clear_free(sta->fils_dh_ss); |
| 1589 | sta->fils_dh_ss = NULL; |
| 1590 | #ifdef CONFIG_FILS_SK_PFS |
| 1591 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 1592 | sta->fils_ecdh = NULL; |
| 1593 | #endif /* CONFIG_FILS_SK_PFS */ |
| 1594 | return data; |
| 1595 | } |
| 1596 | |
| 1597 | |
| 1598 | static void handle_auth_fils_finish(struct hostapd_data *hapd, |
| 1599 | struct sta_info *sta, u16 resp, |
| 1600 | struct wpabuf *data, int pub) |
| 1601 | { |
| 1602 | u16 auth_alg; |
| 1603 | |
| 1604 | auth_alg = (pub || |
| 1605 | resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ? |
| 1606 | WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK; |
| 1607 | send_auth_reply(hapd, sta->addr, hapd->own_addr, auth_alg, 2, resp, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1608 | data ? wpabuf_head(data) : (u8 *) "", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1609 | data ? wpabuf_len(data) : 0, "auth-fils-finish"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1610 | wpabuf_free(data); |
| 1611 | |
| 1612 | if (resp == WLAN_STATUS_SUCCESS) { |
| 1613 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1614 | HOSTAPD_LEVEL_DEBUG, |
| 1615 | "authentication OK (FILS)"); |
| 1616 | sta->flags |= WLAN_STA_AUTH; |
| 1617 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1618 | sta->auth_alg = pub ? WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1619 | mlme_authenticate_indication(hapd, sta); |
| 1620 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | void ieee802_11_finish_fils_auth(struct hostapd_data *hapd, |
| 1625 | struct sta_info *sta, int success, |
| 1626 | struct wpabuf *erp_resp, |
| 1627 | const u8 *msk, size_t msk_len) |
| 1628 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1629 | struct wpabuf *data; |
| 1630 | int pub = 0; |
| 1631 | u16 resp; |
| 1632 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1633 | sta->flags &= ~WLAN_STA_PENDING_FILS_ERP; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1634 | |
| 1635 | if (!sta->fils_pending_cb) |
| 1636 | return; |
| 1637 | resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1638 | data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp, |
| 1639 | msk, msk_len, &pub); |
| 1640 | if (!data) { |
| 1641 | wpa_printf(MSG_DEBUG, |
| 1642 | "%s: prepare_auth_resp_fils() returned failure", |
| 1643 | __func__); |
| 1644 | } |
| 1645 | sta->fils_pending_cb(hapd, sta, resp, data, pub); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | #endif /* CONFIG_FILS */ |
| 1649 | |
| 1650 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1651 | int |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1652 | ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr, |
| 1653 | const u8 *msg, size_t len, u32 *session_timeout, |
| 1654 | u32 *acct_interim_interval, |
| 1655 | struct vlan_description *vlan_id, |
| 1656 | struct hostapd_sta_wpa_psk_short **psk, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1657 | char **identity, char **radius_cui, int is_probe_req) |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1658 | { |
| 1659 | int res; |
| 1660 | |
| 1661 | os_memset(vlan_id, 0, sizeof(*vlan_id)); |
| 1662 | res = hostapd_allowed_address(hapd, addr, msg, len, |
| 1663 | session_timeout, acct_interim_interval, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1664 | vlan_id, psk, identity, radius_cui, |
| 1665 | is_probe_req); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1666 | |
| 1667 | if (res == HOSTAPD_ACL_REJECT) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 1668 | if (!is_probe_req) |
| 1669 | wpa_printf(MSG_DEBUG, |
| 1670 | "Station " MACSTR |
| 1671 | " not allowed to authenticate", |
| 1672 | MAC2STR(addr)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1673 | return HOSTAPD_ACL_REJECT; |
| 1674 | } |
| 1675 | |
| 1676 | if (res == HOSTAPD_ACL_PENDING) { |
| 1677 | wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR |
| 1678 | " waiting for an external authentication", |
| 1679 | MAC2STR(addr)); |
| 1680 | /* Authentication code will re-send the authentication frame |
| 1681 | * after it has received (and cached) information from the |
| 1682 | * external source. */ |
| 1683 | return HOSTAPD_ACL_PENDING; |
| 1684 | } |
| 1685 | |
| 1686 | return res; |
| 1687 | } |
| 1688 | |
| 1689 | |
| 1690 | static int |
| 1691 | ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta, |
| 1692 | int res, u32 session_timeout, |
| 1693 | u32 acct_interim_interval, |
| 1694 | struct vlan_description *vlan_id, |
| 1695 | struct hostapd_sta_wpa_psk_short **psk, |
| 1696 | char **identity, char **radius_cui) |
| 1697 | { |
| 1698 | if (vlan_id->notempty && |
| 1699 | !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) { |
| 1700 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 1701 | HOSTAPD_LEVEL_INFO, |
| 1702 | "Invalid VLAN %d%s received from RADIUS server", |
| 1703 | vlan_id->untagged, |
| 1704 | vlan_id->tagged[0] ? "+" : ""); |
| 1705 | return -1; |
| 1706 | } |
| 1707 | if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0) |
| 1708 | return -1; |
| 1709 | if (sta->vlan_id) |
| 1710 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 1711 | HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id); |
| 1712 | |
| 1713 | hostapd_free_psk_list(sta->psk); |
| 1714 | if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) { |
| 1715 | sta->psk = *psk; |
| 1716 | *psk = NULL; |
| 1717 | } else { |
| 1718 | sta->psk = NULL; |
| 1719 | } |
| 1720 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1721 | os_free(sta->identity); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1722 | sta->identity = *identity; |
| 1723 | *identity = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1724 | |
| 1725 | os_free(sta->radius_cui); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1726 | sta->radius_cui = *radius_cui; |
| 1727 | *radius_cui = NULL; |
| 1728 | |
| 1729 | if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval) |
| 1730 | sta->acct_interim_interval = acct_interim_interval; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1731 | if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) { |
| 1732 | sta->session_timeout_set = 1; |
| 1733 | os_get_reltime(&sta->session_timeout); |
| 1734 | sta->session_timeout.sec += session_timeout; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1735 | ap_sta_session_timeout(hapd, sta, session_timeout); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1736 | } else { |
| 1737 | sta->session_timeout_set = 0; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1738 | ap_sta_no_session_timeout(hapd, sta); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1739 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1740 | |
| 1741 | return 0; |
| 1742 | } |
| 1743 | |
| 1744 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1745 | static void handle_auth(struct hostapd_data *hapd, |
| 1746 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 1747 | { |
| 1748 | u16 auth_alg, auth_transaction, status_code; |
| 1749 | u16 resp = WLAN_STATUS_SUCCESS; |
| 1750 | struct sta_info *sta = NULL; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1751 | int res, reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1752 | u16 fc; |
| 1753 | const u8 *challenge = NULL; |
| 1754 | u32 session_timeout, acct_interim_interval; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1755 | struct vlan_description vlan_id; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1756 | struct hostapd_sta_wpa_psk_short *psk = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1757 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
| 1758 | size_t resp_ies_len = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1759 | char *identity = NULL; |
| 1760 | char *radius_cui = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1761 | u16 seq_ctrl; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1762 | |
| 1763 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1764 | wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)", |
| 1765 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1766 | return; |
| 1767 | } |
| 1768 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1769 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 1770 | if (hapd->iconf->ignore_auth_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1771 | drand48() < hapd->iconf->ignore_auth_probability) { |
| 1772 | wpa_printf(MSG_INFO, |
| 1773 | "TESTING: ignoring auth frame from " MACSTR, |
| 1774 | MAC2STR(mgmt->sa)); |
| 1775 | return; |
| 1776 | } |
| 1777 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1778 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1779 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 1780 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 1781 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 1782 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1783 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1784 | |
| 1785 | if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) + |
| 1786 | 2 + WLAN_AUTH_CHALLENGE_LEN && |
| 1787 | mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE && |
| 1788 | mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN) |
| 1789 | challenge = &mgmt->u.auth.variable[2]; |
| 1790 | |
| 1791 | wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1792 | "auth_transaction=%d status_code=%d wep=%d%s " |
| 1793 | "seq_ctrl=0x%x%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1794 | MAC2STR(mgmt->sa), auth_alg, auth_transaction, |
| 1795 | status_code, !!(fc & WLAN_FC_ISWEP), |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1796 | challenge ? " challenge" : "", |
| 1797 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1798 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1799 | #ifdef CONFIG_NO_RC4 |
| 1800 | if (auth_alg == WLAN_AUTH_SHARED_KEY) { |
| 1801 | wpa_printf(MSG_INFO, |
| 1802 | "Unsupported authentication algorithm (%d)", |
| 1803 | auth_alg); |
| 1804 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 1805 | goto fail; |
| 1806 | } |
| 1807 | #endif /* CONFIG_NO_RC4 */ |
| 1808 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1809 | if (hapd->tkip_countermeasures) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1810 | wpa_printf(MSG_DEBUG, |
| 1811 | "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication"); |
| 1812 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1813 | goto fail; |
| 1814 | } |
| 1815 | |
| 1816 | if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) && |
| 1817 | auth_alg == WLAN_AUTH_OPEN) || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1818 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1819 | (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1820 | auth_alg == WLAN_AUTH_FT) || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1821 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1822 | #ifdef CONFIG_SAE |
| 1823 | (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) && |
| 1824 | auth_alg == WLAN_AUTH_SAE) || |
| 1825 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1826 | #ifdef CONFIG_FILS |
| 1827 | (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) && |
| 1828 | auth_alg == WLAN_AUTH_FILS_SK) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1829 | (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) && |
| 1830 | hapd->conf->fils_dh_group && |
| 1831 | auth_alg == WLAN_AUTH_FILS_SK_PFS) || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1832 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1833 | ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) && |
| 1834 | auth_alg == WLAN_AUTH_SHARED_KEY))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1835 | wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)", |
| 1836 | auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1837 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 1838 | goto fail; |
| 1839 | } |
| 1840 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1841 | if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1842 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1843 | wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)", |
| 1844 | auth_transaction); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1845 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 1846 | goto fail; |
| 1847 | } |
| 1848 | |
| 1849 | if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1850 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
| 1851 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1852 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1853 | goto fail; |
| 1854 | } |
| 1855 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1856 | if (hapd->conf->no_auth_if_seen_on) { |
| 1857 | struct hostapd_data *other; |
| 1858 | |
| 1859 | other = sta_track_seen_on(hapd->iface, mgmt->sa, |
| 1860 | hapd->conf->no_auth_if_seen_on); |
| 1861 | if (other) { |
| 1862 | u8 *pos; |
| 1863 | u32 info; |
| 1864 | u8 op_class, channel, phytype; |
| 1865 | |
| 1866 | wpa_printf(MSG_DEBUG, "%s: Reject authentication from " |
| 1867 | MACSTR " since STA has been seen on %s", |
| 1868 | hapd->conf->iface, MAC2STR(mgmt->sa), |
| 1869 | hapd->conf->no_auth_if_seen_on); |
| 1870 | |
| 1871 | resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION; |
| 1872 | pos = &resp_ies[0]; |
| 1873 | *pos++ = WLAN_EID_NEIGHBOR_REPORT; |
| 1874 | *pos++ = 13; |
| 1875 | os_memcpy(pos, other->own_addr, ETH_ALEN); |
| 1876 | pos += ETH_ALEN; |
| 1877 | info = 0; /* TODO: BSSID Information */ |
| 1878 | WPA_PUT_LE32(pos, info); |
| 1879 | pos += 4; |
| 1880 | if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD) |
| 1881 | phytype = 8; /* dmg */ |
| 1882 | else if (other->iconf->ieee80211ac) |
| 1883 | phytype = 9; /* vht */ |
| 1884 | else if (other->iconf->ieee80211n) |
| 1885 | phytype = 7; /* ht */ |
| 1886 | else if (other->iconf->hw_mode == |
| 1887 | HOSTAPD_MODE_IEEE80211A) |
| 1888 | phytype = 4; /* ofdm */ |
| 1889 | else if (other->iconf->hw_mode == |
| 1890 | HOSTAPD_MODE_IEEE80211G) |
| 1891 | phytype = 6; /* erp */ |
| 1892 | else |
| 1893 | phytype = 5; /* hrdsss */ |
| 1894 | if (ieee80211_freq_to_channel_ext( |
| 1895 | hostapd_hw_get_freq(other, |
| 1896 | other->iconf->channel), |
| 1897 | other->iconf->secondary_channel, |
| 1898 | other->iconf->ieee80211ac, |
| 1899 | &op_class, &channel) == NUM_HOSTAPD_MODES) { |
| 1900 | op_class = 0; |
| 1901 | channel = other->iconf->channel; |
| 1902 | } |
| 1903 | *pos++ = op_class; |
| 1904 | *pos++ = channel; |
| 1905 | *pos++ = phytype; |
| 1906 | resp_ies_len = pos - &resp_ies[0]; |
| 1907 | goto fail; |
| 1908 | } |
| 1909 | } |
| 1910 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1911 | res = ieee802_11_allowed_address( |
| 1912 | hapd, mgmt->sa, (const u8 *) mgmt, len, &session_timeout, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1913 | &acct_interim_interval, &vlan_id, &psk, &identity, &radius_cui, |
| 1914 | 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1915 | if (res == HOSTAPD_ACL_REJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1916 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 1917 | "Ignore Authentication frame from " MACSTR |
| 1918 | " due to ACL reject", MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1919 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1920 | goto fail; |
| 1921 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1922 | if (res == HOSTAPD_ACL_PENDING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1923 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1924 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1925 | sta = ap_get_sta(hapd, mgmt->sa); |
| 1926 | if (sta) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1927 | sta->flags &= ~WLAN_STA_PENDING_FILS_ERP; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1928 | if ((fc & WLAN_FC_RETRY) && |
| 1929 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 1930 | sta->last_seq_ctrl == seq_ctrl && |
| 1931 | sta->last_subtype == WLAN_FC_STYPE_AUTH) { |
| 1932 | hostapd_logger(hapd, sta->addr, |
| 1933 | HOSTAPD_MODULE_IEEE80211, |
| 1934 | HOSTAPD_LEVEL_DEBUG, |
| 1935 | "Drop repeated authentication frame seq_ctrl=0x%x", |
| 1936 | seq_ctrl); |
| 1937 | return; |
| 1938 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1939 | #ifdef CONFIG_MESH |
| 1940 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 1941 | sta->plink_state == PLINK_BLOCKED) { |
| 1942 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
| 1943 | " is blocked - drop Authentication frame", |
| 1944 | MAC2STR(mgmt->sa)); |
| 1945 | return; |
| 1946 | } |
| 1947 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1948 | } else { |
| 1949 | #ifdef CONFIG_MESH |
| 1950 | if (hapd->conf->mesh & MESH_ENABLED) { |
| 1951 | /* if the mesh peer is not available, we don't do auth. |
| 1952 | */ |
| 1953 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1954 | " not yet known - drop Authentication frame", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1955 | MAC2STR(mgmt->sa)); |
| 1956 | /* |
| 1957 | * Save a copy of the frame so that it can be processed |
| 1958 | * if a new peer entry is added shortly after this. |
| 1959 | */ |
| 1960 | wpabuf_free(hapd->mesh_pending_auth); |
| 1961 | hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len); |
| 1962 | os_get_reltime(&hapd->mesh_pending_auth_time); |
| 1963 | return; |
| 1964 | } |
| 1965 | #endif /* CONFIG_MESH */ |
| 1966 | |
| 1967 | sta = ap_sta_add(hapd, mgmt->sa); |
| 1968 | if (!sta) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1969 | wpa_printf(MSG_DEBUG, "ap_sta_add() failed"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1970 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 1971 | goto fail; |
| 1972 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1973 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1974 | sta->last_seq_ctrl = seq_ctrl; |
| 1975 | sta->last_subtype = WLAN_FC_STYPE_AUTH; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1976 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1977 | res = ieee802_11_set_radius_info( |
| 1978 | hapd, sta, res, session_timeout, acct_interim_interval, |
| 1979 | &vlan_id, &psk, &identity, &radius_cui); |
| 1980 | if (res) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1981 | wpa_printf(MSG_DEBUG, "ieee802_11_set_radius_info() failed"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1982 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1983 | goto fail; |
| 1984 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1986 | sta->flags &= ~WLAN_STA_PREAUTH; |
| 1987 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |
| 1988 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1989 | /* |
| 1990 | * If the driver supports full AP client state, add a station to the |
| 1991 | * driver before sending authentication reply to make sure the driver |
| 1992 | * has resources, and not to go through the entire authentication and |
| 1993 | * association handshake, and fail it at the end. |
| 1994 | * |
| 1995 | * If this is not the first transaction, in a multi-step authentication |
| 1996 | * algorithm, the station already exists in the driver |
| 1997 | * (sta->added_unassoc = 1) so skip it. |
| 1998 | * |
| 1999 | * In mesh mode, the station was already added to the driver when the |
| 2000 | * NEW_PEER_CANDIDATE event is received. |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2001 | * |
| 2002 | * If PMF was negotiated for the existing association, skip this to |
| 2003 | * avoid dropping the STA entry and the associated keys. This is needed |
| 2004 | * to allow the original connection work until the attempt can complete |
| 2005 | * (re)association, so that unprotected Authentication frame cannot be |
| 2006 | * used to bypass PMF protection. |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2007 | */ |
| 2008 | if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) && |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2009 | (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2010 | !(hapd->conf->mesh & MESH_ENABLED) && |
| 2011 | !(sta->added_unassoc)) { |
| 2012 | /* |
| 2013 | * If a station that is already associated to the AP, is trying |
| 2014 | * to authenticate again, remove the STA entry, in order to make |
| 2015 | * sure the STA PS state gets cleared and configuration gets |
| 2016 | * updated. To handle this, station's added_unassoc flag is |
| 2017 | * cleared once the station has completed association. |
| 2018 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 2019 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2020 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 2021 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_AUTH | |
| 2022 | WLAN_STA_AUTHORIZED); |
| 2023 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 2024 | if (hostapd_sta_add(hapd, sta->addr, 0, 0, NULL, 0, 0, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2025 | NULL, NULL, sta->flags, 0, 0, 0, 0)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2026 | hostapd_logger(hapd, sta->addr, |
| 2027 | HOSTAPD_MODULE_IEEE80211, |
| 2028 | HOSTAPD_LEVEL_NOTICE, |
| 2029 | "Could not add STA to kernel driver"); |
| 2030 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 2031 | goto fail; |
| 2032 | } |
| 2033 | |
| 2034 | sta->added_unassoc = 1; |
| 2035 | } |
| 2036 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2037 | switch (auth_alg) { |
| 2038 | case WLAN_AUTH_OPEN: |
| 2039 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2040 | HOSTAPD_LEVEL_DEBUG, |
| 2041 | "authentication OK (open system)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2042 | sta->flags |= WLAN_STA_AUTH; |
| 2043 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 2044 | sta->auth_alg = WLAN_AUTH_OPEN; |
| 2045 | mlme_authenticate_indication(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2046 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2047 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2048 | case WLAN_AUTH_SHARED_KEY: |
| 2049 | resp = auth_shared_key(hapd, sta, auth_transaction, challenge, |
| 2050 | fc & WLAN_FC_ISWEP); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2051 | if (resp != 0) |
| 2052 | wpa_printf(MSG_DEBUG, |
| 2053 | "auth_shared_key() failed: status=%d", resp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2054 | sta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 2055 | mlme_authenticate_indication(hapd, sta); |
| 2056 | if (sta->challenge && auth_transaction == 1) { |
| 2057 | resp_ies[0] = WLAN_EID_CHALLENGE; |
| 2058 | resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN; |
| 2059 | os_memcpy(resp_ies + 2, sta->challenge, |
| 2060 | WLAN_AUTH_CHALLENGE_LEN); |
| 2061 | resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN; |
| 2062 | } |
| 2063 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2064 | #endif /* CONFIG_NO_RC4 */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2065 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2066 | case WLAN_AUTH_FT: |
| 2067 | sta->auth_alg = WLAN_AUTH_FT; |
| 2068 | if (sta->wpa_sm == NULL) |
| 2069 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2070 | sta->addr, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2071 | if (sta->wpa_sm == NULL) { |
| 2072 | wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA " |
| 2073 | "state machine"); |
| 2074 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2075 | goto fail; |
| 2076 | } |
| 2077 | wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid, |
| 2078 | auth_transaction, mgmt->u.auth.variable, |
| 2079 | len - IEEE80211_HDRLEN - |
| 2080 | sizeof(mgmt->u.auth), |
| 2081 | handle_auth_ft_finish, hapd); |
| 2082 | /* handle_auth_ft_finish() callback will complete auth. */ |
| 2083 | return; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2084 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2085 | #ifdef CONFIG_SAE |
| 2086 | case WLAN_AUTH_SAE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2087 | #ifdef CONFIG_MESH |
| 2088 | if (status_code == WLAN_STATUS_SUCCESS && |
| 2089 | hapd->conf->mesh & MESH_ENABLED) { |
| 2090 | if (sta->wpa_sm == NULL) |
| 2091 | sta->wpa_sm = |
| 2092 | wpa_auth_sta_init(hapd->wpa_auth, |
| 2093 | sta->addr, NULL); |
| 2094 | if (sta->wpa_sm == NULL) { |
| 2095 | wpa_printf(MSG_DEBUG, |
| 2096 | "SAE: Failed to initialize WPA state machine"); |
| 2097 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2098 | goto fail; |
| 2099 | } |
| 2100 | } |
| 2101 | #endif /* CONFIG_MESH */ |
| 2102 | handle_auth_sae(hapd, sta, mgmt, len, auth_transaction, |
| 2103 | status_code); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2104 | return; |
| 2105 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2106 | #ifdef CONFIG_FILS |
| 2107 | case WLAN_AUTH_FILS_SK: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2108 | case WLAN_AUTH_FILS_SK_PFS: |
| 2109 | handle_auth_fils(hapd, sta, mgmt->u.auth.variable, |
| 2110 | len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth), |
| 2111 | auth_alg, auth_transaction, status_code, |
| 2112 | handle_auth_fils_finish); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2113 | return; |
| 2114 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | fail: |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2118 | os_free(identity); |
| 2119 | os_free(radius_cui); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2120 | hostapd_free_psk_list(psk); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2121 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2122 | reply_res = send_auth_reply(hapd, mgmt->sa, mgmt->bssid, auth_alg, |
| 2123 | auth_transaction + 1, resp, resp_ies, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2124 | resp_ies_len, "handle-auth"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2125 | |
| 2126 | if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS || |
| 2127 | reply_res != WLAN_STATUS_SUCCESS)) { |
| 2128 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 2129 | sta->added_unassoc = 0; |
| 2130 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2131 | } |
| 2132 | |
| 2133 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2134 | int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2135 | { |
| 2136 | int i, j = 32, aid; |
| 2137 | |
| 2138 | /* get a unique AID */ |
| 2139 | if (sta->aid > 0) { |
| 2140 | wpa_printf(MSG_DEBUG, " old AID %d", sta->aid); |
| 2141 | return 0; |
| 2142 | } |
| 2143 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2144 | if (TEST_FAIL()) |
| 2145 | return -1; |
| 2146 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2147 | for (i = 0; i < AID_WORDS; i++) { |
| 2148 | if (hapd->sta_aid[i] == (u32) -1) |
| 2149 | continue; |
| 2150 | for (j = 0; j < 32; j++) { |
| 2151 | if (!(hapd->sta_aid[i] & BIT(j))) |
| 2152 | break; |
| 2153 | } |
| 2154 | if (j < 32) |
| 2155 | break; |
| 2156 | } |
| 2157 | if (j == 32) |
| 2158 | return -1; |
| 2159 | aid = i * 32 + j + 1; |
| 2160 | if (aid > 2007) |
| 2161 | return -1; |
| 2162 | |
| 2163 | sta->aid = aid; |
| 2164 | hapd->sta_aid[i] |= BIT(j); |
| 2165 | wpa_printf(MSG_DEBUG, " new AID %d", sta->aid); |
| 2166 | return 0; |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta, |
| 2171 | const u8 *ssid_ie, size_t ssid_ie_len) |
| 2172 | { |
| 2173 | if (ssid_ie == NULL) |
| 2174 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2175 | |
| 2176 | if (ssid_ie_len != hapd->conf->ssid.ssid_len || |
| 2177 | os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2178 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2179 | HOSTAPD_LEVEL_INFO, |
| 2180 | "Station tried to associate with unknown SSID " |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 2181 | "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2182 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2183 | } |
| 2184 | |
| 2185 | return WLAN_STATUS_SUCCESS; |
| 2186 | } |
| 2187 | |
| 2188 | |
| 2189 | static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta, |
| 2190 | const u8 *wmm_ie, size_t wmm_ie_len) |
| 2191 | { |
| 2192 | sta->flags &= ~WLAN_STA_WMM; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2193 | sta->qosinfo = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2194 | if (wmm_ie && hapd->conf->wmm_enabled) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2195 | struct wmm_information_element *wmm; |
| 2196 | |
| 2197 | if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2198 | hostapd_logger(hapd, sta->addr, |
| 2199 | HOSTAPD_MODULE_WPA, |
| 2200 | HOSTAPD_LEVEL_DEBUG, |
| 2201 | "invalid WMM element in association " |
| 2202 | "request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2203 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2204 | } |
| 2205 | |
| 2206 | sta->flags |= WLAN_STA_WMM; |
| 2207 | wmm = (struct wmm_information_element *) wmm_ie; |
| 2208 | sta->qosinfo = wmm->qos_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2209 | } |
| 2210 | return WLAN_STATUS_SUCCESS; |
| 2211 | } |
| 2212 | |
| 2213 | |
| 2214 | static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta, |
| 2215 | struct ieee802_11_elems *elems) |
| 2216 | { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2217 | /* Supported rates not used in IEEE 802.11ad/DMG */ |
| 2218 | if (hapd->iface->current_mode && |
| 2219 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) |
| 2220 | return WLAN_STATUS_SUCCESS; |
| 2221 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2222 | if (!elems->supp_rates) { |
| 2223 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2224 | HOSTAPD_LEVEL_DEBUG, |
| 2225 | "No supported rates element in AssocReq"); |
| 2226 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2227 | } |
| 2228 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2229 | if (elems->supp_rates_len + elems->ext_supp_rates_len > |
| 2230 | sizeof(sta->supported_rates)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2231 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2232 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2233 | "Invalid supported rates element length %d+%d", |
| 2234 | elems->supp_rates_len, |
| 2235 | elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2236 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2237 | } |
| 2238 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2239 | sta->supported_rates_len = merge_byte_arrays( |
| 2240 | sta->supported_rates, sizeof(sta->supported_rates), |
| 2241 | elems->supp_rates, elems->supp_rates_len, |
| 2242 | elems->ext_supp_rates, elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | |
| 2244 | return WLAN_STATUS_SUCCESS; |
| 2245 | } |
| 2246 | |
| 2247 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2248 | static u16 check_ext_capab(struct hostapd_data *hapd, struct sta_info *sta, |
| 2249 | const u8 *ext_capab_ie, size_t ext_capab_ie_len) |
| 2250 | { |
| 2251 | #ifdef CONFIG_INTERWORKING |
| 2252 | /* check for QoS Map support */ |
| 2253 | if (ext_capab_ie_len >= 5) { |
| 2254 | if (ext_capab_ie[4] & 0x01) |
| 2255 | sta->qos_map_enabled = 1; |
| 2256 | } |
| 2257 | #endif /* CONFIG_INTERWORKING */ |
| 2258 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2259 | if (ext_capab_ie_len > 0) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2260 | sta->ecsa_supported = !!(ext_capab_ie[0] & BIT(2)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2261 | os_free(sta->ext_capability); |
| 2262 | sta->ext_capability = os_malloc(1 + ext_capab_ie_len); |
| 2263 | if (sta->ext_capability) { |
| 2264 | sta->ext_capability[0] = ext_capab_ie_len; |
| 2265 | os_memcpy(sta->ext_capability + 1, ext_capab_ie, |
| 2266 | ext_capab_ie_len); |
| 2267 | } |
| 2268 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2269 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2270 | return WLAN_STATUS_SUCCESS; |
| 2271 | } |
| 2272 | |
| 2273 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2274 | #ifdef CONFIG_OWE |
| 2275 | |
| 2276 | static int owe_group_supported(struct hostapd_data *hapd, u16 group) |
| 2277 | { |
| 2278 | int i; |
| 2279 | int *groups = hapd->conf->owe_groups; |
| 2280 | |
| 2281 | if (group != 19 && group != 20 && group != 21) |
| 2282 | return 0; |
| 2283 | |
| 2284 | if (!groups) |
| 2285 | return 1; |
| 2286 | |
| 2287 | for (i = 0; groups[i] > 0; i++) { |
| 2288 | if (groups[i] == group) |
| 2289 | return 1; |
| 2290 | } |
| 2291 | |
| 2292 | return 0; |
| 2293 | } |
| 2294 | |
| 2295 | |
| 2296 | static u16 owe_process_assoc_req(struct hostapd_data *hapd, |
| 2297 | struct sta_info *sta, const u8 *owe_dh, |
| 2298 | u8 owe_dh_len) |
| 2299 | { |
| 2300 | struct wpabuf *secret, *pub, *hkey; |
| 2301 | int res; |
| 2302 | u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN]; |
| 2303 | const char *info = "OWE Key Generation"; |
| 2304 | const u8 *addr[2]; |
| 2305 | size_t len[2]; |
| 2306 | u16 group; |
| 2307 | size_t hash_len, prime_len; |
| 2308 | |
| 2309 | if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) { |
| 2310 | wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching"); |
| 2311 | return WLAN_STATUS_SUCCESS; |
| 2312 | } |
| 2313 | |
| 2314 | group = WPA_GET_LE16(owe_dh); |
| 2315 | if (!owe_group_supported(hapd, group)) { |
| 2316 | wpa_printf(MSG_DEBUG, "OWE: Unsupported DH group %u", group); |
| 2317 | return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 2318 | } |
| 2319 | if (group == 19) |
| 2320 | prime_len = 32; |
| 2321 | else if (group == 20) |
| 2322 | prime_len = 48; |
| 2323 | else if (group == 21) |
| 2324 | prime_len = 66; |
| 2325 | else |
| 2326 | return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 2327 | |
| 2328 | crypto_ecdh_deinit(sta->owe_ecdh); |
| 2329 | sta->owe_ecdh = crypto_ecdh_init(group); |
| 2330 | if (!sta->owe_ecdh) |
| 2331 | return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 2332 | sta->owe_group = group; |
| 2333 | |
| 2334 | secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2, |
| 2335 | owe_dh_len - 2); |
| 2336 | secret = wpabuf_zeropad(secret, prime_len); |
| 2337 | if (!secret) { |
| 2338 | wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key"); |
| 2339 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2340 | } |
| 2341 | wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret); |
| 2342 | |
| 2343 | /* prk = HKDF-extract(C | A | group, z) */ |
| 2344 | |
| 2345 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 2346 | if (!pub) { |
| 2347 | wpabuf_clear_free(secret); |
| 2348 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2349 | } |
| 2350 | |
| 2351 | /* PMKID = Truncate-128(Hash(C | A)) */ |
| 2352 | addr[0] = owe_dh + 2; |
| 2353 | len[0] = owe_dh_len - 2; |
| 2354 | addr[1] = wpabuf_head(pub); |
| 2355 | len[1] = wpabuf_len(pub); |
| 2356 | if (group == 19) { |
| 2357 | res = sha256_vector(2, addr, len, pmkid); |
| 2358 | hash_len = SHA256_MAC_LEN; |
| 2359 | } else if (group == 20) { |
| 2360 | res = sha384_vector(2, addr, len, pmkid); |
| 2361 | hash_len = SHA384_MAC_LEN; |
| 2362 | } else if (group == 21) { |
| 2363 | res = sha512_vector(2, addr, len, pmkid); |
| 2364 | hash_len = SHA512_MAC_LEN; |
| 2365 | } else { |
| 2366 | wpabuf_free(pub); |
| 2367 | wpabuf_clear_free(secret); |
| 2368 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2369 | } |
| 2370 | pub = wpabuf_zeropad(pub, prime_len); |
| 2371 | if (res < 0 || !pub) { |
| 2372 | wpabuf_free(pub); |
| 2373 | wpabuf_clear_free(secret); |
| 2374 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2375 | } |
| 2376 | |
| 2377 | hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2); |
| 2378 | if (!hkey) { |
| 2379 | wpabuf_free(pub); |
| 2380 | wpabuf_clear_free(secret); |
| 2381 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2382 | } |
| 2383 | |
| 2384 | wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */ |
| 2385 | wpabuf_put_buf(hkey, pub); /* A */ |
| 2386 | wpabuf_free(pub); |
| 2387 | wpabuf_put_le16(hkey, group); /* group */ |
| 2388 | if (group == 19) |
| 2389 | res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey), |
| 2390 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 2391 | else if (group == 20) |
| 2392 | res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey), |
| 2393 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 2394 | else if (group == 21) |
| 2395 | res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey), |
| 2396 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 2397 | wpabuf_clear_free(hkey); |
| 2398 | wpabuf_clear_free(secret); |
| 2399 | if (res < 0) |
| 2400 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2401 | |
| 2402 | wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len); |
| 2403 | |
| 2404 | /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */ |
| 2405 | |
| 2406 | os_free(sta->owe_pmk); |
| 2407 | sta->owe_pmk = os_malloc(hash_len); |
| 2408 | if (!sta->owe_pmk) { |
| 2409 | os_memset(prk, 0, SHA512_MAC_LEN); |
| 2410 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2411 | } |
| 2412 | |
| 2413 | if (group == 19) |
| 2414 | res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 2415 | os_strlen(info), sta->owe_pmk, hash_len); |
| 2416 | else if (group == 20) |
| 2417 | res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 2418 | os_strlen(info), sta->owe_pmk, hash_len); |
| 2419 | else if (group == 21) |
| 2420 | res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 2421 | os_strlen(info), sta->owe_pmk, hash_len); |
| 2422 | os_memset(prk, 0, SHA512_MAC_LEN); |
| 2423 | if (res < 0) { |
| 2424 | os_free(sta->owe_pmk); |
| 2425 | sta->owe_pmk = NULL; |
| 2426 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2427 | } |
| 2428 | sta->owe_pmk_len = hash_len; |
| 2429 | |
| 2430 | wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, sta->owe_pmk_len); |
| 2431 | wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN); |
| 2432 | wpa_auth_pmksa_add2(hapd->wpa_auth, sta->addr, sta->owe_pmk, |
| 2433 | sta->owe_pmk_len, pmkid, 0, WPA_KEY_MGMT_OWE); |
| 2434 | |
| 2435 | return WLAN_STATUS_SUCCESS; |
| 2436 | } |
| 2437 | |
| 2438 | #endif /* CONFIG_OWE */ |
| 2439 | |
| 2440 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2441 | static u16 check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta, |
| 2442 | const u8 *ies, size_t ies_len, int reassoc) |
| 2443 | { |
| 2444 | struct ieee802_11_elems elems; |
| 2445 | u16 resp; |
| 2446 | const u8 *wpa_ie; |
| 2447 | size_t wpa_ie_len; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2448 | const u8 *p2p_dev_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2449 | |
| 2450 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) { |
| 2451 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2452 | HOSTAPD_LEVEL_INFO, "Station sent an invalid " |
| 2453 | "association request"); |
| 2454 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2455 | } |
| 2456 | |
| 2457 | resp = check_ssid(hapd, sta, elems.ssid, elems.ssid_len); |
| 2458 | if (resp != WLAN_STATUS_SUCCESS) |
| 2459 | return resp; |
| 2460 | resp = check_wmm(hapd, sta, elems.wmm, elems.wmm_len); |
| 2461 | if (resp != WLAN_STATUS_SUCCESS) |
| 2462 | return resp; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2463 | resp = check_ext_capab(hapd, sta, elems.ext_capab, elems.ext_capab_len); |
| 2464 | if (resp != WLAN_STATUS_SUCCESS) |
| 2465 | return resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2466 | resp = copy_supp_rates(hapd, sta, &elems); |
| 2467 | if (resp != WLAN_STATUS_SUCCESS) |
| 2468 | return resp; |
| 2469 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2470 | resp = copy_sta_ht_capab(hapd, sta, elems.ht_capabilities); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | if (resp != WLAN_STATUS_SUCCESS) |
| 2472 | return resp; |
| 2473 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && |
| 2474 | !(sta->flags & WLAN_STA_HT)) { |
| 2475 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2476 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 2477 | "mandatory HT PHY - reject association"); |
| 2478 | return WLAN_STATUS_ASSOC_DENIED_NO_HT; |
| 2479 | } |
| 2480 | #endif /* CONFIG_IEEE80211N */ |
| 2481 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2482 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2483 | if (hapd->iconf->ieee80211ac) { |
| 2484 | resp = copy_sta_vht_capab(hapd, sta, elems.vht_capabilities); |
| 2485 | if (resp != WLAN_STATUS_SUCCESS) |
| 2486 | return resp; |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2487 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2488 | resp = set_sta_vht_opmode(hapd, sta, elems.vht_opmode_notif); |
| 2489 | if (resp != WLAN_STATUS_SUCCESS) |
| 2490 | return resp; |
| 2491 | } |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 2492 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2493 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && |
| 2494 | !(sta->flags & WLAN_STA_VHT)) { |
| 2495 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2496 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 2497 | "mandatory VHT PHY - reject association"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2498 | return WLAN_STATUS_ASSOC_DENIED_NO_VHT; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2499 | } |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2500 | |
| 2501 | if (hapd->conf->vendor_vht && !elems.vht_capabilities) { |
| 2502 | resp = copy_sta_vendor_vht(hapd, sta, elems.vendor_vht, |
| 2503 | elems.vendor_vht_len); |
| 2504 | if (resp != WLAN_STATUS_SUCCESS) |
| 2505 | return resp; |
| 2506 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2507 | #endif /* CONFIG_IEEE80211AC */ |
| 2508 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2509 | #ifdef CONFIG_P2P |
| 2510 | if (elems.p2p) { |
| 2511 | wpabuf_free(sta->p2p_ie); |
| 2512 | sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 2513 | P2P_IE_VENDOR_TYPE); |
| 2514 | if (sta->p2p_ie) |
| 2515 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
| 2516 | } else { |
| 2517 | wpabuf_free(sta->p2p_ie); |
| 2518 | sta->p2p_ie = NULL; |
| 2519 | } |
| 2520 | #endif /* CONFIG_P2P */ |
| 2521 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2522 | if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems.rsn_ie) { |
| 2523 | wpa_ie = elems.rsn_ie; |
| 2524 | wpa_ie_len = elems.rsn_ie_len; |
| 2525 | } else if ((hapd->conf->wpa & WPA_PROTO_WPA) && |
| 2526 | elems.wpa_ie) { |
| 2527 | wpa_ie = elems.wpa_ie; |
| 2528 | wpa_ie_len = elems.wpa_ie_len; |
| 2529 | } else { |
| 2530 | wpa_ie = NULL; |
| 2531 | wpa_ie_len = 0; |
| 2532 | } |
| 2533 | |
| 2534 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2535 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2536 | if (hapd->conf->wps_state && elems.wps_ie) { |
| 2537 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association " |
| 2538 | "Request - assume WPS is used"); |
| 2539 | sta->flags |= WLAN_STA_WPS; |
| 2540 | wpabuf_free(sta->wps_ie); |
| 2541 | sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 2542 | WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2543 | if (sta->wps_ie && wps_is_20(sta->wps_ie)) { |
| 2544 | wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0"); |
| 2545 | sta->flags |= WLAN_STA_WPS2; |
| 2546 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2547 | wpa_ie = NULL; |
| 2548 | wpa_ie_len = 0; |
| 2549 | if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) { |
| 2550 | wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in " |
| 2551 | "(Re)Association Request - reject"); |
| 2552 | return WLAN_STATUS_INVALID_IE; |
| 2553 | } |
| 2554 | } else if (hapd->conf->wps_state && wpa_ie == NULL) { |
| 2555 | wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in " |
| 2556 | "(Re)Association Request - possible WPS use"); |
| 2557 | sta->flags |= WLAN_STA_MAYBE_WPS; |
| 2558 | } else |
| 2559 | #endif /* CONFIG_WPS */ |
| 2560 | if (hapd->conf->wpa && wpa_ie == NULL) { |
| 2561 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2562 | HOSTAPD_LEVEL_INFO, |
| 2563 | "No WPA/RSN IE in association request"); |
| 2564 | return WLAN_STATUS_INVALID_IE; |
| 2565 | } |
| 2566 | |
| 2567 | if (hapd->conf->wpa && wpa_ie) { |
| 2568 | int res; |
| 2569 | wpa_ie -= 2; |
| 2570 | wpa_ie_len += 2; |
| 2571 | if (sta->wpa_sm == NULL) |
| 2572 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 2573 | sta->addr, |
| 2574 | p2p_dev_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2575 | if (sta->wpa_sm == NULL) { |
| 2576 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 2577 | "state machine"); |
| 2578 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2579 | } |
| 2580 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
| 2581 | wpa_ie, wpa_ie_len, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2582 | elems.mdie, elems.mdie_len, |
| 2583 | elems.owe_dh, elems.owe_dh_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2584 | resp = wpa_res_to_status_code(res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2585 | if (resp != WLAN_STATUS_SUCCESS) |
| 2586 | return resp; |
| 2587 | #ifdef CONFIG_IEEE80211W |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 2588 | if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) == |
| 2589 | (WLAN_STA_ASSOC | WLAN_STA_MFP) && |
| 2590 | !sta->sa_query_timed_out && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2591 | sta->sa_query_count > 0) |
| 2592 | ap_check_sa_query_timeout(hapd, sta); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 2593 | if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_MFP)) == |
| 2594 | (WLAN_STA_ASSOC | WLAN_STA_MFP) && |
| 2595 | !sta->sa_query_timed_out && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2596 | (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) { |
| 2597 | /* |
| 2598 | * STA has already been associated with MFP and SA |
| 2599 | * Query timeout has not been reached. Reject the |
| 2600 | * association attempt temporarily and start SA Query, |
| 2601 | * if one is not pending. |
| 2602 | */ |
| 2603 | |
| 2604 | if (sta->sa_query_count == 0) |
| 2605 | ap_sta_start_sa_query(hapd, sta); |
| 2606 | |
| 2607 | return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
| 2608 | } |
| 2609 | |
| 2610 | if (wpa_auth_uses_mfp(sta->wpa_sm)) |
| 2611 | sta->flags |= WLAN_STA_MFP; |
| 2612 | else |
| 2613 | sta->flags &= ~WLAN_STA_MFP; |
| 2614 | #endif /* CONFIG_IEEE80211W */ |
| 2615 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2616 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2617 | if (sta->auth_alg == WLAN_AUTH_FT) { |
| 2618 | if (!reassoc) { |
| 2619 | wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried " |
| 2620 | "to use association (not " |
| 2621 | "re-association) with FT auth_alg", |
| 2622 | MAC2STR(sta->addr)); |
| 2623 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2624 | } |
| 2625 | |
| 2626 | resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies, |
| 2627 | ies_len); |
| 2628 | if (resp != WLAN_STATUS_SUCCESS) |
| 2629 | return resp; |
| 2630 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2631 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2632 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2633 | #ifdef CONFIG_SAE |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2634 | if (wpa_auth_uses_sae(sta->wpa_sm) && sta->sae && |
| 2635 | sta->sae->state == SAE_ACCEPTED) |
| 2636 | wpa_auth_add_sae_pmkid(sta->wpa_sm, sta->sae->pmkid); |
| 2637 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2638 | if (wpa_auth_uses_sae(sta->wpa_sm) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2639 | sta->auth_alg == WLAN_AUTH_OPEN) { |
| 2640 | struct rsn_pmksa_cache_entry *sa; |
| 2641 | sa = wpa_auth_sta_get_pmksa(sta->wpa_sm); |
| 2642 | if (!sa || sa->akmp != WPA_KEY_MGMT_SAE) { |
| 2643 | wpa_printf(MSG_DEBUG, |
| 2644 | "SAE: No PMKSA cache entry found for " |
| 2645 | MACSTR, MAC2STR(sta->addr)); |
| 2646 | return WLAN_STATUS_INVALID_PMKID; |
| 2647 | } |
| 2648 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR |
| 2649 | " using PMKSA caching", MAC2STR(sta->addr)); |
| 2650 | } else if (wpa_auth_uses_sae(sta->wpa_sm) && |
| 2651 | sta->auth_alg != WLAN_AUTH_SAE && |
| 2652 | !(sta->auth_alg == WLAN_AUTH_FT && |
| 2653 | wpa_auth_uses_ft_sae(sta->wpa_sm))) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2654 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use " |
| 2655 | "SAE AKM after non-SAE auth_alg %u", |
| 2656 | MAC2STR(sta->addr), sta->auth_alg); |
| 2657 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 2658 | } |
| 2659 | #endif /* CONFIG_SAE */ |
| 2660 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2661 | #ifdef CONFIG_OWE |
| 2662 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && |
| 2663 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE && |
| 2664 | elems.owe_dh) { |
| 2665 | resp = owe_process_assoc_req(hapd, sta, elems.owe_dh, |
| 2666 | elems.owe_dh_len); |
| 2667 | if (resp != WLAN_STATUS_SUCCESS) |
| 2668 | return resp; |
| 2669 | } |
| 2670 | #endif /* CONFIG_OWE */ |
| 2671 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2672 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2673 | if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) { |
| 2675 | hostapd_logger(hapd, sta->addr, |
| 2676 | HOSTAPD_MODULE_IEEE80211, |
| 2677 | HOSTAPD_LEVEL_INFO, |
| 2678 | "Station tried to use TKIP with HT " |
| 2679 | "association"); |
| 2680 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
| 2681 | } |
| 2682 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2683 | #ifdef CONFIG_HS20 |
| 2684 | } else if (hapd->conf->osen) { |
| 2685 | if (elems.osen == NULL) { |
| 2686 | hostapd_logger( |
| 2687 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2688 | HOSTAPD_LEVEL_INFO, |
| 2689 | "No HS 2.0 OSEN element in association request"); |
| 2690 | return WLAN_STATUS_INVALID_IE; |
| 2691 | } |
| 2692 | |
| 2693 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); |
| 2694 | if (sta->wpa_sm == NULL) |
| 2695 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
| 2696 | sta->addr, NULL); |
| 2697 | if (sta->wpa_sm == NULL) { |
| 2698 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 2699 | "state machine"); |
| 2700 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2701 | } |
| 2702 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, |
| 2703 | elems.osen - 2, elems.osen_len + 2) < 0) |
| 2704 | return WLAN_STATUS_INVALID_IE; |
| 2705 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2706 | } else |
| 2707 | wpa_auth_sta_no_wpa(sta->wpa_sm); |
| 2708 | |
| 2709 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2710 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len); |
| 2711 | #endif /* CONFIG_P2P */ |
| 2712 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2713 | #ifdef CONFIG_HS20 |
| 2714 | wpabuf_free(sta->hs20_ie); |
| 2715 | if (elems.hs20 && elems.hs20_len > 4) { |
| 2716 | sta->hs20_ie = wpabuf_alloc_copy(elems.hs20 + 4, |
| 2717 | elems.hs20_len - 4); |
| 2718 | } else |
| 2719 | sta->hs20_ie = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2720 | |
| 2721 | wpabuf_free(sta->roaming_consortium); |
| 2722 | if (elems.roaming_cons_sel) |
| 2723 | sta->roaming_consortium = wpabuf_alloc_copy( |
| 2724 | elems.roaming_cons_sel + 4, |
| 2725 | elems.roaming_cons_sel_len - 4); |
| 2726 | else |
| 2727 | sta->roaming_consortium = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2728 | #endif /* CONFIG_HS20 */ |
| 2729 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2730 | #ifdef CONFIG_FST |
| 2731 | wpabuf_free(sta->mb_ies); |
| 2732 | if (hapd->iface->fst) |
| 2733 | sta->mb_ies = mb_ies_by_info(&elems.mb_ies); |
| 2734 | else |
| 2735 | sta->mb_ies = NULL; |
| 2736 | #endif /* CONFIG_FST */ |
| 2737 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2738 | #ifdef CONFIG_MBO |
| 2739 | mbo_ap_check_sta_assoc(hapd, sta, &elems); |
| 2740 | |
| 2741 | if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) && |
| 2742 | elems.mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) && |
| 2743 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
| 2744 | wpa_printf(MSG_INFO, |
| 2745 | "MBO: Reject WPA2 association without PMF"); |
| 2746 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2747 | } |
| 2748 | #endif /* CONFIG_MBO */ |
| 2749 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2750 | ap_copy_sta_supp_op_classes(sta, elems.supp_op_classes, |
| 2751 | elems.supp_op_classes_len); |
| 2752 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2753 | if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) && |
| 2754 | elems.rrm_enabled && |
| 2755 | elems.rrm_enabled_len >= sizeof(sta->rrm_enabled_capa)) |
| 2756 | os_memcpy(sta->rrm_enabled_capa, elems.rrm_enabled, |
| 2757 | sizeof(sta->rrm_enabled_capa)); |
| 2758 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2759 | if (elems.power_capab) { |
| 2760 | sta->min_tx_power = elems.power_capab[0]; |
| 2761 | sta->max_tx_power = elems.power_capab[1]; |
| 2762 | sta->power_capab = 1; |
| 2763 | } else { |
| 2764 | sta->power_capab = 0; |
| 2765 | } |
| 2766 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2767 | return WLAN_STATUS_SUCCESS; |
| 2768 | } |
| 2769 | |
| 2770 | |
| 2771 | static void send_deauth(struct hostapd_data *hapd, const u8 *addr, |
| 2772 | u16 reason_code) |
| 2773 | { |
| 2774 | int send_len; |
| 2775 | struct ieee80211_mgmt reply; |
| 2776 | |
| 2777 | os_memset(&reply, 0, sizeof(reply)); |
| 2778 | reply.frame_control = |
| 2779 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH); |
| 2780 | os_memcpy(reply.da, addr, ETH_ALEN); |
| 2781 | os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN); |
| 2782 | os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN); |
| 2783 | |
| 2784 | send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth); |
| 2785 | reply.u.deauth.reason_code = host_to_le16(reason_code); |
| 2786 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2787 | if (hostapd_drv_send_mlme(hapd, &reply, send_len, 0) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2788 | wpa_printf(MSG_INFO, "Failed to send deauth: %s", |
| 2789 | strerror(errno)); |
| 2790 | } |
| 2791 | |
| 2792 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2793 | static int add_associated_sta(struct hostapd_data *hapd, |
| 2794 | struct sta_info *sta) |
| 2795 | { |
| 2796 | struct ieee80211_ht_capabilities ht_cap; |
| 2797 | struct ieee80211_vht_capabilities vht_cap; |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 2798 | int set = 1; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2799 | |
| 2800 | /* |
| 2801 | * Remove the STA entry to ensure the STA PS state gets cleared and |
| 2802 | * configuration gets updated. This is relevant for cases, such as |
| 2803 | * FT-over-the-DS, where a station re-associates back to the same AP but |
| 2804 | * skips the authentication flow, or if working with a driver that |
| 2805 | * does not support full AP client state. |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 2806 | * |
| 2807 | * Skip this if the STA has already completed FT reassociation and the |
| 2808 | * TK has been configured since the TX/RX PN must not be reset to 0 for |
| 2809 | * the same key. |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2810 | */ |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 2811 | if (!sta->added_unassoc && |
| 2812 | (!(sta->flags & WLAN_STA_AUTHORIZED) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2813 | (!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm) && |
| 2814 | !wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)))) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2815 | hostapd_drv_sta_remove(hapd, sta->addr); |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 2816 | wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED); |
| 2817 | set = 0; |
| 2818 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2819 | |
| 2820 | #ifdef CONFIG_IEEE80211N |
| 2821 | if (sta->flags & WLAN_STA_HT) |
| 2822 | hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap); |
| 2823 | #endif /* CONFIG_IEEE80211N */ |
| 2824 | #ifdef CONFIG_IEEE80211AC |
| 2825 | if (sta->flags & WLAN_STA_VHT) |
| 2826 | hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap); |
| 2827 | #endif /* CONFIG_IEEE80211AC */ |
| 2828 | |
| 2829 | /* |
| 2830 | * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags |
| 2831 | * will be set when the ACK frame for the (Re)Association Response frame |
| 2832 | * is processed (TX status driver event). |
| 2833 | */ |
| 2834 | if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability, |
| 2835 | sta->supported_rates, sta->supported_rates_len, |
| 2836 | sta->listen_interval, |
| 2837 | sta->flags & WLAN_STA_HT ? &ht_cap : NULL, |
| 2838 | sta->flags & WLAN_STA_VHT ? &vht_cap : NULL, |
| 2839 | sta->flags | WLAN_STA_ASSOC, sta->qosinfo, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2840 | sta->vht_opmode, sta->p2p_ie ? 1 : 0, |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 2841 | set)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2842 | hostapd_logger(hapd, sta->addr, |
| 2843 | HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE, |
| 2844 | "Could not %s STA to kernel driver", |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 2845 | set ? "set" : "add"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2846 | |
| 2847 | if (sta->added_unassoc) { |
| 2848 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 2849 | sta->added_unassoc = 0; |
| 2850 | } |
| 2851 | |
| 2852 | return -1; |
| 2853 | } |
| 2854 | |
| 2855 | sta->added_unassoc = 0; |
| 2856 | |
| 2857 | return 0; |
| 2858 | } |
| 2859 | |
| 2860 | |
| 2861 | static u16 send_assoc_resp(struct hostapd_data *hapd, struct sta_info *sta, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2862 | const u8 *addr, u16 status_code, int reassoc, |
| 2863 | const u8 *ies, size_t ies_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2864 | { |
| 2865 | int send_len; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2866 | u8 *buf; |
| 2867 | size_t buflen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2868 | struct ieee80211_mgmt *reply; |
| 2869 | u8 *p; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2870 | u16 res = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2871 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2872 | buflen = sizeof(struct ieee80211_mgmt) + 1024; |
| 2873 | #ifdef CONFIG_FILS |
| 2874 | if (sta && sta->fils_hlp_resp) |
| 2875 | buflen += wpabuf_len(sta->fils_hlp_resp); |
| 2876 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2877 | #ifdef CONFIG_OWE |
| 2878 | if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) |
| 2879 | buflen += 150; |
| 2880 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2881 | buf = os_zalloc(buflen); |
| 2882 | if (!buf) { |
| 2883 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2884 | goto done; |
| 2885 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2886 | reply = (struct ieee80211_mgmt *) buf; |
| 2887 | reply->frame_control = |
| 2888 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 2889 | (reassoc ? WLAN_FC_STYPE_REASSOC_RESP : |
| 2890 | WLAN_FC_STYPE_ASSOC_RESP)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2891 | os_memcpy(reply->da, addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2892 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 2893 | os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN); |
| 2894 | |
| 2895 | send_len = IEEE80211_HDRLEN; |
| 2896 | send_len += sizeof(reply->u.assoc_resp); |
| 2897 | reply->u.assoc_resp.capab_info = |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 2898 | host_to_le16(hostapd_own_capab_info(hapd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2899 | reply->u.assoc_resp.status_code = host_to_le16(status_code); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2900 | |
| 2901 | reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) | |
| 2902 | BIT(14) | BIT(15)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | /* Supported rates */ |
| 2904 | p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable); |
| 2905 | /* Extended supported rates */ |
| 2906 | p = hostapd_eid_ext_supp_rates(hapd, p); |
| 2907 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2908 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2909 | if (sta && status_code == WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2910 | /* IEEE 802.11r: Mobility Domain Information, Fast BSS |
| 2911 | * Transition Information, RSN, [RIC Response] */ |
| 2912 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2913 | buf + buflen - p, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | sta->auth_alg, ies, ies_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2915 | if (!p) { |
| 2916 | wpa_printf(MSG_DEBUG, |
| 2917 | "FT: Failed to write AssocResp IEs"); |
| 2918 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2919 | goto done; |
| 2920 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2922 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2923 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2924 | #ifdef CONFIG_OWE |
| 2925 | if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) |
| 2926 | p = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, p, |
| 2927 | buf + buflen - p, |
| 2928 | ies, ies_len); |
| 2929 | #endif /* CONFIG_OWE */ |
| 2930 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2931 | #ifdef CONFIG_IEEE80211W |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2932 | if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2933 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); |
| 2934 | #endif /* CONFIG_IEEE80211W */ |
| 2935 | |
| 2936 | #ifdef CONFIG_IEEE80211N |
| 2937 | p = hostapd_eid_ht_capabilities(hapd, p); |
| 2938 | p = hostapd_eid_ht_operation(hapd, p); |
| 2939 | #endif /* CONFIG_IEEE80211N */ |
| 2940 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2941 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2942 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 2943 | u32 nsts = 0, sta_nsts; |
| 2944 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2945 | if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 2946 | struct ieee80211_vht_capabilities *capa; |
| 2947 | |
| 2948 | nsts = (hapd->iface->conf->vht_capab >> |
| 2949 | VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7; |
| 2950 | capa = sta->vht_capabilities; |
| 2951 | sta_nsts = (le_to_host32(capa->vht_capabilities_info) >> |
| 2952 | VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7; |
| 2953 | |
| 2954 | if (nsts < sta_nsts) |
| 2955 | nsts = 0; |
| 2956 | else |
| 2957 | nsts = sta_nsts; |
| 2958 | } |
| 2959 | p = hostapd_eid_vht_capabilities(hapd, p, nsts); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2960 | p = hostapd_eid_vht_operation(hapd, p); |
| 2961 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2962 | #endif /* CONFIG_IEEE80211AC */ |
| 2963 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2964 | p = hostapd_eid_ext_capab(hapd, p); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2965 | p = hostapd_eid_bss_max_idle_period(hapd, p); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2966 | if (sta && sta->qos_map_enabled) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2967 | p = hostapd_eid_qos_map_set(hapd, p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2968 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2969 | #ifdef CONFIG_FST |
| 2970 | if (hapd->iface->fst_ies) { |
| 2971 | os_memcpy(p, wpabuf_head(hapd->iface->fst_ies), |
| 2972 | wpabuf_len(hapd->iface->fst_ies)); |
| 2973 | p += wpabuf_len(hapd->iface->fst_ies); |
| 2974 | } |
| 2975 | #endif /* CONFIG_FST */ |
| 2976 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2977 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2978 | if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT)) |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 2979 | p = hostapd_eid_vendor_vht(hapd, p); |
| 2980 | #endif /* CONFIG_IEEE80211AC */ |
| 2981 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2982 | if (sta && (sta->flags & WLAN_STA_WMM)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2983 | p = hostapd_eid_wmm(hapd, p); |
| 2984 | |
| 2985 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2986 | if (sta && |
| 2987 | ((sta->flags & WLAN_STA_WPS) || |
| 2988 | ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2989 | struct wpabuf *wps = wps_build_assoc_resp_ie(); |
| 2990 | if (wps) { |
| 2991 | os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps)); |
| 2992 | p += wpabuf_len(wps); |
| 2993 | wpabuf_free(wps); |
| 2994 | } |
| 2995 | } |
| 2996 | #endif /* CONFIG_WPS */ |
| 2997 | |
| 2998 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2999 | if (sta && sta->p2p_ie && hapd->p2p_group) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3000 | struct wpabuf *p2p_resp_ie; |
| 3001 | enum p2p_status_code status; |
| 3002 | switch (status_code) { |
| 3003 | case WLAN_STATUS_SUCCESS: |
| 3004 | status = P2P_SC_SUCCESS; |
| 3005 | break; |
| 3006 | case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA: |
| 3007 | status = P2P_SC_FAIL_LIMIT_REACHED; |
| 3008 | break; |
| 3009 | default: |
| 3010 | status = P2P_SC_FAIL_INVALID_PARAMS; |
| 3011 | break; |
| 3012 | } |
| 3013 | p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status); |
| 3014 | if (p2p_resp_ie) { |
| 3015 | os_memcpy(p, wpabuf_head(p2p_resp_ie), |
| 3016 | wpabuf_len(p2p_resp_ie)); |
| 3017 | p += wpabuf_len(p2p_resp_ie); |
| 3018 | wpabuf_free(p2p_resp_ie); |
| 3019 | } |
| 3020 | } |
| 3021 | #endif /* CONFIG_P2P */ |
| 3022 | |
| 3023 | #ifdef CONFIG_P2P_MANAGER |
| 3024 | if (hapd->conf->p2p & P2P_MANAGE) |
| 3025 | p = hostapd_eid_p2p_manage(hapd, p); |
| 3026 | #endif /* CONFIG_P2P_MANAGER */ |
| 3027 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3028 | p = hostapd_eid_mbo(hapd, p, buf + buflen - p); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3029 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3030 | if (hapd->conf->assocresp_elements && |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3031 | (size_t) (buf + buflen - p) >= |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3032 | wpabuf_len(hapd->conf->assocresp_elements)) { |
| 3033 | os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements), |
| 3034 | wpabuf_len(hapd->conf->assocresp_elements)); |
| 3035 | p += wpabuf_len(hapd->conf->assocresp_elements); |
| 3036 | } |
| 3037 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3038 | send_len += p - reply->u.assoc_resp.variable; |
| 3039 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3040 | #ifdef CONFIG_FILS |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3041 | if (sta && |
| 3042 | (sta->auth_alg == WLAN_AUTH_FILS_SK || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3043 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 3044 | sta->auth_alg == WLAN_AUTH_FILS_PK) && |
| 3045 | status_code == WLAN_STATUS_SUCCESS) { |
| 3046 | struct ieee802_11_elems elems; |
| 3047 | |
| 3048 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3049 | ParseFailed || !elems.fils_session) { |
| 3050 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3051 | goto done; |
| 3052 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3053 | |
| 3054 | /* FILS Session */ |
| 3055 | *p++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 3056 | *p++ = 1 + FILS_SESSION_LEN; /* Length */ |
| 3057 | *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */ |
| 3058 | os_memcpy(p, elems.fils_session, FILS_SESSION_LEN); |
| 3059 | send_len += 2 + 1 + FILS_SESSION_LEN; |
| 3060 | |
| 3061 | send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3062 | buflen, sta->fils_hlp_resp); |
| 3063 | if (send_len < 0) { |
| 3064 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3065 | goto done; |
| 3066 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3067 | } |
| 3068 | #endif /* CONFIG_FILS */ |
| 3069 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3070 | #ifdef CONFIG_OWE |
| 3071 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && |
| 3072 | sta && sta->owe_ecdh && |
| 3073 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE) { |
| 3074 | struct wpabuf *pub; |
| 3075 | |
| 3076 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 3077 | if (!pub) { |
| 3078 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3079 | goto done; |
| 3080 | } |
| 3081 | /* OWE Diffie-Hellman Parameter element */ |
| 3082 | *p++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 3083 | *p++ = 1 + 2 + wpabuf_len(pub); /* Length */ |
| 3084 | *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */ |
| 3085 | WPA_PUT_LE16(p, sta->owe_group); |
| 3086 | p += 2; |
| 3087 | os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub)); |
| 3088 | p += wpabuf_len(pub); |
| 3089 | send_len += 3 + 2 + wpabuf_len(pub); |
| 3090 | wpabuf_free(pub); |
| 3091 | } |
| 3092 | #endif /* CONFIG_OWE */ |
| 3093 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3094 | if (hostapd_drv_send_mlme(hapd, reply, send_len, 0) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3095 | wpa_printf(MSG_INFO, "Failed to send assoc resp: %s", |
| 3096 | strerror(errno)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3097 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3098 | } |
| 3099 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3100 | done: |
| 3101 | os_free(buf); |
| 3102 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3106 | #ifdef CONFIG_OWE |
| 3107 | u8 * owe_assoc_req_process(struct hostapd_data *hapd, struct sta_info *sta, |
| 3108 | const u8 *owe_dh, u8 owe_dh_len, |
| 3109 | u8 *owe_buf, size_t owe_buf_len, u16 *reason) |
| 3110 | { |
| 3111 | #ifdef CONFIG_TESTING_OPTIONS |
| 3112 | if (hapd->conf->own_ie_override) { |
| 3113 | wpa_printf(MSG_DEBUG, "OWE: Using IE override"); |
| 3114 | *reason = WLAN_STATUS_SUCCESS; |
| 3115 | return wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf, |
| 3116 | owe_buf_len, NULL, 0); |
| 3117 | } |
| 3118 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3119 | |
| 3120 | if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) { |
| 3121 | wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching"); |
| 3122 | owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf, |
| 3123 | owe_buf_len, NULL, 0); |
| 3124 | *reason = WLAN_STATUS_SUCCESS; |
| 3125 | return owe_buf; |
| 3126 | } |
| 3127 | |
| 3128 | *reason = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len); |
| 3129 | if (*reason != WLAN_STATUS_SUCCESS) |
| 3130 | return NULL; |
| 3131 | |
| 3132 | owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf, |
| 3133 | owe_buf_len, NULL, 0); |
| 3134 | |
| 3135 | if (sta->owe_ecdh && owe_buf) { |
| 3136 | struct wpabuf *pub; |
| 3137 | |
| 3138 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 3139 | if (!pub) { |
| 3140 | *reason = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3141 | return owe_buf; |
| 3142 | } |
| 3143 | |
| 3144 | /* OWE Diffie-Hellman Parameter element */ |
| 3145 | *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 3146 | *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */ |
| 3147 | *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension |
| 3148 | */ |
| 3149 | WPA_PUT_LE16(owe_buf, sta->owe_group); |
| 3150 | owe_buf += 2; |
| 3151 | os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub)); |
| 3152 | owe_buf += wpabuf_len(pub); |
| 3153 | wpabuf_free(pub); |
| 3154 | } |
| 3155 | |
| 3156 | return owe_buf; |
| 3157 | } |
| 3158 | #endif /* CONFIG_OWE */ |
| 3159 | |
| 3160 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3161 | #ifdef CONFIG_FILS |
| 3162 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3163 | void fils_hlp_finish_assoc(struct hostapd_data *hapd, struct sta_info *sta) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3164 | { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3165 | u16 reply_res; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3166 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3167 | wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR, |
| 3168 | MAC2STR(sta->addr)); |
| 3169 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 3170 | if (!sta->fils_pending_assoc_req) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3171 | return; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3172 | reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS, |
| 3173 | sta->fils_pending_assoc_is_reassoc, |
| 3174 | sta->fils_pending_assoc_req, |
| 3175 | sta->fils_pending_assoc_req_len); |
| 3176 | os_free(sta->fils_pending_assoc_req); |
| 3177 | sta->fils_pending_assoc_req = NULL; |
| 3178 | sta->fils_pending_assoc_req_len = 0; |
| 3179 | wpabuf_free(sta->fils_hlp_resp); |
| 3180 | sta->fils_hlp_resp = NULL; |
| 3181 | wpabuf_free(sta->hlp_dhcp_discover); |
| 3182 | sta->hlp_dhcp_discover = NULL; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3183 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3184 | /* |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3185 | * Remove the station in case transmission of a success response fails. |
| 3186 | * At this point the station was already added associated to the driver. |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3187 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3188 | if (reply_res != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3189 | hostapd_drv_sta_remove(hapd, sta->addr); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3190 | } |
| 3191 | |
| 3192 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3193 | void fils_hlp_timeout(void *eloop_ctx, void *eloop_data) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3194 | { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3195 | struct hostapd_data *hapd = eloop_ctx; |
| 3196 | struct sta_info *sta = eloop_data; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3197 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3198 | wpa_printf(MSG_DEBUG, |
| 3199 | "FILS: HLP response timeout - continue with association response for " |
| 3200 | MACSTR, MAC2STR(sta->addr)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3201 | if (sta->fils_drv_assoc_finish) |
| 3202 | hostapd_notify_assoc_fils_finish(hapd, sta); |
| 3203 | else |
| 3204 | fils_hlp_finish_assoc(hapd, sta); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3205 | } |
| 3206 | |
| 3207 | #endif /* CONFIG_FILS */ |
| 3208 | |
| 3209 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3210 | static void handle_assoc(struct hostapd_data *hapd, |
| 3211 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 3212 | int reassoc) |
| 3213 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3214 | u16 capab_info, listen_interval, seq_ctrl, fc; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3215 | u16 resp = WLAN_STATUS_SUCCESS, reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3216 | const u8 *pos; |
| 3217 | int left, i; |
| 3218 | struct sta_info *sta; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3219 | u8 *tmp = NULL; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3220 | struct hostapd_sta_wpa_psk_short *psk = NULL; |
| 3221 | char *identity = NULL; |
| 3222 | char *radius_cui = NULL; |
| 3223 | #ifdef CONFIG_FILS |
| 3224 | int delay_assoc = 0; |
| 3225 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3226 | |
| 3227 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) : |
| 3228 | sizeof(mgmt->u.assoc_req))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3229 | wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)", |
| 3230 | reassoc, (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3231 | return; |
| 3232 | } |
| 3233 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3234 | #ifdef CONFIG_TESTING_OPTIONS |
| 3235 | if (reassoc) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3236 | if (hapd->iconf->ignore_reassoc_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3237 | drand48() < hapd->iconf->ignore_reassoc_probability) { |
| 3238 | wpa_printf(MSG_INFO, |
| 3239 | "TESTING: ignoring reassoc request from " |
| 3240 | MACSTR, MAC2STR(mgmt->sa)); |
| 3241 | return; |
| 3242 | } |
| 3243 | } else { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3244 | if (hapd->iconf->ignore_assoc_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3245 | drand48() < hapd->iconf->ignore_assoc_probability) { |
| 3246 | wpa_printf(MSG_INFO, |
| 3247 | "TESTING: ignoring assoc request from " |
| 3248 | MACSTR, MAC2STR(mgmt->sa)); |
| 3249 | return; |
| 3250 | } |
| 3251 | } |
| 3252 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3253 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3254 | fc = le_to_host16(mgmt->frame_control); |
| 3255 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
| 3256 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3257 | if (reassoc) { |
| 3258 | capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info); |
| 3259 | listen_interval = le_to_host16( |
| 3260 | mgmt->u.reassoc_req.listen_interval); |
| 3261 | wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR |
| 3262 | " capab_info=0x%02x listen_interval=%d current_ap=" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3263 | MACSTR " seq_ctrl=0x%x%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3264 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3265 | MAC2STR(mgmt->u.reassoc_req.current_ap), |
| 3266 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3267 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req)); |
| 3268 | pos = mgmt->u.reassoc_req.variable; |
| 3269 | } else { |
| 3270 | capab_info = le_to_host16(mgmt->u.assoc_req.capab_info); |
| 3271 | listen_interval = le_to_host16( |
| 3272 | mgmt->u.assoc_req.listen_interval); |
| 3273 | wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3274 | " capab_info=0x%02x listen_interval=%d " |
| 3275 | "seq_ctrl=0x%x%s", |
| 3276 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
| 3277 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3278 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req)); |
| 3279 | pos = mgmt->u.assoc_req.variable; |
| 3280 | } |
| 3281 | |
| 3282 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3283 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3284 | if (sta && sta->auth_alg == WLAN_AUTH_FT && |
| 3285 | (sta->flags & WLAN_STA_AUTH) == 0) { |
| 3286 | wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate " |
| 3287 | "prior to authentication since it is using " |
| 3288 | "over-the-DS FT", MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3289 | |
| 3290 | /* |
| 3291 | * Mark station as authenticated, to avoid adding station |
| 3292 | * entry in the driver as associated and not authenticated |
| 3293 | */ |
| 3294 | sta->flags |= WLAN_STA_AUTH; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3295 | } else |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3296 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3297 | if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3298 | if (hapd->iface->current_mode && |
| 3299 | hapd->iface->current_mode->mode == |
| 3300 | HOSTAPD_MODE_IEEE80211AD) { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3301 | int acl_res; |
| 3302 | u32 session_timeout, acct_interim_interval; |
| 3303 | struct vlan_description vlan_id; |
| 3304 | |
| 3305 | acl_res = ieee802_11_allowed_address( |
| 3306 | hapd, mgmt->sa, (const u8 *) mgmt, len, |
| 3307 | &session_timeout, &acct_interim_interval, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3308 | &vlan_id, &psk, &identity, &radius_cui, 0); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3309 | if (acl_res == HOSTAPD_ACL_REJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3310 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 3311 | "Ignore Association Request frame from " |
| 3312 | MACSTR " due to ACL reject", |
| 3313 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3314 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3315 | goto fail; |
| 3316 | } |
| 3317 | if (acl_res == HOSTAPD_ACL_PENDING) |
| 3318 | return; |
| 3319 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3320 | /* DMG/IEEE 802.11ad does not use authentication. |
| 3321 | * Allocate sta entry upon association. */ |
| 3322 | sta = ap_sta_add(hapd, mgmt->sa); |
| 3323 | if (!sta) { |
| 3324 | hostapd_logger(hapd, mgmt->sa, |
| 3325 | HOSTAPD_MODULE_IEEE80211, |
| 3326 | HOSTAPD_LEVEL_INFO, |
| 3327 | "Failed to add STA"); |
| 3328 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 3329 | goto fail; |
| 3330 | } |
| 3331 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3332 | acl_res = ieee802_11_set_radius_info( |
| 3333 | hapd, sta, acl_res, session_timeout, |
| 3334 | acct_interim_interval, &vlan_id, &psk, |
| 3335 | &identity, &radius_cui); |
| 3336 | if (acl_res) { |
| 3337 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3338 | goto fail; |
| 3339 | } |
| 3340 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3341 | hostapd_logger(hapd, sta->addr, |
| 3342 | HOSTAPD_MODULE_IEEE80211, |
| 3343 | HOSTAPD_LEVEL_DEBUG, |
| 3344 | "Skip authentication for DMG/IEEE 802.11ad"); |
| 3345 | sta->flags |= WLAN_STA_AUTH; |
| 3346 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 3347 | sta->auth_alg = WLAN_AUTH_OPEN; |
| 3348 | } else { |
| 3349 | hostapd_logger(hapd, mgmt->sa, |
| 3350 | HOSTAPD_MODULE_IEEE80211, |
| 3351 | HOSTAPD_LEVEL_INFO, |
| 3352 | "Station tried to associate before authentication (aid=%d flags=0x%x)", |
| 3353 | sta ? sta->aid : -1, |
| 3354 | sta ? sta->flags : 0); |
| 3355 | send_deauth(hapd, mgmt->sa, |
| 3356 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); |
| 3357 | return; |
| 3358 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3361 | if ((fc & WLAN_FC_RETRY) && |
| 3362 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 3363 | sta->last_seq_ctrl == seq_ctrl && |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3364 | sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ : |
| 3365 | WLAN_FC_STYPE_ASSOC_REQ)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3366 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3367 | HOSTAPD_LEVEL_DEBUG, |
| 3368 | "Drop repeated association frame seq_ctrl=0x%x", |
| 3369 | seq_ctrl); |
| 3370 | return; |
| 3371 | } |
| 3372 | sta->last_seq_ctrl = seq_ctrl; |
| 3373 | sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ : |
| 3374 | WLAN_FC_STYPE_ASSOC_REQ; |
| 3375 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3376 | if (hapd->tkip_countermeasures) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3377 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3378 | goto fail; |
| 3379 | } |
| 3380 | |
| 3381 | if (listen_interval > hapd->conf->max_listen_interval) { |
| 3382 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 3383 | HOSTAPD_LEVEL_DEBUG, |
| 3384 | "Too large Listen Interval (%d)", |
| 3385 | listen_interval); |
| 3386 | resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE; |
| 3387 | goto fail; |
| 3388 | } |
| 3389 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3390 | #ifdef CONFIG_MBO |
| 3391 | if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) { |
| 3392 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 3393 | goto fail; |
| 3394 | } |
| 3395 | #endif /* CONFIG_MBO */ |
| 3396 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3397 | /* |
| 3398 | * sta->capability is used in check_assoc_ies() for RRM enabled |
| 3399 | * capability element. |
| 3400 | */ |
| 3401 | sta->capability = capab_info; |
| 3402 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3403 | #ifdef CONFIG_FILS |
| 3404 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 3405 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 3406 | sta->auth_alg == WLAN_AUTH_FILS_PK) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3407 | int res; |
| 3408 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3409 | /* The end of the payload is encrypted. Need to decrypt it |
| 3410 | * before parsing. */ |
| 3411 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3412 | tmp = os_memdup(pos, left); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3413 | if (!tmp) { |
| 3414 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3415 | goto fail; |
| 3416 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3417 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3418 | res = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt, |
| 3419 | len, tmp, left); |
| 3420 | if (res < 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3421 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3422 | goto fail; |
| 3423 | } |
| 3424 | pos = tmp; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3425 | left = res; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3426 | } |
| 3427 | #endif /* CONFIG_FILS */ |
| 3428 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3429 | /* followed by SSID and Supported rates; and HT capabilities if 802.11n |
| 3430 | * is used */ |
| 3431 | resp = check_assoc_ies(hapd, sta, pos, left, reassoc); |
| 3432 | if (resp != WLAN_STATUS_SUCCESS) |
| 3433 | goto fail; |
| 3434 | |
| 3435 | if (hostapd_get_aid(hapd, sta) < 0) { |
| 3436 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 3437 | HOSTAPD_LEVEL_INFO, "No room for more AIDs"); |
| 3438 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 3439 | goto fail; |
| 3440 | } |
| 3441 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3442 | sta->listen_interval = listen_interval; |
| 3443 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3444 | if (hapd->iface->current_mode && |
| 3445 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3446 | sta->flags |= WLAN_STA_NONERP; |
| 3447 | for (i = 0; i < sta->supported_rates_len; i++) { |
| 3448 | if ((sta->supported_rates[i] & 0x7f) > 22) { |
| 3449 | sta->flags &= ~WLAN_STA_NONERP; |
| 3450 | break; |
| 3451 | } |
| 3452 | } |
| 3453 | if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) { |
| 3454 | sta->nonerp_set = 1; |
| 3455 | hapd->iface->num_sta_non_erp++; |
| 3456 | if (hapd->iface->num_sta_non_erp == 1) |
| 3457 | ieee802_11_set_beacons(hapd->iface); |
| 3458 | } |
| 3459 | |
| 3460 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) && |
| 3461 | !sta->no_short_slot_time_set) { |
| 3462 | sta->no_short_slot_time_set = 1; |
| 3463 | hapd->iface->num_sta_no_short_slot_time++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3464 | if (hapd->iface->current_mode && |
| 3465 | hapd->iface->current_mode->mode == |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3466 | HOSTAPD_MODE_IEEE80211G && |
| 3467 | hapd->iface->num_sta_no_short_slot_time == 1) |
| 3468 | ieee802_11_set_beacons(hapd->iface); |
| 3469 | } |
| 3470 | |
| 3471 | if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 3472 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 3473 | else |
| 3474 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 3475 | |
| 3476 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
| 3477 | !sta->no_short_preamble_set) { |
| 3478 | sta->no_short_preamble_set = 1; |
| 3479 | hapd->iface->num_sta_no_short_preamble++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3480 | if (hapd->iface->current_mode && |
| 3481 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3482 | && hapd->iface->num_sta_no_short_preamble == 1) |
| 3483 | ieee802_11_set_beacons(hapd->iface); |
| 3484 | } |
| 3485 | |
| 3486 | #ifdef CONFIG_IEEE80211N |
| 3487 | update_ht_state(hapd, sta); |
| 3488 | #endif /* CONFIG_IEEE80211N */ |
| 3489 | |
| 3490 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3491 | HOSTAPD_LEVEL_DEBUG, |
| 3492 | "association OK (aid %d)", sta->aid); |
| 3493 | /* Station will be marked associated, after it acknowledges AssocResp |
| 3494 | */ |
| 3495 | sta->flags |= WLAN_STA_ASSOC_REQ_OK; |
| 3496 | |
| 3497 | #ifdef CONFIG_IEEE80211W |
| 3498 | if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) { |
| 3499 | wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out " |
| 3500 | "SA Query procedure", reassoc ? "re" : ""); |
| 3501 | /* TODO: Send a protected Disassociate frame to the STA using |
| 3502 | * the old key and Reason Code "Previous Authentication no |
| 3503 | * longer valid". Make sure this is only sent protected since |
| 3504 | * unprotected frame would be received by the STA that is now |
| 3505 | * trying to associate. |
| 3506 | */ |
| 3507 | } |
| 3508 | #endif /* CONFIG_IEEE80211W */ |
| 3509 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3510 | /* Make sure that the previously registered inactivity timer will not |
| 3511 | * remove the STA immediately. */ |
| 3512 | sta->timeout_next = STA_NULLFUNC; |
| 3513 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3514 | #ifdef CONFIG_TAXONOMY |
| 3515 | taxonomy_sta_info_assoc_req(hapd, sta, pos, left); |
| 3516 | #endif /* CONFIG_TAXONOMY */ |
| 3517 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3518 | sta->pending_wds_enable = 0; |
| 3519 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3520 | #ifdef CONFIG_FILS |
| 3521 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 3522 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3523 | sta->auth_alg == WLAN_AUTH_FILS_PK) { |
| 3524 | if (fils_process_hlp(hapd, sta, pos, left) > 0) |
| 3525 | delay_assoc = 1; |
| 3526 | } |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3527 | #endif /* CONFIG_FILS */ |
| 3528 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3529 | fail: |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3530 | os_free(identity); |
| 3531 | os_free(radius_cui); |
| 3532 | hostapd_free_psk_list(psk); |
| 3533 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3534 | /* |
| 3535 | * In case of a successful response, add the station to the driver. |
| 3536 | * Otherwise, the kernel may ignore Data frames before we process the |
| 3537 | * ACK frame (TX status). In case of a failure, this station will be |
| 3538 | * removed. |
| 3539 | * |
| 3540 | * Note that this is not compliant with the IEEE 802.11 standard that |
| 3541 | * states that a non-AP station should transition into the |
| 3542 | * authenticated/associated state only after the station acknowledges |
| 3543 | * the (Re)Association Response frame. However, still do this as: |
| 3544 | * |
| 3545 | * 1. In case the station does not acknowledge the (Re)Association |
| 3546 | * Response frame, it will be removed. |
| 3547 | * 2. Data frames will be dropped in the kernel until the station is |
| 3548 | * set into authorized state, and there are no significant known |
| 3549 | * issues with processing other non-Data Class 3 frames during this |
| 3550 | * window. |
| 3551 | */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3552 | if (resp == WLAN_STATUS_SUCCESS && sta && add_associated_sta(hapd, sta)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3553 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 3554 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3555 | #ifdef CONFIG_FILS |
| 3556 | if (sta) { |
| 3557 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 3558 | os_free(sta->fils_pending_assoc_req); |
| 3559 | sta->fils_pending_assoc_req = NULL; |
| 3560 | sta->fils_pending_assoc_req_len = 0; |
| 3561 | wpabuf_free(sta->fils_hlp_resp); |
| 3562 | sta->fils_hlp_resp = NULL; |
| 3563 | } |
| 3564 | if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) { |
| 3565 | sta->fils_pending_assoc_req = tmp; |
| 3566 | sta->fils_pending_assoc_req_len = left; |
| 3567 | sta->fils_pending_assoc_is_reassoc = reassoc; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3568 | sta->fils_drv_assoc_finish = 0; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3569 | wpa_printf(MSG_DEBUG, |
| 3570 | "FILS: Waiting for HLP processing before sending (Re)Association Response frame to " |
| 3571 | MACSTR, MAC2STR(sta->addr)); |
| 3572 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 3573 | eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024, |
| 3574 | fils_hlp_timeout, hapd, sta); |
| 3575 | return; |
| 3576 | } |
| 3577 | #endif /* CONFIG_FILS */ |
| 3578 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3579 | reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, pos, |
| 3580 | left); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3581 | os_free(tmp); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3582 | |
| 3583 | /* |
| 3584 | * Remove the station in case tranmission of a success response fails |
| 3585 | * (the STA was added associated to the driver) or if the station was |
| 3586 | * previously added unassociated. |
| 3587 | */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3588 | if (sta && ((reply_res != WLAN_STATUS_SUCCESS && |
| 3589 | resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3590 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 3591 | sta->added_unassoc = 0; |
| 3592 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3593 | } |
| 3594 | |
| 3595 | |
| 3596 | static void handle_disassoc(struct hostapd_data *hapd, |
| 3597 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 3598 | { |
| 3599 | struct sta_info *sta; |
| 3600 | |
| 3601 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3602 | wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)", |
| 3603 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3604 | return; |
| 3605 | } |
| 3606 | |
| 3607 | wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d", |
| 3608 | MAC2STR(mgmt->sa), |
| 3609 | le_to_host16(mgmt->u.disassoc.reason_code)); |
| 3610 | |
| 3611 | sta = ap_get_sta(hapd, mgmt->sa); |
| 3612 | if (sta == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3613 | wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated", |
| 3614 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3615 | return; |
| 3616 | } |
| 3617 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3618 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3619 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3620 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3621 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
| 3622 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3623 | HOSTAPD_LEVEL_INFO, "disassociated"); |
| 3624 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 3625 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 3626 | /* Stop Accounting and IEEE 802.1X sessions, but leave the STA |
| 3627 | * authenticated. */ |
| 3628 | accounting_sta_stop(hapd, sta); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 3629 | ieee802_1x_free_station(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3630 | if (sta->ipaddr) |
| 3631 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 3632 | ap_sta_ip6addr_del(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3633 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3634 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3635 | |
| 3636 | if (sta->timeout_next == STA_NULLFUNC || |
| 3637 | sta->timeout_next == STA_DISASSOC) { |
| 3638 | sta->timeout_next = STA_DEAUTH; |
| 3639 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 3640 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
| 3641 | hapd, sta); |
| 3642 | } |
| 3643 | |
| 3644 | mlme_disassociate_indication( |
| 3645 | hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3646 | |
| 3647 | /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon |
| 3648 | * disassociation. */ |
| 3649 | if (hapd->iface->current_mode && |
| 3650 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { |
| 3651 | sta->flags &= ~WLAN_STA_AUTH; |
| 3652 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 3653 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3654 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); |
| 3655 | ap_free_sta(hapd, sta); |
| 3656 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | |
| 3660 | static void handle_deauth(struct hostapd_data *hapd, |
| 3661 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 3662 | { |
| 3663 | struct sta_info *sta; |
| 3664 | |
| 3665 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3666 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short " |
| 3667 | "payload (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3668 | return; |
| 3669 | } |
| 3670 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3671 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3672 | " reason_code=%d", |
| 3673 | MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code)); |
| 3674 | |
| 3675 | sta = ap_get_sta(hapd, mgmt->sa); |
| 3676 | if (sta == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3677 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " |
| 3678 | "to deauthenticate, but it is not authenticated", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3679 | MAC2STR(mgmt->sa)); |
| 3680 | return; |
| 3681 | } |
| 3682 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3683 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3684 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3685 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 3686 | WLAN_STA_ASSOC_REQ_OK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3687 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 3688 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3689 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); |
| 3690 | mlme_deauthenticate_indication( |
| 3691 | hapd, sta, le_to_host16(mgmt->u.deauth.reason_code)); |
| 3692 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 3693 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 3694 | ap_free_sta(hapd, sta); |
| 3695 | } |
| 3696 | |
| 3697 | |
| 3698 | static void handle_beacon(struct hostapd_data *hapd, |
| 3699 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 3700 | struct hostapd_frame_info *fi) |
| 3701 | { |
| 3702 | struct ieee802_11_elems elems; |
| 3703 | |
| 3704 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3705 | wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)", |
| 3706 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3707 | return; |
| 3708 | } |
| 3709 | |
| 3710 | (void) ieee802_11_parse_elems(mgmt->u.beacon.variable, |
| 3711 | len - (IEEE80211_HDRLEN + |
| 3712 | sizeof(mgmt->u.beacon)), &elems, |
| 3713 | 0); |
| 3714 | |
| 3715 | ap_list_process_beacon(hapd->iface, mgmt, &elems, fi); |
| 3716 | } |
| 3717 | |
| 3718 | |
| 3719 | #ifdef CONFIG_IEEE80211W |
| 3720 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3721 | static int hostapd_sa_query_action(struct hostapd_data *hapd, |
| 3722 | const struct ieee80211_mgmt *mgmt, |
| 3723 | size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3724 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3725 | const u8 *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3726 | |
| 3727 | end = mgmt->u.action.u.sa_query_resp.trans_id + |
| 3728 | WLAN_SA_QUERY_TR_ID_LEN; |
| 3729 | if (((u8 *) mgmt) + len < end) { |
| 3730 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Too short SA Query Action " |
| 3731 | "frame (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3732 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3733 | } |
| 3734 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3735 | ieee802_11_sa_query_action(hapd, mgmt->sa, |
| 3736 | mgmt->u.action.u.sa_query_resp.action, |
| 3737 | mgmt->u.action.u.sa_query_resp.trans_id); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3738 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3739 | } |
| 3740 | |
| 3741 | |
| 3742 | static int robust_action_frame(u8 category) |
| 3743 | { |
| 3744 | return category != WLAN_ACTION_PUBLIC && |
| 3745 | category != WLAN_ACTION_HT; |
| 3746 | } |
| 3747 | #endif /* CONFIG_IEEE80211W */ |
| 3748 | |
| 3749 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3750 | static int handle_action(struct hostapd_data *hapd, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3751 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 3752 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3753 | { |
| 3754 | struct sta_info *sta; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3755 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3756 | |
| 3757 | if (len < IEEE80211_HDRLEN + 1) { |
| 3758 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 3759 | HOSTAPD_LEVEL_DEBUG, |
| 3760 | "handle_action - too short payload (len=%lu)", |
| 3761 | (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3762 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3765 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC && |
| 3766 | (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) { |
| 3767 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action " |
| 3768 | "frame (category=%u) from unassociated STA " MACSTR, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3769 | mgmt->u.action.category, MAC2STR(mgmt->sa)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3770 | return 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3771 | } |
| 3772 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3773 | #ifdef CONFIG_IEEE80211W |
| 3774 | if (sta && (sta->flags & WLAN_STA_MFP) && |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3775 | !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) && |
| 3776 | robust_action_frame(mgmt->u.action.category)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3777 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 3778 | HOSTAPD_LEVEL_DEBUG, |
| 3779 | "Dropped unprotected Robust Action frame from " |
| 3780 | "an MFP STA"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3781 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3782 | } |
| 3783 | #endif /* CONFIG_IEEE80211W */ |
| 3784 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3785 | if (sta) { |
| 3786 | u16 fc = le_to_host16(mgmt->frame_control); |
| 3787 | u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
| 3788 | |
| 3789 | if ((fc & WLAN_FC_RETRY) && |
| 3790 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 3791 | sta->last_seq_ctrl == seq_ctrl && |
| 3792 | sta->last_subtype == WLAN_FC_STYPE_ACTION) { |
| 3793 | hostapd_logger(hapd, sta->addr, |
| 3794 | HOSTAPD_MODULE_IEEE80211, |
| 3795 | HOSTAPD_LEVEL_DEBUG, |
| 3796 | "Drop repeated action frame seq_ctrl=0x%x", |
| 3797 | seq_ctrl); |
| 3798 | return 1; |
| 3799 | } |
| 3800 | |
| 3801 | sta->last_seq_ctrl = seq_ctrl; |
| 3802 | sta->last_subtype = WLAN_FC_STYPE_ACTION; |
| 3803 | } |
| 3804 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3805 | switch (mgmt->u.action.category) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3806 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3807 | case WLAN_ACTION_FT: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3808 | if (!sta || |
| 3809 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3810 | len - IEEE80211_HDRLEN)) |
| 3811 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3812 | return 1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3813 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3814 | case WLAN_ACTION_WMM: |
| 3815 | hostapd_wmm_action(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3816 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3817 | #ifdef CONFIG_IEEE80211W |
| 3818 | case WLAN_ACTION_SA_QUERY: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3819 | return hostapd_sa_query_action(hapd, mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3820 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3821 | #ifdef CONFIG_WNM_AP |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3822 | case WLAN_ACTION_WNM: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3823 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, len); |
| 3824 | return 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3825 | #endif /* CONFIG_WNM_AP */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3826 | #ifdef CONFIG_FST |
| 3827 | case WLAN_ACTION_FST: |
| 3828 | if (hapd->iface->fst) |
| 3829 | fst_rx_action(hapd->iface->fst, mgmt, len); |
| 3830 | else |
| 3831 | wpa_printf(MSG_DEBUG, |
| 3832 | "FST: Ignore FST Action frame - no FST attached"); |
| 3833 | return 1; |
| 3834 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | case WLAN_ACTION_PUBLIC: |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 3836 | case WLAN_ACTION_PROTECTED_DUAL: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3837 | #ifdef CONFIG_IEEE80211N |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 3838 | if (len >= IEEE80211_HDRLEN + 2 && |
| 3839 | mgmt->u.action.u.public_action.action == |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3840 | WLAN_PA_20_40_BSS_COEX) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3841 | hostapd_2040_coex_action(hapd, mgmt, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3842 | return 1; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3843 | } |
| 3844 | #endif /* CONFIG_IEEE80211N */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3845 | #ifdef CONFIG_DPP |
| 3846 | if (len >= IEEE80211_HDRLEN + 6 && |
| 3847 | mgmt->u.action.u.vs_public_action.action == |
| 3848 | WLAN_PA_VENDOR_SPECIFIC && |
| 3849 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 3850 | OUI_WFA && |
| 3851 | mgmt->u.action.u.vs_public_action.variable[0] == |
| 3852 | DPP_OUI_TYPE) { |
| 3853 | const u8 *pos, *end; |
| 3854 | |
| 3855 | pos = mgmt->u.action.u.vs_public_action.oui; |
| 3856 | end = ((const u8 *) mgmt) + len; |
| 3857 | hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3858 | freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3859 | return 1; |
| 3860 | } |
| 3861 | if (len >= IEEE80211_HDRLEN + 2 && |
| 3862 | (mgmt->u.action.u.public_action.action == |
| 3863 | WLAN_PA_GAS_INITIAL_RESP || |
| 3864 | mgmt->u.action.u.public_action.action == |
| 3865 | WLAN_PA_GAS_COMEBACK_RESP)) { |
| 3866 | const u8 *pos, *end; |
| 3867 | |
| 3868 | pos = &mgmt->u.action.u.public_action.action; |
| 3869 | end = ((const u8 *) mgmt) + len; |
| 3870 | gas_query_ap_rx(hapd->gas, mgmt->sa, |
| 3871 | mgmt->u.action.category, |
| 3872 | pos, end - pos, hapd->iface->freq); |
| 3873 | return 1; |
| 3874 | } |
| 3875 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3876 | if (hapd->public_action_cb) { |
| 3877 | hapd->public_action_cb(hapd->public_action_cb_ctx, |
| 3878 | (u8 *) mgmt, len, |
| 3879 | hapd->iface->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3880 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3881 | if (hapd->public_action_cb2) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3882 | hapd->public_action_cb2(hapd->public_action_cb2_ctx, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3883 | (u8 *) mgmt, len, |
| 3884 | hapd->iface->freq); |
| 3885 | } |
| 3886 | if (hapd->public_action_cb || hapd->public_action_cb2) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3887 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3888 | break; |
| 3889 | case WLAN_ACTION_VENDOR_SPECIFIC: |
| 3890 | if (hapd->vendor_action_cb) { |
| 3891 | if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx, |
| 3892 | (u8 *) mgmt, len, |
| 3893 | hapd->iface->freq) == 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3894 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3895 | } |
| 3896 | break; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 3897 | case WLAN_ACTION_RADIO_MEASUREMENT: |
| 3898 | hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len); |
| 3899 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3900 | } |
| 3901 | |
| 3902 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 3903 | HOSTAPD_LEVEL_DEBUG, |
| 3904 | "handle_action - unknown action category %d or invalid " |
| 3905 | "frame", |
| 3906 | mgmt->u.action.category); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3907 | if (!is_multicast_ether_addr(mgmt->da) && |
| 3908 | !(mgmt->u.action.category & 0x80) && |
| 3909 | !is_multicast_ether_addr(mgmt->sa)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3910 | struct ieee80211_mgmt *resp; |
| 3911 | |
| 3912 | /* |
| 3913 | * IEEE 802.11-REVma/D9.0 - 7.3.1.11 |
| 3914 | * Return the Action frame to the source without change |
| 3915 | * except that MSB of the Category set to 1. |
| 3916 | */ |
| 3917 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action " |
| 3918 | "frame back to sender"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3919 | resp = os_memdup(mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3920 | if (resp == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3921 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3922 | os_memcpy(resp->da, resp->sa, ETH_ALEN); |
| 3923 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); |
| 3924 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); |
| 3925 | resp->u.action.category |= 0x80; |
| 3926 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3927 | if (hostapd_drv_send_mlme(hapd, resp, len, 0) < 0) { |
| 3928 | wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send " |
| 3929 | "Action frame"); |
| 3930 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3931 | os_free(resp); |
| 3932 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3933 | |
| 3934 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3935 | } |
| 3936 | |
| 3937 | |
| 3938 | /** |
| 3939 | * ieee802_11_mgmt - process incoming IEEE 802.11 management frames |
| 3940 | * @hapd: hostapd BSS data structure (the BSS to which the management frame was |
| 3941 | * sent to) |
| 3942 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 3943 | * @len: length of frame data in octets |
| 3944 | * @fi: meta data about received frame (signal level, etc.) |
| 3945 | * |
| 3946 | * Process all incoming IEEE 802.11 management frames. This will be called for |
| 3947 | * each frame received from the kernel driver through wlan#ap interface. In |
| 3948 | * addition, it can be called to re-inserted pending frames (e.g., when using |
| 3949 | * external RADIUS server as an MAC ACL). |
| 3950 | */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3951 | int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 3952 | struct hostapd_frame_info *fi) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3953 | { |
| 3954 | struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3955 | u16 fc, stype; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3956 | int ret = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3957 | unsigned int freq; |
| 3958 | int ssi_signal = fi ? fi->ssi_signal : 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3959 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3960 | if (len < 24) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3961 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3962 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3963 | if (fi && fi->freq) |
| 3964 | freq = fi->freq; |
| 3965 | else |
| 3966 | freq = hapd->iface->freq; |
| 3967 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3968 | mgmt = (struct ieee80211_mgmt *) buf; |
| 3969 | fc = le_to_host16(mgmt->frame_control); |
| 3970 | stype = WLAN_FC_GET_STYPE(fc); |
| 3971 | |
| 3972 | if (stype == WLAN_FC_STYPE_BEACON) { |
| 3973 | handle_beacon(hapd, mgmt, len, fi); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3974 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3975 | } |
| 3976 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 3977 | if (!is_broadcast_ether_addr(mgmt->bssid) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3978 | #ifdef CONFIG_P2P |
| 3979 | /* Invitation responses can be sent with the peer MAC as BSSID */ |
| 3980 | !((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 3981 | stype == WLAN_FC_STYPE_ACTION) && |
| 3982 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3983 | #ifdef CONFIG_MESH |
| 3984 | !(hapd->conf->mesh & MESH_ENABLED) && |
| 3985 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3986 | os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3987 | wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address", |
| 3988 | MAC2STR(mgmt->bssid)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3989 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3990 | } |
| 3991 | |
| 3992 | |
| 3993 | if (stype == WLAN_FC_STYPE_PROBE_REQ) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3994 | handle_probe_req(hapd, mgmt, len, ssi_signal); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3995 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3998 | if ((!is_broadcast_ether_addr(mgmt->da) || |
| 3999 | stype != WLAN_FC_STYPE_ACTION) && |
| 4000 | os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4001 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 4002 | HOSTAPD_LEVEL_DEBUG, |
| 4003 | "MGMT: DA=" MACSTR " not our address", |
| 4004 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4005 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4006 | } |
| 4007 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4008 | if (hapd->iconf->track_sta_max_num) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4009 | sta_track_add(hapd->iface, mgmt->sa, ssi_signal); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4011 | switch (stype) { |
| 4012 | case WLAN_FC_STYPE_AUTH: |
| 4013 | wpa_printf(MSG_DEBUG, "mgmt::auth"); |
| 4014 | handle_auth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4015 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4016 | break; |
| 4017 | case WLAN_FC_STYPE_ASSOC_REQ: |
| 4018 | wpa_printf(MSG_DEBUG, "mgmt::assoc_req"); |
| 4019 | handle_assoc(hapd, mgmt, len, 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4020 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4021 | break; |
| 4022 | case WLAN_FC_STYPE_REASSOC_REQ: |
| 4023 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_req"); |
| 4024 | handle_assoc(hapd, mgmt, len, 1); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4025 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4026 | break; |
| 4027 | case WLAN_FC_STYPE_DISASSOC: |
| 4028 | wpa_printf(MSG_DEBUG, "mgmt::disassoc"); |
| 4029 | handle_disassoc(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4030 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4031 | break; |
| 4032 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4033 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4034 | handle_deauth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4035 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4036 | break; |
| 4037 | case WLAN_FC_STYPE_ACTION: |
| 4038 | wpa_printf(MSG_DEBUG, "mgmt::action"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4039 | ret = handle_action(hapd, mgmt, len, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4040 | break; |
| 4041 | default: |
| 4042 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 4043 | HOSTAPD_LEVEL_DEBUG, |
| 4044 | "unknown mgmt frame subtype %d", stype); |
| 4045 | break; |
| 4046 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4047 | |
| 4048 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | |
| 4052 | static void handle_auth_cb(struct hostapd_data *hapd, |
| 4053 | const struct ieee80211_mgmt *mgmt, |
| 4054 | size_t len, int ok) |
| 4055 | { |
| 4056 | u16 auth_alg, auth_transaction, status_code; |
| 4057 | struct sta_info *sta; |
| 4058 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4059 | sta = ap_get_sta(hapd, mgmt->da); |
| 4060 | if (!sta) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 4061 | wpa_printf(MSG_DEBUG, "handle_auth_cb: STA " MACSTR |
| 4062 | " not found", |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4063 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4064 | return; |
| 4065 | } |
| 4066 | |
| 4067 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 4068 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 4069 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 4070 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4071 | if (!ok) { |
| 4072 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 4073 | HOSTAPD_LEVEL_NOTICE, |
| 4074 | "did not acknowledge authentication response"); |
| 4075 | goto fail; |
| 4076 | } |
| 4077 | |
| 4078 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
| 4079 | wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)", |
| 4080 | (unsigned long) len); |
| 4081 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4082 | } |
| 4083 | |
| 4084 | if (status_code == WLAN_STATUS_SUCCESS && |
| 4085 | ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) || |
| 4086 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) { |
| 4087 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 4088 | HOSTAPD_LEVEL_INFO, "authenticated"); |
| 4089 | sta->flags |= WLAN_STA_AUTH; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4090 | if (sta->added_unassoc) |
| 4091 | hostapd_set_sta_flags(hapd, sta); |
| 4092 | return; |
| 4093 | } |
| 4094 | |
| 4095 | fail: |
| 4096 | if (status_code != WLAN_STATUS_SUCCESS && sta->added_unassoc) { |
| 4097 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 4098 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4099 | } |
| 4100 | } |
| 4101 | |
| 4102 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4103 | static void hostapd_set_wds_encryption(struct hostapd_data *hapd, |
| 4104 | struct sta_info *sta, |
| 4105 | char *ifname_wds) |
| 4106 | { |
| 4107 | int i; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 4108 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4109 | |
| 4110 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 4111 | return; |
| 4112 | |
| 4113 | for (i = 0; i < 4; i++) { |
| 4114 | if (ssid->wep.key[i] && |
| 4115 | hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i, |
| 4116 | i == ssid->wep.idx, NULL, 0, |
| 4117 | ssid->wep.key[i], ssid->wep.len[i])) { |
| 4118 | wpa_printf(MSG_WARNING, |
| 4119 | "Could not set WEP keys for WDS interface; %s", |
| 4120 | ifname_wds); |
| 4121 | break; |
| 4122 | } |
| 4123 | } |
| 4124 | } |
| 4125 | |
| 4126 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4127 | static void handle_assoc_cb(struct hostapd_data *hapd, |
| 4128 | const struct ieee80211_mgmt *mgmt, |
| 4129 | size_t len, int reassoc, int ok) |
| 4130 | { |
| 4131 | u16 status; |
| 4132 | struct sta_info *sta; |
| 4133 | int new_assoc = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4134 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4135 | sta = ap_get_sta(hapd, mgmt->da); |
| 4136 | if (!sta) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4137 | wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found", |
| 4138 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4139 | return; |
| 4140 | } |
| 4141 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4142 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) : |
| 4143 | sizeof(mgmt->u.assoc_resp))) { |
| 4144 | wpa_printf(MSG_INFO, |
| 4145 | "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)", |
| 4146 | reassoc, (unsigned long) len); |
| 4147 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4148 | return; |
| 4149 | } |
| 4150 | |
| 4151 | if (reassoc) |
| 4152 | status = le_to_host16(mgmt->u.reassoc_resp.status_code); |
| 4153 | else |
| 4154 | status = le_to_host16(mgmt->u.assoc_resp.status_code); |
| 4155 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4156 | if (!ok) { |
| 4157 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 4158 | HOSTAPD_LEVEL_DEBUG, |
| 4159 | "did not acknowledge association response"); |
| 4160 | sta->flags &= ~WLAN_STA_ASSOC_REQ_OK; |
| 4161 | /* The STA is added only in case of SUCCESS */ |
| 4162 | if (status == WLAN_STATUS_SUCCESS) |
| 4163 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 4164 | |
| 4165 | return; |
| 4166 | } |
| 4167 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4168 | if (status != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 4169 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4170 | |
| 4171 | /* Stop previous accounting session, if one is started, and allocate |
| 4172 | * new session id for the new session. */ |
| 4173 | accounting_sta_stop(hapd, sta); |
| 4174 | |
| 4175 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 4176 | HOSTAPD_LEVEL_INFO, |
| 4177 | "associated (aid %d)", |
| 4178 | sta->aid); |
| 4179 | |
| 4180 | if (sta->flags & WLAN_STA_ASSOC) |
| 4181 | new_assoc = 0; |
| 4182 | sta->flags |= WLAN_STA_ASSOC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4183 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4184 | if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && |
| 4185 | !hapd->conf->osen) || |
| 4186 | sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 4187 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 4188 | sta->auth_alg == WLAN_AUTH_FILS_PK || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4189 | sta->auth_alg == WLAN_AUTH_FT) { |
| 4190 | /* |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4191 | * Open, static WEP, FT protocol, or FILS; no separate |
| 4192 | * authorization step. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | */ |
| 4194 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4195 | } |
| 4196 | |
| 4197 | if (reassoc) |
| 4198 | mlme_reassociate_indication(hapd, sta); |
| 4199 | else |
| 4200 | mlme_associate_indication(hapd, sta); |
| 4201 | |
| 4202 | #ifdef CONFIG_IEEE80211W |
| 4203 | sta->sa_query_timed_out = 0; |
| 4204 | #endif /* CONFIG_IEEE80211W */ |
| 4205 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4206 | if (sta->eapol_sm == NULL) { |
| 4207 | /* |
| 4208 | * This STA does not use RADIUS server for EAP authentication, |
| 4209 | * so bind it to the selected VLAN interface now, since the |
| 4210 | * interface selection is not going to change anymore. |
| 4211 | */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 4212 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 4213 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4214 | } else if (sta->vlan_id) { |
| 4215 | /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 4216 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 4217 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | hostapd_set_sta_flags(hapd, sta); |
| 4221 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4222 | if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) { |
| 4223 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA " |
| 4224 | MACSTR " based on pending request", |
| 4225 | MAC2STR(sta->addr)); |
| 4226 | sta->pending_wds_enable = 0; |
| 4227 | sta->flags |= WLAN_STA_WDS; |
| 4228 | } |
| 4229 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4230 | if (sta->flags & WLAN_STA_WDS) { |
| 4231 | int ret; |
| 4232 | char ifname_wds[IFNAMSIZ + 1]; |
| 4233 | |
| 4234 | wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA " |
| 4235 | MACSTR " (aid %u)", |
| 4236 | MAC2STR(sta->addr), sta->aid); |
| 4237 | ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr, |
| 4238 | sta->aid, 1); |
| 4239 | if (!ret) |
| 4240 | hostapd_set_wds_encryption(hapd, sta, ifname_wds); |
| 4241 | } |
| 4242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4243 | if (sta->auth_alg == WLAN_AUTH_FT) |
| 4244 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); |
| 4245 | else |
| 4246 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); |
| 4247 | hapd->new_assoc_sta_cb(hapd, sta, !new_assoc); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4248 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 4249 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4250 | #ifdef CONFIG_FILS |
| 4251 | if ((sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 4252 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 4253 | sta->auth_alg == WLAN_AUTH_FILS_PK) && |
| 4254 | fils_set_tk(sta->wpa_sm) < 0) { |
| 4255 | wpa_printf(MSG_DEBUG, "FILS: TK configuration failed"); |
| 4256 | ap_sta_disconnect(hapd, sta, sta->addr, |
| 4257 | WLAN_REASON_UNSPECIFIED); |
| 4258 | return; |
| 4259 | } |
| 4260 | #endif /* CONFIG_FILS */ |
| 4261 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 4262 | if (sta->pending_eapol_rx) { |
| 4263 | struct os_reltime now, age; |
| 4264 | |
| 4265 | os_get_reltime(&now); |
| 4266 | os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age); |
| 4267 | if (age.sec == 0 && age.usec < 200000) { |
| 4268 | wpa_printf(MSG_DEBUG, |
| 4269 | "Process pending EAPOL frame that was received from " MACSTR " just before association notification", |
| 4270 | MAC2STR(sta->addr)); |
| 4271 | ieee802_1x_receive( |
| 4272 | hapd, mgmt->da, |
| 4273 | wpabuf_head(sta->pending_eapol_rx->buf), |
| 4274 | wpabuf_len(sta->pending_eapol_rx->buf)); |
| 4275 | } |
| 4276 | wpabuf_free(sta->pending_eapol_rx->buf); |
| 4277 | os_free(sta->pending_eapol_rx); |
| 4278 | sta->pending_eapol_rx = NULL; |
| 4279 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4283 | static void handle_deauth_cb(struct hostapd_data *hapd, |
| 4284 | const struct ieee80211_mgmt *mgmt, |
| 4285 | size_t len, int ok) |
| 4286 | { |
| 4287 | struct sta_info *sta; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4288 | if (is_multicast_ether_addr(mgmt->da)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4289 | return; |
| 4290 | sta = ap_get_sta(hapd, mgmt->da); |
| 4291 | if (!sta) { |
| 4292 | wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR |
| 4293 | " not found", MAC2STR(mgmt->da)); |
| 4294 | return; |
| 4295 | } |
| 4296 | if (ok) |
| 4297 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth", |
| 4298 | MAC2STR(sta->addr)); |
| 4299 | else |
| 4300 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 4301 | "deauth", MAC2STR(sta->addr)); |
| 4302 | |
| 4303 | ap_sta_deauth_cb(hapd, sta); |
| 4304 | } |
| 4305 | |
| 4306 | |
| 4307 | static void handle_disassoc_cb(struct hostapd_data *hapd, |
| 4308 | const struct ieee80211_mgmt *mgmt, |
| 4309 | size_t len, int ok) |
| 4310 | { |
| 4311 | struct sta_info *sta; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4312 | if (is_multicast_ether_addr(mgmt->da)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4313 | return; |
| 4314 | sta = ap_get_sta(hapd, mgmt->da); |
| 4315 | if (!sta) { |
| 4316 | wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR |
| 4317 | " not found", MAC2STR(mgmt->da)); |
| 4318 | return; |
| 4319 | } |
| 4320 | if (ok) |
| 4321 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc", |
| 4322 | MAC2STR(sta->addr)); |
| 4323 | else |
| 4324 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 4325 | "disassoc", MAC2STR(sta->addr)); |
| 4326 | |
| 4327 | ap_sta_disassoc_cb(hapd, sta); |
| 4328 | } |
| 4329 | |
| 4330 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4331 | static void handle_action_cb(struct hostapd_data *hapd, |
| 4332 | const struct ieee80211_mgmt *mgmt, |
| 4333 | size_t len, int ok) |
| 4334 | { |
| 4335 | struct sta_info *sta; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4336 | const struct rrm_measurement_report_element *report; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4337 | |
| 4338 | if (is_multicast_ether_addr(mgmt->da)) |
| 4339 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4340 | #ifdef CONFIG_DPP |
| 4341 | if (len >= IEEE80211_HDRLEN + 6 && |
| 4342 | mgmt->u.action.category == WLAN_ACTION_PUBLIC && |
| 4343 | mgmt->u.action.u.vs_public_action.action == |
| 4344 | WLAN_PA_VENDOR_SPECIFIC && |
| 4345 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 4346 | OUI_WFA && |
| 4347 | mgmt->u.action.u.vs_public_action.variable[0] == |
| 4348 | DPP_OUI_TYPE) { |
| 4349 | const u8 *pos, *end; |
| 4350 | |
| 4351 | pos = &mgmt->u.action.u.vs_public_action.variable[1]; |
| 4352 | end = ((const u8 *) mgmt) + len; |
| 4353 | hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok); |
| 4354 | return; |
| 4355 | } |
| 4356 | if (len >= IEEE80211_HDRLEN + 2 && |
| 4357 | mgmt->u.action.category == WLAN_ACTION_PUBLIC && |
| 4358 | (mgmt->u.action.u.public_action.action == |
| 4359 | WLAN_PA_GAS_INITIAL_REQ || |
| 4360 | mgmt->u.action.u.public_action.action == |
| 4361 | WLAN_PA_GAS_COMEBACK_REQ)) { |
| 4362 | const u8 *pos, *end; |
| 4363 | |
| 4364 | pos = mgmt->u.action.u.public_action.variable; |
| 4365 | end = ((const u8 *) mgmt) + len; |
| 4366 | gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok); |
| 4367 | return; |
| 4368 | } |
| 4369 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4370 | sta = ap_get_sta(hapd, mgmt->da); |
| 4371 | if (!sta) { |
| 4372 | wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR |
| 4373 | " not found", MAC2STR(mgmt->da)); |
| 4374 | return; |
| 4375 | } |
| 4376 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4377 | if (len < 24 + 5 + sizeof(*report)) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4378 | return; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4379 | report = (const struct rrm_measurement_report_element *) |
| 4380 | &mgmt->u.action.u.rrm.variable[2]; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4381 | if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT && |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4382 | mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST && |
| 4383 | report->eid == WLAN_EID_MEASURE_REQUEST && |
| 4384 | report->len >= 3 && |
| 4385 | report->type == MEASURE_TYPE_BEACON) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4386 | hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok); |
| 4387 | } |
| 4388 | |
| 4389 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4390 | /** |
| 4391 | * ieee802_11_mgmt_cb - Process management frame TX status callback |
| 4392 | * @hapd: hostapd BSS data structure (the BSS from which the management frame |
| 4393 | * was sent from) |
| 4394 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 4395 | * @len: length of frame data in octets |
| 4396 | * @stype: management frame subtype from frame control field |
| 4397 | * @ok: Whether the frame was ACK'ed |
| 4398 | */ |
| 4399 | void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 4400 | u16 stype, int ok) |
| 4401 | { |
| 4402 | const struct ieee80211_mgmt *mgmt; |
| 4403 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 4404 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4405 | #ifdef CONFIG_TESTING_OPTIONS |
| 4406 | if (hapd->ext_mgmt_frame_handling) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4407 | size_t hex_len = 2 * len + 1; |
| 4408 | char *hex = os_malloc(hex_len); |
| 4409 | |
| 4410 | if (hex) { |
| 4411 | wpa_snprintf_hex(hex, hex_len, buf, len); |
| 4412 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
| 4413 | "MGMT-TX-STATUS stype=%u ok=%d buf=%s", |
| 4414 | stype, ok, hex); |
| 4415 | os_free(hex); |
| 4416 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4417 | return; |
| 4418 | } |
| 4419 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4421 | switch (stype) { |
| 4422 | case WLAN_FC_STYPE_AUTH: |
| 4423 | wpa_printf(MSG_DEBUG, "mgmt::auth cb"); |
| 4424 | handle_auth_cb(hapd, mgmt, len, ok); |
| 4425 | break; |
| 4426 | case WLAN_FC_STYPE_ASSOC_RESP: |
| 4427 | wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb"); |
| 4428 | handle_assoc_cb(hapd, mgmt, len, 0, ok); |
| 4429 | break; |
| 4430 | case WLAN_FC_STYPE_REASSOC_RESP: |
| 4431 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb"); |
| 4432 | handle_assoc_cb(hapd, mgmt, len, 1, ok); |
| 4433 | break; |
| 4434 | case WLAN_FC_STYPE_PROBE_RESP: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4435 | wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4436 | break; |
| 4437 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4438 | wpa_printf(MSG_DEBUG, "mgmt::deauth cb"); |
| 4439 | handle_deauth_cb(hapd, mgmt, len, ok); |
| 4440 | break; |
| 4441 | case WLAN_FC_STYPE_DISASSOC: |
| 4442 | wpa_printf(MSG_DEBUG, "mgmt::disassoc cb"); |
| 4443 | handle_disassoc_cb(hapd, mgmt, len, ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4444 | break; |
| 4445 | case WLAN_FC_STYPE_ACTION: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4446 | wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4447 | handle_action_cb(hapd, mgmt, len, ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4448 | break; |
| 4449 | default: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4450 | wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4451 | break; |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | |
| 4456 | int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen) |
| 4457 | { |
| 4458 | /* TODO */ |
| 4459 | return 0; |
| 4460 | } |
| 4461 | |
| 4462 | |
| 4463 | int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 4464 | char *buf, size_t buflen) |
| 4465 | { |
| 4466 | /* TODO */ |
| 4467 | return 0; |
| 4468 | } |
| 4469 | |
| 4470 | |
| 4471 | void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr, |
| 4472 | const u8 *buf, size_t len, int ack) |
| 4473 | { |
| 4474 | struct sta_info *sta; |
| 4475 | struct hostapd_iface *iface = hapd->iface; |
| 4476 | |
| 4477 | sta = ap_get_sta(hapd, addr); |
| 4478 | if (sta == NULL && iface->num_bss > 1) { |
| 4479 | size_t j; |
| 4480 | for (j = 0; j < iface->num_bss; j++) { |
| 4481 | hapd = iface->bss[j]; |
| 4482 | sta = ap_get_sta(hapd, addr); |
| 4483 | if (sta) |
| 4484 | break; |
| 4485 | } |
| 4486 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4487 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4488 | return; |
| 4489 | if (sta->flags & WLAN_STA_PENDING_POLL) { |
| 4490 | wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending " |
| 4491 | "activity poll", MAC2STR(sta->addr), |
| 4492 | ack ? "ACKed" : "did not ACK"); |
| 4493 | if (ack) |
| 4494 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 4495 | } |
| 4496 | |
| 4497 | ieee802_1x_tx_status(hapd, sta, buf, len, ack); |
| 4498 | } |
| 4499 | |
| 4500 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4501 | void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst, |
| 4502 | const u8 *data, size_t len, int ack) |
| 4503 | { |
| 4504 | struct sta_info *sta; |
| 4505 | struct hostapd_iface *iface = hapd->iface; |
| 4506 | |
| 4507 | sta = ap_get_sta(hapd, dst); |
| 4508 | if (sta == NULL && iface->num_bss > 1) { |
| 4509 | size_t j; |
| 4510 | for (j = 0; j < iface->num_bss; j++) { |
| 4511 | hapd = iface->bss[j]; |
| 4512 | sta = ap_get_sta(hapd, dst); |
| 4513 | if (sta) |
| 4514 | break; |
| 4515 | } |
| 4516 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4517 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) { |
| 4518 | wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA " |
| 4519 | MACSTR " that is not currently associated", |
| 4520 | MAC2STR(dst)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4521 | return; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4522 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4523 | |
| 4524 | ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); |
| 4525 | } |
| 4526 | |
| 4527 | |
| 4528 | void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr) |
| 4529 | { |
| 4530 | struct sta_info *sta; |
| 4531 | struct hostapd_iface *iface = hapd->iface; |
| 4532 | |
| 4533 | sta = ap_get_sta(hapd, addr); |
| 4534 | if (sta == NULL && iface->num_bss > 1) { |
| 4535 | size_t j; |
| 4536 | for (j = 0; j < iface->num_bss; j++) { |
| 4537 | hapd = iface->bss[j]; |
| 4538 | sta = ap_get_sta(hapd, addr); |
| 4539 | if (sta) |
| 4540 | break; |
| 4541 | } |
| 4542 | } |
| 4543 | if (sta == NULL) |
| 4544 | return; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4545 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR, |
| 4546 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4547 | if (!(sta->flags & WLAN_STA_PENDING_POLL)) |
| 4548 | return; |
| 4549 | |
| 4550 | wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending " |
| 4551 | "activity poll", MAC2STR(sta->addr)); |
| 4552 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 4553 | } |
| 4554 | |
| 4555 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4556 | void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src, |
| 4557 | int wds) |
| 4558 | { |
| 4559 | struct sta_info *sta; |
| 4560 | |
| 4561 | sta = ap_get_sta(hapd, src); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4562 | if (sta && |
| 4563 | ((sta->flags & WLAN_STA_ASSOC) || |
| 4564 | ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4565 | if (!hapd->conf->wds_sta) |
| 4566 | return; |
| 4567 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4568 | if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) == |
| 4569 | WLAN_STA_ASSOC_REQ_OK) { |
| 4570 | wpa_printf(MSG_DEBUG, |
| 4571 | "Postpone 4-address WDS mode enabling for STA " |
| 4572 | MACSTR " since TX status for AssocResp is not yet known", |
| 4573 | MAC2STR(sta->addr)); |
| 4574 | sta->pending_wds_enable = 1; |
| 4575 | return; |
| 4576 | } |
| 4577 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4578 | if (wds && !(sta->flags & WLAN_STA_WDS)) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4579 | int ret; |
| 4580 | char ifname_wds[IFNAMSIZ + 1]; |
| 4581 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4582 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for " |
| 4583 | "STA " MACSTR " (aid %u)", |
| 4584 | MAC2STR(sta->addr), sta->aid); |
| 4585 | sta->flags |= WLAN_STA_WDS; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4586 | ret = hostapd_set_wds_sta(hapd, ifname_wds, |
| 4587 | sta->addr, sta->aid, 1); |
| 4588 | if (!ret) |
| 4589 | hostapd_set_wds_encryption(hapd, sta, |
| 4590 | ifname_wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4591 | } |
| 4592 | return; |
| 4593 | } |
| 4594 | |
| 4595 | wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA " |
| 4596 | MACSTR, MAC2STR(src)); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4597 | if (is_multicast_ether_addr(src)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4598 | /* Broadcast bit set in SA?! Ignore the frame silently. */ |
| 4599 | return; |
| 4600 | } |
| 4601 | |
| 4602 | if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) { |
| 4603 | wpa_printf(MSG_DEBUG, "Association Response to the STA has " |
| 4604 | "already been sent, but no TX status yet known - " |
| 4605 | "ignore Class 3 frame issue with " MACSTR, |
| 4606 | MAC2STR(src)); |
| 4607 | return; |
| 4608 | } |
| 4609 | |
| 4610 | if (sta && (sta->flags & WLAN_STA_AUTH)) |
| 4611 | hostapd_drv_sta_disassoc( |
| 4612 | hapd, src, |
| 4613 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 4614 | else |
| 4615 | hostapd_drv_sta_deauth( |
| 4616 | hapd, src, |
| 4617 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 4618 | } |
| 4619 | |
| 4620 | |
| 4621 | #endif /* CONFIG_NATIVE_WINDOWS */ |