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