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" |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 27 | #include "common/wpa_ctrl.h" |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 28 | #include "common/ptksa_cache.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 29 | #include "radius/radius.h" |
| 30 | #include "radius/radius_client.h" |
| 31 | #include "p2p/p2p.h" |
| 32 | #include "wps/wps.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 33 | #include "fst/fst.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "hostapd.h" |
| 35 | #include "beacon.h" |
| 36 | #include "ieee802_11_auth.h" |
| 37 | #include "sta_info.h" |
| 38 | #include "ieee802_1x.h" |
| 39 | #include "wpa_auth.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 40 | #include "pmksa_cache_auth.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | #include "wmm.h" |
| 42 | #include "ap_list.h" |
| 43 | #include "accounting.h" |
| 44 | #include "ap_config.h" |
| 45 | #include "ap_mlme.h" |
| 46 | #include "p2p_hostapd.h" |
| 47 | #include "ap_drv_ops.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 48 | #include "wnm_ap.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 49 | #include "hw_features.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 50 | #include "ieee802_11.h" |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 51 | #include "dfs.h" |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 52 | #include "mbo_ap.h" |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 53 | #include "rrm.h" |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 54 | #include "taxonomy.h" |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 55 | #include "fils_hlp.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 56 | #include "dpp_hostapd.h" |
| 57 | #include "gas_query_ap.h" |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 58 | #include "comeback_token.h" |
| 59 | #include "pasn/pasn_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 60 | |
| 61 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 62 | #ifdef CONFIG_FILS |
| 63 | static struct wpabuf * |
| 64 | prepare_auth_resp_fils(struct hostapd_data *hapd, |
| 65 | struct sta_info *sta, u16 *resp, |
| 66 | struct rsn_pmksa_cache_entry *pmksa, |
| 67 | struct wpabuf *erp_resp, |
| 68 | const u8 *msk, size_t msk_len, |
| 69 | int *is_pub); |
| 70 | #endif /* CONFIG_FILS */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 71 | |
| 72 | #ifdef CONFIG_PASN |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 73 | #ifdef CONFIG_FILS |
| 74 | |
| 75 | static void pasn_fils_auth_resp(struct hostapd_data *hapd, |
| 76 | struct sta_info *sta, u16 status, |
| 77 | struct wpabuf *erp_resp, |
| 78 | const u8 *msk, size_t msk_len); |
| 79 | |
| 80 | #endif /* CONFIG_FILS */ |
| 81 | #endif /* CONFIG_PASN */ |
| 82 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 83 | static void handle_auth(struct hostapd_data *hapd, |
| 84 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 85 | int rssi, int from_queue); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 86 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 87 | |
| 88 | u8 * hostapd_eid_multi_ap(struct hostapd_data *hapd, u8 *eid) |
| 89 | { |
| 90 | u8 multi_ap_val = 0; |
| 91 | |
| 92 | if (!hapd->conf->multi_ap) |
| 93 | return eid; |
| 94 | if (hapd->conf->multi_ap & BACKHAUL_BSS) |
| 95 | multi_ap_val |= MULTI_AP_BACKHAUL_BSS; |
| 96 | if (hapd->conf->multi_ap & FRONTHAUL_BSS) |
| 97 | multi_ap_val |= MULTI_AP_FRONTHAUL_BSS; |
| 98 | |
| 99 | return eid + add_multi_ap_ie(eid, 9, multi_ap_val); |
| 100 | } |
| 101 | |
| 102 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 103 | u8 * hostapd_eid_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 104 | { |
| 105 | u8 *pos = eid; |
| 106 | int i, num, count; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 107 | int h2e_required; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 108 | |
| 109 | if (hapd->iface->current_rates == NULL) |
| 110 | return eid; |
| 111 | |
| 112 | *pos++ = WLAN_EID_SUPP_RATES; |
| 113 | num = hapd->iface->num_rates; |
| 114 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 115 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 116 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 117 | num++; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 118 | #ifdef CONFIG_IEEE80211AX |
| 119 | if (hapd->iconf->ieee80211ax && hapd->iconf->require_he) |
| 120 | num++; |
| 121 | #endif /* CONFIG_IEEE80211AX */ |
| 122 | h2e_required = (hapd->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 123 | hostapd_sae_pw_id_in_use(hapd->conf) == 2) && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 124 | hapd->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 125 | wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt); |
| 126 | if (h2e_required) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 127 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 128 | if (num > 8) { |
| 129 | /* rest of the rates are encoded in Extended supported |
| 130 | * rates element */ |
| 131 | num = 8; |
| 132 | } |
| 133 | |
| 134 | *pos++ = num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 135 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num; |
| 136 | i++) { |
| 137 | count++; |
| 138 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 139 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 140 | *pos |= 0x80; |
| 141 | pos++; |
| 142 | } |
| 143 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 144 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && count < 8) { |
| 145 | count++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 146 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && count < 8) { |
| 150 | count++; |
| 151 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 152 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 153 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 154 | #ifdef CONFIG_IEEE80211AX |
| 155 | if (hapd->iconf->ieee80211ax && hapd->iconf->require_he && count < 8) { |
| 156 | count++; |
| 157 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY; |
| 158 | } |
| 159 | #endif /* CONFIG_IEEE80211AX */ |
| 160 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 161 | if (h2e_required && count < 8) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 162 | count++; |
| 163 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY; |
| 164 | } |
| 165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 166 | return pos; |
| 167 | } |
| 168 | |
| 169 | |
| 170 | u8 * hostapd_eid_ext_supp_rates(struct hostapd_data *hapd, u8 *eid) |
| 171 | { |
| 172 | u8 *pos = eid; |
| 173 | int i, num, count; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 174 | int h2e_required; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 175 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 176 | hapd->conf->xrates_supported = false; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 177 | if (hapd->iface->current_rates == NULL) |
| 178 | return eid; |
| 179 | |
| 180 | num = hapd->iface->num_rates; |
| 181 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) |
| 182 | num++; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 183 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) |
| 184 | num++; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 185 | #ifdef CONFIG_IEEE80211AX |
| 186 | if (hapd->iconf->ieee80211ax && hapd->iconf->require_he) |
| 187 | num++; |
| 188 | #endif /* CONFIG_IEEE80211AX */ |
| 189 | h2e_required = (hapd->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 190 | hostapd_sae_pw_id_in_use(hapd->conf) == 2) && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 191 | hapd->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 192 | wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt); |
| 193 | if (h2e_required) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 194 | num++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 195 | if (num <= 8) |
| 196 | return eid; |
| 197 | num -= 8; |
| 198 | |
| 199 | *pos++ = WLAN_EID_EXT_SUPP_RATES; |
| 200 | *pos++ = num; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 201 | for (i = 0, count = 0; i < hapd->iface->num_rates && count < num + 8; |
| 202 | i++) { |
| 203 | count++; |
| 204 | if (count <= 8) |
| 205 | continue; /* already in SuppRates IE */ |
| 206 | *pos = hapd->iface->current_rates[i].rate / 5; |
| 207 | if (hapd->iface->current_rates[i].flags & HOSTAPD_RATE_BASIC) |
| 208 | *pos |= 0x80; |
| 209 | pos++; |
| 210 | } |
| 211 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 212 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht) { |
| 213 | count++; |
| 214 | if (count > 8) |
| 215 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY; |
| 216 | } |
| 217 | |
| 218 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht) { |
| 219 | count++; |
| 220 | if (count > 8) |
| 221 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY; |
| 222 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 223 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 224 | #ifdef CONFIG_IEEE80211AX |
| 225 | if (hapd->iconf->ieee80211ax && hapd->iconf->require_he) { |
| 226 | count++; |
| 227 | if (count > 8) |
| 228 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY; |
| 229 | } |
| 230 | #endif /* CONFIG_IEEE80211AX */ |
| 231 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 232 | if (h2e_required) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 233 | count++; |
| 234 | if (count > 8) |
| 235 | *pos++ = 0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY; |
| 236 | } |
| 237 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 238 | hapd->conf->xrates_supported = true; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 239 | return pos; |
| 240 | } |
| 241 | |
| 242 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 243 | u8 * hostapd_eid_rm_enabled_capab(struct hostapd_data *hapd, u8 *eid, |
| 244 | size_t len) |
| 245 | { |
| 246 | size_t i; |
| 247 | |
| 248 | for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) { |
| 249 | if (hapd->conf->radio_measurements[i]) |
| 250 | break; |
| 251 | } |
| 252 | |
| 253 | if (i == RRM_CAPABILITIES_IE_LEN || len < 2 + RRM_CAPABILITIES_IE_LEN) |
| 254 | return eid; |
| 255 | |
| 256 | *eid++ = WLAN_EID_RRM_ENABLED_CAPABILITIES; |
| 257 | *eid++ = RRM_CAPABILITIES_IE_LEN; |
| 258 | os_memcpy(eid, hapd->conf->radio_measurements, RRM_CAPABILITIES_IE_LEN); |
| 259 | |
| 260 | return eid + RRM_CAPABILITIES_IE_LEN; |
| 261 | } |
| 262 | |
| 263 | |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 264 | u16 hostapd_own_capab_info(struct hostapd_data *hapd) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 265 | { |
| 266 | int capab = WLAN_CAPABILITY_ESS; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 267 | int privacy = 0; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 268 | int dfs; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 269 | int i; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 270 | |
| 271 | /* Check if any of configured channels require DFS */ |
| 272 | dfs = hostapd_is_dfs_required(hapd->iface); |
| 273 | if (dfs < 0) { |
| 274 | wpa_printf(MSG_WARNING, "Failed to check if DFS is required; ret=%d", |
| 275 | dfs); |
| 276 | dfs = 0; |
| 277 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 278 | |
| 279 | if (hapd->iface->num_sta_no_short_preamble == 0 && |
| 280 | hapd->iconf->preamble == SHORT_PREAMBLE) |
| 281 | capab |= WLAN_CAPABILITY_SHORT_PREAMBLE; |
| 282 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 283 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 284 | privacy = hapd->conf->ssid.wep.keys_set; |
| 285 | |
| 286 | if (hapd->conf->ieee802_1x && |
| 287 | (hapd->conf->default_wep_key_len || |
| 288 | hapd->conf->individual_wep_key_len)) |
| 289 | privacy = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 290 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | |
| 292 | if (hapd->conf->wpa) |
| 293 | privacy = 1; |
| 294 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 295 | #ifdef CONFIG_HS20 |
| 296 | if (hapd->conf->osen) |
| 297 | privacy = 1; |
| 298 | #endif /* CONFIG_HS20 */ |
| 299 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 300 | if (privacy) |
| 301 | capab |= WLAN_CAPABILITY_PRIVACY; |
| 302 | |
| 303 | if (hapd->iface->current_mode && |
| 304 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G && |
| 305 | hapd->iface->num_sta_no_short_slot_time == 0) |
| 306 | capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME; |
| 307 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 308 | /* |
| 309 | * Currently, Spectrum Management capability bit is set when directly |
| 310 | * requested in configuration by spectrum_mgmt_required or when AP is |
| 311 | * running on DFS channel. |
| 312 | * TODO: Also consider driver support for TPC to set Spectrum Mgmt bit |
| 313 | */ |
| 314 | if (hapd->iface->current_mode && |
| 315 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211A && |
| 316 | (hapd->iconf->spectrum_mgmt_required || dfs)) |
| 317 | capab |= WLAN_CAPABILITY_SPECTRUM_MGMT; |
| 318 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 319 | for (i = 0; i < RRM_CAPABILITIES_IE_LEN; i++) { |
| 320 | if (hapd->conf->radio_measurements[i]) { |
| 321 | capab |= IEEE80211_CAP_RRM; |
| 322 | break; |
| 323 | } |
| 324 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 326 | return capab; |
| 327 | } |
| 328 | |
| 329 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 330 | #ifdef CONFIG_WEP |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 331 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 332 | static u16 auth_shared_key(struct hostapd_data *hapd, struct sta_info *sta, |
| 333 | u16 auth_transaction, const u8 *challenge, |
| 334 | int iswep) |
| 335 | { |
| 336 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 337 | HOSTAPD_LEVEL_DEBUG, |
| 338 | "authentication (shared key, transaction %d)", |
| 339 | auth_transaction); |
| 340 | |
| 341 | if (auth_transaction == 1) { |
| 342 | if (!sta->challenge) { |
| 343 | /* Generate a pseudo-random challenge */ |
| 344 | u8 key[8]; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 345 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | sta->challenge = os_zalloc(WLAN_AUTH_CHALLENGE_LEN); |
| 347 | if (sta->challenge == NULL) |
| 348 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 349 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 350 | if (os_get_random(key, sizeof(key)) < 0) { |
| 351 | os_free(sta->challenge); |
| 352 | sta->challenge = NULL; |
| 353 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 354 | } |
| 355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 356 | rc4_skip(key, sizeof(key), 0, |
| 357 | sta->challenge, WLAN_AUTH_CHALLENGE_LEN); |
| 358 | } |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | if (auth_transaction != 3) |
| 363 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 364 | |
| 365 | /* Transaction 3 */ |
| 366 | if (!iswep || !sta->challenge || !challenge || |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 367 | os_memcmp_const(sta->challenge, challenge, |
| 368 | WLAN_AUTH_CHALLENGE_LEN)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 369 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 370 | HOSTAPD_LEVEL_INFO, |
| 371 | "shared key authentication - invalid " |
| 372 | "challenge-response"); |
| 373 | return WLAN_STATUS_CHALLENGE_FAIL; |
| 374 | } |
| 375 | |
| 376 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 377 | HOSTAPD_LEVEL_DEBUG, |
| 378 | "authentication OK (shared key)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 379 | sta->flags |= WLAN_STA_AUTH; |
| 380 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 381 | os_free(sta->challenge); |
| 382 | sta->challenge = NULL; |
| 383 | |
| 384 | return 0; |
| 385 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 386 | #endif /* CONFIG_NO_RC4 */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 387 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 388 | |
| 389 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 390 | 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] | 391 | const u8 *dst, const u8 *bssid, |
| 392 | u16 auth_alg, u16 auth_transaction, u16 resp, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 393 | const u8 *ies, size_t ies_len, const char *dbg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 394 | { |
| 395 | struct ieee80211_mgmt *reply; |
| 396 | u8 *buf; |
| 397 | size_t rlen; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 398 | int reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 399 | |
| 400 | rlen = IEEE80211_HDRLEN + sizeof(reply->u.auth) + ies_len; |
| 401 | buf = os_zalloc(rlen); |
| 402 | if (buf == NULL) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 403 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 404 | |
| 405 | reply = (struct ieee80211_mgmt *) buf; |
| 406 | reply->frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 407 | WLAN_FC_STYPE_AUTH); |
| 408 | os_memcpy(reply->da, dst, ETH_ALEN); |
| 409 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 410 | os_memcpy(reply->bssid, bssid, ETH_ALEN); |
| 411 | |
| 412 | reply->u.auth.auth_alg = host_to_le16(auth_alg); |
| 413 | reply->u.auth.auth_transaction = host_to_le16(auth_transaction); |
| 414 | reply->u.auth.status_code = host_to_le16(resp); |
| 415 | |
| 416 | if (ies && ies_len) |
| 417 | os_memcpy(reply->u.auth.variable, ies, ies_len); |
| 418 | |
| 419 | wpa_printf(MSG_DEBUG, "authentication reply: STA=" MACSTR |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 420 | " 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] | 421 | MAC2STR(dst), auth_alg, auth_transaction, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 422 | resp, (unsigned long) ies_len, dbg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 423 | #ifdef CONFIG_TESTING_OPTIONS |
| 424 | #ifdef CONFIG_SAE |
| 425 | if (hapd->conf->sae_confirm_immediate == 2 && |
| 426 | auth_alg == WLAN_AUTH_SAE) { |
| 427 | if (auth_transaction == 1 && sta && |
| 428 | (resp == WLAN_STATUS_SUCCESS || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 429 | resp == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 430 | resp == WLAN_STATUS_SAE_PK)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 431 | wpa_printf(MSG_DEBUG, |
| 432 | "TESTING: Postpone SAE Commit transmission until Confirm is ready"); |
| 433 | os_free(sta->sae_postponed_commit); |
| 434 | sta->sae_postponed_commit = buf; |
| 435 | sta->sae_postponed_commit_len = rlen; |
| 436 | return WLAN_STATUS_SUCCESS; |
| 437 | } |
| 438 | |
| 439 | if (auth_transaction == 2 && sta && sta->sae_postponed_commit) { |
| 440 | wpa_printf(MSG_DEBUG, |
| 441 | "TESTING: Send postponed SAE Commit first, immediately followed by SAE Confirm"); |
| 442 | if (hostapd_drv_send_mlme(hapd, |
| 443 | sta->sae_postponed_commit, |
| 444 | sta->sae_postponed_commit_len, |
| 445 | 0, NULL, 0, 0) < 0) |
| 446 | wpa_printf(MSG_INFO, "send_auth_reply: send failed"); |
| 447 | os_free(sta->sae_postponed_commit); |
| 448 | sta->sae_postponed_commit = NULL; |
| 449 | sta->sae_postponed_commit_len = 0; |
| 450 | } |
| 451 | } |
| 452 | #endif /* CONFIG_SAE */ |
| 453 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 454 | 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] | 455 | wpa_printf(MSG_INFO, "send_auth_reply: send failed"); |
| 456 | else |
| 457 | reply_res = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 458 | |
| 459 | os_free(buf); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 460 | |
| 461 | return reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 465 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 466 | static void handle_auth_ft_finish(void *ctx, const u8 *dst, const u8 *bssid, |
| 467 | u16 auth_transaction, u16 status, |
| 468 | const u8 *ies, size_t ies_len) |
| 469 | { |
| 470 | struct hostapd_data *hapd = ctx; |
| 471 | struct sta_info *sta; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 472 | int reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 473 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 474 | reply_res = send_auth_reply(hapd, NULL, dst, bssid, WLAN_AUTH_FT, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 475 | auth_transaction, status, ies, ies_len, |
| 476 | "auth-ft-finish"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 477 | |
| 478 | sta = ap_get_sta(hapd, dst); |
| 479 | if (sta == NULL) |
| 480 | return; |
| 481 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 482 | if (sta->added_unassoc && (reply_res != WLAN_STATUS_SUCCESS || |
| 483 | status != WLAN_STATUS_SUCCESS)) { |
| 484 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 485 | sta->added_unassoc = 0; |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | if (status != WLAN_STATUS_SUCCESS) |
| 490 | return; |
| 491 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 492 | hostapd_logger(hapd, dst, HOSTAPD_MODULE_IEEE80211, |
| 493 | HOSTAPD_LEVEL_DEBUG, "authentication OK (FT)"); |
| 494 | sta->flags |= WLAN_STA_AUTH; |
| 495 | mlme_authenticate_indication(hapd, sta); |
| 496 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 497 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 498 | |
| 499 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 500 | #ifdef CONFIG_SAE |
| 501 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 502 | static void sae_set_state(struct sta_info *sta, enum sae_state state, |
| 503 | const char *reason) |
| 504 | { |
| 505 | wpa_printf(MSG_DEBUG, "SAE: State %s -> %s for peer " MACSTR " (%s)", |
| 506 | sae_state_txt(sta->sae->state), sae_state_txt(state), |
| 507 | MAC2STR(sta->addr), reason); |
| 508 | sta->sae->state = state; |
| 509 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 510 | |
| 511 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 512 | static const char * sae_get_password(struct hostapd_data *hapd, |
| 513 | struct sta_info *sta, |
| 514 | const char *rx_id, |
| 515 | struct sae_password_entry **pw_entry, |
| 516 | struct sae_pt **s_pt, |
| 517 | const struct sae_pk **s_pk) |
| 518 | { |
| 519 | const char *password = NULL; |
| 520 | struct sae_password_entry *pw; |
| 521 | struct sae_pt *pt = NULL; |
| 522 | const struct sae_pk *pk = NULL; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 523 | struct hostapd_sta_wpa_psk_short *psk = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 524 | |
| 525 | for (pw = hapd->conf->sae_passwords; pw; pw = pw->next) { |
| 526 | if (!is_broadcast_ether_addr(pw->peer_addr) && |
| 527 | os_memcmp(pw->peer_addr, sta->addr, ETH_ALEN) != 0) |
| 528 | continue; |
| 529 | if ((rx_id && !pw->identifier) || (!rx_id && pw->identifier)) |
| 530 | continue; |
| 531 | if (rx_id && pw->identifier && |
| 532 | os_strcmp(rx_id, pw->identifier) != 0) |
| 533 | continue; |
| 534 | password = pw->password; |
| 535 | pt = pw->pt; |
| 536 | if (!(hapd->conf->mesh & MESH_ENABLED)) |
| 537 | pk = pw->pk; |
| 538 | break; |
| 539 | } |
| 540 | if (!password) { |
| 541 | password = hapd->conf->ssid.wpa_passphrase; |
| 542 | pt = hapd->conf->ssid.pt; |
| 543 | } |
| 544 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 545 | if (!password) { |
| 546 | for (psk = sta->psk; psk; psk = psk->next) { |
| 547 | if (psk->is_passphrase) { |
| 548 | password = psk->passphrase; |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 554 | if (pw_entry) |
| 555 | *pw_entry = pw; |
| 556 | if (s_pt) |
| 557 | *s_pt = pt; |
| 558 | if (s_pk) |
| 559 | *s_pk = pk; |
| 560 | |
| 561 | return password; |
| 562 | } |
| 563 | |
| 564 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 565 | static struct wpabuf * auth_build_sae_commit(struct hostapd_data *hapd, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 566 | struct sta_info *sta, int update, |
| 567 | int status_code) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 568 | { |
| 569 | struct wpabuf *buf; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 570 | const char *password = NULL; |
| 571 | struct sae_password_entry *pw; |
| 572 | const char *rx_id = NULL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 573 | int use_pt = 0; |
| 574 | struct sae_pt *pt = NULL; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 575 | const struct sae_pk *pk = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 576 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 577 | if (sta->sae->tmp) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 578 | rx_id = sta->sae->tmp->pw_id; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 579 | use_pt = sta->sae->h2e; |
| 580 | #ifdef CONFIG_SAE_PK |
| 581 | os_memcpy(sta->sae->tmp->own_addr, hapd->own_addr, ETH_ALEN); |
| 582 | os_memcpy(sta->sae->tmp->peer_addr, sta->addr, ETH_ALEN); |
| 583 | #endif /* CONFIG_SAE_PK */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 586 | if (rx_id && hapd->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 587 | use_pt = 1; |
| 588 | else if (status_code == WLAN_STATUS_SUCCESS) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 589 | use_pt = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 590 | else if (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 591 | status_code == WLAN_STATUS_SAE_PK) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 592 | use_pt = 1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 593 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 594 | password = sae_get_password(hapd, sta, rx_id, &pw, &pt, &pk); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 595 | if (!password || (use_pt && !pt)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 596 | wpa_printf(MSG_DEBUG, "SAE: No password available"); |
| 597 | return NULL; |
| 598 | } |
| 599 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 600 | if (update && use_pt && |
| 601 | sae_prepare_commit_pt(sta->sae, pt, hapd->own_addr, sta->addr, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 602 | NULL, pk) < 0) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 603 | return NULL; |
| 604 | |
| 605 | if (update && !use_pt && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 606 | sae_prepare_commit(hapd->own_addr, sta->addr, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 607 | (u8 *) password, os_strlen(password), |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 608 | sta->sae) < 0) { |
| 609 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); |
| 610 | return NULL; |
| 611 | } |
| 612 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 613 | if (pw && pw->vlan_id) { |
| 614 | if (!sta->sae->tmp) { |
| 615 | wpa_printf(MSG_INFO, |
| 616 | "SAE: No temporary data allocated - cannot store VLAN ID"); |
| 617 | return NULL; |
| 618 | } |
| 619 | sta->sae->tmp->vlan_id = pw->vlan_id; |
| 620 | } |
| 621 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 622 | buf = wpabuf_alloc(SAE_COMMIT_MAX_LEN + |
| 623 | (rx_id ? 3 + os_strlen(rx_id) : 0)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 624 | if (buf && |
| 625 | sae_write_commit(sta->sae, buf, sta->sae->tmp ? |
| 626 | sta->sae->tmp->anti_clogging_token : NULL, |
| 627 | rx_id) < 0) { |
| 628 | wpabuf_free(buf); |
| 629 | buf = NULL; |
| 630 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 631 | |
| 632 | return buf; |
| 633 | } |
| 634 | |
| 635 | |
| 636 | static struct wpabuf * auth_build_sae_confirm(struct hostapd_data *hapd, |
| 637 | struct sta_info *sta) |
| 638 | { |
| 639 | struct wpabuf *buf; |
| 640 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 641 | buf = wpabuf_alloc(SAE_CONFIRM_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 642 | if (buf == NULL) |
| 643 | return NULL; |
| 644 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 645 | #ifdef CONFIG_SAE_PK |
| 646 | #ifdef CONFIG_TESTING_OPTIONS |
| 647 | if (sta->sae->tmp) |
| 648 | sta->sae->tmp->omit_pk_elem = hapd->conf->sae_pk_omit; |
| 649 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 650 | #endif /* CONFIG_SAE_PK */ |
| 651 | |
| 652 | if (sae_write_confirm(sta->sae, buf) < 0) { |
| 653 | wpabuf_free(buf); |
| 654 | return NULL; |
| 655 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 656 | |
| 657 | return buf; |
| 658 | } |
| 659 | |
| 660 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 661 | static int auth_sae_send_commit(struct hostapd_data *hapd, |
| 662 | struct sta_info *sta, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 663 | const u8 *bssid, int update, int status_code) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 664 | { |
| 665 | struct wpabuf *data; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 666 | int reply_res; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 667 | u16 status; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 668 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 669 | data = auth_build_sae_commit(hapd, sta, update, status_code); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 670 | if (!data && sta->sae->tmp && sta->sae->tmp->pw_id) |
| 671 | return WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 672 | if (data == NULL) |
| 673 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 674 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 675 | if (sta->sae->tmp && sta->sae->pk) |
| 676 | status = WLAN_STATUS_SAE_PK; |
| 677 | else if (sta->sae->tmp && sta->sae->h2e) |
| 678 | status = WLAN_STATUS_SAE_HASH_TO_ELEMENT; |
| 679 | else |
| 680 | status = WLAN_STATUS_SUCCESS; |
| 681 | #ifdef CONFIG_TESTING_OPTIONS |
| 682 | if (hapd->conf->sae_commit_status >= 0 && |
| 683 | hapd->conf->sae_commit_status != status) { |
| 684 | wpa_printf(MSG_INFO, |
| 685 | "TESTING: Override SAE commit status code %u --> %d", |
| 686 | status, hapd->conf->sae_commit_status); |
| 687 | status = hapd->conf->sae_commit_status; |
| 688 | } |
| 689 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 690 | reply_res = send_auth_reply(hapd, sta, sta->addr, bssid, |
| 691 | WLAN_AUTH_SAE, 1, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 692 | status, wpabuf_head(data), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 693 | wpabuf_len(data), "sae-send-commit"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 694 | |
| 695 | wpabuf_free(data); |
| 696 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 697 | return reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | |
| 701 | static int auth_sae_send_confirm(struct hostapd_data *hapd, |
| 702 | struct sta_info *sta, |
| 703 | const u8 *bssid) |
| 704 | { |
| 705 | struct wpabuf *data; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 706 | int reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 707 | |
| 708 | data = auth_build_sae_confirm(hapd, sta); |
| 709 | if (data == NULL) |
| 710 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 711 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 712 | reply_res = send_auth_reply(hapd, sta, sta->addr, bssid, |
| 713 | WLAN_AUTH_SAE, 2, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 714 | WLAN_STATUS_SUCCESS, wpabuf_head(data), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 715 | wpabuf_len(data), "sae-send-confirm"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 716 | |
| 717 | wpabuf_free(data); |
| 718 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 719 | return reply_res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 720 | } |
| 721 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 722 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 723 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 724 | |
| 725 | #if defined(CONFIG_SAE) || defined(CONFIG_PASN) |
| 726 | |
| 727 | static int use_anti_clogging(struct hostapd_data *hapd) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 728 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 729 | struct sta_info *sta; |
| 730 | unsigned int open = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 731 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 732 | if (hapd->conf->anti_clogging_threshold == 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 733 | return 1; |
| 734 | |
| 735 | for (sta = hapd->sta_list; sta; sta = sta->next) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 736 | #ifdef CONFIG_SAE |
| 737 | if (sta->sae && |
| 738 | (sta->sae->state == SAE_COMMITTED || |
| 739 | sta->sae->state == SAE_CONFIRMED)) |
| 740 | open++; |
| 741 | #endif /* CONFIG_SAE */ |
| 742 | #ifdef CONFIG_PASN |
| 743 | if (sta->pasn && sta->pasn->ecdh) |
| 744 | open++; |
| 745 | #endif /* CONFIG_PASN */ |
| 746 | if (open >= hapd->conf->anti_clogging_threshold) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 747 | return 1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 748 | } |
| 749 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 750 | #ifdef CONFIG_SAE |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 751 | /* In addition to already existing open SAE sessions, check whether |
| 752 | * there are enough pending commit messages in the processing queue to |
| 753 | * potentially result in too many open sessions. */ |
| 754 | if (open + dl_list_len(&hapd->sae_commit_queue) >= |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 755 | hapd->conf->anti_clogging_threshold) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 756 | return 1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 757 | #endif /* CONFIG_SAE */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 758 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 759 | return 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 760 | } |
| 761 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 762 | #endif /* defined(CONFIG_SAE) || defined(CONFIG_PASN) */ |
| 763 | |
| 764 | |
| 765 | #ifdef CONFIG_SAE |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 766 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 767 | 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] | 768 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 769 | if (sta->sae->sync > hapd->conf->sae_sync) { |
| 770 | sae_set_state(sta, SAE_NOTHING, "Sync > dot11RSNASAESync"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 771 | sta->sae->sync = 0; |
| 772 | return -1; |
| 773 | } |
| 774 | return 0; |
| 775 | } |
| 776 | |
| 777 | |
| 778 | static void auth_sae_retransmit_timer(void *eloop_ctx, void *eloop_data) |
| 779 | { |
| 780 | struct hostapd_data *hapd = eloop_ctx; |
| 781 | struct sta_info *sta = eloop_data; |
| 782 | int ret; |
| 783 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 784 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 785 | return; |
| 786 | sta->sae->sync++; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 787 | wpa_printf(MSG_DEBUG, "SAE: Auth SAE retransmit timer for " MACSTR |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 788 | " (sync=%d state=%s)", |
| 789 | MAC2STR(sta->addr), sta->sae->sync, |
| 790 | sae_state_txt(sta->sae->state)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 791 | |
| 792 | switch (sta->sae->state) { |
| 793 | case SAE_COMMITTED: |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 794 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0, -1); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 795 | eloop_register_timeout(0, |
| 796 | hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 797 | auth_sae_retransmit_timer, hapd, sta); |
| 798 | break; |
| 799 | case SAE_CONFIRMED: |
| 800 | ret = auth_sae_send_confirm(hapd, sta, hapd->own_addr); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 801 | eloop_register_timeout(0, |
| 802 | hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 803 | auth_sae_retransmit_timer, hapd, sta); |
| 804 | break; |
| 805 | default: |
| 806 | ret = -1; |
| 807 | break; |
| 808 | } |
| 809 | |
| 810 | if (ret != WLAN_STATUS_SUCCESS) |
| 811 | wpa_printf(MSG_INFO, "SAE: Failed to retransmit: ret=%d", ret); |
| 812 | } |
| 813 | |
| 814 | |
| 815 | void sae_clear_retransmit_timer(struct hostapd_data *hapd, struct sta_info *sta) |
| 816 | { |
| 817 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); |
| 818 | } |
| 819 | |
| 820 | |
| 821 | static void sae_set_retransmit_timer(struct hostapd_data *hapd, |
| 822 | struct sta_info *sta) |
| 823 | { |
| 824 | if (!(hapd->conf->mesh & MESH_ENABLED)) |
| 825 | return; |
| 826 | |
| 827 | eloop_cancel_timeout(auth_sae_retransmit_timer, hapd, sta); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 828 | eloop_register_timeout(0, hapd->dot11RSNASAERetransPeriod * 1000, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 829 | auth_sae_retransmit_timer, hapd, sta); |
| 830 | } |
| 831 | |
| 832 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 833 | static void sae_sme_send_external_auth_status(struct hostapd_data *hapd, |
| 834 | struct sta_info *sta, u16 status) |
| 835 | { |
| 836 | struct external_auth params; |
| 837 | |
| 838 | os_memset(¶ms, 0, sizeof(params)); |
| 839 | params.status = status; |
| 840 | params.bssid = sta->addr; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 841 | if (status == WLAN_STATUS_SUCCESS && sta->sae && |
| 842 | !hapd->conf->disable_pmksa_caching) |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 843 | params.pmkid = sta->sae->pmkid; |
| 844 | |
| 845 | hostapd_drv_send_external_auth_status(hapd, ¶ms); |
| 846 | } |
| 847 | |
| 848 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 849 | void sae_accept_sta(struct hostapd_data *hapd, struct sta_info *sta) |
| 850 | { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 851 | #ifndef CONFIG_NO_VLAN |
| 852 | struct vlan_description vlan_desc; |
| 853 | |
| 854 | if (sta->sae->tmp && sta->sae->tmp->vlan_id > 0) { |
| 855 | wpa_printf(MSG_DEBUG, "SAE: Assign STA " MACSTR |
| 856 | " to VLAN ID %d", |
| 857 | MAC2STR(sta->addr), sta->sae->tmp->vlan_id); |
| 858 | |
| 859 | os_memset(&vlan_desc, 0, sizeof(vlan_desc)); |
| 860 | vlan_desc.notempty = 1; |
| 861 | vlan_desc.untagged = sta->sae->tmp->vlan_id; |
| 862 | if (!hostapd_vlan_valid(hapd->conf->vlan, &vlan_desc)) { |
| 863 | wpa_printf(MSG_INFO, |
| 864 | "Invalid VLAN ID %d in sae_password", |
| 865 | sta->sae->tmp->vlan_id); |
| 866 | return; |
| 867 | } |
| 868 | |
| 869 | if (ap_sta_set_vlan(hapd, sta, &vlan_desc) < 0 || |
| 870 | ap_sta_bind_vlan(hapd, sta) < 0) { |
| 871 | wpa_printf(MSG_INFO, |
| 872 | "Failed to assign VLAN ID %d from sae_password to " |
| 873 | MACSTR, sta->sae->tmp->vlan_id, |
| 874 | MAC2STR(sta->addr)); |
| 875 | return; |
| 876 | } |
| 877 | } |
| 878 | #endif /* CONFIG_NO_VLAN */ |
| 879 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 880 | sta->flags |= WLAN_STA_AUTH; |
| 881 | sta->auth_alg = WLAN_AUTH_SAE; |
| 882 | mlme_authenticate_indication(hapd, sta); |
| 883 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 884 | sae_set_state(sta, SAE_ACCEPTED, "Accept Confirm"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 885 | crypto_bignum_deinit(sta->sae->peer_commit_scalar_accepted, 0); |
| 886 | sta->sae->peer_commit_scalar_accepted = sta->sae->peer_commit_scalar; |
| 887 | sta->sae->peer_commit_scalar = NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 888 | wpa_auth_pmksa_add_sae(hapd->wpa_auth, sta->addr, |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 889 | sta->sae->pmk, sta->sae->pmk_len, |
| 890 | sta->sae->pmkid, sta->sae->akmp); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 891 | sae_sme_send_external_auth_status(hapd, sta, WLAN_STATUS_SUCCESS); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 895 | 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] | 896 | const u8 *bssid, u16 auth_transaction, u16 status_code, |
| 897 | int allow_reuse, int *sta_removed) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 898 | { |
| 899 | int ret; |
| 900 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 901 | *sta_removed = 0; |
| 902 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 903 | if (auth_transaction != 1 && auth_transaction != 2) |
| 904 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 905 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 906 | wpa_printf(MSG_DEBUG, "SAE: Peer " MACSTR " state=%s auth_trans=%u", |
| 907 | MAC2STR(sta->addr), sae_state_txt(sta->sae->state), |
| 908 | auth_transaction); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 909 | switch (sta->sae->state) { |
| 910 | case SAE_NOTHING: |
| 911 | if (auth_transaction == 1) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 912 | if (sta->sae->tmp) { |
| 913 | sta->sae->h2e = |
| 914 | (status_code == |
| 915 | WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 916 | status_code == WLAN_STATUS_SAE_PK); |
| 917 | sta->sae->pk = |
| 918 | status_code == WLAN_STATUS_SAE_PK; |
| 919 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 920 | ret = auth_sae_send_commit(hapd, sta, bssid, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 921 | !allow_reuse, status_code); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 922 | if (ret) |
| 923 | return ret; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 924 | sae_set_state(sta, SAE_COMMITTED, "Sent Commit"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 925 | |
| 926 | if (sae_process_commit(sta->sae) < 0) |
| 927 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 928 | |
| 929 | /* |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 930 | * In mesh case, both Commit and Confirm are sent |
| 931 | * immediately. In infrastructure BSS, by default, only |
| 932 | * a single Authentication frame (Commit) is expected |
| 933 | * from the AP here and the second one (Confirm) will |
| 934 | * be sent once the STA has sent its second |
| 935 | * Authentication frame (Confirm). This behavior can be |
| 936 | * overridden with explicit configuration so that the |
| 937 | * infrastructure BSS case sends both frames together. |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 938 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 939 | if ((hapd->conf->mesh & MESH_ENABLED) || |
| 940 | hapd->conf->sae_confirm_immediate) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 941 | /* |
| 942 | * Send both Commit and Confirm immediately |
| 943 | * based on SAE finite state machine |
| 944 | * Nothing -> Confirm transition. |
| 945 | */ |
| 946 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 947 | if (ret) |
| 948 | return ret; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 949 | sae_set_state(sta, SAE_CONFIRMED, |
| 950 | "Sent Confirm (mesh)"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 951 | } else { |
| 952 | /* |
| 953 | * For infrastructure BSS, send only the Commit |
| 954 | * message now to get alternating sequence of |
| 955 | * Authentication frames between the AP and STA. |
| 956 | * Confirm will be sent in |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 957 | * Committed -> Confirmed/Accepted transition |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 958 | * when receiving Confirm from STA. |
| 959 | */ |
| 960 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 961 | sta->sae->sync = 0; |
| 962 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 963 | } else { |
| 964 | hostapd_logger(hapd, sta->addr, |
| 965 | HOSTAPD_MODULE_IEEE80211, |
| 966 | HOSTAPD_LEVEL_DEBUG, |
| 967 | "SAE confirm before commit"); |
| 968 | } |
| 969 | break; |
| 970 | case SAE_COMMITTED: |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 971 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 972 | if (auth_transaction == 1) { |
| 973 | if (sae_process_commit(sta->sae) < 0) |
| 974 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 975 | |
| 976 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 977 | if (ret) |
| 978 | return ret; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 979 | sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 980 | sta->sae->sync = 0; |
| 981 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 982 | } else if (hapd->conf->mesh & MESH_ENABLED) { |
| 983 | /* |
| 984 | * In mesh case, follow SAE finite state machine and |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 985 | * send Commit now, if sync count allows. |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 986 | */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 987 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 988 | return WLAN_STATUS_SUCCESS; |
| 989 | sta->sae->sync++; |
| 990 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 991 | ret = auth_sae_send_commit(hapd, sta, bssid, 0, |
| 992 | status_code); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 993 | if (ret) |
| 994 | return ret; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 995 | |
| 996 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 997 | } else { |
| 998 | /* |
| 999 | * For instructure BSS, send the postponed Confirm from |
| 1000 | * Nothing -> Confirmed transition that was reduced to |
| 1001 | * Nothing -> Committed above. |
| 1002 | */ |
| 1003 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 1004 | if (ret) |
| 1005 | return ret; |
| 1006 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1007 | sae_set_state(sta, SAE_CONFIRMED, "Sent Confirm"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1008 | |
| 1009 | /* |
| 1010 | * Since this was triggered on Confirm RX, run another |
| 1011 | * step to get to Accepted without waiting for |
| 1012 | * additional events. |
| 1013 | */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1014 | return sae_sm_step(hapd, sta, bssid, auth_transaction, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1015 | WLAN_STATUS_SUCCESS, 0, sta_removed); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1016 | } |
| 1017 | break; |
| 1018 | case SAE_CONFIRMED: |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1019 | sae_clear_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1020 | if (auth_transaction == 1) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1021 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1022 | return WLAN_STATUS_SUCCESS; |
| 1023 | sta->sae->sync++; |
| 1024 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1025 | ret = auth_sae_send_commit(hapd, sta, bssid, 1, |
| 1026 | status_code); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1027 | if (ret) |
| 1028 | return ret; |
| 1029 | |
| 1030 | if (sae_process_commit(sta->sae) < 0) |
| 1031 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1032 | |
| 1033 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 1034 | if (ret) |
| 1035 | return ret; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1036 | |
| 1037 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1038 | } else { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1039 | sta->sae->send_confirm = 0xffff; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1040 | sae_accept_sta(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1041 | } |
| 1042 | break; |
| 1043 | case SAE_ACCEPTED: |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1044 | if (auth_transaction == 1 && |
| 1045 | (hapd->conf->mesh & MESH_ENABLED)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1046 | wpa_printf(MSG_DEBUG, "SAE: remove the STA (" MACSTR |
| 1047 | ") doing reauthentication", |
| 1048 | MAC2STR(sta->addr)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1049 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1050 | ap_free_sta(hapd, sta); |
| 1051 | *sta_removed = 1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1052 | } else if (auth_transaction == 1) { |
| 1053 | wpa_printf(MSG_DEBUG, "SAE: Start reauthentication"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1054 | ret = auth_sae_send_commit(hapd, sta, bssid, 1, |
| 1055 | status_code); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1056 | if (ret) |
| 1057 | return ret; |
| 1058 | sae_set_state(sta, SAE_COMMITTED, "Sent Commit"); |
| 1059 | |
| 1060 | if (sae_process_commit(sta->sae) < 0) |
| 1061 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1062 | sta->sae->sync = 0; |
| 1063 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1064 | } else { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1065 | if (sae_check_big_sync(hapd, sta)) |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1066 | return WLAN_STATUS_SUCCESS; |
| 1067 | sta->sae->sync++; |
| 1068 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1069 | ret = auth_sae_send_confirm(hapd, sta, bssid); |
| 1070 | sae_clear_temp_data(sta->sae); |
| 1071 | if (ret) |
| 1072 | return ret; |
| 1073 | } |
| 1074 | break; |
| 1075 | default: |
| 1076 | wpa_printf(MSG_ERROR, "SAE: invalid state %d", |
| 1077 | sta->sae->state); |
| 1078 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1079 | } |
| 1080 | return WLAN_STATUS_SUCCESS; |
| 1081 | } |
| 1082 | |
| 1083 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1084 | static void sae_pick_next_group(struct hostapd_data *hapd, struct sta_info *sta) |
| 1085 | { |
| 1086 | struct sae_data *sae = sta->sae; |
| 1087 | int i, *groups = hapd->conf->sae_groups; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1088 | int default_groups[] = { 19, 0 }; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1089 | |
| 1090 | if (sae->state != SAE_COMMITTED) |
| 1091 | return; |
| 1092 | |
| 1093 | wpa_printf(MSG_DEBUG, "SAE: Previously selected group: %d", sae->group); |
| 1094 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1095 | if (!groups) |
| 1096 | groups = default_groups; |
| 1097 | for (i = 0; groups[i] > 0; i++) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1098 | if (sae->group == groups[i]) |
| 1099 | break; |
| 1100 | } |
| 1101 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1102 | if (groups[i] <= 0) { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1103 | wpa_printf(MSG_DEBUG, |
| 1104 | "SAE: Previously selected group not found from the current configuration"); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
| 1108 | for (;;) { |
| 1109 | i++; |
| 1110 | if (groups[i] <= 0) { |
| 1111 | wpa_printf(MSG_DEBUG, |
| 1112 | "SAE: No alternative group enabled"); |
| 1113 | return; |
| 1114 | } |
| 1115 | |
| 1116 | if (sae_set_group(sae, groups[i]) < 0) |
| 1117 | continue; |
| 1118 | |
| 1119 | break; |
| 1120 | } |
| 1121 | wpa_printf(MSG_DEBUG, "SAE: Selected new group: %d", groups[i]); |
| 1122 | } |
| 1123 | |
| 1124 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1125 | static int sae_status_success(struct hostapd_data *hapd, u16 status_code) |
| 1126 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1127 | enum sae_pwe sae_pwe = hapd->conf->sae_pwe; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1128 | int id_in_use; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1129 | bool sae_pk = false; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1130 | |
| 1131 | id_in_use = hostapd_sae_pw_id_in_use(hapd->conf); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1132 | if (id_in_use == 2 && sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK) |
| 1133 | sae_pwe = SAE_PWE_HASH_TO_ELEMENT; |
| 1134 | else if (id_in_use == 1 && sae_pwe == SAE_PWE_HUNT_AND_PECK) |
| 1135 | sae_pwe = SAE_PWE_BOTH; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1136 | #ifdef CONFIG_SAE_PK |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1137 | sae_pk = hostapd_sae_pk_in_use(hapd->conf); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1138 | if (sae_pwe == SAE_PWE_HUNT_AND_PECK && sae_pk) |
| 1139 | sae_pwe = SAE_PWE_BOTH; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1140 | #endif /* CONFIG_SAE_PK */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1141 | if (sae_pwe == SAE_PWE_HUNT_AND_PECK && |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 1142 | (hapd->conf->wpa_key_mgmt & |
| 1143 | (WPA_KEY_MGMT_SAE_EXT_KEY | WPA_KEY_MGMT_FT_SAE_EXT_KEY))) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1144 | sae_pwe = SAE_PWE_BOTH; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1145 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1146 | return ((sae_pwe == SAE_PWE_HUNT_AND_PECK || |
| 1147 | sae_pwe == SAE_PWE_FORCE_HUNT_AND_PECK) && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1148 | status_code == WLAN_STATUS_SUCCESS) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1149 | (sae_pwe == SAE_PWE_HASH_TO_ELEMENT && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1150 | (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1151 | (sae_pk && status_code == WLAN_STATUS_SAE_PK))) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1152 | (sae_pwe == SAE_PWE_BOTH && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1153 | (status_code == WLAN_STATUS_SUCCESS || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1154 | status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1155 | (sae_pk && status_code == WLAN_STATUS_SAE_PK))); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | |
| 1159 | static int sae_is_group_enabled(struct hostapd_data *hapd, int group) |
| 1160 | { |
| 1161 | int *groups = hapd->conf->sae_groups; |
| 1162 | int default_groups[] = { 19, 0 }; |
| 1163 | int i; |
| 1164 | |
| 1165 | if (!groups) |
| 1166 | groups = default_groups; |
| 1167 | |
| 1168 | for (i = 0; groups[i] > 0; i++) { |
| 1169 | if (groups[i] == group) |
| 1170 | return 1; |
| 1171 | } |
| 1172 | |
| 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | |
| 1177 | static int check_sae_rejected_groups(struct hostapd_data *hapd, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1178 | struct sae_data *sae) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1179 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1180 | const struct wpabuf *groups; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1181 | size_t i, count; |
| 1182 | const u8 *pos; |
| 1183 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1184 | if (!sae->tmp) |
| 1185 | return 0; |
| 1186 | groups = sae->tmp->peer_rejected_groups; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1187 | if (!groups) |
| 1188 | return 0; |
| 1189 | |
| 1190 | pos = wpabuf_head(groups); |
| 1191 | count = wpabuf_len(groups) / 2; |
| 1192 | for (i = 0; i < count; i++) { |
| 1193 | int enabled; |
| 1194 | u16 group; |
| 1195 | |
| 1196 | group = WPA_GET_LE16(pos); |
| 1197 | pos += 2; |
| 1198 | enabled = sae_is_group_enabled(hapd, group); |
| 1199 | wpa_printf(MSG_DEBUG, "SAE: Rejected group %u is %s", |
| 1200 | group, enabled ? "enabled" : "disabled"); |
| 1201 | if (enabled) |
| 1202 | return 1; |
| 1203 | } |
| 1204 | |
| 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1209 | static void handle_auth_sae(struct hostapd_data *hapd, struct sta_info *sta, |
| 1210 | const struct ieee80211_mgmt *mgmt, size_t len, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1211 | u16 auth_transaction, u16 status_code) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1212 | { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1213 | int resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1214 | struct wpabuf *data = NULL; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1215 | int *groups = hapd->conf->sae_groups; |
| 1216 | int default_groups[] = { 19, 0 }; |
| 1217 | const u8 *pos, *end; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1218 | int sta_removed = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1219 | bool success_status; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1220 | |
| 1221 | if (!groups) |
| 1222 | groups = default_groups; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1223 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1224 | #ifdef CONFIG_TESTING_OPTIONS |
| 1225 | if (hapd->conf->sae_reflection_attack && auth_transaction == 1) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1226 | wpa_printf(MSG_DEBUG, "SAE: TESTING - reflection attack"); |
| 1227 | pos = mgmt->u.auth.variable; |
| 1228 | end = ((const u8 *) mgmt) + len; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1229 | resp = status_code; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1230 | send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1231 | auth_transaction, resp, pos, end - pos, |
| 1232 | "auth-sae-reflection-attack"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1233 | goto remove_sta; |
| 1234 | } |
| 1235 | |
| 1236 | if (hapd->conf->sae_commit_override && auth_transaction == 1) { |
| 1237 | wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1238 | send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1239 | auth_transaction, resp, |
| 1240 | wpabuf_head(hapd->conf->sae_commit_override), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1241 | wpabuf_len(hapd->conf->sae_commit_override), |
| 1242 | "sae-commit-override"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1243 | goto remove_sta; |
| 1244 | } |
| 1245 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1246 | if (!sta->sae) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1247 | if (auth_transaction != 1 || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1248 | !sae_status_success(hapd, status_code)) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1249 | wpa_printf(MSG_DEBUG, "SAE: Unexpected Status Code %u", |
| 1250 | status_code); |
| 1251 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1252 | goto reply; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1253 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1254 | sta->sae = os_zalloc(sizeof(*sta->sae)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1255 | if (!sta->sae) { |
| 1256 | resp = -1; |
| 1257 | goto remove_sta; |
| 1258 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1259 | sae_set_state(sta, SAE_NOTHING, "Init"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1260 | sta->sae->sync = 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1261 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1262 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1263 | if (sta->mesh_sae_pmksa_caching) { |
| 1264 | wpa_printf(MSG_DEBUG, |
| 1265 | "SAE: Cancel use of mesh PMKSA caching because peer starts SAE authentication"); |
| 1266 | wpa_auth_pmksa_remove(hapd->wpa_auth, sta->addr); |
| 1267 | sta->mesh_sae_pmksa_caching = 0; |
| 1268 | } |
| 1269 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1270 | if (auth_transaction == 1) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1271 | const u8 *token = NULL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1272 | size_t token_len = 0; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1273 | int allow_reuse = 0; |
| 1274 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1275 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1276 | HOSTAPD_LEVEL_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1277 | "start SAE authentication (RX commit, status=%u (%s))", |
| 1278 | status_code, status2str(status_code)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1279 | |
| 1280 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 1281 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && |
| 1282 | sta->sae->tmp) { |
| 1283 | pos = mgmt->u.auth.variable; |
| 1284 | end = ((const u8 *) mgmt) + len; |
| 1285 | if (pos + sizeof(le16) > end) { |
| 1286 | wpa_printf(MSG_ERROR, |
| 1287 | "SAE: Too short anti-clogging token request"); |
| 1288 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1289 | goto reply; |
| 1290 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1291 | resp = sae_group_allowed(sta->sae, groups, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1292 | WPA_GET_LE16(pos)); |
| 1293 | if (resp != WLAN_STATUS_SUCCESS) { |
| 1294 | wpa_printf(MSG_ERROR, |
| 1295 | "SAE: Invalid group in anti-clogging token request"); |
| 1296 | goto reply; |
| 1297 | } |
| 1298 | pos += sizeof(le16); |
| 1299 | |
| 1300 | wpabuf_free(sta->sae->tmp->anti_clogging_token); |
| 1301 | sta->sae->tmp->anti_clogging_token = |
| 1302 | wpabuf_alloc_copy(pos, end - pos); |
| 1303 | if (sta->sae->tmp->anti_clogging_token == NULL) { |
| 1304 | wpa_printf(MSG_ERROR, |
| 1305 | "SAE: Failed to alloc for anti-clogging token"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1306 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1307 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | /* |
| 1311 | * IEEE Std 802.11-2012, 11.3.8.6.4: If the Status code |
| 1312 | * is 76, a new Commit Message shall be constructed |
| 1313 | * with the Anti-Clogging Token from the received |
| 1314 | * Authentication frame, and the commit-scalar and |
| 1315 | * COMMIT-ELEMENT previously sent. |
| 1316 | */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1317 | resp = auth_sae_send_commit(hapd, sta, mgmt->bssid, 0, |
| 1318 | status_code); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1319 | if (resp != WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1320 | wpa_printf(MSG_ERROR, |
| 1321 | "SAE: Failed to send commit message"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1322 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1323 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1324 | sae_set_state(sta, SAE_COMMITTED, |
| 1325 | "Sent Commit (anti-clogging token case in mesh)"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1326 | sta->sae->sync = 0; |
| 1327 | sae_set_retransmit_timer(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1328 | return; |
| 1329 | } |
| 1330 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1331 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 1332 | status_code == |
| 1333 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && |
| 1334 | sta->sae->tmp) { |
| 1335 | wpa_printf(MSG_DEBUG, |
| 1336 | "SAE: Peer did not accept our SAE group"); |
| 1337 | sae_pick_next_group(hapd, sta); |
| 1338 | goto remove_sta; |
| 1339 | } |
| 1340 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1341 | if (!sae_status_success(hapd, status_code)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1342 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1343 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1344 | if (!(hapd->conf->mesh & MESH_ENABLED) && |
| 1345 | sta->sae->state == SAE_COMMITTED) { |
| 1346 | /* This is needed in the infrastructure BSS case to |
| 1347 | * address a sequence where a STA entry may remain in |
| 1348 | * hostapd across two attempts to do SAE authentication |
| 1349 | * by the same STA. The second attempt may end up trying |
| 1350 | * to use a different group and that would not be |
| 1351 | * allowed if we remain in Committed state with the |
| 1352 | * previously set parameters. */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1353 | pos = mgmt->u.auth.variable; |
| 1354 | end = ((const u8 *) mgmt) + len; |
| 1355 | if (end - pos >= (int) sizeof(le16) && |
| 1356 | sae_group_allowed(sta->sae, groups, |
| 1357 | WPA_GET_LE16(pos)) == |
| 1358 | WLAN_STATUS_SUCCESS) { |
| 1359 | /* Do not waste resources deriving the same PWE |
| 1360 | * again since the same group is reused. */ |
| 1361 | sae_set_state(sta, SAE_NOTHING, |
| 1362 | "Allow previous PWE to be reused"); |
| 1363 | allow_reuse = 1; |
| 1364 | } else { |
| 1365 | sae_set_state(sta, SAE_NOTHING, |
| 1366 | "Clear existing state to allow restart"); |
| 1367 | sae_clear_data(sta->sae); |
| 1368 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1371 | resp = sae_parse_commit(sta->sae, mgmt->u.auth.variable, |
| 1372 | ((const u8 *) mgmt) + len - |
| 1373 | mgmt->u.auth.variable, &token, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1374 | &token_len, groups, status_code == |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1375 | WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1376 | status_code == WLAN_STATUS_SAE_PK, |
| 1377 | NULL); |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1378 | if (resp == SAE_SILENTLY_DISCARD) { |
| 1379 | wpa_printf(MSG_DEBUG, |
| 1380 | "SAE: Drop commit message from " MACSTR " due to reflection attack", |
| 1381 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1382 | goto remove_sta; |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1383 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1384 | |
| 1385 | if (resp == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) { |
| 1386 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
| 1387 | WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER |
| 1388 | MACSTR, MAC2STR(sta->addr)); |
| 1389 | sae_clear_retransmit_timer(hapd, sta); |
| 1390 | sae_set_state(sta, SAE_NOTHING, |
| 1391 | "Unknown Password Identifier"); |
| 1392 | goto remove_sta; |
| 1393 | } |
| 1394 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1395 | if (token && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1396 | check_comeback_token(hapd->comeback_key, |
| 1397 | hapd->comeback_pending_idx, sta->addr, |
| 1398 | token, token_len) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1399 | < 0) { |
| 1400 | wpa_printf(MSG_DEBUG, "SAE: Drop commit message with " |
| 1401 | "incorrect token from " MACSTR, |
| 1402 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1403 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1404 | goto remove_sta; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1405 | } |
| 1406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1407 | if (resp != WLAN_STATUS_SUCCESS) |
| 1408 | goto reply; |
| 1409 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1410 | if (check_sae_rejected_groups(hapd, sta->sae)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1411 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1412 | goto reply; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1415 | if (!token && use_anti_clogging(hapd) && !allow_reuse) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1416 | int h2e = 0; |
| 1417 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1418 | wpa_printf(MSG_DEBUG, |
| 1419 | "SAE: Request anti-clogging token from " |
| 1420 | MACSTR, MAC2STR(sta->addr)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1421 | if (sta->sae->tmp) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1422 | h2e = sta->sae->h2e; |
| 1423 | if (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 1424 | status_code == WLAN_STATUS_SAE_PK) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1425 | h2e = 1; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1426 | data = auth_build_token_req( |
| 1427 | &hapd->last_comeback_key_update, |
| 1428 | hapd->comeback_key, |
| 1429 | hapd->comeback_idx, |
| 1430 | hapd->comeback_pending_idx, |
| 1431 | sizeof(hapd->comeback_pending_idx), |
| 1432 | sta->sae->group, |
| 1433 | sta->addr, h2e); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1434 | resp = WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ; |
| 1435 | if (hapd->conf->mesh & MESH_ENABLED) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1436 | sae_set_state(sta, SAE_NOTHING, |
| 1437 | "Request anti-clogging token case in mesh"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1438 | goto reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1439 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1440 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1441 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1442 | status_code, allow_reuse, &sta_removed); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1443 | } else if (auth_transaction == 2) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1444 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1445 | HOSTAPD_LEVEL_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1446 | "SAE authentication (RX confirm, status=%u (%s))", |
| 1447 | status_code, status2str(status_code)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1448 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1449 | goto remove_sta; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1450 | if (sta->sae->state >= SAE_CONFIRMED || |
| 1451 | !(hapd->conf->mesh & MESH_ENABLED)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1452 | const u8 *var; |
| 1453 | size_t var_len; |
| 1454 | u16 peer_send_confirm; |
| 1455 | |
| 1456 | var = mgmt->u.auth.variable; |
| 1457 | var_len = ((u8 *) mgmt) + len - mgmt->u.auth.variable; |
| 1458 | if (var_len < 2) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1459 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1460 | goto reply; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1461 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1462 | |
| 1463 | peer_send_confirm = WPA_GET_LE16(var); |
| 1464 | |
| 1465 | if (sta->sae->state == SAE_ACCEPTED && |
| 1466 | (peer_send_confirm <= sta->sae->rc || |
| 1467 | peer_send_confirm == 0xffff)) { |
| 1468 | wpa_printf(MSG_DEBUG, |
| 1469 | "SAE: Silently ignore unexpected Confirm from peer " |
| 1470 | MACSTR |
| 1471 | " (peer-send-confirm=%u Rc=%u)", |
| 1472 | MAC2STR(sta->addr), |
| 1473 | peer_send_confirm, sta->sae->rc); |
| 1474 | return; |
| 1475 | } |
| 1476 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1477 | if (sae_check_confirm(sta->sae, var, var_len, |
| 1478 | NULL) < 0) { |
| 1479 | resp = WLAN_STATUS_CHALLENGE_FAIL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1480 | goto reply; |
| 1481 | } |
| 1482 | sta->sae->rc = peer_send_confirm; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1483 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1484 | resp = sae_sm_step(hapd, sta, mgmt->bssid, auth_transaction, |
| 1485 | status_code, 0, &sta_removed); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1486 | } else { |
| 1487 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 1488 | HOSTAPD_LEVEL_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1489 | "unexpected SAE authentication transaction %u (status=%u (%s))", |
| 1490 | auth_transaction, status_code, |
| 1491 | status2str(status_code)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1492 | if (status_code != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1493 | goto remove_sta; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1494 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 1495 | } |
| 1496 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1497 | reply: |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1498 | if (!sta_removed && resp != WLAN_STATUS_SUCCESS) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1499 | pos = mgmt->u.auth.variable; |
| 1500 | end = ((const u8 *) mgmt) + len; |
| 1501 | |
| 1502 | /* Copy the Finite Cyclic Group field from the request if we |
| 1503 | * rejected it as unsupported group. */ |
| 1504 | if (resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && |
| 1505 | !data && end - pos >= 2) |
| 1506 | data = wpabuf_alloc_copy(pos, 2); |
| 1507 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1508 | sae_sme_send_external_auth_status(hapd, sta, resp); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1509 | send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, WLAN_AUTH_SAE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1510 | auth_transaction, resp, |
| 1511 | data ? wpabuf_head(data) : (u8 *) "", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1512 | data ? wpabuf_len(data) : 0, "auth-sae"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1513 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1514 | |
| 1515 | remove_sta: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1516 | if (auth_transaction == 1) |
| 1517 | success_status = sae_status_success(hapd, status_code); |
| 1518 | else |
| 1519 | success_status = status_code == WLAN_STATUS_SUCCESS; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1520 | if (!sta_removed && sta->added_unassoc && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1521 | (resp != WLAN_STATUS_SUCCESS || !success_status)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1522 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 1523 | sta->added_unassoc = 0; |
| 1524 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1525 | wpabuf_free(data); |
| 1526 | } |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1527 | |
| 1528 | |
| 1529 | /** |
| 1530 | * auth_sae_init_committed - Send COMMIT and start SAE in committed state |
| 1531 | * @hapd: BSS data for the device initiating the authentication |
| 1532 | * @sta: the peer to which commit authentication frame is sent |
| 1533 | * |
| 1534 | * This function implements Init event handling (IEEE Std 802.11-2012, |
| 1535 | * 11.3.8.6.3) in which initial COMMIT message is sent. Prior to calling, the |
| 1536 | * sta->sae structure should be initialized appropriately via a call to |
| 1537 | * sae_prepare_commit(). |
| 1538 | */ |
| 1539 | int auth_sae_init_committed(struct hostapd_data *hapd, struct sta_info *sta) |
| 1540 | { |
| 1541 | int ret; |
| 1542 | |
| 1543 | if (!sta->sae || !sta->sae->tmp) |
| 1544 | return -1; |
| 1545 | |
| 1546 | if (sta->sae->state != SAE_NOTHING) |
| 1547 | return -1; |
| 1548 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1549 | ret = auth_sae_send_commit(hapd, sta, hapd->own_addr, 0, -1); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1550 | if (ret) |
| 1551 | return -1; |
| 1552 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1553 | sae_set_state(sta, SAE_COMMITTED, "Init and sent commit"); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1554 | sta->sae->sync = 0; |
| 1555 | sae_set_retransmit_timer(hapd, sta); |
| 1556 | |
| 1557 | return 0; |
| 1558 | } |
| 1559 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1560 | |
| 1561 | void auth_sae_process_commit(void *eloop_ctx, void *user_ctx) |
| 1562 | { |
| 1563 | struct hostapd_data *hapd = eloop_ctx; |
| 1564 | struct hostapd_sae_commit_queue *q; |
| 1565 | unsigned int queue_len; |
| 1566 | |
| 1567 | q = dl_list_first(&hapd->sae_commit_queue, |
| 1568 | struct hostapd_sae_commit_queue, list); |
| 1569 | if (!q) |
| 1570 | return; |
| 1571 | wpa_printf(MSG_DEBUG, |
| 1572 | "SAE: Process next available message from queue"); |
| 1573 | dl_list_del(&q->list); |
| 1574 | handle_auth(hapd, (const struct ieee80211_mgmt *) q->msg, q->len, |
| 1575 | q->rssi, 1); |
| 1576 | os_free(q); |
| 1577 | |
| 1578 | if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL)) |
| 1579 | return; |
| 1580 | queue_len = dl_list_len(&hapd->sae_commit_queue); |
| 1581 | eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit, |
| 1582 | hapd, NULL); |
| 1583 | } |
| 1584 | |
| 1585 | |
| 1586 | static void auth_sae_queue(struct hostapd_data *hapd, |
| 1587 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 1588 | int rssi) |
| 1589 | { |
| 1590 | struct hostapd_sae_commit_queue *q, *q2; |
| 1591 | unsigned int queue_len; |
| 1592 | const struct ieee80211_mgmt *mgmt2; |
| 1593 | |
| 1594 | queue_len = dl_list_len(&hapd->sae_commit_queue); |
| 1595 | if (queue_len >= 15) { |
| 1596 | wpa_printf(MSG_DEBUG, |
| 1597 | "SAE: No more room in message queue - drop the new frame from " |
| 1598 | MACSTR, MAC2STR(mgmt->sa)); |
| 1599 | return; |
| 1600 | } |
| 1601 | |
| 1602 | wpa_printf(MSG_DEBUG, "SAE: Queue Authentication message from " |
| 1603 | MACSTR " for processing (queue_len %u)", MAC2STR(mgmt->sa), |
| 1604 | queue_len); |
| 1605 | q = os_zalloc(sizeof(*q) + len); |
| 1606 | if (!q) |
| 1607 | return; |
| 1608 | q->rssi = rssi; |
| 1609 | q->len = len; |
| 1610 | os_memcpy(q->msg, mgmt, len); |
| 1611 | |
| 1612 | /* Check whether there is already a queued Authentication frame from the |
| 1613 | * same station with the same transaction number and if so, replace that |
| 1614 | * queue entry with the new one. This avoids issues with a peer that |
| 1615 | * sends multiple times (e.g., due to frequent SAE retries). There is no |
| 1616 | * point in us trying to process the old attempts after a new one has |
| 1617 | * obsoleted them. */ |
| 1618 | dl_list_for_each(q2, &hapd->sae_commit_queue, |
| 1619 | struct hostapd_sae_commit_queue, list) { |
| 1620 | mgmt2 = (const struct ieee80211_mgmt *) q2->msg; |
| 1621 | if (os_memcmp(mgmt->sa, mgmt2->sa, ETH_ALEN) == 0 && |
| 1622 | mgmt->u.auth.auth_transaction == |
| 1623 | mgmt2->u.auth.auth_transaction) { |
| 1624 | wpa_printf(MSG_DEBUG, |
| 1625 | "SAE: Replace queued message from same STA with same transaction number"); |
| 1626 | dl_list_add(&q2->list, &q->list); |
| 1627 | dl_list_del(&q2->list); |
| 1628 | os_free(q2); |
| 1629 | goto queued; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | /* No pending identical entry, so add to the end of the queue */ |
| 1634 | dl_list_add_tail(&hapd->sae_commit_queue, &q->list); |
| 1635 | |
| 1636 | queued: |
| 1637 | if (eloop_is_timeout_registered(auth_sae_process_commit, hapd, NULL)) |
| 1638 | return; |
| 1639 | eloop_register_timeout(0, queue_len * 10000, auth_sae_process_commit, |
| 1640 | hapd, NULL); |
| 1641 | } |
| 1642 | |
| 1643 | |
| 1644 | static int auth_sae_queued_addr(struct hostapd_data *hapd, const u8 *addr) |
| 1645 | { |
| 1646 | struct hostapd_sae_commit_queue *q; |
| 1647 | const struct ieee80211_mgmt *mgmt; |
| 1648 | |
| 1649 | dl_list_for_each(q, &hapd->sae_commit_queue, |
| 1650 | struct hostapd_sae_commit_queue, list) { |
| 1651 | mgmt = (const struct ieee80211_mgmt *) q->msg; |
| 1652 | if (os_memcmp(addr, mgmt->sa, ETH_ALEN) == 0) |
| 1653 | return 1; |
| 1654 | } |
| 1655 | |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1659 | #endif /* CONFIG_SAE */ |
| 1660 | |
| 1661 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1662 | static u16 wpa_res_to_status_code(enum wpa_validate_result res) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1663 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1664 | switch (res) { |
| 1665 | case WPA_IE_OK: |
| 1666 | return WLAN_STATUS_SUCCESS; |
| 1667 | case WPA_INVALID_IE: |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1668 | return WLAN_STATUS_INVALID_IE; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1669 | case WPA_INVALID_GROUP: |
| 1670 | return WLAN_STATUS_GROUP_CIPHER_NOT_VALID; |
| 1671 | case WPA_INVALID_PAIRWISE: |
| 1672 | return WLAN_STATUS_PAIRWISE_CIPHER_NOT_VALID; |
| 1673 | case WPA_INVALID_AKMP: |
| 1674 | return WLAN_STATUS_AKMP_NOT_VALID; |
| 1675 | case WPA_NOT_ENABLED: |
| 1676 | return WLAN_STATUS_INVALID_IE; |
| 1677 | case WPA_ALLOC_FAIL: |
| 1678 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1679 | case WPA_MGMT_FRAME_PROTECTION_VIOLATION: |
| 1680 | return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 1681 | case WPA_INVALID_MGMT_GROUP_CIPHER: |
| 1682 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
| 1683 | case WPA_INVALID_MDIE: |
| 1684 | return WLAN_STATUS_INVALID_MDIE; |
| 1685 | case WPA_INVALID_PROTO: |
| 1686 | return WLAN_STATUS_INVALID_IE; |
| 1687 | case WPA_INVALID_PMKID: |
| 1688 | return WLAN_STATUS_INVALID_PMKID; |
| 1689 | case WPA_DENIED_OTHER_REASON: |
| 1690 | return WLAN_STATUS_ASSOC_DENIED_UNSPEC; |
| 1691 | } |
| 1692 | return WLAN_STATUS_INVALID_IE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | |
| 1696 | #ifdef CONFIG_FILS |
| 1697 | |
| 1698 | static void handle_auth_fils_finish(struct hostapd_data *hapd, |
| 1699 | struct sta_info *sta, u16 resp, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1700 | struct wpabuf *data, int pub); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1701 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1702 | void handle_auth_fils(struct hostapd_data *hapd, struct sta_info *sta, |
| 1703 | const u8 *pos, size_t len, u16 auth_alg, |
| 1704 | u16 auth_transaction, u16 status_code, |
| 1705 | void (*cb)(struct hostapd_data *hapd, |
| 1706 | struct sta_info *sta, u16 resp, |
| 1707 | struct wpabuf *data, int pub)) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1708 | { |
| 1709 | u16 resp = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1710 | const u8 *end; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1711 | struct ieee802_11_elems elems; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1712 | enum wpa_validate_result res; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1713 | struct wpa_ie_data rsn; |
| 1714 | struct rsn_pmksa_cache_entry *pmksa = NULL; |
| 1715 | |
| 1716 | if (auth_transaction != 1 || status_code != WLAN_STATUS_SUCCESS) |
| 1717 | return; |
| 1718 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1719 | end = pos + len; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1720 | |
| 1721 | wpa_hexdump(MSG_DEBUG, "FILS: Authentication frame fields", |
| 1722 | pos, end - pos); |
| 1723 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1724 | /* TODO: FILS PK */ |
| 1725 | #ifdef CONFIG_FILS_SK_PFS |
| 1726 | if (auth_alg == WLAN_AUTH_FILS_SK_PFS) { |
| 1727 | u16 group; |
| 1728 | struct wpabuf *pub; |
| 1729 | size_t elem_len; |
| 1730 | |
| 1731 | /* Using FILS PFS */ |
| 1732 | |
| 1733 | /* Finite Cyclic Group */ |
| 1734 | if (end - pos < 2) { |
| 1735 | wpa_printf(MSG_DEBUG, |
| 1736 | "FILS: No room for Finite Cyclic Group"); |
| 1737 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1738 | goto fail; |
| 1739 | } |
| 1740 | group = WPA_GET_LE16(pos); |
| 1741 | pos += 2; |
| 1742 | if (group != hapd->conf->fils_dh_group) { |
| 1743 | wpa_printf(MSG_DEBUG, |
| 1744 | "FILS: Unsupported Finite Cyclic Group: %u (expected %u)", |
| 1745 | group, hapd->conf->fils_dh_group); |
| 1746 | resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 1747 | goto fail; |
| 1748 | } |
| 1749 | |
| 1750 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 1751 | sta->fils_ecdh = crypto_ecdh_init(group); |
| 1752 | if (!sta->fils_ecdh) { |
| 1753 | wpa_printf(MSG_INFO, |
| 1754 | "FILS: Could not initialize ECDH with group %d", |
| 1755 | group); |
| 1756 | resp = WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 1757 | goto fail; |
| 1758 | } |
| 1759 | |
| 1760 | pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1); |
| 1761 | if (!pub) { |
| 1762 | wpa_printf(MSG_DEBUG, |
| 1763 | "FILS: Failed to derive ECDH public key"); |
| 1764 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1765 | goto fail; |
| 1766 | } |
| 1767 | elem_len = wpabuf_len(pub); |
| 1768 | wpabuf_free(pub); |
| 1769 | |
| 1770 | /* Element */ |
| 1771 | if ((size_t) (end - pos) < elem_len) { |
| 1772 | wpa_printf(MSG_DEBUG, "FILS: No room for Element"); |
| 1773 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1774 | goto fail; |
| 1775 | } |
| 1776 | |
| 1777 | wpabuf_free(sta->fils_g_sta); |
| 1778 | sta->fils_g_sta = wpabuf_alloc_copy(pos, elem_len); |
| 1779 | wpabuf_clear_free(sta->fils_dh_ss); |
| 1780 | sta->fils_dh_ss = crypto_ecdh_set_peerkey(sta->fils_ecdh, 1, |
| 1781 | pos, elem_len); |
| 1782 | if (!sta->fils_dh_ss) { |
| 1783 | wpa_printf(MSG_DEBUG, "FILS: ECDH operation failed"); |
| 1784 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1785 | goto fail; |
| 1786 | } |
| 1787 | wpa_hexdump_buf_key(MSG_DEBUG, "FILS: DH_SS", sta->fils_dh_ss); |
| 1788 | pos += elem_len; |
| 1789 | } else { |
| 1790 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 1791 | sta->fils_ecdh = NULL; |
| 1792 | wpabuf_clear_free(sta->fils_dh_ss); |
| 1793 | sta->fils_dh_ss = NULL; |
| 1794 | } |
| 1795 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1796 | |
| 1797 | wpa_hexdump(MSG_DEBUG, "FILS: Remaining IEs", pos, end - pos); |
| 1798 | if (ieee802_11_parse_elems(pos, end - pos, &elems, 1) == ParseFailed) { |
| 1799 | wpa_printf(MSG_DEBUG, "FILS: Could not parse elements"); |
| 1800 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1801 | goto fail; |
| 1802 | } |
| 1803 | |
| 1804 | /* RSNE */ |
| 1805 | wpa_hexdump(MSG_DEBUG, "FILS: RSN element", |
| 1806 | elems.rsn_ie, elems.rsn_ie_len); |
| 1807 | if (!elems.rsn_ie || |
| 1808 | wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
| 1809 | &rsn) < 0) { |
| 1810 | wpa_printf(MSG_DEBUG, "FILS: No valid RSN element"); |
| 1811 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1812 | goto fail; |
| 1813 | } |
| 1814 | |
| 1815 | if (!sta->wpa_sm) |
| 1816 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, |
| 1817 | NULL); |
| 1818 | if (!sta->wpa_sm) { |
| 1819 | wpa_printf(MSG_DEBUG, |
| 1820 | "FILS: Failed to initialize RSN state machine"); |
| 1821 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1822 | goto fail; |
| 1823 | } |
| 1824 | |
| 1825 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1826 | hapd->iface->freq, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1827 | elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1828 | elems.rsnxe ? elems.rsnxe - 2 : NULL, |
| 1829 | elems.rsnxe ? elems.rsnxe_len + 2 : 0, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1830 | elems.mdie, elems.mdie_len, NULL, 0); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1831 | resp = wpa_res_to_status_code(res); |
| 1832 | if (resp != WLAN_STATUS_SUCCESS) |
| 1833 | goto fail; |
| 1834 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1835 | if (!elems.fils_nonce) { |
| 1836 | wpa_printf(MSG_DEBUG, "FILS: No FILS Nonce field"); |
| 1837 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1838 | goto fail; |
| 1839 | } |
| 1840 | wpa_hexdump(MSG_DEBUG, "FILS: SNonce", elems.fils_nonce, |
| 1841 | FILS_NONCE_LEN); |
| 1842 | os_memcpy(sta->fils_snonce, elems.fils_nonce, FILS_NONCE_LEN); |
| 1843 | |
| 1844 | /* PMKID List */ |
| 1845 | if (rsn.pmkid && rsn.num_pmkid > 0) { |
| 1846 | u8 num; |
| 1847 | const u8 *pmkid; |
| 1848 | |
| 1849 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID List", |
| 1850 | rsn.pmkid, rsn.num_pmkid * PMKID_LEN); |
| 1851 | |
| 1852 | pmkid = rsn.pmkid; |
| 1853 | num = rsn.num_pmkid; |
| 1854 | while (num) { |
| 1855 | wpa_hexdump(MSG_DEBUG, "FILS: PMKID", pmkid, PMKID_LEN); |
| 1856 | pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr, |
| 1857 | pmkid); |
| 1858 | if (pmksa) |
| 1859 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1860 | pmksa = wpa_auth_pmksa_get_fils_cache_id(hapd->wpa_auth, |
| 1861 | sta->addr, |
| 1862 | pmkid); |
| 1863 | if (pmksa) |
| 1864 | break; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1865 | pmkid += PMKID_LEN; |
| 1866 | num--; |
| 1867 | } |
| 1868 | } |
| 1869 | if (pmksa && wpa_auth_sta_key_mgmt(sta->wpa_sm) != pmksa->akmp) { |
| 1870 | wpa_printf(MSG_DEBUG, |
| 1871 | "FILS: Matching PMKSA cache entry has different AKMP (0x%x != 0x%x) - ignore", |
| 1872 | wpa_auth_sta_key_mgmt(sta->wpa_sm), pmksa->akmp); |
| 1873 | pmksa = NULL; |
| 1874 | } |
| 1875 | if (pmksa) |
| 1876 | wpa_printf(MSG_DEBUG, "FILS: Found matching PMKSA cache entry"); |
| 1877 | |
| 1878 | /* FILS Session */ |
| 1879 | if (!elems.fils_session) { |
| 1880 | wpa_printf(MSG_DEBUG, "FILS: No FILS Session element"); |
| 1881 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1882 | goto fail; |
| 1883 | } |
| 1884 | wpa_hexdump(MSG_DEBUG, "FILS: FILS Session", elems.fils_session, |
| 1885 | FILS_SESSION_LEN); |
| 1886 | os_memcpy(sta->fils_session, elems.fils_session, FILS_SESSION_LEN); |
| 1887 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1888 | /* Wrapped Data */ |
| 1889 | if (elems.wrapped_data) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1890 | wpa_hexdump(MSG_DEBUG, "FILS: Wrapped Data", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1891 | elems.wrapped_data, |
| 1892 | elems.wrapped_data_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1893 | if (!pmksa) { |
| 1894 | #ifndef CONFIG_NO_RADIUS |
| 1895 | if (!sta->eapol_sm) { |
| 1896 | sta->eapol_sm = |
| 1897 | ieee802_1x_alloc_eapol_sm(hapd, sta); |
| 1898 | } |
| 1899 | wpa_printf(MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1900 | "FILS: Forward EAP-Initiate/Re-auth to authentication server"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1901 | ieee802_1x_encapsulate_radius( |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1902 | hapd, sta, elems.wrapped_data, |
| 1903 | elems.wrapped_data_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1904 | sta->fils_pending_cb = cb; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1905 | wpa_printf(MSG_DEBUG, |
| 1906 | "FILS: Will send Authentication frame once the response from authentication server is available"); |
| 1907 | sta->flags |= WLAN_STA_PENDING_FILS_ERP; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1908 | /* Calculate pending PMKID here so that we do not need |
| 1909 | * to maintain a copy of the EAP-Initiate/Reauth |
| 1910 | * message. */ |
| 1911 | if (fils_pmkid_erp(wpa_auth_sta_key_mgmt(sta->wpa_sm), |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1912 | elems.wrapped_data, |
| 1913 | elems.wrapped_data_len, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1914 | sta->fils_erp_pmkid) == 0) |
| 1915 | sta->fils_erp_pmkid_set = 1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1916 | return; |
| 1917 | #else /* CONFIG_NO_RADIUS */ |
| 1918 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1919 | goto fail; |
| 1920 | #endif /* CONFIG_NO_RADIUS */ |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | fail: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1925 | if (cb) { |
| 1926 | struct wpabuf *data; |
| 1927 | int pub = 0; |
| 1928 | |
| 1929 | data = prepare_auth_resp_fils(hapd, sta, &resp, pmksa, NULL, |
| 1930 | NULL, 0, &pub); |
| 1931 | if (!data) { |
| 1932 | wpa_printf(MSG_DEBUG, |
| 1933 | "%s: prepare_auth_resp_fils() returned failure", |
| 1934 | __func__); |
| 1935 | } |
| 1936 | |
| 1937 | cb(hapd, sta, resp, data, pub); |
| 1938 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1942 | static struct wpabuf * |
| 1943 | prepare_auth_resp_fils(struct hostapd_data *hapd, |
| 1944 | struct sta_info *sta, u16 *resp, |
| 1945 | struct rsn_pmksa_cache_entry *pmksa, |
| 1946 | struct wpabuf *erp_resp, |
| 1947 | const u8 *msk, size_t msk_len, |
| 1948 | int *is_pub) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1949 | { |
| 1950 | u8 fils_nonce[FILS_NONCE_LEN]; |
| 1951 | size_t ielen; |
| 1952 | struct wpabuf *data = NULL; |
| 1953 | const u8 *ie; |
| 1954 | u8 *ie_buf = NULL; |
| 1955 | const u8 *pmk = NULL; |
| 1956 | size_t pmk_len = 0; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1957 | u8 pmk_buf[PMK_LEN_MAX]; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1958 | struct wpabuf *pub = NULL; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1959 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1960 | if (*resp != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1961 | goto fail; |
| 1962 | |
| 1963 | ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &ielen); |
| 1964 | if (!ie) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1965 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1966 | goto fail; |
| 1967 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1968 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1969 | if (pmksa) { |
| 1970 | /* Add PMKID of the selected PMKSA into RSNE */ |
| 1971 | ie_buf = os_malloc(ielen + 2 + 2 + PMKID_LEN); |
| 1972 | if (!ie_buf) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1973 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1974 | goto fail; |
| 1975 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1976 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1977 | os_memcpy(ie_buf, ie, ielen); |
| 1978 | if (wpa_insert_pmkid(ie_buf, &ielen, pmksa->pmkid) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1979 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1980 | goto fail; |
| 1981 | } |
| 1982 | ie = ie_buf; |
| 1983 | } |
| 1984 | |
| 1985 | if (random_get_bytes(fils_nonce, FILS_NONCE_LEN) < 0) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1986 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1987 | goto fail; |
| 1988 | } |
| 1989 | wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS Nonce", |
| 1990 | fils_nonce, FILS_NONCE_LEN); |
| 1991 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1992 | #ifdef CONFIG_FILS_SK_PFS |
| 1993 | if (sta->fils_dh_ss && sta->fils_ecdh) { |
| 1994 | pub = crypto_ecdh_get_pubkey(sta->fils_ecdh, 1); |
| 1995 | if (!pub) { |
| 1996 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 1997 | goto fail; |
| 1998 | } |
| 1999 | } |
| 2000 | #endif /* CONFIG_FILS_SK_PFS */ |
| 2001 | |
| 2002 | data = wpabuf_alloc(1000 + ielen + (pub ? wpabuf_len(pub) : 0)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2003 | if (!data) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2004 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2005 | goto fail; |
| 2006 | } |
| 2007 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2008 | /* TODO: FILS PK */ |
| 2009 | #ifdef CONFIG_FILS_SK_PFS |
| 2010 | if (pub) { |
| 2011 | /* Finite Cyclic Group */ |
| 2012 | wpabuf_put_le16(data, hapd->conf->fils_dh_group); |
| 2013 | |
| 2014 | /* Element */ |
| 2015 | wpabuf_put_buf(data, pub); |
| 2016 | } |
| 2017 | #endif /* CONFIG_FILS_SK_PFS */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2018 | |
| 2019 | /* RSNE */ |
| 2020 | wpabuf_put_data(data, ie, ielen); |
| 2021 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2022 | /* MDE when using FILS+FT (already included in ie,ielen with RSNE) */ |
| 2023 | |
| 2024 | #ifdef CONFIG_IEEE80211R_AP |
| 2025 | if (wpa_key_mgmt_ft(wpa_auth_sta_key_mgmt(sta->wpa_sm))) { |
| 2026 | /* FTE[R1KH-ID,R0KH-ID] when using FILS+FT */ |
| 2027 | int res; |
| 2028 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2029 | res = wpa_auth_write_fte(hapd->wpa_auth, sta->wpa_sm, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2030 | wpabuf_put(data, 0), |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2031 | wpabuf_tailroom(data)); |
| 2032 | if (res < 0) { |
| 2033 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2034 | goto fail; |
| 2035 | } |
| 2036 | wpabuf_put(data, res); |
| 2037 | } |
| 2038 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2039 | |
| 2040 | /* FILS Nonce */ |
| 2041 | wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */ |
| 2042 | wpabuf_put_u8(data, 1 + FILS_NONCE_LEN); /* Length */ |
| 2043 | /* Element ID Extension */ |
| 2044 | wpabuf_put_u8(data, WLAN_EID_EXT_FILS_NONCE); |
| 2045 | wpabuf_put_data(data, fils_nonce, FILS_NONCE_LEN); |
| 2046 | |
| 2047 | /* FILS Session */ |
| 2048 | wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */ |
| 2049 | wpabuf_put_u8(data, 1 + FILS_SESSION_LEN); /* Length */ |
| 2050 | /* Element ID Extension */ |
| 2051 | wpabuf_put_u8(data, WLAN_EID_EXT_FILS_SESSION); |
| 2052 | wpabuf_put_data(data, sta->fils_session, FILS_SESSION_LEN); |
| 2053 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2054 | /* Wrapped Data */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2055 | if (!pmksa && erp_resp) { |
| 2056 | wpabuf_put_u8(data, WLAN_EID_EXTENSION); /* Element ID */ |
| 2057 | wpabuf_put_u8(data, 1 + wpabuf_len(erp_resp)); /* Length */ |
| 2058 | /* Element ID Extension */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2059 | wpabuf_put_u8(data, WLAN_EID_EXT_WRAPPED_DATA); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2060 | wpabuf_put_buf(data, erp_resp); |
| 2061 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2062 | if (fils_rmsk_to_pmk(wpa_auth_sta_key_mgmt(sta->wpa_sm), |
| 2063 | msk, msk_len, sta->fils_snonce, fils_nonce, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2064 | sta->fils_dh_ss ? |
| 2065 | wpabuf_head(sta->fils_dh_ss) : NULL, |
| 2066 | sta->fils_dh_ss ? |
| 2067 | wpabuf_len(sta->fils_dh_ss) : 0, |
| 2068 | pmk_buf, &pmk_len)) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2069 | wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2070 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2071 | wpabuf_free(data); |
| 2072 | data = NULL; |
| 2073 | goto fail; |
| 2074 | } |
| 2075 | pmk = pmk_buf; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2076 | |
| 2077 | /* Don't use DHss in PTK derivation if PMKSA caching is not |
| 2078 | * used. */ |
| 2079 | wpabuf_clear_free(sta->fils_dh_ss); |
| 2080 | sta->fils_dh_ss = NULL; |
| 2081 | |
| 2082 | if (sta->fils_erp_pmkid_set) { |
| 2083 | /* TODO: get PMKLifetime from WPA parameters */ |
| 2084 | unsigned int dot11RSNAConfigPMKLifetime = 43200; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2085 | int session_timeout; |
| 2086 | |
| 2087 | session_timeout = dot11RSNAConfigPMKLifetime; |
| 2088 | if (sta->session_timeout_set) { |
| 2089 | struct os_reltime now, diff; |
| 2090 | |
| 2091 | os_get_reltime(&now); |
| 2092 | os_reltime_sub(&sta->session_timeout, &now, |
| 2093 | &diff); |
| 2094 | session_timeout = diff.sec; |
| 2095 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2096 | |
| 2097 | sta->fils_erp_pmkid_set = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2098 | wpa_auth_add_fils_pmk_pmkid(sta->wpa_sm, pmk, pmk_len, |
| 2099 | sta->fils_erp_pmkid); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2100 | if (!hapd->conf->disable_pmksa_caching && |
| 2101 | wpa_auth_pmksa_add2( |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2102 | hapd->wpa_auth, sta->addr, |
| 2103 | pmk, pmk_len, |
| 2104 | sta->fils_erp_pmkid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2105 | session_timeout, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2106 | wpa_auth_sta_key_mgmt(sta->wpa_sm)) < 0) { |
| 2107 | wpa_printf(MSG_ERROR, |
| 2108 | "FILS: Failed to add PMKSA cache entry based on ERP"); |
| 2109 | } |
| 2110 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2111 | } else if (pmksa) { |
| 2112 | pmk = pmksa->pmk; |
| 2113 | pmk_len = pmksa->pmk_len; |
| 2114 | } |
| 2115 | |
| 2116 | if (!pmk) { |
| 2117 | wpa_printf(MSG_DEBUG, "FILS: No PMK available"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2118 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2119 | wpabuf_free(data); |
| 2120 | data = NULL; |
| 2121 | goto fail; |
| 2122 | } |
| 2123 | |
| 2124 | if (fils_auth_pmk_to_ptk(sta->wpa_sm, pmk, pmk_len, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2125 | sta->fils_snonce, fils_nonce, |
| 2126 | sta->fils_dh_ss ? |
| 2127 | wpabuf_head(sta->fils_dh_ss) : NULL, |
| 2128 | sta->fils_dh_ss ? |
| 2129 | wpabuf_len(sta->fils_dh_ss) : 0, |
| 2130 | sta->fils_g_sta, pub) < 0) { |
| 2131 | *resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2132 | wpabuf_free(data); |
| 2133 | data = NULL; |
| 2134 | goto fail; |
| 2135 | } |
| 2136 | |
| 2137 | fail: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2138 | if (is_pub) |
| 2139 | *is_pub = pub != NULL; |
| 2140 | os_free(ie_buf); |
| 2141 | wpabuf_free(pub); |
| 2142 | wpabuf_clear_free(sta->fils_dh_ss); |
| 2143 | sta->fils_dh_ss = NULL; |
| 2144 | #ifdef CONFIG_FILS_SK_PFS |
| 2145 | crypto_ecdh_deinit(sta->fils_ecdh); |
| 2146 | sta->fils_ecdh = NULL; |
| 2147 | #endif /* CONFIG_FILS_SK_PFS */ |
| 2148 | return data; |
| 2149 | } |
| 2150 | |
| 2151 | |
| 2152 | static void handle_auth_fils_finish(struct hostapd_data *hapd, |
| 2153 | struct sta_info *sta, u16 resp, |
| 2154 | struct wpabuf *data, int pub) |
| 2155 | { |
| 2156 | u16 auth_alg; |
| 2157 | |
| 2158 | auth_alg = (pub || |
| 2159 | resp == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) ? |
| 2160 | WLAN_AUTH_FILS_SK_PFS : WLAN_AUTH_FILS_SK; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2161 | 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] | 2162 | data ? wpabuf_head(data) : (u8 *) "", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2163 | data ? wpabuf_len(data) : 0, "auth-fils-finish"); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2164 | wpabuf_free(data); |
| 2165 | |
| 2166 | if (resp == WLAN_STATUS_SUCCESS) { |
| 2167 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 2168 | HOSTAPD_LEVEL_DEBUG, |
| 2169 | "authentication OK (FILS)"); |
| 2170 | sta->flags |= WLAN_STA_AUTH; |
| 2171 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2172 | 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] | 2173 | mlme_authenticate_indication(hapd, sta); |
| 2174 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2175 | } |
| 2176 | |
| 2177 | |
| 2178 | void ieee802_11_finish_fils_auth(struct hostapd_data *hapd, |
| 2179 | struct sta_info *sta, int success, |
| 2180 | struct wpabuf *erp_resp, |
| 2181 | const u8 *msk, size_t msk_len) |
| 2182 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2183 | u16 resp; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2184 | u32 flags = sta->flags; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2185 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2186 | sta->flags &= ~(WLAN_STA_PENDING_FILS_ERP | |
| 2187 | WLAN_STA_PENDING_PASN_FILS_ERP); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2188 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2189 | resp = success ? WLAN_STATUS_SUCCESS : WLAN_STATUS_UNSPECIFIED_FAILURE; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2190 | |
| 2191 | if (flags & WLAN_STA_PENDING_FILS_ERP) { |
| 2192 | struct wpabuf *data; |
| 2193 | int pub = 0; |
| 2194 | |
| 2195 | if (!sta->fils_pending_cb) |
| 2196 | return; |
| 2197 | |
| 2198 | data = prepare_auth_resp_fils(hapd, sta, &resp, NULL, erp_resp, |
| 2199 | msk, msk_len, &pub); |
| 2200 | if (!data) { |
| 2201 | wpa_printf(MSG_DEBUG, |
| 2202 | "%s: prepare_auth_resp_fils() failure", |
| 2203 | __func__); |
| 2204 | } |
| 2205 | sta->fils_pending_cb(hapd, sta, resp, data, pub); |
| 2206 | #ifdef CONFIG_PASN |
| 2207 | } else if (flags & WLAN_STA_PENDING_PASN_FILS_ERP) { |
| 2208 | pasn_fils_auth_resp(hapd, sta, resp, erp_resp, |
| 2209 | msk, msk_len); |
| 2210 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2211 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2212 | } |
| 2213 | |
| 2214 | #endif /* CONFIG_FILS */ |
| 2215 | |
| 2216 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2217 | static int ieee802_11_allowed_address(struct hostapd_data *hapd, const u8 *addr, |
| 2218 | const u8 *msg, size_t len, |
| 2219 | struct radius_sta *info) |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2220 | { |
| 2221 | int res; |
| 2222 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2223 | res = hostapd_allowed_address(hapd, addr, msg, len, info, 0); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2224 | |
| 2225 | if (res == HOSTAPD_ACL_REJECT) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2226 | wpa_printf(MSG_DEBUG, "Station " MACSTR |
| 2227 | " not allowed to authenticate", |
| 2228 | MAC2STR(addr)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2229 | return HOSTAPD_ACL_REJECT; |
| 2230 | } |
| 2231 | |
| 2232 | if (res == HOSTAPD_ACL_PENDING) { |
| 2233 | wpa_printf(MSG_DEBUG, "Authentication frame from " MACSTR |
| 2234 | " waiting for an external authentication", |
| 2235 | MAC2STR(addr)); |
| 2236 | /* Authentication code will re-send the authentication frame |
| 2237 | * after it has received (and cached) information from the |
| 2238 | * external source. */ |
| 2239 | return HOSTAPD_ACL_PENDING; |
| 2240 | } |
| 2241 | |
| 2242 | return res; |
| 2243 | } |
| 2244 | |
| 2245 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2246 | int ieee802_11_set_radius_info(struct hostapd_data *hapd, struct sta_info *sta, |
| 2247 | int res, struct radius_sta *info) |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2248 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2249 | u32 session_timeout = info->session_timeout; |
| 2250 | u32 acct_interim_interval = info->acct_interim_interval; |
| 2251 | struct vlan_description *vlan_id = &info->vlan_id; |
| 2252 | struct hostapd_sta_wpa_psk_short *psk = info->psk; |
| 2253 | char *identity = info->identity; |
| 2254 | char *radius_cui = info->radius_cui; |
| 2255 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2256 | if (vlan_id->notempty && |
| 2257 | !hostapd_vlan_valid(hapd->conf->vlan, vlan_id)) { |
| 2258 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 2259 | HOSTAPD_LEVEL_INFO, |
| 2260 | "Invalid VLAN %d%s received from RADIUS server", |
| 2261 | vlan_id->untagged, |
| 2262 | vlan_id->tagged[0] ? "+" : ""); |
| 2263 | return -1; |
| 2264 | } |
| 2265 | if (ap_sta_set_vlan(hapd, sta, vlan_id) < 0) |
| 2266 | return -1; |
| 2267 | if (sta->vlan_id) |
| 2268 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_RADIUS, |
| 2269 | HOSTAPD_LEVEL_INFO, "VLAN ID %d", sta->vlan_id); |
| 2270 | |
| 2271 | hostapd_free_psk_list(sta->psk); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2272 | if (hapd->conf->wpa_psk_radius != PSK_RADIUS_IGNORED) |
| 2273 | hostapd_copy_psk_list(&sta->psk, psk); |
| 2274 | else |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2275 | sta->psk = NULL; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2276 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2277 | os_free(sta->identity); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2278 | if (identity) |
| 2279 | sta->identity = os_strdup(identity); |
| 2280 | else |
| 2281 | sta->identity = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2282 | |
| 2283 | os_free(sta->radius_cui); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2284 | if (radius_cui) |
| 2285 | sta->radius_cui = os_strdup(radius_cui); |
| 2286 | else |
| 2287 | sta->radius_cui = NULL; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2288 | |
| 2289 | if (hapd->conf->acct_interim_interval == 0 && acct_interim_interval) |
| 2290 | sta->acct_interim_interval = acct_interim_interval; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2291 | if (res == HOSTAPD_ACL_ACCEPT_TIMEOUT) { |
| 2292 | sta->session_timeout_set = 1; |
| 2293 | os_get_reltime(&sta->session_timeout); |
| 2294 | sta->session_timeout.sec += session_timeout; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2295 | ap_sta_session_timeout(hapd, sta, session_timeout); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2296 | } else { |
| 2297 | sta->session_timeout_set = 0; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2298 | ap_sta_no_session_timeout(hapd, sta); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2299 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2300 | |
| 2301 | return 0; |
| 2302 | } |
| 2303 | |
| 2304 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2305 | #ifdef CONFIG_PASN |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2306 | #ifdef CONFIG_FILS |
| 2307 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2308 | static void pasn_fils_auth_resp(struct hostapd_data *hapd, |
| 2309 | struct sta_info *sta, u16 status, |
| 2310 | struct wpabuf *erp_resp, |
| 2311 | const u8 *msk, size_t msk_len) |
| 2312 | { |
| 2313 | struct pasn_data *pasn = sta->pasn; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2314 | struct pasn_fils *fils = &pasn->fils; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2315 | u8 pmk[PMK_LEN_MAX]; |
| 2316 | size_t pmk_len; |
| 2317 | int ret; |
| 2318 | |
| 2319 | wpa_printf(MSG_DEBUG, "PASN: FILS: Handle AS response - status=%u", |
| 2320 | status); |
| 2321 | |
| 2322 | if (status != WLAN_STATUS_SUCCESS) |
| 2323 | goto fail; |
| 2324 | |
| 2325 | if (!pasn->secret) { |
| 2326 | wpa_printf(MSG_DEBUG, "PASN: FILS: Missing secret"); |
| 2327 | goto fail; |
| 2328 | } |
| 2329 | |
| 2330 | if (random_get_bytes(fils->anonce, FILS_NONCE_LEN) < 0) { |
| 2331 | wpa_printf(MSG_DEBUG, "PASN: FILS: Failed to get ANonce"); |
| 2332 | goto fail; |
| 2333 | } |
| 2334 | |
| 2335 | wpa_hexdump(MSG_DEBUG, "RSN: Generated FILS ANonce", |
| 2336 | fils->anonce, FILS_NONCE_LEN); |
| 2337 | |
| 2338 | ret = fils_rmsk_to_pmk(pasn->akmp, msk, msk_len, fils->nonce, |
| 2339 | fils->anonce, NULL, 0, pmk, &pmk_len); |
| 2340 | if (ret) { |
| 2341 | wpa_printf(MSG_DEBUG, "FILS: Failed to derive PMK"); |
| 2342 | goto fail; |
| 2343 | } |
| 2344 | |
| 2345 | ret = pasn_pmk_to_ptk(pmk, pmk_len, sta->addr, hapd->own_addr, |
| 2346 | wpabuf_head(pasn->secret), |
| 2347 | wpabuf_len(pasn->secret), |
| 2348 | &sta->pasn->ptk, sta->pasn->akmp, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2349 | sta->pasn->cipher, sta->pasn->kdk_len); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2350 | if (ret) { |
| 2351 | wpa_printf(MSG_DEBUG, "PASN: FILS: Failed to derive PTK"); |
| 2352 | goto fail; |
| 2353 | } |
| 2354 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2355 | if (pasn->secure_ltf) { |
| 2356 | ret = wpa_ltf_keyseed(&pasn->ptk, pasn->akmp, pasn->cipher); |
| 2357 | if (ret) { |
| 2358 | wpa_printf(MSG_DEBUG, |
| 2359 | "PASN: FILS: Failed to derive LTF keyseed"); |
| 2360 | goto fail; |
| 2361 | } |
| 2362 | } |
| 2363 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2364 | wpa_printf(MSG_DEBUG, "PASN: PTK successfully derived"); |
| 2365 | |
| 2366 | wpabuf_free(pasn->secret); |
| 2367 | pasn->secret = NULL; |
| 2368 | |
| 2369 | fils->erp_resp = erp_resp; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2370 | ret = handle_auth_pasn_resp(sta->pasn, hapd->own_addr, sta->addr, NULL, |
| 2371 | WLAN_STATUS_SUCCESS); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2372 | fils->erp_resp = NULL; |
| 2373 | |
| 2374 | if (ret) { |
| 2375 | wpa_printf(MSG_DEBUG, "PASN: FILS: Failed to send response"); |
| 2376 | goto fail; |
| 2377 | } |
| 2378 | |
| 2379 | fils->state = PASN_FILS_STATE_COMPLETE; |
| 2380 | return; |
| 2381 | fail: |
| 2382 | ap_free_sta(hapd, sta); |
| 2383 | } |
| 2384 | |
| 2385 | |
| 2386 | static int pasn_wd_handle_fils(struct hostapd_data *hapd, struct sta_info *sta, |
| 2387 | struct wpabuf *wd) |
| 2388 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2389 | #ifdef CONFIG_NO_RADIUS |
| 2390 | wpa_printf(MSG_DEBUG, "PASN: FILS: RADIUS is not configured. Fail"); |
| 2391 | return -1; |
| 2392 | #else /* CONFIG_NO_RADIUS */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2393 | struct pasn_data *pasn = sta->pasn; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2394 | struct pasn_fils *fils = &pasn->fils; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2395 | struct ieee802_11_elems elems; |
| 2396 | struct wpa_ie_data rsne_data; |
| 2397 | struct wpabuf *fils_wd; |
| 2398 | const u8 *data; |
| 2399 | size_t buf_len; |
| 2400 | u16 alg, seq, status; |
| 2401 | int ret; |
| 2402 | |
| 2403 | if (fils->state != PASN_FILS_STATE_NONE) { |
| 2404 | wpa_printf(MSG_DEBUG, "PASN: FILS: Not expecting wrapped data"); |
| 2405 | return -1; |
| 2406 | } |
| 2407 | |
| 2408 | if (!wd) { |
| 2409 | wpa_printf(MSG_DEBUG, "PASN: FILS: No wrapped data"); |
| 2410 | return -1; |
| 2411 | } |
| 2412 | |
| 2413 | data = wpabuf_head_u8(wd); |
| 2414 | buf_len = wpabuf_len(wd); |
| 2415 | |
| 2416 | if (buf_len < 6) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2417 | wpa_printf(MSG_DEBUG, "PASN: FILS: Buffer too short. len=%zu", |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2418 | buf_len); |
| 2419 | return -1; |
| 2420 | } |
| 2421 | |
| 2422 | alg = WPA_GET_LE16(data); |
| 2423 | seq = WPA_GET_LE16(data + 2); |
| 2424 | status = WPA_GET_LE16(data + 4); |
| 2425 | |
| 2426 | wpa_printf(MSG_DEBUG, "PASN: FILS: alg=%u, seq=%u, status=%u", |
| 2427 | alg, seq, status); |
| 2428 | |
| 2429 | if (alg != WLAN_AUTH_FILS_SK || seq != 1 || |
| 2430 | status != WLAN_STATUS_SUCCESS) { |
| 2431 | wpa_printf(MSG_DEBUG, |
| 2432 | "PASN: FILS: Dropping peer authentication"); |
| 2433 | return -1; |
| 2434 | } |
| 2435 | |
| 2436 | data += 6; |
| 2437 | buf_len -= 6; |
| 2438 | |
| 2439 | if (ieee802_11_parse_elems(data, buf_len, &elems, 1) == ParseFailed) { |
| 2440 | wpa_printf(MSG_DEBUG, "PASN: FILS: Could not parse elements"); |
| 2441 | return -1; |
| 2442 | } |
| 2443 | |
| 2444 | if (!elems.rsn_ie || !elems.fils_nonce || !elems.fils_nonce || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2445 | !elems.wrapped_data || !elems.fils_session) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2446 | wpa_printf(MSG_DEBUG, "PASN: FILS: Missing IEs"); |
| 2447 | return -1; |
| 2448 | } |
| 2449 | |
| 2450 | ret = wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
| 2451 | &rsne_data); |
| 2452 | if (ret) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2453 | wpa_printf(MSG_DEBUG, "PASN: FILS: Failed parsing RSNE"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2454 | return -1; |
| 2455 | } |
| 2456 | |
| 2457 | ret = wpa_pasn_validate_rsne(&rsne_data); |
| 2458 | if (ret) { |
| 2459 | wpa_printf(MSG_DEBUG, "PASN: FILS: Failed validating RSNE"); |
| 2460 | return -1; |
| 2461 | } |
| 2462 | |
| 2463 | if (rsne_data.num_pmkid) { |
| 2464 | wpa_printf(MSG_DEBUG, |
| 2465 | "PASN: FILS: Not expecting PMKID in RSNE"); |
| 2466 | return -1; |
| 2467 | } |
| 2468 | |
| 2469 | wpa_hexdump(MSG_DEBUG, "PASN: FILS: Nonce", elems.fils_nonce, |
| 2470 | FILS_NONCE_LEN); |
| 2471 | os_memcpy(fils->nonce, elems.fils_nonce, FILS_NONCE_LEN); |
| 2472 | |
| 2473 | wpa_hexdump(MSG_DEBUG, "PASN: FILS: Session", elems.fils_session, |
| 2474 | FILS_SESSION_LEN); |
| 2475 | os_memcpy(fils->session, elems.fils_session, FILS_SESSION_LEN); |
| 2476 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2477 | fils_wd = ieee802_11_defrag(&elems, WLAN_EID_EXTENSION, |
| 2478 | WLAN_EID_EXT_WRAPPED_DATA); |
| 2479 | |
| 2480 | if (!fils_wd) { |
| 2481 | wpa_printf(MSG_DEBUG, "PASN: FILS: Missing wrapped data"); |
| 2482 | return -1; |
| 2483 | } |
| 2484 | |
| 2485 | if (!sta->eapol_sm) |
| 2486 | sta->eapol_sm = ieee802_1x_alloc_eapol_sm(hapd, sta); |
| 2487 | |
| 2488 | wpa_printf(MSG_DEBUG, |
| 2489 | "PASN: FILS: Forward EAP-Initiate/Re-auth to AS"); |
| 2490 | |
| 2491 | ieee802_1x_encapsulate_radius(hapd, sta, wpabuf_head(fils_wd), |
| 2492 | wpabuf_len(fils_wd)); |
| 2493 | |
| 2494 | sta->flags |= WLAN_STA_PENDING_PASN_FILS_ERP; |
| 2495 | |
| 2496 | fils->state = PASN_FILS_STATE_PENDING_AS; |
| 2497 | |
| 2498 | /* |
| 2499 | * Calculate pending PMKID here so that we do not need to maintain a |
| 2500 | * copy of the EAP-Initiate/Reautt message. |
| 2501 | */ |
| 2502 | fils_pmkid_erp(pasn->akmp, wpabuf_head(fils_wd), wpabuf_len(fils_wd), |
| 2503 | fils->erp_pmkid); |
| 2504 | |
| 2505 | wpabuf_free(fils_wd); |
| 2506 | return 0; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2507 | #endif /* CONFIG_NO_RADIUS */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2508 | } |
| 2509 | |
| 2510 | #endif /* CONFIG_FILS */ |
| 2511 | |
| 2512 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2513 | static int hapd_pasn_send_mlme(void *ctx, const u8 *data, size_t data_len, |
| 2514 | int noack, unsigned int freq, unsigned int wait) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2515 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2516 | struct hostapd_data *hapd = ctx; |
| 2517 | |
| 2518 | return hostapd_drv_send_mlme(hapd, data, data_len, 0, NULL, 0, 0); |
| 2519 | } |
| 2520 | |
| 2521 | |
| 2522 | static void hapd_initialize_pasn(struct hostapd_data *hapd, |
| 2523 | struct sta_info *sta) |
| 2524 | { |
| 2525 | struct pasn_data *pasn = sta->pasn; |
| 2526 | |
| 2527 | pasn->cb_ctx = hapd; |
| 2528 | pasn->send_mgmt = hapd_pasn_send_mlme; |
| 2529 | pasn->pasn_groups = hapd->conf->pasn_groups; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 2530 | pasn->noauth = hapd->conf->pasn_noauth; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2531 | pasn->wpa_key_mgmt = hapd->conf->wpa_key_mgmt; |
| 2532 | pasn->rsn_pairwise = hapd->conf->rsn_pairwise; |
| 2533 | pasn->derive_kdk = hapd->iface->drv_flags2 & |
| 2534 | WPA_DRIVER_FLAGS2_SEC_LTF_AP; |
| 2535 | #ifdef CONFIG_TESTING_OPTIONS |
| 2536 | pasn->corrupt_mic = hapd->conf->pasn_corrupt_mic; |
| 2537 | if (hapd->conf->force_kdk_derivation) |
| 2538 | pasn->derive_kdk = true; |
| 2539 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2540 | pasn->use_anti_clogging = use_anti_clogging(hapd); |
| 2541 | pasn->password = sae_get_password(hapd, sta, NULL, NULL, &pasn->pt, |
| 2542 | NULL); |
| 2543 | pasn->rsn_ie = wpa_auth_get_wpa_ie(hapd->wpa_auth, &pasn->rsn_ie_len); |
| 2544 | pasn->rsnxe_ie = hostapd_wpa_ie(hapd, WLAN_EID_RSNX); |
| 2545 | pasn->disable_pmksa_caching = hapd->conf->disable_pmksa_caching; |
| 2546 | pasn->pmksa = wpa_auth_get_pmksa_cache(hapd->wpa_auth); |
| 2547 | |
| 2548 | pasn->comeback_after = hapd->conf->pasn_comeback_after; |
| 2549 | pasn->comeback_idx = hapd->comeback_idx; |
| 2550 | pasn->comeback_key = hapd->comeback_key; |
| 2551 | pasn->comeback_pending_idx = hapd->comeback_pending_idx; |
| 2552 | os_memcpy(pasn->bssid, hapd->own_addr, ETH_ALEN); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2556 | static int pasn_set_keys_from_cache(struct hostapd_data *hapd, |
| 2557 | const u8 *own_addr, const u8 *sta_addr, |
| 2558 | int cipher, int akmp) |
| 2559 | { |
| 2560 | struct ptksa_cache_entry *entry; |
| 2561 | |
| 2562 | entry = ptksa_cache_get(hapd->ptksa, sta_addr, cipher); |
| 2563 | if (!entry) { |
| 2564 | wpa_printf(MSG_DEBUG, "PASN: peer " MACSTR |
| 2565 | " not present in PTKSA cache", MAC2STR(sta_addr)); |
| 2566 | return -1; |
| 2567 | } |
| 2568 | |
| 2569 | if (os_memcmp(entry->own_addr, own_addr, ETH_ALEN) != 0) { |
| 2570 | wpa_printf(MSG_DEBUG, |
| 2571 | "PASN: own addr " MACSTR " and PTKSA entry own addr " |
| 2572 | MACSTR " differ", |
| 2573 | MAC2STR(own_addr), MAC2STR(entry->own_addr)); |
| 2574 | return -1; |
| 2575 | } |
| 2576 | |
| 2577 | wpa_printf(MSG_DEBUG, "PASN: " MACSTR " present in PTKSA cache", |
| 2578 | MAC2STR(sta_addr)); |
| 2579 | hostapd_drv_set_secure_ranging_ctx(hapd, own_addr, sta_addr, cipher, |
| 2580 | entry->ptk.tk_len, entry->ptk.tk, |
| 2581 | entry->ptk.ltf_keyseed_len, |
| 2582 | entry->ptk.ltf_keyseed, 0); |
| 2583 | |
| 2584 | return 0; |
| 2585 | } |
| 2586 | |
| 2587 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2588 | static void hapd_pasn_update_params(struct hostapd_data *hapd, |
| 2589 | struct sta_info *sta, |
| 2590 | const struct ieee80211_mgmt *mgmt, |
| 2591 | size_t len) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2592 | { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2593 | struct pasn_data *pasn = sta->pasn; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2594 | struct ieee802_11_elems elems; |
| 2595 | struct wpa_ie_data rsn_data; |
| 2596 | struct wpa_pasn_params_data pasn_params; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2597 | struct wpabuf *wrapped_data = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2598 | |
| 2599 | if (ieee802_11_parse_elems(mgmt->u.auth.variable, |
| 2600 | len - offsetof(struct ieee80211_mgmt, |
| 2601 | u.auth.variable), |
| 2602 | &elems, 0) == ParseFailed) { |
| 2603 | wpa_printf(MSG_DEBUG, |
| 2604 | "PASN: Failed parsing Authentication frame"); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2605 | return; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2606 | } |
| 2607 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2608 | if (!elems.rsn_ie || |
| 2609 | wpa_parse_wpa_ie_rsn(elems.rsn_ie - 2, elems.rsn_ie_len + 2, |
| 2610 | &rsn_data)) { |
| 2611 | wpa_printf(MSG_DEBUG, "PASN: Failed parsing RSNE"); |
| 2612 | return; |
| 2613 | } |
| 2614 | |
| 2615 | if (!(rsn_data.key_mgmt & pasn->wpa_key_mgmt) || |
| 2616 | !(rsn_data.pairwise_cipher & pasn->rsn_pairwise)) { |
| 2617 | wpa_printf(MSG_DEBUG, "PASN: Mismatch in AKMP/cipher"); |
| 2618 | return; |
| 2619 | } |
| 2620 | |
| 2621 | pasn->akmp = rsn_data.key_mgmt; |
| 2622 | pasn->cipher = rsn_data.pairwise_cipher; |
| 2623 | |
| 2624 | if (wpa_key_mgmt_ft(pasn->akmp) && rsn_data.num_pmkid) { |
| 2625 | #ifdef CONFIG_IEEE80211R_AP |
| 2626 | pasn->pmk_r1_len = 0; |
| 2627 | wpa_ft_fetch_pmk_r1(hapd->wpa_auth, sta->addr, |
| 2628 | rsn_data.pmkid, |
| 2629 | pasn->pmk_r1, &pasn->pmk_r1_len, NULL, |
| 2630 | NULL, NULL, NULL, |
| 2631 | NULL, NULL, NULL); |
| 2632 | #endif /* CONFIG_IEEE80211R_AP */ |
| 2633 | } |
| 2634 | #ifdef CONFIG_FILS |
| 2635 | if (pasn->akmp != WPA_KEY_MGMT_FILS_SHA256 && |
| 2636 | pasn->akmp != WPA_KEY_MGMT_FILS_SHA384) |
| 2637 | return; |
| 2638 | if (!elems.pasn_params || |
| 2639 | wpa_pasn_parse_parameter_ie(elems.pasn_params - 3, |
| 2640 | elems.pasn_params_len + 3, |
| 2641 | false, &pasn_params)) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2642 | wpa_printf(MSG_DEBUG, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2643 | "PASN: Failed validation of PASN Parameters element"); |
| 2644 | return; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2645 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2646 | if (pasn_params.wrapped_data_format != WPA_PASN_WRAPPED_DATA_NO) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2647 | wrapped_data = ieee802_11_defrag(&elems, WLAN_EID_EXTENSION, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2648 | WLAN_EID_EXT_WRAPPED_DATA); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2649 | if (!wrapped_data) { |
| 2650 | wpa_printf(MSG_DEBUG, "PASN: Missing wrapped data"); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2651 | return; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2652 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2653 | if (pasn_wd_handle_fils(hapd, sta, wrapped_data)) |
| 2654 | wpa_printf(MSG_DEBUG, |
| 2655 | "PASN: Failed processing FILS wrapped data"); |
| 2656 | else |
| 2657 | pasn->fils_wd_valid = true; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2658 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2659 | wpabuf_free(wrapped_data); |
| 2660 | #endif /* CONFIG_FILS */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | |
| 2664 | static void handle_auth_pasn(struct hostapd_data *hapd, struct sta_info *sta, |
| 2665 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 2666 | u16 trans_seq, u16 status) |
| 2667 | { |
| 2668 | if (hapd->conf->wpa != WPA_PROTO_RSN) { |
| 2669 | wpa_printf(MSG_INFO, "PASN: RSN is not configured"); |
| 2670 | return; |
| 2671 | } |
| 2672 | |
| 2673 | wpa_printf(MSG_INFO, "PASN authentication: sta=" MACSTR, |
| 2674 | MAC2STR(sta->addr)); |
| 2675 | |
| 2676 | if (trans_seq == 1) { |
| 2677 | if (sta->pasn) { |
| 2678 | wpa_printf(MSG_DEBUG, |
| 2679 | "PASN: Not expecting transaction == 1"); |
| 2680 | return; |
| 2681 | } |
| 2682 | |
| 2683 | if (status != WLAN_STATUS_SUCCESS) { |
| 2684 | wpa_printf(MSG_DEBUG, |
| 2685 | "PASN: Failure status in transaction == 1"); |
| 2686 | return; |
| 2687 | } |
| 2688 | |
| 2689 | sta->pasn = os_zalloc(sizeof(*sta->pasn)); |
| 2690 | if (!sta->pasn) { |
| 2691 | wpa_printf(MSG_DEBUG, |
| 2692 | "PASN: Failed to allocate PASN context"); |
| 2693 | return; |
| 2694 | } |
| 2695 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2696 | hapd_initialize_pasn(hapd, sta); |
| 2697 | |
| 2698 | hapd_pasn_update_params(hapd, sta, mgmt, len); |
| 2699 | if (handle_auth_pasn_1(sta->pasn, hapd->own_addr, |
| 2700 | sta->addr, mgmt, len) < 0) |
| 2701 | ap_free_sta(hapd, sta); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2702 | } else if (trans_seq == 3) { |
| 2703 | if (!sta->pasn) { |
| 2704 | wpa_printf(MSG_DEBUG, |
| 2705 | "PASN: Not expecting transaction == 3"); |
| 2706 | return; |
| 2707 | } |
| 2708 | |
| 2709 | if (status != WLAN_STATUS_SUCCESS) { |
| 2710 | wpa_printf(MSG_DEBUG, |
| 2711 | "PASN: Failure status in transaction == 3"); |
| 2712 | ap_free_sta_pasn(hapd, sta); |
| 2713 | return; |
| 2714 | } |
| 2715 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2716 | if (handle_auth_pasn_3(sta->pasn, hapd->own_addr, |
| 2717 | sta->addr, mgmt, len) == 0) { |
| 2718 | ptksa_cache_add(hapd->ptksa, hapd->own_addr, sta->addr, |
| 2719 | sta->pasn->cipher, 43200, |
| 2720 | &sta->pasn->ptk, NULL, NULL, |
| 2721 | sta->pasn->akmp); |
| 2722 | |
| 2723 | pasn_set_keys_from_cache(hapd, hapd->own_addr, |
| 2724 | sta->addr, sta->pasn->cipher, |
| 2725 | sta->pasn->akmp); |
| 2726 | } |
| 2727 | ap_free_sta(hapd, sta); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2728 | } else { |
| 2729 | wpa_printf(MSG_DEBUG, |
| 2730 | "PASN: Invalid transaction %u - ignore", trans_seq); |
| 2731 | } |
| 2732 | } |
| 2733 | |
| 2734 | #endif /* CONFIG_PASN */ |
| 2735 | |
| 2736 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2737 | static void handle_auth(struct hostapd_data *hapd, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2738 | const struct ieee80211_mgmt *mgmt, size_t len, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2739 | int rssi, int from_queue) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2740 | { |
| 2741 | u16 auth_alg, auth_transaction, status_code; |
| 2742 | u16 resp = WLAN_STATUS_SUCCESS; |
| 2743 | struct sta_info *sta = NULL; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2744 | int res, reply_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2745 | u16 fc; |
| 2746 | const u8 *challenge = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2747 | u8 resp_ies[2 + WLAN_AUTH_CHALLENGE_LEN]; |
| 2748 | size_t resp_ies_len = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2749 | u16 seq_ctrl; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2750 | struct radius_sta rad_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2751 | |
| 2752 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2753 | wpa_printf(MSG_INFO, "handle_auth - too short payload (len=%lu)", |
| 2754 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2755 | return; |
| 2756 | } |
| 2757 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2758 | #ifdef CONFIG_TESTING_OPTIONS |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2759 | if (hapd->iconf->ignore_auth_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2760 | drand48() < hapd->iconf->ignore_auth_probability) { |
| 2761 | wpa_printf(MSG_INFO, |
| 2762 | "TESTING: ignoring auth frame from " MACSTR, |
| 2763 | MAC2STR(mgmt->sa)); |
| 2764 | return; |
| 2765 | } |
| 2766 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2767 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2768 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 2769 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 2770 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 2771 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2772 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2773 | |
| 2774 | if (len >= IEEE80211_HDRLEN + sizeof(mgmt->u.auth) + |
| 2775 | 2 + WLAN_AUTH_CHALLENGE_LEN && |
| 2776 | mgmt->u.auth.variable[0] == WLAN_EID_CHALLENGE && |
| 2777 | mgmt->u.auth.variable[1] == WLAN_AUTH_CHALLENGE_LEN) |
| 2778 | challenge = &mgmt->u.auth.variable[2]; |
| 2779 | |
| 2780 | wpa_printf(MSG_DEBUG, "authentication: STA=" MACSTR " auth_alg=%d " |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2781 | "auth_transaction=%d status_code=%d wep=%d%s " |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2782 | "seq_ctrl=0x%x%s%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2783 | MAC2STR(mgmt->sa), auth_alg, auth_transaction, |
| 2784 | status_code, !!(fc & WLAN_FC_ISWEP), |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2785 | challenge ? " challenge" : "", |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2786 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : "", |
| 2787 | from_queue ? " (from queue)" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2788 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2789 | #ifdef CONFIG_NO_RC4 |
| 2790 | if (auth_alg == WLAN_AUTH_SHARED_KEY) { |
| 2791 | wpa_printf(MSG_INFO, |
| 2792 | "Unsupported authentication algorithm (%d)", |
| 2793 | auth_alg); |
| 2794 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 2795 | goto fail; |
| 2796 | } |
| 2797 | #endif /* CONFIG_NO_RC4 */ |
| 2798 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2799 | if (hapd->tkip_countermeasures) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2800 | wpa_printf(MSG_DEBUG, |
| 2801 | "Ongoing TKIP countermeasures (Michael MIC failure) - reject authentication"); |
| 2802 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2803 | goto fail; |
| 2804 | } |
| 2805 | |
| 2806 | if (!(((hapd->conf->auth_algs & WPA_AUTH_ALG_OPEN) && |
| 2807 | auth_alg == WLAN_AUTH_OPEN) || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2808 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2809 | (hapd->conf->wpa && wpa_key_mgmt_ft(hapd->conf->wpa_key_mgmt) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | auth_alg == WLAN_AUTH_FT) || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2811 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2812 | #ifdef CONFIG_SAE |
| 2813 | (hapd->conf->wpa && wpa_key_mgmt_sae(hapd->conf->wpa_key_mgmt) && |
| 2814 | auth_alg == WLAN_AUTH_SAE) || |
| 2815 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2816 | #ifdef CONFIG_FILS |
| 2817 | (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) && |
| 2818 | auth_alg == WLAN_AUTH_FILS_SK) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2819 | (hapd->conf->wpa && wpa_key_mgmt_fils(hapd->conf->wpa_key_mgmt) && |
| 2820 | hapd->conf->fils_dh_group && |
| 2821 | auth_alg == WLAN_AUTH_FILS_SK_PFS) || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2822 | #endif /* CONFIG_FILS */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2823 | #ifdef CONFIG_PASN |
| 2824 | (hapd->conf->wpa && |
| 2825 | (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_PASN) && |
| 2826 | auth_alg == WLAN_AUTH_PASN) || |
| 2827 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2828 | ((hapd->conf->auth_algs & WPA_AUTH_ALG_SHARED) && |
| 2829 | auth_alg == WLAN_AUTH_SHARED_KEY))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2830 | wpa_printf(MSG_INFO, "Unsupported authentication algorithm (%d)", |
| 2831 | auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2832 | resp = WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 2833 | goto fail; |
| 2834 | } |
| 2835 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2836 | if (!(auth_transaction == 1 || auth_alg == WLAN_AUTH_SAE || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2837 | #ifdef CONFIG_PASN |
| 2838 | (auth_alg == WLAN_AUTH_PASN && auth_transaction == 3) || |
| 2839 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2840 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 3))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2841 | wpa_printf(MSG_INFO, "Unknown authentication transaction number (%d)", |
| 2842 | auth_transaction); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2843 | resp = WLAN_STATUS_UNKNOWN_AUTH_TRANSACTION; |
| 2844 | goto fail; |
| 2845 | } |
| 2846 | |
| 2847 | if (os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2848 | wpa_printf(MSG_INFO, "Station " MACSTR " not allowed to authenticate", |
| 2849 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2850 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2851 | goto fail; |
| 2852 | } |
| 2853 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2854 | if (hapd->conf->no_auth_if_seen_on) { |
| 2855 | struct hostapd_data *other; |
| 2856 | |
| 2857 | other = sta_track_seen_on(hapd->iface, mgmt->sa, |
| 2858 | hapd->conf->no_auth_if_seen_on); |
| 2859 | if (other) { |
| 2860 | u8 *pos; |
| 2861 | u32 info; |
| 2862 | u8 op_class, channel, phytype; |
| 2863 | |
| 2864 | wpa_printf(MSG_DEBUG, "%s: Reject authentication from " |
| 2865 | MACSTR " since STA has been seen on %s", |
| 2866 | hapd->conf->iface, MAC2STR(mgmt->sa), |
| 2867 | hapd->conf->no_auth_if_seen_on); |
| 2868 | |
| 2869 | resp = WLAN_STATUS_REJECTED_WITH_SUGGESTED_BSS_TRANSITION; |
| 2870 | pos = &resp_ies[0]; |
| 2871 | *pos++ = WLAN_EID_NEIGHBOR_REPORT; |
| 2872 | *pos++ = 13; |
| 2873 | os_memcpy(pos, other->own_addr, ETH_ALEN); |
| 2874 | pos += ETH_ALEN; |
| 2875 | info = 0; /* TODO: BSSID Information */ |
| 2876 | WPA_PUT_LE32(pos, info); |
| 2877 | pos += 4; |
| 2878 | if (other->iconf->hw_mode == HOSTAPD_MODE_IEEE80211AD) |
| 2879 | phytype = 8; /* dmg */ |
| 2880 | else if (other->iconf->ieee80211ac) |
| 2881 | phytype = 9; /* vht */ |
| 2882 | else if (other->iconf->ieee80211n) |
| 2883 | phytype = 7; /* ht */ |
| 2884 | else if (other->iconf->hw_mode == |
| 2885 | HOSTAPD_MODE_IEEE80211A) |
| 2886 | phytype = 4; /* ofdm */ |
| 2887 | else if (other->iconf->hw_mode == |
| 2888 | HOSTAPD_MODE_IEEE80211G) |
| 2889 | phytype = 6; /* erp */ |
| 2890 | else |
| 2891 | phytype = 5; /* hrdsss */ |
| 2892 | if (ieee80211_freq_to_channel_ext( |
| 2893 | hostapd_hw_get_freq(other, |
| 2894 | other->iconf->channel), |
| 2895 | other->iconf->secondary_channel, |
| 2896 | other->iconf->ieee80211ac, |
| 2897 | &op_class, &channel) == NUM_HOSTAPD_MODES) { |
| 2898 | op_class = 0; |
| 2899 | channel = other->iconf->channel; |
| 2900 | } |
| 2901 | *pos++ = op_class; |
| 2902 | *pos++ = channel; |
| 2903 | *pos++ = phytype; |
| 2904 | resp_ies_len = pos - &resp_ies[0]; |
| 2905 | goto fail; |
| 2906 | } |
| 2907 | } |
| 2908 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2909 | res = ieee802_11_allowed_address(hapd, mgmt->sa, (const u8 *) mgmt, len, |
| 2910 | &rad_info); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2911 | if (res == HOSTAPD_ACL_REJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2912 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 2913 | "Ignore Authentication frame from " MACSTR |
| 2914 | " due to ACL reject", MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2915 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 2916 | goto fail; |
| 2917 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2918 | if (res == HOSTAPD_ACL_PENDING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2919 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2920 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2921 | #ifdef CONFIG_SAE |
| 2922 | if (auth_alg == WLAN_AUTH_SAE && !from_queue && |
| 2923 | (auth_transaction == 1 || |
| 2924 | (auth_transaction == 2 && auth_sae_queued_addr(hapd, mgmt->sa)))) { |
| 2925 | /* Handle SAE Authentication commit message through a queue to |
| 2926 | * provide more control for postponing the needed heavy |
| 2927 | * processing under a possible DoS attack scenario. In addition, |
| 2928 | * queue SAE Authentication confirm message if there happens to |
| 2929 | * be a queued commit message from the same peer. This is needed |
| 2930 | * to avoid reordering Authentication frames within the same |
| 2931 | * SAE exchange. */ |
| 2932 | auth_sae_queue(hapd, mgmt, len, rssi); |
| 2933 | return; |
| 2934 | } |
| 2935 | #endif /* CONFIG_SAE */ |
| 2936 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2937 | sta = ap_get_sta(hapd, mgmt->sa); |
| 2938 | if (sta) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2939 | sta->flags &= ~WLAN_STA_PENDING_FILS_ERP; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2940 | sta->ft_over_ds = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2941 | if ((fc & WLAN_FC_RETRY) && |
| 2942 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 2943 | sta->last_seq_ctrl == seq_ctrl && |
| 2944 | sta->last_subtype == WLAN_FC_STYPE_AUTH) { |
| 2945 | hostapd_logger(hapd, sta->addr, |
| 2946 | HOSTAPD_MODULE_IEEE80211, |
| 2947 | HOSTAPD_LEVEL_DEBUG, |
| 2948 | "Drop repeated authentication frame seq_ctrl=0x%x", |
| 2949 | seq_ctrl); |
| 2950 | return; |
| 2951 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2952 | #ifdef CONFIG_MESH |
| 2953 | if ((hapd->conf->mesh & MESH_ENABLED) && |
| 2954 | sta->plink_state == PLINK_BLOCKED) { |
| 2955 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
| 2956 | " is blocked - drop Authentication frame", |
| 2957 | MAC2STR(mgmt->sa)); |
| 2958 | return; |
| 2959 | } |
| 2960 | #endif /* CONFIG_MESH */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2961 | #ifdef CONFIG_PASN |
| 2962 | if (auth_alg == WLAN_AUTH_PASN && |
| 2963 | (sta->flags & WLAN_STA_ASSOC)) { |
| 2964 | wpa_printf(MSG_DEBUG, |
| 2965 | "PASN: auth: Existing station: " MACSTR, |
| 2966 | MAC2STR(sta->addr)); |
| 2967 | return; |
| 2968 | } |
| 2969 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2970 | } else { |
| 2971 | #ifdef CONFIG_MESH |
| 2972 | if (hapd->conf->mesh & MESH_ENABLED) { |
| 2973 | /* if the mesh peer is not available, we don't do auth. |
| 2974 | */ |
| 2975 | wpa_printf(MSG_DEBUG, "Mesh peer " MACSTR |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 2976 | " not yet known - drop Authentication frame", |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2977 | MAC2STR(mgmt->sa)); |
| 2978 | /* |
| 2979 | * Save a copy of the frame so that it can be processed |
| 2980 | * if a new peer entry is added shortly after this. |
| 2981 | */ |
| 2982 | wpabuf_free(hapd->mesh_pending_auth); |
| 2983 | hapd->mesh_pending_auth = wpabuf_alloc_copy(mgmt, len); |
| 2984 | os_get_reltime(&hapd->mesh_pending_auth_time); |
| 2985 | return; |
| 2986 | } |
| 2987 | #endif /* CONFIG_MESH */ |
| 2988 | |
| 2989 | sta = ap_sta_add(hapd, mgmt->sa); |
| 2990 | if (!sta) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2991 | wpa_printf(MSG_DEBUG, "ap_sta_add() failed"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2992 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 2993 | goto fail; |
| 2994 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2995 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2996 | sta->last_seq_ctrl = seq_ctrl; |
| 2997 | sta->last_subtype = WLAN_FC_STYPE_AUTH; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2998 | #ifdef CONFIG_MBO |
| 2999 | sta->auth_rssi = rssi; |
| 3000 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3001 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3002 | res = ieee802_11_set_radius_info(hapd, sta, res, &rad_info); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3003 | if (res) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3004 | wpa_printf(MSG_DEBUG, "ieee802_11_set_radius_info() failed"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3005 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3006 | goto fail; |
| 3007 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3008 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3009 | sta->flags &= ~WLAN_STA_PREAUTH; |
| 3010 | ieee802_1x_notify_pre_auth(sta->eapol_sm, 0); |
| 3011 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3012 | /* |
| 3013 | * If the driver supports full AP client state, add a station to the |
| 3014 | * driver before sending authentication reply to make sure the driver |
| 3015 | * has resources, and not to go through the entire authentication and |
| 3016 | * association handshake, and fail it at the end. |
| 3017 | * |
| 3018 | * If this is not the first transaction, in a multi-step authentication |
| 3019 | * algorithm, the station already exists in the driver |
| 3020 | * (sta->added_unassoc = 1) so skip it. |
| 3021 | * |
| 3022 | * In mesh mode, the station was already added to the driver when the |
| 3023 | * NEW_PEER_CANDIDATE event is received. |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3024 | * |
| 3025 | * If PMF was negotiated for the existing association, skip this to |
| 3026 | * avoid dropping the STA entry and the associated keys. This is needed |
| 3027 | * to allow the original connection work until the attempt can complete |
| 3028 | * (re)association, so that unprotected Authentication frame cannot be |
| 3029 | * used to bypass PMF protection. |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3030 | * |
| 3031 | * PASN authentication does not require adding/removing station to the |
| 3032 | * driver so skip this flow in case of PASN authentication. |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3033 | */ |
| 3034 | if (FULL_AP_CLIENT_STATE_SUPP(hapd->iface->drv_flags) && |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3035 | (!(sta->flags & WLAN_STA_MFP) || !ap_sta_is_authorized(sta)) && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3036 | !(hapd->conf->mesh & MESH_ENABLED) && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3037 | !(sta->added_unassoc) && auth_alg != WLAN_AUTH_PASN) { |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3038 | if (ap_sta_re_add(hapd, sta) < 0) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3039 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 3040 | goto fail; |
| 3041 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3042 | } |
| 3043 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3044 | switch (auth_alg) { |
| 3045 | case WLAN_AUTH_OPEN: |
| 3046 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3047 | HOSTAPD_LEVEL_DEBUG, |
| 3048 | "authentication OK (open system)"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3049 | sta->flags |= WLAN_STA_AUTH; |
| 3050 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 3051 | sta->auth_alg = WLAN_AUTH_OPEN; |
| 3052 | mlme_authenticate_indication(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3053 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3054 | #ifdef CONFIG_WEP |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3055 | #ifndef CONFIG_NO_RC4 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3056 | case WLAN_AUTH_SHARED_KEY: |
| 3057 | resp = auth_shared_key(hapd, sta, auth_transaction, challenge, |
| 3058 | fc & WLAN_FC_ISWEP); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3059 | if (resp != 0) |
| 3060 | wpa_printf(MSG_DEBUG, |
| 3061 | "auth_shared_key() failed: status=%d", resp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3062 | sta->auth_alg = WLAN_AUTH_SHARED_KEY; |
| 3063 | mlme_authenticate_indication(hapd, sta); |
| 3064 | if (sta->challenge && auth_transaction == 1) { |
| 3065 | resp_ies[0] = WLAN_EID_CHALLENGE; |
| 3066 | resp_ies[1] = WLAN_AUTH_CHALLENGE_LEN; |
| 3067 | os_memcpy(resp_ies + 2, sta->challenge, |
| 3068 | WLAN_AUTH_CHALLENGE_LEN); |
| 3069 | resp_ies_len = 2 + WLAN_AUTH_CHALLENGE_LEN; |
| 3070 | } |
| 3071 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3072 | #endif /* CONFIG_NO_RC4 */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3073 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3074 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3075 | case WLAN_AUTH_FT: |
| 3076 | sta->auth_alg = WLAN_AUTH_FT; |
| 3077 | if (sta->wpa_sm == NULL) |
| 3078 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3079 | sta->addr, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3080 | if (sta->wpa_sm == NULL) { |
| 3081 | wpa_printf(MSG_DEBUG, "FT: Failed to initialize WPA " |
| 3082 | "state machine"); |
| 3083 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3084 | goto fail; |
| 3085 | } |
| 3086 | wpa_ft_process_auth(sta->wpa_sm, mgmt->bssid, |
| 3087 | auth_transaction, mgmt->u.auth.variable, |
| 3088 | len - IEEE80211_HDRLEN - |
| 3089 | sizeof(mgmt->u.auth), |
| 3090 | handle_auth_ft_finish, hapd); |
| 3091 | /* handle_auth_ft_finish() callback will complete auth. */ |
| 3092 | return; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3093 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3094 | #ifdef CONFIG_SAE |
| 3095 | case WLAN_AUTH_SAE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3096 | #ifdef CONFIG_MESH |
| 3097 | if (status_code == WLAN_STATUS_SUCCESS && |
| 3098 | hapd->conf->mesh & MESH_ENABLED) { |
| 3099 | if (sta->wpa_sm == NULL) |
| 3100 | sta->wpa_sm = |
| 3101 | wpa_auth_sta_init(hapd->wpa_auth, |
| 3102 | sta->addr, NULL); |
| 3103 | if (sta->wpa_sm == NULL) { |
| 3104 | wpa_printf(MSG_DEBUG, |
| 3105 | "SAE: Failed to initialize WPA state machine"); |
| 3106 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3107 | goto fail; |
| 3108 | } |
| 3109 | } |
| 3110 | #endif /* CONFIG_MESH */ |
| 3111 | handle_auth_sae(hapd, sta, mgmt, len, auth_transaction, |
| 3112 | status_code); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3113 | return; |
| 3114 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3115 | #ifdef CONFIG_FILS |
| 3116 | case WLAN_AUTH_FILS_SK: |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3117 | case WLAN_AUTH_FILS_SK_PFS: |
| 3118 | handle_auth_fils(hapd, sta, mgmt->u.auth.variable, |
| 3119 | len - IEEE80211_HDRLEN - sizeof(mgmt->u.auth), |
| 3120 | auth_alg, auth_transaction, status_code, |
| 3121 | handle_auth_fils_finish); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3122 | return; |
| 3123 | #endif /* CONFIG_FILS */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3124 | #ifdef CONFIG_PASN |
| 3125 | case WLAN_AUTH_PASN: |
| 3126 | handle_auth_pasn(hapd, sta, mgmt, len, auth_transaction, |
| 3127 | status_code); |
| 3128 | return; |
| 3129 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3130 | } |
| 3131 | |
| 3132 | fail: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3133 | reply_res = send_auth_reply(hapd, sta, mgmt->sa, mgmt->bssid, auth_alg, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3134 | auth_alg == WLAN_AUTH_SAE ? |
| 3135 | auth_transaction : auth_transaction + 1, |
| 3136 | resp, resp_ies, resp_ies_len, |
| 3137 | "handle-auth"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3138 | |
| 3139 | if (sta && sta->added_unassoc && (resp != WLAN_STATUS_SUCCESS || |
| 3140 | reply_res != WLAN_STATUS_SUCCESS)) { |
| 3141 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 3142 | sta->added_unassoc = 0; |
| 3143 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3147 | static u8 hostapd_max_bssid_indicator(struct hostapd_data *hapd) |
| 3148 | { |
| 3149 | size_t num_bss_nontx; |
| 3150 | u8 max_bssid_ind = 0; |
| 3151 | |
| 3152 | if (!hapd->iconf->mbssid || hapd->iface->num_bss <= 1) |
| 3153 | return 0; |
| 3154 | |
| 3155 | num_bss_nontx = hapd->iface->num_bss - 1; |
| 3156 | while (num_bss_nontx > 0) { |
| 3157 | max_bssid_ind++; |
| 3158 | num_bss_nontx >>= 1; |
| 3159 | } |
| 3160 | return max_bssid_ind; |
| 3161 | } |
| 3162 | |
| 3163 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3164 | int hostapd_get_aid(struct hostapd_data *hapd, struct sta_info *sta) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3165 | { |
| 3166 | int i, j = 32, aid; |
| 3167 | |
| 3168 | /* get a unique AID */ |
| 3169 | if (sta->aid > 0) { |
| 3170 | wpa_printf(MSG_DEBUG, " old AID %d", sta->aid); |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3174 | if (TEST_FAIL()) |
| 3175 | return -1; |
| 3176 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3177 | for (i = 0; i < AID_WORDS; i++) { |
| 3178 | if (hapd->sta_aid[i] == (u32) -1) |
| 3179 | continue; |
| 3180 | for (j = 0; j < 32; j++) { |
| 3181 | if (!(hapd->sta_aid[i] & BIT(j))) |
| 3182 | break; |
| 3183 | } |
| 3184 | if (j < 32) |
| 3185 | break; |
| 3186 | } |
| 3187 | if (j == 32) |
| 3188 | return -1; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3189 | aid = i * 32 + j + (1 << hostapd_max_bssid_indicator(hapd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3190 | if (aid > 2007) |
| 3191 | return -1; |
| 3192 | |
| 3193 | sta->aid = aid; |
| 3194 | hapd->sta_aid[i] |= BIT(j); |
| 3195 | wpa_printf(MSG_DEBUG, " new AID %d", sta->aid); |
| 3196 | return 0; |
| 3197 | } |
| 3198 | |
| 3199 | |
| 3200 | static u16 check_ssid(struct hostapd_data *hapd, struct sta_info *sta, |
| 3201 | const u8 *ssid_ie, size_t ssid_ie_len) |
| 3202 | { |
| 3203 | if (ssid_ie == NULL) |
| 3204 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3205 | |
| 3206 | if (ssid_ie_len != hapd->conf->ssid.ssid_len || |
| 3207 | os_memcmp(ssid_ie, hapd->conf->ssid.ssid, ssid_ie_len) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3208 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3209 | HOSTAPD_LEVEL_INFO, |
| 3210 | "Station tried to associate with unknown SSID " |
Dmitry Shmidt | 3c47937 | 2014-02-04 10:50:36 -0800 | [diff] [blame] | 3211 | "'%s'", wpa_ssid_txt(ssid_ie, ssid_ie_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3212 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3213 | } |
| 3214 | |
| 3215 | return WLAN_STATUS_SUCCESS; |
| 3216 | } |
| 3217 | |
| 3218 | |
| 3219 | static u16 check_wmm(struct hostapd_data *hapd, struct sta_info *sta, |
| 3220 | const u8 *wmm_ie, size_t wmm_ie_len) |
| 3221 | { |
| 3222 | sta->flags &= ~WLAN_STA_WMM; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3223 | sta->qosinfo = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3224 | if (wmm_ie && hapd->conf->wmm_enabled) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3225 | struct wmm_information_element *wmm; |
| 3226 | |
| 3227 | if (!hostapd_eid_wmm_valid(hapd, wmm_ie, wmm_ie_len)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3228 | hostapd_logger(hapd, sta->addr, |
| 3229 | HOSTAPD_MODULE_WPA, |
| 3230 | HOSTAPD_LEVEL_DEBUG, |
| 3231 | "invalid WMM element in association " |
| 3232 | "request"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3233 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3234 | } |
| 3235 | |
| 3236 | sta->flags |= WLAN_STA_WMM; |
| 3237 | wmm = (struct wmm_information_element *) wmm_ie; |
| 3238 | sta->qosinfo = wmm->qos_info; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3239 | } |
| 3240 | return WLAN_STATUS_SUCCESS; |
| 3241 | } |
| 3242 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3243 | static u16 check_multi_ap(struct hostapd_data *hapd, struct sta_info *sta, |
| 3244 | const u8 *multi_ap_ie, size_t multi_ap_len) |
| 3245 | { |
| 3246 | u8 multi_ap_value = 0; |
| 3247 | |
| 3248 | sta->flags &= ~WLAN_STA_MULTI_AP; |
| 3249 | |
| 3250 | if (!hapd->conf->multi_ap) |
| 3251 | return WLAN_STATUS_SUCCESS; |
| 3252 | |
| 3253 | if (multi_ap_ie) { |
| 3254 | const u8 *multi_ap_subelem; |
| 3255 | |
| 3256 | multi_ap_subelem = get_ie(multi_ap_ie + 4, |
| 3257 | multi_ap_len - 4, |
| 3258 | MULTI_AP_SUB_ELEM_TYPE); |
| 3259 | if (multi_ap_subelem && multi_ap_subelem[1] == 1) { |
| 3260 | multi_ap_value = multi_ap_subelem[2]; |
| 3261 | } else { |
| 3262 | hostapd_logger(hapd, sta->addr, |
| 3263 | HOSTAPD_MODULE_IEEE80211, |
| 3264 | HOSTAPD_LEVEL_INFO, |
| 3265 | "Multi-AP IE has missing or invalid Multi-AP subelement"); |
| 3266 | return WLAN_STATUS_INVALID_IE; |
| 3267 | } |
| 3268 | } |
| 3269 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3270 | if (multi_ap_value && multi_ap_value != MULTI_AP_BACKHAUL_STA) |
| 3271 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3272 | HOSTAPD_LEVEL_INFO, |
| 3273 | "Multi-AP IE with unexpected value 0x%02x", |
| 3274 | multi_ap_value); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3275 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3276 | if (!(multi_ap_value & MULTI_AP_BACKHAUL_STA)) { |
| 3277 | if (hapd->conf->multi_ap & FRONTHAUL_BSS) |
| 3278 | return WLAN_STATUS_SUCCESS; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3279 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3280 | hostapd_logger(hapd, sta->addr, |
| 3281 | HOSTAPD_MODULE_IEEE80211, |
| 3282 | HOSTAPD_LEVEL_INFO, |
| 3283 | "Non-Multi-AP STA tries to associate with backhaul-only BSS"); |
| 3284 | return WLAN_STATUS_ASSOC_DENIED_UNSPEC; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3285 | } |
| 3286 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3287 | if (!(hapd->conf->multi_ap & BACKHAUL_BSS)) |
| 3288 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3289 | HOSTAPD_LEVEL_DEBUG, |
| 3290 | "Backhaul STA tries to associate with fronthaul-only BSS"); |
| 3291 | |
| 3292 | sta->flags |= WLAN_STA_MULTI_AP; |
| 3293 | return WLAN_STATUS_SUCCESS; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3294 | } |
| 3295 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3296 | |
| 3297 | static u16 copy_supp_rates(struct hostapd_data *hapd, struct sta_info *sta, |
| 3298 | struct ieee802_11_elems *elems) |
| 3299 | { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3300 | /* Supported rates not used in IEEE 802.11ad/DMG */ |
| 3301 | if (hapd->iface->current_mode && |
| 3302 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) |
| 3303 | return WLAN_STATUS_SUCCESS; |
| 3304 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | if (!elems->supp_rates) { |
| 3306 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3307 | HOSTAPD_LEVEL_DEBUG, |
| 3308 | "No supported rates element in AssocReq"); |
| 3309 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3310 | } |
| 3311 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3312 | if (elems->supp_rates_len + elems->ext_supp_rates_len > |
| 3313 | sizeof(sta->supported_rates)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3314 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3315 | HOSTAPD_LEVEL_DEBUG, |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3316 | "Invalid supported rates element length %d+%d", |
| 3317 | elems->supp_rates_len, |
| 3318 | elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3319 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3320 | } |
| 3321 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3322 | sta->supported_rates_len = merge_byte_arrays( |
| 3323 | sta->supported_rates, sizeof(sta->supported_rates), |
| 3324 | elems->supp_rates, elems->supp_rates_len, |
| 3325 | elems->ext_supp_rates, elems->ext_supp_rates_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3326 | |
| 3327 | return WLAN_STATUS_SUCCESS; |
| 3328 | } |
| 3329 | |
| 3330 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3331 | #ifdef CONFIG_OWE |
| 3332 | |
| 3333 | static int owe_group_supported(struct hostapd_data *hapd, u16 group) |
| 3334 | { |
| 3335 | int i; |
| 3336 | int *groups = hapd->conf->owe_groups; |
| 3337 | |
| 3338 | if (group != 19 && group != 20 && group != 21) |
| 3339 | return 0; |
| 3340 | |
| 3341 | if (!groups) |
| 3342 | return 1; |
| 3343 | |
| 3344 | for (i = 0; groups[i] > 0; i++) { |
| 3345 | if (groups[i] == group) |
| 3346 | return 1; |
| 3347 | } |
| 3348 | |
| 3349 | return 0; |
| 3350 | } |
| 3351 | |
| 3352 | |
| 3353 | static u16 owe_process_assoc_req(struct hostapd_data *hapd, |
| 3354 | struct sta_info *sta, const u8 *owe_dh, |
| 3355 | u8 owe_dh_len) |
| 3356 | { |
| 3357 | struct wpabuf *secret, *pub, *hkey; |
| 3358 | int res; |
| 3359 | u8 prk[SHA512_MAC_LEN], pmkid[SHA512_MAC_LEN]; |
| 3360 | const char *info = "OWE Key Generation"; |
| 3361 | const u8 *addr[2]; |
| 3362 | size_t len[2]; |
| 3363 | u16 group; |
| 3364 | size_t hash_len, prime_len; |
| 3365 | |
| 3366 | if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) { |
| 3367 | wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching"); |
| 3368 | return WLAN_STATUS_SUCCESS; |
| 3369 | } |
| 3370 | |
| 3371 | group = WPA_GET_LE16(owe_dh); |
| 3372 | if (!owe_group_supported(hapd, group)) { |
| 3373 | wpa_printf(MSG_DEBUG, "OWE: Unsupported DH group %u", group); |
| 3374 | return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 3375 | } |
| 3376 | if (group == 19) |
| 3377 | prime_len = 32; |
| 3378 | else if (group == 20) |
| 3379 | prime_len = 48; |
| 3380 | else if (group == 21) |
| 3381 | prime_len = 66; |
| 3382 | else |
| 3383 | return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 3384 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3385 | if (sta->owe_group == group && sta->owe_ecdh) { |
| 3386 | /* This is a workaround for mac80211 behavior of retransmitting |
| 3387 | * the Association Request frames multiple times if the link |
| 3388 | * layer retries (i.e., seq# remains same) fail. The mac80211 |
| 3389 | * initiated retransmission will use a different seq# and as |
| 3390 | * such, will go through duplicate detection. If we were to |
| 3391 | * change our DH key for that attempt, there would be two |
| 3392 | * different DH shared secrets and the STA would likely select |
| 3393 | * the wrong one. */ |
| 3394 | wpa_printf(MSG_DEBUG, |
| 3395 | "OWE: Try to reuse own previous DH key since the STA tried to go through OWE association again"); |
| 3396 | } else { |
| 3397 | crypto_ecdh_deinit(sta->owe_ecdh); |
| 3398 | sta->owe_ecdh = crypto_ecdh_init(group); |
| 3399 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3400 | if (!sta->owe_ecdh) |
| 3401 | return WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED; |
| 3402 | sta->owe_group = group; |
| 3403 | |
| 3404 | secret = crypto_ecdh_set_peerkey(sta->owe_ecdh, 0, owe_dh + 2, |
| 3405 | owe_dh_len - 2); |
| 3406 | secret = wpabuf_zeropad(secret, prime_len); |
| 3407 | if (!secret) { |
| 3408 | wpa_printf(MSG_DEBUG, "OWE: Invalid peer DH public key"); |
| 3409 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3410 | } |
| 3411 | wpa_hexdump_buf_key(MSG_DEBUG, "OWE: DH shared secret", secret); |
| 3412 | |
| 3413 | /* prk = HKDF-extract(C | A | group, z) */ |
| 3414 | |
| 3415 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 3416 | if (!pub) { |
| 3417 | wpabuf_clear_free(secret); |
| 3418 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3419 | } |
| 3420 | |
| 3421 | /* PMKID = Truncate-128(Hash(C | A)) */ |
| 3422 | addr[0] = owe_dh + 2; |
| 3423 | len[0] = owe_dh_len - 2; |
| 3424 | addr[1] = wpabuf_head(pub); |
| 3425 | len[1] = wpabuf_len(pub); |
| 3426 | if (group == 19) { |
| 3427 | res = sha256_vector(2, addr, len, pmkid); |
| 3428 | hash_len = SHA256_MAC_LEN; |
| 3429 | } else if (group == 20) { |
| 3430 | res = sha384_vector(2, addr, len, pmkid); |
| 3431 | hash_len = SHA384_MAC_LEN; |
| 3432 | } else if (group == 21) { |
| 3433 | res = sha512_vector(2, addr, len, pmkid); |
| 3434 | hash_len = SHA512_MAC_LEN; |
| 3435 | } else { |
| 3436 | wpabuf_free(pub); |
| 3437 | wpabuf_clear_free(secret); |
| 3438 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3439 | } |
| 3440 | pub = wpabuf_zeropad(pub, prime_len); |
| 3441 | if (res < 0 || !pub) { |
| 3442 | wpabuf_free(pub); |
| 3443 | wpabuf_clear_free(secret); |
| 3444 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3445 | } |
| 3446 | |
| 3447 | hkey = wpabuf_alloc(owe_dh_len - 2 + wpabuf_len(pub) + 2); |
| 3448 | if (!hkey) { |
| 3449 | wpabuf_free(pub); |
| 3450 | wpabuf_clear_free(secret); |
| 3451 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3452 | } |
| 3453 | |
| 3454 | wpabuf_put_data(hkey, owe_dh + 2, owe_dh_len - 2); /* C */ |
| 3455 | wpabuf_put_buf(hkey, pub); /* A */ |
| 3456 | wpabuf_free(pub); |
| 3457 | wpabuf_put_le16(hkey, group); /* group */ |
| 3458 | if (group == 19) |
| 3459 | res = hmac_sha256(wpabuf_head(hkey), wpabuf_len(hkey), |
| 3460 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 3461 | else if (group == 20) |
| 3462 | res = hmac_sha384(wpabuf_head(hkey), wpabuf_len(hkey), |
| 3463 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 3464 | else if (group == 21) |
| 3465 | res = hmac_sha512(wpabuf_head(hkey), wpabuf_len(hkey), |
| 3466 | wpabuf_head(secret), wpabuf_len(secret), prk); |
| 3467 | wpabuf_clear_free(hkey); |
| 3468 | wpabuf_clear_free(secret); |
| 3469 | if (res < 0) |
| 3470 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3471 | |
| 3472 | wpa_hexdump_key(MSG_DEBUG, "OWE: prk", prk, hash_len); |
| 3473 | |
| 3474 | /* PMK = HKDF-expand(prk, "OWE Key Generation", n) */ |
| 3475 | |
| 3476 | os_free(sta->owe_pmk); |
| 3477 | sta->owe_pmk = os_malloc(hash_len); |
| 3478 | if (!sta->owe_pmk) { |
| 3479 | os_memset(prk, 0, SHA512_MAC_LEN); |
| 3480 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3481 | } |
| 3482 | |
| 3483 | if (group == 19) |
| 3484 | res = hmac_sha256_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 3485 | os_strlen(info), sta->owe_pmk, hash_len); |
| 3486 | else if (group == 20) |
| 3487 | res = hmac_sha384_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 3488 | os_strlen(info), sta->owe_pmk, hash_len); |
| 3489 | else if (group == 21) |
| 3490 | res = hmac_sha512_kdf(prk, hash_len, NULL, (const u8 *) info, |
| 3491 | os_strlen(info), sta->owe_pmk, hash_len); |
| 3492 | os_memset(prk, 0, SHA512_MAC_LEN); |
| 3493 | if (res < 0) { |
| 3494 | os_free(sta->owe_pmk); |
| 3495 | sta->owe_pmk = NULL; |
| 3496 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3497 | } |
| 3498 | sta->owe_pmk_len = hash_len; |
| 3499 | |
| 3500 | wpa_hexdump_key(MSG_DEBUG, "OWE: PMK", sta->owe_pmk, sta->owe_pmk_len); |
| 3501 | wpa_hexdump(MSG_DEBUG, "OWE: PMKID", pmkid, PMKID_LEN); |
| 3502 | wpa_auth_pmksa_add2(hapd->wpa_auth, sta->addr, sta->owe_pmk, |
| 3503 | sta->owe_pmk_len, pmkid, 0, WPA_KEY_MGMT_OWE); |
| 3504 | |
| 3505 | return WLAN_STATUS_SUCCESS; |
| 3506 | } |
| 3507 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3508 | |
| 3509 | u16 owe_validate_request(struct hostapd_data *hapd, const u8 *peer, |
| 3510 | const u8 *rsn_ie, size_t rsn_ie_len, |
| 3511 | const u8 *owe_dh, size_t owe_dh_len) |
| 3512 | { |
| 3513 | struct wpa_ie_data data; |
| 3514 | int res; |
| 3515 | |
| 3516 | if (!rsn_ie || rsn_ie_len < 2) { |
| 3517 | wpa_printf(MSG_DEBUG, "OWE: Invalid RSNE from " MACSTR, |
| 3518 | MAC2STR(peer)); |
| 3519 | return WLAN_STATUS_INVALID_IE; |
| 3520 | } |
| 3521 | rsn_ie -= 2; |
| 3522 | rsn_ie_len += 2; |
| 3523 | |
| 3524 | res = wpa_parse_wpa_ie_rsn(rsn_ie, rsn_ie_len, &data); |
| 3525 | if (res) { |
| 3526 | wpa_printf(MSG_DEBUG, "Failed to parse RSNE from " MACSTR |
| 3527 | " (res=%d)", MAC2STR(peer), res); |
| 3528 | wpa_hexdump(MSG_DEBUG, "RSNE", rsn_ie, rsn_ie_len); |
| 3529 | return wpa_res_to_status_code(res); |
| 3530 | } |
| 3531 | if (!(data.key_mgmt & WPA_KEY_MGMT_OWE)) { |
| 3532 | wpa_printf(MSG_DEBUG, |
| 3533 | "OWE: Unexpected key mgmt 0x%x from " MACSTR, |
| 3534 | (unsigned int) data.key_mgmt, MAC2STR(peer)); |
| 3535 | return WLAN_STATUS_AKMP_NOT_VALID; |
| 3536 | } |
| 3537 | if (!owe_dh) { |
| 3538 | wpa_printf(MSG_DEBUG, |
| 3539 | "OWE: No Diffie-Hellman Parameter element from " |
| 3540 | MACSTR, MAC2STR(peer)); |
| 3541 | return WLAN_STATUS_AKMP_NOT_VALID; |
| 3542 | } |
| 3543 | |
| 3544 | return WLAN_STATUS_SUCCESS; |
| 3545 | } |
| 3546 | |
| 3547 | |
| 3548 | u16 owe_process_rsn_ie(struct hostapd_data *hapd, |
| 3549 | struct sta_info *sta, |
| 3550 | const u8 *rsn_ie, size_t rsn_ie_len, |
| 3551 | const u8 *owe_dh, size_t owe_dh_len) |
| 3552 | { |
| 3553 | u16 status; |
| 3554 | u8 *owe_buf, ie[256 * 2]; |
| 3555 | size_t ie_len = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3556 | enum wpa_validate_result res; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3557 | |
| 3558 | if (!rsn_ie || rsn_ie_len < 2) { |
| 3559 | wpa_printf(MSG_DEBUG, "OWE: No RSNE in (Re)AssocReq"); |
| 3560 | status = WLAN_STATUS_INVALID_IE; |
| 3561 | goto end; |
| 3562 | } |
| 3563 | |
| 3564 | if (!sta->wpa_sm) |
| 3565 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, sta->addr, |
| 3566 | NULL); |
| 3567 | if (!sta->wpa_sm) { |
| 3568 | wpa_printf(MSG_WARNING, |
| 3569 | "OWE: Failed to initialize WPA state machine"); |
| 3570 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3571 | goto end; |
| 3572 | } |
| 3573 | rsn_ie -= 2; |
| 3574 | rsn_ie_len += 2; |
| 3575 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
| 3576 | hapd->iface->freq, rsn_ie, rsn_ie_len, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3577 | NULL, 0, NULL, 0, owe_dh, owe_dh_len); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3578 | status = wpa_res_to_status_code(res); |
| 3579 | if (status != WLAN_STATUS_SUCCESS) |
| 3580 | goto end; |
| 3581 | status = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len); |
| 3582 | if (status != WLAN_STATUS_SUCCESS) |
| 3583 | goto end; |
| 3584 | owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, ie, sizeof(ie), |
| 3585 | NULL, 0); |
| 3586 | if (!owe_buf) { |
| 3587 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3588 | goto end; |
| 3589 | } |
| 3590 | |
| 3591 | if (sta->owe_ecdh) { |
| 3592 | struct wpabuf *pub; |
| 3593 | |
| 3594 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 3595 | if (!pub) { |
| 3596 | status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3597 | goto end; |
| 3598 | } |
| 3599 | |
| 3600 | /* OWE Diffie-Hellman Parameter element */ |
| 3601 | *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 3602 | *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */ |
| 3603 | *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension |
| 3604 | */ |
| 3605 | WPA_PUT_LE16(owe_buf, sta->owe_group); |
| 3606 | owe_buf += 2; |
| 3607 | os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub)); |
| 3608 | owe_buf += wpabuf_len(pub); |
| 3609 | wpabuf_free(pub); |
| 3610 | sta->external_dh_updated = 1; |
| 3611 | } |
| 3612 | ie_len = owe_buf - ie; |
| 3613 | |
| 3614 | end: |
| 3615 | wpa_printf(MSG_DEBUG, "OWE: Update status %d, ie len %d for peer " |
| 3616 | MACSTR, status, (unsigned int) ie_len, |
| 3617 | MAC2STR(sta->addr)); |
| 3618 | hostapd_drv_update_dh_ie(hapd, sta->addr, status, |
| 3619 | status == WLAN_STATUS_SUCCESS ? ie : NULL, |
| 3620 | ie_len); |
| 3621 | |
| 3622 | return status; |
| 3623 | } |
| 3624 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3625 | #endif /* CONFIG_OWE */ |
| 3626 | |
| 3627 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3628 | static bool check_sa_query(struct hostapd_data *hapd, struct sta_info *sta, |
| 3629 | int reassoc) |
| 3630 | { |
| 3631 | if ((sta->flags & |
| 3632 | (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) != |
| 3633 | (WLAN_STA_ASSOC | WLAN_STA_MFP | WLAN_STA_AUTHORIZED)) |
| 3634 | return false; |
| 3635 | |
| 3636 | if (!sta->sa_query_timed_out && sta->sa_query_count > 0) |
| 3637 | ap_check_sa_query_timeout(hapd, sta); |
| 3638 | |
| 3639 | if (!sta->sa_query_timed_out && |
| 3640 | (!reassoc || sta->auth_alg != WLAN_AUTH_FT)) { |
| 3641 | /* |
| 3642 | * STA has already been associated with MFP and SA Query timeout |
| 3643 | * has not been reached. Reject the association attempt |
| 3644 | * temporarily and start SA Query, if one is not pending. |
| 3645 | */ |
| 3646 | if (sta->sa_query_count == 0) |
| 3647 | ap_sta_start_sa_query(hapd, sta); |
| 3648 | |
| 3649 | return true; |
| 3650 | } |
| 3651 | |
| 3652 | return false; |
| 3653 | } |
| 3654 | |
| 3655 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3656 | static int __check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta, |
| 3657 | const u8 *ies, size_t ies_len, |
| 3658 | struct ieee802_11_elems *elems, int reassoc) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3659 | { |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3660 | int resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3661 | const u8 *wpa_ie; |
| 3662 | size_t wpa_ie_len; |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3663 | const u8 *p2p_dev_addr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3664 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3665 | resp = check_ssid(hapd, sta, elems->ssid, elems->ssid_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3666 | if (resp != WLAN_STATUS_SUCCESS) |
| 3667 | return resp; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3668 | resp = check_wmm(hapd, sta, elems->wmm, elems->wmm_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3669 | if (resp != WLAN_STATUS_SUCCESS) |
| 3670 | return resp; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3671 | resp = check_ext_capab(hapd, sta, elems->ext_capab, |
| 3672 | elems->ext_capab_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3673 | if (resp != WLAN_STATUS_SUCCESS) |
| 3674 | return resp; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3675 | resp = copy_supp_rates(hapd, sta, elems); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3676 | if (resp != WLAN_STATUS_SUCCESS) |
| 3677 | return resp; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3678 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3679 | resp = check_multi_ap(hapd, sta, elems->multi_ap, elems->multi_ap_len); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3680 | if (resp != WLAN_STATUS_SUCCESS) |
| 3681 | return resp; |
| 3682 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3683 | resp = copy_sta_ht_capab(hapd, sta, elems->ht_capabilities); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3684 | if (resp != WLAN_STATUS_SUCCESS) |
| 3685 | return resp; |
| 3686 | if (hapd->iconf->ieee80211n && hapd->iconf->require_ht && |
| 3687 | !(sta->flags & WLAN_STA_HT)) { |
| 3688 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3689 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 3690 | "mandatory HT PHY - reject association"); |
| 3691 | return WLAN_STATUS_ASSOC_DENIED_NO_HT; |
| 3692 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3693 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3694 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3695 | if (hapd->iconf->ieee80211ac) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3696 | resp = copy_sta_vht_capab(hapd, sta, elems->vht_capabilities); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3697 | if (resp != WLAN_STATUS_SUCCESS) |
| 3698 | return resp; |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3699 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 3700 | resp = set_sta_vht_opmode(hapd, sta, elems->opmode_notif); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3701 | if (resp != WLAN_STATUS_SUCCESS) |
| 3702 | return resp; |
| 3703 | } |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 3704 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3705 | if (hapd->iconf->ieee80211ac && hapd->iconf->require_vht && |
| 3706 | !(sta->flags & WLAN_STA_VHT)) { |
| 3707 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3708 | HOSTAPD_LEVEL_INFO, "Station does not support " |
| 3709 | "mandatory VHT PHY - reject association"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3710 | return WLAN_STATUS_ASSOC_DENIED_NO_VHT; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3711 | } |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3712 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3713 | if (hapd->conf->vendor_vht && !elems->vht_capabilities) { |
| 3714 | resp = copy_sta_vendor_vht(hapd, sta, elems->vendor_vht, |
| 3715 | elems->vendor_vht_len); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 3716 | if (resp != WLAN_STATUS_SUCCESS) |
| 3717 | return resp; |
| 3718 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3719 | #endif /* CONFIG_IEEE80211AC */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3720 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3721 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3722 | resp = copy_sta_he_capab(hapd, sta, IEEE80211_MODE_AP, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3723 | elems->he_capabilities, |
| 3724 | elems->he_capabilities_len); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3725 | if (resp != WLAN_STATUS_SUCCESS) |
| 3726 | return resp; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3727 | |
| 3728 | if (hapd->iconf->require_he && !(sta->flags & WLAN_STA_HE)) { |
| 3729 | hostapd_logger(hapd, sta->addr, |
| 3730 | HOSTAPD_MODULE_IEEE80211, |
| 3731 | HOSTAPD_LEVEL_INFO, |
| 3732 | "Station does not support mandatory HE PHY - reject association"); |
| 3733 | return WLAN_STATUS_DENIED_HE_NOT_SUPPORTED; |
| 3734 | } |
| 3735 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3736 | if (is_6ghz_op_class(hapd->iconf->op_class)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3737 | if (!(sta->flags & WLAN_STA_HE)) { |
| 3738 | hostapd_logger(hapd, sta->addr, |
| 3739 | HOSTAPD_MODULE_IEEE80211, |
| 3740 | HOSTAPD_LEVEL_INFO, |
| 3741 | "Station does not support mandatory HE PHY - reject association"); |
| 3742 | return WLAN_STATUS_DENIED_HE_NOT_SUPPORTED; |
| 3743 | } |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3744 | resp = copy_sta_he_6ghz_capab(hapd, sta, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3745 | elems->he_6ghz_band_cap); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3746 | if (resp != WLAN_STATUS_SUCCESS) |
| 3747 | return resp; |
| 3748 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3749 | } |
| 3750 | #endif /* CONFIG_IEEE80211AX */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3751 | #ifdef CONFIG_IEEE80211BE |
| 3752 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 3753 | resp = copy_sta_eht_capab(hapd, sta, IEEE80211_MODE_AP, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3754 | elems->he_capabilities, |
| 3755 | elems->he_capabilities_len, |
| 3756 | elems->eht_capabilities, |
| 3757 | elems->eht_capabilities_len); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3758 | if (resp != WLAN_STATUS_SUCCESS) |
| 3759 | return resp; |
| 3760 | } |
| 3761 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3762 | |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3763 | #ifdef CONFIG_P2P |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3764 | if (elems->p2p && ies && ies_len) { |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3765 | wpabuf_free(sta->p2p_ie); |
| 3766 | sta->p2p_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 3767 | P2P_IE_VENDOR_TYPE); |
| 3768 | if (sta->p2p_ie) |
| 3769 | p2p_dev_addr = p2p_get_go_dev_addr(sta->p2p_ie); |
| 3770 | } else { |
| 3771 | wpabuf_free(sta->p2p_ie); |
| 3772 | sta->p2p_ie = NULL; |
| 3773 | } |
| 3774 | #endif /* CONFIG_P2P */ |
| 3775 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3776 | if ((hapd->conf->wpa & WPA_PROTO_RSN) && elems->rsn_ie) { |
| 3777 | wpa_ie = elems->rsn_ie; |
| 3778 | wpa_ie_len = elems->rsn_ie_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3779 | } else if ((hapd->conf->wpa & WPA_PROTO_WPA) && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3780 | elems->wpa_ie) { |
| 3781 | wpa_ie = elems->wpa_ie; |
| 3782 | wpa_ie_len = elems->wpa_ie_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3783 | } else { |
| 3784 | wpa_ie = NULL; |
| 3785 | wpa_ie_len = 0; |
| 3786 | } |
| 3787 | |
| 3788 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3789 | sta->flags &= ~(WLAN_STA_WPS | WLAN_STA_MAYBE_WPS | WLAN_STA_WPS2); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3790 | if (hapd->conf->wps_state && elems->wps_ie && ies && ies_len) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3791 | wpa_printf(MSG_DEBUG, "STA included WPS IE in (Re)Association " |
| 3792 | "Request - assume WPS is used"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3793 | if (check_sa_query(hapd, sta, reassoc)) |
| 3794 | return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3795 | sta->flags |= WLAN_STA_WPS; |
| 3796 | wpabuf_free(sta->wps_ie); |
| 3797 | sta->wps_ie = ieee802_11_vendor_ie_concat(ies, ies_len, |
| 3798 | WPS_IE_VENDOR_TYPE); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3799 | if (sta->wps_ie && wps_is_20(sta->wps_ie)) { |
| 3800 | wpa_printf(MSG_DEBUG, "WPS: STA supports WPS 2.0"); |
| 3801 | sta->flags |= WLAN_STA_WPS2; |
| 3802 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3803 | wpa_ie = NULL; |
| 3804 | wpa_ie_len = 0; |
| 3805 | if (sta->wps_ie && wps_validate_assoc_req(sta->wps_ie) < 0) { |
| 3806 | wpa_printf(MSG_DEBUG, "WPS: Invalid WPS IE in " |
| 3807 | "(Re)Association Request - reject"); |
| 3808 | return WLAN_STATUS_INVALID_IE; |
| 3809 | } |
| 3810 | } else if (hapd->conf->wps_state && wpa_ie == NULL) { |
| 3811 | wpa_printf(MSG_DEBUG, "STA did not include WPA/RSN IE in " |
| 3812 | "(Re)Association Request - possible WPS use"); |
| 3813 | sta->flags |= WLAN_STA_MAYBE_WPS; |
| 3814 | } else |
| 3815 | #endif /* CONFIG_WPS */ |
| 3816 | if (hapd->conf->wpa && wpa_ie == NULL) { |
| 3817 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3818 | HOSTAPD_LEVEL_INFO, |
| 3819 | "No WPA/RSN IE in association request"); |
| 3820 | return WLAN_STATUS_INVALID_IE; |
| 3821 | } |
| 3822 | |
| 3823 | if (hapd->conf->wpa && wpa_ie) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3824 | enum wpa_validate_result res; |
| 3825 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 3826 | if (check_sa_query(hapd, sta, reassoc)) |
| 3827 | return WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY; |
| 3828 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3829 | wpa_ie -= 2; |
| 3830 | wpa_ie_len += 2; |
| 3831 | if (sta->wpa_sm == NULL) |
| 3832 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 3833 | sta->addr, |
| 3834 | p2p_dev_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | if (sta->wpa_sm == NULL) { |
| 3836 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 3837 | "state machine"); |
| 3838 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3839 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3840 | wpa_auth_set_auth_alg(sta->wpa_sm, sta->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3841 | res = wpa_validate_wpa_ie(hapd->wpa_auth, sta->wpa_sm, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3842 | hapd->iface->freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3843 | wpa_ie, wpa_ie_len, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3844 | elems->rsnxe ? elems->rsnxe - 2 : |
| 3845 | NULL, |
| 3846 | elems->rsnxe ? elems->rsnxe_len + 2 : |
| 3847 | 0, |
| 3848 | elems->mdie, elems->mdie_len, |
| 3849 | elems->owe_dh, elems->owe_dh_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3850 | resp = wpa_res_to_status_code(res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3851 | if (resp != WLAN_STATUS_SUCCESS) |
| 3852 | return resp; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3853 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3854 | if (wpa_auth_uses_mfp(sta->wpa_sm)) |
| 3855 | sta->flags |= WLAN_STA_MFP; |
| 3856 | else |
| 3857 | sta->flags &= ~WLAN_STA_MFP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3858 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3859 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3860 | if (sta->auth_alg == WLAN_AUTH_FT) { |
| 3861 | if (!reassoc) { |
| 3862 | wpa_printf(MSG_DEBUG, "FT: " MACSTR " tried " |
| 3863 | "to use association (not " |
| 3864 | "re-association) with FT auth_alg", |
| 3865 | MAC2STR(sta->addr)); |
| 3866 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3867 | } |
| 3868 | |
| 3869 | resp = wpa_ft_validate_reassoc(sta->wpa_sm, ies, |
| 3870 | ies_len); |
| 3871 | if (resp != WLAN_STATUS_SUCCESS) |
| 3872 | return resp; |
| 3873 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3874 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3875 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3876 | #ifdef CONFIG_SAE |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3877 | if (wpa_auth_uses_sae(sta->wpa_sm) && sta->sae && |
| 3878 | sta->sae->state == SAE_ACCEPTED) |
| 3879 | wpa_auth_add_sae_pmkid(sta->wpa_sm, sta->sae->pmkid); |
| 3880 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3881 | if (wpa_auth_uses_sae(sta->wpa_sm) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3882 | sta->auth_alg == WLAN_AUTH_OPEN) { |
| 3883 | struct rsn_pmksa_cache_entry *sa; |
| 3884 | sa = wpa_auth_sta_get_pmksa(sta->wpa_sm); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3885 | if (!sa || !wpa_key_mgmt_sae(sa->akmp)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3886 | wpa_printf(MSG_DEBUG, |
| 3887 | "SAE: No PMKSA cache entry found for " |
| 3888 | MACSTR, MAC2STR(sta->addr)); |
| 3889 | return WLAN_STATUS_INVALID_PMKID; |
| 3890 | } |
| 3891 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR |
| 3892 | " using PMKSA caching", MAC2STR(sta->addr)); |
| 3893 | } else if (wpa_auth_uses_sae(sta->wpa_sm) && |
| 3894 | sta->auth_alg != WLAN_AUTH_SAE && |
| 3895 | !(sta->auth_alg == WLAN_AUTH_FT && |
| 3896 | wpa_auth_uses_ft_sae(sta->wpa_sm))) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3897 | wpa_printf(MSG_DEBUG, "SAE: " MACSTR " tried to use " |
| 3898 | "SAE AKM after non-SAE auth_alg %u", |
| 3899 | MAC2STR(sta->addr), sta->auth_alg); |
| 3900 | return WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG; |
| 3901 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3902 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3903 | if (hapd->conf->sae_pwe == SAE_PWE_BOTH && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3904 | sta->auth_alg == WLAN_AUTH_SAE && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3905 | sta->sae && !sta->sae->h2e && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3906 | ieee802_11_rsnx_capab_len(elems->rsnxe, elems->rsnxe_len, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3907 | WLAN_RSNX_CAPAB_SAE_H2E)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3908 | wpa_printf(MSG_INFO, "SAE: " MACSTR |
| 3909 | " indicates support for SAE H2E, but did not use it", |
| 3910 | MAC2STR(sta->addr)); |
| 3911 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3912 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3913 | #endif /* CONFIG_SAE */ |
| 3914 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3915 | #ifdef CONFIG_OWE |
| 3916 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && |
| 3917 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3918 | elems->owe_dh) { |
| 3919 | resp = owe_process_assoc_req(hapd, sta, elems->owe_dh, |
| 3920 | elems->owe_dh_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3921 | if (resp != WLAN_STATUS_SUCCESS) |
| 3922 | return resp; |
| 3923 | } |
| 3924 | #endif /* CONFIG_OWE */ |
| 3925 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3926 | #ifdef CONFIG_DPP2 |
| 3927 | dpp_pfs_free(sta->dpp_pfs); |
| 3928 | sta->dpp_pfs = NULL; |
| 3929 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3930 | if (DPP_VERSION > 1 && |
| 3931 | (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) && |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3932 | hapd->conf->dpp_netaccesskey && sta->wpa_sm && |
| 3933 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3934 | elems->owe_dh) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3935 | sta->dpp_pfs = dpp_pfs_init( |
| 3936 | wpabuf_head(hapd->conf->dpp_netaccesskey), |
| 3937 | wpabuf_len(hapd->conf->dpp_netaccesskey)); |
| 3938 | if (!sta->dpp_pfs) { |
| 3939 | wpa_printf(MSG_DEBUG, |
| 3940 | "DPP: Could not initialize PFS"); |
| 3941 | /* Try to continue without PFS */ |
| 3942 | goto pfs_fail; |
| 3943 | } |
| 3944 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3945 | if (dpp_pfs_process(sta->dpp_pfs, elems->owe_dh, |
| 3946 | elems->owe_dh_len) < 0) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3947 | dpp_pfs_free(sta->dpp_pfs); |
| 3948 | sta->dpp_pfs = NULL; |
| 3949 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | wpa_auth_set_dpp_z(sta->wpa_sm, sta->dpp_pfs ? |
| 3954 | sta->dpp_pfs->secret : NULL); |
| 3955 | pfs_fail: |
| 3956 | #endif /* CONFIG_DPP2 */ |
| 3957 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3958 | if ((sta->flags & (WLAN_STA_HT | WLAN_STA_VHT)) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3959 | wpa_auth_get_pairwise(sta->wpa_sm) == WPA_CIPHER_TKIP) { |
| 3960 | hostapd_logger(hapd, sta->addr, |
| 3961 | HOSTAPD_MODULE_IEEE80211, |
| 3962 | HOSTAPD_LEVEL_INFO, |
| 3963 | "Station tried to use TKIP with HT " |
| 3964 | "association"); |
| 3965 | return WLAN_STATUS_CIPHER_REJECTED_PER_POLICY; |
| 3966 | } |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3967 | #ifdef CONFIG_HS20 |
| 3968 | } else if (hapd->conf->osen) { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3969 | if (!elems->osen) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3970 | hostapd_logger( |
| 3971 | hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 3972 | HOSTAPD_LEVEL_INFO, |
| 3973 | "No HS 2.0 OSEN element in association request"); |
| 3974 | return WLAN_STATUS_INVALID_IE; |
| 3975 | } |
| 3976 | |
| 3977 | wpa_printf(MSG_DEBUG, "HS 2.0: OSEN association"); |
| 3978 | if (sta->wpa_sm == NULL) |
| 3979 | sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth, |
| 3980 | sta->addr, NULL); |
| 3981 | if (sta->wpa_sm == NULL) { |
| 3982 | wpa_printf(MSG_WARNING, "Failed to initialize WPA " |
| 3983 | "state machine"); |
| 3984 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 3985 | } |
| 3986 | if (wpa_validate_osen(hapd->wpa_auth, sta->wpa_sm, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3987 | elems->osen - 2, elems->osen_len + 2) < 0) |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3988 | return WLAN_STATUS_INVALID_IE; |
| 3989 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3990 | } else |
| 3991 | wpa_auth_sta_no_wpa(sta->wpa_sm); |
| 3992 | |
| 3993 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3994 | p2p_group_notif_assoc(hapd->p2p_group, sta->addr, ies, ies_len); |
| 3995 | #endif /* CONFIG_P2P */ |
| 3996 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3997 | #ifdef CONFIG_HS20 |
| 3998 | wpabuf_free(sta->hs20_ie); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3999 | if (elems->hs20 && elems->hs20_len > 4) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4000 | int release; |
| 4001 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4002 | sta->hs20_ie = wpabuf_alloc_copy(elems->hs20 + 4, |
| 4003 | elems->hs20_len - 4); |
| 4004 | release = ((elems->hs20[4] >> 4) & 0x0f) + 1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4005 | if (release >= 2 && !wpa_auth_uses_mfp(sta->wpa_sm) && |
| 4006 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4007 | wpa_printf(MSG_DEBUG, |
| 4008 | "HS 2.0: PMF not negotiated by release %d station " |
| 4009 | MACSTR, release, MAC2STR(sta->addr)); |
| 4010 | return WLAN_STATUS_ROBUST_MGMT_FRAME_POLICY_VIOLATION; |
| 4011 | } |
| 4012 | } else { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4013 | sta->hs20_ie = NULL; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4014 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4015 | |
| 4016 | wpabuf_free(sta->roaming_consortium); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4017 | if (elems->roaming_cons_sel) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4018 | sta->roaming_consortium = wpabuf_alloc_copy( |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4019 | elems->roaming_cons_sel + 4, |
| 4020 | elems->roaming_cons_sel_len - 4); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4021 | else |
| 4022 | sta->roaming_consortium = NULL; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4023 | #endif /* CONFIG_HS20 */ |
| 4024 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4025 | #ifdef CONFIG_FST |
| 4026 | wpabuf_free(sta->mb_ies); |
| 4027 | if (hapd->iface->fst) |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4028 | sta->mb_ies = mb_ies_by_info(&elems->mb_ies); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4029 | else |
| 4030 | sta->mb_ies = NULL; |
| 4031 | #endif /* CONFIG_FST */ |
| 4032 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4033 | #ifdef CONFIG_MBO |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4034 | mbo_ap_check_sta_assoc(hapd, sta, elems); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4035 | |
| 4036 | if (hapd->conf->mbo_enabled && (hapd->conf->wpa & 2) && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4037 | elems->mbo && sta->cell_capa && !(sta->flags & WLAN_STA_MFP) && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4038 | hapd->conf->ieee80211w != NO_MGMT_FRAME_PROTECTION) { |
| 4039 | wpa_printf(MSG_INFO, |
| 4040 | "MBO: Reject WPA2 association without PMF"); |
| 4041 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4042 | } |
| 4043 | #endif /* CONFIG_MBO */ |
| 4044 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4045 | #if defined(CONFIG_FILS) && defined(CONFIG_OCV) |
| 4046 | if (wpa_auth_uses_ocv(sta->wpa_sm) && |
| 4047 | (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 4048 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 4049 | sta->auth_alg == WLAN_AUTH_FILS_PK)) { |
| 4050 | struct wpa_channel_info ci; |
| 4051 | int tx_chanwidth; |
| 4052 | int tx_seg1_idx; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4053 | enum oci_verify_result res; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4054 | |
| 4055 | if (hostapd_drv_channel_info(hapd, &ci) != 0) { |
| 4056 | wpa_printf(MSG_WARNING, |
| 4057 | "Failed to get channel info to validate received OCI in FILS (Re)Association Request frame"); |
| 4058 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4059 | } |
| 4060 | |
| 4061 | if (get_sta_tx_parameters(sta->wpa_sm, |
| 4062 | channel_width_to_int(ci.chanwidth), |
| 4063 | ci.seg1_idx, &tx_chanwidth, |
| 4064 | &tx_seg1_idx) < 0) |
| 4065 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4066 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4067 | res = ocv_verify_tx_params(elems->oci, elems->oci_len, &ci, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4068 | tx_chanwidth, tx_seg1_idx); |
| 4069 | if (wpa_auth_uses_ocv(sta->wpa_sm) == 2 && |
| 4070 | res == OCI_NOT_FOUND) { |
| 4071 | /* Work around misbehaving STAs */ |
| 4072 | wpa_printf(MSG_INFO, |
| 4073 | "FILS: Disable OCV with a STA that does not send OCI"); |
| 4074 | wpa_auth_set_ocv(sta->wpa_sm, 0); |
| 4075 | } else if (res != OCI_SUCCESS) { |
| 4076 | wpa_printf(MSG_WARNING, "FILS: OCV failed: %s", |
| 4077 | ocv_errorstr); |
| 4078 | wpa_msg(hapd->msg_ctx, MSG_INFO, OCV_FAILURE "addr=" |
| 4079 | MACSTR " frame=fils-reassoc-req error=%s", |
| 4080 | MAC2STR(sta->addr), ocv_errorstr); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4081 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4082 | } |
| 4083 | } |
| 4084 | #endif /* CONFIG_FILS && CONFIG_OCV */ |
| 4085 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4086 | ap_copy_sta_supp_op_classes(sta, elems->supp_op_classes, |
| 4087 | elems->supp_op_classes_len); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4088 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4089 | if ((sta->capability & WLAN_CAPABILITY_RADIO_MEASUREMENT) && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4090 | elems->rrm_enabled && |
| 4091 | elems->rrm_enabled_len >= sizeof(sta->rrm_enabled_capa)) |
| 4092 | os_memcpy(sta->rrm_enabled_capa, elems->rrm_enabled, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4093 | sizeof(sta->rrm_enabled_capa)); |
| 4094 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4095 | if (elems->power_capab) { |
| 4096 | sta->min_tx_power = elems->power_capab[0]; |
| 4097 | sta->max_tx_power = elems->power_capab[1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4098 | sta->power_capab = 1; |
| 4099 | } else { |
| 4100 | sta->power_capab = 0; |
| 4101 | } |
| 4102 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4103 | return WLAN_STATUS_SUCCESS; |
| 4104 | } |
| 4105 | |
| 4106 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4107 | static int check_assoc_ies(struct hostapd_data *hapd, struct sta_info *sta, |
| 4108 | const u8 *ies, size_t ies_len, int reassoc) |
| 4109 | { |
| 4110 | struct ieee802_11_elems elems; |
| 4111 | |
| 4112 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) { |
| 4113 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 4114 | HOSTAPD_LEVEL_INFO, |
| 4115 | "Station sent an invalid association request"); |
| 4116 | return WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4117 | } |
| 4118 | |
| 4119 | return __check_assoc_ies(hapd, sta, ies, ies_len, &elems, reassoc); |
| 4120 | } |
| 4121 | |
| 4122 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | static void send_deauth(struct hostapd_data *hapd, const u8 *addr, |
| 4124 | u16 reason_code) |
| 4125 | { |
| 4126 | int send_len; |
| 4127 | struct ieee80211_mgmt reply; |
| 4128 | |
| 4129 | os_memset(&reply, 0, sizeof(reply)); |
| 4130 | reply.frame_control = |
| 4131 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_DEAUTH); |
| 4132 | os_memcpy(reply.da, addr, ETH_ALEN); |
| 4133 | os_memcpy(reply.sa, hapd->own_addr, ETH_ALEN); |
| 4134 | os_memcpy(reply.bssid, hapd->own_addr, ETH_ALEN); |
| 4135 | |
| 4136 | send_len = IEEE80211_HDRLEN + sizeof(reply.u.deauth); |
| 4137 | reply.u.deauth.reason_code = host_to_le16(reason_code); |
| 4138 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4139 | 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] | 4140 | wpa_printf(MSG_INFO, "Failed to send deauth: %s", |
| 4141 | strerror(errno)); |
| 4142 | } |
| 4143 | |
| 4144 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4145 | static int add_associated_sta(struct hostapd_data *hapd, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4146 | struct sta_info *sta, int reassoc) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4147 | { |
| 4148 | struct ieee80211_ht_capabilities ht_cap; |
| 4149 | struct ieee80211_vht_capabilities vht_cap; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4150 | struct ieee80211_he_capabilities he_cap; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4151 | struct ieee80211_eht_capabilities eht_cap; |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4152 | int set = 1; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4153 | |
| 4154 | /* |
| 4155 | * Remove the STA entry to ensure the STA PS state gets cleared and |
| 4156 | * configuration gets updated. This is relevant for cases, such as |
| 4157 | * FT-over-the-DS, where a station re-associates back to the same AP but |
| 4158 | * skips the authentication flow, or if working with a driver that |
| 4159 | * does not support full AP client state. |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4160 | * |
| 4161 | * Skip this if the STA has already completed FT reassociation and the |
| 4162 | * TK has been configured since the TX/RX PN must not be reset to 0 for |
| 4163 | * the same key. |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4164 | * |
| 4165 | * FT-over-the-DS has a special case where the STA entry (and as such, |
| 4166 | * the TK) has not yet been configured to the driver depending on which |
| 4167 | * driver interface is used. For that case, allow add-STA operation to |
| 4168 | * be used (instead of set-STA). This is needed to allow mac80211-based |
| 4169 | * drivers to accept the STA parameter configuration. Since this is |
| 4170 | * after a new FT-over-DS exchange, a new TK has been derived, so key |
| 4171 | * reinstallation is not a concern for this case. |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4172 | */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4173 | wpa_printf(MSG_DEBUG, "Add associated STA " MACSTR |
| 4174 | " (added_unassoc=%d auth_alg=%u ft_over_ds=%u reassoc=%d authorized=%d ft_tk=%d fils_tk=%d)", |
| 4175 | MAC2STR(sta->addr), sta->added_unassoc, sta->auth_alg, |
| 4176 | sta->ft_over_ds, reassoc, |
| 4177 | !!(sta->flags & WLAN_STA_AUTHORIZED), |
| 4178 | wpa_auth_sta_ft_tk_already_set(sta->wpa_sm), |
| 4179 | wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)); |
| 4180 | |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4181 | if (!sta->added_unassoc && |
| 4182 | (!(sta->flags & WLAN_STA_AUTHORIZED) || |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4183 | (reassoc && sta->ft_over_ds && sta->auth_alg == WLAN_AUTH_FT) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4184 | (!wpa_auth_sta_ft_tk_already_set(sta->wpa_sm) && |
| 4185 | !wpa_auth_sta_fils_tk_already_set(sta->wpa_sm)))) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4186 | hostapd_drv_sta_remove(hapd, sta->addr); |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4187 | wpa_auth_sm_event(sta->wpa_sm, WPA_DRV_STA_REMOVED); |
| 4188 | set = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4189 | |
| 4190 | /* Do not allow the FT-over-DS exception to be used more than |
| 4191 | * once per authentication exchange to guarantee a new TK is |
| 4192 | * used here */ |
| 4193 | sta->ft_over_ds = 0; |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4194 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4195 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4196 | if (sta->flags & WLAN_STA_HT) |
| 4197 | hostapd_get_ht_capab(hapd, sta->ht_capabilities, &ht_cap); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4198 | #ifdef CONFIG_IEEE80211AC |
| 4199 | if (sta->flags & WLAN_STA_VHT) |
| 4200 | hostapd_get_vht_capab(hapd, sta->vht_capabilities, &vht_cap); |
| 4201 | #endif /* CONFIG_IEEE80211AC */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4202 | #ifdef CONFIG_IEEE80211AX |
| 4203 | if (sta->flags & WLAN_STA_HE) { |
| 4204 | hostapd_get_he_capab(hapd, sta->he_capab, &he_cap, |
| 4205 | sta->he_capab_len); |
| 4206 | } |
| 4207 | #endif /* CONFIG_IEEE80211AX */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4208 | #ifdef CONFIG_IEEE80211BE |
| 4209 | if (sta->flags & WLAN_STA_EHT) |
| 4210 | hostapd_get_eht_capab(hapd, sta->eht_capab, &eht_cap, |
| 4211 | sta->eht_capab_len); |
| 4212 | #endif /* CONFIG_IEEE80211BE */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4213 | |
| 4214 | /* |
| 4215 | * Add the station with forced WLAN_STA_ASSOC flag. The sta->flags |
| 4216 | * will be set when the ACK frame for the (Re)Association Response frame |
| 4217 | * is processed (TX status driver event). |
| 4218 | */ |
| 4219 | if (hostapd_sta_add(hapd, sta->addr, sta->aid, sta->capability, |
| 4220 | sta->supported_rates, sta->supported_rates_len, |
| 4221 | sta->listen_interval, |
| 4222 | sta->flags & WLAN_STA_HT ? &ht_cap : NULL, |
| 4223 | sta->flags & WLAN_STA_VHT ? &vht_cap : NULL, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4224 | sta->flags & WLAN_STA_HE ? &he_cap : NULL, |
| 4225 | sta->flags & WLAN_STA_HE ? sta->he_capab_len : 0, |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4226 | sta->flags & WLAN_STA_EHT ? &eht_cap : NULL, |
| 4227 | sta->flags & WLAN_STA_EHT ? sta->eht_capab_len : 0, |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4228 | sta->he_6ghz_capab, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4229 | sta->flags | WLAN_STA_ASSOC, sta->qosinfo, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4230 | sta->vht_opmode, sta->p2p_ie ? 1 : 0, |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4231 | set)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4232 | hostapd_logger(hapd, sta->addr, |
| 4233 | HOSTAPD_MODULE_IEEE80211, HOSTAPD_LEVEL_NOTICE, |
| 4234 | "Could not %s STA to kernel driver", |
Mathy Vanhoef | f6e1f66 | 2017-07-14 15:15:35 +0200 | [diff] [blame] | 4235 | set ? "set" : "add"); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4236 | |
| 4237 | if (sta->added_unassoc) { |
| 4238 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 4239 | sta->added_unassoc = 0; |
| 4240 | } |
| 4241 | |
| 4242 | return -1; |
| 4243 | } |
| 4244 | |
| 4245 | sta->added_unassoc = 0; |
| 4246 | |
| 4247 | return 0; |
| 4248 | } |
| 4249 | |
| 4250 | |
| 4251 | 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] | 4252 | const u8 *addr, u16 status_code, int reassoc, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4253 | const u8 *ies, size_t ies_len, int rssi, |
| 4254 | int omit_rsnxe) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4255 | { |
| 4256 | int send_len; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4257 | u8 *buf; |
| 4258 | size_t buflen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4259 | struct ieee80211_mgmt *reply; |
| 4260 | u8 *p; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4261 | u16 res = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4262 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4263 | buflen = sizeof(struct ieee80211_mgmt) + 1024; |
| 4264 | #ifdef CONFIG_FILS |
| 4265 | if (sta && sta->fils_hlp_resp) |
| 4266 | buflen += wpabuf_len(sta->fils_hlp_resp); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4267 | if (sta) |
| 4268 | buflen += 150; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4269 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4270 | #ifdef CONFIG_OWE |
| 4271 | if (sta && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) |
| 4272 | buflen += 150; |
| 4273 | #endif /* CONFIG_OWE */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4274 | #ifdef CONFIG_DPP2 |
| 4275 | if (sta && sta->dpp_pfs) |
| 4276 | buflen += 5 + sta->dpp_pfs->curve->prime_len; |
| 4277 | #endif /* CONFIG_DPP2 */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4278 | #ifdef CONFIG_IEEE80211BE |
| 4279 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 4280 | buflen += hostapd_eid_eht_capab_len(hapd, IEEE80211_MODE_AP); |
| 4281 | buflen += 3 + sizeof(struct ieee80211_eht_operation); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4282 | if (hapd->iconf->punct_bitmap) |
| 4283 | buflen += EHT_OPER_DISABLED_SUBCHAN_BITMAP_SIZE; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4284 | } |
| 4285 | #endif /* CONFIG_IEEE80211BE */ |
| 4286 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4287 | buf = os_zalloc(buflen); |
| 4288 | if (!buf) { |
| 4289 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4290 | goto done; |
| 4291 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4292 | reply = (struct ieee80211_mgmt *) buf; |
| 4293 | reply->frame_control = |
| 4294 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 4295 | (reassoc ? WLAN_FC_STYPE_REASSOC_RESP : |
| 4296 | WLAN_FC_STYPE_ASSOC_RESP)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4297 | os_memcpy(reply->da, addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4298 | os_memcpy(reply->sa, hapd->own_addr, ETH_ALEN); |
| 4299 | os_memcpy(reply->bssid, hapd->own_addr, ETH_ALEN); |
| 4300 | |
| 4301 | send_len = IEEE80211_HDRLEN; |
| 4302 | send_len += sizeof(reply->u.assoc_resp); |
| 4303 | reply->u.assoc_resp.capab_info = |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 4304 | host_to_le16(hostapd_own_capab_info(hapd)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4305 | reply->u.assoc_resp.status_code = host_to_le16(status_code); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4306 | |
| 4307 | reply->u.assoc_resp.aid = host_to_le16((sta ? sta->aid : 0) | |
| 4308 | BIT(14) | BIT(15)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4309 | /* Supported rates */ |
| 4310 | p = hostapd_eid_supp_rates(hapd, reply->u.assoc_resp.variable); |
| 4311 | /* Extended supported rates */ |
| 4312 | p = hostapd_eid_ext_supp_rates(hapd, p); |
| 4313 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4314 | /* Radio measurement capabilities */ |
| 4315 | p = hostapd_eid_rm_enabled_capab(hapd, p, buf + buflen - p); |
| 4316 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4317 | #ifdef CONFIG_MBO |
| 4318 | if (status_code == WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS && |
| 4319 | rssi != 0) { |
| 4320 | int delta = hapd->iconf->rssi_reject_assoc_rssi - rssi; |
| 4321 | |
| 4322 | p = hostapd_eid_mbo_rssi_assoc_rej(hapd, p, buf + buflen - p, |
| 4323 | delta); |
| 4324 | } |
| 4325 | #endif /* CONFIG_MBO */ |
| 4326 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4327 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4328 | if (sta && status_code == WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4329 | /* IEEE 802.11r: Mobility Domain Information, Fast BSS |
| 4330 | * Transition Information, RSN, [RIC Response] */ |
| 4331 | p = wpa_sm_write_assoc_resp_ies(sta->wpa_sm, p, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4332 | buf + buflen - p, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4333 | sta->auth_alg, ies, ies_len, |
| 4334 | omit_rsnxe); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4335 | if (!p) { |
| 4336 | wpa_printf(MSG_DEBUG, |
| 4337 | "FT: Failed to write AssocResp IEs"); |
| 4338 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4339 | goto done; |
| 4340 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4341 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4342 | #endif /* CONFIG_IEEE80211R_AP */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4343 | #ifdef CONFIG_FILS |
| 4344 | if (sta && status_code == WLAN_STATUS_SUCCESS && |
| 4345 | (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 4346 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 4347 | sta->auth_alg == WLAN_AUTH_FILS_PK)) |
| 4348 | p = wpa_auth_write_assoc_resp_fils(sta->wpa_sm, p, |
| 4349 | buf + buflen - p, |
| 4350 | ies, ies_len); |
| 4351 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4352 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4353 | #ifdef CONFIG_OWE |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4354 | if (sta && status_code == WLAN_STATUS_SUCCESS && |
| 4355 | (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE)) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4356 | p = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, p, |
| 4357 | buf + buflen - p, |
| 4358 | ies, ies_len); |
| 4359 | #endif /* CONFIG_OWE */ |
| 4360 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4361 | if (sta && status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4362 | p = hostapd_eid_assoc_comeback_time(hapd, sta, p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4363 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4364 | p = hostapd_eid_ht_capabilities(hapd, p); |
| 4365 | p = hostapd_eid_ht_operation(hapd, p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4366 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4367 | #ifdef CONFIG_IEEE80211AC |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4368 | if (hapd->iconf->ieee80211ac && !hapd->conf->disable_11ac && |
| 4369 | !is_6ghz_op_class(hapd->iconf->op_class)) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 4370 | u32 nsts = 0, sta_nsts; |
| 4371 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4372 | if (sta && hapd->conf->use_sta_nsts && sta->vht_capabilities) { |
Dmitry Shmidt | 7d17530 | 2016-09-06 13:11:34 -0700 | [diff] [blame] | 4373 | struct ieee80211_vht_capabilities *capa; |
| 4374 | |
| 4375 | nsts = (hapd->iface->conf->vht_capab >> |
| 4376 | VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7; |
| 4377 | capa = sta->vht_capabilities; |
| 4378 | sta_nsts = (le_to_host32(capa->vht_capabilities_info) >> |
| 4379 | VHT_CAP_BEAMFORMEE_STS_OFFSET) & 7; |
| 4380 | |
| 4381 | if (nsts < sta_nsts) |
| 4382 | nsts = 0; |
| 4383 | else |
| 4384 | nsts = sta_nsts; |
| 4385 | } |
| 4386 | p = hostapd_eid_vht_capabilities(hapd, p, nsts); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4387 | p = hostapd_eid_vht_operation(hapd, p); |
| 4388 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4389 | #endif /* CONFIG_IEEE80211AC */ |
| 4390 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4391 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4392 | if (hapd->iconf->ieee80211ax && !hapd->conf->disable_11ax) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4393 | p = hostapd_eid_he_capab(hapd, p, IEEE80211_MODE_AP); |
| 4394 | p = hostapd_eid_he_operation(hapd, p); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4395 | p = hostapd_eid_cca(hapd, p); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4396 | p = hostapd_eid_spatial_reuse(hapd, p); |
| 4397 | p = hostapd_eid_he_mu_edca_parameter_set(hapd, p); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4398 | p = hostapd_eid_he_6ghz_band_cap(hapd, p); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4399 | } |
| 4400 | #endif /* CONFIG_IEEE80211AX */ |
| 4401 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4402 | p = hostapd_eid_ext_capab(hapd, p, false); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4403 | p = hostapd_eid_bss_max_idle_period(hapd, p); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4404 | if (sta && sta->qos_map_enabled) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 4405 | p = hostapd_eid_qos_map_set(hapd, p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4406 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4407 | #ifdef CONFIG_FST |
| 4408 | if (hapd->iface->fst_ies) { |
| 4409 | os_memcpy(p, wpabuf_head(hapd->iface->fst_ies), |
| 4410 | wpabuf_len(hapd->iface->fst_ies)); |
| 4411 | p += wpabuf_len(hapd->iface->fst_ies); |
| 4412 | } |
| 4413 | #endif /* CONFIG_FST */ |
| 4414 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4415 | #ifdef CONFIG_TESTING_OPTIONS |
| 4416 | if (hapd->conf->rsnxe_override_ft && |
| 4417 | buf + buflen - p >= |
| 4418 | (long int) wpabuf_len(hapd->conf->rsnxe_override_ft) && |
| 4419 | sta && sta->auth_alg == WLAN_AUTH_FT) { |
| 4420 | wpa_printf(MSG_DEBUG, "TESTING: RSNXE FT override"); |
| 4421 | os_memcpy(p, wpabuf_head(hapd->conf->rsnxe_override_ft), |
| 4422 | wpabuf_len(hapd->conf->rsnxe_override_ft)); |
| 4423 | p += wpabuf_len(hapd->conf->rsnxe_override_ft); |
| 4424 | goto rsnxe_done; |
| 4425 | } |
| 4426 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4427 | if (!omit_rsnxe) |
| 4428 | p = hostapd_eid_rsnxe(hapd, p, buf + buflen - p); |
| 4429 | #ifdef CONFIG_TESTING_OPTIONS |
| 4430 | rsnxe_done: |
| 4431 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4432 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4433 | #ifdef CONFIG_IEEE80211BE |
| 4434 | if (hapd->iconf->ieee80211be && !hapd->conf->disable_11be) { |
| 4435 | p = hostapd_eid_eht_capab(hapd, p, IEEE80211_MODE_AP); |
| 4436 | p = hostapd_eid_eht_operation(hapd, p); |
| 4437 | } |
| 4438 | #endif /* CONFIG_IEEE80211BE */ |
| 4439 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4440 | #ifdef CONFIG_OWE |
| 4441 | if ((hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_OWE) && |
| 4442 | sta && sta->owe_ecdh && status_code == WLAN_STATUS_SUCCESS && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4443 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_OWE && |
| 4444 | !wpa_auth_sta_get_pmksa(sta->wpa_sm)) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4445 | struct wpabuf *pub; |
| 4446 | |
| 4447 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 4448 | if (!pub) { |
| 4449 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4450 | goto done; |
| 4451 | } |
| 4452 | /* OWE Diffie-Hellman Parameter element */ |
| 4453 | *p++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 4454 | *p++ = 1 + 2 + wpabuf_len(pub); /* Length */ |
| 4455 | *p++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension */ |
| 4456 | WPA_PUT_LE16(p, sta->owe_group); |
| 4457 | p += 2; |
| 4458 | os_memcpy(p, wpabuf_head(pub), wpabuf_len(pub)); |
| 4459 | p += wpabuf_len(pub); |
| 4460 | wpabuf_free(pub); |
| 4461 | } |
| 4462 | #endif /* CONFIG_OWE */ |
| 4463 | |
| 4464 | #ifdef CONFIG_DPP2 |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4465 | if (DPP_VERSION > 1 && (hapd->conf->wpa_key_mgmt & WPA_KEY_MGMT_DPP) && |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4466 | sta && sta->dpp_pfs && status_code == WLAN_STATUS_SUCCESS && |
| 4467 | wpa_auth_sta_key_mgmt(sta->wpa_sm) == WPA_KEY_MGMT_DPP) { |
| 4468 | os_memcpy(p, wpabuf_head(sta->dpp_pfs->ie), |
| 4469 | wpabuf_len(sta->dpp_pfs->ie)); |
| 4470 | p += wpabuf_len(sta->dpp_pfs->ie); |
| 4471 | } |
| 4472 | #endif /* CONFIG_DPP2 */ |
| 4473 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4474 | #ifdef CONFIG_IEEE80211AC |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4475 | if (sta && hapd->conf->vendor_vht && (sta->flags & WLAN_STA_VENDOR_VHT)) |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4476 | p = hostapd_eid_vendor_vht(hapd, p); |
| 4477 | #endif /* CONFIG_IEEE80211AC */ |
| 4478 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4479 | if (sta && (sta->flags & WLAN_STA_WMM)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4480 | p = hostapd_eid_wmm(hapd, p); |
| 4481 | |
| 4482 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4483 | if (sta && |
| 4484 | ((sta->flags & WLAN_STA_WPS) || |
| 4485 | ((sta->flags & WLAN_STA_MAYBE_WPS) && hapd->conf->wpa))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4486 | struct wpabuf *wps = wps_build_assoc_resp_ie(); |
| 4487 | if (wps) { |
| 4488 | os_memcpy(p, wpabuf_head(wps), wpabuf_len(wps)); |
| 4489 | p += wpabuf_len(wps); |
| 4490 | wpabuf_free(wps); |
| 4491 | } |
| 4492 | } |
| 4493 | #endif /* CONFIG_WPS */ |
| 4494 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4495 | if (sta && (sta->flags & WLAN_STA_MULTI_AP)) |
| 4496 | p = hostapd_eid_multi_ap(hapd, p); |
| 4497 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4498 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4499 | if (sta && sta->p2p_ie && hapd->p2p_group) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4500 | struct wpabuf *p2p_resp_ie; |
| 4501 | enum p2p_status_code status; |
| 4502 | switch (status_code) { |
| 4503 | case WLAN_STATUS_SUCCESS: |
| 4504 | status = P2P_SC_SUCCESS; |
| 4505 | break; |
| 4506 | case WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA: |
| 4507 | status = P2P_SC_FAIL_LIMIT_REACHED; |
| 4508 | break; |
| 4509 | default: |
| 4510 | status = P2P_SC_FAIL_INVALID_PARAMS; |
| 4511 | break; |
| 4512 | } |
| 4513 | p2p_resp_ie = p2p_group_assoc_resp_ie(hapd->p2p_group, status); |
| 4514 | if (p2p_resp_ie) { |
| 4515 | os_memcpy(p, wpabuf_head(p2p_resp_ie), |
| 4516 | wpabuf_len(p2p_resp_ie)); |
| 4517 | p += wpabuf_len(p2p_resp_ie); |
| 4518 | wpabuf_free(p2p_resp_ie); |
| 4519 | } |
| 4520 | } |
| 4521 | #endif /* CONFIG_P2P */ |
| 4522 | |
| 4523 | #ifdef CONFIG_P2P_MANAGER |
| 4524 | if (hapd->conf->p2p & P2P_MANAGE) |
| 4525 | p = hostapd_eid_p2p_manage(hapd, p); |
| 4526 | #endif /* CONFIG_P2P_MANAGER */ |
| 4527 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4528 | p = hostapd_eid_mbo(hapd, p, buf + buflen - p); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4529 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4530 | if (hapd->conf->assocresp_elements && |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4531 | (size_t) (buf + buflen - p) >= |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4532 | wpabuf_len(hapd->conf->assocresp_elements)) { |
| 4533 | os_memcpy(p, wpabuf_head(hapd->conf->assocresp_elements), |
| 4534 | wpabuf_len(hapd->conf->assocresp_elements)); |
| 4535 | p += wpabuf_len(hapd->conf->assocresp_elements); |
| 4536 | } |
| 4537 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4538 | send_len += p - reply->u.assoc_resp.variable; |
| 4539 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4540 | #ifdef CONFIG_FILS |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4541 | if (sta && |
| 4542 | (sta->auth_alg == WLAN_AUTH_FILS_SK || |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4543 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 4544 | sta->auth_alg == WLAN_AUTH_FILS_PK) && |
| 4545 | status_code == WLAN_STATUS_SUCCESS) { |
| 4546 | struct ieee802_11_elems elems; |
| 4547 | |
| 4548 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 0) == |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4549 | ParseFailed || !elems.fils_session) { |
| 4550 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4551 | goto done; |
| 4552 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4553 | |
| 4554 | /* FILS Session */ |
| 4555 | *p++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 4556 | *p++ = 1 + FILS_SESSION_LEN; /* Length */ |
| 4557 | *p++ = WLAN_EID_EXT_FILS_SESSION; /* Element ID Extension */ |
| 4558 | os_memcpy(p, elems.fils_session, FILS_SESSION_LEN); |
| 4559 | send_len += 2 + 1 + FILS_SESSION_LEN; |
| 4560 | |
| 4561 | send_len = fils_encrypt_assoc(sta->wpa_sm, buf, send_len, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4562 | buflen, sta->fils_hlp_resp); |
| 4563 | if (send_len < 0) { |
| 4564 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4565 | goto done; |
| 4566 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4567 | } |
| 4568 | #endif /* CONFIG_FILS */ |
| 4569 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4570 | 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] | 4571 | wpa_printf(MSG_INFO, "Failed to send assoc resp: %s", |
| 4572 | strerror(errno)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4573 | res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4574 | } |
| 4575 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4576 | done: |
| 4577 | os_free(buf); |
| 4578 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4582 | #ifdef CONFIG_OWE |
| 4583 | u8 * owe_assoc_req_process(struct hostapd_data *hapd, struct sta_info *sta, |
| 4584 | const u8 *owe_dh, u8 owe_dh_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4585 | u8 *owe_buf, size_t owe_buf_len, u16 *status) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4586 | { |
| 4587 | #ifdef CONFIG_TESTING_OPTIONS |
| 4588 | if (hapd->conf->own_ie_override) { |
| 4589 | wpa_printf(MSG_DEBUG, "OWE: Using IE override"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4590 | *status = WLAN_STATUS_SUCCESS; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4591 | return wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf, |
| 4592 | owe_buf_len, NULL, 0); |
| 4593 | } |
| 4594 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4595 | |
| 4596 | if (wpa_auth_sta_get_pmksa(sta->wpa_sm)) { |
| 4597 | wpa_printf(MSG_DEBUG, "OWE: Using PMKSA caching"); |
| 4598 | owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf, |
| 4599 | owe_buf_len, NULL, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4600 | *status = WLAN_STATUS_SUCCESS; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4601 | return owe_buf; |
| 4602 | } |
| 4603 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4604 | if (sta->owe_pmk && sta->external_dh_updated) { |
| 4605 | wpa_printf(MSG_DEBUG, "OWE: Using previously derived PMK"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4606 | *status = WLAN_STATUS_SUCCESS; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4607 | return owe_buf; |
| 4608 | } |
| 4609 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4610 | *status = owe_process_assoc_req(hapd, sta, owe_dh, owe_dh_len); |
| 4611 | if (*status != WLAN_STATUS_SUCCESS) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4612 | return NULL; |
| 4613 | |
| 4614 | owe_buf = wpa_auth_write_assoc_resp_owe(sta->wpa_sm, owe_buf, |
| 4615 | owe_buf_len, NULL, 0); |
| 4616 | |
| 4617 | if (sta->owe_ecdh && owe_buf) { |
| 4618 | struct wpabuf *pub; |
| 4619 | |
| 4620 | pub = crypto_ecdh_get_pubkey(sta->owe_ecdh, 0); |
| 4621 | if (!pub) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4622 | *status = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4623 | return owe_buf; |
| 4624 | } |
| 4625 | |
| 4626 | /* OWE Diffie-Hellman Parameter element */ |
| 4627 | *owe_buf++ = WLAN_EID_EXTENSION; /* Element ID */ |
| 4628 | *owe_buf++ = 1 + 2 + wpabuf_len(pub); /* Length */ |
| 4629 | *owe_buf++ = WLAN_EID_EXT_OWE_DH_PARAM; /* Element ID Extension |
| 4630 | */ |
| 4631 | WPA_PUT_LE16(owe_buf, sta->owe_group); |
| 4632 | owe_buf += 2; |
| 4633 | os_memcpy(owe_buf, wpabuf_head(pub), wpabuf_len(pub)); |
| 4634 | owe_buf += wpabuf_len(pub); |
| 4635 | wpabuf_free(pub); |
| 4636 | } |
| 4637 | |
| 4638 | return owe_buf; |
| 4639 | } |
| 4640 | #endif /* CONFIG_OWE */ |
| 4641 | |
| 4642 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4643 | #ifdef CONFIG_FILS |
| 4644 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4645 | 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] | 4646 | { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4647 | u16 reply_res; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4648 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4649 | wpa_printf(MSG_DEBUG, "FILS: Finish association with " MACSTR, |
| 4650 | MAC2STR(sta->addr)); |
| 4651 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 4652 | if (!sta->fils_pending_assoc_req) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4653 | return; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4654 | reply_res = send_assoc_resp(hapd, sta, sta->addr, WLAN_STATUS_SUCCESS, |
| 4655 | sta->fils_pending_assoc_is_reassoc, |
| 4656 | sta->fils_pending_assoc_req, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4657 | sta->fils_pending_assoc_req_len, 0, 0); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4658 | os_free(sta->fils_pending_assoc_req); |
| 4659 | sta->fils_pending_assoc_req = NULL; |
| 4660 | sta->fils_pending_assoc_req_len = 0; |
| 4661 | wpabuf_free(sta->fils_hlp_resp); |
| 4662 | sta->fils_hlp_resp = NULL; |
| 4663 | wpabuf_free(sta->hlp_dhcp_discover); |
| 4664 | sta->hlp_dhcp_discover = NULL; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4665 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4666 | /* |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4667 | * Remove the station in case transmission of a success response fails. |
| 4668 | * At this point the station was already added associated to the driver. |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4669 | */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4670 | if (reply_res != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4671 | hostapd_drv_sta_remove(hapd, sta->addr); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4675 | void fils_hlp_timeout(void *eloop_ctx, void *eloop_data) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4676 | { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4677 | struct hostapd_data *hapd = eloop_ctx; |
| 4678 | struct sta_info *sta = eloop_data; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4679 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4680 | wpa_printf(MSG_DEBUG, |
| 4681 | "FILS: HLP response timeout - continue with association response for " |
| 4682 | MACSTR, MAC2STR(sta->addr)); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4683 | if (sta->fils_drv_assoc_finish) |
| 4684 | hostapd_notify_assoc_fils_finish(hapd, sta); |
| 4685 | else |
| 4686 | fils_hlp_finish_assoc(hapd, sta); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4687 | } |
| 4688 | |
| 4689 | #endif /* CONFIG_FILS */ |
| 4690 | |
| 4691 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4692 | static void handle_assoc(struct hostapd_data *hapd, |
| 4693 | const struct ieee80211_mgmt *mgmt, size_t len, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4694 | int reassoc, int rssi) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4695 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4696 | u16 capab_info, listen_interval, seq_ctrl, fc; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4697 | int resp = WLAN_STATUS_SUCCESS; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4698 | u16 reply_res = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4699 | const u8 *pos; |
| 4700 | int left, i; |
| 4701 | struct sta_info *sta; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4702 | u8 *tmp = NULL; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4703 | #ifdef CONFIG_FILS |
| 4704 | int delay_assoc = 0; |
| 4705 | #endif /* CONFIG_FILS */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4706 | int omit_rsnxe = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4707 | |
| 4708 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_req) : |
| 4709 | sizeof(mgmt->u.assoc_req))) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4710 | wpa_printf(MSG_INFO, "handle_assoc(reassoc=%d) - too short payload (len=%lu)", |
| 4711 | reassoc, (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4712 | return; |
| 4713 | } |
| 4714 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4715 | #ifdef CONFIG_TESTING_OPTIONS |
| 4716 | if (reassoc) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4717 | if (hapd->iconf->ignore_reassoc_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4718 | drand48() < hapd->iconf->ignore_reassoc_probability) { |
| 4719 | wpa_printf(MSG_INFO, |
| 4720 | "TESTING: ignoring reassoc request from " |
| 4721 | MACSTR, MAC2STR(mgmt->sa)); |
| 4722 | return; |
| 4723 | } |
| 4724 | } else { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4725 | if (hapd->iconf->ignore_assoc_probability > 0.0 && |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4726 | drand48() < hapd->iconf->ignore_assoc_probability) { |
| 4727 | wpa_printf(MSG_INFO, |
| 4728 | "TESTING: ignoring assoc request from " |
| 4729 | MACSTR, MAC2STR(mgmt->sa)); |
| 4730 | return; |
| 4731 | } |
| 4732 | } |
| 4733 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4734 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4735 | fc = le_to_host16(mgmt->frame_control); |
| 4736 | seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
| 4737 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4738 | if (reassoc) { |
| 4739 | capab_info = le_to_host16(mgmt->u.reassoc_req.capab_info); |
| 4740 | listen_interval = le_to_host16( |
| 4741 | mgmt->u.reassoc_req.listen_interval); |
| 4742 | wpa_printf(MSG_DEBUG, "reassociation request: STA=" MACSTR |
| 4743 | " capab_info=0x%02x listen_interval=%d current_ap=" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4744 | MACSTR " seq_ctrl=0x%x%s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4745 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4746 | MAC2STR(mgmt->u.reassoc_req.current_ap), |
| 4747 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4748 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.reassoc_req)); |
| 4749 | pos = mgmt->u.reassoc_req.variable; |
| 4750 | } else { |
| 4751 | capab_info = le_to_host16(mgmt->u.assoc_req.capab_info); |
| 4752 | listen_interval = le_to_host16( |
| 4753 | mgmt->u.assoc_req.listen_interval); |
| 4754 | wpa_printf(MSG_DEBUG, "association request: STA=" MACSTR |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4755 | " capab_info=0x%02x listen_interval=%d " |
| 4756 | "seq_ctrl=0x%x%s", |
| 4757 | MAC2STR(mgmt->sa), capab_info, listen_interval, |
| 4758 | seq_ctrl, (fc & WLAN_FC_RETRY) ? " retry" : ""); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4759 | left = len - (IEEE80211_HDRLEN + sizeof(mgmt->u.assoc_req)); |
| 4760 | pos = mgmt->u.assoc_req.variable; |
| 4761 | } |
| 4762 | |
| 4763 | sta = ap_get_sta(hapd, mgmt->sa); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4764 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4765 | if (sta && sta->auth_alg == WLAN_AUTH_FT && |
| 4766 | (sta->flags & WLAN_STA_AUTH) == 0) { |
| 4767 | wpa_printf(MSG_DEBUG, "FT: Allow STA " MACSTR " to associate " |
| 4768 | "prior to authentication since it is using " |
| 4769 | "over-the-DS FT", MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4770 | |
| 4771 | /* |
| 4772 | * Mark station as authenticated, to avoid adding station |
| 4773 | * entry in the driver as associated and not authenticated |
| 4774 | */ |
| 4775 | sta->flags |= WLAN_STA_AUTH; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4776 | } else |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4777 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4778 | if (sta == NULL || (sta->flags & WLAN_STA_AUTH) == 0) { |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4779 | if (hapd->iface->current_mode && |
| 4780 | hapd->iface->current_mode->mode == |
| 4781 | HOSTAPD_MODE_IEEE80211AD) { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4782 | int acl_res; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4783 | struct radius_sta info; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4784 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4785 | acl_res = ieee802_11_allowed_address(hapd, mgmt->sa, |
| 4786 | (const u8 *) mgmt, |
| 4787 | len, &info); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4788 | if (acl_res == HOSTAPD_ACL_REJECT) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4789 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, |
| 4790 | "Ignore Association Request frame from " |
| 4791 | MACSTR " due to ACL reject", |
| 4792 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4793 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4794 | goto fail; |
| 4795 | } |
| 4796 | if (acl_res == HOSTAPD_ACL_PENDING) |
| 4797 | return; |
| 4798 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4799 | /* DMG/IEEE 802.11ad does not use authentication. |
| 4800 | * Allocate sta entry upon association. */ |
| 4801 | sta = ap_sta_add(hapd, mgmt->sa); |
| 4802 | if (!sta) { |
| 4803 | hostapd_logger(hapd, mgmt->sa, |
| 4804 | HOSTAPD_MODULE_IEEE80211, |
| 4805 | HOSTAPD_LEVEL_INFO, |
| 4806 | "Failed to add STA"); |
| 4807 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 4808 | goto fail; |
| 4809 | } |
| 4810 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4811 | acl_res = ieee802_11_set_radius_info( |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4812 | hapd, sta, acl_res, &info); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 4813 | if (acl_res) { |
| 4814 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4815 | goto fail; |
| 4816 | } |
| 4817 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 4818 | hostapd_logger(hapd, sta->addr, |
| 4819 | HOSTAPD_MODULE_IEEE80211, |
| 4820 | HOSTAPD_LEVEL_DEBUG, |
| 4821 | "Skip authentication for DMG/IEEE 802.11ad"); |
| 4822 | sta->flags |= WLAN_STA_AUTH; |
| 4823 | wpa_auth_sm_event(sta->wpa_sm, WPA_AUTH); |
| 4824 | sta->auth_alg = WLAN_AUTH_OPEN; |
| 4825 | } else { |
| 4826 | hostapd_logger(hapd, mgmt->sa, |
| 4827 | HOSTAPD_MODULE_IEEE80211, |
| 4828 | HOSTAPD_LEVEL_INFO, |
| 4829 | "Station tried to associate before authentication (aid=%d flags=0x%x)", |
| 4830 | sta ? sta->aid : -1, |
| 4831 | sta ? sta->flags : 0); |
| 4832 | send_deauth(hapd, mgmt->sa, |
| 4833 | WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA); |
| 4834 | return; |
| 4835 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4836 | } |
| 4837 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4838 | if ((fc & WLAN_FC_RETRY) && |
| 4839 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 4840 | sta->last_seq_ctrl == seq_ctrl && |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4841 | sta->last_subtype == (reassoc ? WLAN_FC_STYPE_REASSOC_REQ : |
| 4842 | WLAN_FC_STYPE_ASSOC_REQ)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4843 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 4844 | HOSTAPD_LEVEL_DEBUG, |
| 4845 | "Drop repeated association frame seq_ctrl=0x%x", |
| 4846 | seq_ctrl); |
| 4847 | return; |
| 4848 | } |
| 4849 | sta->last_seq_ctrl = seq_ctrl; |
| 4850 | sta->last_subtype = reassoc ? WLAN_FC_STYPE_REASSOC_REQ : |
| 4851 | WLAN_FC_STYPE_ASSOC_REQ; |
| 4852 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4853 | if (hapd->tkip_countermeasures) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4854 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4855 | goto fail; |
| 4856 | } |
| 4857 | |
| 4858 | if (listen_interval > hapd->conf->max_listen_interval) { |
| 4859 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 4860 | HOSTAPD_LEVEL_DEBUG, |
| 4861 | "Too large Listen Interval (%d)", |
| 4862 | listen_interval); |
| 4863 | resp = WLAN_STATUS_ASSOC_DENIED_LISTEN_INT_TOO_LARGE; |
| 4864 | goto fail; |
| 4865 | } |
| 4866 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4867 | #ifdef CONFIG_MBO |
| 4868 | if (hapd->conf->mbo_enabled && hapd->mbo_assoc_disallow) { |
| 4869 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 4870 | goto fail; |
| 4871 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4872 | |
| 4873 | if (hapd->iconf->rssi_reject_assoc_rssi && rssi && |
| 4874 | rssi < hapd->iconf->rssi_reject_assoc_rssi && |
| 4875 | (sta->auth_rssi == 0 || |
| 4876 | sta->auth_rssi < hapd->iconf->rssi_reject_assoc_rssi)) { |
| 4877 | resp = WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS; |
| 4878 | goto fail; |
| 4879 | } |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4880 | #endif /* CONFIG_MBO */ |
| 4881 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4882 | /* |
| 4883 | * sta->capability is used in check_assoc_ies() for RRM enabled |
| 4884 | * capability element. |
| 4885 | */ |
| 4886 | sta->capability = capab_info; |
| 4887 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4888 | #ifdef CONFIG_FILS |
| 4889 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 4890 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 4891 | sta->auth_alg == WLAN_AUTH_FILS_PK) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4892 | int res; |
| 4893 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4894 | /* The end of the payload is encrypted. Need to decrypt it |
| 4895 | * before parsing. */ |
| 4896 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4897 | tmp = os_memdup(pos, left); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4898 | if (!tmp) { |
| 4899 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4900 | goto fail; |
| 4901 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4902 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4903 | res = fils_decrypt_assoc(sta->wpa_sm, sta->fils_session, mgmt, |
| 4904 | len, tmp, left); |
| 4905 | if (res < 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4906 | resp = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 4907 | goto fail; |
| 4908 | } |
| 4909 | pos = tmp; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4910 | left = res; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4911 | } |
| 4912 | #endif /* CONFIG_FILS */ |
| 4913 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4914 | /* followed by SSID and Supported rates; and HT capabilities if 802.11n |
| 4915 | * is used */ |
| 4916 | resp = check_assoc_ies(hapd, sta, pos, left, reassoc); |
| 4917 | if (resp != WLAN_STATUS_SUCCESS) |
| 4918 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4919 | omit_rsnxe = !get_ie(pos, left, WLAN_EID_RSNX); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4920 | |
| 4921 | if (hostapd_get_aid(hapd, sta) < 0) { |
| 4922 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 4923 | HOSTAPD_LEVEL_INFO, "No room for more AIDs"); |
| 4924 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 4925 | goto fail; |
| 4926 | } |
| 4927 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4928 | sta->listen_interval = listen_interval; |
| 4929 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4930 | if (hapd->iface->current_mode && |
| 4931 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4932 | sta->flags |= WLAN_STA_NONERP; |
| 4933 | for (i = 0; i < sta->supported_rates_len; i++) { |
| 4934 | if ((sta->supported_rates[i] & 0x7f) > 22) { |
| 4935 | sta->flags &= ~WLAN_STA_NONERP; |
| 4936 | break; |
| 4937 | } |
| 4938 | } |
| 4939 | if (sta->flags & WLAN_STA_NONERP && !sta->nonerp_set) { |
| 4940 | sta->nonerp_set = 1; |
| 4941 | hapd->iface->num_sta_non_erp++; |
| 4942 | if (hapd->iface->num_sta_non_erp == 1) |
| 4943 | ieee802_11_set_beacons(hapd->iface); |
| 4944 | } |
| 4945 | |
| 4946 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_SLOT_TIME) && |
| 4947 | !sta->no_short_slot_time_set) { |
| 4948 | sta->no_short_slot_time_set = 1; |
| 4949 | hapd->iface->num_sta_no_short_slot_time++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4950 | if (hapd->iface->current_mode && |
| 4951 | hapd->iface->current_mode->mode == |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4952 | HOSTAPD_MODE_IEEE80211G && |
| 4953 | hapd->iface->num_sta_no_short_slot_time == 1) |
| 4954 | ieee802_11_set_beacons(hapd->iface); |
| 4955 | } |
| 4956 | |
| 4957 | if (sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) |
| 4958 | sta->flags |= WLAN_STA_SHORT_PREAMBLE; |
| 4959 | else |
| 4960 | sta->flags &= ~WLAN_STA_SHORT_PREAMBLE; |
| 4961 | |
| 4962 | if (!(sta->capability & WLAN_CAPABILITY_SHORT_PREAMBLE) && |
| 4963 | !sta->no_short_preamble_set) { |
| 4964 | sta->no_short_preamble_set = 1; |
| 4965 | hapd->iface->num_sta_no_short_preamble++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4966 | if (hapd->iface->current_mode && |
| 4967 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211G |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4968 | && hapd->iface->num_sta_no_short_preamble == 1) |
| 4969 | ieee802_11_set_beacons(hapd->iface); |
| 4970 | } |
| 4971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | update_ht_state(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4973 | |
| 4974 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 4975 | HOSTAPD_LEVEL_DEBUG, |
| 4976 | "association OK (aid %d)", sta->aid); |
| 4977 | /* Station will be marked associated, after it acknowledges AssocResp |
| 4978 | */ |
| 4979 | sta->flags |= WLAN_STA_ASSOC_REQ_OK; |
| 4980 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4981 | if ((sta->flags & WLAN_STA_MFP) && sta->sa_query_timed_out) { |
| 4982 | wpa_printf(MSG_DEBUG, "Allowing %sassociation after timed out " |
| 4983 | "SA Query procedure", reassoc ? "re" : ""); |
| 4984 | /* TODO: Send a protected Disassociate frame to the STA using |
| 4985 | * the old key and Reason Code "Previous Authentication no |
| 4986 | * longer valid". Make sure this is only sent protected since |
| 4987 | * unprotected frame would be received by the STA that is now |
| 4988 | * trying to associate. |
| 4989 | */ |
| 4990 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4991 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4992 | /* Make sure that the previously registered inactivity timer will not |
| 4993 | * remove the STA immediately. */ |
| 4994 | sta->timeout_next = STA_NULLFUNC; |
| 4995 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4996 | #ifdef CONFIG_TAXONOMY |
| 4997 | taxonomy_sta_info_assoc_req(hapd, sta, pos, left); |
| 4998 | #endif /* CONFIG_TAXONOMY */ |
| 4999 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5000 | sta->pending_wds_enable = 0; |
| 5001 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5002 | #ifdef CONFIG_FILS |
| 5003 | if (sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 5004 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5005 | sta->auth_alg == WLAN_AUTH_FILS_PK) { |
| 5006 | if (fils_process_hlp(hapd, sta, pos, left) > 0) |
| 5007 | delay_assoc = 1; |
| 5008 | } |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5009 | #endif /* CONFIG_FILS */ |
| 5010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5011 | fail: |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5012 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5013 | /* |
| 5014 | * In case of a successful response, add the station to the driver. |
| 5015 | * Otherwise, the kernel may ignore Data frames before we process the |
| 5016 | * ACK frame (TX status). In case of a failure, this station will be |
| 5017 | * removed. |
| 5018 | * |
| 5019 | * Note that this is not compliant with the IEEE 802.11 standard that |
| 5020 | * states that a non-AP station should transition into the |
| 5021 | * authenticated/associated state only after the station acknowledges |
| 5022 | * the (Re)Association Response frame. However, still do this as: |
| 5023 | * |
| 5024 | * 1. In case the station does not acknowledge the (Re)Association |
| 5025 | * Response frame, it will be removed. |
| 5026 | * 2. Data frames will be dropped in the kernel until the station is |
| 5027 | * set into authorized state, and there are no significant known |
| 5028 | * issues with processing other non-Data Class 3 frames during this |
| 5029 | * window. |
| 5030 | */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5031 | if (resp == WLAN_STATUS_SUCCESS && sta && |
| 5032 | add_associated_sta(hapd, sta, reassoc)) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5033 | resp = WLAN_STATUS_AP_UNABLE_TO_HANDLE_NEW_STA; |
| 5034 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5035 | #ifdef CONFIG_FILS |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5036 | if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS && |
| 5037 | eloop_is_timeout_registered(fils_hlp_timeout, hapd, sta) && |
| 5038 | sta->fils_pending_assoc_req) { |
| 5039 | /* Do not reschedule fils_hlp_timeout in case the station |
| 5040 | * retransmits (Re)Association Request frame while waiting for |
| 5041 | * the previously started FILS HLP wait, so that the timeout can |
| 5042 | * be determined from the first pending attempt. */ |
| 5043 | wpa_printf(MSG_DEBUG, |
| 5044 | "FILS: Continue waiting for HLP processing before sending (Re)Association Response frame to " |
| 5045 | MACSTR, MAC2STR(sta->addr)); |
| 5046 | os_free(tmp); |
| 5047 | return; |
| 5048 | } |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5049 | if (sta) { |
| 5050 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 5051 | os_free(sta->fils_pending_assoc_req); |
| 5052 | sta->fils_pending_assoc_req = NULL; |
| 5053 | sta->fils_pending_assoc_req_len = 0; |
| 5054 | wpabuf_free(sta->fils_hlp_resp); |
| 5055 | sta->fils_hlp_resp = NULL; |
| 5056 | } |
| 5057 | if (sta && delay_assoc && resp == WLAN_STATUS_SUCCESS) { |
| 5058 | sta->fils_pending_assoc_req = tmp; |
| 5059 | sta->fils_pending_assoc_req_len = left; |
| 5060 | sta->fils_pending_assoc_is_reassoc = reassoc; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5061 | sta->fils_drv_assoc_finish = 0; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5062 | wpa_printf(MSG_DEBUG, |
| 5063 | "FILS: Waiting for HLP processing before sending (Re)Association Response frame to " |
| 5064 | MACSTR, MAC2STR(sta->addr)); |
| 5065 | eloop_cancel_timeout(fils_hlp_timeout, hapd, sta); |
| 5066 | eloop_register_timeout(0, hapd->conf->fils_hlp_wait_time * 1024, |
| 5067 | fils_hlp_timeout, hapd, sta); |
| 5068 | return; |
| 5069 | } |
| 5070 | #endif /* CONFIG_FILS */ |
| 5071 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5072 | if (resp >= 0) |
| 5073 | reply_res = send_assoc_resp(hapd, sta, mgmt->sa, resp, reassoc, |
| 5074 | pos, left, rssi, omit_rsnxe); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5075 | os_free(tmp); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5076 | |
| 5077 | /* |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5078 | * Remove the station in case transmission of a success response fails |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5079 | * (the STA was added associated to the driver) or if the station was |
| 5080 | * previously added unassociated. |
| 5081 | */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5082 | if (sta && ((reply_res != WLAN_STATUS_SUCCESS && |
| 5083 | resp == WLAN_STATUS_SUCCESS) || sta->added_unassoc)) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5084 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 5085 | sta->added_unassoc = 0; |
| 5086 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5087 | } |
| 5088 | |
| 5089 | |
| 5090 | static void handle_disassoc(struct hostapd_data *hapd, |
| 5091 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 5092 | { |
| 5093 | struct sta_info *sta; |
| 5094 | |
| 5095 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.disassoc)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5096 | wpa_printf(MSG_INFO, "handle_disassoc - too short payload (len=%lu)", |
| 5097 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5098 | return; |
| 5099 | } |
| 5100 | |
| 5101 | wpa_printf(MSG_DEBUG, "disassocation: STA=" MACSTR " reason_code=%d", |
| 5102 | MAC2STR(mgmt->sa), |
| 5103 | le_to_host16(mgmt->u.disassoc.reason_code)); |
| 5104 | |
| 5105 | sta = ap_get_sta(hapd, mgmt->sa); |
| 5106 | if (sta == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5107 | wpa_printf(MSG_INFO, "Station " MACSTR " trying to disassociate, but it is not associated", |
| 5108 | MAC2STR(mgmt->sa)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5109 | return; |
| 5110 | } |
| 5111 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5112 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5113 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5114 | sta->flags &= ~(WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5115 | hostapd_set_sta_flags(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5116 | wpa_auth_sm_event(sta->wpa_sm, WPA_DISASSOC); |
| 5117 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 5118 | HOSTAPD_LEVEL_INFO, "disassociated"); |
| 5119 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 5120 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 5121 | /* Stop Accounting and IEEE 802.1X sessions, but leave the STA |
| 5122 | * authenticated. */ |
| 5123 | accounting_sta_stop(hapd, sta); |
Dmitry Shmidt | de47be7 | 2016-01-07 12:52:55 -0800 | [diff] [blame] | 5124 | ieee802_1x_free_station(hapd, sta); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5125 | if (sta->ipaddr) |
| 5126 | hostapd_drv_br_delete_ip_neigh(hapd, 4, (u8 *) &sta->ipaddr); |
| 5127 | ap_sta_ip6addr_del(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5128 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5129 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5130 | |
| 5131 | if (sta->timeout_next == STA_NULLFUNC || |
| 5132 | sta->timeout_next == STA_DISASSOC) { |
| 5133 | sta->timeout_next = STA_DEAUTH; |
| 5134 | eloop_cancel_timeout(ap_handle_timer, hapd, sta); |
| 5135 | eloop_register_timeout(AP_DEAUTH_DELAY, 0, ap_handle_timer, |
| 5136 | hapd, sta); |
| 5137 | } |
| 5138 | |
| 5139 | mlme_disassociate_indication( |
| 5140 | hapd, sta, le_to_host16(mgmt->u.disassoc.reason_code)); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5141 | |
| 5142 | /* DMG/IEEE 802.11ad does not use deauthication. Deallocate sta upon |
| 5143 | * disassociation. */ |
| 5144 | if (hapd->iface->current_mode && |
| 5145 | hapd->iface->current_mode->mode == HOSTAPD_MODE_IEEE80211AD) { |
| 5146 | sta->flags &= ~WLAN_STA_AUTH; |
| 5147 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 5148 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 5149 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); |
| 5150 | ap_free_sta(hapd, sta); |
| 5151 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | |
| 5155 | static void handle_deauth(struct hostapd_data *hapd, |
| 5156 | const struct ieee80211_mgmt *mgmt, size_t len) |
| 5157 | { |
| 5158 | struct sta_info *sta; |
| 5159 | |
| 5160 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.deauth)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5161 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "handle_deauth - too short " |
| 5162 | "payload (len=%lu)", (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5163 | return; |
| 5164 | } |
| 5165 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5166 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "deauthentication: STA=" MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5167 | " reason_code=%d", |
| 5168 | MAC2STR(mgmt->sa), le_to_host16(mgmt->u.deauth.reason_code)); |
| 5169 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5170 | /* Clear the PTKSA cache entries for PASN */ |
| 5171 | ptksa_cache_flush(hapd->ptksa, mgmt->sa, WPA_CIPHER_NONE); |
| 5172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5173 | sta = ap_get_sta(hapd, mgmt->sa); |
| 5174 | if (sta == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5175 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "Station " MACSTR " trying " |
| 5176 | "to deauthenticate, but it is not authenticated", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5177 | MAC2STR(mgmt->sa)); |
| 5178 | return; |
| 5179 | } |
| 5180 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5181 | ap_sta_set_authorized(hapd, sta, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5182 | sta->last_seq_ctrl = WLAN_INVALID_MGMT_SEQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5183 | sta->flags &= ~(WLAN_STA_AUTH | WLAN_STA_ASSOC | |
| 5184 | WLAN_STA_ASSOC_REQ_OK); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5185 | hostapd_set_sta_flags(hapd, sta); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5186 | wpa_auth_sm_event(sta->wpa_sm, WPA_DEAUTH); |
| 5187 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 5188 | HOSTAPD_LEVEL_DEBUG, "deauthenticated"); |
| 5189 | mlme_deauthenticate_indication( |
| 5190 | hapd, sta, le_to_host16(mgmt->u.deauth.reason_code)); |
| 5191 | sta->acct_terminate_cause = RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST; |
| 5192 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 0); |
| 5193 | ap_free_sta(hapd, sta); |
| 5194 | } |
| 5195 | |
| 5196 | |
| 5197 | static void handle_beacon(struct hostapd_data *hapd, |
| 5198 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 5199 | struct hostapd_frame_info *fi) |
| 5200 | { |
| 5201 | struct ieee802_11_elems elems; |
| 5202 | |
| 5203 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.beacon)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5204 | wpa_printf(MSG_INFO, "handle_beacon - too short payload (len=%lu)", |
| 5205 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5206 | return; |
| 5207 | } |
| 5208 | |
| 5209 | (void) ieee802_11_parse_elems(mgmt->u.beacon.variable, |
| 5210 | len - (IEEE80211_HDRLEN + |
| 5211 | sizeof(mgmt->u.beacon)), &elems, |
| 5212 | 0); |
| 5213 | |
| 5214 | ap_list_process_beacon(hapd->iface, mgmt, &elems, fi); |
| 5215 | } |
| 5216 | |
| 5217 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5218 | static int robust_action_frame(u8 category) |
| 5219 | { |
| 5220 | return category != WLAN_ACTION_PUBLIC && |
| 5221 | category != WLAN_ACTION_HT; |
| 5222 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5223 | |
| 5224 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5225 | static int handle_action(struct hostapd_data *hapd, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5226 | const struct ieee80211_mgmt *mgmt, size_t len, |
| 5227 | unsigned int freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5228 | { |
| 5229 | struct sta_info *sta; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5230 | u8 *action __maybe_unused; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5231 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5232 | if (len < IEEE80211_HDRLEN + 2 + 1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5233 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 5234 | HOSTAPD_LEVEL_DEBUG, |
| 5235 | "handle_action - too short payload (len=%lu)", |
| 5236 | (unsigned long) len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5237 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5238 | } |
| 5239 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5240 | action = (u8 *) &mgmt->u.action.u; |
| 5241 | wpa_printf(MSG_DEBUG, "RX_ACTION category %u action %u sa " MACSTR |
| 5242 | " da " MACSTR " len %d freq %u", |
| 5243 | mgmt->u.action.category, *action, |
| 5244 | MAC2STR(mgmt->sa), MAC2STR(mgmt->da), (int) len, freq); |
| 5245 | |
| 5246 | sta = ap_get_sta(hapd, mgmt->sa); |
| 5247 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5248 | if (mgmt->u.action.category != WLAN_ACTION_PUBLIC && |
| 5249 | (sta == NULL || !(sta->flags & WLAN_STA_ASSOC))) { |
| 5250 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Ignored Action " |
| 5251 | "frame (category=%u) from unassociated STA " MACSTR, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 5252 | mgmt->u.action.category, MAC2STR(mgmt->sa)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5253 | return 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5254 | } |
| 5255 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5256 | if (sta && (sta->flags & WLAN_STA_MFP) && |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5257 | !(mgmt->frame_control & host_to_le16(WLAN_FC_ISWEP)) && |
| 5258 | robust_action_frame(mgmt->u.action.category)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5259 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 5260 | HOSTAPD_LEVEL_DEBUG, |
| 5261 | "Dropped unprotected Robust Action frame from " |
| 5262 | "an MFP STA"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5263 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5264 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5265 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5266 | if (sta) { |
| 5267 | u16 fc = le_to_host16(mgmt->frame_control); |
| 5268 | u16 seq_ctrl = le_to_host16(mgmt->seq_ctrl); |
| 5269 | |
| 5270 | if ((fc & WLAN_FC_RETRY) && |
| 5271 | sta->last_seq_ctrl != WLAN_INVALID_MGMT_SEQ && |
| 5272 | sta->last_seq_ctrl == seq_ctrl && |
| 5273 | sta->last_subtype == WLAN_FC_STYPE_ACTION) { |
| 5274 | hostapd_logger(hapd, sta->addr, |
| 5275 | HOSTAPD_MODULE_IEEE80211, |
| 5276 | HOSTAPD_LEVEL_DEBUG, |
| 5277 | "Drop repeated action frame seq_ctrl=0x%x", |
| 5278 | seq_ctrl); |
| 5279 | return 1; |
| 5280 | } |
| 5281 | |
| 5282 | sta->last_seq_ctrl = seq_ctrl; |
| 5283 | sta->last_subtype = WLAN_FC_STYPE_ACTION; |
| 5284 | } |
| 5285 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5286 | switch (mgmt->u.action.category) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5287 | #ifdef CONFIG_IEEE80211R_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5288 | case WLAN_ACTION_FT: |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5289 | if (!sta || |
| 5290 | wpa_ft_action_rx(sta->wpa_sm, (u8 *) &mgmt->u.action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5291 | len - IEEE80211_HDRLEN)) |
| 5292 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5293 | return 1; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5294 | #endif /* CONFIG_IEEE80211R_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5295 | case WLAN_ACTION_WMM: |
| 5296 | hostapd_wmm_action(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5297 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5298 | case WLAN_ACTION_SA_QUERY: |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5299 | ieee802_11_sa_query_action(hapd, mgmt, len); |
| 5300 | return 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5301 | #ifdef CONFIG_WNM_AP |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5302 | case WLAN_ACTION_WNM: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5303 | ieee802_11_rx_wnm_action_ap(hapd, mgmt, len); |
| 5304 | return 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5305 | #endif /* CONFIG_WNM_AP */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5306 | #ifdef CONFIG_FST |
| 5307 | case WLAN_ACTION_FST: |
| 5308 | if (hapd->iface->fst) |
| 5309 | fst_rx_action(hapd->iface->fst, mgmt, len); |
| 5310 | else |
| 5311 | wpa_printf(MSG_DEBUG, |
| 5312 | "FST: Ignore FST Action frame - no FST attached"); |
| 5313 | return 1; |
| 5314 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5315 | case WLAN_ACTION_PUBLIC: |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5316 | case WLAN_ACTION_PROTECTED_DUAL: |
Dmitry Shmidt | cc00d5d | 2015-05-04 10:34:12 -0700 | [diff] [blame] | 5317 | if (len >= IEEE80211_HDRLEN + 2 && |
| 5318 | mgmt->u.action.u.public_action.action == |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5319 | WLAN_PA_20_40_BSS_COEX) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5320 | hostapd_2040_coex_action(hapd, mgmt, len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5321 | return 1; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5322 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5323 | #ifdef CONFIG_DPP |
| 5324 | if (len >= IEEE80211_HDRLEN + 6 && |
| 5325 | mgmt->u.action.u.vs_public_action.action == |
| 5326 | WLAN_PA_VENDOR_SPECIFIC && |
| 5327 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 5328 | OUI_WFA && |
| 5329 | mgmt->u.action.u.vs_public_action.variable[0] == |
| 5330 | DPP_OUI_TYPE) { |
| 5331 | const u8 *pos, *end; |
| 5332 | |
| 5333 | pos = mgmt->u.action.u.vs_public_action.oui; |
| 5334 | end = ((const u8 *) mgmt) + len; |
| 5335 | hostapd_dpp_rx_action(hapd, mgmt->sa, pos, end - pos, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5336 | freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5337 | return 1; |
| 5338 | } |
| 5339 | if (len >= IEEE80211_HDRLEN + 2 && |
| 5340 | (mgmt->u.action.u.public_action.action == |
| 5341 | WLAN_PA_GAS_INITIAL_RESP || |
| 5342 | mgmt->u.action.u.public_action.action == |
| 5343 | WLAN_PA_GAS_COMEBACK_RESP)) { |
| 5344 | const u8 *pos, *end; |
| 5345 | |
| 5346 | pos = &mgmt->u.action.u.public_action.action; |
| 5347 | end = ((const u8 *) mgmt) + len; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5348 | if (gas_query_ap_rx(hapd->gas, mgmt->sa, |
| 5349 | mgmt->u.action.category, |
| 5350 | pos, end - pos, freq) == 0) |
| 5351 | return 1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5352 | } |
| 5353 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5354 | if (hapd->public_action_cb) { |
| 5355 | hapd->public_action_cb(hapd->public_action_cb_ctx, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5356 | (u8 *) mgmt, len, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5357 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5358 | if (hapd->public_action_cb2) { |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5359 | hapd->public_action_cb2(hapd->public_action_cb2_ctx, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5360 | (u8 *) mgmt, len, freq); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5361 | } |
| 5362 | if (hapd->public_action_cb || hapd->public_action_cb2) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5363 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5364 | break; |
| 5365 | case WLAN_ACTION_VENDOR_SPECIFIC: |
| 5366 | if (hapd->vendor_action_cb) { |
| 5367 | if (hapd->vendor_action_cb(hapd->vendor_action_cb_ctx, |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5368 | (u8 *) mgmt, len, freq) == 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5369 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5370 | } |
| 5371 | break; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5372 | case WLAN_ACTION_RADIO_MEASUREMENT: |
| 5373 | hostapd_handle_radio_measurement(hapd, (const u8 *) mgmt, len); |
| 5374 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5375 | } |
| 5376 | |
| 5377 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 5378 | HOSTAPD_LEVEL_DEBUG, |
| 5379 | "handle_action - unknown action category %d or invalid " |
| 5380 | "frame", |
| 5381 | mgmt->u.action.category); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5382 | if (!is_multicast_ether_addr(mgmt->da) && |
| 5383 | !(mgmt->u.action.category & 0x80) && |
| 5384 | !is_multicast_ether_addr(mgmt->sa)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5385 | struct ieee80211_mgmt *resp; |
| 5386 | |
| 5387 | /* |
| 5388 | * IEEE 802.11-REVma/D9.0 - 7.3.1.11 |
| 5389 | * Return the Action frame to the source without change |
| 5390 | * except that MSB of the Category set to 1. |
| 5391 | */ |
| 5392 | wpa_printf(MSG_DEBUG, "IEEE 802.11: Return unknown Action " |
| 5393 | "frame back to sender"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5394 | resp = os_memdup(mgmt, len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5395 | if (resp == NULL) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5396 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5397 | os_memcpy(resp->da, resp->sa, ETH_ALEN); |
| 5398 | os_memcpy(resp->sa, hapd->own_addr, ETH_ALEN); |
| 5399 | os_memcpy(resp->bssid, hapd->own_addr, ETH_ALEN); |
| 5400 | resp->u.action.category |= 0x80; |
| 5401 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5402 | 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] | 5403 | wpa_printf(MSG_ERROR, "IEEE 802.11: Failed to send " |
| 5404 | "Action frame"); |
| 5405 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5406 | os_free(resp); |
| 5407 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5408 | |
| 5409 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | |
| 5413 | /** |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5414 | * notify_mgmt_frame - Notify of Management frames on the control interface |
| 5415 | * @hapd: hostapd BSS data structure (the BSS to which the Management frame was |
| 5416 | * sent to) |
| 5417 | * @buf: Management frame data (starting from the IEEE 802.11 header) |
| 5418 | * @len: Length of frame data in octets |
| 5419 | * |
| 5420 | * Notify the control interface of any received Management frame. |
| 5421 | */ |
| 5422 | static void notify_mgmt_frame(struct hostapd_data *hapd, const u8 *buf, |
| 5423 | size_t len) |
| 5424 | { |
| 5425 | |
| 5426 | int hex_len = len * 2 + 1; |
| 5427 | char *hex = os_malloc(hex_len); |
| 5428 | |
| 5429 | if (hex) { |
| 5430 | wpa_snprintf_hex(hex, hex_len, buf, len); |
| 5431 | wpa_msg_ctrl(hapd->msg_ctx, MSG_INFO, |
| 5432 | AP_MGMT_FRAME_RECEIVED "buf=%s", hex); |
| 5433 | os_free(hex); |
| 5434 | } |
| 5435 | } |
| 5436 | |
| 5437 | |
| 5438 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5439 | * ieee802_11_mgmt - process incoming IEEE 802.11 management frames |
| 5440 | * @hapd: hostapd BSS data structure (the BSS to which the management frame was |
| 5441 | * sent to) |
| 5442 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 5443 | * @len: length of frame data in octets |
| 5444 | * @fi: meta data about received frame (signal level, etc.) |
| 5445 | * |
| 5446 | * Process all incoming IEEE 802.11 management frames. This will be called for |
| 5447 | * each frame received from the kernel driver through wlan#ap interface. In |
| 5448 | * addition, it can be called to re-inserted pending frames (e.g., when using |
| 5449 | * external RADIUS server as an MAC ACL). |
| 5450 | */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5451 | int ieee802_11_mgmt(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 5452 | struct hostapd_frame_info *fi) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5453 | { |
| 5454 | struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5455 | u16 fc, stype; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5456 | int ret = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5457 | unsigned int freq; |
| 5458 | int ssi_signal = fi ? fi->ssi_signal : 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5459 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5460 | if (len < 24) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5461 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5462 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5463 | if (fi && fi->freq) |
| 5464 | freq = fi->freq; |
| 5465 | else |
| 5466 | freq = hapd->iface->freq; |
| 5467 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5468 | mgmt = (struct ieee80211_mgmt *) buf; |
| 5469 | fc = le_to_host16(mgmt->frame_control); |
| 5470 | stype = WLAN_FC_GET_STYPE(fc); |
| 5471 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5472 | if (is_multicast_ether_addr(mgmt->sa) || |
| 5473 | is_zero_ether_addr(mgmt->sa) || |
| 5474 | os_memcmp(mgmt->sa, hapd->own_addr, ETH_ALEN) == 0) { |
| 5475 | /* Do not process any frames with unexpected/invalid SA so that |
| 5476 | * we do not add any state for unexpected STA addresses or end |
| 5477 | * up sending out frames to unexpected destination. */ |
| 5478 | wpa_printf(MSG_DEBUG, "MGMT: Invalid SA=" MACSTR |
| 5479 | " in received frame - ignore this frame silently", |
| 5480 | MAC2STR(mgmt->sa)); |
| 5481 | return 0; |
| 5482 | } |
| 5483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5484 | if (stype == WLAN_FC_STYPE_BEACON) { |
| 5485 | handle_beacon(hapd, mgmt, len, fi); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5486 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 5489 | if (!is_broadcast_ether_addr(mgmt->bssid) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5490 | #ifdef CONFIG_P2P |
| 5491 | /* Invitation responses can be sent with the peer MAC as BSSID */ |
| 5492 | !((hapd->conf->p2p & P2P_GROUP_OWNER) && |
| 5493 | stype == WLAN_FC_STYPE_ACTION) && |
| 5494 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5495 | #ifdef CONFIG_MESH |
| 5496 | !(hapd->conf->mesh & MESH_ENABLED) && |
| 5497 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5498 | os_memcmp(mgmt->bssid, hapd->own_addr, ETH_ALEN) != 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5499 | wpa_printf(MSG_INFO, "MGMT: BSSID=" MACSTR " not our address", |
| 5500 | MAC2STR(mgmt->bssid)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5501 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5502 | } |
| 5503 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5504 | if (hapd->iface->state != HAPD_IFACE_ENABLED) { |
| 5505 | wpa_printf(MSG_DEBUG, "MGMT: Ignore management frame while interface is not enabled (SA=" MACSTR " DA=" MACSTR " subtype=%u)", |
| 5506 | MAC2STR(mgmt->sa), MAC2STR(mgmt->da), stype); |
| 5507 | return 1; |
| 5508 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5509 | |
| 5510 | if (stype == WLAN_FC_STYPE_PROBE_REQ) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5511 | handle_probe_req(hapd, mgmt, len, ssi_signal); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5512 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5513 | } |
| 5514 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5515 | if ((!is_broadcast_ether_addr(mgmt->da) || |
| 5516 | stype != WLAN_FC_STYPE_ACTION) && |
| 5517 | os_memcmp(mgmt->da, hapd->own_addr, ETH_ALEN) != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5518 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 5519 | HOSTAPD_LEVEL_DEBUG, |
| 5520 | "MGMT: DA=" MACSTR " not our address", |
| 5521 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5522 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5523 | } |
| 5524 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5525 | if (hapd->iconf->track_sta_max_num) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5526 | sta_track_add(hapd->iface, mgmt->sa, ssi_signal); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5527 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5528 | if (hapd->conf->notify_mgmt_frames) |
| 5529 | notify_mgmt_frame(hapd, buf, len); |
| 5530 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5531 | switch (stype) { |
| 5532 | case WLAN_FC_STYPE_AUTH: |
| 5533 | wpa_printf(MSG_DEBUG, "mgmt::auth"); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5534 | handle_auth(hapd, mgmt, len, ssi_signal, 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5535 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5536 | break; |
| 5537 | case WLAN_FC_STYPE_ASSOC_REQ: |
| 5538 | wpa_printf(MSG_DEBUG, "mgmt::assoc_req"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5539 | handle_assoc(hapd, mgmt, len, 0, ssi_signal); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5540 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5541 | break; |
| 5542 | case WLAN_FC_STYPE_REASSOC_REQ: |
| 5543 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_req"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5544 | handle_assoc(hapd, mgmt, len, 1, ssi_signal); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5545 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5546 | break; |
| 5547 | case WLAN_FC_STYPE_DISASSOC: |
| 5548 | wpa_printf(MSG_DEBUG, "mgmt::disassoc"); |
| 5549 | handle_disassoc(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5550 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5551 | break; |
| 5552 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5553 | wpa_msg(hapd->msg_ctx, MSG_DEBUG, "mgmt::deauth"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5554 | handle_deauth(hapd, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5555 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5556 | break; |
| 5557 | case WLAN_FC_STYPE_ACTION: |
| 5558 | wpa_printf(MSG_DEBUG, "mgmt::action"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5559 | ret = handle_action(hapd, mgmt, len, freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5560 | break; |
| 5561 | default: |
| 5562 | hostapd_logger(hapd, mgmt->sa, HOSTAPD_MODULE_IEEE80211, |
| 5563 | HOSTAPD_LEVEL_DEBUG, |
| 5564 | "unknown mgmt frame subtype %d", stype); |
| 5565 | break; |
| 5566 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5567 | |
| 5568 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5569 | } |
| 5570 | |
| 5571 | |
| 5572 | static void handle_auth_cb(struct hostapd_data *hapd, |
| 5573 | const struct ieee80211_mgmt *mgmt, |
| 5574 | size_t len, int ok) |
| 5575 | { |
| 5576 | u16 auth_alg, auth_transaction, status_code; |
| 5577 | struct sta_info *sta; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5578 | bool success_status; |
Hai Shalom | e5e28bb | 2019-01-28 14:51:04 -0800 | [diff] [blame] | 5579 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5580 | sta = ap_get_sta(hapd, mgmt->da); |
| 5581 | if (!sta) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5582 | wpa_printf(MSG_DEBUG, "handle_auth_cb: STA " MACSTR |
| 5583 | " not found", |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5584 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5585 | return; |
| 5586 | } |
| 5587 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5588 | if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) { |
| 5589 | wpa_printf(MSG_INFO, "handle_auth_cb - too short payload (len=%lu)", |
| 5590 | (unsigned long) len); |
| 5591 | auth_alg = 0; |
| 5592 | auth_transaction = 0; |
| 5593 | status_code = WLAN_STATUS_UNSPECIFIED_FAILURE; |
| 5594 | goto fail; |
| 5595 | } |
| 5596 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5597 | auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 5598 | auth_transaction = le_to_host16(mgmt->u.auth.auth_transaction); |
| 5599 | status_code = le_to_host16(mgmt->u.auth.status_code); |
| 5600 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5601 | if (!ok) { |
| 5602 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 5603 | HOSTAPD_LEVEL_NOTICE, |
| 5604 | "did not acknowledge authentication response"); |
| 5605 | goto fail; |
| 5606 | } |
| 5607 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5608 | if (status_code == WLAN_STATUS_SUCCESS && |
| 5609 | ((auth_alg == WLAN_AUTH_OPEN && auth_transaction == 2) || |
| 5610 | (auth_alg == WLAN_AUTH_SHARED_KEY && auth_transaction == 4))) { |
| 5611 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 5612 | HOSTAPD_LEVEL_INFO, "authenticated"); |
| 5613 | sta->flags |= WLAN_STA_AUTH; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5614 | if (sta->added_unassoc) |
| 5615 | hostapd_set_sta_flags(hapd, sta); |
| 5616 | return; |
| 5617 | } |
| 5618 | |
| 5619 | fail: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5620 | success_status = status_code == WLAN_STATUS_SUCCESS; |
| 5621 | #ifdef CONFIG_SAE |
| 5622 | if (auth_alg == WLAN_AUTH_SAE && auth_transaction == 1) |
| 5623 | success_status = sae_status_success(hapd, status_code); |
| 5624 | #endif /* CONFIG_SAE */ |
| 5625 | if (!success_status && sta->added_unassoc) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5626 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 5627 | sta->added_unassoc = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5628 | } |
| 5629 | } |
| 5630 | |
| 5631 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5632 | static void hostapd_set_wds_encryption(struct hostapd_data *hapd, |
| 5633 | struct sta_info *sta, |
| 5634 | char *ifname_wds) |
| 5635 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5636 | #ifdef CONFIG_WEP |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5637 | int i; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 5638 | struct hostapd_ssid *ssid = &hapd->conf->ssid; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5639 | |
| 5640 | if (hapd->conf->ieee802_1x || hapd->conf->wpa) |
| 5641 | return; |
| 5642 | |
| 5643 | for (i = 0; i < 4; i++) { |
| 5644 | if (ssid->wep.key[i] && |
| 5645 | hostapd_drv_set_key(ifname_wds, hapd, WPA_ALG_WEP, NULL, i, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5646 | 0, i == ssid->wep.idx, NULL, 0, |
| 5647 | ssid->wep.key[i], ssid->wep.len[i], |
| 5648 | i == ssid->wep.idx ? |
| 5649 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 5650 | KEY_FLAG_GROUP_RX_TX)) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5651 | wpa_printf(MSG_WARNING, |
| 5652 | "Could not set WEP keys for WDS interface; %s", |
| 5653 | ifname_wds); |
| 5654 | break; |
| 5655 | } |
| 5656 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5657 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5661 | static void handle_assoc_cb(struct hostapd_data *hapd, |
| 5662 | const struct ieee80211_mgmt *mgmt, |
| 5663 | size_t len, int reassoc, int ok) |
| 5664 | { |
| 5665 | u16 status; |
| 5666 | struct sta_info *sta; |
| 5667 | int new_assoc = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5669 | sta = ap_get_sta(hapd, mgmt->da); |
| 5670 | if (!sta) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5671 | wpa_printf(MSG_INFO, "handle_assoc_cb: STA " MACSTR " not found", |
| 5672 | MAC2STR(mgmt->da)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5673 | return; |
| 5674 | } |
| 5675 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5676 | if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) : |
| 5677 | sizeof(mgmt->u.assoc_resp))) { |
| 5678 | wpa_printf(MSG_INFO, |
| 5679 | "handle_assoc_cb(reassoc=%d) - too short payload (len=%lu)", |
| 5680 | reassoc, (unsigned long) len); |
| 5681 | hostapd_drv_sta_remove(hapd, sta->addr); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5682 | return; |
| 5683 | } |
| 5684 | |
| 5685 | if (reassoc) |
| 5686 | status = le_to_host16(mgmt->u.reassoc_resp.status_code); |
| 5687 | else |
| 5688 | status = le_to_host16(mgmt->u.assoc_resp.status_code); |
| 5689 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5690 | if (!ok) { |
| 5691 | hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211, |
| 5692 | HOSTAPD_LEVEL_DEBUG, |
| 5693 | "did not acknowledge association response"); |
| 5694 | sta->flags &= ~WLAN_STA_ASSOC_REQ_OK; |
| 5695 | /* The STA is added only in case of SUCCESS */ |
| 5696 | if (status == WLAN_STATUS_SUCCESS) |
| 5697 | hostapd_drv_sta_remove(hapd, sta->addr); |
| 5698 | |
| 5699 | return; |
| 5700 | } |
| 5701 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5702 | if (status != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 5703 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5704 | |
| 5705 | /* Stop previous accounting session, if one is started, and allocate |
| 5706 | * new session id for the new session. */ |
| 5707 | accounting_sta_stop(hapd, sta); |
| 5708 | |
| 5709 | hostapd_logger(hapd, sta->addr, HOSTAPD_MODULE_IEEE80211, |
| 5710 | HOSTAPD_LEVEL_INFO, |
| 5711 | "associated (aid %d)", |
| 5712 | sta->aid); |
| 5713 | |
| 5714 | if (sta->flags & WLAN_STA_ASSOC) |
| 5715 | new_assoc = 0; |
| 5716 | sta->flags |= WLAN_STA_ASSOC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5717 | sta->flags &= ~WLAN_STA_WNM_SLEEP_MODE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5718 | if ((!hapd->conf->ieee802_1x && !hapd->conf->wpa && |
| 5719 | !hapd->conf->osen) || |
| 5720 | sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 5721 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 5722 | sta->auth_alg == WLAN_AUTH_FILS_PK || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5723 | sta->auth_alg == WLAN_AUTH_FT) { |
| 5724 | /* |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5725 | * Open, static WEP, FT protocol, or FILS; no separate |
| 5726 | * authorization step. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5727 | */ |
| 5728 | ap_sta_set_authorized(hapd, sta, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5729 | } |
| 5730 | |
| 5731 | if (reassoc) |
| 5732 | mlme_reassociate_indication(hapd, sta); |
| 5733 | else |
| 5734 | mlme_associate_indication(hapd, sta); |
| 5735 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5736 | sta->sa_query_timed_out = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5737 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5738 | if (sta->eapol_sm == NULL) { |
| 5739 | /* |
| 5740 | * This STA does not use RADIUS server for EAP authentication, |
| 5741 | * so bind it to the selected VLAN interface now, since the |
| 5742 | * interface selection is not going to change anymore. |
| 5743 | */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 5744 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 5745 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5746 | } else if (sta->vlan_id) { |
| 5747 | /* VLAN ID already set (e.g., by PMKSA caching), so bind STA */ |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 5748 | if (ap_sta_bind_vlan(hapd, sta) < 0) |
Dmitry Shmidt | b36ed7c | 2014-03-17 10:57:26 -0700 | [diff] [blame] | 5749 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5750 | } |
| 5751 | |
| 5752 | hostapd_set_sta_flags(hapd, sta); |
| 5753 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5754 | if (!(sta->flags & WLAN_STA_WDS) && sta->pending_wds_enable) { |
| 5755 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for STA " |
| 5756 | MACSTR " based on pending request", |
| 5757 | MAC2STR(sta->addr)); |
| 5758 | sta->pending_wds_enable = 0; |
| 5759 | sta->flags |= WLAN_STA_WDS; |
| 5760 | } |
| 5761 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 5762 | /* WPS not supported on backhaul BSS. Disable 4addr mode on fronthaul */ |
| 5763 | if ((sta->flags & WLAN_STA_WDS) || |
| 5764 | (sta->flags & WLAN_STA_MULTI_AP && |
| 5765 | !(hapd->conf->multi_ap & FRONTHAUL_BSS) && |
| 5766 | !(sta->flags & WLAN_STA_WPS))) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 5767 | int ret; |
| 5768 | char ifname_wds[IFNAMSIZ + 1]; |
| 5769 | |
| 5770 | wpa_printf(MSG_DEBUG, "Reenable 4-address WDS mode for STA " |
| 5771 | MACSTR " (aid %u)", |
| 5772 | MAC2STR(sta->addr), sta->aid); |
| 5773 | ret = hostapd_set_wds_sta(hapd, ifname_wds, sta->addr, |
| 5774 | sta->aid, 1); |
| 5775 | if (!ret) |
| 5776 | hostapd_set_wds_encryption(hapd, sta, ifname_wds); |
| 5777 | } |
| 5778 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5779 | if (sta->auth_alg == WLAN_AUTH_FT) |
| 5780 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC_FT); |
| 5781 | else |
| 5782 | wpa_auth_sm_event(sta->wpa_sm, WPA_ASSOC); |
| 5783 | hapd->new_assoc_sta_cb(hapd, sta, !new_assoc); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5784 | ieee802_1x_notify_port_enabled(sta->eapol_sm, 1); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 5785 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5786 | #ifdef CONFIG_FILS |
| 5787 | if ((sta->auth_alg == WLAN_AUTH_FILS_SK || |
| 5788 | sta->auth_alg == WLAN_AUTH_FILS_SK_PFS || |
| 5789 | sta->auth_alg == WLAN_AUTH_FILS_PK) && |
| 5790 | fils_set_tk(sta->wpa_sm) < 0) { |
| 5791 | wpa_printf(MSG_DEBUG, "FILS: TK configuration failed"); |
| 5792 | ap_sta_disconnect(hapd, sta, sta->addr, |
| 5793 | WLAN_REASON_UNSPECIFIED); |
| 5794 | return; |
| 5795 | } |
| 5796 | #endif /* CONFIG_FILS */ |
| 5797 | |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 5798 | if (sta->pending_eapol_rx) { |
| 5799 | struct os_reltime now, age; |
| 5800 | |
| 5801 | os_get_reltime(&now); |
| 5802 | os_reltime_sub(&now, &sta->pending_eapol_rx->rx_time, &age); |
| 5803 | if (age.sec == 0 && age.usec < 200000) { |
| 5804 | wpa_printf(MSG_DEBUG, |
| 5805 | "Process pending EAPOL frame that was received from " MACSTR " just before association notification", |
| 5806 | MAC2STR(sta->addr)); |
| 5807 | ieee802_1x_receive( |
| 5808 | hapd, mgmt->da, |
| 5809 | wpabuf_head(sta->pending_eapol_rx->buf), |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5810 | wpabuf_len(sta->pending_eapol_rx->buf), |
| 5811 | sta->pending_eapol_rx->encrypted); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 5812 | } |
| 5813 | wpabuf_free(sta->pending_eapol_rx->buf); |
| 5814 | os_free(sta->pending_eapol_rx); |
| 5815 | sta->pending_eapol_rx = NULL; |
| 5816 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5817 | } |
| 5818 | |
| 5819 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5820 | static void handle_deauth_cb(struct hostapd_data *hapd, |
| 5821 | const struct ieee80211_mgmt *mgmt, |
| 5822 | size_t len, int ok) |
| 5823 | { |
| 5824 | struct sta_info *sta; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5825 | if (is_multicast_ether_addr(mgmt->da)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5826 | return; |
| 5827 | sta = ap_get_sta(hapd, mgmt->da); |
| 5828 | if (!sta) { |
| 5829 | wpa_printf(MSG_DEBUG, "handle_deauth_cb: STA " MACSTR |
| 5830 | " not found", MAC2STR(mgmt->da)); |
| 5831 | return; |
| 5832 | } |
| 5833 | if (ok) |
| 5834 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged deauth", |
| 5835 | MAC2STR(sta->addr)); |
| 5836 | else |
| 5837 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 5838 | "deauth", MAC2STR(sta->addr)); |
| 5839 | |
| 5840 | ap_sta_deauth_cb(hapd, sta); |
| 5841 | } |
| 5842 | |
| 5843 | |
| 5844 | static void handle_disassoc_cb(struct hostapd_data *hapd, |
| 5845 | const struct ieee80211_mgmt *mgmt, |
| 5846 | size_t len, int ok) |
| 5847 | { |
| 5848 | struct sta_info *sta; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5849 | if (is_multicast_ether_addr(mgmt->da)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5850 | return; |
| 5851 | sta = ap_get_sta(hapd, mgmt->da); |
| 5852 | if (!sta) { |
| 5853 | wpa_printf(MSG_DEBUG, "handle_disassoc_cb: STA " MACSTR |
| 5854 | " not found", MAC2STR(mgmt->da)); |
| 5855 | return; |
| 5856 | } |
| 5857 | if (ok) |
| 5858 | wpa_printf(MSG_DEBUG, "STA " MACSTR " acknowledged disassoc", |
| 5859 | MAC2STR(sta->addr)); |
| 5860 | else |
| 5861 | wpa_printf(MSG_DEBUG, "STA " MACSTR " did not acknowledge " |
| 5862 | "disassoc", MAC2STR(sta->addr)); |
| 5863 | |
| 5864 | ap_sta_disassoc_cb(hapd, sta); |
| 5865 | } |
| 5866 | |
| 5867 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5868 | static void handle_action_cb(struct hostapd_data *hapd, |
| 5869 | const struct ieee80211_mgmt *mgmt, |
| 5870 | size_t len, int ok) |
| 5871 | { |
| 5872 | struct sta_info *sta; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5873 | const struct rrm_measurement_report_element *report; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5874 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5875 | #ifdef CONFIG_DPP |
| 5876 | if (len >= IEEE80211_HDRLEN + 6 && |
| 5877 | mgmt->u.action.category == WLAN_ACTION_PUBLIC && |
| 5878 | mgmt->u.action.u.vs_public_action.action == |
| 5879 | WLAN_PA_VENDOR_SPECIFIC && |
| 5880 | WPA_GET_BE24(mgmt->u.action.u.vs_public_action.oui) == |
| 5881 | OUI_WFA && |
| 5882 | mgmt->u.action.u.vs_public_action.variable[0] == |
| 5883 | DPP_OUI_TYPE) { |
| 5884 | const u8 *pos, *end; |
| 5885 | |
| 5886 | pos = &mgmt->u.action.u.vs_public_action.variable[1]; |
| 5887 | end = ((const u8 *) mgmt) + len; |
| 5888 | hostapd_dpp_tx_status(hapd, mgmt->da, pos, end - pos, ok); |
| 5889 | return; |
| 5890 | } |
| 5891 | if (len >= IEEE80211_HDRLEN + 2 && |
| 5892 | mgmt->u.action.category == WLAN_ACTION_PUBLIC && |
| 5893 | (mgmt->u.action.u.public_action.action == |
| 5894 | WLAN_PA_GAS_INITIAL_REQ || |
| 5895 | mgmt->u.action.u.public_action.action == |
| 5896 | WLAN_PA_GAS_COMEBACK_REQ)) { |
| 5897 | const u8 *pos, *end; |
| 5898 | |
| 5899 | pos = mgmt->u.action.u.public_action.variable; |
| 5900 | end = ((const u8 *) mgmt) + len; |
| 5901 | gas_query_ap_tx_status(hapd->gas, mgmt->da, pos, end - pos, ok); |
| 5902 | return; |
| 5903 | } |
| 5904 | #endif /* CONFIG_DPP */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5905 | if (is_multicast_ether_addr(mgmt->da)) |
| 5906 | return; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5907 | sta = ap_get_sta(hapd, mgmt->da); |
| 5908 | if (!sta) { |
| 5909 | wpa_printf(MSG_DEBUG, "handle_action_cb: STA " MACSTR |
| 5910 | " not found", MAC2STR(mgmt->da)); |
| 5911 | return; |
| 5912 | } |
| 5913 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5914 | #ifdef CONFIG_HS20 |
| 5915 | if (ok && len >= IEEE80211_HDRLEN + 2 && |
| 5916 | mgmt->u.action.category == WLAN_ACTION_WNM && |
| 5917 | mgmt->u.action.u.vs_public_action.action == WNM_NOTIFICATION_REQ && |
| 5918 | sta->hs20_deauth_on_ack) { |
| 5919 | wpa_printf(MSG_DEBUG, "HS 2.0: Deauthenticate STA " MACSTR |
| 5920 | " on acknowledging the WNM-Notification", |
| 5921 | MAC2STR(sta->addr)); |
| 5922 | ap_sta_session_timeout(hapd, sta, 0); |
| 5923 | return; |
| 5924 | } |
| 5925 | #endif /* CONFIG_HS20 */ |
| 5926 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5927 | if (len < 24 + 5 + sizeof(*report)) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5928 | return; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5929 | report = (const struct rrm_measurement_report_element *) |
| 5930 | &mgmt->u.action.u.rrm.variable[2]; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5931 | if (mgmt->u.action.category == WLAN_ACTION_RADIO_MEASUREMENT && |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5932 | mgmt->u.action.u.rrm.action == WLAN_RRM_RADIO_MEASUREMENT_REQUEST && |
| 5933 | report->eid == WLAN_EID_MEASURE_REQUEST && |
| 5934 | report->len >= 3 && |
| 5935 | report->type == MEASURE_TYPE_BEACON) |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5936 | hostapd_rrm_beacon_req_tx_status(hapd, mgmt, len, ok); |
| 5937 | } |
| 5938 | |
| 5939 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5940 | /** |
| 5941 | * ieee802_11_mgmt_cb - Process management frame TX status callback |
| 5942 | * @hapd: hostapd BSS data structure (the BSS from which the management frame |
| 5943 | * was sent from) |
| 5944 | * @buf: management frame data (starting from IEEE 802.11 header) |
| 5945 | * @len: length of frame data in octets |
| 5946 | * @stype: management frame subtype from frame control field |
| 5947 | * @ok: Whether the frame was ACK'ed |
| 5948 | */ |
| 5949 | void ieee802_11_mgmt_cb(struct hostapd_data *hapd, const u8 *buf, size_t len, |
| 5950 | u16 stype, int ok) |
| 5951 | { |
| 5952 | const struct ieee80211_mgmt *mgmt; |
| 5953 | mgmt = (const struct ieee80211_mgmt *) buf; |
| 5954 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5955 | #ifdef CONFIG_TESTING_OPTIONS |
| 5956 | if (hapd->ext_mgmt_frame_handling) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5957 | size_t hex_len = 2 * len + 1; |
| 5958 | char *hex = os_malloc(hex_len); |
| 5959 | |
| 5960 | if (hex) { |
| 5961 | wpa_snprintf_hex(hex, hex_len, buf, len); |
| 5962 | wpa_msg(hapd->msg_ctx, MSG_INFO, |
| 5963 | "MGMT-TX-STATUS stype=%u ok=%d buf=%s", |
| 5964 | stype, ok, hex); |
| 5965 | os_free(hex); |
| 5966 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5967 | return; |
| 5968 | } |
| 5969 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 5970 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5971 | switch (stype) { |
| 5972 | case WLAN_FC_STYPE_AUTH: |
| 5973 | wpa_printf(MSG_DEBUG, "mgmt::auth cb"); |
| 5974 | handle_auth_cb(hapd, mgmt, len, ok); |
| 5975 | break; |
| 5976 | case WLAN_FC_STYPE_ASSOC_RESP: |
| 5977 | wpa_printf(MSG_DEBUG, "mgmt::assoc_resp cb"); |
| 5978 | handle_assoc_cb(hapd, mgmt, len, 0, ok); |
| 5979 | break; |
| 5980 | case WLAN_FC_STYPE_REASSOC_RESP: |
| 5981 | wpa_printf(MSG_DEBUG, "mgmt::reassoc_resp cb"); |
| 5982 | handle_assoc_cb(hapd, mgmt, len, 1, ok); |
| 5983 | break; |
| 5984 | case WLAN_FC_STYPE_PROBE_RESP: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5985 | wpa_printf(MSG_EXCESSIVE, "mgmt::proberesp cb ok=%d", ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5986 | break; |
| 5987 | case WLAN_FC_STYPE_DEAUTH: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5988 | wpa_printf(MSG_DEBUG, "mgmt::deauth cb"); |
| 5989 | handle_deauth_cb(hapd, mgmt, len, ok); |
| 5990 | break; |
| 5991 | case WLAN_FC_STYPE_DISASSOC: |
| 5992 | wpa_printf(MSG_DEBUG, "mgmt::disassoc cb"); |
| 5993 | handle_disassoc_cb(hapd, mgmt, len, ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | break; |
| 5995 | case WLAN_FC_STYPE_ACTION: |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5996 | wpa_printf(MSG_DEBUG, "mgmt::action cb ok=%d", ok); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 5997 | handle_action_cb(hapd, mgmt, len, ok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5998 | break; |
| 5999 | default: |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6000 | wpa_printf(MSG_INFO, "unknown mgmt cb frame subtype %d", stype); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6001 | break; |
| 6002 | } |
| 6003 | } |
| 6004 | |
| 6005 | |
| 6006 | int ieee802_11_get_mib(struct hostapd_data *hapd, char *buf, size_t buflen) |
| 6007 | { |
| 6008 | /* TODO */ |
| 6009 | return 0; |
| 6010 | } |
| 6011 | |
| 6012 | |
| 6013 | int ieee802_11_get_mib_sta(struct hostapd_data *hapd, struct sta_info *sta, |
| 6014 | char *buf, size_t buflen) |
| 6015 | { |
| 6016 | /* TODO */ |
| 6017 | return 0; |
| 6018 | } |
| 6019 | |
| 6020 | |
| 6021 | void hostapd_tx_status(struct hostapd_data *hapd, const u8 *addr, |
| 6022 | const u8 *buf, size_t len, int ack) |
| 6023 | { |
| 6024 | struct sta_info *sta; |
| 6025 | struct hostapd_iface *iface = hapd->iface; |
| 6026 | |
| 6027 | sta = ap_get_sta(hapd, addr); |
| 6028 | if (sta == NULL && iface->num_bss > 1) { |
| 6029 | size_t j; |
| 6030 | for (j = 0; j < iface->num_bss; j++) { |
| 6031 | hapd = iface->bss[j]; |
| 6032 | sta = ap_get_sta(hapd, addr); |
| 6033 | if (sta) |
| 6034 | break; |
| 6035 | } |
| 6036 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6037 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6038 | return; |
| 6039 | if (sta->flags & WLAN_STA_PENDING_POLL) { |
| 6040 | wpa_printf(MSG_DEBUG, "STA " MACSTR " %s pending " |
| 6041 | "activity poll", MAC2STR(sta->addr), |
| 6042 | ack ? "ACKed" : "did not ACK"); |
| 6043 | if (ack) |
| 6044 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 6045 | } |
| 6046 | |
| 6047 | ieee802_1x_tx_status(hapd, sta, buf, len, ack); |
| 6048 | } |
| 6049 | |
| 6050 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6051 | void hostapd_eapol_tx_status(struct hostapd_data *hapd, const u8 *dst, |
| 6052 | const u8 *data, size_t len, int ack) |
| 6053 | { |
| 6054 | struct sta_info *sta; |
| 6055 | struct hostapd_iface *iface = hapd->iface; |
| 6056 | |
| 6057 | sta = ap_get_sta(hapd, dst); |
| 6058 | if (sta == NULL && iface->num_bss > 1) { |
| 6059 | size_t j; |
| 6060 | for (j = 0; j < iface->num_bss; j++) { |
| 6061 | hapd = iface->bss[j]; |
| 6062 | sta = ap_get_sta(hapd, dst); |
| 6063 | if (sta) |
| 6064 | break; |
| 6065 | } |
| 6066 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6067 | if (sta == NULL || !(sta->flags & WLAN_STA_ASSOC)) { |
| 6068 | wpa_printf(MSG_DEBUG, "Ignore TX status for Data frame to STA " |
| 6069 | MACSTR " that is not currently associated", |
| 6070 | MAC2STR(dst)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6071 | return; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6072 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6073 | |
| 6074 | ieee802_1x_eapol_tx_status(hapd, sta, data, len, ack); |
| 6075 | } |
| 6076 | |
| 6077 | |
| 6078 | void hostapd_client_poll_ok(struct hostapd_data *hapd, const u8 *addr) |
| 6079 | { |
| 6080 | struct sta_info *sta; |
| 6081 | struct hostapd_iface *iface = hapd->iface; |
| 6082 | |
| 6083 | sta = ap_get_sta(hapd, addr); |
| 6084 | if (sta == NULL && iface->num_bss > 1) { |
| 6085 | size_t j; |
| 6086 | for (j = 0; j < iface->num_bss; j++) { |
| 6087 | hapd = iface->bss[j]; |
| 6088 | sta = ap_get_sta(hapd, addr); |
| 6089 | if (sta) |
| 6090 | break; |
| 6091 | } |
| 6092 | } |
| 6093 | if (sta == NULL) |
| 6094 | return; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6095 | wpa_msg(hapd->msg_ctx, MSG_INFO, AP_STA_POLL_OK MACSTR, |
| 6096 | MAC2STR(sta->addr)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6097 | if (!(sta->flags & WLAN_STA_PENDING_POLL)) |
| 6098 | return; |
| 6099 | |
| 6100 | wpa_printf(MSG_DEBUG, "STA " MACSTR " ACKed pending " |
| 6101 | "activity poll", MAC2STR(sta->addr)); |
| 6102 | sta->flags &= ~WLAN_STA_PENDING_POLL; |
| 6103 | } |
| 6104 | |
| 6105 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | void ieee802_11_rx_from_unknown(struct hostapd_data *hapd, const u8 *src, |
| 6107 | int wds) |
| 6108 | { |
| 6109 | struct sta_info *sta; |
| 6110 | |
| 6111 | sta = ap_get_sta(hapd, src); |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6112 | if (sta && |
| 6113 | ((sta->flags & WLAN_STA_ASSOC) || |
| 6114 | ((sta->flags & WLAN_STA_ASSOC_REQ_OK) && wds))) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6115 | if (!hapd->conf->wds_sta) |
| 6116 | return; |
| 6117 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6118 | if ((sta->flags & (WLAN_STA_ASSOC | WLAN_STA_ASSOC_REQ_OK)) == |
| 6119 | WLAN_STA_ASSOC_REQ_OK) { |
| 6120 | wpa_printf(MSG_DEBUG, |
| 6121 | "Postpone 4-address WDS mode enabling for STA " |
| 6122 | MACSTR " since TX status for AssocResp is not yet known", |
| 6123 | MAC2STR(sta->addr)); |
| 6124 | sta->pending_wds_enable = 1; |
| 6125 | return; |
| 6126 | } |
| 6127 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6128 | if (wds && !(sta->flags & WLAN_STA_WDS)) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6129 | int ret; |
| 6130 | char ifname_wds[IFNAMSIZ + 1]; |
| 6131 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6132 | wpa_printf(MSG_DEBUG, "Enable 4-address WDS mode for " |
| 6133 | "STA " MACSTR " (aid %u)", |
| 6134 | MAC2STR(sta->addr), sta->aid); |
| 6135 | sta->flags |= WLAN_STA_WDS; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6136 | ret = hostapd_set_wds_sta(hapd, ifname_wds, |
| 6137 | sta->addr, sta->aid, 1); |
| 6138 | if (!ret) |
| 6139 | hostapd_set_wds_encryption(hapd, sta, |
| 6140 | ifname_wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6141 | } |
| 6142 | return; |
| 6143 | } |
| 6144 | |
| 6145 | wpa_printf(MSG_DEBUG, "Data/PS-poll frame from not associated STA " |
| 6146 | MACSTR, MAC2STR(src)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6147 | if (is_multicast_ether_addr(src) || is_zero_ether_addr(src) || |
| 6148 | os_memcmp(src, hapd->own_addr, ETH_ALEN) == 0) { |
| 6149 | /* Broadcast bit set in SA or unexpected SA?! Ignore the frame |
| 6150 | * silently. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6151 | return; |
| 6152 | } |
| 6153 | |
| 6154 | if (sta && (sta->flags & WLAN_STA_ASSOC_REQ_OK)) { |
| 6155 | wpa_printf(MSG_DEBUG, "Association Response to the STA has " |
| 6156 | "already been sent, but no TX status yet known - " |
| 6157 | "ignore Class 3 frame issue with " MACSTR, |
| 6158 | MAC2STR(src)); |
| 6159 | return; |
| 6160 | } |
| 6161 | |
| 6162 | if (sta && (sta->flags & WLAN_STA_AUTH)) |
| 6163 | hostapd_drv_sta_disassoc( |
| 6164 | hapd, src, |
| 6165 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 6166 | else |
| 6167 | hostapd_drv_sta_deauth( |
| 6168 | hapd, src, |
| 6169 | WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); |
| 6170 | } |
| 6171 | |
| 6172 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 6173 | static u8 * hostapd_add_tpe_info(u8 *eid, u8 tx_pwr_count, |
| 6174 | enum max_tx_pwr_interpretation tx_pwr_intrpn, |
| 6175 | u8 tx_pwr_cat, u8 tx_pwr) |
| 6176 | { |
| 6177 | int i; |
| 6178 | |
| 6179 | *eid++ = WLAN_EID_TRANSMIT_POWER_ENVELOPE; /* Element ID */ |
| 6180 | *eid++ = 2 + tx_pwr_count; /* Length */ |
| 6181 | |
| 6182 | /* |
| 6183 | * Transmit Power Information field |
| 6184 | * bits 0-2 : Maximum Transmit Power Count |
| 6185 | * bits 3-5 : Maximum Transmit Power Interpretation |
| 6186 | * bits 6-7 : Maximum Transmit Power Category |
| 6187 | */ |
| 6188 | *eid++ = tx_pwr_count | (tx_pwr_intrpn << 3) | (tx_pwr_cat << 6); |
| 6189 | |
| 6190 | /* Maximum Transmit Power field */ |
| 6191 | for (i = 0; i <= tx_pwr_count; i++) |
| 6192 | *eid++ = tx_pwr; |
| 6193 | |
| 6194 | return eid; |
| 6195 | } |
| 6196 | |
| 6197 | |
| 6198 | /* |
| 6199 | * TODO: Extract power limits from channel data after 6G regulatory |
| 6200 | * support. |
| 6201 | */ |
| 6202 | #define REG_PSD_MAX_TXPOWER_FOR_DEFAULT_CLIENT (-1) /* dBm/MHz */ |
| 6203 | #define REG_PSD_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT 5 /* dBm/MHz */ |
| 6204 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6205 | u8 * hostapd_eid_txpower_envelope(struct hostapd_data *hapd, u8 *eid) |
| 6206 | { |
| 6207 | struct hostapd_iface *iface = hapd->iface; |
| 6208 | struct hostapd_config *iconf = iface->conf; |
| 6209 | struct hostapd_hw_modes *mode = iface->current_mode; |
| 6210 | struct hostapd_channel_data *chan; |
| 6211 | int dfs, i; |
| 6212 | u8 channel, tx_pwr_count, local_pwr_constraint; |
| 6213 | int max_tx_power; |
| 6214 | u8 tx_pwr; |
| 6215 | |
| 6216 | if (!mode) |
| 6217 | return eid; |
| 6218 | |
| 6219 | if (ieee80211_freq_to_chan(iface->freq, &channel) == NUM_HOSTAPD_MODES) |
| 6220 | return eid; |
| 6221 | |
| 6222 | for (i = 0; i < mode->num_channels; i++) { |
| 6223 | if (mode->channels[i].freq == iface->freq) |
| 6224 | break; |
| 6225 | } |
| 6226 | if (i == mode->num_channels) |
| 6227 | return eid; |
| 6228 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 6229 | #ifdef CONFIG_IEEE80211AX |
| 6230 | /* IEEE Std 802.11ax-2021, Annex E.2.7 (6 GHz band in the United |
| 6231 | * States): An AP that is an Indoor Access Point per regulatory rules |
| 6232 | * shall send at least two Transmit Power Envelope elements in Beacon |
| 6233 | * and Probe Response frames as follows: |
| 6234 | * - Maximum Transmit Power Category subfield = Default; |
| 6235 | * Unit interpretation = Regulatory client EIRP PSD |
| 6236 | * - Maximum Transmit Power Category subfield = Subordinate Device; |
| 6237 | * Unit interpretation = Regulatory client EIRP PSD |
| 6238 | */ |
| 6239 | if (is_6ghz_op_class(iconf->op_class)) { |
| 6240 | enum max_tx_pwr_interpretation tx_pwr_intrpn; |
| 6241 | |
| 6242 | /* Same Maximum Transmit Power for all 20 MHz bands */ |
| 6243 | tx_pwr_count = 0; |
| 6244 | tx_pwr_intrpn = REGULATORY_CLIENT_EIRP_PSD; |
| 6245 | |
| 6246 | /* Default Transmit Power Envelope for Global Operating Class */ |
| 6247 | tx_pwr = REG_PSD_MAX_TXPOWER_FOR_DEFAULT_CLIENT * 2; |
| 6248 | eid = hostapd_add_tpe_info(eid, tx_pwr_count, tx_pwr_intrpn, |
| 6249 | REG_DEFAULT_CLIENT, tx_pwr); |
| 6250 | |
| 6251 | /* Indoor Access Point must include an additional TPE for |
| 6252 | * subordinate devices */ |
| 6253 | if (iconf->he_6ghz_reg_pwr_type == HE_6GHZ_INDOOR_AP) { |
| 6254 | /* TODO: Extract PSD limits from channel data */ |
| 6255 | tx_pwr = REG_PSD_MAX_TXPOWER_FOR_SUBORDINATE_CLIENT * 2; |
| 6256 | eid = hostapd_add_tpe_info(eid, tx_pwr_count, |
| 6257 | tx_pwr_intrpn, |
| 6258 | REG_SUBORDINATE_CLIENT, |
| 6259 | tx_pwr); |
| 6260 | } |
| 6261 | |
| 6262 | return eid; |
| 6263 | } |
| 6264 | #endif /* CONFIG_IEEE80211AX */ |
| 6265 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6266 | switch (hostapd_get_oper_chwidth(iconf)) { |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6267 | case CONF_OPER_CHWIDTH_USE_HT: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6268 | if (iconf->secondary_channel == 0) { |
| 6269 | /* Max Transmit Power count = 0 (20 MHz) */ |
| 6270 | tx_pwr_count = 0; |
| 6271 | } else { |
| 6272 | /* Max Transmit Power count = 1 (20, 40 MHz) */ |
| 6273 | tx_pwr_count = 1; |
| 6274 | } |
| 6275 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6276 | case CONF_OPER_CHWIDTH_80MHZ: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6277 | /* Max Transmit Power count = 2 (20, 40, and 80 MHz) */ |
| 6278 | tx_pwr_count = 2; |
| 6279 | break; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6280 | case CONF_OPER_CHWIDTH_80P80MHZ: |
| 6281 | case CONF_OPER_CHWIDTH_160MHZ: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6282 | /* Max Transmit Power count = 3 (20, 40, 80, 160/80+80 MHz) */ |
| 6283 | tx_pwr_count = 3; |
| 6284 | break; |
| 6285 | default: |
| 6286 | return eid; |
| 6287 | } |
| 6288 | |
| 6289 | /* |
| 6290 | * Below local_pwr_constraint logic is referred from |
| 6291 | * hostapd_eid_pwr_constraint. |
| 6292 | * |
| 6293 | * Check if DFS is required by regulatory. |
| 6294 | */ |
| 6295 | dfs = hostapd_is_dfs_required(hapd->iface); |
| 6296 | if (dfs < 0) |
| 6297 | dfs = 0; |
| 6298 | |
| 6299 | /* |
| 6300 | * In order to meet regulations when TPC is not implemented using |
| 6301 | * a transmit power that is below the legal maximum (including any |
| 6302 | * mitigation factor) should help. In this case, indicate 3 dB below |
| 6303 | * maximum allowed transmit power. |
| 6304 | */ |
| 6305 | if (hapd->iconf->local_pwr_constraint == -1) |
| 6306 | local_pwr_constraint = (dfs == 0) ? 0 : 3; |
| 6307 | else |
| 6308 | local_pwr_constraint = hapd->iconf->local_pwr_constraint; |
| 6309 | |
| 6310 | /* |
| 6311 | * A STA that is not an AP shall use a transmit power less than or |
| 6312 | * equal to the local maximum transmit power level for the channel. |
| 6313 | * The local maximum transmit power can be calculated from the formula: |
| 6314 | * local max TX pwr = max TX pwr - local pwr constraint |
| 6315 | * Where max TX pwr is maximum transmit power level specified for |
| 6316 | * channel in Country element and local pwr constraint is specified |
| 6317 | * for channel in this Power Constraint element. |
| 6318 | */ |
| 6319 | chan = &mode->channels[i]; |
| 6320 | max_tx_power = chan->max_tx_power - local_pwr_constraint; |
| 6321 | |
| 6322 | /* |
| 6323 | * Local Maximum Transmit power is encoded as two's complement |
| 6324 | * with a 0.5 dB step. |
| 6325 | */ |
| 6326 | max_tx_power *= 2; /* in 0.5 dB steps */ |
| 6327 | if (max_tx_power > 127) { |
| 6328 | /* 63.5 has special meaning of 63.5 dBm or higher */ |
| 6329 | max_tx_power = 127; |
| 6330 | } |
| 6331 | if (max_tx_power < -128) |
| 6332 | max_tx_power = -128; |
| 6333 | if (max_tx_power < 0) |
| 6334 | tx_pwr = 0x80 + max_tx_power + 128; |
| 6335 | else |
| 6336 | tx_pwr = max_tx_power; |
| 6337 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 6338 | return hostapd_add_tpe_info(eid, tx_pwr_count, LOCAL_EIRP, |
| 6339 | 0 /* Reserved for bands other than 6 GHz */, |
| 6340 | tx_pwr); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6341 | } |
| 6342 | |
| 6343 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6344 | u8 * hostapd_eid_wb_chsw_wrapper(struct hostapd_data *hapd, u8 *eid) |
| 6345 | { |
| 6346 | u8 bw, chan1, chan2 = 0; |
| 6347 | int freq1; |
| 6348 | |
| 6349 | if (!hapd->cs_freq_params.channel || |
| 6350 | (!hapd->cs_freq_params.vht_enabled && |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 6351 | !hapd->cs_freq_params.he_enabled && |
| 6352 | !hapd->cs_freq_params.eht_enabled)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6353 | return eid; |
| 6354 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6355 | /* bandwidth: 0: 40, 1: 80, 2: 160, 3: 80+80, 4: 320 */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6356 | switch (hapd->cs_freq_params.bandwidth) { |
| 6357 | case 40: |
| 6358 | bw = 0; |
| 6359 | break; |
| 6360 | case 80: |
| 6361 | /* check if it's 80+80 */ |
| 6362 | if (!hapd->cs_freq_params.center_freq2) |
| 6363 | bw = 1; |
| 6364 | else |
| 6365 | bw = 3; |
| 6366 | break; |
| 6367 | case 160: |
| 6368 | bw = 2; |
| 6369 | break; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6370 | case 320: |
| 6371 | bw = 4; |
| 6372 | break; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6373 | default: |
| 6374 | /* not valid VHT bandwidth or not in CSA */ |
| 6375 | return eid; |
| 6376 | } |
| 6377 | |
| 6378 | freq1 = hapd->cs_freq_params.center_freq1 ? |
| 6379 | hapd->cs_freq_params.center_freq1 : |
| 6380 | hapd->cs_freq_params.freq; |
| 6381 | if (ieee80211_freq_to_chan(freq1, &chan1) != |
| 6382 | HOSTAPD_MODE_IEEE80211A) |
| 6383 | return eid; |
| 6384 | |
| 6385 | if (hapd->cs_freq_params.center_freq2 && |
| 6386 | ieee80211_freq_to_chan(hapd->cs_freq_params.center_freq2, |
| 6387 | &chan2) != HOSTAPD_MODE_IEEE80211A) |
| 6388 | return eid; |
| 6389 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6390 | *eid++ = WLAN_EID_CHANNEL_SWITCH_WRAPPER; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6391 | *eid++ = 5; /* Length of Channel Switch Wrapper */ |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6392 | *eid++ = WLAN_EID_WIDE_BW_CHSWITCH; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6393 | *eid++ = 3; /* Length of Wide Bandwidth Channel Switch element */ |
| 6394 | *eid++ = bw; /* New Channel Width */ |
| 6395 | *eid++ = chan1; /* New Channel Center Frequency Segment 0 */ |
| 6396 | *eid++ = chan2; /* New Channel Center Frequency Segment 1 */ |
| 6397 | |
| 6398 | return eid; |
| 6399 | } |
| 6400 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6401 | |
| 6402 | static size_t hostapd_eid_nr_db_len(struct hostapd_data *hapd, |
| 6403 | size_t *current_len) |
| 6404 | { |
| 6405 | struct hostapd_neighbor_entry *nr; |
| 6406 | size_t total_len = 0, len = *current_len; |
| 6407 | |
| 6408 | dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, |
| 6409 | list) { |
| 6410 | if (!nr->nr || wpabuf_len(nr->nr) < 12) |
| 6411 | continue; |
| 6412 | |
| 6413 | if (nr->short_ssid == hapd->conf->ssid.short_ssid) |
| 6414 | continue; |
| 6415 | |
| 6416 | /* Start a new element */ |
| 6417 | if (!len || |
| 6418 | len + RNR_TBTT_HEADER_LEN + RNR_TBTT_INFO_LEN > 255) { |
| 6419 | len = RNR_HEADER_LEN; |
| 6420 | total_len += RNR_HEADER_LEN; |
| 6421 | } |
| 6422 | |
| 6423 | len += RNR_TBTT_HEADER_LEN + RNR_TBTT_INFO_LEN; |
| 6424 | total_len += RNR_TBTT_HEADER_LEN + RNR_TBTT_INFO_LEN; |
| 6425 | } |
| 6426 | |
| 6427 | *current_len = len; |
| 6428 | return total_len; |
| 6429 | } |
| 6430 | |
| 6431 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6432 | struct mbssid_ie_profiles { |
| 6433 | u8 start; |
| 6434 | u8 end; |
| 6435 | }; |
| 6436 | |
| 6437 | static size_t |
| 6438 | hostapd_eid_rnr_iface_len(struct hostapd_data *hapd, |
| 6439 | struct hostapd_data *reporting_hapd, |
| 6440 | size_t *current_len, |
| 6441 | struct mbssid_ie_profiles *skip_profiles) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6442 | { |
| 6443 | size_t total_len = 0, len = *current_len; |
| 6444 | int tbtt_count = 0; |
| 6445 | size_t i, start = 0; |
| 6446 | |
| 6447 | while (start < hapd->iface->num_bss) { |
| 6448 | if (!len || |
| 6449 | len + RNR_TBTT_HEADER_LEN + RNR_TBTT_INFO_LEN > 255) { |
| 6450 | len = RNR_HEADER_LEN; |
| 6451 | total_len += RNR_HEADER_LEN; |
| 6452 | } |
| 6453 | |
| 6454 | len += RNR_TBTT_HEADER_LEN; |
| 6455 | total_len += RNR_TBTT_HEADER_LEN; |
| 6456 | |
| 6457 | for (i = start; i < hapd->iface->num_bss; i++) { |
| 6458 | struct hostapd_data *bss = hapd->iface->bss[i]; |
| 6459 | |
| 6460 | if (!bss || !bss->conf || !bss->started) |
| 6461 | continue; |
| 6462 | |
| 6463 | if (bss == reporting_hapd || |
| 6464 | bss->conf->ignore_broadcast_ssid) |
| 6465 | continue; |
| 6466 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6467 | if (skip_profiles && |
| 6468 | i >= skip_profiles->start && i < skip_profiles->end) |
| 6469 | continue; |
| 6470 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6471 | if (len + RNR_TBTT_INFO_LEN > 255 || |
| 6472 | tbtt_count >= RNR_TBTT_INFO_COUNT_MAX) |
| 6473 | break; |
| 6474 | |
| 6475 | len += RNR_TBTT_INFO_LEN; |
| 6476 | total_len += RNR_TBTT_INFO_LEN; |
| 6477 | tbtt_count++; |
| 6478 | } |
| 6479 | start = i; |
| 6480 | } |
| 6481 | |
| 6482 | if (!tbtt_count) |
| 6483 | total_len = 0; |
| 6484 | else |
| 6485 | *current_len = len; |
| 6486 | |
| 6487 | return total_len; |
| 6488 | } |
| 6489 | |
| 6490 | |
| 6491 | enum colocation_mode { |
| 6492 | NO_COLOCATED_6GHZ, |
| 6493 | STANDALONE_6GHZ, |
| 6494 | COLOCATED_6GHZ, |
| 6495 | COLOCATED_LOWER_BAND, |
| 6496 | }; |
| 6497 | |
| 6498 | static enum colocation_mode get_colocation_mode(struct hostapd_data *hapd) |
| 6499 | { |
| 6500 | u8 i; |
| 6501 | bool is_6ghz = is_6ghz_op_class(hapd->iconf->op_class); |
| 6502 | |
| 6503 | if (!hapd->iface || !hapd->iface->interfaces) |
| 6504 | return NO_COLOCATED_6GHZ; |
| 6505 | |
| 6506 | if (is_6ghz && hapd->iface->interfaces->count == 1) |
| 6507 | return STANDALONE_6GHZ; |
| 6508 | |
| 6509 | for (i = 0; i < hapd->iface->interfaces->count; i++) { |
| 6510 | struct hostapd_iface *iface; |
| 6511 | bool is_colocated_6ghz; |
| 6512 | |
| 6513 | iface = hapd->iface->interfaces->iface[i]; |
| 6514 | if (iface == hapd->iface || !iface || !iface->conf) |
| 6515 | continue; |
| 6516 | |
| 6517 | is_colocated_6ghz = is_6ghz_op_class(iface->conf->op_class); |
| 6518 | if (!is_6ghz && is_colocated_6ghz) |
| 6519 | return COLOCATED_LOWER_BAND; |
| 6520 | if (is_6ghz && !is_colocated_6ghz) |
| 6521 | return COLOCATED_6GHZ; |
| 6522 | } |
| 6523 | |
| 6524 | if (is_6ghz) |
| 6525 | return STANDALONE_6GHZ; |
| 6526 | |
| 6527 | return NO_COLOCATED_6GHZ; |
| 6528 | } |
| 6529 | |
| 6530 | |
| 6531 | static size_t hostapd_eid_rnr_colocation_len(struct hostapd_data *hapd, |
| 6532 | size_t *current_len) |
| 6533 | { |
| 6534 | struct hostapd_iface *iface; |
| 6535 | size_t len = 0; |
| 6536 | size_t i; |
| 6537 | |
| 6538 | if (!hapd->iface || !hapd->iface->interfaces) |
| 6539 | return 0; |
| 6540 | |
| 6541 | for (i = 0; i < hapd->iface->interfaces->count; i++) { |
| 6542 | iface = hapd->iface->interfaces->iface[i]; |
| 6543 | |
| 6544 | if (iface == hapd->iface || |
| 6545 | !is_6ghz_op_class(iface->conf->op_class)) |
| 6546 | continue; |
| 6547 | |
| 6548 | len += hostapd_eid_rnr_iface_len(iface->bss[0], hapd, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6549 | current_len, NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | return len; |
| 6553 | } |
| 6554 | |
| 6555 | |
| 6556 | size_t hostapd_eid_rnr_len(struct hostapd_data *hapd, u32 type) |
| 6557 | { |
| 6558 | size_t total_len = 0, current_len = 0; |
| 6559 | enum colocation_mode mode = get_colocation_mode(hapd); |
| 6560 | |
| 6561 | switch (type) { |
| 6562 | case WLAN_FC_STYPE_BEACON: |
| 6563 | if (hapd->conf->rnr) |
| 6564 | total_len += hostapd_eid_nr_db_len(hapd, ¤t_len); |
| 6565 | /* fallthrough */ |
| 6566 | |
| 6567 | case WLAN_FC_STYPE_PROBE_RESP: |
| 6568 | if (mode == COLOCATED_LOWER_BAND) |
| 6569 | total_len += hostapd_eid_rnr_colocation_len( |
| 6570 | hapd, ¤t_len); |
| 6571 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6572 | if (hapd->conf->rnr && hapd->iface->num_bss > 1 && |
| 6573 | !hapd->iconf->mbssid) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6574 | total_len += hostapd_eid_rnr_iface_len(hapd, hapd, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6575 | ¤t_len, |
| 6576 | NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6577 | break; |
| 6578 | |
| 6579 | case WLAN_FC_STYPE_ACTION: |
| 6580 | if (hapd->iface->num_bss > 1 && mode == STANDALONE_6GHZ) |
| 6581 | total_len += hostapd_eid_rnr_iface_len(hapd, hapd, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6582 | ¤t_len, |
| 6583 | NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6584 | break; |
| 6585 | |
| 6586 | default: |
| 6587 | break; |
| 6588 | } |
| 6589 | |
| 6590 | return total_len; |
| 6591 | } |
| 6592 | |
| 6593 | |
| 6594 | static u8 * hostapd_eid_nr_db(struct hostapd_data *hapd, u8 *eid, |
| 6595 | size_t *current_len) |
| 6596 | { |
| 6597 | struct hostapd_neighbor_entry *nr; |
| 6598 | size_t len = *current_len; |
| 6599 | u8 *size_offset = (eid - len) + 1; |
| 6600 | |
| 6601 | dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry, |
| 6602 | list) { |
| 6603 | if (!nr->nr || wpabuf_len(nr->nr) < 12) |
| 6604 | continue; |
| 6605 | |
| 6606 | if (nr->short_ssid == hapd->conf->ssid.short_ssid) |
| 6607 | continue; |
| 6608 | |
| 6609 | /* Start a new element */ |
| 6610 | if (!len || |
| 6611 | len + RNR_TBTT_HEADER_LEN + RNR_TBTT_INFO_LEN > 255) { |
| 6612 | *eid++ = WLAN_EID_REDUCED_NEIGHBOR_REPORT; |
| 6613 | size_offset = eid++; |
| 6614 | len = RNR_HEADER_LEN; |
| 6615 | } |
| 6616 | |
| 6617 | /* TBTT Information Header subfield (2 octets) */ |
| 6618 | *eid++ = 0; |
| 6619 | /* TBTT Information Length */ |
| 6620 | *eid++ = RNR_TBTT_INFO_LEN; |
| 6621 | /* Operating Class */ |
| 6622 | *eid++ = wpabuf_head_u8(nr->nr)[10]; |
| 6623 | /* Channel Number */ |
| 6624 | *eid++ = wpabuf_head_u8(nr->nr)[11]; |
| 6625 | len += RNR_TBTT_HEADER_LEN; |
| 6626 | /* TBTT Information Set */ |
| 6627 | /* TBTT Information field */ |
| 6628 | /* Neighbor AP TBTT Offset */ |
| 6629 | *eid++ = RNR_NEIGHBOR_AP_OFFSET_UNKNOWN; |
| 6630 | /* BSSID */ |
| 6631 | os_memcpy(eid, nr->bssid, ETH_ALEN); |
| 6632 | eid += ETH_ALEN; |
| 6633 | /* Short SSID */ |
| 6634 | os_memcpy(eid, &nr->short_ssid, 4); |
| 6635 | eid += 4; |
| 6636 | /* BSS parameters */ |
| 6637 | *eid++ = nr->bss_parameters; |
| 6638 | /* 20 MHz PSD */ |
| 6639 | *eid++ = RNR_20_MHZ_PSD_MAX_TXPOWER - 1; |
| 6640 | len += RNR_TBTT_INFO_LEN; |
| 6641 | *size_offset = (eid - size_offset) - 1; |
| 6642 | } |
| 6643 | |
| 6644 | *current_len = len; |
| 6645 | return eid; |
| 6646 | } |
| 6647 | |
| 6648 | |
| 6649 | static u8 * hostapd_eid_rnr_iface(struct hostapd_data *hapd, |
| 6650 | struct hostapd_data *reporting_hapd, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6651 | u8 *eid, size_t *current_len, |
| 6652 | struct mbssid_ie_profiles *skip_profiles) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6653 | { |
| 6654 | struct hostapd_data *bss; |
| 6655 | struct hostapd_iface *iface = hapd->iface; |
| 6656 | size_t i, start = 0; |
| 6657 | size_t len = *current_len; |
| 6658 | u8 *tbtt_count_pos, *eid_start = eid, *size_offset = (eid - len) + 1; |
| 6659 | u8 tbtt_count = 0, op_class, channel, bss_param; |
| 6660 | |
| 6661 | if (!(iface->drv_flags & WPA_DRIVER_FLAGS_AP_CSA) || !iface->freq) |
| 6662 | return eid; |
| 6663 | |
| 6664 | if (ieee80211_freq_to_channel_ext(iface->freq, |
| 6665 | hapd->iconf->secondary_channel, |
| 6666 | hostapd_get_oper_chwidth(hapd->iconf), |
| 6667 | &op_class, &channel) == |
| 6668 | NUM_HOSTAPD_MODES) |
| 6669 | return eid; |
| 6670 | |
| 6671 | while (start < iface->num_bss) { |
| 6672 | if (!len || |
| 6673 | len + RNR_TBTT_HEADER_LEN + RNR_TBTT_INFO_LEN > 255) { |
| 6674 | eid_start = eid; |
| 6675 | *eid++ = WLAN_EID_REDUCED_NEIGHBOR_REPORT; |
| 6676 | size_offset = eid++; |
| 6677 | len = RNR_HEADER_LEN; |
| 6678 | tbtt_count = 0; |
| 6679 | } |
| 6680 | |
| 6681 | tbtt_count_pos = eid++; |
| 6682 | *eid++ = RNR_TBTT_INFO_LEN; |
| 6683 | *eid++ = op_class; |
| 6684 | *eid++ = hapd->iconf->channel; |
| 6685 | len += RNR_TBTT_HEADER_LEN; |
| 6686 | |
| 6687 | for (i = start; i < iface->num_bss; i++) { |
| 6688 | bss_param = 0; |
| 6689 | bss = iface->bss[i]; |
| 6690 | if (!bss || !bss->conf || !bss->started) |
| 6691 | continue; |
| 6692 | |
| 6693 | if (bss == reporting_hapd || |
| 6694 | bss->conf->ignore_broadcast_ssid) |
| 6695 | continue; |
| 6696 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6697 | if (skip_profiles && |
| 6698 | i >= skip_profiles->start && i < skip_profiles->end) |
| 6699 | continue; |
| 6700 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6701 | if (len + RNR_TBTT_INFO_LEN > 255 || |
| 6702 | tbtt_count >= RNR_TBTT_INFO_COUNT_MAX) |
| 6703 | break; |
| 6704 | |
| 6705 | *eid++ = RNR_NEIGHBOR_AP_OFFSET_UNKNOWN; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6706 | os_memcpy(eid, bss->own_addr, ETH_ALEN); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6707 | eid += ETH_ALEN; |
| 6708 | os_memcpy(eid, &bss->conf->ssid.short_ssid, 4); |
| 6709 | eid += 4; |
| 6710 | if (bss->conf->ssid.short_ssid == |
| 6711 | reporting_hapd->conf->ssid.short_ssid) |
| 6712 | bss_param |= RNR_BSS_PARAM_SAME_SSID; |
| 6713 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6714 | if (iface->conf->mbssid != MBSSID_DISABLED && |
| 6715 | iface->num_bss > 1) { |
| 6716 | bss_param |= RNR_BSS_PARAM_MULTIPLE_BSSID; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6717 | if (bss == hostapd_mbssid_get_tx_bss(hapd)) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6718 | bss_param |= |
| 6719 | RNR_BSS_PARAM_TRANSMITTED_BSSID; |
| 6720 | } |
| 6721 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6722 | if (is_6ghz_op_class(hapd->iconf->op_class) && |
| 6723 | bss->conf->unsol_bcast_probe_resp_interval) |
| 6724 | bss_param |= |
| 6725 | RNR_BSS_PARAM_UNSOLIC_PROBE_RESP_ACTIVE; |
| 6726 | |
| 6727 | bss_param |= RNR_BSS_PARAM_CO_LOCATED; |
| 6728 | |
| 6729 | *eid++ = bss_param; |
| 6730 | *eid++ = RNR_20_MHZ_PSD_MAX_TXPOWER - 1; |
| 6731 | len += RNR_TBTT_INFO_LEN; |
| 6732 | tbtt_count += 1; |
| 6733 | } |
| 6734 | |
| 6735 | start = i; |
| 6736 | *tbtt_count_pos = RNR_TBTT_INFO_COUNT(tbtt_count - 1); |
| 6737 | *size_offset = (eid - size_offset) - 1; |
| 6738 | } |
| 6739 | |
| 6740 | if (tbtt_count == 0) |
| 6741 | return eid_start; |
| 6742 | |
| 6743 | *current_len = len; |
| 6744 | return eid; |
| 6745 | } |
| 6746 | |
| 6747 | |
| 6748 | static u8 * hostapd_eid_rnr_colocation(struct hostapd_data *hapd, u8 *eid, |
| 6749 | size_t *current_len) |
| 6750 | { |
| 6751 | struct hostapd_iface *iface; |
| 6752 | size_t i; |
| 6753 | |
| 6754 | if (!hapd->iface || !hapd->iface->interfaces) |
| 6755 | return eid; |
| 6756 | |
| 6757 | for (i = 0; i < hapd->iface->interfaces->count; i++) { |
| 6758 | iface = hapd->iface->interfaces->iface[i]; |
| 6759 | |
| 6760 | if (iface == hapd->iface || |
| 6761 | !is_6ghz_op_class(iface->conf->op_class)) |
| 6762 | continue; |
| 6763 | |
| 6764 | eid = hostapd_eid_rnr_iface(iface->bss[0], hapd, eid, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6765 | current_len, NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6766 | } |
| 6767 | |
| 6768 | return eid; |
| 6769 | } |
| 6770 | |
| 6771 | |
| 6772 | u8 * hostapd_eid_rnr(struct hostapd_data *hapd, u8 *eid, u32 type) |
| 6773 | { |
| 6774 | u8 *eid_start = eid; |
| 6775 | size_t current_len = 0; |
| 6776 | enum colocation_mode mode = get_colocation_mode(hapd); |
| 6777 | |
| 6778 | switch (type) { |
| 6779 | case WLAN_FC_STYPE_BEACON: |
| 6780 | if (hapd->conf->rnr) |
| 6781 | eid = hostapd_eid_nr_db(hapd, eid, ¤t_len); |
| 6782 | /* fallthrough */ |
| 6783 | |
| 6784 | case WLAN_FC_STYPE_PROBE_RESP: |
| 6785 | if (mode == COLOCATED_LOWER_BAND) |
| 6786 | eid = hostapd_eid_rnr_colocation(hapd, eid, |
| 6787 | ¤t_len); |
| 6788 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6789 | if (hapd->conf->rnr && hapd->iface->num_bss > 1 && |
| 6790 | !hapd->iconf->mbssid) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6791 | eid = hostapd_eid_rnr_iface(hapd, hapd, eid, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6792 | ¤t_len, NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6793 | break; |
| 6794 | |
| 6795 | case WLAN_FC_STYPE_ACTION: |
| 6796 | if (hapd->iface->num_bss > 1 && mode == STANDALONE_6GHZ) |
| 6797 | eid = hostapd_eid_rnr_iface(hapd, hapd, eid, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6798 | ¤t_len, NULL); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6799 | break; |
| 6800 | |
| 6801 | default: |
| 6802 | return eid_start; |
| 6803 | } |
| 6804 | |
| 6805 | if (eid == eid_start + 2) |
| 6806 | return eid_start; |
| 6807 | |
| 6808 | return eid; |
| 6809 | } |
| 6810 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6811 | |
| 6812 | static bool mbssid_known_bss(unsigned int i, const u8 *known_bss, |
| 6813 | size_t known_bss_len) |
| 6814 | { |
| 6815 | if (!known_bss || known_bss_len <= i / 8) |
| 6816 | return false; |
| 6817 | known_bss = &known_bss[i / 8]; |
| 6818 | return *known_bss & (u8) (BIT(i % 8)); |
| 6819 | } |
| 6820 | |
| 6821 | |
| 6822 | static size_t hostapd_eid_mbssid_elem_len(struct hostapd_data *hapd, |
| 6823 | u32 frame_type, size_t *bss_index, |
| 6824 | const u8 *known_bss, |
| 6825 | size_t known_bss_len) |
| 6826 | { |
| 6827 | struct hostapd_data *tx_bss = hostapd_mbssid_get_tx_bss(hapd); |
| 6828 | size_t len = 3, i; |
| 6829 | |
| 6830 | for (i = *bss_index; i < hapd->iface->num_bss; i++) { |
| 6831 | struct hostapd_data *bss = hapd->iface->bss[i]; |
| 6832 | const u8 *auth, *rsn = NULL, *rsnx = NULL; |
| 6833 | size_t nontx_profile_len, auth_len; |
| 6834 | u8 ie_count = 0; |
| 6835 | |
| 6836 | if (!bss || !bss->conf || !bss->started || |
| 6837 | mbssid_known_bss(i, known_bss, known_bss_len)) |
| 6838 | continue; |
| 6839 | |
| 6840 | /* |
| 6841 | * Sublement ID: 1 octet |
| 6842 | * Length: 1 octet |
| 6843 | * Nontransmitted capabilities: 4 octets |
| 6844 | * SSID element: 2 + variable |
| 6845 | * Multiple BSSID Index Element: 3 octets (+2 octets in beacons) |
| 6846 | * Fixed length = 1 + 1 + 4 + 2 + 3 = 11 |
| 6847 | */ |
| 6848 | nontx_profile_len = 11 + bss->conf->ssid.ssid_len; |
| 6849 | |
| 6850 | if (frame_type == WLAN_FC_STYPE_BEACON) |
| 6851 | nontx_profile_len += 2; |
| 6852 | |
| 6853 | auth = wpa_auth_get_wpa_ie(bss->wpa_auth, &auth_len); |
| 6854 | if (auth) { |
| 6855 | rsn = get_ie(auth, auth_len, WLAN_EID_RSN); |
| 6856 | if (rsn) |
| 6857 | nontx_profile_len += 2 + rsn[1]; |
| 6858 | |
| 6859 | rsnx = get_ie(auth, auth_len, WLAN_EID_RSNX); |
| 6860 | if (rsnx) |
| 6861 | nontx_profile_len += 2 + rsnx[1]; |
| 6862 | } |
| 6863 | if (!rsn && hostapd_wpa_ie(tx_bss, WLAN_EID_RSN)) |
| 6864 | ie_count++; |
| 6865 | if (!rsnx && hostapd_wpa_ie(tx_bss, WLAN_EID_RSNX)) |
| 6866 | ie_count++; |
| 6867 | if (bss->conf->xrates_supported) |
| 6868 | nontx_profile_len += 8; |
| 6869 | else if (hapd->conf->xrates_supported) |
| 6870 | ie_count++; |
| 6871 | if (ie_count) |
| 6872 | nontx_profile_len += 4 + ie_count; |
| 6873 | |
| 6874 | if (len + nontx_profile_len > 255) |
| 6875 | break; |
| 6876 | |
| 6877 | len += nontx_profile_len; |
| 6878 | } |
| 6879 | |
| 6880 | *bss_index = i; |
| 6881 | return len; |
| 6882 | } |
| 6883 | |
| 6884 | |
| 6885 | size_t hostapd_eid_mbssid_len(struct hostapd_data *hapd, u32 frame_type, |
| 6886 | u8 *elem_count, const u8 *known_bss, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6887 | size_t known_bss_len, size_t *rnr_len) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6888 | { |
| 6889 | size_t len = 0, bss_index = 1; |
| 6890 | |
| 6891 | if (!hapd->iconf->mbssid || hapd->iface->num_bss <= 1 || |
| 6892 | (frame_type != WLAN_FC_STYPE_BEACON && |
| 6893 | frame_type != WLAN_FC_STYPE_PROBE_RESP)) |
| 6894 | return 0; |
| 6895 | |
| 6896 | if (frame_type == WLAN_FC_STYPE_BEACON) { |
| 6897 | if (!elem_count) { |
| 6898 | wpa_printf(MSG_INFO, |
| 6899 | "MBSSID: Insufficient data for Beacon frames"); |
| 6900 | return 0; |
| 6901 | } |
| 6902 | *elem_count = 0; |
| 6903 | } |
| 6904 | |
| 6905 | while (bss_index < hapd->iface->num_bss) { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6906 | size_t rnr_count = bss_index; |
| 6907 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6908 | len += hostapd_eid_mbssid_elem_len(hapd, frame_type, |
| 6909 | &bss_index, known_bss, |
| 6910 | known_bss_len); |
| 6911 | |
| 6912 | if (frame_type == WLAN_FC_STYPE_BEACON) |
| 6913 | *elem_count += 1; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6914 | if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && rnr_len) { |
| 6915 | size_t rnr_cur_len = 0; |
| 6916 | struct mbssid_ie_profiles skip_profiles = { |
| 6917 | rnr_count, bss_index |
| 6918 | }; |
| 6919 | |
| 6920 | *rnr_len += hostapd_eid_rnr_iface_len( |
| 6921 | hapd, hostapd_mbssid_get_tx_bss(hapd), |
| 6922 | &rnr_cur_len, &skip_profiles); |
| 6923 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6924 | } |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 6925 | |
| 6926 | if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && rnr_len) |
| 6927 | *rnr_len += hostapd_eid_rnr_len(hapd, frame_type); |
| 6928 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6929 | return len; |
| 6930 | } |
| 6931 | |
| 6932 | |
| 6933 | static u8 * hostapd_eid_mbssid_elem(struct hostapd_data *hapd, u8 *eid, u8 *end, |
| 6934 | u32 frame_type, u8 max_bssid_indicator, |
| 6935 | size_t *bss_index, u8 elem_count, |
| 6936 | const u8 *known_bss, size_t known_bss_len) |
| 6937 | { |
| 6938 | struct hostapd_data *tx_bss = hostapd_mbssid_get_tx_bss(hapd); |
| 6939 | size_t i; |
| 6940 | u8 *eid_len_offset, *max_bssid_indicator_offset; |
| 6941 | |
| 6942 | *eid++ = WLAN_EID_MULTIPLE_BSSID; |
| 6943 | eid_len_offset = eid++; |
| 6944 | max_bssid_indicator_offset = eid++; |
| 6945 | |
| 6946 | for (i = *bss_index; i < hapd->iface->num_bss; i++) { |
| 6947 | struct hostapd_data *bss = hapd->iface->bss[i]; |
| 6948 | struct hostapd_bss_config *conf; |
| 6949 | u8 *eid_len_pos, *nontx_bss_start = eid; |
| 6950 | const u8 *auth, *rsn = NULL, *rsnx = NULL; |
| 6951 | u8 ie_count = 0, non_inherit_ie[3]; |
| 6952 | size_t auth_len = 0; |
| 6953 | u16 capab_info; |
| 6954 | |
| 6955 | if (!bss || !bss->conf || !bss->started || |
| 6956 | mbssid_known_bss(i, known_bss, known_bss_len)) |
| 6957 | continue; |
| 6958 | conf = bss->conf; |
| 6959 | |
| 6960 | *eid++ = WLAN_MBSSID_SUBELEMENT_NONTRANSMITTED_BSSID_PROFILE; |
| 6961 | eid_len_pos = eid++; |
| 6962 | |
| 6963 | capab_info = hostapd_own_capab_info(bss); |
| 6964 | *eid++ = WLAN_EID_NONTRANSMITTED_BSSID_CAPA; |
| 6965 | *eid++ = sizeof(capab_info); |
| 6966 | WPA_PUT_LE16(eid, capab_info); |
| 6967 | eid += sizeof(capab_info); |
| 6968 | |
| 6969 | *eid++ = WLAN_EID_SSID; |
| 6970 | *eid++ = conf->ssid.ssid_len; |
| 6971 | os_memcpy(eid, conf->ssid.ssid, conf->ssid.ssid_len); |
| 6972 | eid += conf->ssid.ssid_len; |
| 6973 | |
| 6974 | *eid++ = WLAN_EID_MULTIPLE_BSSID_INDEX; |
| 6975 | if (frame_type == WLAN_FC_STYPE_BEACON) { |
| 6976 | *eid++ = 3; |
| 6977 | *eid++ = i; /* BSSID Index */ |
| 6978 | if (hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 6979 | (conf->dtim_period % elem_count)) |
| 6980 | conf->dtim_period = elem_count; |
| 6981 | *eid++ = conf->dtim_period; |
| 6982 | *eid++ = 0xFF; /* DTIM Count */ |
| 6983 | } else { |
| 6984 | /* Probe Request frame does not include DTIM Period and |
| 6985 | * DTIM Count fields. */ |
| 6986 | *eid++ = 1; |
| 6987 | *eid++ = i; /* BSSID Index */ |
| 6988 | } |
| 6989 | |
| 6990 | auth = wpa_auth_get_wpa_ie(bss->wpa_auth, &auth_len); |
| 6991 | if (auth) { |
| 6992 | rsn = get_ie(auth, auth_len, WLAN_EID_RSN); |
| 6993 | if (rsn) { |
| 6994 | os_memcpy(eid, rsn, 2 + rsn[1]); |
| 6995 | eid += 2 + rsn[1]; |
| 6996 | } |
| 6997 | |
| 6998 | rsnx = get_ie(auth, auth_len, WLAN_EID_RSNX); |
| 6999 | if (rsnx) { |
| 7000 | os_memcpy(eid, rsnx, 2 + rsnx[1]); |
| 7001 | eid += 2 + rsnx[1]; |
| 7002 | } |
| 7003 | } |
| 7004 | if (!rsn && hostapd_wpa_ie(tx_bss, WLAN_EID_RSN)) |
| 7005 | non_inherit_ie[ie_count++] = WLAN_EID_RSN; |
| 7006 | if (!rsnx && hostapd_wpa_ie(tx_bss, WLAN_EID_RSNX)) |
| 7007 | non_inherit_ie[ie_count++] = WLAN_EID_RSNX; |
| 7008 | if (hapd->conf->xrates_supported && |
| 7009 | !bss->conf->xrates_supported) |
| 7010 | non_inherit_ie[ie_count++] = WLAN_EID_EXT_SUPP_RATES; |
| 7011 | if (ie_count) { |
| 7012 | *eid++ = WLAN_EID_EXTENSION; |
| 7013 | *eid++ = 2 + ie_count; |
| 7014 | *eid++ = WLAN_EID_EXT_NON_INHERITANCE; |
| 7015 | *eid++ = ie_count; |
| 7016 | os_memcpy(eid, non_inherit_ie, ie_count); |
| 7017 | eid += ie_count; |
| 7018 | } |
| 7019 | |
| 7020 | *eid_len_pos = (eid - eid_len_pos) - 1; |
| 7021 | |
| 7022 | if (((eid - eid_len_offset) - 1) > 255) { |
| 7023 | eid = nontx_bss_start; |
| 7024 | break; |
| 7025 | } |
| 7026 | } |
| 7027 | |
| 7028 | *bss_index = i; |
| 7029 | *max_bssid_indicator_offset = max_bssid_indicator; |
| 7030 | if (*max_bssid_indicator_offset < 1) |
| 7031 | *max_bssid_indicator_offset = 1; |
| 7032 | *eid_len_offset = (eid - eid_len_offset) - 1; |
| 7033 | return eid; |
| 7034 | } |
| 7035 | |
| 7036 | |
| 7037 | u8 * hostapd_eid_mbssid(struct hostapd_data *hapd, u8 *eid, u8 *end, |
| 7038 | unsigned int frame_stype, u8 elem_count, |
| 7039 | u8 **elem_offset, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 7040 | const u8 *known_bss, size_t known_bss_len, u8 *rnr_eid, |
| 7041 | u8 *rnr_count, u8 **rnr_offset, size_t rnr_len) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7042 | { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 7043 | size_t bss_index = 1, cur_len = 0; |
| 7044 | u8 elem_index = 0, *rnr_start_eid = rnr_eid; |
| 7045 | bool add_rnr; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7046 | |
| 7047 | if (!hapd->iconf->mbssid || hapd->iface->num_bss <= 1 || |
| 7048 | (frame_stype != WLAN_FC_STYPE_BEACON && |
| 7049 | frame_stype != WLAN_FC_STYPE_PROBE_RESP)) |
| 7050 | return eid; |
| 7051 | |
| 7052 | if (frame_stype == WLAN_FC_STYPE_BEACON && !elem_offset) { |
| 7053 | wpa_printf(MSG_INFO, |
| 7054 | "MBSSID: Insufficient data for Beacon frames"); |
| 7055 | return eid; |
| 7056 | } |
| 7057 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 7058 | add_rnr = hapd->iconf->mbssid == ENHANCED_MBSSID_ENABLED && |
| 7059 | frame_stype == WLAN_FC_STYPE_BEACON && |
| 7060 | rnr_eid && rnr_count && rnr_offset && rnr_len; |
| 7061 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7062 | while (bss_index < hapd->iface->num_bss) { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 7063 | unsigned int rnr_start_count = bss_index; |
| 7064 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7065 | if (frame_stype == WLAN_FC_STYPE_BEACON) { |
| 7066 | if (elem_index == elem_count) { |
| 7067 | wpa_printf(MSG_WARNING, |
| 7068 | "MBSSID: Larger number of elements than there is room in the provided array"); |
| 7069 | break; |
| 7070 | } |
| 7071 | |
| 7072 | elem_offset[elem_index] = eid; |
| 7073 | elem_index = elem_index + 1; |
| 7074 | } |
| 7075 | eid = hostapd_eid_mbssid_elem(hapd, eid, end, frame_stype, |
| 7076 | hostapd_max_bssid_indicator(hapd), |
| 7077 | &bss_index, elem_count, |
| 7078 | known_bss, known_bss_len); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame^] | 7079 | |
| 7080 | if (add_rnr) { |
| 7081 | struct mbssid_ie_profiles skip_profiles = { |
| 7082 | rnr_start_count, bss_index |
| 7083 | }; |
| 7084 | |
| 7085 | rnr_offset[*rnr_count] = rnr_eid; |
| 7086 | *rnr_count = *rnr_count + 1; |
| 7087 | cur_len = 0; |
| 7088 | rnr_eid = hostapd_eid_rnr_iface( |
| 7089 | hapd, hostapd_mbssid_get_tx_bss(hapd), |
| 7090 | rnr_eid, &cur_len, &skip_profiles); |
| 7091 | } |
| 7092 | } |
| 7093 | |
| 7094 | if (add_rnr && (size_t) (rnr_eid - rnr_start_eid) < rnr_len) { |
| 7095 | rnr_offset[*rnr_count] = rnr_eid; |
| 7096 | *rnr_count = *rnr_count + 1; |
| 7097 | cur_len = 0; |
| 7098 | |
| 7099 | if (hapd->conf->rnr) |
| 7100 | rnr_eid = hostapd_eid_nr_db(hapd, rnr_eid, &cur_len); |
| 7101 | if (get_colocation_mode(hapd) == COLOCATED_LOWER_BAND) |
| 7102 | rnr_eid = hostapd_eid_rnr_colocation(hapd, rnr_eid, |
| 7103 | &cur_len); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 7104 | } |
| 7105 | |
| 7106 | return eid; |
| 7107 | } |
| 7108 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 7109 | |
| 7110 | static void punct_update_legacy_bw_80(u8 bitmap, u8 pri_chan, u8 *seg0) |
| 7111 | { |
| 7112 | u8 first_chan = *seg0 - 6, sec_chan; |
| 7113 | |
| 7114 | switch (bitmap) { |
| 7115 | case 0x6: |
| 7116 | *seg0 = 0; |
| 7117 | return; |
| 7118 | case 0x8: |
| 7119 | case 0x4: |
| 7120 | case 0x2: |
| 7121 | case 0x1: |
| 7122 | case 0xC: |
| 7123 | case 0x3: |
| 7124 | if (pri_chan < *seg0) |
| 7125 | *seg0 -= 4; |
| 7126 | else |
| 7127 | *seg0 += 4; |
| 7128 | break; |
| 7129 | } |
| 7130 | |
| 7131 | if (pri_chan < *seg0) |
| 7132 | sec_chan = pri_chan + 4; |
| 7133 | else |
| 7134 | sec_chan = pri_chan - 4; |
| 7135 | |
| 7136 | if (bitmap & BIT((sec_chan - first_chan) / 4)) |
| 7137 | *seg0 = 0; |
| 7138 | } |
| 7139 | |
| 7140 | |
| 7141 | static void punct_update_legacy_bw_160(u8 bitmap, u8 pri, |
| 7142 | enum oper_chan_width *width, u8 *seg0) |
| 7143 | { |
| 7144 | if (pri < *seg0) { |
| 7145 | *seg0 -= 8; |
| 7146 | if (bitmap & 0x0F) { |
| 7147 | *width = 0; |
| 7148 | punct_update_legacy_bw_80(bitmap & 0xF, pri, seg0); |
| 7149 | } |
| 7150 | } else { |
| 7151 | *seg0 += 8; |
| 7152 | if (bitmap & 0xF0) { |
| 7153 | *width = 0; |
| 7154 | punct_update_legacy_bw_80((bitmap & 0xF0) >> 4, pri, |
| 7155 | seg0); |
| 7156 | } |
| 7157 | } |
| 7158 | } |
| 7159 | |
| 7160 | |
| 7161 | void punct_update_legacy_bw(u16 bitmap, u8 pri, enum oper_chan_width *width, |
| 7162 | u8 *seg0, u8 *seg1) |
| 7163 | { |
| 7164 | if (*width == CONF_OPER_CHWIDTH_80MHZ && (bitmap & 0xF)) { |
| 7165 | *width = CONF_OPER_CHWIDTH_USE_HT; |
| 7166 | punct_update_legacy_bw_80(bitmap & 0xF, pri, seg0); |
| 7167 | } |
| 7168 | |
| 7169 | if (*width == CONF_OPER_CHWIDTH_160MHZ && (bitmap & 0xFF)) { |
| 7170 | *width = CONF_OPER_CHWIDTH_80MHZ; |
| 7171 | *seg1 = 0; |
| 7172 | punct_update_legacy_bw_160(bitmap & 0xFF, pri, width, seg0); |
| 7173 | } |
| 7174 | |
| 7175 | /* TODO: 320 MHz */ |
| 7176 | } |
| 7177 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7178 | #endif /* CONFIG_NATIVE_WINDOWS */ |