Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * wpa_supplicant - SME |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3 | * Copyright (c) 2009-2014, 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 "includes.h" |
| 10 | |
| 11 | #include "common.h" |
| 12 | #include "utils/eloop.h" |
| 13 | #include "common/ieee802_11_defs.h" |
| 14 | #include "common/ieee802_11_common.h" |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 15 | #include "common/ocv.h" |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 16 | #include "common/hw_features_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 17 | #include "eapol_supp/eapol_supp_sm.h" |
| 18 | #include "common/wpa_common.h" |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 19 | #include "common/sae.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 20 | #include "common/dpp.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 21 | #include "rsn_supp/wpa.h" |
| 22 | #include "rsn_supp/pmksa_cache.h" |
| 23 | #include "config.h" |
| 24 | #include "wpa_supplicant_i.h" |
| 25 | #include "driver_i.h" |
| 26 | #include "wpas_glue.h" |
| 27 | #include "wps_supplicant.h" |
| 28 | #include "p2p_supplicant.h" |
| 29 | #include "notify.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "bss.h" |
| 31 | #include "scan.h" |
| 32 | #include "sme.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 33 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | |
| 35 | #define SME_AUTH_TIMEOUT 5 |
| 36 | #define SME_ASSOC_TIMEOUT 5 |
| 37 | |
| 38 | static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx); |
| 39 | static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 40 | static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | static void sme_stop_sa_query(struct wpa_supplicant *wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | |
| 43 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 44 | #ifdef CONFIG_SAE |
| 45 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 46 | static int index_within_array(const int *array, int idx) |
| 47 | { |
| 48 | int i; |
| 49 | for (i = 0; i < idx; i++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 50 | if (array[i] <= 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 51 | return 0; |
| 52 | } |
| 53 | return 1; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | static int sme_set_sae_group(struct wpa_supplicant *wpa_s) |
| 58 | { |
| 59 | int *groups = wpa_s->conf->sae_groups; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 60 | int default_groups[] = { 19, 20, 21, 0 }; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 61 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 62 | if (!groups || groups[0] <= 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 63 | groups = default_groups; |
| 64 | |
| 65 | /* Configuration may have changed, so validate current index */ |
| 66 | if (!index_within_array(groups, wpa_s->sme.sae_group_index)) |
| 67 | return -1; |
| 68 | |
| 69 | for (;;) { |
| 70 | int group = groups[wpa_s->sme.sae_group_index]; |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 71 | if (group <= 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 72 | break; |
| 73 | if (sae_set_group(&wpa_s->sme.sae, group) == 0) { |
| 74 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected SAE group %d", |
| 75 | wpa_s->sme.sae.group); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 76 | return 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 77 | } |
| 78 | wpa_s->sme.sae_group_index++; |
| 79 | } |
| 80 | |
| 81 | return -1; |
| 82 | } |
| 83 | |
| 84 | |
| 85 | static struct wpabuf * sme_auth_build_sae_commit(struct wpa_supplicant *wpa_s, |
| 86 | struct wpa_ssid *ssid, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 87 | const u8 *bssid, int external, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 88 | int reuse, int *ret_use_pt, |
| 89 | bool *ret_use_pk) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 90 | { |
| 91 | struct wpabuf *buf; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 92 | size_t len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 93 | const char *password; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 94 | struct wpa_bss *bss; |
| 95 | int use_pt = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 96 | bool use_pk = false; |
| 97 | u8 rsnxe_capa = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 98 | |
| 99 | if (ret_use_pt) |
| 100 | *ret_use_pt = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 101 | if (ret_use_pk) |
| 102 | *ret_use_pk = false; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 103 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 104 | #ifdef CONFIG_TESTING_OPTIONS |
| 105 | if (wpa_s->sae_commit_override) { |
| 106 | wpa_printf(MSG_DEBUG, "SAE: TESTING - commit override"); |
| 107 | buf = wpabuf_alloc(4 + wpabuf_len(wpa_s->sae_commit_override)); |
| 108 | if (!buf) |
| 109 | return NULL; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 110 | if (!external) { |
| 111 | wpabuf_put_le16(buf, 1); /* Transaction seq# */ |
| 112 | wpabuf_put_le16(buf, WLAN_STATUS_SUCCESS); |
| 113 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 114 | wpabuf_put_buf(buf, wpa_s->sae_commit_override); |
| 115 | return buf; |
| 116 | } |
| 117 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 118 | |
| 119 | password = ssid->sae_password; |
| 120 | if (!password) |
| 121 | password = ssid->passphrase; |
| 122 | if (!password) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 123 | wpa_printf(MSG_DEBUG, "SAE: No password available"); |
| 124 | return NULL; |
| 125 | } |
| 126 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 127 | if (reuse && wpa_s->sme.sae.tmp && |
| 128 | os_memcmp(bssid, wpa_s->sme.sae.tmp->bssid, ETH_ALEN) == 0) { |
| 129 | wpa_printf(MSG_DEBUG, |
| 130 | "SAE: Reuse previously generated PWE on a retry with the same AP"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 131 | use_pt = wpa_s->sme.sae.h2e; |
| 132 | use_pk = wpa_s->sme.sae.pk; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 133 | goto reuse_data; |
| 134 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 135 | if (sme_set_sae_group(wpa_s) < 0) { |
| 136 | wpa_printf(MSG_DEBUG, "SAE: Failed to select group"); |
| 137 | return NULL; |
| 138 | } |
| 139 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 140 | bss = wpa_bss_get_bssid_latest(wpa_s, bssid); |
| 141 | if (bss) { |
| 142 | const u8 *rsnxe; |
| 143 | |
| 144 | rsnxe = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
| 145 | if (rsnxe && rsnxe[1] >= 1) |
| 146 | rsnxe_capa = rsnxe[2]; |
| 147 | } |
| 148 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 149 | if (ssid->sae_password_id && wpa_s->conf->sae_pwe != 3) |
| 150 | use_pt = 1; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 151 | #ifdef CONFIG_SAE_PK |
| 152 | if ((rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) && |
| 153 | ssid->sae_pk != SAE_PK_MODE_DISABLED && |
| 154 | ((ssid->sae_password && |
| 155 | sae_pk_valid_password(ssid->sae_password)) || |
| 156 | (!ssid->sae_password && ssid->passphrase && |
| 157 | sae_pk_valid_password(ssid->passphrase)))) { |
| 158 | use_pt = 1; |
| 159 | use_pk = true; |
| 160 | } |
| 161 | |
| 162 | if (ssid->sae_pk == SAE_PK_MODE_ONLY && !use_pk) { |
| 163 | wpa_printf(MSG_DEBUG, |
| 164 | "SAE: Cannot use PK with the selected AP"); |
| 165 | return NULL; |
| 166 | } |
| 167 | #endif /* CONFIG_SAE_PK */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 168 | |
| 169 | if (use_pt || wpa_s->conf->sae_pwe == 1 || wpa_s->conf->sae_pwe == 2) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 170 | use_pt = !!(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 171 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 172 | if ((wpa_s->conf->sae_pwe == 1 || ssid->sae_password_id) && |
| 173 | wpa_s->conf->sae_pwe != 3 && |
| 174 | !use_pt) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 175 | wpa_printf(MSG_DEBUG, |
| 176 | "SAE: Cannot use H2E with the selected AP"); |
| 177 | return NULL; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if (use_pt && |
| 182 | sae_prepare_commit_pt(&wpa_s->sme.sae, ssid->pt, |
| 183 | wpa_s->own_addr, bssid, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 184 | wpa_s->sme.sae_rejected_groups, NULL) < 0) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 185 | return NULL; |
| 186 | if (!use_pt && |
| 187 | sae_prepare_commit(wpa_s->own_addr, bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 188 | (u8 *) password, os_strlen(password), |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 189 | ssid->sae_password_id, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 190 | &wpa_s->sme.sae) < 0) { |
| 191 | wpa_printf(MSG_DEBUG, "SAE: Could not pick PWE"); |
| 192 | return NULL; |
| 193 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 194 | if (wpa_s->sme.sae.tmp) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 195 | os_memcpy(wpa_s->sme.sae.tmp->bssid, bssid, ETH_ALEN); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 196 | if (use_pt && use_pk) |
| 197 | wpa_s->sme.sae.pk = 1; |
| 198 | #ifdef CONFIG_SAE_PK |
| 199 | os_memcpy(wpa_s->sme.sae.tmp->own_addr, wpa_s->own_addr, |
| 200 | ETH_ALEN); |
| 201 | os_memcpy(wpa_s->sme.sae.tmp->peer_addr, bssid, ETH_ALEN); |
| 202 | sae_pk_set_password(&wpa_s->sme.sae, password); |
| 203 | #endif /* CONFIG_SAE_PK */ |
| 204 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 205 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 206 | reuse_data: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 207 | len = wpa_s->sme.sae_token ? 3 + wpabuf_len(wpa_s->sme.sae_token) : 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 208 | if (ssid->sae_password_id) |
| 209 | len += 4 + os_strlen(ssid->sae_password_id); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 210 | buf = wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN + len); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 211 | if (buf == NULL) |
| 212 | return NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 213 | if (!external) { |
| 214 | wpabuf_put_le16(buf, 1); /* Transaction seq# */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 215 | if (use_pk) |
| 216 | wpabuf_put_le16(buf, WLAN_STATUS_SAE_PK); |
| 217 | else if (use_pt) |
| 218 | wpabuf_put_le16(buf, WLAN_STATUS_SAE_HASH_TO_ELEMENT); |
| 219 | else |
| 220 | wpabuf_put_le16(buf,WLAN_STATUS_SUCCESS); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 221 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 222 | if (sae_write_commit(&wpa_s->sme.sae, buf, wpa_s->sme.sae_token, |
| 223 | ssid->sae_password_id) < 0) { |
| 224 | wpabuf_free(buf); |
| 225 | return NULL; |
| 226 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 227 | if (ret_use_pt) |
| 228 | *ret_use_pt = use_pt; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 229 | if (ret_use_pk) |
| 230 | *ret_use_pk = use_pk; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 231 | |
| 232 | return buf; |
| 233 | } |
| 234 | |
| 235 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 236 | static struct wpabuf * sme_auth_build_sae_confirm(struct wpa_supplicant *wpa_s, |
| 237 | int external) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 238 | { |
| 239 | struct wpabuf *buf; |
| 240 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 241 | buf = wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 242 | if (buf == NULL) |
| 243 | return NULL; |
| 244 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 245 | if (!external) { |
| 246 | wpabuf_put_le16(buf, 2); /* Transaction seq# */ |
| 247 | wpabuf_put_le16(buf, WLAN_STATUS_SUCCESS); |
| 248 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 249 | sae_write_confirm(&wpa_s->sme.sae, buf); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 250 | |
| 251 | return buf; |
| 252 | } |
| 253 | |
| 254 | #endif /* CONFIG_SAE */ |
| 255 | |
| 256 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 257 | /** |
| 258 | * sme_auth_handle_rrm - Handle RRM aspects of current authentication attempt |
| 259 | * @wpa_s: Pointer to wpa_supplicant data |
| 260 | * @bss: Pointer to the bss which is the target of authentication attempt |
| 261 | */ |
| 262 | static void sme_auth_handle_rrm(struct wpa_supplicant *wpa_s, |
| 263 | struct wpa_bss *bss) |
| 264 | { |
| 265 | const u8 rrm_ie_len = 5; |
| 266 | u8 *pos; |
| 267 | const u8 *rrm_ie; |
| 268 | |
| 269 | wpa_s->rrm.rrm_used = 0; |
| 270 | |
| 271 | wpa_printf(MSG_DEBUG, |
| 272 | "RRM: Determining whether RRM can be used - device support: 0x%x", |
| 273 | wpa_s->drv_rrm_flags); |
| 274 | |
| 275 | rrm_ie = wpa_bss_get_ie(bss, WLAN_EID_RRM_ENABLED_CAPABILITIES); |
| 276 | if (!rrm_ie || !(bss->caps & IEEE80211_CAP_RRM)) { |
| 277 | wpa_printf(MSG_DEBUG, "RRM: No RRM in network"); |
| 278 | return; |
| 279 | } |
| 280 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 281 | if (!((wpa_s->drv_rrm_flags & |
| 282 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 283 | (wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 284 | !(wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 285 | wpa_printf(MSG_DEBUG, |
| 286 | "RRM: Insufficient RRM support in driver - do not use RRM"); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | if (sizeof(wpa_s->sme.assoc_req_ie) < |
| 291 | wpa_s->sme.assoc_req_ie_len + rrm_ie_len + 2) { |
| 292 | wpa_printf(MSG_INFO, |
| 293 | "RRM: Unable to use RRM, no room for RRM IE"); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | wpa_printf(MSG_DEBUG, "RRM: Adding RRM IE to Association Request"); |
| 298 | pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len; |
| 299 | os_memset(pos, 0, 2 + rrm_ie_len); |
| 300 | *pos++ = WLAN_EID_RRM_ENABLED_CAPABILITIES; |
| 301 | *pos++ = rrm_ie_len; |
| 302 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 303 | /* Set supported capabilities flags */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 304 | if (wpa_s->drv_rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) |
| 305 | *pos |= WLAN_RRM_CAPS_LINK_MEASUREMENT; |
| 306 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 307 | *pos |= WLAN_RRM_CAPS_BEACON_REPORT_PASSIVE | |
| 308 | WLAN_RRM_CAPS_BEACON_REPORT_ACTIVE | |
| 309 | WLAN_RRM_CAPS_BEACON_REPORT_TABLE; |
| 310 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 311 | if (wpa_s->lci) |
| 312 | pos[1] |= WLAN_RRM_CAPS_LCI_MEASUREMENT; |
| 313 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 314 | wpa_s->sme.assoc_req_ie_len += rrm_ie_len + 2; |
| 315 | wpa_s->rrm.rrm_used = 1; |
| 316 | } |
| 317 | |
| 318 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 319 | static void sme_send_authentication(struct wpa_supplicant *wpa_s, |
| 320 | struct wpa_bss *bss, struct wpa_ssid *ssid, |
| 321 | int start) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 322 | { |
| 323 | struct wpa_driver_auth_params params; |
| 324 | struct wpa_ssid *old_ssid; |
| 325 | #ifdef CONFIG_IEEE80211R |
| 326 | const u8 *ie; |
| 327 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 328 | #if defined(CONFIG_IEEE80211R) || defined(CONFIG_FILS) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 329 | const u8 *md = NULL; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 330 | #endif /* CONFIG_IEEE80211R || CONFIG_FILS */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 331 | int bssid_changed; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 332 | struct wpabuf *resp = NULL; |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 333 | u8 ext_capab[18]; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 334 | int ext_capab_len; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 335 | int skip_auth; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 336 | u8 *wpa_ie; |
| 337 | size_t wpa_ie_len; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 338 | #ifdef CONFIG_MBO |
| 339 | const u8 *mbo_ie; |
| 340 | #endif /* CONFIG_MBO */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 341 | int omit_rsnxe = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 342 | |
| 343 | if (bss == NULL) { |
| 344 | wpa_msg(wpa_s, MSG_ERROR, "SME: No scan result available for " |
| 345 | "the network"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 346 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 347 | return; |
| 348 | } |
| 349 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 350 | skip_auth = wpa_s->conf->reassoc_same_bss_optim && |
| 351 | wpa_s->reassoc_same_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 352 | wpa_s->current_bss = bss; |
| 353 | |
| 354 | os_memset(¶ms, 0, sizeof(params)); |
| 355 | wpa_s->reassociate = 0; |
| 356 | |
| 357 | params.freq = bss->freq; |
| 358 | params.bssid = bss->bssid; |
| 359 | params.ssid = bss->ssid; |
| 360 | params.ssid_len = bss->ssid_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 361 | params.p2p = ssid->p2p_group; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | |
| 363 | if (wpa_s->sme.ssid_len != params.ssid_len || |
| 364 | os_memcmp(wpa_s->sme.ssid, params.ssid, params.ssid_len) != 0) |
| 365 | wpa_s->sme.prev_bssid_set = 0; |
| 366 | |
| 367 | wpa_s->sme.freq = params.freq; |
| 368 | os_memcpy(wpa_s->sme.ssid, params.ssid, params.ssid_len); |
| 369 | wpa_s->sme.ssid_len = params.ssid_len; |
| 370 | |
| 371 | params.auth_alg = WPA_AUTH_ALG_OPEN; |
| 372 | #ifdef IEEE8021X_EAPOL |
| 373 | if (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) { |
| 374 | if (ssid->leap) { |
| 375 | if (ssid->non_leap == 0) |
| 376 | params.auth_alg = WPA_AUTH_ALG_LEAP; |
| 377 | else |
| 378 | params.auth_alg |= WPA_AUTH_ALG_LEAP; |
| 379 | } |
| 380 | } |
| 381 | #endif /* IEEE8021X_EAPOL */ |
| 382 | wpa_dbg(wpa_s, MSG_DEBUG, "Automatic auth_alg selection: 0x%x", |
| 383 | params.auth_alg); |
| 384 | if (ssid->auth_alg) { |
| 385 | params.auth_alg = ssid->auth_alg; |
| 386 | wpa_dbg(wpa_s, MSG_DEBUG, "Overriding auth_alg selection: " |
| 387 | "0x%x", params.auth_alg); |
| 388 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 389 | #ifdef CONFIG_SAE |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 390 | wpa_s->sme.sae_pmksa_caching = 0; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 391 | if (wpa_key_mgmt_sae(ssid->key_mgmt)) { |
| 392 | const u8 *rsn; |
| 393 | struct wpa_ie_data ied; |
| 394 | |
| 395 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 396 | if (!rsn) { |
| 397 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 398 | "SAE enabled, but target BSS does not advertise RSN"); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 399 | #ifdef CONFIG_DPP |
| 400 | } else if (wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 && |
| 401 | (ssid->key_mgmt & WPA_KEY_MGMT_DPP) && |
| 402 | (ied.key_mgmt & WPA_KEY_MGMT_DPP)) { |
| 403 | wpa_dbg(wpa_s, MSG_DEBUG, "Prefer DPP over SAE when both are enabled"); |
| 404 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 405 | } else if (wpa_parse_wpa_ie(rsn, 2 + rsn[1], &ied) == 0 && |
| 406 | wpa_key_mgmt_sae(ied.key_mgmt)) { |
| 407 | wpa_dbg(wpa_s, MSG_DEBUG, "Using SAE auth_alg"); |
| 408 | params.auth_alg = WPA_AUTH_ALG_SAE; |
| 409 | } else { |
| 410 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 411 | "SAE enabled, but target BSS does not advertise SAE AKM for RSN"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 415 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 416 | #ifdef CONFIG_WEP |
| 417 | { |
| 418 | int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 419 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 420 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 421 | if (ssid->wep_key_len[i]) |
| 422 | params.wep_key[i] = ssid->wep_key[i]; |
| 423 | params.wep_key_len[i] = ssid->wep_key_len[i]; |
| 424 | } |
| 425 | params.wep_tx_keyidx = ssid->wep_tx_keyidx; |
| 426 | } |
| 427 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 428 | |
| 429 | if ((wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE) || |
| 430 | wpa_bss_get_ie(bss, WLAN_EID_RSN)) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 431 | wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 432 | int try_opportunistic; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 433 | const u8 *cache_id = NULL; |
| 434 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 435 | try_opportunistic = (ssid->proactive_key_caching < 0 ? |
| 436 | wpa_s->conf->okc : |
| 437 | ssid->proactive_key_caching) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 438 | (ssid->proto & WPA_PROTO_RSN); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 439 | #ifdef CONFIG_FILS |
| 440 | if (wpa_key_mgmt_fils(ssid->key_mgmt)) |
| 441 | cache_id = wpa_bss_get_fils_cache_id(bss); |
| 442 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, |
| 444 | wpa_s->current_ssid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 445 | try_opportunistic, cache_id, |
| 446 | 0) == 0) |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 447 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 448 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
| 449 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
| 450 | wpa_s->sme.assoc_req_ie, |
| 451 | &wpa_s->sme.assoc_req_ie_len)) { |
| 452 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
| 453 | "key management and encryption suites"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 454 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 455 | return; |
| 456 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 457 | #ifdef CONFIG_HS20 |
| 458 | } else if (wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE) && |
| 459 | (ssid->key_mgmt & WPA_KEY_MGMT_OSEN)) { |
| 460 | /* No PMKSA caching, but otherwise similar to RSN/WPA */ |
| 461 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
| 462 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
| 463 | wpa_s->sme.assoc_req_ie, |
| 464 | &wpa_s->sme.assoc_req_ie_len)) { |
| 465 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
| 466 | "key management and encryption suites"); |
| 467 | wpas_connect_work_done(wpa_s); |
| 468 | return; |
| 469 | } |
| 470 | #endif /* CONFIG_HS20 */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 471 | } else if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
| 472 | wpa_key_mgmt_wpa_ieee8021x(ssid->key_mgmt)) { |
| 473 | /* |
| 474 | * Both WPA and non-WPA IEEE 802.1X enabled in configuration - |
| 475 | * use non-WPA since the scan results did not indicate that the |
| 476 | * AP is using WPA or WPA2. |
| 477 | */ |
| 478 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 479 | wpa_s->sme.assoc_req_ie_len = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 480 | } else if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 481 | wpa_s->sme.assoc_req_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
| 482 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
| 483 | wpa_s->sme.assoc_req_ie, |
| 484 | &wpa_s->sme.assoc_req_ie_len)) { |
| 485 | wpa_msg(wpa_s, MSG_WARNING, "SME: Failed to set WPA " |
| 486 | "key management and encryption suites (no " |
| 487 | "scan results)"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 488 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | return; |
| 490 | } |
| 491 | #ifdef CONFIG_WPS |
| 492 | } else if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
| 493 | struct wpabuf *wps_ie; |
| 494 | wps_ie = wps_build_assoc_req_ie(wpas_wps_get_req_type(ssid)); |
| 495 | if (wps_ie && wpabuf_len(wps_ie) <= |
| 496 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 497 | wpa_s->sme.assoc_req_ie_len = wpabuf_len(wps_ie); |
| 498 | os_memcpy(wpa_s->sme.assoc_req_ie, wpabuf_head(wps_ie), |
| 499 | wpa_s->sme.assoc_req_ie_len); |
| 500 | } else |
| 501 | wpa_s->sme.assoc_req_ie_len = 0; |
| 502 | wpabuf_free(wps_ie); |
| 503 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 504 | #endif /* CONFIG_WPS */ |
| 505 | } else { |
| 506 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 507 | wpa_s->sme.assoc_req_ie_len = 0; |
| 508 | } |
| 509 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 510 | /* In case the WPA vendor IE is used, it should be placed after all the |
| 511 | * non-vendor IEs, as the lower layer expects the IEs to be ordered as |
| 512 | * defined in the standard. Store the WPA IE so it can later be |
| 513 | * inserted at the correct location. |
| 514 | */ |
| 515 | wpa_ie = NULL; |
| 516 | wpa_ie_len = 0; |
| 517 | if (wpa_s->wpa_proto == WPA_PROTO_WPA) { |
| 518 | wpa_ie = os_memdup(wpa_s->sme.assoc_req_ie, |
| 519 | wpa_s->sme.assoc_req_ie_len); |
| 520 | if (wpa_ie) { |
| 521 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Storing WPA IE"); |
| 522 | |
| 523 | wpa_ie_len = wpa_s->sme.assoc_req_ie_len; |
| 524 | wpa_s->sme.assoc_req_ie_len = 0; |
| 525 | } else { |
| 526 | wpa_msg(wpa_s, MSG_WARNING, "WPA: Failed copy WPA IE"); |
| 527 | wpas_connect_work_done(wpa_s); |
| 528 | return; |
| 529 | } |
| 530 | } |
| 531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 532 | #ifdef CONFIG_IEEE80211R |
| 533 | ie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN); |
| 534 | if (ie && ie[1] >= MOBILITY_DOMAIN_ID_LEN) |
| 535 | md = ie + 2; |
| 536 | wpa_sm_set_ft_params(wpa_s->wpa, ie, ie ? 2 + ie[1] : 0); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 537 | if (md && (!wpa_key_mgmt_ft(ssid->key_mgmt) || |
| 538 | !wpa_key_mgmt_ft(wpa_s->key_mgmt))) |
| 539 | md = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 540 | if (md) { |
| 541 | /* Prepare for the next transition */ |
| 542 | wpa_ft_prepare_auth_request(wpa_s->wpa, ie); |
| 543 | } |
| 544 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 545 | if (md) { |
| 546 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: FT mobility domain %02x%02x", |
| 547 | md[0], md[1]); |
| 548 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 549 | omit_rsnxe = !wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 550 | if (wpa_s->sme.assoc_req_ie_len + 5 < |
| 551 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 552 | struct rsn_mdie *mdie; |
| 553 | u8 *pos = wpa_s->sme.assoc_req_ie + |
| 554 | wpa_s->sme.assoc_req_ie_len; |
| 555 | *pos++ = WLAN_EID_MOBILITY_DOMAIN; |
| 556 | *pos++ = sizeof(*mdie); |
| 557 | mdie = (struct rsn_mdie *) pos; |
| 558 | os_memcpy(mdie->mobility_domain, md, |
| 559 | MOBILITY_DOMAIN_ID_LEN); |
| 560 | mdie->ft_capab = md[MOBILITY_DOMAIN_ID_LEN]; |
| 561 | wpa_s->sme.assoc_req_ie_len += 5; |
| 562 | } |
| 563 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 564 | if (wpa_s->sme.prev_bssid_set && wpa_s->sme.ft_used && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 565 | os_memcmp(md, wpa_s->sme.mobility_domain, 2) == 0 && |
| 566 | wpa_sm_has_ptk(wpa_s->wpa)) { |
| 567 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying to use FT " |
| 568 | "over-the-air"); |
| 569 | params.auth_alg = WPA_AUTH_ALG_FT; |
| 570 | params.ie = wpa_s->sme.ft_ies; |
| 571 | params.ie_len = wpa_s->sme.ft_ies_len; |
| 572 | } |
| 573 | } |
| 574 | #endif /* CONFIG_IEEE80211R */ |
| 575 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 576 | wpa_s->sme.mfp = wpas_get_ssid_pmf(wpa_s, ssid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 577 | if (wpa_s->sme.mfp != NO_MGMT_FRAME_PROTECTION) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 578 | const u8 *rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 579 | struct wpa_ie_data _ie; |
| 580 | if (rsn && wpa_parse_wpa_ie(rsn, 2 + rsn[1], &_ie) == 0 && |
| 581 | _ie.capabilities & |
| 582 | (WPA_CAPABILITY_MFPC | WPA_CAPABILITY_MFPR)) { |
| 583 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected AP supports " |
| 584 | "MFP: require MFP"); |
| 585 | wpa_s->sme.mfp = MGMT_FRAME_PROTECTION_REQUIRED; |
| 586 | } |
| 587 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 588 | |
| 589 | #ifdef CONFIG_P2P |
| 590 | if (wpa_s->global->p2p) { |
| 591 | u8 *pos; |
| 592 | size_t len; |
| 593 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 594 | pos = wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len; |
| 595 | len = sizeof(wpa_s->sme.assoc_req_ie) - |
| 596 | wpa_s->sme.assoc_req_ie_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 597 | res = wpas_p2p_assoc_req_ie(wpa_s, bss, pos, len, |
| 598 | ssid->p2p_group); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 599 | if (res >= 0) |
| 600 | wpa_s->sme.assoc_req_ie_len += res; |
| 601 | } |
| 602 | #endif /* CONFIG_P2P */ |
| 603 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 604 | #ifdef CONFIG_FST |
| 605 | if (wpa_s->fst_ies) { |
| 606 | int fst_ies_len = wpabuf_len(wpa_s->fst_ies); |
| 607 | |
| 608 | if (wpa_s->sme.assoc_req_ie_len + fst_ies_len <= |
| 609 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 610 | os_memcpy(wpa_s->sme.assoc_req_ie + |
| 611 | wpa_s->sme.assoc_req_ie_len, |
| 612 | wpabuf_head(wpa_s->fst_ies), |
| 613 | fst_ies_len); |
| 614 | wpa_s->sme.assoc_req_ie_len += fst_ies_len; |
| 615 | } |
| 616 | } |
| 617 | #endif /* CONFIG_FST */ |
| 618 | |
| 619 | sme_auth_handle_rrm(wpa_s, bss); |
| 620 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 621 | wpa_s->sme.assoc_req_ie_len += wpas_supp_op_class_ie( |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 622 | wpa_s, ssid, bss, |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 623 | wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 624 | sizeof(wpa_s->sme.assoc_req_ie) - wpa_s->sme.assoc_req_ie_len); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 625 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 626 | if (params.p2p) |
| 627 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT); |
| 628 | else |
| 629 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION); |
| 630 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 631 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
| 632 | sizeof(ext_capab)); |
| 633 | if (ext_capab_len > 0) { |
| 634 | u8 *pos = wpa_s->sme.assoc_req_ie; |
| 635 | if (wpa_s->sme.assoc_req_ie_len > 0 && pos[0] == WLAN_EID_RSN) |
| 636 | pos += 2 + pos[1]; |
| 637 | os_memmove(pos + ext_capab_len, pos, |
| 638 | wpa_s->sme.assoc_req_ie_len - |
| 639 | (pos - wpa_s->sme.assoc_req_ie)); |
| 640 | wpa_s->sme.assoc_req_ie_len += ext_capab_len; |
| 641 | os_memcpy(pos, ext_capab, ext_capab_len); |
| 642 | } |
| 643 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 644 | #ifdef CONFIG_TESTING_OPTIONS |
| 645 | if (wpa_s->rsnxe_override_assoc && |
| 646 | wpabuf_len(wpa_s->rsnxe_override_assoc) <= |
| 647 | sizeof(wpa_s->sme.assoc_req_ie) - wpa_s->sme.assoc_req_ie_len) { |
| 648 | wpa_printf(MSG_DEBUG, "TESTING: RSNXE AssocReq override"); |
| 649 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 650 | wpabuf_head(wpa_s->rsnxe_override_assoc), |
| 651 | wpabuf_len(wpa_s->rsnxe_override_assoc)); |
| 652 | wpa_s->sme.assoc_req_ie_len += |
| 653 | wpabuf_len(wpa_s->rsnxe_override_assoc); |
| 654 | } else |
| 655 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 656 | if (wpa_s->rsnxe_len > 0 && |
| 657 | wpa_s->rsnxe_len <= |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 658 | sizeof(wpa_s->sme.assoc_req_ie) - wpa_s->sme.assoc_req_ie_len && |
| 659 | !omit_rsnxe) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 660 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 661 | wpa_s->rsnxe, wpa_s->rsnxe_len); |
| 662 | wpa_s->sme.assoc_req_ie_len += wpa_s->rsnxe_len; |
| 663 | } |
| 664 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 665 | #ifdef CONFIG_HS20 |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 666 | if (is_hs20_network(wpa_s, ssid, bss)) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 667 | struct wpabuf *hs20; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 668 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 669 | hs20 = wpabuf_alloc(20 + MAX_ROAMING_CONS_OI_LEN); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 670 | if (hs20) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 671 | int pps_mo_id = hs20_get_pps_mo_id(wpa_s, ssid); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 672 | size_t len; |
| 673 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 674 | wpas_hs20_add_indication(hs20, pps_mo_id, |
| 675 | get_hs20_version(bss)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 676 | wpas_hs20_add_roam_cons_sel(hs20, ssid); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 677 | len = sizeof(wpa_s->sme.assoc_req_ie) - |
| 678 | wpa_s->sme.assoc_req_ie_len; |
| 679 | if (wpabuf_len(hs20) <= len) { |
| 680 | os_memcpy(wpa_s->sme.assoc_req_ie + |
| 681 | wpa_s->sme.assoc_req_ie_len, |
| 682 | wpabuf_head(hs20), wpabuf_len(hs20)); |
| 683 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(hs20); |
| 684 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 685 | wpabuf_free(hs20); |
| 686 | } |
| 687 | } |
| 688 | #endif /* CONFIG_HS20 */ |
| 689 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 690 | if (wpa_ie) { |
| 691 | size_t len; |
| 692 | |
| 693 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Reinsert WPA IE"); |
| 694 | |
| 695 | len = sizeof(wpa_s->sme.assoc_req_ie) - |
| 696 | wpa_s->sme.assoc_req_ie_len; |
| 697 | |
| 698 | if (len > wpa_ie_len) { |
| 699 | os_memcpy(wpa_s->sme.assoc_req_ie + |
| 700 | wpa_s->sme.assoc_req_ie_len, |
| 701 | wpa_ie, wpa_ie_len); |
| 702 | wpa_s->sme.assoc_req_ie_len += wpa_ie_len; |
| 703 | } else { |
| 704 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Failed to add WPA IE"); |
| 705 | } |
| 706 | |
| 707 | os_free(wpa_ie); |
| 708 | } |
| 709 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 710 | if (wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]) { |
| 711 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_ASSOC_REQ]; |
| 712 | size_t len; |
| 713 | |
| 714 | len = sizeof(wpa_s->sme.assoc_req_ie) - |
| 715 | wpa_s->sme.assoc_req_ie_len; |
| 716 | if (wpabuf_len(buf) <= len) { |
| 717 | os_memcpy(wpa_s->sme.assoc_req_ie + |
| 718 | wpa_s->sme.assoc_req_ie_len, |
| 719 | wpabuf_head(buf), wpabuf_len(buf)); |
| 720 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(buf); |
| 721 | } |
| 722 | } |
| 723 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 724 | #ifdef CONFIG_MBO |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 725 | mbo_ie = wpa_bss_get_vendor_ie(bss, MBO_IE_VENDOR_TYPE); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 726 | if (!wpa_s->disable_mbo_oce && mbo_ie) { |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 727 | int len; |
| 728 | |
| 729 | len = wpas_mbo_ie(wpa_s, wpa_s->sme.assoc_req_ie + |
| 730 | wpa_s->sme.assoc_req_ie_len, |
| 731 | sizeof(wpa_s->sme.assoc_req_ie) - |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 732 | wpa_s->sme.assoc_req_ie_len, |
| 733 | !!mbo_attr_from_mbo_ie(mbo_ie, |
| 734 | OCE_ATTR_ID_CAPA_IND)); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 735 | if (len >= 0) |
| 736 | wpa_s->sme.assoc_req_ie_len += len; |
| 737 | } |
| 738 | #endif /* CONFIG_MBO */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 739 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 740 | #ifdef CONFIG_SAE |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 741 | if (!skip_auth && params.auth_alg == WPA_AUTH_ALG_SAE && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 742 | pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, ssid, 0, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 743 | NULL, |
| 744 | wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE ? |
| 745 | WPA_KEY_MGMT_FT_SAE : |
| 746 | WPA_KEY_MGMT_SAE) == 0) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 747 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 748 | "PMKSA cache entry found - try to use PMKSA caching instead of new SAE authentication"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 749 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 750 | params.auth_alg = WPA_AUTH_ALG_OPEN; |
| 751 | wpa_s->sme.sae_pmksa_caching = 1; |
| 752 | } |
| 753 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 754 | if (!skip_auth && params.auth_alg == WPA_AUTH_ALG_SAE) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 755 | if (start) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 756 | resp = sme_auth_build_sae_commit(wpa_s, ssid, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 757 | bss->bssid, 0, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 758 | start == 2, NULL, |
| 759 | NULL); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 760 | else |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 761 | resp = sme_auth_build_sae_confirm(wpa_s, 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 762 | if (resp == NULL) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 763 | wpas_connection_failed(wpa_s, bss->bssid); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 764 | return; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 765 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 766 | params.auth_data = wpabuf_head(resp); |
| 767 | params.auth_data_len = wpabuf_len(resp); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 768 | wpa_s->sme.sae.state = start ? SAE_COMMITTED : SAE_CONFIRMED; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 769 | } |
| 770 | #endif /* CONFIG_SAE */ |
| 771 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 772 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
| 773 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
| 774 | os_memcpy(wpa_s->pending_bssid, bss->bssid, ETH_ALEN); |
| 775 | if (bssid_changed) |
| 776 | wpas_notify_bssid_changed(wpa_s); |
| 777 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 778 | old_ssid = wpa_s->current_ssid; |
| 779 | wpa_s->current_ssid = ssid; |
| 780 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
| 781 | wpa_supplicant_initiate_eapol(wpa_s); |
| 782 | |
| 783 | #ifdef CONFIG_FILS |
| 784 | /* TODO: FILS operations can in some cases be done between different |
| 785 | * network_ctx (i.e., same credentials can be used with multiple |
| 786 | * networks). */ |
| 787 | if (params.auth_alg == WPA_AUTH_ALG_OPEN && |
| 788 | wpa_key_mgmt_fils(ssid->key_mgmt)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 789 | const u8 *indic; |
| 790 | u16 fils_info; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 791 | const u8 *realm, *username, *rrk; |
| 792 | size_t realm_len, username_len, rrk_len; |
| 793 | u16 next_seq_num; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 794 | |
| 795 | /* |
| 796 | * Check FILS Indication element (FILS Information field) bits |
| 797 | * indicating supported authentication algorithms against local |
| 798 | * configuration (ssid->fils_dh_group). Try to use FILS |
| 799 | * authentication only if the AP supports the combination in the |
| 800 | * network profile. */ |
| 801 | indic = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION); |
| 802 | if (!indic || indic[1] < 2) { |
| 803 | wpa_printf(MSG_DEBUG, "SME: " MACSTR |
| 804 | " does not include FILS Indication element - cannot use FILS authentication with it", |
| 805 | MAC2STR(bss->bssid)); |
| 806 | goto no_fils; |
| 807 | } |
| 808 | |
| 809 | fils_info = WPA_GET_LE16(indic + 2); |
| 810 | if (ssid->fils_dh_group == 0 && !(fils_info & BIT(9))) { |
| 811 | wpa_printf(MSG_DEBUG, "SME: " MACSTR |
| 812 | " does not support FILS SK without PFS - cannot use FILS authentication with it", |
| 813 | MAC2STR(bss->bssid)); |
| 814 | goto no_fils; |
| 815 | } |
| 816 | if (ssid->fils_dh_group != 0 && !(fils_info & BIT(10))) { |
| 817 | wpa_printf(MSG_DEBUG, "SME: " MACSTR |
| 818 | " does not support FILS SK with PFS - cannot use FILS authentication with it", |
| 819 | MAC2STR(bss->bssid)); |
| 820 | goto no_fils; |
| 821 | } |
| 822 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 823 | if (wpa_s->last_con_fail_realm && |
| 824 | eapol_sm_get_erp_info(wpa_s->eapol, &ssid->eap, |
| 825 | &username, &username_len, |
| 826 | &realm, &realm_len, &next_seq_num, |
| 827 | &rrk, &rrk_len) == 0 && |
| 828 | realm && realm_len == wpa_s->last_con_fail_realm_len && |
| 829 | os_memcmp(realm, wpa_s->last_con_fail_realm, |
| 830 | realm_len) == 0) { |
| 831 | wpa_printf(MSG_DEBUG, |
| 832 | "SME: FILS authentication for this realm failed last time - try to regenerate ERP key hierarchy"); |
| 833 | goto no_fils; |
| 834 | } |
| 835 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 836 | if (pmksa_cache_set_current(wpa_s->wpa, NULL, bss->bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 837 | ssid, 0, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 838 | wpa_bss_get_fils_cache_id(bss), |
| 839 | 0) == 0) |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 840 | wpa_printf(MSG_DEBUG, |
| 841 | "SME: Try to use FILS with PMKSA caching"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 842 | resp = fils_build_auth(wpa_s->wpa, ssid->fils_dh_group, md); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 843 | if (resp) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 844 | int auth_alg; |
| 845 | |
| 846 | if (ssid->fils_dh_group) |
| 847 | wpa_printf(MSG_DEBUG, |
| 848 | "SME: Try to use FILS SK authentication with PFS (DH Group %u)", |
| 849 | ssid->fils_dh_group); |
| 850 | else |
| 851 | wpa_printf(MSG_DEBUG, |
| 852 | "SME: Try to use FILS SK authentication without PFS"); |
| 853 | auth_alg = ssid->fils_dh_group ? |
| 854 | WPA_AUTH_ALG_FILS_SK_PFS : WPA_AUTH_ALG_FILS; |
| 855 | params.auth_alg = auth_alg; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 856 | params.auth_data = wpabuf_head(resp); |
| 857 | params.auth_data_len = wpabuf_len(resp); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 858 | wpa_s->sme.auth_alg = auth_alg; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 859 | } |
| 860 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 861 | no_fils: |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 862 | #endif /* CONFIG_FILS */ |
| 863 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 864 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 865 | wpa_supplicant_cancel_scan(wpa_s); |
| 866 | |
| 867 | wpa_msg(wpa_s, MSG_INFO, "SME: Trying to authenticate with " MACSTR |
| 868 | " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid), |
| 869 | wpa_ssid_txt(params.ssid, params.ssid_len), params.freq); |
| 870 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 871 | eapol_sm_notify_portValid(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 872 | wpa_clear_keys(wpa_s, bss->bssid); |
| 873 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 874 | if (old_ssid != wpa_s->current_ssid) |
| 875 | wpas_notify_network_changed(wpa_s); |
| 876 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 877 | #ifdef CONFIG_HS20 |
| 878 | hs20_configure_frame_filters(wpa_s); |
| 879 | #endif /* CONFIG_HS20 */ |
| 880 | |
Dmitry Shmidt | f9bdef9 | 2014-04-25 10:46:36 -0700 | [diff] [blame] | 881 | #ifdef CONFIG_P2P |
| 882 | /* |
| 883 | * If multi-channel concurrency is not supported, check for any |
| 884 | * frequency conflict. In case of any frequency conflict, remove the |
| 885 | * least prioritized connection. |
| 886 | */ |
| 887 | if (wpa_s->num_multichan_concurrent < 2) { |
| 888 | int freq, num; |
| 889 | num = get_shared_radio_freqs(wpa_s, &freq, 1); |
| 890 | if (num > 0 && freq > 0 && freq != params.freq) { |
| 891 | wpa_printf(MSG_DEBUG, |
| 892 | "Conflicting frequency found (%d != %d)", |
| 893 | freq, params.freq); |
| 894 | if (wpas_p2p_handle_frequency_conflicts(wpa_s, |
| 895 | params.freq, |
| 896 | ssid) < 0) { |
| 897 | wpas_connection_failed(wpa_s, bss->bssid); |
| 898 | wpa_supplicant_mark_disassoc(wpa_s); |
| 899 | wpabuf_free(resp); |
| 900 | wpas_connect_work_done(wpa_s); |
| 901 | return; |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | #endif /* CONFIG_P2P */ |
| 906 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 907 | if (skip_auth) { |
| 908 | wpa_msg(wpa_s, MSG_DEBUG, |
| 909 | "SME: Skip authentication step on reassoc-to-same-BSS"); |
| 910 | wpabuf_free(resp); |
| 911 | sme_associate(wpa_s, ssid->mode, bss->bssid, WLAN_AUTH_OPEN); |
| 912 | return; |
| 913 | } |
| 914 | |
| 915 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 916 | wpa_s->sme.auth_alg = params.auth_alg; |
| 917 | if (wpa_drv_authenticate(wpa_s, ¶ms) < 0) { |
| 918 | wpa_msg(wpa_s, MSG_INFO, "SME: Authentication request to the " |
| 919 | "driver failed"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 920 | wpas_connection_failed(wpa_s, bss->bssid); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 921 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 922 | wpabuf_free(resp); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 923 | wpas_connect_work_done(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 924 | return; |
| 925 | } |
| 926 | |
| 927 | eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s, |
| 928 | NULL); |
| 929 | |
| 930 | /* |
| 931 | * Association will be started based on the authentication event from |
| 932 | * the driver. |
| 933 | */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 934 | |
| 935 | wpabuf_free(resp); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 939 | static void sme_auth_start_cb(struct wpa_radio_work *work, int deinit) |
| 940 | { |
| 941 | struct wpa_connect_work *cwork = work->ctx; |
| 942 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 943 | |
| 944 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 945 | if (work->started) |
| 946 | wpa_s->connect_work = NULL; |
| 947 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 948 | wpas_connect_work_free(cwork); |
| 949 | return; |
| 950 | } |
| 951 | |
| 952 | wpa_s->connect_work = work; |
| 953 | |
Dmitry Shmidt | 2e425d6 | 2014-11-10 11:18:27 -0800 | [diff] [blame] | 954 | if (cwork->bss_removed || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 955 | !wpas_valid_bss_ssid(wpa_s, cwork->bss, cwork->ssid) || |
| 956 | wpas_network_disabled(wpa_s, cwork->ssid)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 957 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: BSS/SSID entry for authentication not valid anymore - drop connection attempt"); |
| 958 | wpas_connect_work_done(wpa_s); |
| 959 | return; |
| 960 | } |
| 961 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 962 | /* Starting new connection, so clear the possibly used WPA IE from the |
| 963 | * previous association. */ |
| 964 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 965 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0); |
| 966 | wpa_s->rsnxe_len = 0; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 967 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 968 | sme_send_authentication(wpa_s, cwork->bss, cwork->ssid, 1); |
| 969 | } |
| 970 | |
| 971 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 972 | void sme_authenticate(struct wpa_supplicant *wpa_s, |
| 973 | struct wpa_bss *bss, struct wpa_ssid *ssid) |
| 974 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 975 | struct wpa_connect_work *cwork; |
| 976 | |
| 977 | if (bss == NULL || ssid == NULL) |
| 978 | return; |
| 979 | if (wpa_s->connect_work) { |
| 980 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reject sme_authenticate() call since connect_work exist"); |
| 981 | return; |
| 982 | } |
| 983 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 984 | if (radio_work_pending(wpa_s, "sme-connect")) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 985 | /* |
| 986 | * The previous sme-connect work might no longer be valid due to |
| 987 | * the fact that the BSS list was updated. In addition, it makes |
| 988 | * sense to adhere to the 'newer' decision. |
| 989 | */ |
| 990 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 991 | "SME: Remove previous pending sme-connect"); |
| 992 | radio_remove_works(wpa_s, "sme-connect", 0); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 993 | } |
| 994 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 995 | wpas_abort_ongoing_scan(wpa_s); |
| 996 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 997 | cwork = os_zalloc(sizeof(*cwork)); |
| 998 | if (cwork == NULL) |
| 999 | return; |
| 1000 | cwork->bss = bss; |
| 1001 | cwork->ssid = ssid; |
| 1002 | cwork->sme = 1; |
| 1003 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1004 | #ifdef CONFIG_SAE |
| 1005 | wpa_s->sme.sae.state = SAE_NOTHING; |
| 1006 | wpa_s->sme.sae.send_confirm = 0; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1007 | wpa_s->sme.sae_group_index = 0; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1008 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1009 | |
| 1010 | if (radio_add_work(wpa_s, bss->freq, "sme-connect", 1, |
| 1011 | sme_auth_start_cb, cwork) < 0) |
| 1012 | wpas_connect_work_free(cwork); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | #ifdef CONFIG_SAE |
| 1017 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1018 | static int sme_external_auth_build_buf(struct wpabuf *buf, |
| 1019 | struct wpabuf *params, |
| 1020 | const u8 *sa, const u8 *da, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1021 | u16 auth_transaction, u16 seq_num, |
| 1022 | u16 status_code) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1023 | { |
| 1024 | struct ieee80211_mgmt *resp; |
| 1025 | |
| 1026 | resp = wpabuf_put(buf, offsetof(struct ieee80211_mgmt, |
| 1027 | u.auth.variable)); |
| 1028 | |
| 1029 | resp->frame_control = host_to_le16((WLAN_FC_TYPE_MGMT << 2) | |
| 1030 | (WLAN_FC_STYPE_AUTH << 4)); |
| 1031 | os_memcpy(resp->da, da, ETH_ALEN); |
| 1032 | os_memcpy(resp->sa, sa, ETH_ALEN); |
| 1033 | os_memcpy(resp->bssid, da, ETH_ALEN); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1034 | resp->u.auth.auth_alg = host_to_le16(WLAN_AUTH_SAE); |
| 1035 | resp->seq_ctrl = host_to_le16(seq_num << 4); |
| 1036 | resp->u.auth.auth_transaction = host_to_le16(auth_transaction); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1037 | resp->u.auth.status_code = host_to_le16(status_code); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1038 | if (params) |
| 1039 | wpabuf_put_buf(buf, params); |
| 1040 | |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
| 1044 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1045 | static int sme_external_auth_send_sae_commit(struct wpa_supplicant *wpa_s, |
| 1046 | const u8 *bssid, |
| 1047 | struct wpa_ssid *ssid) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1048 | { |
| 1049 | struct wpabuf *resp, *buf; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1050 | int use_pt; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1051 | bool use_pk; |
| 1052 | u16 status; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1053 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1054 | resp = sme_auth_build_sae_commit(wpa_s, ssid, bssid, 1, 0, &use_pt, |
| 1055 | &use_pk); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1056 | if (!resp) { |
| 1057 | wpa_printf(MSG_DEBUG, "SAE: Failed to build SAE commit"); |
| 1058 | return -1; |
| 1059 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1060 | |
| 1061 | wpa_s->sme.sae.state = SAE_COMMITTED; |
| 1062 | buf = wpabuf_alloc(4 + SAE_COMMIT_MAX_LEN + wpabuf_len(resp)); |
| 1063 | if (!buf) { |
| 1064 | wpabuf_free(resp); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1065 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | wpa_s->sme.seq_num++; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1069 | if (use_pk) |
| 1070 | status = WLAN_STATUS_SAE_PK; |
| 1071 | else if (use_pt) |
| 1072 | status = WLAN_STATUS_SAE_HASH_TO_ELEMENT; |
| 1073 | else |
| 1074 | status = WLAN_STATUS_SUCCESS; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1075 | sme_external_auth_build_buf(buf, resp, wpa_s->own_addr, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1076 | bssid, 1, wpa_s->sme.seq_num, status); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1077 | wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1, 0, 0); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1078 | wpabuf_free(resp); |
| 1079 | wpabuf_free(buf); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1080 | |
| 1081 | return 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | |
| 1085 | static void sme_send_external_auth_status(struct wpa_supplicant *wpa_s, |
| 1086 | u16 status) |
| 1087 | { |
| 1088 | struct external_auth params; |
| 1089 | |
| 1090 | os_memset(¶ms, 0, sizeof(params)); |
| 1091 | params.status = status; |
Hai Shalom | 6690473 | 2019-05-29 11:54:04 -0700 | [diff] [blame] | 1092 | params.ssid = wpa_s->sme.ext_auth_ssid; |
| 1093 | params.ssid_len = wpa_s->sme.ext_auth_ssid_len; |
| 1094 | params.bssid = wpa_s->sme.ext_auth_bssid; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1095 | if (wpa_s->conf->sae_pmkid_in_assoc && status == WLAN_STATUS_SUCCESS) |
| 1096 | params.pmkid = wpa_s->sme.sae.pmkid; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1097 | wpa_drv_send_external_auth_status(wpa_s, ¶ms); |
| 1098 | } |
| 1099 | |
| 1100 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1101 | static int sme_handle_external_auth_start(struct wpa_supplicant *wpa_s, |
| 1102 | union wpa_event_data *data) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1103 | { |
| 1104 | struct wpa_ssid *ssid; |
| 1105 | size_t ssid_str_len = data->external_auth.ssid_len; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 1106 | const u8 *ssid_str = data->external_auth.ssid; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1107 | |
| 1108 | /* Get the SSID conf from the ssid string obtained */ |
| 1109 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1110 | if (!wpas_network_disabled(wpa_s, ssid) && |
| 1111 | ssid_str_len == ssid->ssid_len && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1112 | os_memcmp(ssid_str, ssid->ssid, ssid_str_len) == 0 && |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1113 | (ssid->key_mgmt & (WPA_KEY_MGMT_SAE | WPA_KEY_MGMT_FT_SAE))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1114 | break; |
| 1115 | } |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1116 | if (!ssid || |
| 1117 | sme_external_auth_send_sae_commit(wpa_s, data->external_auth.bssid, |
| 1118 | ssid) < 0) |
| 1119 | return -1; |
| 1120 | |
| 1121 | return 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | |
| 1125 | static void sme_external_auth_send_sae_confirm(struct wpa_supplicant *wpa_s, |
| 1126 | const u8 *da) |
| 1127 | { |
| 1128 | struct wpabuf *resp, *buf; |
| 1129 | |
| 1130 | resp = sme_auth_build_sae_confirm(wpa_s, 1); |
| 1131 | if (!resp) { |
| 1132 | wpa_printf(MSG_DEBUG, "SAE: Confirm message buf alloc failure"); |
| 1133 | return; |
| 1134 | } |
| 1135 | |
| 1136 | wpa_s->sme.sae.state = SAE_CONFIRMED; |
| 1137 | buf = wpabuf_alloc(4 + SAE_CONFIRM_MAX_LEN + wpabuf_len(resp)); |
| 1138 | if (!buf) { |
| 1139 | wpa_printf(MSG_DEBUG, "SAE: Auth Confirm buf alloc failure"); |
| 1140 | wpabuf_free(resp); |
| 1141 | return; |
| 1142 | } |
| 1143 | wpa_s->sme.seq_num++; |
| 1144 | sme_external_auth_build_buf(buf, resp, wpa_s->own_addr, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1145 | da, 2, wpa_s->sme.seq_num, |
| 1146 | WLAN_STATUS_SUCCESS); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1147 | wpa_drv_send_mlme(wpa_s, wpabuf_head(buf), wpabuf_len(buf), 1, 0, 0); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1148 | wpabuf_free(resp); |
| 1149 | wpabuf_free(buf); |
| 1150 | } |
| 1151 | |
| 1152 | |
| 1153 | void sme_external_auth_trigger(struct wpa_supplicant *wpa_s, |
| 1154 | union wpa_event_data *data) |
| 1155 | { |
| 1156 | if (RSN_SELECTOR_GET(&data->external_auth.key_mgmt_suite) != |
| 1157 | RSN_AUTH_KEY_MGMT_SAE) |
| 1158 | return; |
| 1159 | |
| 1160 | if (data->external_auth.action == EXT_AUTH_START) { |
Hai Shalom | 6690473 | 2019-05-29 11:54:04 -0700 | [diff] [blame] | 1161 | if (!data->external_auth.bssid || !data->external_auth.ssid) |
| 1162 | return; |
| 1163 | os_memcpy(wpa_s->sme.ext_auth_bssid, data->external_auth.bssid, |
| 1164 | ETH_ALEN); |
| 1165 | os_memcpy(wpa_s->sme.ext_auth_ssid, data->external_auth.ssid, |
| 1166 | data->external_auth.ssid_len); |
| 1167 | wpa_s->sme.ext_auth_ssid_len = data->external_auth.ssid_len; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1168 | wpa_s->sme.seq_num = 0; |
| 1169 | wpa_s->sme.sae.state = SAE_NOTHING; |
| 1170 | wpa_s->sme.sae.send_confirm = 0; |
| 1171 | wpa_s->sme.sae_group_index = 0; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1172 | if (sme_handle_external_auth_start(wpa_s, data) < 0) |
| 1173 | sme_send_external_auth_status(wpa_s, |
| 1174 | WLAN_STATUS_UNSPECIFIED_FAILURE); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1175 | } else if (data->external_auth.action == EXT_AUTH_ABORT) { |
| 1176 | /* Report failure to driver for the wrong trigger */ |
| 1177 | sme_send_external_auth_status(wpa_s, |
| 1178 | WLAN_STATUS_UNSPECIFIED_FAILURE); |
| 1179 | } |
| 1180 | } |
| 1181 | |
| 1182 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1183 | static int sme_sae_is_group_enabled(struct wpa_supplicant *wpa_s, int group) |
| 1184 | { |
| 1185 | int *groups = wpa_s->conf->sae_groups; |
| 1186 | int default_groups[] = { 19, 20, 21, 0 }; |
| 1187 | int i; |
| 1188 | |
| 1189 | if (!groups) |
| 1190 | groups = default_groups; |
| 1191 | |
| 1192 | for (i = 0; groups[i] > 0; i++) { |
| 1193 | if (groups[i] == group) |
| 1194 | return 1; |
| 1195 | } |
| 1196 | |
| 1197 | return 0; |
| 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | static int sme_check_sae_rejected_groups(struct wpa_supplicant *wpa_s, |
| 1202 | const struct wpabuf *groups) |
| 1203 | { |
| 1204 | size_t i, count; |
| 1205 | const u8 *pos; |
| 1206 | |
| 1207 | if (!groups) |
| 1208 | return 0; |
| 1209 | |
| 1210 | pos = wpabuf_head(groups); |
| 1211 | count = wpabuf_len(groups) / 2; |
| 1212 | for (i = 0; i < count; i++) { |
| 1213 | int enabled; |
| 1214 | u16 group; |
| 1215 | |
| 1216 | group = WPA_GET_LE16(pos); |
| 1217 | pos += 2; |
| 1218 | enabled = sme_sae_is_group_enabled(wpa_s, group); |
| 1219 | wpa_printf(MSG_DEBUG, "SAE: Rejected group %u is %s", |
| 1220 | group, enabled ? "enabled" : "disabled"); |
| 1221 | if (enabled) |
| 1222 | return 1; |
| 1223 | } |
| 1224 | |
| 1225 | return 0; |
| 1226 | } |
| 1227 | |
| 1228 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1229 | static int sme_sae_auth(struct wpa_supplicant *wpa_s, u16 auth_transaction, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1230 | u16 status_code, const u8 *data, size_t len, |
| 1231 | int external, const u8 *sa) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1232 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1233 | int *groups; |
| 1234 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1235 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SAE authentication transaction %u " |
| 1236 | "status code %u", auth_transaction, status_code); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1237 | |
| 1238 | if (auth_transaction == 1 && |
| 1239 | status_code == WLAN_STATUS_ANTI_CLOGGING_TOKEN_REQ && |
| 1240 | wpa_s->sme.sae.state == SAE_COMMITTED && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1241 | (external || wpa_s->current_bss) && wpa_s->current_ssid) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1242 | int default_groups[] = { 19, 20, 21, 0 }; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1243 | u16 group; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1244 | const u8 *token_pos; |
| 1245 | size_t token_len; |
| 1246 | int h2e = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1247 | |
| 1248 | groups = wpa_s->conf->sae_groups; |
| 1249 | if (!groups || groups[0] <= 0) |
| 1250 | groups = default_groups; |
| 1251 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1252 | wpa_hexdump(MSG_DEBUG, "SME: SAE anti-clogging token request", |
| 1253 | data, len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1254 | if (len < sizeof(le16)) { |
| 1255 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1256 | "SME: Too short SAE anti-clogging token request"); |
| 1257 | return -1; |
| 1258 | } |
| 1259 | group = WPA_GET_LE16(data); |
| 1260 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1261 | "SME: SAE anti-clogging token requested (group %u)", |
| 1262 | group); |
| 1263 | if (sae_group_allowed(&wpa_s->sme.sae, groups, group) != |
| 1264 | WLAN_STATUS_SUCCESS) { |
| 1265 | wpa_dbg(wpa_s, MSG_ERROR, |
| 1266 | "SME: SAE group %u of anti-clogging request is invalid", |
| 1267 | group); |
| 1268 | return -1; |
| 1269 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1270 | wpabuf_free(wpa_s->sme.sae_token); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1271 | token_pos = data + sizeof(le16); |
| 1272 | token_len = len - sizeof(le16); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1273 | h2e = wpa_s->sme.sae.h2e; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1274 | if (h2e) { |
| 1275 | if (token_len < 3) { |
| 1276 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1277 | "SME: Too short SAE anti-clogging token container"); |
| 1278 | return -1; |
| 1279 | } |
| 1280 | if (token_pos[0] != WLAN_EID_EXTENSION || |
| 1281 | token_pos[1] == 0 || |
| 1282 | token_pos[1] > token_len - 2 || |
| 1283 | token_pos[2] != WLAN_EID_EXT_ANTI_CLOGGING_TOKEN) { |
| 1284 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1285 | "SME: Invalid SAE anti-clogging token container header"); |
| 1286 | return -1; |
| 1287 | } |
| 1288 | token_len = token_pos[1] - 1; |
| 1289 | token_pos += 3; |
| 1290 | } |
| 1291 | wpa_s->sme.sae_token = wpabuf_alloc_copy(token_pos, token_len); |
| 1292 | wpa_hexdump_buf(MSG_DEBUG, "SME: Requested anti-clogging token", |
| 1293 | wpa_s->sme.sae_token); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1294 | if (!external) |
| 1295 | sme_send_authentication(wpa_s, wpa_s->current_bss, |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1296 | wpa_s->current_ssid, 2); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1297 | else |
| 1298 | sme_external_auth_send_sae_commit( |
Hai Shalom | 6690473 | 2019-05-29 11:54:04 -0700 | [diff] [blame] | 1299 | wpa_s, wpa_s->sme.ext_auth_bssid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1300 | wpa_s->current_ssid); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | if (auth_transaction == 1 && |
| 1305 | status_code == WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && |
| 1306 | wpa_s->sme.sae.state == SAE_COMMITTED && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1307 | (external || wpa_s->current_bss) && wpa_s->current_ssid) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1308 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SAE group not supported"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1309 | int_array_add_unique(&wpa_s->sme.sae_rejected_groups, |
| 1310 | wpa_s->sme.sae.group); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1311 | wpa_s->sme.sae_group_index++; |
| 1312 | if (sme_set_sae_group(wpa_s) < 0) |
| 1313 | return -1; /* no other groups enabled */ |
| 1314 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Try next enabled SAE group"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1315 | if (!external) |
| 1316 | sme_send_authentication(wpa_s, wpa_s->current_bss, |
| 1317 | wpa_s->current_ssid, 1); |
| 1318 | else |
| 1319 | sme_external_auth_send_sae_commit( |
Hai Shalom | 6690473 | 2019-05-29 11:54:04 -0700 | [diff] [blame] | 1320 | wpa_s, wpa_s->sme.ext_auth_bssid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1321 | wpa_s->current_ssid); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1322 | return 0; |
| 1323 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1324 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1325 | if (auth_transaction == 1 && |
| 1326 | status_code == WLAN_STATUS_UNKNOWN_PASSWORD_IDENTIFIER) { |
| 1327 | const u8 *bssid = sa ? sa : wpa_s->pending_bssid; |
| 1328 | |
| 1329 | wpa_msg(wpa_s, MSG_INFO, |
| 1330 | WPA_EVENT_SAE_UNKNOWN_PASSWORD_IDENTIFIER MACSTR, |
| 1331 | MAC2STR(bssid)); |
| 1332 | return -1; |
| 1333 | } |
| 1334 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1335 | if (status_code != WLAN_STATUS_SUCCESS && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1336 | status_code != WLAN_STATUS_SAE_HASH_TO_ELEMENT && |
| 1337 | status_code != WLAN_STATUS_SAE_PK) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1338 | return -1; |
| 1339 | |
| 1340 | if (auth_transaction == 1) { |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1341 | u16 res; |
| 1342 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1343 | groups = wpa_s->conf->sae_groups; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1344 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1345 | wpa_dbg(wpa_s, MSG_DEBUG, "SME SAE commit"); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1346 | if ((!external && wpa_s->current_bss == NULL) || |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1347 | wpa_s->current_ssid == NULL) |
| 1348 | return -1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1349 | if (wpa_s->sme.sae.state != SAE_COMMITTED) { |
| 1350 | wpa_printf(MSG_DEBUG, |
| 1351 | "SAE: Ignore commit message while waiting for confirm"); |
| 1352 | return 0; |
| 1353 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1354 | if (wpa_s->sme.sae.h2e && status_code == WLAN_STATUS_SUCCESS) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1355 | wpa_printf(MSG_DEBUG, |
| 1356 | "SAE: Unexpected use of status code 0 in SAE commit when H2E was expected"); |
| 1357 | return -1; |
| 1358 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1359 | if ((!wpa_s->sme.sae.h2e || wpa_s->sme.sae.pk) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1360 | status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT) { |
| 1361 | wpa_printf(MSG_DEBUG, |
| 1362 | "SAE: Unexpected use of status code for H2E in SAE commit when H2E was not expected"); |
| 1363 | return -1; |
| 1364 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1365 | if (!wpa_s->sme.sae.pk && |
| 1366 | status_code == WLAN_STATUS_SAE_PK) { |
| 1367 | wpa_printf(MSG_DEBUG, |
| 1368 | "SAE: Unexpected use of status code for PK in SAE commit when PK was not expected"); |
| 1369 | return -1; |
| 1370 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1371 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1372 | if (groups && groups[0] <= 0) |
| 1373 | groups = NULL; |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1374 | res = sae_parse_commit(&wpa_s->sme.sae, data, len, NULL, NULL, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1375 | groups, status_code == |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1376 | WLAN_STATUS_SAE_HASH_TO_ELEMENT || |
| 1377 | status_code == WLAN_STATUS_SAE_PK); |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1378 | if (res == SAE_SILENTLY_DISCARD) { |
| 1379 | wpa_printf(MSG_DEBUG, |
| 1380 | "SAE: Drop commit message due to reflection attack"); |
| 1381 | return 0; |
| 1382 | } |
| 1383 | if (res != WLAN_STATUS_SUCCESS) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1384 | return -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1385 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1386 | if (wpa_s->sme.sae.tmp && |
| 1387 | sme_check_sae_rejected_groups( |
| 1388 | wpa_s, |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1389 | wpa_s->sme.sae.tmp->peer_rejected_groups)) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1390 | return -1; |
| 1391 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1392 | if (sae_process_commit(&wpa_s->sme.sae) < 0) { |
| 1393 | wpa_printf(MSG_DEBUG, "SAE: Failed to process peer " |
| 1394 | "commit"); |
| 1395 | return -1; |
| 1396 | } |
| 1397 | |
| 1398 | wpabuf_free(wpa_s->sme.sae_token); |
| 1399 | wpa_s->sme.sae_token = NULL; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1400 | if (!external) |
| 1401 | sme_send_authentication(wpa_s, wpa_s->current_bss, |
| 1402 | wpa_s->current_ssid, 0); |
| 1403 | else |
| 1404 | sme_external_auth_send_sae_confirm(wpa_s, sa); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1405 | return 0; |
| 1406 | } else if (auth_transaction == 2) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1407 | if (status_code != WLAN_STATUS_SUCCESS) |
| 1408 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1409 | wpa_dbg(wpa_s, MSG_DEBUG, "SME SAE confirm"); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1410 | if (wpa_s->sme.sae.state != SAE_CONFIRMED) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1411 | return -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1412 | if (sae_check_confirm(&wpa_s->sme.sae, data, len) < 0) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1413 | return -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1414 | wpa_s->sme.sae.state = SAE_ACCEPTED; |
| 1415 | sae_clear_temp_data(&wpa_s->sme.sae); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1416 | |
| 1417 | if (external) { |
| 1418 | /* Report success to driver */ |
| 1419 | sme_send_external_auth_status(wpa_s, |
| 1420 | WLAN_STATUS_SUCCESS); |
| 1421 | } |
| 1422 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1423 | return 1; |
| 1424 | } |
| 1425 | |
| 1426 | return -1; |
| 1427 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1428 | |
| 1429 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1430 | static int sme_sae_set_pmk(struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 1431 | { |
| 1432 | wpa_printf(MSG_DEBUG, |
| 1433 | "SME: SAE completed - setting PMK for 4-way handshake"); |
| 1434 | wpa_sm_set_pmk(wpa_s->wpa, wpa_s->sme.sae.pmk, PMK_LEN, |
| 1435 | wpa_s->sme.sae.pmkid, bssid); |
| 1436 | if (wpa_s->conf->sae_pmkid_in_assoc) { |
| 1437 | /* Update the own RSNE contents now that we have set the PMK |
| 1438 | * and added a PMKSA cache entry based on the successfully |
| 1439 | * completed SAE exchange. In practice, this will add the PMKID |
| 1440 | * into RSNE. */ |
| 1441 | if (wpa_s->sme.assoc_req_ie_len + 2 + PMKID_LEN > |
| 1442 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 1443 | wpa_msg(wpa_s, MSG_WARNING, |
| 1444 | "RSN: Not enough room for inserting own PMKID into RSNE"); |
| 1445 | return -1; |
| 1446 | } |
| 1447 | if (wpa_insert_pmkid(wpa_s->sme.assoc_req_ie, |
| 1448 | &wpa_s->sme.assoc_req_ie_len, |
| 1449 | wpa_s->sme.sae.pmkid) < 0) |
| 1450 | return -1; |
| 1451 | wpa_hexdump(MSG_DEBUG, |
| 1452 | "SME: Updated Association Request IEs", |
| 1453 | wpa_s->sme.assoc_req_ie, |
| 1454 | wpa_s->sme.assoc_req_ie_len); |
| 1455 | } |
| 1456 | |
| 1457 | return 0; |
| 1458 | } |
| 1459 | |
| 1460 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1461 | void sme_external_auth_mgmt_rx(struct wpa_supplicant *wpa_s, |
| 1462 | const u8 *auth_frame, size_t len) |
| 1463 | { |
| 1464 | const struct ieee80211_mgmt *header; |
| 1465 | size_t auth_length; |
| 1466 | |
| 1467 | header = (const struct ieee80211_mgmt *) auth_frame; |
| 1468 | auth_length = IEEE80211_HDRLEN + sizeof(header->u.auth); |
| 1469 | |
| 1470 | if (len < auth_length) { |
| 1471 | /* Notify failure to the driver */ |
| 1472 | sme_send_external_auth_status(wpa_s, |
| 1473 | WLAN_STATUS_UNSPECIFIED_FAILURE); |
| 1474 | return; |
| 1475 | } |
| 1476 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1477 | if (le_to_host16(header->u.auth.auth_alg) == WLAN_AUTH_SAE) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1478 | int res; |
| 1479 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1480 | res = sme_sae_auth( |
| 1481 | wpa_s, le_to_host16(header->u.auth.auth_transaction), |
| 1482 | le_to_host16(header->u.auth.status_code), |
| 1483 | header->u.auth.variable, |
| 1484 | len - auth_length, 1, header->sa); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1485 | if (res < 0) { |
| 1486 | /* Notify failure to the driver */ |
| 1487 | sme_send_external_auth_status( |
| 1488 | wpa_s, WLAN_STATUS_UNSPECIFIED_FAILURE); |
| 1489 | return; |
| 1490 | } |
| 1491 | if (res != 1) |
| 1492 | return; |
| 1493 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1494 | if (sme_sae_set_pmk(wpa_s, wpa_s->sme.ext_auth_bssid) < 0) |
| 1495 | return; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1496 | } |
| 1497 | } |
| 1498 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1499 | #endif /* CONFIG_SAE */ |
| 1500 | |
| 1501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1502 | void sme_event_auth(struct wpa_supplicant *wpa_s, union wpa_event_data *data) |
| 1503 | { |
| 1504 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 1505 | |
| 1506 | if (ssid == NULL) { |
| 1507 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event " |
| 1508 | "when network is not selected"); |
| 1509 | return; |
| 1510 | } |
| 1511 | |
| 1512 | if (wpa_s->wpa_state != WPA_AUTHENTICATING) { |
| 1513 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication event " |
| 1514 | "when not in authenticating state"); |
| 1515 | return; |
| 1516 | } |
| 1517 | |
| 1518 | if (os_memcmp(wpa_s->pending_bssid, data->auth.peer, ETH_ALEN) != 0) { |
| 1519 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Ignore authentication with " |
| 1520 | "unexpected peer " MACSTR, |
| 1521 | MAC2STR(data->auth.peer)); |
| 1522 | return; |
| 1523 | } |
| 1524 | |
| 1525 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication response: peer=" MACSTR |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1526 | " auth_type=%d auth_transaction=%d status_code=%d", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1527 | MAC2STR(data->auth.peer), data->auth.auth_type, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1528 | data->auth.auth_transaction, data->auth.status_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1529 | wpa_hexdump(MSG_MSGDUMP, "SME: Authentication response IEs", |
| 1530 | data->auth.ies, data->auth.ies_len); |
| 1531 | |
| 1532 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); |
| 1533 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1534 | #ifdef CONFIG_SAE |
| 1535 | if (data->auth.auth_type == WLAN_AUTH_SAE) { |
| 1536 | int res; |
| 1537 | res = sme_sae_auth(wpa_s, data->auth.auth_transaction, |
| 1538 | data->auth.status_code, data->auth.ies, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1539 | data->auth.ies_len, 0, NULL); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1540 | if (res < 0) { |
| 1541 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
| 1542 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 1543 | |
| 1544 | } |
| 1545 | if (res != 1) |
| 1546 | return; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1547 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1548 | if (sme_sae_set_pmk(wpa_s, wpa_s->pending_bssid) < 0) |
| 1549 | return; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1550 | } |
| 1551 | #endif /* CONFIG_SAE */ |
| 1552 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1553 | if (data->auth.status_code != WLAN_STATUS_SUCCESS) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1554 | char *ie_txt = NULL; |
| 1555 | |
| 1556 | if (data->auth.ies && data->auth.ies_len) { |
| 1557 | size_t buflen = 2 * data->auth.ies_len + 1; |
| 1558 | ie_txt = os_malloc(buflen); |
| 1559 | if (ie_txt) { |
| 1560 | wpa_snprintf_hex(ie_txt, buflen, data->auth.ies, |
| 1561 | data->auth.ies_len); |
| 1562 | } |
| 1563 | } |
| 1564 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AUTH_REJECT MACSTR |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1565 | " auth_type=%u auth_transaction=%u status_code=%u%s%s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1566 | MAC2STR(data->auth.peer), data->auth.auth_type, |
| 1567 | data->auth.auth_transaction, data->auth.status_code, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1568 | ie_txt ? " ie=" : "", |
| 1569 | ie_txt ? ie_txt : ""); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1570 | os_free(ie_txt); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1571 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 1572 | #ifdef CONFIG_FILS |
| 1573 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS || |
| 1574 | wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) |
| 1575 | fils_connection_failure(wpa_s); |
| 1576 | #endif /* CONFIG_FILS */ |
| 1577 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1578 | if (data->auth.status_code != |
| 1579 | WLAN_STATUS_NOT_SUPPORTED_AUTH_ALG || |
| 1580 | wpa_s->sme.auth_alg == data->auth.auth_type || |
| 1581 | wpa_s->current_ssid->auth_alg == WPA_AUTH_ALG_LEAP) { |
| 1582 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1583 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1584 | return; |
| 1585 | } |
| 1586 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 1587 | wpas_connect_work_done(wpa_s); |
| 1588 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1589 | switch (data->auth.auth_type) { |
| 1590 | case WLAN_AUTH_OPEN: |
| 1591 | wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_SHARED; |
| 1592 | |
| 1593 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying SHARED auth"); |
| 1594 | wpa_supplicant_associate(wpa_s, wpa_s->current_bss, |
| 1595 | wpa_s->current_ssid); |
| 1596 | return; |
| 1597 | |
| 1598 | case WLAN_AUTH_SHARED_KEY: |
| 1599 | wpa_s->current_ssid->auth_alg = WPA_AUTH_ALG_LEAP; |
| 1600 | |
| 1601 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Trying LEAP auth"); |
| 1602 | wpa_supplicant_associate(wpa_s, wpa_s->current_bss, |
| 1603 | wpa_s->current_ssid); |
| 1604 | return; |
| 1605 | |
| 1606 | default: |
| 1607 | return; |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | #ifdef CONFIG_IEEE80211R |
| 1612 | if (data->auth.auth_type == WLAN_AUTH_FT) { |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1613 | const u8 *ric_ies = NULL; |
| 1614 | size_t ric_ies_len = 0; |
| 1615 | |
| 1616 | if (wpa_s->ric_ies) { |
| 1617 | ric_ies = wpabuf_head(wpa_s->ric_ies); |
| 1618 | ric_ies_len = wpabuf_len(wpa_s->ric_ies); |
| 1619 | } |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1620 | if (wpa_ft_process_response(wpa_s->wpa, data->auth.ies, |
| 1621 | data->auth.ies_len, 0, |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1622 | data->auth.peer, |
| 1623 | ric_ies, ric_ies_len) < 0) { |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 1624 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1625 | "SME: FT Authentication response processing failed"); |
| 1626 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" |
| 1627 | MACSTR |
| 1628 | " reason=%d locally_generated=1", |
| 1629 | MAC2STR(wpa_s->pending_bssid), |
| 1630 | WLAN_REASON_DEAUTH_LEAVING); |
| 1631 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
| 1632 | wpa_supplicant_mark_disassoc(wpa_s); |
| 1633 | return; |
| 1634 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1635 | } |
| 1636 | #endif /* CONFIG_IEEE80211R */ |
| 1637 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1638 | #ifdef CONFIG_FILS |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1639 | if (data->auth.auth_type == WLAN_AUTH_FILS_SK || |
| 1640 | data->auth.auth_type == WLAN_AUTH_FILS_SK_PFS) { |
| 1641 | u16 expect_auth_type; |
| 1642 | |
| 1643 | expect_auth_type = wpa_s->sme.auth_alg == |
| 1644 | WPA_AUTH_ALG_FILS_SK_PFS ? WLAN_AUTH_FILS_SK_PFS : |
| 1645 | WLAN_AUTH_FILS_SK; |
| 1646 | if (data->auth.auth_type != expect_auth_type) { |
| 1647 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1648 | "SME: FILS Authentication response used different auth alg (%u; expected %u)", |
| 1649 | data->auth.auth_type, expect_auth_type); |
| 1650 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" |
| 1651 | MACSTR |
| 1652 | " reason=%d locally_generated=1", |
| 1653 | MAC2STR(wpa_s->pending_bssid), |
| 1654 | WLAN_REASON_DEAUTH_LEAVING); |
| 1655 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
| 1656 | wpa_supplicant_mark_disassoc(wpa_s); |
| 1657 | return; |
| 1658 | } |
| 1659 | |
| 1660 | if (fils_process_auth(wpa_s->wpa, wpa_s->pending_bssid, |
| 1661 | data->auth.ies, data->auth.ies_len) < 0) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1662 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1663 | "SME: FILS Authentication response processing failed"); |
| 1664 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" |
| 1665 | MACSTR |
| 1666 | " reason=%d locally_generated=1", |
| 1667 | MAC2STR(wpa_s->pending_bssid), |
| 1668 | WLAN_REASON_DEAUTH_LEAVING); |
| 1669 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
| 1670 | wpa_supplicant_mark_disassoc(wpa_s); |
| 1671 | return; |
| 1672 | } |
| 1673 | } |
| 1674 | #endif /* CONFIG_FILS */ |
| 1675 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1676 | sme_associate(wpa_s, ssid->mode, data->auth.peer, |
| 1677 | data->auth.auth_type); |
| 1678 | } |
| 1679 | |
| 1680 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1681 | #ifdef CONFIG_IEEE80211R |
| 1682 | static void remove_ie(u8 *buf, size_t *len, u8 eid) |
| 1683 | { |
| 1684 | u8 *pos, *next, *end; |
| 1685 | |
| 1686 | pos = (u8 *) get_ie(buf, *len, eid); |
| 1687 | if (pos) { |
| 1688 | next = pos + 2 + pos[1]; |
| 1689 | end = buf + *len; |
| 1690 | *len -= 2 + pos[1]; |
| 1691 | os_memmove(pos, next, end - next); |
| 1692 | } |
| 1693 | } |
| 1694 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1695 | |
| 1696 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1697 | void sme_associate(struct wpa_supplicant *wpa_s, enum wpas_mode mode, |
| 1698 | const u8 *bssid, u16 auth_type) |
| 1699 | { |
| 1700 | struct wpa_driver_associate_params params; |
| 1701 | struct ieee802_11_elems elems; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1702 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1703 | #ifdef CONFIG_FILS |
| 1704 | u8 nonces[2 * FILS_NONCE_LEN]; |
| 1705 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1706 | #ifdef CONFIG_HT_OVERRIDES |
| 1707 | struct ieee80211_ht_capabilities htcaps; |
| 1708 | struct ieee80211_ht_capabilities htcaps_mask; |
| 1709 | #endif /* CONFIG_HT_OVERRIDES */ |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1710 | #ifdef CONFIG_VHT_OVERRIDES |
| 1711 | struct ieee80211_vht_capabilities vhtcaps; |
| 1712 | struct ieee80211_vht_capabilities vhtcaps_mask; |
| 1713 | #endif /* CONFIG_VHT_OVERRIDES */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1714 | |
| 1715 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1716 | |
| 1717 | #ifdef CONFIG_FILS |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1718 | if (auth_type == WLAN_AUTH_FILS_SK || |
| 1719 | auth_type == WLAN_AUTH_FILS_SK_PFS) { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1720 | struct wpabuf *buf; |
| 1721 | const u8 *snonce, *anonce; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1722 | const unsigned int max_hlp = 20; |
| 1723 | struct wpabuf *hlp[max_hlp]; |
| 1724 | unsigned int i, num_hlp = 0; |
| 1725 | struct fils_hlp_req *req; |
| 1726 | |
| 1727 | dl_list_for_each(req, &wpa_s->fils_hlp_req, struct fils_hlp_req, |
| 1728 | list) { |
| 1729 | hlp[num_hlp] = wpabuf_alloc(2 * ETH_ALEN + 6 + |
| 1730 | wpabuf_len(req->pkt)); |
| 1731 | if (!hlp[num_hlp]) |
| 1732 | break; |
| 1733 | wpabuf_put_data(hlp[num_hlp], req->dst, ETH_ALEN); |
| 1734 | wpabuf_put_data(hlp[num_hlp], wpa_s->own_addr, |
| 1735 | ETH_ALEN); |
| 1736 | wpabuf_put_data(hlp[num_hlp], |
| 1737 | "\xaa\xaa\x03\x00\x00\x00", 6); |
| 1738 | wpabuf_put_buf(hlp[num_hlp], req->pkt); |
| 1739 | num_hlp++; |
| 1740 | if (num_hlp >= max_hlp) |
| 1741 | break; |
| 1742 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1743 | |
| 1744 | buf = fils_build_assoc_req(wpa_s->wpa, ¶ms.fils_kek, |
| 1745 | ¶ms.fils_kek_len, &snonce, |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 1746 | &anonce, |
| 1747 | (const struct wpabuf **) hlp, |
| 1748 | num_hlp); |
| 1749 | for (i = 0; i < num_hlp; i++) |
| 1750 | wpabuf_free(hlp[i]); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1751 | if (!buf) |
| 1752 | return; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1753 | wpa_hexdump(MSG_DEBUG, "FILS: assoc_req before FILS elements", |
| 1754 | wpa_s->sme.assoc_req_ie, |
| 1755 | wpa_s->sme.assoc_req_ie_len); |
| 1756 | #ifdef CONFIG_IEEE80211R |
| 1757 | if (wpa_key_mgmt_ft(wpa_s->key_mgmt)) { |
| 1758 | /* Remove RSNE and MDE to allow them to be overridden |
| 1759 | * with FILS+FT specific values from |
| 1760 | * fils_build_assoc_req(). */ |
| 1761 | remove_ie(wpa_s->sme.assoc_req_ie, |
| 1762 | &wpa_s->sme.assoc_req_ie_len, |
| 1763 | WLAN_EID_RSN); |
| 1764 | wpa_hexdump(MSG_DEBUG, |
| 1765 | "FILS: assoc_req after RSNE removal", |
| 1766 | wpa_s->sme.assoc_req_ie, |
| 1767 | wpa_s->sme.assoc_req_ie_len); |
| 1768 | remove_ie(wpa_s->sme.assoc_req_ie, |
| 1769 | &wpa_s->sme.assoc_req_ie_len, |
| 1770 | WLAN_EID_MOBILITY_DOMAIN); |
| 1771 | wpa_hexdump(MSG_DEBUG, |
| 1772 | "FILS: assoc_req after MDE removal", |
| 1773 | wpa_s->sme.assoc_req_ie, |
| 1774 | wpa_s->sme.assoc_req_ie_len); |
| 1775 | } |
| 1776 | #endif /* CONFIG_IEEE80211R */ |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1777 | /* TODO: Make wpa_s->sme.assoc_req_ie use dynamic allocation */ |
| 1778 | if (wpa_s->sme.assoc_req_ie_len + wpabuf_len(buf) > |
| 1779 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 1780 | wpa_printf(MSG_ERROR, |
| 1781 | "FILS: Not enough buffer room for own AssocReq elements"); |
| 1782 | wpabuf_free(buf); |
| 1783 | return; |
| 1784 | } |
| 1785 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 1786 | wpabuf_head(buf), wpabuf_len(buf)); |
| 1787 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(buf); |
| 1788 | wpabuf_free(buf); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1789 | wpa_hexdump(MSG_DEBUG, "FILS: assoc_req after FILS elements", |
| 1790 | wpa_s->sme.assoc_req_ie, |
| 1791 | wpa_s->sme.assoc_req_ie_len); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1792 | |
| 1793 | os_memcpy(nonces, snonce, FILS_NONCE_LEN); |
| 1794 | os_memcpy(nonces + FILS_NONCE_LEN, anonce, FILS_NONCE_LEN); |
| 1795 | params.fils_nonces = nonces; |
| 1796 | params.fils_nonces_len = sizeof(nonces); |
| 1797 | } |
| 1798 | #endif /* CONFIG_FILS */ |
| 1799 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1800 | #ifdef CONFIG_OWE |
| 1801 | #ifdef CONFIG_TESTING_OPTIONS |
| 1802 | if (get_ie_ext(wpa_s->sme.assoc_req_ie, wpa_s->sme.assoc_req_ie_len, |
| 1803 | WLAN_EID_EXT_OWE_DH_PARAM)) { |
| 1804 | wpa_printf(MSG_INFO, "TESTING: Override OWE DH element"); |
| 1805 | } else |
| 1806 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1807 | if (auth_type == WLAN_AUTH_OPEN && |
| 1808 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE) { |
| 1809 | struct wpabuf *owe_ie; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1810 | u16 group; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1811 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1812 | if (ssid && ssid->owe_group) { |
| 1813 | group = ssid->owe_group; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1814 | } else if (wpa_s->assoc_status_code == |
| 1815 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1816 | if (wpa_s->last_owe_group == 19) |
| 1817 | group = 20; |
| 1818 | else if (wpa_s->last_owe_group == 20) |
| 1819 | group = 21; |
| 1820 | else |
| 1821 | group = OWE_DH_GROUP; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1822 | } else { |
| 1823 | group = OWE_DH_GROUP; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1824 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1825 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1826 | wpa_s->last_owe_group = group; |
| 1827 | wpa_printf(MSG_DEBUG, "OWE: Try to use group %u", group); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1828 | owe_ie = owe_build_assoc_req(wpa_s->wpa, group); |
| 1829 | if (!owe_ie) { |
| 1830 | wpa_printf(MSG_ERROR, |
| 1831 | "OWE: Failed to build IE for Association Request frame"); |
| 1832 | return; |
| 1833 | } |
| 1834 | if (wpa_s->sme.assoc_req_ie_len + wpabuf_len(owe_ie) > |
| 1835 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 1836 | wpa_printf(MSG_ERROR, |
| 1837 | "OWE: Not enough buffer room for own Association Request frame elements"); |
| 1838 | wpabuf_free(owe_ie); |
| 1839 | return; |
| 1840 | } |
| 1841 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 1842 | wpabuf_head(owe_ie), wpabuf_len(owe_ie)); |
| 1843 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(owe_ie); |
| 1844 | wpabuf_free(owe_ie); |
| 1845 | } |
| 1846 | #endif /* CONFIG_OWE */ |
| 1847 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1848 | #ifdef CONFIG_DPP2 |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1849 | if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && ssid && |
| 1850 | ssid->dpp_netaccesskey && ssid->dpp_pfs != 2 && |
| 1851 | !ssid->dpp_pfs_fallback) { |
| 1852 | struct rsn_pmksa_cache_entry *pmksa; |
| 1853 | |
| 1854 | pmksa = pmksa_cache_get_current(wpa_s->wpa); |
| 1855 | if (!pmksa || !pmksa->dpp_pfs) |
| 1856 | goto pfs_fail; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 1857 | |
| 1858 | dpp_pfs_free(wpa_s->dpp_pfs); |
| 1859 | wpa_s->dpp_pfs = dpp_pfs_init(ssid->dpp_netaccesskey, |
| 1860 | ssid->dpp_netaccesskey_len); |
| 1861 | if (!wpa_s->dpp_pfs) { |
| 1862 | wpa_printf(MSG_DEBUG, "DPP: Could not initialize PFS"); |
| 1863 | /* Try to continue without PFS */ |
| 1864 | goto pfs_fail; |
| 1865 | } |
| 1866 | if (wpa_s->sme.assoc_req_ie_len + |
| 1867 | wpabuf_len(wpa_s->dpp_pfs->ie) > |
| 1868 | sizeof(wpa_s->sme.assoc_req_ie)) { |
| 1869 | wpa_printf(MSG_ERROR, |
| 1870 | "DPP: Not enough buffer room for own Association Request frame elements"); |
| 1871 | dpp_pfs_free(wpa_s->dpp_pfs); |
| 1872 | wpa_s->dpp_pfs = NULL; |
| 1873 | goto pfs_fail; |
| 1874 | } |
| 1875 | os_memcpy(wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 1876 | wpabuf_head(wpa_s->dpp_pfs->ie), |
| 1877 | wpabuf_len(wpa_s->dpp_pfs->ie)); |
| 1878 | wpa_s->sme.assoc_req_ie_len += wpabuf_len(wpa_s->dpp_pfs->ie); |
| 1879 | } |
| 1880 | pfs_fail: |
| 1881 | #endif /* CONFIG_DPP2 */ |
| 1882 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1883 | wpa_s->mscs_setup_done = false; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 1884 | if (wpa_bss_ext_capab(wpa_s->current_bss, WLAN_EXT_CAPAB_MSCS) && |
| 1885 | wpa_s->robust_av.valid_config) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1886 | struct wpabuf *mscs_ie; |
| 1887 | size_t mscs_ie_len, buf_len, *wpa_ie_len, max_ie_len; |
| 1888 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1889 | buf_len = 3 + /* MSCS descriptor IE header */ |
| 1890 | 1 + /* Request type */ |
| 1891 | 2 + /* User priority control */ |
| 1892 | 4 + /* Stream timeout */ |
| 1893 | 3 + /* TCLAS Mask IE header */ |
| 1894 | wpa_s->robust_av.frame_classifier_len; |
| 1895 | mscs_ie = wpabuf_alloc(buf_len); |
| 1896 | if (!mscs_ie) { |
| 1897 | wpa_printf(MSG_INFO, |
| 1898 | "MSCS: Failed to allocate MSCS IE"); |
| 1899 | goto mscs_fail; |
| 1900 | } |
| 1901 | |
| 1902 | wpa_ie_len = &wpa_s->sme.assoc_req_ie_len; |
| 1903 | max_ie_len = sizeof(wpa_s->sme.assoc_req_ie); |
| 1904 | wpas_populate_mscs_descriptor_ie(&wpa_s->robust_av, mscs_ie); |
| 1905 | if ((*wpa_ie_len + wpabuf_len(mscs_ie)) <= max_ie_len) { |
| 1906 | wpa_hexdump_buf(MSG_MSGDUMP, "MSCS IE", mscs_ie); |
| 1907 | mscs_ie_len = wpabuf_len(mscs_ie); |
| 1908 | os_memcpy(wpa_s->sme.assoc_req_ie + *wpa_ie_len, |
| 1909 | wpabuf_head(mscs_ie), mscs_ie_len); |
| 1910 | *wpa_ie_len += mscs_ie_len; |
| 1911 | } |
| 1912 | |
| 1913 | wpabuf_free(mscs_ie); |
| 1914 | } |
| 1915 | mscs_fail: |
| 1916 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1917 | if (ssid && ssid->multi_ap_backhaul_sta) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1918 | size_t multi_ap_ie_len; |
| 1919 | |
| 1920 | multi_ap_ie_len = add_multi_ap_ie( |
| 1921 | wpa_s->sme.assoc_req_ie + wpa_s->sme.assoc_req_ie_len, |
| 1922 | sizeof(wpa_s->sme.assoc_req_ie) - |
| 1923 | wpa_s->sme.assoc_req_ie_len, |
| 1924 | MULTI_AP_BACKHAUL_STA); |
| 1925 | if (multi_ap_ie_len == 0) { |
| 1926 | wpa_printf(MSG_ERROR, |
| 1927 | "Multi-AP: Failed to build Multi-AP IE"); |
| 1928 | return; |
| 1929 | } |
| 1930 | wpa_s->sme.assoc_req_ie_len += multi_ap_ie_len; |
| 1931 | } |
| 1932 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1933 | params.bssid = bssid; |
| 1934 | params.ssid = wpa_s->sme.ssid; |
| 1935 | params.ssid_len = wpa_s->sme.ssid_len; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1936 | params.freq.freq = wpa_s->sme.freq; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1937 | params.bg_scan_period = ssid ? ssid->bg_scan_period : -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1938 | params.wpa_ie = wpa_s->sme.assoc_req_ie_len ? |
| 1939 | wpa_s->sme.assoc_req_ie : NULL; |
| 1940 | params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1941 | wpa_hexdump(MSG_DEBUG, "SME: Association Request IEs", |
| 1942 | params.wpa_ie, params.wpa_ie_len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1943 | params.pairwise_suite = wpa_s->pairwise_cipher; |
| 1944 | params.group_suite = wpa_s->group_cipher; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1945 | params.mgmt_group_suite = wpa_s->mgmt_group_cipher; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1946 | params.key_mgmt_suite = wpa_s->key_mgmt; |
| 1947 | params.wpa_proto = wpa_s->wpa_proto; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1948 | #ifdef CONFIG_HT_OVERRIDES |
| 1949 | os_memset(&htcaps, 0, sizeof(htcaps)); |
| 1950 | os_memset(&htcaps_mask, 0, sizeof(htcaps_mask)); |
| 1951 | params.htcaps = (u8 *) &htcaps; |
| 1952 | params.htcaps_mask = (u8 *) &htcaps_mask; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1953 | wpa_supplicant_apply_ht_overrides(wpa_s, ssid, ¶ms); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1954 | #endif /* CONFIG_HT_OVERRIDES */ |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1955 | #ifdef CONFIG_VHT_OVERRIDES |
| 1956 | os_memset(&vhtcaps, 0, sizeof(vhtcaps)); |
| 1957 | os_memset(&vhtcaps_mask, 0, sizeof(vhtcaps_mask)); |
| 1958 | params.vhtcaps = &vhtcaps; |
| 1959 | params.vhtcaps_mask = &vhtcaps_mask; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1960 | wpa_supplicant_apply_vht_overrides(wpa_s, ssid, ¶ms); |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1961 | #endif /* CONFIG_VHT_OVERRIDES */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1962 | #ifdef CONFIG_HE_OVERRIDES |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 1963 | wpa_supplicant_apply_he_overrides(wpa_s, ssid, ¶ms); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1964 | #endif /* CONFIG_HE_OVERRIDES */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1965 | #ifdef CONFIG_IEEE80211R |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1966 | if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies && |
| 1967 | get_ie(wpa_s->sme.ft_ies, wpa_s->sme.ft_ies_len, |
| 1968 | WLAN_EID_RIC_DATA)) { |
| 1969 | /* There seems to be a pretty inconvenient bug in the Linux |
| 1970 | * kernel IE splitting functionality when RIC is used. For now, |
| 1971 | * skip correct behavior in IE construction here (i.e., drop the |
| 1972 | * additional non-FT-specific IEs) to avoid kernel issues. This |
| 1973 | * is fine since RIC is used only for testing purposes in the |
| 1974 | * current implementation. */ |
| 1975 | wpa_printf(MSG_INFO, |
| 1976 | "SME: Linux kernel workaround - do not try to include additional IEs with RIC"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1977 | params.wpa_ie = wpa_s->sme.ft_ies; |
| 1978 | params.wpa_ie_len = wpa_s->sme.ft_ies_len; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1979 | } else if (auth_type == WLAN_AUTH_FT && wpa_s->sme.ft_ies) { |
| 1980 | const u8 *rm_en, *pos, *end; |
| 1981 | size_t rm_en_len = 0; |
| 1982 | u8 *rm_en_dup = NULL, *wpos; |
| 1983 | |
| 1984 | /* Remove RSNE, MDE, FTE to allow them to be overridden with |
| 1985 | * FT specific values */ |
| 1986 | remove_ie(wpa_s->sme.assoc_req_ie, |
| 1987 | &wpa_s->sme.assoc_req_ie_len, |
| 1988 | WLAN_EID_RSN); |
| 1989 | remove_ie(wpa_s->sme.assoc_req_ie, |
| 1990 | &wpa_s->sme.assoc_req_ie_len, |
| 1991 | WLAN_EID_MOBILITY_DOMAIN); |
| 1992 | remove_ie(wpa_s->sme.assoc_req_ie, |
| 1993 | &wpa_s->sme.assoc_req_ie_len, |
| 1994 | WLAN_EID_FAST_BSS_TRANSITION); |
| 1995 | rm_en = get_ie(wpa_s->sme.assoc_req_ie, |
| 1996 | wpa_s->sme.assoc_req_ie_len, |
| 1997 | WLAN_EID_RRM_ENABLED_CAPABILITIES); |
| 1998 | if (rm_en) { |
| 1999 | /* Need to remove RM Enabled Capabilities element as |
| 2000 | * well temporarily, so that it can be placed between |
| 2001 | * RSNE and MDE. */ |
| 2002 | rm_en_len = 2 + rm_en[1]; |
| 2003 | rm_en_dup = os_memdup(rm_en, rm_en_len); |
| 2004 | remove_ie(wpa_s->sme.assoc_req_ie, |
| 2005 | &wpa_s->sme.assoc_req_ie_len, |
| 2006 | WLAN_EID_RRM_ENABLED_CAPABILITIES); |
| 2007 | } |
| 2008 | wpa_hexdump(MSG_DEBUG, |
| 2009 | "SME: Association Request IEs after FT IE removal", |
| 2010 | wpa_s->sme.assoc_req_ie, |
| 2011 | wpa_s->sme.assoc_req_ie_len); |
| 2012 | if (wpa_s->sme.assoc_req_ie_len + wpa_s->sme.ft_ies_len + |
| 2013 | rm_en_len > sizeof(wpa_s->sme.assoc_req_ie)) { |
| 2014 | wpa_printf(MSG_ERROR, |
| 2015 | "SME: Not enough buffer room for FT IEs in Association Request frame"); |
| 2016 | os_free(rm_en_dup); |
| 2017 | return; |
| 2018 | } |
| 2019 | |
| 2020 | os_memmove(wpa_s->sme.assoc_req_ie + wpa_s->sme.ft_ies_len + |
| 2021 | rm_en_len, |
| 2022 | wpa_s->sme.assoc_req_ie, |
| 2023 | wpa_s->sme.assoc_req_ie_len); |
| 2024 | pos = wpa_s->sme.ft_ies; |
| 2025 | end = pos + wpa_s->sme.ft_ies_len; |
| 2026 | wpos = wpa_s->sme.assoc_req_ie; |
| 2027 | if (*pos == WLAN_EID_RSN) { |
| 2028 | os_memcpy(wpos, pos, 2 + pos[1]); |
| 2029 | wpos += 2 + pos[1]; |
| 2030 | pos += 2 + pos[1]; |
| 2031 | } |
| 2032 | if (rm_en_dup) { |
| 2033 | os_memcpy(wpos, rm_en_dup, rm_en_len); |
| 2034 | wpos += rm_en_len; |
| 2035 | os_free(rm_en_dup); |
| 2036 | } |
| 2037 | os_memcpy(wpos, pos, end - pos); |
| 2038 | wpa_s->sme.assoc_req_ie_len += wpa_s->sme.ft_ies_len + |
| 2039 | rm_en_len; |
| 2040 | params.wpa_ie = wpa_s->sme.assoc_req_ie; |
| 2041 | params.wpa_ie_len = wpa_s->sme.assoc_req_ie_len; |
| 2042 | wpa_hexdump(MSG_DEBUG, |
| 2043 | "SME: Association Request IEs after FT override", |
| 2044 | params.wpa_ie, params.wpa_ie_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2045 | } |
| 2046 | #endif /* CONFIG_IEEE80211R */ |
| 2047 | params.mode = mode; |
| 2048 | params.mgmt_frame_protection = wpa_s->sme.mfp; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2049 | params.rrm_used = wpa_s->rrm.rrm_used; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2050 | if (wpa_s->sme.prev_bssid_set) |
| 2051 | params.prev_bssid = wpa_s->sme.prev_bssid; |
| 2052 | |
| 2053 | wpa_msg(wpa_s, MSG_INFO, "Trying to associate with " MACSTR |
| 2054 | " (SSID='%s' freq=%d MHz)", MAC2STR(params.bssid), |
| 2055 | params.ssid ? wpa_ssid_txt(params.ssid, params.ssid_len) : "", |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2056 | params.freq.freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2057 | |
| 2058 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATING); |
| 2059 | |
| 2060 | if (params.wpa_ie == NULL || |
| 2061 | ieee802_11_parse_elems(params.wpa_ie, params.wpa_ie_len, &elems, 0) |
| 2062 | < 0) { |
| 2063 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Could not parse own IEs?!"); |
| 2064 | os_memset(&elems, 0, sizeof(elems)); |
| 2065 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2066 | if (elems.rsn_ie) { |
| 2067 | params.wpa_proto = WPA_PROTO_RSN; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2068 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.rsn_ie - 2, |
| 2069 | elems.rsn_ie_len + 2); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2070 | } else if (elems.wpa_ie) { |
| 2071 | params.wpa_proto = WPA_PROTO_WPA; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2072 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.wpa_ie - 2, |
| 2073 | elems.wpa_ie_len + 2); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2074 | } else if (elems.osen) { |
| 2075 | params.wpa_proto = WPA_PROTO_OSEN; |
| 2076 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, elems.osen - 2, |
| 2077 | elems.osen_len + 2); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2078 | } else |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2079 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2080 | if (elems.rsnxe) |
| 2081 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, elems.rsnxe - 2, |
| 2082 | elems.rsnxe_len + 2); |
| 2083 | else |
| 2084 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2085 | if (ssid && ssid->p2p_group) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2086 | params.p2p = 1; |
| 2087 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2088 | if (wpa_s->p2pdev->set_sta_uapsd) |
| 2089 | params.uapsd = wpa_s->p2pdev->sta_uapsd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | else |
| 2091 | params.uapsd = -1; |
| 2092 | |
| 2093 | if (wpa_drv_associate(wpa_s, ¶ms) < 0) { |
| 2094 | wpa_msg(wpa_s, MSG_INFO, "SME: Association request to the " |
| 2095 | "driver failed"); |
| 2096 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2097 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2098 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
| 2099 | return; |
| 2100 | } |
| 2101 | |
| 2102 | eloop_register_timeout(SME_ASSOC_TIMEOUT, 0, sme_assoc_timer, wpa_s, |
| 2103 | NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2104 | |
| 2105 | #ifdef CONFIG_TESTING_OPTIONS |
| 2106 | wpabuf_free(wpa_s->last_assoc_req_wpa_ie); |
| 2107 | wpa_s->last_assoc_req_wpa_ie = NULL; |
| 2108 | if (params.wpa_ie) |
| 2109 | wpa_s->last_assoc_req_wpa_ie = |
| 2110 | wpabuf_alloc_copy(params.wpa_ie, params.wpa_ie_len); |
| 2111 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2112 | } |
| 2113 | |
| 2114 | |
| 2115 | int sme_update_ft_ies(struct wpa_supplicant *wpa_s, const u8 *md, |
| 2116 | const u8 *ies, size_t ies_len) |
| 2117 | { |
| 2118 | if (md == NULL || ies == NULL) { |
| 2119 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Remove mobility domain"); |
| 2120 | os_free(wpa_s->sme.ft_ies); |
| 2121 | wpa_s->sme.ft_ies = NULL; |
| 2122 | wpa_s->sme.ft_ies_len = 0; |
| 2123 | wpa_s->sme.ft_used = 0; |
| 2124 | return 0; |
| 2125 | } |
| 2126 | |
| 2127 | os_memcpy(wpa_s->sme.mobility_domain, md, MOBILITY_DOMAIN_ID_LEN); |
| 2128 | wpa_hexdump(MSG_DEBUG, "SME: FT IEs", ies, ies_len); |
| 2129 | os_free(wpa_s->sme.ft_ies); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2130 | wpa_s->sme.ft_ies = os_memdup(ies, ies_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2131 | if (wpa_s->sme.ft_ies == NULL) |
| 2132 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2133 | wpa_s->sme.ft_ies_len = ies_len; |
| 2134 | return 0; |
| 2135 | } |
| 2136 | |
| 2137 | |
| 2138 | static void sme_deauth(struct wpa_supplicant *wpa_s) |
| 2139 | { |
| 2140 | int bssid_changed; |
| 2141 | |
| 2142 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
| 2143 | |
| 2144 | if (wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid, |
| 2145 | WLAN_REASON_DEAUTH_LEAVING) < 0) { |
| 2146 | wpa_msg(wpa_s, MSG_INFO, "SME: Deauth request to the driver " |
| 2147 | "failed"); |
| 2148 | } |
| 2149 | wpa_s->sme.prev_bssid_set = 0; |
| 2150 | |
| 2151 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
| 2152 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 2153 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
| 2154 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
| 2155 | if (bssid_changed) |
| 2156 | wpas_notify_bssid_changed(wpa_s); |
| 2157 | } |
| 2158 | |
| 2159 | |
| 2160 | void sme_event_assoc_reject(struct wpa_supplicant *wpa_s, |
| 2161 | union wpa_event_data *data) |
| 2162 | { |
| 2163 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association with " MACSTR " failed: " |
| 2164 | "status code %d", MAC2STR(wpa_s->pending_bssid), |
| 2165 | data->assoc_reject.status_code); |
| 2166 | |
| 2167 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); |
| 2168 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2169 | #ifdef CONFIG_SAE |
| 2170 | if (wpa_s->sme.sae_pmksa_caching && wpa_s->current_ssid && |
| 2171 | wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt)) { |
| 2172 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2173 | "PMKSA caching attempt rejected - drop PMKSA cache entry and fall back to SAE authentication"); |
| 2174 | wpa_sm_aborted_cached(wpa_s->wpa); |
| 2175 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); |
| 2176 | if (wpa_s->current_bss) { |
| 2177 | struct wpa_bss *bss = wpa_s->current_bss; |
| 2178 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2179 | |
| 2180 | wpa_drv_deauthenticate(wpa_s, wpa_s->pending_bssid, |
| 2181 | WLAN_REASON_DEAUTH_LEAVING); |
| 2182 | wpas_connect_work_done(wpa_s); |
| 2183 | wpa_supplicant_mark_disassoc(wpa_s); |
| 2184 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 2185 | return; |
| 2186 | } |
| 2187 | } |
| 2188 | #endif /* CONFIG_SAE */ |
| 2189 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2190 | /* |
| 2191 | * For now, unconditionally terminate the previous authentication. In |
| 2192 | * theory, this should not be needed, but mac80211 gets quite confused |
| 2193 | * if the authentication is left pending.. Some roaming cases might |
| 2194 | * benefit from using the previous authentication, so this could be |
| 2195 | * optimized in the future. |
| 2196 | */ |
| 2197 | sme_deauth(wpa_s); |
| 2198 | } |
| 2199 | |
| 2200 | |
| 2201 | void sme_event_auth_timed_out(struct wpa_supplicant *wpa_s, |
| 2202 | union wpa_event_data *data) |
| 2203 | { |
| 2204 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Authentication timed out"); |
| 2205 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2206 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2207 | } |
| 2208 | |
| 2209 | |
| 2210 | void sme_event_assoc_timed_out(struct wpa_supplicant *wpa_s, |
| 2211 | union wpa_event_data *data) |
| 2212 | { |
| 2213 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association timed out"); |
| 2214 | wpas_connection_failed(wpa_s, wpa_s->pending_bssid); |
| 2215 | wpa_supplicant_mark_disassoc(wpa_s); |
| 2216 | } |
| 2217 | |
| 2218 | |
| 2219 | void sme_event_disassoc(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2220 | struct disassoc_info *info) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2221 | { |
| 2222 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Disassociation event received"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2223 | if (wpa_s->sme.prev_bssid_set) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2224 | /* |
| 2225 | * cfg80211/mac80211 can get into somewhat confused state if |
| 2226 | * the AP only disassociates us and leaves us in authenticated |
| 2227 | * state. For now, force the state to be cleared to avoid |
| 2228 | * confusing errors if we try to associate with the AP again. |
| 2229 | */ |
| 2230 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Deauthenticate to clear " |
| 2231 | "driver state"); |
| 2232 | wpa_drv_deauthenticate(wpa_s, wpa_s->sme.prev_bssid, |
| 2233 | WLAN_REASON_DEAUTH_LEAVING); |
| 2234 | } |
| 2235 | } |
| 2236 | |
| 2237 | |
| 2238 | static void sme_auth_timer(void *eloop_ctx, void *timeout_ctx) |
| 2239 | { |
| 2240 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2241 | if (wpa_s->wpa_state == WPA_AUTHENTICATING) { |
| 2242 | wpa_msg(wpa_s, MSG_DEBUG, "SME: Authentication timeout"); |
| 2243 | sme_deauth(wpa_s); |
| 2244 | } |
| 2245 | } |
| 2246 | |
| 2247 | |
| 2248 | static void sme_assoc_timer(void *eloop_ctx, void *timeout_ctx) |
| 2249 | { |
| 2250 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2251 | if (wpa_s->wpa_state == WPA_ASSOCIATING) { |
| 2252 | wpa_msg(wpa_s, MSG_DEBUG, "SME: Association timeout"); |
| 2253 | sme_deauth(wpa_s); |
| 2254 | } |
| 2255 | } |
| 2256 | |
| 2257 | |
| 2258 | void sme_state_changed(struct wpa_supplicant *wpa_s) |
| 2259 | { |
| 2260 | /* Make sure timers are cleaned up appropriately. */ |
| 2261 | if (wpa_s->wpa_state != WPA_ASSOCIATING) |
| 2262 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); |
| 2263 | if (wpa_s->wpa_state != WPA_AUTHENTICATING) |
| 2264 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); |
| 2265 | } |
| 2266 | |
| 2267 | |
| 2268 | void sme_disassoc_while_authenticating(struct wpa_supplicant *wpa_s, |
| 2269 | const u8 *prev_pending_bssid) |
| 2270 | { |
| 2271 | /* |
| 2272 | * mac80211-workaround to force deauth on failed auth cmd, |
| 2273 | * requires us to remain in authenticating state to allow the |
| 2274 | * second authentication attempt to be continued properly. |
| 2275 | */ |
| 2276 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Allow pending authentication " |
| 2277 | "to proceed after disconnection event"); |
| 2278 | wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING); |
| 2279 | os_memcpy(wpa_s->pending_bssid, prev_pending_bssid, ETH_ALEN); |
| 2280 | |
| 2281 | /* |
| 2282 | * Re-arm authentication timer in case auth fails for whatever reason. |
| 2283 | */ |
| 2284 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); |
| 2285 | eloop_register_timeout(SME_AUTH_TIMEOUT, 0, sme_auth_timer, wpa_s, |
| 2286 | NULL); |
| 2287 | } |
| 2288 | |
| 2289 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2290 | void sme_clear_on_disassoc(struct wpa_supplicant *wpa_s) |
| 2291 | { |
| 2292 | wpa_s->sme.prev_bssid_set = 0; |
| 2293 | #ifdef CONFIG_SAE |
| 2294 | wpabuf_free(wpa_s->sme.sae_token); |
| 2295 | wpa_s->sme.sae_token = NULL; |
| 2296 | sae_clear_data(&wpa_s->sme.sae); |
| 2297 | #endif /* CONFIG_SAE */ |
| 2298 | #ifdef CONFIG_IEEE80211R |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2299 | if (wpa_s->sme.ft_ies || wpa_s->sme.ft_used) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2300 | sme_update_ft_ies(wpa_s, NULL, NULL, 0); |
| 2301 | #endif /* CONFIG_IEEE80211R */ |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2302 | sme_stop_sa_query(wpa_s); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2306 | void sme_deinit(struct wpa_supplicant *wpa_s) |
| 2307 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2308 | sme_clear_on_disassoc(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2309 | #ifdef CONFIG_SAE |
| 2310 | os_free(wpa_s->sme.sae_rejected_groups); |
| 2311 | wpa_s->sme.sae_rejected_groups = NULL; |
| 2312 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2313 | |
| 2314 | eloop_cancel_timeout(sme_assoc_timer, wpa_s, NULL); |
| 2315 | eloop_cancel_timeout(sme_auth_timer, wpa_s, NULL); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2316 | eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL); |
| 2317 | } |
| 2318 | |
| 2319 | |
| 2320 | static void sme_send_2040_bss_coex(struct wpa_supplicant *wpa_s, |
| 2321 | const u8 *chan_list, u8 num_channels, |
| 2322 | u8 num_intol) |
| 2323 | { |
| 2324 | struct ieee80211_2040_bss_coex_ie *bc_ie; |
| 2325 | struct ieee80211_2040_intol_chan_report *ic_report; |
| 2326 | struct wpabuf *buf; |
| 2327 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2328 | wpa_printf(MSG_DEBUG, "SME: Send 20/40 BSS Coexistence to " MACSTR |
| 2329 | " (num_channels=%u num_intol=%u)", |
| 2330 | MAC2STR(wpa_s->bssid), num_channels, num_intol); |
| 2331 | wpa_hexdump(MSG_DEBUG, "SME: 20/40 BSS Intolerant Channels", |
| 2332 | chan_list, num_channels); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2333 | |
| 2334 | buf = wpabuf_alloc(2 + /* action.category + action_code */ |
| 2335 | sizeof(struct ieee80211_2040_bss_coex_ie) + |
| 2336 | sizeof(struct ieee80211_2040_intol_chan_report) + |
| 2337 | num_channels); |
| 2338 | if (buf == NULL) |
| 2339 | return; |
| 2340 | |
| 2341 | wpabuf_put_u8(buf, WLAN_ACTION_PUBLIC); |
| 2342 | wpabuf_put_u8(buf, WLAN_PA_20_40_BSS_COEX); |
| 2343 | |
| 2344 | bc_ie = wpabuf_put(buf, sizeof(*bc_ie)); |
| 2345 | bc_ie->element_id = WLAN_EID_20_40_BSS_COEXISTENCE; |
| 2346 | bc_ie->length = 1; |
| 2347 | if (num_intol) |
| 2348 | bc_ie->coex_param |= WLAN_20_40_BSS_COEX_20MHZ_WIDTH_REQ; |
| 2349 | |
| 2350 | if (num_channels > 0) { |
| 2351 | ic_report = wpabuf_put(buf, sizeof(*ic_report)); |
| 2352 | ic_report->element_id = WLAN_EID_20_40_BSS_INTOLERANT; |
| 2353 | ic_report->length = num_channels + 1; |
| 2354 | ic_report->op_class = 0; |
| 2355 | os_memcpy(wpabuf_put(buf, num_channels), chan_list, |
| 2356 | num_channels); |
| 2357 | } |
| 2358 | |
| 2359 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 2360 | wpa_s->own_addr, wpa_s->bssid, |
| 2361 | wpabuf_head(buf), wpabuf_len(buf), 0) < 0) { |
| 2362 | wpa_msg(wpa_s, MSG_INFO, |
| 2363 | "SME: Failed to send 20/40 BSS Coexistence frame"); |
| 2364 | } |
| 2365 | |
| 2366 | wpabuf_free(buf); |
| 2367 | } |
| 2368 | |
| 2369 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2370 | int sme_proc_obss_scan(struct wpa_supplicant *wpa_s, |
| 2371 | struct wpa_scan_results *scan_res) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2372 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2373 | const u8 *ie; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2374 | u8 chan_list[P2P_MAX_CHANNELS], channel; |
| 2375 | u8 num_channels = 0, num_intol = 0, i; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2376 | size_t j; |
| 2377 | int pri_freq, sec_freq; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2378 | |
| 2379 | if (!wpa_s->sme.sched_obss_scan) |
| 2380 | return 0; |
| 2381 | |
| 2382 | wpa_s->sme.sched_obss_scan = 0; |
| 2383 | if (!wpa_s->current_bss || wpa_s->wpa_state != WPA_COMPLETED) |
| 2384 | return 1; |
| 2385 | |
| 2386 | /* |
| 2387 | * Check whether AP uses regulatory triplet or channel triplet in |
| 2388 | * country info. Right now the operating class of the BSS channel |
| 2389 | * width trigger event is "unknown" (IEEE Std 802.11-2012 10.15.12), |
| 2390 | * based on the assumption that operating class triplet is not used in |
| 2391 | * beacon frame. If the First Channel Number/Operating Extension |
| 2392 | * Identifier octet has a positive integer value of 201 or greater, |
| 2393 | * then its operating class triplet. |
| 2394 | * |
| 2395 | * TODO: If Supported Operating Classes element is present in beacon |
| 2396 | * frame, have to lookup operating class in Annex E and fill them in |
| 2397 | * 2040 coex frame. |
| 2398 | */ |
| 2399 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_COUNTRY); |
| 2400 | if (ie && (ie[1] >= 6) && (ie[5] >= 201)) |
| 2401 | return 1; |
| 2402 | |
| 2403 | os_memset(chan_list, 0, sizeof(chan_list)); |
| 2404 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2405 | pri_freq = wpa_s->assoc_freq; |
| 2406 | |
| 2407 | switch (wpa_s->sme.ht_sec_chan) { |
| 2408 | case HT_SEC_CHAN_ABOVE: |
| 2409 | sec_freq = pri_freq + 20; |
| 2410 | break; |
| 2411 | case HT_SEC_CHAN_BELOW: |
| 2412 | sec_freq = pri_freq - 20; |
| 2413 | break; |
| 2414 | case HT_SEC_CHAN_UNKNOWN: |
| 2415 | default: |
| 2416 | wpa_msg(wpa_s, MSG_WARNING, |
| 2417 | "Undefined secondary channel: drop OBSS scan results"); |
| 2418 | return 1; |
| 2419 | } |
| 2420 | |
| 2421 | for (j = 0; j < scan_res->num; j++) { |
| 2422 | struct wpa_scan_res *bss = scan_res->res[j]; |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 2423 | enum hostapd_hw_mode mode; |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2424 | int res; |
| 2425 | |
| 2426 | /* Skip other band bss */ |
Dmitry Shmidt | 4b06059 | 2013-04-29 16:42:49 -0700 | [diff] [blame] | 2427 | mode = ieee80211_freq_to_chan(bss->freq, &channel); |
| 2428 | if (mode != HOSTAPD_MODE_IEEE80211G && |
| 2429 | mode != HOSTAPD_MODE_IEEE80211B) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2430 | continue; |
| 2431 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 2432 | res = check_bss_coex_40mhz(bss, pri_freq, sec_freq); |
| 2433 | if (res) { |
| 2434 | if (res == 2) |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 2435 | num_intol++; |
| 2436 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2437 | /* Check whether the channel is already considered */ |
| 2438 | for (i = 0; i < num_channels; i++) { |
| 2439 | if (channel == chan_list[i]) |
| 2440 | break; |
| 2441 | } |
| 2442 | if (i != num_channels) |
| 2443 | continue; |
| 2444 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2445 | chan_list[num_channels++] = channel; |
| 2446 | } |
| 2447 | } |
| 2448 | |
| 2449 | sme_send_2040_bss_coex(wpa_s, chan_list, num_channels, num_intol); |
| 2450 | return 1; |
| 2451 | } |
| 2452 | |
| 2453 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2454 | static void wpa_obss_scan_freqs_list(struct wpa_supplicant *wpa_s, |
| 2455 | struct wpa_driver_scan_params *params) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2456 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2457 | /* Include only affected channels */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2458 | struct hostapd_hw_modes *mode; |
| 2459 | int count, i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2460 | int start, end; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2461 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2462 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame^] | 2463 | HOSTAPD_MODE_IEEE80211G, false); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2464 | if (mode == NULL) { |
| 2465 | /* No channels supported in this band - use empty list */ |
| 2466 | params->freqs = os_zalloc(sizeof(int)); |
| 2467 | return; |
| 2468 | } |
| 2469 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2470 | if (wpa_s->sme.ht_sec_chan == HT_SEC_CHAN_UNKNOWN && |
| 2471 | wpa_s->current_bss) { |
| 2472 | const u8 *ie; |
| 2473 | |
| 2474 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_OPERATION); |
| 2475 | if (ie && ie[1] >= 2) { |
| 2476 | u8 o; |
| 2477 | |
| 2478 | o = ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK; |
| 2479 | if (o == HT_INFO_HT_PARAM_SECONDARY_CHNL_ABOVE) |
| 2480 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE; |
| 2481 | else if (o == HT_INFO_HT_PARAM_SECONDARY_CHNL_BELOW) |
| 2482 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW; |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | start = wpa_s->assoc_freq - 10; |
| 2487 | end = wpa_s->assoc_freq + 10; |
| 2488 | switch (wpa_s->sme.ht_sec_chan) { |
| 2489 | case HT_SEC_CHAN_UNKNOWN: |
| 2490 | /* HT40+ possible on channels 1..9 */ |
| 2491 | if (wpa_s->assoc_freq <= 2452) |
| 2492 | start -= 20; |
| 2493 | /* HT40- possible on channels 5-13 */ |
| 2494 | if (wpa_s->assoc_freq >= 2432) |
| 2495 | end += 20; |
| 2496 | break; |
| 2497 | case HT_SEC_CHAN_ABOVE: |
| 2498 | end += 20; |
| 2499 | break; |
| 2500 | case HT_SEC_CHAN_BELOW: |
| 2501 | start -= 20; |
| 2502 | break; |
| 2503 | } |
| 2504 | wpa_printf(MSG_DEBUG, |
| 2505 | "OBSS: assoc_freq %d possible affected range %d-%d", |
| 2506 | wpa_s->assoc_freq, start, end); |
| 2507 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2508 | params->freqs = os_calloc(mode->num_channels + 1, sizeof(int)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2509 | if (params->freqs == NULL) |
| 2510 | return; |
| 2511 | for (count = 0, i = 0; i < mode->num_channels; i++) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2512 | int freq; |
| 2513 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2514 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
| 2515 | continue; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2516 | freq = mode->channels[i].freq; |
| 2517 | if (freq - 10 >= end || freq + 10 <= start) |
| 2518 | continue; /* not affected */ |
| 2519 | params->freqs[count++] = freq; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | static void sme_obss_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
| 2525 | { |
| 2526 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2527 | struct wpa_driver_scan_params params; |
| 2528 | |
| 2529 | if (!wpa_s->current_bss) { |
| 2530 | wpa_printf(MSG_DEBUG, "SME OBSS: Ignore scan request"); |
| 2531 | return; |
| 2532 | } |
| 2533 | |
| 2534 | os_memset(¶ms, 0, sizeof(params)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2535 | wpa_obss_scan_freqs_list(wpa_s, ¶ms); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 2536 | params.low_priority = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2537 | wpa_printf(MSG_DEBUG, "SME OBSS: Request an OBSS scan"); |
| 2538 | |
| 2539 | if (wpa_supplicant_trigger_scan(wpa_s, ¶ms)) |
| 2540 | wpa_printf(MSG_DEBUG, "SME OBSS: Failed to trigger scan"); |
| 2541 | else |
| 2542 | wpa_s->sme.sched_obss_scan = 1; |
| 2543 | os_free(params.freqs); |
| 2544 | |
| 2545 | eloop_register_timeout(wpa_s->sme.obss_scan_int, 0, |
| 2546 | sme_obss_scan_timeout, wpa_s, NULL); |
| 2547 | } |
| 2548 | |
| 2549 | |
| 2550 | void sme_sched_obss_scan(struct wpa_supplicant *wpa_s, int enable) |
| 2551 | { |
| 2552 | const u8 *ie; |
| 2553 | struct wpa_bss *bss = wpa_s->current_bss; |
| 2554 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2555 | struct hostapd_hw_modes *hw_mode = NULL; |
| 2556 | int i; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2557 | |
| 2558 | eloop_cancel_timeout(sme_obss_scan_timeout, wpa_s, NULL); |
| 2559 | wpa_s->sme.sched_obss_scan = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2560 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2561 | if (!enable) |
| 2562 | return; |
| 2563 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2564 | /* |
| 2565 | * Schedule OBSS scan if driver is using station SME in wpa_supplicant |
| 2566 | * or it expects OBSS scan to be performed by wpa_supplicant. |
| 2567 | */ |
| 2568 | if (!((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || |
| 2569 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OBSS_SCAN)) || |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2570 | ssid == NULL || ssid->mode != WPAS_MODE_INFRA) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2571 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2572 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2573 | if (!wpa_s->hw.modes) |
| 2574 | return; |
| 2575 | |
| 2576 | /* only HT caps in 11g mode are relevant */ |
| 2577 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 2578 | hw_mode = &wpa_s->hw.modes[i]; |
| 2579 | if (hw_mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 2580 | break; |
| 2581 | } |
| 2582 | |
| 2583 | /* Driver does not support HT40 for 11g or doesn't have 11g. */ |
| 2584 | if (i == wpa_s->hw.num_modes || !hw_mode || |
| 2585 | !(hw_mode->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 2586 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2587 | |
| 2588 | if (bss == NULL || bss->freq < 2400 || bss->freq > 2500) |
| 2589 | return; /* Not associated on 2.4 GHz band */ |
| 2590 | |
| 2591 | /* Check whether AP supports HT40 */ |
| 2592 | ie = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_HT_CAP); |
| 2593 | if (!ie || ie[1] < 2 || |
| 2594 | !(WPA_GET_LE16(ie + 2) & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) |
| 2595 | return; /* AP does not support HT40 */ |
| 2596 | |
| 2597 | ie = wpa_bss_get_ie(wpa_s->current_bss, |
| 2598 | WLAN_EID_OVERLAPPING_BSS_SCAN_PARAMS); |
| 2599 | if (!ie || ie[1] < 14) |
| 2600 | return; /* AP does not request OBSS scans */ |
| 2601 | |
| 2602 | wpa_s->sme.obss_scan_int = WPA_GET_LE16(ie + 6); |
| 2603 | if (wpa_s->sme.obss_scan_int < 10) { |
| 2604 | wpa_printf(MSG_DEBUG, "SME: Invalid OBSS Scan Interval %u " |
| 2605 | "replaced with the minimum 10 sec", |
| 2606 | wpa_s->sme.obss_scan_int); |
| 2607 | wpa_s->sme.obss_scan_int = 10; |
| 2608 | } |
| 2609 | wpa_printf(MSG_DEBUG, "SME: OBSS Scan Interval %u sec", |
| 2610 | wpa_s->sme.obss_scan_int); |
| 2611 | eloop_register_timeout(wpa_s->sme.obss_scan_int, 0, |
| 2612 | sme_obss_scan_timeout, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | static const unsigned int sa_query_max_timeout = 1000; |
| 2617 | static const unsigned int sa_query_retry_timeout = 201; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2618 | static const unsigned int sa_query_ch_switch_max_delay = 5000; /* in usec */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2619 | |
| 2620 | static int sme_check_sa_query_timeout(struct wpa_supplicant *wpa_s) |
| 2621 | { |
| 2622 | u32 tu; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2623 | struct os_reltime now, passed; |
| 2624 | os_get_reltime(&now); |
| 2625 | os_reltime_sub(&now, &wpa_s->sme.sa_query_start, &passed); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2626 | tu = (passed.sec * 1000000 + passed.usec) / 1024; |
| 2627 | if (sa_query_max_timeout < tu) { |
| 2628 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: SA Query timed out"); |
| 2629 | sme_stop_sa_query(wpa_s); |
| 2630 | wpa_supplicant_deauthenticate( |
| 2631 | wpa_s, WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 2632 | return 1; |
| 2633 | } |
| 2634 | |
| 2635 | return 0; |
| 2636 | } |
| 2637 | |
| 2638 | |
| 2639 | static void sme_send_sa_query_req(struct wpa_supplicant *wpa_s, |
| 2640 | const u8 *trans_id) |
| 2641 | { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2642 | u8 req[2 + WLAN_SA_QUERY_TR_ID_LEN + OCV_OCI_EXTENDED_LEN]; |
| 2643 | u8 req_len = 2 + WLAN_SA_QUERY_TR_ID_LEN; |
| 2644 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2645 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Sending SA Query Request to " |
| 2646 | MACSTR, MAC2STR(wpa_s->bssid)); |
| 2647 | wpa_hexdump(MSG_DEBUG, "SME: SA Query Transaction ID", |
| 2648 | trans_id, WLAN_SA_QUERY_TR_ID_LEN); |
| 2649 | req[0] = WLAN_ACTION_SA_QUERY; |
| 2650 | req[1] = WLAN_SA_QUERY_REQUEST; |
| 2651 | os_memcpy(req + 2, trans_id, WLAN_SA_QUERY_TR_ID_LEN); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2652 | |
| 2653 | #ifdef CONFIG_OCV |
| 2654 | if (wpa_sm_ocv_enabled(wpa_s->wpa)) { |
| 2655 | struct wpa_channel_info ci; |
| 2656 | |
| 2657 | if (wpa_drv_channel_info(wpa_s, &ci) != 0) { |
| 2658 | wpa_printf(MSG_WARNING, |
| 2659 | "Failed to get channel info for OCI element in SA Query Request frame"); |
| 2660 | return; |
| 2661 | } |
| 2662 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2663 | #ifdef CONFIG_TESTING_OPTIONS |
| 2664 | if (wpa_s->oci_freq_override_saquery_req) { |
| 2665 | wpa_printf(MSG_INFO, |
| 2666 | "TEST: Override SA Query Request OCI frequency %d -> %d MHz", |
| 2667 | ci.frequency, |
| 2668 | wpa_s->oci_freq_override_saquery_req); |
| 2669 | ci.frequency = wpa_s->oci_freq_override_saquery_req; |
| 2670 | } |
| 2671 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2672 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2673 | if (ocv_insert_extended_oci(&ci, req + req_len) < 0) |
| 2674 | return; |
| 2675 | |
| 2676 | req_len += OCV_OCI_EXTENDED_LEN; |
| 2677 | } |
| 2678 | #endif /* CONFIG_OCV */ |
| 2679 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2680 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 2681 | wpa_s->own_addr, wpa_s->bssid, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2682 | req, req_len, 0) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2683 | wpa_msg(wpa_s, MSG_INFO, "SME: Failed to send SA Query " |
| 2684 | "Request"); |
| 2685 | } |
| 2686 | |
| 2687 | |
| 2688 | static void sme_sa_query_timer(void *eloop_ctx, void *timeout_ctx) |
| 2689 | { |
| 2690 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2691 | unsigned int timeout, sec, usec; |
| 2692 | u8 *trans_id, *nbuf; |
| 2693 | |
| 2694 | if (wpa_s->sme.sa_query_count > 0 && |
| 2695 | sme_check_sa_query_timeout(wpa_s)) |
| 2696 | return; |
| 2697 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2698 | nbuf = os_realloc_array(wpa_s->sme.sa_query_trans_id, |
| 2699 | wpa_s->sme.sa_query_count + 1, |
| 2700 | WLAN_SA_QUERY_TR_ID_LEN); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2701 | if (nbuf == NULL) { |
| 2702 | sme_stop_sa_query(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2703 | return; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2704 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2705 | if (wpa_s->sme.sa_query_count == 0) { |
| 2706 | /* Starting a new SA Query procedure */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2707 | os_get_reltime(&wpa_s->sme.sa_query_start); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2708 | } |
| 2709 | trans_id = nbuf + wpa_s->sme.sa_query_count * WLAN_SA_QUERY_TR_ID_LEN; |
| 2710 | wpa_s->sme.sa_query_trans_id = nbuf; |
| 2711 | wpa_s->sme.sa_query_count++; |
| 2712 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2713 | if (os_get_random(trans_id, WLAN_SA_QUERY_TR_ID_LEN) < 0) { |
| 2714 | wpa_printf(MSG_DEBUG, "Could not generate SA Query ID"); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2715 | sme_stop_sa_query(wpa_s); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2716 | return; |
| 2717 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2718 | |
| 2719 | timeout = sa_query_retry_timeout; |
| 2720 | sec = ((timeout / 1000) * 1024) / 1000; |
| 2721 | usec = (timeout % 1000) * 1024; |
| 2722 | eloop_register_timeout(sec, usec, sme_sa_query_timer, wpa_s, NULL); |
| 2723 | |
| 2724 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Association SA Query attempt %d", |
| 2725 | wpa_s->sme.sa_query_count); |
| 2726 | |
| 2727 | sme_send_sa_query_req(wpa_s, trans_id); |
| 2728 | } |
| 2729 | |
| 2730 | |
| 2731 | static void sme_start_sa_query(struct wpa_supplicant *wpa_s) |
| 2732 | { |
| 2733 | sme_sa_query_timer(wpa_s, NULL); |
| 2734 | } |
| 2735 | |
| 2736 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2737 | static void sme_stop_sa_query(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2738 | { |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2739 | if (wpa_s->sme.sa_query_trans_id) |
| 2740 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Stop SA Query"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2741 | eloop_cancel_timeout(sme_sa_query_timer, wpa_s, NULL); |
| 2742 | os_free(wpa_s->sme.sa_query_trans_id); |
| 2743 | wpa_s->sme.sa_query_trans_id = NULL; |
| 2744 | wpa_s->sme.sa_query_count = 0; |
| 2745 | } |
| 2746 | |
| 2747 | |
| 2748 | void sme_event_unprot_disconnect(struct wpa_supplicant *wpa_s, const u8 *sa, |
| 2749 | const u8 *da, u16 reason_code) |
| 2750 | { |
| 2751 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 0c08fdc | 2014-06-20 10:16:40 -0700 | [diff] [blame] | 2752 | struct os_reltime now; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2753 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2754 | if (wpa_s->wpa_state != WPA_COMPLETED) |
| 2755 | return; |
| 2756 | ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2757 | if (wpas_get_ssid_pmf(wpa_s, ssid) == NO_MGMT_FRAME_PROTECTION) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2758 | return; |
| 2759 | if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) |
| 2760 | return; |
| 2761 | if (reason_code != WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA && |
| 2762 | reason_code != WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA) |
| 2763 | return; |
| 2764 | if (wpa_s->sme.sa_query_count > 0) |
| 2765 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2766 | #ifdef CONFIG_TESTING_OPTIONS |
| 2767 | if (wpa_s->disable_sa_query) |
| 2768 | return; |
| 2769 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2770 | |
Dmitry Shmidt | 0c08fdc | 2014-06-20 10:16:40 -0700 | [diff] [blame] | 2771 | os_get_reltime(&now); |
| 2772 | if (wpa_s->sme.last_unprot_disconnect.sec && |
| 2773 | !os_reltime_expired(&now, &wpa_s->sme.last_unprot_disconnect, 10)) |
| 2774 | return; /* limit SA Query procedure frequency */ |
| 2775 | wpa_s->sme.last_unprot_disconnect = now; |
| 2776 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2777 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Unprotected disconnect dropped - " |
| 2778 | "possible AP/STA state mismatch - trigger SA Query"); |
| 2779 | sme_start_sa_query(wpa_s); |
| 2780 | } |
| 2781 | |
| 2782 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2783 | void sme_event_ch_switch(struct wpa_supplicant *wpa_s) |
| 2784 | { |
| 2785 | unsigned int usec; |
| 2786 | u32 _rand; |
| 2787 | |
| 2788 | if (wpa_s->wpa_state != WPA_COMPLETED || |
| 2789 | !wpa_sm_ocv_enabled(wpa_s->wpa)) |
| 2790 | return; |
| 2791 | |
| 2792 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2793 | "SME: Channel switch completed - trigger new SA Query to verify new operating channel"); |
| 2794 | sme_stop_sa_query(wpa_s); |
| 2795 | |
| 2796 | if (os_get_random((u8 *) &_rand, sizeof(_rand)) < 0) |
| 2797 | _rand = os_random(); |
| 2798 | usec = _rand % (sa_query_ch_switch_max_delay + 1); |
| 2799 | eloop_register_timeout(0, usec, sme_sa_query_timer, wpa_s, NULL); |
| 2800 | } |
| 2801 | |
| 2802 | |
| 2803 | static void sme_process_sa_query_request(struct wpa_supplicant *wpa_s, |
| 2804 | const u8 *sa, const u8 *data, |
| 2805 | size_t len) |
| 2806 | { |
| 2807 | u8 resp[2 + WLAN_SA_QUERY_TR_ID_LEN + OCV_OCI_EXTENDED_LEN]; |
| 2808 | u8 resp_len = 2 + WLAN_SA_QUERY_TR_ID_LEN; |
| 2809 | |
| 2810 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Sending SA Query Response to " |
| 2811 | MACSTR, MAC2STR(wpa_s->bssid)); |
| 2812 | |
| 2813 | resp[0] = WLAN_ACTION_SA_QUERY; |
| 2814 | resp[1] = WLAN_SA_QUERY_RESPONSE; |
| 2815 | os_memcpy(resp + 2, data + 1, WLAN_SA_QUERY_TR_ID_LEN); |
| 2816 | |
| 2817 | #ifdef CONFIG_OCV |
| 2818 | if (wpa_sm_ocv_enabled(wpa_s->wpa)) { |
| 2819 | struct wpa_channel_info ci; |
| 2820 | |
| 2821 | if (wpa_drv_channel_info(wpa_s, &ci) != 0) { |
| 2822 | wpa_printf(MSG_WARNING, |
| 2823 | "Failed to get channel info for OCI element in SA Query Response frame"); |
| 2824 | return; |
| 2825 | } |
| 2826 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2827 | #ifdef CONFIG_TESTING_OPTIONS |
| 2828 | if (wpa_s->oci_freq_override_saquery_resp) { |
| 2829 | wpa_printf(MSG_INFO, |
| 2830 | "TEST: Override SA Query Response OCI frequency %d -> %d MHz", |
| 2831 | ci.frequency, |
| 2832 | wpa_s->oci_freq_override_saquery_resp); |
| 2833 | ci.frequency = wpa_s->oci_freq_override_saquery_resp; |
| 2834 | } |
| 2835 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2836 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2837 | if (ocv_insert_extended_oci(&ci, resp + resp_len) < 0) |
| 2838 | return; |
| 2839 | |
| 2840 | resp_len += OCV_OCI_EXTENDED_LEN; |
| 2841 | } |
| 2842 | #endif /* CONFIG_OCV */ |
| 2843 | |
| 2844 | if (wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 2845 | wpa_s->own_addr, wpa_s->bssid, |
| 2846 | resp, resp_len, 0) < 0) |
| 2847 | wpa_msg(wpa_s, MSG_INFO, |
| 2848 | "SME: Failed to send SA Query Response"); |
| 2849 | } |
| 2850 | |
| 2851 | |
| 2852 | static void sme_process_sa_query_response(struct wpa_supplicant *wpa_s, |
| 2853 | const u8 *sa, const u8 *data, |
| 2854 | size_t len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2855 | { |
| 2856 | int i; |
| 2857 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2858 | if (!wpa_s->sme.sa_query_trans_id) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2859 | return; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2860 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2861 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Received SA Query response from " |
| 2862 | MACSTR " (trans_id %02x%02x)", MAC2STR(sa), data[1], data[2]); |
| 2863 | |
| 2864 | if (os_memcmp(sa, wpa_s->bssid, ETH_ALEN) != 0) |
| 2865 | return; |
| 2866 | |
| 2867 | for (i = 0; i < wpa_s->sme.sa_query_count; i++) { |
| 2868 | if (os_memcmp(wpa_s->sme.sa_query_trans_id + |
| 2869 | i * WLAN_SA_QUERY_TR_ID_LEN, |
| 2870 | data + 1, WLAN_SA_QUERY_TR_ID_LEN) == 0) |
| 2871 | break; |
| 2872 | } |
| 2873 | |
| 2874 | if (i >= wpa_s->sme.sa_query_count) { |
| 2875 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: No matching SA Query " |
| 2876 | "transaction identifier found"); |
| 2877 | return; |
| 2878 | } |
| 2879 | |
| 2880 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Reply to pending SA Query received " |
| 2881 | "from " MACSTR, MAC2STR(sa)); |
| 2882 | sme_stop_sa_query(wpa_s); |
| 2883 | } |
| 2884 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2885 | |
| 2886 | void sme_sa_query_rx(struct wpa_supplicant *wpa_s, const u8 *sa, |
| 2887 | const u8 *data, size_t len) |
| 2888 | { |
| 2889 | if (len < 1 + WLAN_SA_QUERY_TR_ID_LEN) |
| 2890 | return; |
| 2891 | |
| 2892 | wpa_dbg(wpa_s, MSG_DEBUG, "SME: Received SA Query frame from " |
| 2893 | MACSTR " (trans_id %02x%02x)", MAC2STR(sa), data[1], data[2]); |
| 2894 | |
| 2895 | #ifdef CONFIG_OCV |
| 2896 | if (wpa_sm_ocv_enabled(wpa_s->wpa)) { |
| 2897 | struct ieee802_11_elems elems; |
| 2898 | struct wpa_channel_info ci; |
| 2899 | |
| 2900 | if (ieee802_11_parse_elems(data + 1 + WLAN_SA_QUERY_TR_ID_LEN, |
| 2901 | len - 1 - WLAN_SA_QUERY_TR_ID_LEN, |
| 2902 | &elems, 1) == ParseFailed) { |
| 2903 | wpa_printf(MSG_DEBUG, |
| 2904 | "SA Query: Failed to parse elements"); |
| 2905 | return; |
| 2906 | } |
| 2907 | |
| 2908 | if (wpa_drv_channel_info(wpa_s, &ci) != 0) { |
| 2909 | wpa_printf(MSG_WARNING, |
| 2910 | "Failed to get channel info to validate received OCI in SA Query Action frame"); |
| 2911 | return; |
| 2912 | } |
| 2913 | |
| 2914 | if (ocv_verify_tx_params(elems.oci, elems.oci_len, &ci, |
| 2915 | channel_width_to_int(ci.chanwidth), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2916 | ci.seg1_idx) != OCI_SUCCESS) { |
| 2917 | wpa_msg(wpa_s, MSG_INFO, OCV_FAILURE "addr=" MACSTR |
| 2918 | " frame=saquery%s error=%s", |
| 2919 | MAC2STR(sa), data[0] == WLAN_SA_QUERY_REQUEST ? |
| 2920 | "req" : "resp", ocv_errorstr); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2921 | return; |
| 2922 | } |
| 2923 | } |
| 2924 | #endif /* CONFIG_OCV */ |
| 2925 | |
| 2926 | if (data[0] == WLAN_SA_QUERY_REQUEST) |
| 2927 | sme_process_sa_query_request(wpa_s, sa, data, len); |
| 2928 | else if (data[0] == WLAN_SA_QUERY_RESPONSE) |
| 2929 | sme_process_sa_query_response(wpa_s, sa, data, len); |
| 2930 | } |