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