Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - Driver event processing |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2019, 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 "eapol_supp/eapol_supp_sm.h" |
| 13 | #include "rsn_supp/wpa.h" |
| 14 | #include "eloop.h" |
| 15 | #include "config.h" |
| 16 | #include "l2_packet/l2_packet.h" |
| 17 | #include "wpa_supplicant_i.h" |
| 18 | #include "driver_i.h" |
| 19 | #include "pcsc_funcs.h" |
| 20 | #include "rsn_supp/preauth.h" |
| 21 | #include "rsn_supp/pmksa_cache.h" |
| 22 | #include "common/wpa_ctrl.h" |
| 23 | #include "eap_peer/eap.h" |
| 24 | #include "ap/hostapd.h" |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 25 | #include "ap/sta_info.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | #include "p2p/p2p.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 27 | #include "fst/fst.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 28 | #include "wnm_sta.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 29 | #include "notify.h" |
| 30 | #include "common/ieee802_11_defs.h" |
| 31 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 32 | #include "common/gas_server.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 33 | #include "common/dpp.h" |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 34 | #include "common/ptksa_cache.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "crypto/random.h" |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 36 | #include "bssid_ignore.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 37 | #include "wpas_glue.h" |
| 38 | #include "wps_supplicant.h" |
| 39 | #include "ibss_rsn.h" |
| 40 | #include "sme.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 41 | #include "gas_query.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | #include "p2p_supplicant.h" |
| 43 | #include "bgscan.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 44 | #include "autoscan.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 45 | #include "ap.h" |
| 46 | #include "bss.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 47 | #include "scan.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 48 | #include "offchannel.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 49 | #include "interworking.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 50 | #include "mesh.h" |
| 51 | #include "mesh_mpm.h" |
| 52 | #include "wmm_ac.h" |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 53 | #include "nan_usd.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 54 | #include "dpp_supplicant.h" |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 55 | #include "rsn_supp/wpa_i.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 56 | |
| 57 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 58 | #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5 |
| 59 | |
| 60 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 61 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 62 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 63 | int new_scan, int own_request, |
| 64 | bool trigger_6ghz_scan, |
| 65 | union wpa_event_data *data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 66 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 67 | |
| 68 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 69 | int wpas_temp_disabled(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 70 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 71 | struct os_reltime now; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 72 | |
| 73 | if (ssid == NULL || ssid->disabled_until.sec == 0) |
| 74 | return 0; |
| 75 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 76 | os_get_reltime(&now); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 77 | if (ssid->disabled_until.sec > now.sec) |
| 78 | return ssid->disabled_until.sec - now.sec; |
| 79 | |
| 80 | wpas_clear_temp_disabled(wpa_s, ssid, 0); |
| 81 | |
| 82 | return 0; |
| 83 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 84 | |
| 85 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 86 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 87 | /** |
| 88 | * wpas_reenabled_network_time - Time until first network is re-enabled |
| 89 | * @wpa_s: Pointer to wpa_supplicant data |
| 90 | * Returns: If all enabled networks are temporarily disabled, returns the time |
| 91 | * (in sec) until the first network is re-enabled. Otherwise returns 0. |
| 92 | * |
| 93 | * This function is used in case all enabled networks are temporarily disabled, |
| 94 | * in which case it returns the time (in sec) that the first network will be |
| 95 | * re-enabled. The function assumes that at least one network is enabled. |
| 96 | */ |
| 97 | static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s) |
| 98 | { |
| 99 | struct wpa_ssid *ssid; |
| 100 | int disabled_for, res = 0; |
| 101 | |
| 102 | #ifdef CONFIG_INTERWORKING |
| 103 | if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking && |
| 104 | wpa_s->conf->cred) |
| 105 | return 0; |
| 106 | #endif /* CONFIG_INTERWORKING */ |
| 107 | |
| 108 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 109 | if (ssid->disabled) |
| 110 | continue; |
| 111 | |
| 112 | disabled_for = wpas_temp_disabled(wpa_s, ssid); |
| 113 | if (!disabled_for) |
| 114 | return 0; |
| 115 | |
| 116 | if (!res || disabled_for < res) |
| 117 | res = disabled_for; |
| 118 | } |
| 119 | |
| 120 | return res; |
| 121 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 122 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 123 | |
| 124 | |
| 125 | void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx) |
| 126 | { |
| 127 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 128 | |
| 129 | if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING) |
| 130 | return; |
| 131 | |
| 132 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 133 | "Try to associate due to network getting re-enabled"); |
| 134 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { |
| 135 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 136 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 141 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
| 142 | struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 143 | { |
| 144 | struct wpa_bss *bss = NULL; |
| 145 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 146 | u8 drv_ssid[SSID_MAX_LEN]; |
| 147 | int res; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 148 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 149 | res = wpa_drv_get_ssid(wpa_s, drv_ssid); |
| 150 | if (res > 0) |
| 151 | bss = wpa_bss_get(wpa_s, bssid, drv_ssid, res); |
| 152 | if (!bss && ssid && ssid->ssid_len > 0) |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 153 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); |
| 154 | if (!bss) |
| 155 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 156 | |
| 157 | return bss; |
| 158 | } |
| 159 | |
| 160 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 161 | static struct wpa_bss * |
| 162 | wpa_supplicant_update_current_bss(struct wpa_supplicant *wpa_s, const u8 *bssid) |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 163 | { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 164 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 165 | |
| 166 | if (!bss) { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 167 | wpa_supplicant_update_scan_results(wpa_s); |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 168 | |
| 169 | /* Get the BSS from the new scan results */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 170 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | if (bss) |
| 174 | wpa_s->current_bss = bss; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 175 | |
| 176 | return bss; |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 180 | static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s, |
| 181 | u8 link_id, const u8 *bssid) |
| 182 | { |
| 183 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 184 | |
| 185 | if (!bss) { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 186 | wpa_supplicant_update_scan_results(wpa_s); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 187 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 188 | } |
| 189 | |
| 190 | if (bss) |
| 191 | wpa_s->links[link_id].bss = bss; |
| 192 | } |
| 193 | |
| 194 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 195 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s, |
| 196 | union wpa_event_data *data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 197 | { |
| 198 | struct wpa_ssid *ssid, *old_ssid; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 199 | struct wpa_bss *bss; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 200 | u8 drv_ssid[SSID_MAX_LEN]; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 201 | size_t drv_ssid_len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 202 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 203 | |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 204 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 205 | wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 206 | |
| 207 | if (wpa_s->current_ssid->ssid_len == 0) |
| 208 | return 0; /* current profile still in use */ |
| 209 | res = wpa_drv_get_ssid(wpa_s, drv_ssid); |
| 210 | if (res < 0) { |
| 211 | wpa_msg(wpa_s, MSG_INFO, |
| 212 | "Failed to read SSID from driver"); |
| 213 | return 0; /* try to use current profile */ |
| 214 | } |
| 215 | drv_ssid_len = res; |
| 216 | |
| 217 | if (drv_ssid_len == wpa_s->current_ssid->ssid_len && |
| 218 | os_memcmp(drv_ssid, wpa_s->current_ssid->ssid, |
| 219 | drv_ssid_len) == 0) |
| 220 | return 0; /* current profile still in use */ |
| 221 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 222 | #ifdef CONFIG_OWE |
| 223 | if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
| 224 | wpa_s->current_bss && |
| 225 | (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) && |
| 226 | drv_ssid_len == wpa_s->current_bss->ssid_len && |
| 227 | os_memcmp(drv_ssid, wpa_s->current_bss->ssid, |
| 228 | drv_ssid_len) == 0) |
| 229 | return 0; /* current profile still in use */ |
| 230 | #endif /* CONFIG_OWE */ |
| 231 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 232 | wpa_msg(wpa_s, MSG_DEBUG, |
| 233 | "Driver-initiated BSS selection changed the SSID to %s", |
| 234 | wpa_ssid_txt(drv_ssid, drv_ssid_len)); |
| 235 | /* continue selecting a new network profile */ |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 236 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 237 | |
| 238 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
| 239 | "information"); |
| 240 | ssid = wpa_supplicant_get_ssid(wpa_s); |
| 241 | if (ssid == NULL) { |
| 242 | wpa_msg(wpa_s, MSG_INFO, |
| 243 | "No network configuration found for the current AP"); |
| 244 | return -1; |
| 245 | } |
| 246 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 247 | if (wpas_network_disabled(wpa_s, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 248 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
| 249 | return -1; |
| 250 | } |
| 251 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 252 | if (disallowed_bssid(wpa_s, wpa_s->bssid) || |
| 253 | disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { |
| 254 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); |
| 255 | return -1; |
| 256 | } |
| 257 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 258 | res = wpas_temp_disabled(wpa_s, ssid); |
| 259 | if (res > 0) { |
| 260 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " |
| 261 | "disabled for %d second(s)", res); |
| 262 | return -1; |
| 263 | } |
| 264 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 265 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
| 266 | "current AP"); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 267 | bss = wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 268 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 269 | u8 wpa_ie[80]; |
| 270 | size_t wpa_ie_len = sizeof(wpa_ie); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 271 | bool skip_default_rsne; |
| 272 | |
| 273 | /* Do not override RSNE/RSNXE with the default values if the |
| 274 | * driver indicated the actual values used in the |
| 275 | * (Re)Association Request frame. */ |
| 276 | skip_default_rsne = data && data->assoc_info.req_ies; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 277 | if (wpa_supplicant_set_suites(wpa_s, bss, ssid, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 278 | wpa_ie, &wpa_ie_len, |
| 279 | skip_default_rsne) < 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 280 | wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 281 | } else { |
| 282 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 283 | } |
| 284 | |
| 285 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) |
| 286 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 287 | old_ssid = wpa_s->current_ssid; |
| 288 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 289 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 290 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
| 291 | wpa_supplicant_initiate_eapol(wpa_s); |
| 292 | if (old_ssid != wpa_s->current_ssid) |
| 293 | wpas_notify_network_changed(wpa_s); |
| 294 | |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 299 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 300 | { |
| 301 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 302 | |
| 303 | if (wpa_s->countermeasures) { |
| 304 | wpa_s->countermeasures = 0; |
| 305 | wpa_drv_set_countermeasures(wpa_s, 0); |
| 306 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 307 | |
| 308 | /* |
| 309 | * It is possible that the device is sched scanning, which means |
| 310 | * that a connection attempt will be done only when we receive |
| 311 | * scan results. However, in this case, it would be preferable |
| 312 | * to scan and connect immediately, so cancel the sched_scan and |
| 313 | * issue a regular scan flow. |
| 314 | */ |
| 315 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 316 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 321 | void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 322 | { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 323 | if (!wpa_s->valid_links) |
| 324 | return; |
| 325 | |
| 326 | wpa_s->valid_links = 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 327 | wpa_s->mlo_assoc_link_id = 0; |
| 328 | os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN); |
| 329 | os_memset(wpa_s->links, 0, sizeof(wpa_s->links)); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 333 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) |
| 334 | { |
| 335 | int bssid_changed; |
| 336 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 337 | wnm_bss_keep_alive_deinit(wpa_s); |
| 338 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 339 | #ifdef CONFIG_IBSS_RSN |
| 340 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
| 341 | wpa_s->ibss_rsn = NULL; |
| 342 | #endif /* CONFIG_IBSS_RSN */ |
| 343 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 344 | #ifdef CONFIG_AP |
| 345 | wpa_supplicant_ap_deinit(wpa_s); |
| 346 | #endif /* CONFIG_AP */ |
| 347 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 348 | #ifdef CONFIG_HS20 |
| 349 | /* Clear possibly configured frame filters */ |
| 350 | wpa_drv_configure_frame_filters(wpa_s, 0); |
| 351 | #endif /* CONFIG_HS20 */ |
| 352 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 353 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 354 | return; |
| 355 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 356 | if (os_reltime_initialized(&wpa_s->session_start)) { |
| 357 | os_reltime_age(&wpa_s->session_start, &wpa_s->session_length); |
| 358 | wpa_s->session_start.sec = 0; |
| 359 | wpa_s->session_start.usec = 0; |
| 360 | wpas_notify_session_length(wpa_s); |
| 361 | } |
| 362 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 363 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 364 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
| 365 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
| 366 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 367 | sme_clear_on_disassoc(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 368 | wpa_s->current_bss = NULL; |
| 369 | wpa_s->assoc_freq = 0; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 370 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 371 | if (bssid_changed) |
| 372 | wpas_notify_bssid_changed(wpa_s); |
| 373 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 374 | eapol_sm_notify_portEnabled(wpa_s->eapol, false); |
| 375 | eapol_sm_notify_portValid(wpa_s->eapol, false); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 376 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 377 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 378 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || wpa_s->drv_authorized_port) |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 379 | eapol_sm_notify_eap_success(wpa_s->eapol, false); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 380 | wpa_s->drv_authorized_port = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 381 | wpa_s->ap_ies_from_associnfo = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 382 | wpa_s->current_ssid = NULL; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 383 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 384 | wpa_s->key_mgmt = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 385 | wpa_s->allowed_key_mgmts = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 386 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 387 | #ifndef CONFIG_NO_RRM |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 388 | wpas_rrm_reset(wpa_s); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 389 | #endif /* CONFIG_NO_RRM */ |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 390 | wpa_s->wnmsleep_used = 0; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 391 | #ifdef CONFIG_WNM |
| 392 | wpa_s->wnm_mode = 0; |
| 393 | #endif /* CONFIG_WNM */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 394 | wnm_clear_coloc_intf_reporting(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 395 | wpa_s->disable_mbo_oce = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 396 | |
| 397 | #ifdef CONFIG_TESTING_OPTIONS |
| 398 | wpa_s->last_tk_alg = WPA_ALG_NONE; |
| 399 | os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk)); |
| 400 | #endif /* CONFIG_TESTING_OPTIONS */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 401 | wpa_s->ieee80211ac = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 402 | |
| 403 | if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0) |
| 404 | wpa_s->enabled_4addr_mode = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 405 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 406 | wpa_s->wps_scan_done = false; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 407 | wpas_reset_mlo_info(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 411 | static void wpa_find_assoc_pmkid(struct wpa_supplicant *wpa_s, bool authorized) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 412 | { |
| 413 | struct wpa_ie_data ie; |
| 414 | int pmksa_set = -1; |
| 415 | size_t i; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 416 | struct rsn_pmksa_cache_entry *cur_pmksa; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 417 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 418 | /* Start with assumption of no PMKSA cache entry match for cases other |
| 419 | * than SAE. In particular, this is needed to generate the PMKSA cache |
| 420 | * entries for Suite B cases with driver-based roaming indication. */ |
| 421 | cur_pmksa = pmksa_cache_get_current(wpa_s->wpa); |
| 422 | if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp)) |
| 423 | pmksa_cache_clear_current(wpa_s->wpa); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 424 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 425 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || |
| 426 | ie.pmkid == NULL) |
| 427 | return; |
| 428 | |
| 429 | for (i = 0; i < ie.num_pmkid; i++) { |
| 430 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, |
| 431 | ie.pmkid + i * PMKID_LEN, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 432 | NULL, NULL, 0, NULL, 0, |
| 433 | true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 434 | if (pmksa_set == 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 435 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 436 | if (authorized) |
| 437 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 438 | break; |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
| 443 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); |
| 444 | } |
| 445 | |
| 446 | |
| 447 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, |
| 448 | union wpa_event_data *data) |
| 449 | { |
| 450 | if (data == NULL) { |
| 451 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
| 452 | "event"); |
| 453 | return; |
| 454 | } |
| 455 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
| 456 | " index=%d preauth=%d", |
| 457 | MAC2STR(data->pmkid_candidate.bssid), |
| 458 | data->pmkid_candidate.index, |
| 459 | data->pmkid_candidate.preauth); |
| 460 | |
| 461 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, |
| 462 | data->pmkid_candidate.index, |
| 463 | data->pmkid_candidate.preauth); |
| 464 | } |
| 465 | |
| 466 | |
| 467 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) |
| 468 | { |
| 469 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 470 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) |
| 471 | return 0; |
| 472 | |
| 473 | #ifdef IEEE8021X_EAPOL |
| 474 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 475 | wpa_s->current_ssid && |
| 476 | !(wpa_s->current_ssid->eapol_flags & |
| 477 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 478 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { |
| 479 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either |
| 480 | * plaintext or static WEP keys). */ |
| 481 | return 0; |
| 482 | } |
| 483 | #endif /* IEEE8021X_EAPOL */ |
| 484 | |
| 485 | return 1; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | /** |
| 490 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC |
| 491 | * @wpa_s: pointer to wpa_supplicant data |
| 492 | * @ssid: Configuration data for the network |
| 493 | * Returns: 0 on success, -1 on failure |
| 494 | * |
| 495 | * This function is called when starting authentication with a network that is |
| 496 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). |
| 497 | */ |
| 498 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, |
| 499 | struct wpa_ssid *ssid) |
| 500 | { |
| 501 | #ifdef IEEE8021X_EAPOL |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 502 | #ifdef PCSC_FUNCS |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 503 | int aka = 0, sim = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 504 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 505 | if ((ssid != NULL && ssid->eap.pcsc == NULL) || |
| 506 | wpa_s->scard != NULL || wpa_s->conf->external_sim) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 507 | return 0; |
| 508 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 509 | if (ssid == NULL || ssid->eap.eap_methods == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 510 | sim = 1; |
| 511 | aka = 1; |
| 512 | } else { |
| 513 | struct eap_method_type *eap = ssid->eap.eap_methods; |
| 514 | while (eap->vendor != EAP_VENDOR_IETF || |
| 515 | eap->method != EAP_TYPE_NONE) { |
| 516 | if (eap->vendor == EAP_VENDOR_IETF) { |
| 517 | if (eap->method == EAP_TYPE_SIM) |
| 518 | sim = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 519 | else if (eap->method == EAP_TYPE_AKA || |
| 520 | eap->method == EAP_TYPE_AKA_PRIME) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 521 | aka = 1; |
| 522 | } |
| 523 | eap++; |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) |
| 528 | sim = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 529 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && |
| 530 | eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == |
| 531 | NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 532 | aka = 0; |
| 533 | |
| 534 | if (!sim && !aka) { |
| 535 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
| 536 | "use SIM, but neither EAP-SIM nor EAP-AKA are " |
| 537 | "enabled"); |
| 538 | return 0; |
| 539 | } |
| 540 | |
| 541 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
| 542 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 543 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 544 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 545 | if (wpa_s->scard == NULL) { |
| 546 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
| 547 | "(pcsc-lite)"); |
| 548 | return -1; |
| 549 | } |
| 550 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); |
| 551 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 552 | #endif /* PCSC_FUNCS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 553 | #endif /* IEEE8021X_EAPOL */ |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | |
| 559 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 560 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 561 | #ifdef CONFIG_WEP |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 562 | static int has_wep_key(struct wpa_ssid *ssid) |
| 563 | { |
| 564 | int i; |
| 565 | |
| 566 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 567 | if (ssid->wep_key_len[i]) |
| 568 | return 1; |
| 569 | } |
| 570 | |
| 571 | return 0; |
| 572 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 573 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 574 | |
| 575 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 576 | static int wpa_supplicant_match_privacy(struct wpa_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 577 | struct wpa_ssid *ssid) |
| 578 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 579 | int privacy = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 580 | |
| 581 | if (ssid->mixed_cell) |
| 582 | return 1; |
| 583 | |
| 584 | #ifdef CONFIG_WPS |
| 585 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) |
| 586 | return 1; |
| 587 | #endif /* CONFIG_WPS */ |
| 588 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 589 | #ifdef CONFIG_OWE |
| 590 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only) |
| 591 | return 1; |
| 592 | #endif /* CONFIG_OWE */ |
| 593 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 594 | #ifdef CONFIG_WEP |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 595 | if (has_wep_key(ssid)) |
| 596 | privacy = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 597 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 598 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 599 | #ifdef IEEE8021X_EAPOL |
| 600 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
| 601 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 602 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) |
| 603 | privacy = 1; |
| 604 | #endif /* IEEE8021X_EAPOL */ |
| 605 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 606 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 607 | privacy = 1; |
| 608 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 609 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) |
| 610 | privacy = 1; |
| 611 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 612 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
| 613 | return privacy; |
| 614 | return !privacy; |
| 615 | } |
| 616 | |
| 617 | |
| 618 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
| 619 | struct wpa_ssid *ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 620 | struct wpa_bss *bss, int debug_print) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 621 | { |
| 622 | struct wpa_ie_data ie; |
| 623 | int proto_match = 0; |
| 624 | const u8 *rsn_ie, *wpa_ie; |
| 625 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 626 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 627 | int wep_ok; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 628 | #endif /* CONFIG_WEP */ |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 629 | bool is_6ghz_bss = is_6ghz_freq(bss->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 630 | |
| 631 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
| 632 | if (ret >= 0) |
| 633 | return ret; |
| 634 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 635 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 636 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
| 637 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
| 638 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
| 639 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || |
| 640 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 641 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 642 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 643 | rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 644 | if (is_6ghz_bss && !rsn_ie) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 645 | if (debug_print) |
| 646 | wpa_dbg(wpa_s, MSG_DEBUG, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 647 | " skip - 6 GHz BSS without RSNE"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 648 | return 0; |
| 649 | } |
| 650 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 651 | while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 652 | proto_match++; |
| 653 | |
| 654 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 655 | if (debug_print) |
| 656 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 657 | " skip RSN IE - parse failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 658 | break; |
| 659 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 660 | if (!ie.has_pairwise) |
| 661 | ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq); |
| 662 | if (!ie.has_group) |
| 663 | ie.group_cipher = wpa_default_rsn_cipher(bss->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 664 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 665 | if (is_6ghz_bss || !is_zero_ether_addr(bss->mld_addr)) { |
| 666 | /* WEP and TKIP are not allowed on 6 GHz/MLD */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 667 | ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 | |
| 668 | WPA_CIPHER_WEP104 | |
| 669 | WPA_CIPHER_TKIP); |
| 670 | ie.group_cipher &= ~(WPA_CIPHER_WEP40 | |
| 671 | WPA_CIPHER_WEP104 | |
| 672 | WPA_CIPHER_TKIP); |
| 673 | } |
| 674 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 675 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 676 | if (wep_ok && |
| 677 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) |
| 678 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 679 | if (debug_print) |
| 680 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 681 | " selected based on TSN in RSN IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 682 | return 1; |
| 683 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 684 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 685 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 686 | if (!(ie.proto & ssid->proto) && |
| 687 | !(ssid->proto & WPA_PROTO_OSEN)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 688 | if (debug_print) |
| 689 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 690 | " skip RSN IE - proto mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 691 | break; |
| 692 | } |
| 693 | |
| 694 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 695 | if (debug_print) |
| 696 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 697 | " skip RSN IE - PTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 698 | break; |
| 699 | } |
| 700 | |
| 701 | if (!(ie.group_cipher & ssid->group_cipher)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 702 | if (debug_print) |
| 703 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 704 | " skip RSN IE - GTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 708 | if (ssid->group_mgmt_cipher && |
| 709 | !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) { |
| 710 | if (debug_print) |
| 711 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 712 | " skip RSN IE - group mgmt cipher mismatch"); |
| 713 | break; |
| 714 | } |
| 715 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 716 | if (is_6ghz_bss) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 717 | /* MFPC must be supported on 6 GHz */ |
| 718 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) { |
| 719 | if (debug_print) |
| 720 | wpa_dbg(wpa_s, MSG_DEBUG, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 721 | " skip RSNE - 6 GHz without MFPC"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 722 | break; |
| 723 | } |
| 724 | |
| 725 | /* WPA PSK is not allowed on the 6 GHz band */ |
| 726 | ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK | |
| 727 | WPA_KEY_MGMT_FT_PSK | |
| 728 | WPA_KEY_MGMT_PSK_SHA256); |
| 729 | } |
| 730 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 731 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 732 | if (debug_print) |
| 733 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 734 | " skip RSN IE - key mgmt mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 735 | break; |
| 736 | } |
| 737 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 738 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 739 | wpas_get_ssid_pmf(wpa_s, ssid) == |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 740 | MGMT_FRAME_PROTECTION_REQUIRED) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 741 | if (debug_print) |
| 742 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 743 | " skip RSN IE - no mgmt frame protection"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 744 | break; |
| 745 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 746 | if ((ie.capabilities & WPA_CAPABILITY_MFPR) && |
| 747 | wpas_get_ssid_pmf(wpa_s, ssid) == |
| 748 | NO_MGMT_FRAME_PROTECTION) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 749 | if (debug_print) |
| 750 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 751 | " skip RSN IE - no mgmt frame protection enabled but AP requires it"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 752 | break; |
| 753 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 754 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 755 | if (debug_print) |
| 756 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 757 | " selected based on RSN IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 758 | return 1; |
| 759 | } |
| 760 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 761 | if (is_6ghz_bss) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 762 | if (debug_print) |
| 763 | wpa_dbg(wpa_s, MSG_DEBUG, |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 764 | " skip - 6 GHz BSS without matching RSNE"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 765 | return 0; |
| 766 | } |
| 767 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 768 | wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 769 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 770 | if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED && |
| 771 | (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 772 | #ifdef CONFIG_OWE |
| 773 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && ssid->owe_only && |
| 774 | !wpa_ie && !rsn_ie && |
| 775 | wpa_s->owe_transition_select && |
| 776 | wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) && |
| 777 | ssid->owe_transition_bss_select_count + 1 <= |
| 778 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT) { |
| 779 | ssid->owe_transition_bss_select_count++; |
| 780 | if (debug_print) |
| 781 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 782 | " skip OWE open BSS (selection count %d does not exceed %d)", |
| 783 | ssid->owe_transition_bss_select_count, |
| 784 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT); |
| 785 | wpa_s->owe_transition_search = 1; |
| 786 | return 0; |
| 787 | } |
| 788 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 789 | if (debug_print) |
| 790 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 791 | " skip - MFP Required but network not MFP Capable"); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 792 | return 0; |
| 793 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 794 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 795 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { |
| 796 | proto_match++; |
| 797 | |
| 798 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 799 | if (debug_print) |
| 800 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 801 | " skip WPA IE - parse failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | break; |
| 803 | } |
| 804 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 805 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 806 | if (wep_ok && |
| 807 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) |
| 808 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 809 | if (debug_print) |
| 810 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 811 | " selected based on TSN in WPA IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 812 | return 1; |
| 813 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 814 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 815 | |
| 816 | if (!(ie.proto & ssid->proto)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 817 | if (debug_print) |
| 818 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 819 | " skip WPA IE - proto mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 820 | break; |
| 821 | } |
| 822 | |
| 823 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 824 | if (debug_print) |
| 825 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 826 | " skip WPA IE - PTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | |
| 830 | if (!(ie.group_cipher & ssid->group_cipher)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 831 | if (debug_print) |
| 832 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 833 | " skip WPA IE - GTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 834 | break; |
| 835 | } |
| 836 | |
| 837 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 838 | if (debug_print) |
| 839 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 840 | " skip WPA IE - key mgmt mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 841 | break; |
| 842 | } |
| 843 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 844 | if (debug_print) |
| 845 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 846 | " selected based on WPA IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 847 | return 1; |
| 848 | } |
| 849 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 850 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && |
| 851 | !rsn_ie) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 852 | if (debug_print) |
| 853 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 854 | " allow for non-WPA IEEE 802.1X"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 855 | return 1; |
| 856 | } |
| 857 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 858 | #ifdef CONFIG_OWE |
| 859 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only && |
| 860 | !wpa_ie && !rsn_ie) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 861 | if (wpa_s->owe_transition_select && |
| 862 | wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) && |
| 863 | ssid->owe_transition_bss_select_count + 1 <= |
| 864 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT) { |
| 865 | ssid->owe_transition_bss_select_count++; |
| 866 | if (debug_print) |
| 867 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 868 | " skip OWE transition BSS (selection count %d does not exceed %d)", |
| 869 | ssid->owe_transition_bss_select_count, |
| 870 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT); |
| 871 | wpa_s->owe_transition_search = 1; |
| 872 | return 0; |
| 873 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 874 | if (debug_print) |
| 875 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 876 | " allow in OWE transition mode"); |
| 877 | return 1; |
| 878 | } |
| 879 | #endif /* CONFIG_OWE */ |
| 880 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 881 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
| 882 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 883 | if (debug_print) |
| 884 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 885 | " skip - no WPA/RSN proto match"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 886 | return 0; |
| 887 | } |
| 888 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 889 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && |
| 890 | wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 891 | if (debug_print) |
| 892 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 893 | return 1; |
| 894 | } |
| 895 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 896 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 897 | if (debug_print) |
| 898 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 899 | return 1; |
| 900 | } |
| 901 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 902 | if (debug_print) |
| 903 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 904 | " reject due to mismatch with WPA/WPA2"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 905 | |
| 906 | return 0; |
| 907 | } |
| 908 | |
| 909 | |
| 910 | static int freq_allowed(int *freqs, int freq) |
| 911 | { |
| 912 | int i; |
| 913 | |
| 914 | if (freqs == NULL) |
| 915 | return 1; |
| 916 | |
| 917 | for (i = 0; freqs[i]; i++) |
| 918 | if (freqs[i] == freq) |
| 919 | return 1; |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 924 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 925 | struct wpa_bss *bss, int debug_print) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 926 | { |
| 927 | const struct hostapd_hw_modes *mode = NULL, *modes; |
| 928 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; |
| 929 | const u8 *rate_ie; |
| 930 | int i, j, k; |
| 931 | |
| 932 | if (bss->freq == 0) |
| 933 | return 1; /* Cannot do matching without knowing band */ |
| 934 | |
| 935 | modes = wpa_s->hw.modes; |
| 936 | if (modes == NULL) { |
| 937 | /* |
| 938 | * The driver does not provide any additional information |
| 939 | * about the utilized hardware, so allow the connection attempt |
| 940 | * to continue. |
| 941 | */ |
| 942 | return 1; |
| 943 | } |
| 944 | |
| 945 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 946 | for (j = 0; j < modes[i].num_channels; j++) { |
| 947 | int freq = modes[i].channels[j].freq; |
| 948 | if (freq == bss->freq) { |
| 949 | if (mode && |
| 950 | mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 951 | break; /* do not allow 802.11b replace |
| 952 | * 802.11g */ |
| 953 | mode = &modes[i]; |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | if (mode == NULL) |
| 960 | return 0; |
| 961 | |
| 962 | for (i = 0; i < (int) sizeof(scan_ie); i++) { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 963 | rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 964 | if (rate_ie == NULL) |
| 965 | continue; |
| 966 | |
| 967 | for (j = 2; j < rate_ie[1] + 2; j++) { |
| 968 | int flagged = !!(rate_ie[j] & 0x80); |
| 969 | int r = (rate_ie[j] & 0x7f) * 5; |
| 970 | |
| 971 | /* |
| 972 | * IEEE Std 802.11n-2009 7.3.2.2: |
| 973 | * The new BSS Membership selector value is encoded |
| 974 | * like a legacy basic rate, but it is not a rate and |
| 975 | * only indicates if the BSS members are required to |
| 976 | * support the mandatory features of Clause 20 [HT PHY] |
| 977 | * in order to join the BSS. |
| 978 | */ |
| 979 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 980 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { |
| 981 | if (!ht_supported(mode)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 982 | if (debug_print) |
| 983 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 984 | " hardware does not support HT PHY"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 985 | return 0; |
| 986 | } |
| 987 | continue; |
| 988 | } |
| 989 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 990 | /* There's also a VHT selector for 802.11ac */ |
| 991 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 992 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { |
| 993 | if (!vht_supported(mode)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 994 | if (debug_print) |
| 995 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 996 | " hardware does not support VHT PHY"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 997 | return 0; |
| 998 | } |
| 999 | continue; |
| 1000 | } |
| 1001 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1002 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 1003 | BSS_MEMBERSHIP_SELECTOR_HE_PHY)) { |
| 1004 | if (!he_supported(mode, IEEE80211_MODE_INFRA)) { |
| 1005 | if (debug_print) |
| 1006 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1007 | " hardware does not support HE PHY"); |
| 1008 | return 0; |
| 1009 | } |
| 1010 | continue; |
| 1011 | } |
| 1012 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1013 | #ifdef CONFIG_SAE |
| 1014 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 1015 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1016 | if (wpa_s->conf->sae_pwe == |
| 1017 | SAE_PWE_HUNT_AND_PECK && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1018 | !ssid->sae_password_id && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1019 | !is_6ghz_freq(bss->freq) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1020 | wpa_key_mgmt_sae(ssid->key_mgmt)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1021 | if (debug_print) |
| 1022 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1023 | " SAE H2E disabled"); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 1024 | #ifdef CONFIG_TESTING_OPTIONS |
| 1025 | if (wpa_s->ignore_sae_h2e_only) { |
| 1026 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1027 | "TESTING: Ignore SAE H2E requirement mismatch"); |
| 1028 | continue; |
| 1029 | } |
| 1030 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1031 | return 0; |
| 1032 | } |
| 1033 | continue; |
| 1034 | } |
| 1035 | #endif /* CONFIG_SAE */ |
| 1036 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1037 | if (!flagged) |
| 1038 | continue; |
| 1039 | |
| 1040 | /* check for legacy basic rates */ |
| 1041 | for (k = 0; k < mode->num_rates; k++) { |
| 1042 | if (mode->rates[k] == r) |
| 1043 | break; |
| 1044 | } |
| 1045 | if (k == mode->num_rates) { |
| 1046 | /* |
| 1047 | * IEEE Std 802.11-2007 7.3.2.2 demands that in |
| 1048 | * order to join a BSS all required rates |
| 1049 | * have to be supported by the hardware. |
| 1050 | */ |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1051 | if (debug_print) |
| 1052 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1053 | " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)", |
| 1054 | r / 10, r % 10, |
| 1055 | bss->freq, mode->mode, mode->num_rates); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1056 | return 0; |
| 1057 | } |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | return 1; |
| 1062 | } |
| 1063 | |
| 1064 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1065 | /* |
| 1066 | * Test whether BSS is in an ESS. |
| 1067 | * This is done differently in DMG (60 GHz) and non-DMG bands |
| 1068 | */ |
| 1069 | static int bss_is_ess(struct wpa_bss *bss) |
| 1070 | { |
| 1071 | if (bss_is_dmg(bss)) { |
| 1072 | return (bss->caps & IEEE80211_CAP_DMG_MASK) == |
| 1073 | IEEE80211_CAP_DMG_AP; |
| 1074 | } |
| 1075 | |
| 1076 | return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == |
| 1077 | IEEE80211_CAP_ESS); |
| 1078 | } |
| 1079 | |
| 1080 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1081 | static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask) |
| 1082 | { |
| 1083 | size_t i; |
| 1084 | |
| 1085 | for (i = 0; i < ETH_ALEN; i++) { |
| 1086 | if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i])) |
| 1087 | return 0; |
| 1088 | } |
| 1089 | return 1; |
| 1090 | } |
| 1091 | |
| 1092 | |
| 1093 | static int addr_in_list(const u8 *addr, const u8 *list, size_t num) |
| 1094 | { |
| 1095 | size_t i; |
| 1096 | |
| 1097 | for (i = 0; i < num; i++) { |
| 1098 | const u8 *a = list + i * ETH_ALEN * 2; |
| 1099 | const u8 *m = a + ETH_ALEN; |
| 1100 | |
| 1101 | if (match_mac_mask(a, addr, m)) |
| 1102 | return 1; |
| 1103 | } |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1108 | static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 1109 | const u8 **ret_ssid, size_t *ret_ssid_len) |
| 1110 | { |
| 1111 | #ifdef CONFIG_OWE |
| 1112 | const u8 *owe, *pos, *end, *bssid; |
| 1113 | u8 ssid_len; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1114 | |
| 1115 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 1116 | if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN)) |
| 1117 | return; |
| 1118 | |
| 1119 | pos = owe + 6; |
| 1120 | end = owe + 2 + owe[1]; |
| 1121 | |
| 1122 | if (end - pos < ETH_ALEN + 1) |
| 1123 | return; |
| 1124 | bssid = pos; |
| 1125 | pos += ETH_ALEN; |
| 1126 | ssid_len = *pos++; |
| 1127 | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) |
| 1128 | return; |
| 1129 | |
| 1130 | /* Match the profile SSID against the OWE transition mode SSID on the |
| 1131 | * open network. */ |
| 1132 | wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR |
| 1133 | " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len)); |
| 1134 | *ret_ssid = pos; |
| 1135 | *ret_ssid_len = ssid_len; |
| 1136 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1137 | if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) { |
| 1138 | struct wpa_ssid *ssid; |
| 1139 | |
| 1140 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1141 | if (wpas_network_disabled(wpa_s, ssid)) |
| 1142 | continue; |
| 1143 | if (ssid->ssid_len == ssid_len && |
| 1144 | os_memcmp(ssid->ssid, pos, ssid_len) == 0) { |
| 1145 | /* OWE BSS in transition mode for a currently |
| 1146 | * enabled OWE network. */ |
| 1147 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1148 | "OWE: transition mode OWE SSID for active OWE profile"); |
| 1149 | bss->flags |= WPA_BSS_OWE_TRANSITION; |
| 1150 | break; |
| 1151 | } |
| 1152 | } |
| 1153 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1154 | #endif /* CONFIG_OWE */ |
| 1155 | } |
| 1156 | |
| 1157 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1158 | static bool wpas_valid_ml_bss(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1159 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1160 | { |
| 1161 | u16 removed_links; |
| 1162 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1163 | if (wpa_bss_parse_basic_ml_element(wpa_s, bss, NULL, NULL, NULL, NULL)) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1164 | return true; |
| 1165 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1166 | if (bss->n_mld_links == 0) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1167 | return true; |
| 1168 | |
| 1169 | /* Check if the current BSS is going to be removed */ |
| 1170 | removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, bss); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1171 | if (BIT(bss->mld_links[0].link_id) & removed_links) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1172 | return false; |
| 1173 | |
| 1174 | return true; |
| 1175 | } |
| 1176 | |
| 1177 | |
Sunil Ravi | 26978f3 | 2021-04-30 15:19:18 -0700 | [diff] [blame] | 1178 | int disabled_freq(struct wpa_supplicant *wpa_s, int freq) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1179 | { |
| 1180 | int i, j; |
| 1181 | |
| 1182 | if (!wpa_s->hw.modes || !wpa_s->hw.num_modes) |
| 1183 | return 0; |
| 1184 | |
| 1185 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 1186 | struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j]; |
| 1187 | |
| 1188 | for (i = 0; i < mode->num_channels; i++) { |
| 1189 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 1190 | |
| 1191 | if (chan->freq == freq) |
| 1192 | return !!(chan->flag & HOSTAPD_CHAN_DISABLED); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | return 1; |
| 1197 | } |
| 1198 | |
| 1199 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1200 | static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 1201 | const u8 *match_ssid, size_t match_ssid_len, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1202 | struct wpa_bss *bss, int bssid_ignore_count, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1203 | bool debug_print); |
| 1204 | |
| 1205 | |
| 1206 | #ifdef CONFIG_SAE_PK |
| 1207 | static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s, |
| 1208 | struct wpa_bss *orig_bss, |
| 1209 | struct wpa_ssid *ssid, |
| 1210 | const u8 *match_ssid, |
| 1211 | size_t match_ssid_len) |
| 1212 | { |
| 1213 | struct wpa_bss *bss; |
| 1214 | |
| 1215 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1216 | int count; |
| 1217 | const u8 *ie; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1218 | |
| 1219 | if (bss == orig_bss) |
| 1220 | continue; |
| 1221 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1222 | if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK))) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1223 | continue; |
| 1224 | |
| 1225 | /* TODO: Could be more thorough in checking what kind of |
| 1226 | * signal strength or throughput estimate would be acceptable |
| 1227 | * compared to the originally selected BSS. */ |
| 1228 | if (bss->est_throughput < 2000) |
| 1229 | return false; |
| 1230 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1231 | count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1232 | if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len, |
| 1233 | bss, count, 0)) |
| 1234 | return true; |
| 1235 | } |
| 1236 | |
| 1237 | return false; |
| 1238 | } |
| 1239 | #endif /* CONFIG_SAE_PK */ |
| 1240 | |
| 1241 | |
| 1242 | static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 1243 | const u8 *match_ssid, size_t match_ssid_len, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1244 | struct wpa_bss *bss, int bssid_ignore_count, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1245 | bool debug_print) |
| 1246 | { |
| 1247 | int res; |
| 1248 | bool wpa, check_ssid, osen, rsn_osen = false; |
| 1249 | struct wpa_ie_data data; |
| 1250 | #ifdef CONFIG_MBO |
| 1251 | const u8 *assoc_disallow; |
| 1252 | #endif /* CONFIG_MBO */ |
| 1253 | #ifdef CONFIG_SAE |
| 1254 | u8 rsnxe_capa = 0; |
| 1255 | #endif /* CONFIG_SAE */ |
| 1256 | const u8 *ie; |
| 1257 | |
| 1258 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 1259 | wpa = ie && ie[1]; |
| 1260 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 1261 | wpa |= ie && ie[1]; |
| 1262 | if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 && |
| 1263 | (data.key_mgmt & WPA_KEY_MGMT_OSEN)) |
| 1264 | rsn_osen = true; |
| 1265 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 1266 | osen = ie != NULL; |
| 1267 | |
| 1268 | #ifdef CONFIG_SAE |
| 1269 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
| 1270 | if (ie && ie[1] >= 1) |
| 1271 | rsnxe_capa = ie[2]; |
| 1272 | #endif /* CONFIG_SAE */ |
| 1273 | |
| 1274 | check_ssid = wpa || ssid->ssid_len > 0; |
| 1275 | |
| 1276 | if (wpas_network_disabled(wpa_s, ssid)) { |
| 1277 | if (debug_print) |
| 1278 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
| 1279 | return false; |
| 1280 | } |
| 1281 | |
| 1282 | res = wpas_temp_disabled(wpa_s, ssid); |
| 1283 | if (res > 0) { |
| 1284 | if (debug_print) |
| 1285 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1286 | " skip - disabled temporarily for %d second(s)", |
| 1287 | res); |
| 1288 | return false; |
| 1289 | } |
| 1290 | |
| 1291 | #ifdef CONFIG_WPS |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1292 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1293 | if (debug_print) |
| 1294 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1295 | " skip - BSSID ignored (WPS)"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1296 | return false; |
| 1297 | } |
| 1298 | |
| 1299 | if (wpa && ssid->ssid_len == 0 && |
| 1300 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
| 1301 | check_ssid = false; |
| 1302 | |
| 1303 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 1304 | /* Only allow wildcard SSID match if an AP advertises active |
| 1305 | * WPS operation that matches our mode. */ |
| 1306 | check_ssid = ssid->ssid_len > 0 || |
| 1307 | !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss); |
| 1308 | } |
| 1309 | #endif /* CONFIG_WPS */ |
| 1310 | |
| 1311 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1312 | ether_addr_equal(bss->bssid, ssid->bssid)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1313 | check_ssid = false; |
| 1314 | |
| 1315 | if (check_ssid && |
| 1316 | (match_ssid_len != ssid->ssid_len || |
| 1317 | os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) { |
| 1318 | if (debug_print) |
| 1319 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
| 1320 | return false; |
| 1321 | } |
| 1322 | |
| 1323 | if (ssid->bssid_set && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1324 | !ether_addr_equal(bss->bssid, ssid->bssid)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1325 | if (debug_print) |
| 1326 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
| 1327 | return false; |
| 1328 | } |
| 1329 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1330 | /* check the list of BSSIDs to ignore */ |
| 1331 | if (ssid->num_bssid_ignore && |
| 1332 | addr_in_list(bss->bssid, ssid->bssid_ignore, |
| 1333 | ssid->num_bssid_ignore)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1334 | if (debug_print) |
| 1335 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1336 | " skip - BSSID configured to be ignored"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1337 | return false; |
| 1338 | } |
| 1339 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1340 | /* if there is a list of accepted BSSIDs, only accept those APs */ |
| 1341 | if (ssid->num_bssid_accept && |
| 1342 | !addr_in_list(bss->bssid, ssid->bssid_accept, |
| 1343 | ssid->num_bssid_accept)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1344 | if (debug_print) |
| 1345 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1346 | " skip - BSSID not in list of accepted values"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1347 | return false; |
| 1348 | } |
| 1349 | |
| 1350 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print)) |
| 1351 | return false; |
| 1352 | |
| 1353 | if (!osen && !wpa && |
| 1354 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
| 1355 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && |
| 1356 | !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
| 1357 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { |
| 1358 | if (debug_print) |
| 1359 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1360 | " skip - non-WPA network not allowed"); |
| 1361 | return false; |
| 1362 | } |
| 1363 | |
| 1364 | #ifdef CONFIG_WEP |
| 1365 | if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) { |
| 1366 | if (debug_print) |
| 1367 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1368 | " skip - ignore WPA/WPA2 AP for WEP network block"); |
| 1369 | return false; |
| 1370 | } |
| 1371 | #endif /* CONFIG_WEP */ |
| 1372 | |
| 1373 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) { |
| 1374 | if (debug_print) |
| 1375 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1376 | " skip - non-OSEN network not allowed"); |
| 1377 | return false; |
| 1378 | } |
| 1379 | |
| 1380 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
| 1381 | if (debug_print) |
| 1382 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch"); |
| 1383 | return false; |
| 1384 | } |
| 1385 | |
| 1386 | if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) && |
| 1387 | !bss_is_pbss(bss)) { |
| 1388 | if (debug_print) |
| 1389 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1390 | " skip - not ESS, PBSS, or MBSS"); |
| 1391 | return false; |
| 1392 | } |
| 1393 | |
| 1394 | if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) { |
| 1395 | if (debug_print) |
| 1396 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1397 | " skip - PBSS mismatch (ssid %d bss %d)", |
| 1398 | ssid->pbss, bss_is_pbss(bss)); |
| 1399 | return false; |
| 1400 | } |
| 1401 | |
| 1402 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
| 1403 | if (debug_print) |
| 1404 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1405 | " skip - frequency not allowed"); |
| 1406 | return false; |
| 1407 | } |
| 1408 | |
| 1409 | #ifdef CONFIG_MESH |
| 1410 | if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 && |
| 1411 | ssid->frequency != bss->freq) { |
| 1412 | if (debug_print) |
| 1413 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1414 | " skip - frequency not allowed (mesh)"); |
| 1415 | return false; |
| 1416 | } |
| 1417 | #endif /* CONFIG_MESH */ |
| 1418 | |
| 1419 | if (!rate_match(wpa_s, ssid, bss, debug_print)) { |
| 1420 | if (debug_print) |
| 1421 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1422 | " skip - rate sets do not match"); |
| 1423 | return false; |
| 1424 | } |
| 1425 | |
| 1426 | #ifdef CONFIG_SAE |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1427 | /* When using SAE Password Identifier and when operationg on the 6 GHz |
| 1428 | * band, only H2E is allowed. */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1429 | if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT || |
| 1430 | is_6ghz_freq(bss->freq) || ssid->sae_password_id) && |
| 1431 | wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK && |
| 1432 | wpa_key_mgmt_sae(ssid->key_mgmt) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 1433 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 1434 | !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 1435 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1436 | !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) { |
| 1437 | if (debug_print) |
| 1438 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1439 | " skip - SAE H2E required, but not supported by the AP"); |
| 1440 | return false; |
| 1441 | } |
| 1442 | #endif /* CONFIG_SAE */ |
| 1443 | |
| 1444 | #ifdef CONFIG_SAE_PK |
| 1445 | if (ssid->sae_pk == SAE_PK_MODE_ONLY && |
| 1446 | !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) { |
| 1447 | if (debug_print) |
| 1448 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1449 | " skip - SAE-PK required, but not supported by the AP"); |
| 1450 | return false; |
| 1451 | } |
| 1452 | #endif /* CONFIG_SAE_PK */ |
| 1453 | |
| 1454 | #ifndef CONFIG_IBSS_RSN |
| 1455 | if (ssid->mode == WPAS_MODE_IBSS && |
| 1456 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) { |
| 1457 | if (debug_print) |
| 1458 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1459 | " skip - IBSS RSN not supported in the build"); |
| 1460 | return false; |
| 1461 | } |
| 1462 | #endif /* !CONFIG_IBSS_RSN */ |
| 1463 | |
| 1464 | #ifdef CONFIG_P2P |
| 1465 | if (ssid->p2p_group && |
| 1466 | !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 1467 | !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 1468 | if (debug_print) |
| 1469 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen"); |
| 1470 | return false; |
| 1471 | } |
| 1472 | |
| 1473 | if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) { |
| 1474 | struct wpabuf *p2p_ie; |
| 1475 | u8 dev_addr[ETH_ALEN]; |
| 1476 | |
| 1477 | ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
| 1478 | if (!ie) { |
| 1479 | if (debug_print) |
| 1480 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1481 | " skip - no P2P element"); |
| 1482 | return false; |
| 1483 | } |
| 1484 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 1485 | if (!p2p_ie) { |
| 1486 | if (debug_print) |
| 1487 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1488 | " skip - could not fetch P2P element"); |
| 1489 | return false; |
| 1490 | } |
| 1491 | |
| 1492 | if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1493 | !ether_addr_equal(dev_addr, ssid->go_p2p_dev_addr)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1494 | if (debug_print) |
| 1495 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1496 | " skip - no matching GO P2P Device Address in P2P element"); |
| 1497 | wpabuf_free(p2p_ie); |
| 1498 | return false; |
| 1499 | } |
| 1500 | wpabuf_free(p2p_ie); |
| 1501 | } |
| 1502 | |
| 1503 | /* |
| 1504 | * TODO: skip the AP if its P2P IE has Group Formation bit set in the |
| 1505 | * P2P Group Capability Bitmap and we are not in Group Formation with |
| 1506 | * that device. |
| 1507 | */ |
| 1508 | #endif /* CONFIG_P2P */ |
| 1509 | |
| 1510 | if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) { |
| 1511 | struct os_reltime diff; |
| 1512 | |
| 1513 | os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff); |
| 1514 | if (debug_print) |
| 1515 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1516 | " skip - scan result not recent enough (%u.%06u seconds too old)", |
| 1517 | (unsigned int) diff.sec, |
| 1518 | (unsigned int) diff.usec); |
| 1519 | return false; |
| 1520 | } |
| 1521 | #ifdef CONFIG_MBO |
| 1522 | #ifdef CONFIG_TESTING_OPTIONS |
| 1523 | if (wpa_s->ignore_assoc_disallow) |
| 1524 | goto skip_assoc_disallow; |
| 1525 | #endif /* CONFIG_TESTING_OPTIONS */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1526 | assoc_disallow = wpas_mbo_check_assoc_disallow(bss); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1527 | if (assoc_disallow && assoc_disallow[1] >= 1) { |
| 1528 | if (debug_print) |
| 1529 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1530 | " skip - MBO association disallowed (reason %u)", |
| 1531 | assoc_disallow[2]); |
| 1532 | return false; |
| 1533 | } |
| 1534 | |
| 1535 | if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) { |
| 1536 | if (debug_print) |
| 1537 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1538 | " skip - AP temporarily disallowed"); |
| 1539 | return false; |
| 1540 | } |
| 1541 | #ifdef CONFIG_TESTING_OPTIONS |
| 1542 | skip_assoc_disallow: |
| 1543 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1544 | #endif /* CONFIG_MBO */ |
| 1545 | |
| 1546 | #ifdef CONFIG_DPP |
| 1547 | if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1548 | !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr, |
| 1549 | ssid) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1550 | (!ssid->dpp_connector || !ssid->dpp_netaccesskey || |
| 1551 | !ssid->dpp_csign)) { |
| 1552 | if (debug_print) |
| 1553 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1554 | " skip - no PMKSA entry for DPP"); |
| 1555 | return false; |
| 1556 | } |
| 1557 | #endif /* CONFIG_DPP */ |
| 1558 | |
| 1559 | #ifdef CONFIG_SAE_PK |
| 1560 | if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC && |
| 1561 | wpa_key_mgmt_sae(ssid->key_mgmt) && |
| 1562 | ((ssid->sae_password && |
| 1563 | sae_pk_valid_password(ssid->sae_password)) || |
| 1564 | (!ssid->sae_password && ssid->passphrase && |
| 1565 | sae_pk_valid_password(ssid->passphrase))) && |
| 1566 | !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) && |
| 1567 | sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid, |
| 1568 | match_ssid_len)) { |
| 1569 | if (debug_print) |
| 1570 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1571 | " skip - another acceptable BSS with SAE-PK in the same ESS"); |
| 1572 | return false; |
| 1573 | } |
| 1574 | #endif /* CONFIG_SAE_PK */ |
| 1575 | |
| 1576 | if (bss->ssid_len == 0) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1577 | #ifdef CONFIG_OWE |
| 1578 | const u8 *owe_ssid = NULL; |
| 1579 | size_t owe_ssid_len = 0; |
| 1580 | |
| 1581 | owe_trans_ssid(wpa_s, bss, &owe_ssid, &owe_ssid_len); |
| 1582 | if (owe_ssid && owe_ssid_len && |
| 1583 | owe_ssid_len == ssid->ssid_len && |
| 1584 | os_memcmp(owe_ssid, ssid->ssid, owe_ssid_len) == 0) { |
| 1585 | if (debug_print) |
| 1586 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1587 | " skip - no SSID in BSS entry for a possible OWE transition mode BSS"); |
| 1588 | int_array_add_unique(&wpa_s->owe_trans_scan_freq, |
| 1589 | bss->freq); |
| 1590 | return false; |
| 1591 | } |
| 1592 | #endif /* CONFIG_OWE */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1593 | if (debug_print) |
| 1594 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1595 | " skip - no SSID known for the BSS"); |
| 1596 | return false; |
| 1597 | } |
| 1598 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1599 | if (!wpas_valid_ml_bss(wpa_s, bss)) { |
| 1600 | if (debug_print) |
| 1601 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1602 | " skip - ML BSS going to be removed"); |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1606 | /* Matching configuration found */ |
| 1607 | return true; |
| 1608 | } |
| 1609 | |
| 1610 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1611 | struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
| 1612 | int i, struct wpa_bss *bss, |
| 1613 | struct wpa_ssid *group, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1614 | int only_first_ssid, int debug_print) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1616 | u8 wpa_ie_len, rsn_ie_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1617 | const u8 *ie; |
| 1618 | struct wpa_ssid *ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1619 | int osen; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1620 | const u8 *match_ssid; |
| 1621 | size_t match_ssid_len; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1622 | int bssid_ignore_count; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1623 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1624 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1625 | wpa_ie_len = ie ? ie[1] : 0; |
| 1626 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1627 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1628 | rsn_ie_len = ie ? ie[1] : 0; |
| 1629 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1630 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 1631 | osen = ie != NULL; |
| 1632 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1633 | if (debug_print) { |
| 1634 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR |
| 1635 | " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s", |
| 1636 | i, MAC2STR(bss->bssid), |
| 1637 | wpa_ssid_txt(bss->ssid, bss->ssid_len), |
| 1638 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, |
| 1639 | bss->freq, |
| 1640 | wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? |
| 1641 | " wps" : "", |
| 1642 | (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
| 1643 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) |
| 1644 | ? " p2p" : "", |
| 1645 | osen ? " osen=1" : ""); |
| 1646 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1647 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1648 | bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid); |
| 1649 | if (bssid_ignore_count) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1650 | int limit = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1651 | if (wpa_supplicant_enabled_networks(wpa_s) == 1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1652 | /* |
| 1653 | * When only a single network is enabled, we can |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1654 | * trigger BSSID ignoring on the first failure. This |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1655 | * should not be done with multiple enabled networks to |
| 1656 | * avoid getting forced to move into a worse ESS on |
| 1657 | * single error if there are no other BSSes of the |
| 1658 | * current ESS. |
| 1659 | */ |
| 1660 | limit = 0; |
| 1661 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1662 | if (bssid_ignore_count > limit) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1663 | if (debug_print) { |
| 1664 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1665 | " skip - BSSID ignored (count=%d limit=%d)", |
| 1666 | bssid_ignore_count, limit); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1667 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1668 | return NULL; |
| 1669 | } |
| 1670 | } |
| 1671 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1672 | match_ssid = bss->ssid; |
| 1673 | match_ssid_len = bss->ssid_len; |
| 1674 | owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len); |
| 1675 | |
| 1676 | if (match_ssid_len == 0) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1677 | if (debug_print) |
| 1678 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1679 | return NULL; |
| 1680 | } |
| 1681 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1682 | if (disallowed_bssid(wpa_s, bss->bssid)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1683 | if (debug_print) |
| 1684 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1685 | return NULL; |
| 1686 | } |
| 1687 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1688 | if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1689 | if (debug_print) |
| 1690 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1691 | return NULL; |
| 1692 | } |
| 1693 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1694 | if (disabled_freq(wpa_s, bss->freq)) { |
| 1695 | if (debug_print) |
| 1696 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled"); |
| 1697 | return NULL; |
| 1698 | } |
| 1699 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1700 | #ifdef CONFIG_WNM |
| 1701 | if (wnm_is_bss_excluded(wpa_s, bss)) { |
| 1702 | if (debug_print) |
| 1703 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID excluded"); |
| 1704 | return NULL; |
| 1705 | } |
| 1706 | #endif /* CONFIG_WNM */ |
| 1707 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1708 | for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1709 | if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1710 | bss, bssid_ignore_count, debug_print)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1711 | return ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | /* No matching configuration found */ |
| 1715 | return NULL; |
| 1716 | } |
| 1717 | |
| 1718 | |
| 1719 | static struct wpa_bss * |
| 1720 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1721 | struct wpa_ssid *group, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1722 | struct wpa_ssid **selected_ssid, |
| 1723 | int only_first_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1724 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1725 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1726 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1727 | if (wpa_s->current_ssid) { |
| 1728 | struct wpa_ssid *ssid; |
| 1729 | |
| 1730 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1731 | "Scan results matching the currently selected network"); |
| 1732 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 1733 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
| 1734 | |
| 1735 | ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
| 1736 | only_first_ssid, 0); |
| 1737 | if (ssid != wpa_s->current_ssid) |
| 1738 | continue; |
| 1739 | wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR |
| 1740 | " freq=%d level=%d snr=%d est_throughput=%u", |
| 1741 | i, MAC2STR(bss->bssid), bss->freq, bss->level, |
| 1742 | bss->snr, bss->est_throughput); |
| 1743 | } |
| 1744 | } |
| 1745 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1746 | if (only_first_ssid) |
| 1747 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d", |
| 1748 | group->id); |
| 1749 | else |
| 1750 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", |
| 1751 | group->priority); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1752 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1753 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 1754 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1755 | |
| 1756 | wpa_s->owe_transition_select = 1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1757 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1758 | only_first_ssid, 1); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1759 | wpa_s->owe_transition_select = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1760 | if (!*selected_ssid) |
| 1761 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1762 | wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1763 | " ssid='%s'", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1764 | bss == wpa_s->current_bss ? "current ": "", |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1765 | MAC2STR(bss->bssid), |
| 1766 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| 1767 | return bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1768 | } |
| 1769 | |
| 1770 | return NULL; |
| 1771 | } |
| 1772 | |
| 1773 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1774 | struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
| 1775 | struct wpa_ssid **selected_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1776 | { |
| 1777 | struct wpa_bss *selected = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1778 | size_t prio; |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1779 | struct wpa_ssid *next_ssid = NULL; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1780 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1781 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1782 | if (wpa_s->last_scan_res == NULL || |
| 1783 | wpa_s->last_scan_res_used == 0) |
| 1784 | return NULL; /* no scan results from last update */ |
| 1785 | |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1786 | if (wpa_s->next_ssid) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1787 | /* check that next_ssid is still valid */ |
| 1788 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1789 | if (ssid == wpa_s->next_ssid) |
| 1790 | break; |
| 1791 | } |
| 1792 | next_ssid = ssid; |
| 1793 | wpa_s->next_ssid = NULL; |
| 1794 | } |
| 1795 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1796 | while (selected == NULL) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1797 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { |
| 1798 | if (next_ssid && next_ssid->priority == |
| 1799 | wpa_s->conf->pssid[prio]->priority) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1800 | selected = wpa_supplicant_select_bss( |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1801 | wpa_s, next_ssid, selected_ssid, 1); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1802 | if (selected) |
| 1803 | break; |
| 1804 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1805 | selected = wpa_supplicant_select_bss( |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1806 | wpa_s, wpa_s->conf->pssid[prio], |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1807 | selected_ssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1808 | if (selected) |
| 1809 | break; |
| 1810 | } |
| 1811 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 1812 | if (selected == NULL && wpa_s->bssid_ignore && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1813 | !wpa_s->countermeasures) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1814 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1815 | "No APs found - clear BSSID ignore list and try again"); |
| 1816 | wpa_bssid_ignore_clear(wpa_s); |
| 1817 | wpa_s->bssid_ignore_cleared = true; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1818 | } else if (selected == NULL) |
| 1819 | break; |
| 1820 | } |
| 1821 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1822 | ssid = *selected_ssid; |
| 1823 | if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set && |
| 1824 | !ssid->passphrase && !ssid->ext_psk) { |
| 1825 | const char *field_name, *txt = NULL; |
| 1826 | |
| 1827 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1828 | "PSK/passphrase not yet available for the selected network"); |
| 1829 | |
| 1830 | wpas_notify_network_request(wpa_s, ssid, |
| 1831 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL); |
| 1832 | |
| 1833 | field_name = wpa_supplicant_ctrl_req_to_string( |
| 1834 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt); |
| 1835 | if (field_name == NULL) |
| 1836 | return NULL; |
| 1837 | |
| 1838 | wpas_send_ctrl_req(wpa_s, ssid, field_name, txt); |
| 1839 | |
| 1840 | selected = NULL; |
| 1841 | } |
| 1842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1843 | return selected; |
| 1844 | } |
| 1845 | |
| 1846 | |
| 1847 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, |
| 1848 | int timeout_sec, int timeout_usec) |
| 1849 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1850 | if (!wpa_supplicant_enabled_networks(wpa_s)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1851 | /* |
| 1852 | * No networks are enabled; short-circuit request so |
| 1853 | * we don't wait timeout seconds before transitioning |
| 1854 | * to INACTIVE state. |
| 1855 | */ |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1856 | wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " |
| 1857 | "since there are no enabled networks"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 1859 | return; |
| 1860 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1861 | |
| 1862 | wpa_s->scan_for_connection = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1863 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
| 1864 | } |
| 1865 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1866 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1867 | static bool ml_link_probe_scan(struct wpa_supplicant *wpa_s) |
| 1868 | { |
| 1869 | if (!wpa_s->ml_connect_probe_ssid || !wpa_s->ml_connect_probe_bss) |
| 1870 | return false; |
| 1871 | |
| 1872 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1873 | "Request association with " MACSTR " after ML probe", |
| 1874 | MAC2STR(wpa_s->ml_connect_probe_bss->bssid)); |
| 1875 | |
| 1876 | wpa_supplicant_associate(wpa_s, wpa_s->ml_connect_probe_bss, |
| 1877 | wpa_s->ml_connect_probe_ssid); |
| 1878 | |
| 1879 | wpa_s->ml_connect_probe_ssid = NULL; |
| 1880 | wpa_s->ml_connect_probe_bss = NULL; |
| 1881 | |
| 1882 | return true; |
| 1883 | } |
| 1884 | |
| 1885 | |
| 1886 | static int wpa_supplicant_connect_ml_missing(struct wpa_supplicant *wpa_s, |
| 1887 | struct wpa_bss *selected, |
| 1888 | struct wpa_ssid *ssid) |
| 1889 | { |
| 1890 | int *freqs; |
| 1891 | u16 missing_links = 0, removed_links; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1892 | u8 ap_mld_id; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1893 | |
| 1894 | if (!((wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_MLO) && |
| 1895 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME))) |
| 1896 | return 0; |
| 1897 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1898 | if (wpa_bss_parse_basic_ml_element(wpa_s, selected, NULL, |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1899 | &missing_links, ssid, |
| 1900 | &ap_mld_id) || |
| 1901 | !missing_links) |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1902 | return 0; |
| 1903 | |
| 1904 | removed_links = wpa_bss_parse_reconf_ml_element(wpa_s, selected); |
| 1905 | missing_links &= ~removed_links; |
| 1906 | |
| 1907 | if (!missing_links) |
| 1908 | return 0; |
| 1909 | |
| 1910 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1911 | "MLD: Doing an ML probe for missing links 0x%04x", |
| 1912 | missing_links); |
| 1913 | |
| 1914 | freqs = os_malloc(sizeof(int) * 2); |
| 1915 | if (!freqs) |
| 1916 | return 0; |
| 1917 | |
| 1918 | wpa_s->ml_connect_probe_ssid = ssid; |
| 1919 | wpa_s->ml_connect_probe_bss = selected; |
| 1920 | |
| 1921 | freqs[0] = selected->freq; |
| 1922 | freqs[1] = 0; |
| 1923 | |
| 1924 | wpa_s->manual_scan_passive = 0; |
| 1925 | wpa_s->manual_scan_use_id = 0; |
| 1926 | wpa_s->manual_scan_only_new = 0; |
| 1927 | wpa_s->scan_id_count = 0; |
| 1928 | os_free(wpa_s->manual_scan_freqs); |
| 1929 | wpa_s->manual_scan_freqs = freqs; |
| 1930 | |
| 1931 | os_memcpy(wpa_s->ml_probe_bssid, selected->bssid, ETH_ALEN); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 1932 | |
| 1933 | /* |
| 1934 | * In case the ML probe request is intended to retrieve information from |
| 1935 | * the transmitted BSS, the AP MLD ID should be included and should be |
| 1936 | * set to zero. |
| 1937 | * In case the ML probe requested is intended to retrieve information |
| 1938 | * from a non-transmitted BSS, the AP MLD ID should not be included. |
| 1939 | */ |
| 1940 | if (ap_mld_id) |
| 1941 | wpa_s->ml_probe_mld_id = -1; |
| 1942 | else |
| 1943 | wpa_s->ml_probe_mld_id = 0; |
| 1944 | |
| 1945 | if (ssid && ssid->ssid_len) { |
| 1946 | os_free(wpa_s->ssids_from_scan_req); |
| 1947 | wpa_s->num_ssids_from_scan_req = 0; |
| 1948 | |
| 1949 | wpa_s->ssids_from_scan_req = |
| 1950 | os_zalloc(sizeof(struct wpa_ssid_value)); |
| 1951 | if (wpa_s->ssids_from_scan_req) { |
| 1952 | wpa_printf(MSG_DEBUG, |
| 1953 | "MLD: ML probe: With direct SSID"); |
| 1954 | |
| 1955 | wpa_s->num_ssids_from_scan_req = 1; |
| 1956 | wpa_s->ssids_from_scan_req[0].ssid_len = ssid->ssid_len; |
| 1957 | os_memcpy(wpa_s->ssids_from_scan_req[0].ssid, |
| 1958 | ssid->ssid, ssid->ssid_len); |
| 1959 | } |
| 1960 | } |
| 1961 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1962 | wpa_s->ml_probe_links = missing_links; |
| 1963 | |
| 1964 | wpa_s->normal_scans = 0; |
| 1965 | wpa_s->scan_req = MANUAL_SCAN_REQ; |
| 1966 | wpa_s->after_wps = 0; |
| 1967 | wpa_s->known_wps_freq = 0; |
| 1968 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 1969 | |
| 1970 | return 1; |
| 1971 | } |
| 1972 | |
| 1973 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1974 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1975 | struct wpa_bss *selected, |
| 1976 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1977 | { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 1978 | #ifdef IEEE8021X_EAPOL |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1979 | if ((eap_is_wps_pbc_enrollee(&ssid->eap) && |
| 1980 | wpas_wps_partner_link_overlap_detect(wpa_s)) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1981 | wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1982 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP |
| 1983 | "PBC session overlap"); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1984 | wpas_notify_wps_event_pbc_overlap(wpa_s); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1985 | wpa_s->wps_overlap = true; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1986 | #ifdef CONFIG_P2P |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1987 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 1988 | wpa_s->p2p_in_provisioning) { |
| 1989 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, |
| 1990 | wpa_s, NULL); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1991 | return -1; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1992 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1993 | #endif /* CONFIG_P2P */ |
| 1994 | |
| 1995 | #ifdef CONFIG_WPS |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1996 | wpas_wps_pbc_overlap(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1997 | wpas_wps_cancel(wpa_s); |
| 1998 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1999 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2000 | } |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 2001 | #endif /* IEEE8021X_EAPOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2002 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2003 | wpa_msg(wpa_s, MSG_DEBUG, |
| 2004 | "Considering connect request: reassociate: %d selected: " |
| 2005 | MACSTR " bssid: " MACSTR " pending: " MACSTR |
| 2006 | " wpa_state: %s ssid=%p current_ssid=%p", |
| 2007 | wpa_s->reassociate, MAC2STR(selected->bssid), |
| 2008 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), |
| 2009 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
| 2010 | ssid, wpa_s->current_ssid); |
| 2011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2012 | /* |
| 2013 | * Do not trigger new association unless the BSSID has changed or if |
| 2014 | * reassociation is requested. If we are in process of associating with |
| 2015 | * the selected BSSID, do not trigger new attempt. |
| 2016 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2017 | if (wpa_s->reassociate || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2018 | (!ether_addr_equal(selected->bssid, wpa_s->bssid) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2019 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
| 2020 | wpa_s->wpa_state != WPA_AUTHENTICATING) || |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2021 | (!is_zero_ether_addr(wpa_s->pending_bssid) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2022 | !ether_addr_equal(selected->bssid, wpa_s->pending_bssid)) || |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2023 | (is_zero_ether_addr(wpa_s->pending_bssid) && |
| 2024 | ssid != wpa_s->current_ssid)))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2025 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { |
| 2026 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2027 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2028 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2029 | |
| 2030 | if (wpa_supplicant_connect_ml_missing(wpa_s, selected, ssid)) |
| 2031 | return 0; |
| 2032 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2033 | wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, |
| 2034 | MAC2STR(selected->bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2035 | wpa_supplicant_associate(wpa_s, selected, ssid); |
| 2036 | } else { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 2037 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " |
| 2038 | "connect with the selected AP"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2039 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2040 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2041 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2042 | } |
| 2043 | |
| 2044 | |
| 2045 | static struct wpa_ssid * |
| 2046 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) |
| 2047 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2048 | size_t prio; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2049 | struct wpa_ssid *ssid; |
| 2050 | |
| 2051 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { |
| 2052 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) |
| 2053 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2054 | if (wpas_network_disabled(wpa_s, ssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2055 | continue; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2056 | #ifndef CONFIG_IBSS_RSN |
| 2057 | if (ssid->mode == WPAS_MODE_IBSS && |
| 2058 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | |
| 2059 | WPA_KEY_MGMT_WPA_NONE))) { |
| 2060 | wpa_msg(wpa_s, MSG_INFO, |
| 2061 | "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'", |
| 2062 | wpa_ssid_txt(ssid->ssid, |
| 2063 | ssid->ssid_len)); |
| 2064 | continue; |
| 2065 | } |
| 2066 | #endif /* !CONFIG_IBSS_RSN */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2067 | if (ssid->mode == WPAS_MODE_IBSS || |
| 2068 | ssid->mode == WPAS_MODE_AP || |
| 2069 | ssid->mode == WPAS_MODE_MESH) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2070 | return ssid; |
| 2071 | } |
| 2072 | } |
| 2073 | return NULL; |
| 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
| 2078 | * on BSS added and BSS changed events */ |
| 2079 | static void wpa_supplicant_rsn_preauth_scan_results( |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2080 | struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2081 | { |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2082 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2083 | |
| 2084 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) |
| 2085 | return; |
| 2086 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2087 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2088 | const u8 *ssid, *rsn; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2089 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2090 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2091 | if (ssid == NULL) |
| 2092 | continue; |
| 2093 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2094 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2095 | if (rsn == NULL) |
| 2096 | continue; |
| 2097 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 2098 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | } |
| 2102 | |
| 2103 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2104 | #ifndef CONFIG_NO_ROAMING |
| 2105 | |
| 2106 | static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise) |
| 2107 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2108 | if (noise == WPA_INVALID_NOISE) { |
| 2109 | if (IS_5GHZ(frequency)) { |
| 2110 | noise = DEFAULT_NOISE_FLOOR_5GHZ; |
| 2111 | } else if (is_6ghz_freq(frequency)) { |
| 2112 | noise = DEFAULT_NOISE_FLOOR_6GHZ; |
| 2113 | } else { |
| 2114 | noise = DEFAULT_NOISE_FLOOR_2GHZ; |
| 2115 | } |
| 2116 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2117 | return avg_signal - noise; |
| 2118 | } |
| 2119 | |
| 2120 | |
| 2121 | static unsigned int |
| 2122 | wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s, |
| 2123 | const struct wpa_bss *bss, int snr) |
| 2124 | { |
| 2125 | int rate = wpa_bss_get_max_rate(bss); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2126 | const u8 *ies = wpa_bss_ie_ptr(bss); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2127 | size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2128 | enum chan_width max_cw = CHAN_WIDTH_UNKNOWN; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2129 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2130 | return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq, |
| 2131 | &max_cw); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2132 | } |
| 2133 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2134 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2135 | static int wpas_evaluate_band_score(int frequency) |
| 2136 | { |
| 2137 | if (is_6ghz_freq(frequency)) |
| 2138 | return 2; |
| 2139 | if (IS_5GHZ(frequency)) |
| 2140 | return 1; |
| 2141 | return 0; |
| 2142 | } |
| 2143 | |
| 2144 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2145 | int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s, |
| 2146 | struct wpa_bss *current_bss, |
| 2147 | struct wpa_bss *selected) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2148 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2149 | int min_diff, diff; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2150 | int cur_band_score, sel_band_score; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2151 | int to_5ghz, to_6ghz; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2152 | int cur_level, sel_level; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2153 | unsigned int cur_est, sel_est; |
| 2154 | struct wpa_signal_info si; |
| 2155 | int cur_snr = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2156 | int ret = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2157 | const u8 *cur_ies = wpa_bss_ie_ptr(current_bss); |
| 2158 | const u8 *sel_ies = wpa_bss_ie_ptr(selected); |
| 2159 | size_t cur_ie_len = current_bss->ie_len ? current_bss->ie_len : |
| 2160 | current_bss->beacon_ie_len; |
| 2161 | size_t sel_ie_len = selected->ie_len ? selected->ie_len : |
| 2162 | selected->beacon_ie_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2164 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2165 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2166 | " freq=%d level=%d snr=%d est_throughput=%u", |
| 2167 | MAC2STR(current_bss->bssid), |
| 2168 | current_bss->freq, current_bss->level, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2169 | current_bss->snr, current_bss->est_throughput); |
| 2170 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2171 | " freq=%d level=%d snr=%d est_throughput=%u", |
| 2172 | MAC2STR(selected->bssid), selected->freq, selected->level, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2173 | selected->snr, selected->est_throughput); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2174 | |
| 2175 | if (wpa_s->current_ssid->bssid_set && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2176 | ether_addr_equal(selected->bssid, wpa_s->current_ssid->bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2177 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
| 2178 | "has preferred BSSID"); |
| 2179 | return 1; |
| 2180 | } |
| 2181 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2182 | /* |
| 2183 | * Try to poll the signal from the driver since this will allow to get |
| 2184 | * more accurate values. In some cases, there can be big differences |
| 2185 | * between the RSSI of the Probe Response frames of the AP we are |
| 2186 | * associated with and the Beacon frames we hear from the same AP after |
| 2187 | * association. This can happen, e.g., when there are two antennas that |
| 2188 | * hear the AP very differently. If the driver chooses to hear the |
| 2189 | * Probe Response frames during the scan on the "bad" antenna because |
| 2190 | * it wants to save power, but knows to choose the other antenna after |
| 2191 | * association, we will hear our AP with a low RSSI as part of the |
| 2192 | * scan even when we can hear it decently on the other antenna. To cope |
| 2193 | * with this, ask the driver to teach us how it hears the AP. Also, the |
| 2194 | * scan results may be a bit old, since we can very quickly get fresh |
| 2195 | * information about our currently associated AP. |
| 2196 | */ |
| 2197 | if (wpa_drv_signal_poll(wpa_s, &si) == 0 && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2198 | (si.data.avg_beacon_signal || si.data.avg_signal)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2199 | /* |
| 2200 | * Normalize avg_signal to the RSSI over 20 MHz, as the |
| 2201 | * throughput is estimated based on the RSSI over 20 MHz |
| 2202 | */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2203 | cur_level = si.data.avg_beacon_signal ? |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2204 | si.data.avg_beacon_signal : |
| 2205 | (si.data.avg_signal - |
| 2206 | wpas_channel_width_rssi_bump(cur_ies, cur_ie_len, |
| 2207 | si.chanwidth)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2208 | cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level, |
| 2209 | si.current_noise); |
| 2210 | |
| 2211 | cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s, |
| 2212 | current_bss, |
| 2213 | cur_snr); |
| 2214 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2215 | "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u", |
| 2216 | cur_level, cur_snr, cur_est); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2217 | } else { |
| 2218 | /* Level and SNR are measured over 20 MHz channel */ |
| 2219 | cur_level = current_bss->level; |
| 2220 | cur_snr = current_bss->snr; |
| 2221 | cur_est = current_bss->est_throughput; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2222 | } |
| 2223 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2224 | /* Adjust the SNR of BSSes based on the channel width. */ |
| 2225 | cur_level += wpas_channel_width_rssi_bump(cur_ies, cur_ie_len, |
| 2226 | current_bss->max_cw); |
| 2227 | cur_snr = wpas_adjust_snr_by_chanwidth(cur_ies, cur_ie_len, |
| 2228 | current_bss->max_cw, cur_snr); |
| 2229 | |
| 2230 | sel_est = selected->est_throughput; |
| 2231 | sel_level = selected->level + |
| 2232 | wpas_channel_width_rssi_bump(sel_ies, sel_ie_len, |
| 2233 | selected->max_cw); |
| 2234 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2235 | if (sel_est > cur_est + 5000) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2236 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2237 | "Allow reassociation - selected BSS has better estimated throughput"); |
| 2238 | return 1; |
| 2239 | } |
| 2240 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2241 | to_5ghz = selected->freq > 4000 && current_bss->freq < 4000; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2242 | to_6ghz = is_6ghz_freq(selected->freq) && |
| 2243 | !is_6ghz_freq(current_bss->freq); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2244 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2245 | if (cur_level < 0 && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2246 | cur_level > sel_level + to_5ghz * 2 + to_6ghz * 2 && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2247 | sel_est < cur_est * 1.2) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2248 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " |
| 2249 | "signal level"); |
| 2250 | return 0; |
| 2251 | } |
| 2252 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2253 | if (cur_est > sel_est + 5000) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2254 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2255 | "Skip roam - Current BSS has better estimated throughput"); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2256 | return 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2257 | } |
| 2258 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2259 | if (cur_snr > GREAT_SNR) { |
| 2260 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2261 | "Skip roam - Current BSS has good SNR (%u > %u)", |
| 2262 | cur_snr, GREAT_SNR); |
| 2263 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2265 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2266 | if (cur_level < -85) /* ..-86 dBm */ |
| 2267 | min_diff = 1; |
| 2268 | else if (cur_level < -80) /* -85..-81 dBm */ |
| 2269 | min_diff = 2; |
| 2270 | else if (cur_level < -75) /* -80..-76 dBm */ |
| 2271 | min_diff = 3; |
| 2272 | else if (cur_level < -70) /* -75..-71 dBm */ |
| 2273 | min_diff = 4; |
| 2274 | else if (cur_level < 0) /* -70..-1 dBm */ |
| 2275 | min_diff = 5; |
| 2276 | else /* unspecified units (not in dBm) */ |
| 2277 | min_diff = 2; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2278 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2279 | if (cur_est > sel_est * 1.5) |
| 2280 | min_diff += 10; |
| 2281 | else if (cur_est > sel_est * 1.2) |
| 2282 | min_diff += 5; |
| 2283 | else if (cur_est > sel_est * 1.1) |
| 2284 | min_diff += 2; |
| 2285 | else if (cur_est > sel_est) |
| 2286 | min_diff++; |
| 2287 | else if (sel_est > cur_est * 1.5) |
| 2288 | min_diff -= 10; |
| 2289 | else if (sel_est > cur_est * 1.2) |
| 2290 | min_diff -= 5; |
| 2291 | else if (sel_est > cur_est * 1.1) |
| 2292 | min_diff -= 2; |
| 2293 | else if (sel_est > cur_est) |
| 2294 | min_diff--; |
| 2295 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2296 | cur_band_score = wpas_evaluate_band_score(current_bss->freq); |
| 2297 | sel_band_score = wpas_evaluate_band_score(selected->freq); |
| 2298 | min_diff += (cur_band_score - sel_band_score) * 2; |
| 2299 | if (wpa_s->signal_threshold && cur_level <= wpa_s->signal_threshold && |
| 2300 | sel_level > wpa_s->signal_threshold) |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2301 | min_diff -= 2; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2302 | diff = sel_level - cur_level; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2303 | if (diff < min_diff) { |
| 2304 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2305 | "Skip roam - too small difference in signal level (%d < %d)", |
| 2306 | diff, min_diff); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2307 | ret = 0; |
| 2308 | } else { |
| 2309 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2310 | "Allow reassociation due to difference in signal level (%d >= %d)", |
| 2311 | diff, min_diff); |
| 2312 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2313 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2314 | wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR |
| 2315 | " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR |
| 2316 | " sel_freq=%d sel_level=%d sel_est=%d", |
| 2317 | ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM, |
| 2318 | MAC2STR(current_bss->bssid), |
| 2319 | current_bss->freq, cur_level, cur_est, |
| 2320 | MAC2STR(selected->bssid), |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2321 | selected->freq, sel_level, sel_est); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2322 | return ret; |
| 2323 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2324 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2325 | #endif /* CONFIG_NO_ROAMING */ |
| 2326 | |
| 2327 | |
| 2328 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
| 2329 | struct wpa_bss *selected, |
| 2330 | struct wpa_ssid *ssid) |
| 2331 | { |
| 2332 | struct wpa_bss *current_bss = NULL; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2333 | const u8 *bssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2334 | |
| 2335 | if (wpa_s->reassociate) |
| 2336 | return 1; /* explicit request to reassociate */ |
| 2337 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 2338 | return 1; /* we are not associated; continue */ |
| 2339 | if (wpa_s->current_ssid == NULL) |
| 2340 | return 1; /* unknown current SSID */ |
| 2341 | if (wpa_s->current_ssid != ssid) |
| 2342 | return 1; /* different network block */ |
| 2343 | |
| 2344 | if (wpas_driver_bss_selection(wpa_s)) |
| 2345 | return 0; /* Driver-based roaming */ |
| 2346 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2347 | if (wpa_s->valid_links) |
| 2348 | bssid = wpa_s->links[wpa_s->mlo_assoc_link_id].bssid; |
| 2349 | else |
| 2350 | bssid = wpa_s->bssid; |
| 2351 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2352 | if (wpa_s->current_ssid->ssid) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2353 | current_bss = wpa_bss_get(wpa_s, bssid, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2354 | wpa_s->current_ssid->ssid, |
| 2355 | wpa_s->current_ssid->ssid_len); |
| 2356 | if (!current_bss) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2357 | current_bss = wpa_bss_get_bssid(wpa_s, bssid); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2358 | |
| 2359 | if (!current_bss) |
| 2360 | return 1; /* current BSS not seen in scan results */ |
| 2361 | |
| 2362 | if (current_bss == selected) |
| 2363 | return 0; |
| 2364 | |
| 2365 | if (selected->last_update_idx > current_bss->last_update_idx) |
| 2366 | return 1; /* current BSS not seen in the last scan */ |
| 2367 | |
| 2368 | #ifndef CONFIG_NO_ROAMING |
| 2369 | return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss, |
| 2370 | selected); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2371 | #else /* CONFIG_NO_ROAMING */ |
Dmitry Shmidt | efdec2e | 2011-08-16 11:55:46 -0700 | [diff] [blame] | 2372 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2373 | #endif /* CONFIG_NO_ROAMING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2374 | } |
| 2375 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2376 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2377 | /* |
| 2378 | * Return a negative value if no scan results could be fetched or if scan |
| 2379 | * results should not be shared with other virtual interfaces. |
| 2380 | * Return 0 if scan results were fetched and may be shared with other |
| 2381 | * interfaces. |
| 2382 | * Return 1 if scan results may be shared with other virtual interfaces but may |
| 2383 | * not trigger any operations. |
| 2384 | * Return 2 if the interface was removed and cannot be used. |
| 2385 | */ |
Dmitry Shmidt | f6c92c4 | 2012-01-26 12:57:43 -0800 | [diff] [blame] | 2386 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 2387 | union wpa_event_data *data, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2388 | int own_request, int update_only) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2389 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2390 | struct wpa_scan_results *scan_res = NULL; |
| 2391 | int ret = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2392 | int ap = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2393 | bool trigger_6ghz_scan; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2394 | #ifndef CONFIG_NO_RANDOM_POOL |
| 2395 | size_t i, num; |
| 2396 | #endif /* CONFIG_NO_RANDOM_POOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2397 | |
| 2398 | #ifdef CONFIG_AP |
| 2399 | if (wpa_s->ap_iface) |
| 2400 | ap = 1; |
| 2401 | #endif /* CONFIG_AP */ |
| 2402 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2403 | trigger_6ghz_scan = wpa_s->crossed_6ghz_dom && |
| 2404 | wpa_s->last_scan_all_chan; |
| 2405 | wpa_s->crossed_6ghz_dom = false; |
| 2406 | wpa_s->last_scan_all_chan = false; |
| 2407 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2408 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 2409 | |
| 2410 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
| 2411 | data ? &data->scan_info : |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2412 | NULL, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2413 | if (scan_res == NULL) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2414 | if (wpa_s->conf->ap_scan == 2 || ap || |
| 2415 | wpa_s->scan_res_handler == scan_only_handler) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2416 | return -1; |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 2417 | if (!own_request) |
| 2418 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2419 | if (data && data->scan_info.external_scan) |
| 2420 | return -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2421 | if (wpa_s->scan_res_fail_handler) { |
| 2422 | void (*handler)(struct wpa_supplicant *wpa_s); |
| 2423 | |
| 2424 | handler = wpa_s->scan_res_fail_handler; |
| 2425 | wpa_s->scan_res_fail_handler = NULL; |
| 2426 | handler(wpa_s); |
| 2427 | } else { |
| 2428 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2429 | "Failed to get scan results - try scanning again"); |
| 2430 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
| 2431 | } |
| 2432 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2433 | ret = -1; |
| 2434 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
| 2437 | #ifndef CONFIG_NO_RANDOM_POOL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2438 | num = scan_res->num; |
| 2439 | if (num > 10) |
| 2440 | num = 10; |
| 2441 | for (i = 0; i < num; i++) { |
| 2442 | u8 buf[5]; |
| 2443 | struct wpa_scan_res *res = scan_res->res[i]; |
| 2444 | buf[0] = res->bssid[5]; |
| 2445 | buf[1] = res->qual & 0xff; |
| 2446 | buf[2] = res->noise & 0xff; |
| 2447 | buf[3] = res->level & 0xff; |
| 2448 | buf[4] = res->tsf & 0xff; |
| 2449 | random_add_randomness(buf, sizeof(buf)); |
| 2450 | } |
| 2451 | #endif /* CONFIG_NO_RANDOM_POOL */ |
| 2452 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2453 | if (update_only) { |
| 2454 | ret = 1; |
| 2455 | goto scan_work_done; |
| 2456 | } |
| 2457 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2458 | if (own_request && wpa_s->scan_res_handler && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2459 | !(data && data->scan_info.external_scan)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2460 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
| 2461 | struct wpa_scan_results *scan_res); |
| 2462 | |
| 2463 | scan_res_handler = wpa_s->scan_res_handler; |
| 2464 | wpa_s->scan_res_handler = NULL; |
| 2465 | scan_res_handler(wpa_s, scan_res); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2466 | ret = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2467 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2468 | } |
| 2469 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2470 | wpa_dbg(wpa_s, MSG_DEBUG, "New scan results available (own=%u ext=%u)", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2471 | wpa_s->own_scan_running, |
| 2472 | data ? data->scan_info.external_scan : 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2473 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2474 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running && |
| 2475 | own_request && !(data && data->scan_info.external_scan)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2476 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", |
| 2477 | wpa_s->manual_scan_id); |
| 2478 | wpa_s->manual_scan_use_id = 0; |
| 2479 | } else { |
| 2480 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
| 2481 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2482 | wpas_notify_scan_results(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2483 | |
| 2484 | wpas_notify_scan_done(wpa_s, 1); |
| 2485 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2486 | if (ap) { |
| 2487 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
| 2488 | #ifdef CONFIG_AP |
| 2489 | if (wpa_s->ap_iface->scan_cb) |
| 2490 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); |
| 2491 | #endif /* CONFIG_AP */ |
| 2492 | goto scan_work_done; |
| 2493 | } |
| 2494 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2495 | if (data && data->scan_info.external_scan) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2496 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not use results from externally requested scan operation for network selection"); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2497 | wpa_scan_results_free(scan_res); |
| 2498 | return 0; |
| 2499 | } |
| 2500 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2501 | if (wnm_scan_process(wpa_s, 1) > 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2502 | goto scan_work_done; |
| 2503 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2504 | if (sme_proc_obss_scan(wpa_s) > 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2505 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2506 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2507 | #ifndef CONFIG_NO_RRM |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2508 | if (own_request && data && |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2509 | wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0) |
| 2510 | goto scan_work_done; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 2511 | #endif /* CONFIG_NO_RRM */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2512 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2513 | if (ml_link_probe_scan(wpa_s)) |
| 2514 | goto scan_work_done; |
| 2515 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2516 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
| 2517 | goto scan_work_done; |
| 2518 | |
| 2519 | if (autoscan_notify_scan(wpa_s, scan_res)) |
| 2520 | goto scan_work_done; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2521 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2522 | if (wpa_s->disconnected) { |
| 2523 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2524 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2525 | } |
| 2526 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2527 | if (!wpas_driver_bss_selection(wpa_s) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2528 | bgscan_notify_scan(wpa_s, scan_res) == 1) |
| 2529 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2530 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2531 | wpas_wps_update_ap_info(wpa_s, scan_res); |
| 2532 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2533 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING && |
| 2534 | wpa_s->wpa_state < WPA_COMPLETED) |
| 2535 | goto scan_work_done; |
| 2536 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2537 | wpa_scan_results_free(scan_res); |
| 2538 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2539 | if (own_request && wpa_s->scan_work) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2540 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 2541 | wpa_s->scan_work = NULL; |
| 2542 | radio_work_done(work); |
| 2543 | } |
| 2544 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2545 | os_free(wpa_s->last_scan_freqs); |
| 2546 | wpa_s->last_scan_freqs = NULL; |
| 2547 | wpa_s->num_last_scan_freqs = 0; |
| 2548 | if (own_request && data && |
| 2549 | data->scan_info.freqs && data->scan_info.num_freqs) { |
| 2550 | wpa_s->last_scan_freqs = os_malloc(sizeof(int) * |
| 2551 | data->scan_info.num_freqs); |
| 2552 | if (wpa_s->last_scan_freqs) { |
| 2553 | os_memcpy(wpa_s->last_scan_freqs, |
| 2554 | data->scan_info.freqs, |
| 2555 | sizeof(int) * data->scan_info.num_freqs); |
| 2556 | wpa_s->num_last_scan_freqs = data->scan_info.num_freqs; |
| 2557 | } |
| 2558 | } |
| 2559 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2560 | if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s)) |
| 2561 | return ret; |
| 2562 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2563 | return wpas_select_network_from_last_scan(wpa_s, 1, own_request, |
| 2564 | trigger_6ghz_scan, data); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2565 | |
| 2566 | scan_work_done: |
| 2567 | wpa_scan_results_free(scan_res); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2568 | if (own_request && wpa_s->scan_work) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2569 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 2570 | wpa_s->scan_work = NULL; |
| 2571 | radio_work_done(work); |
| 2572 | } |
| 2573 | return ret; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2577 | static int wpas_trigger_6ghz_scan(struct wpa_supplicant *wpa_s, |
| 2578 | union wpa_event_data *data) |
| 2579 | { |
| 2580 | struct wpa_driver_scan_params params; |
| 2581 | unsigned int j; |
| 2582 | |
| 2583 | wpa_dbg(wpa_s, MSG_INFO, "Triggering 6GHz-only scan"); |
| 2584 | os_memset(¶ms, 0, sizeof(params)); |
| 2585 | params.non_coloc_6ghz = wpa_s->last_scan_non_coloc_6ghz; |
| 2586 | for (j = 0; j < data->scan_info.num_ssids; j++) |
| 2587 | params.ssids[j] = data->scan_info.ssids[j]; |
| 2588 | params.num_ssids = data->scan_info.num_ssids; |
| 2589 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, ¶ms, |
| 2590 | true, !wpa_s->last_scan_non_coloc_6ghz, false); |
| 2591 | if (!wpa_supplicant_trigger_scan(wpa_s, ¶ms, true, true)) { |
| 2592 | os_free(params.freqs); |
| 2593 | return 1; |
| 2594 | } |
| 2595 | wpa_dbg(wpa_s, MSG_INFO, "Failed to trigger 6GHz-only scan"); |
| 2596 | os_free(params.freqs); |
| 2597 | return 0; |
| 2598 | } |
| 2599 | |
| 2600 | |
| 2601 | /** |
| 2602 | * Select a network from the last scan |
| 2603 | * @wpa_s: Pointer to wpa_supplicant data |
| 2604 | * @new_scan: Whether this function was called right after a scan has finished |
| 2605 | * @own_request: Whether the scan was requested by this interface |
| 2606 | * @trigger_6ghz_scan: Whether to trigger a 6ghz-only scan when applicable |
| 2607 | * @data: Scan data from scan that finished if applicable |
| 2608 | * |
| 2609 | * See _wpa_supplicant_event_scan_results() for return values. |
| 2610 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2611 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2612 | int new_scan, int own_request, |
| 2613 | bool trigger_6ghz_scan, |
| 2614 | union wpa_event_data *data) |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2615 | { |
| 2616 | struct wpa_bss *selected; |
| 2617 | struct wpa_ssid *ssid = NULL; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 2618 | int time_to_reenable = wpas_reenabled_network_time(wpa_s); |
| 2619 | |
| 2620 | if (time_to_reenable > 0) { |
| 2621 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2622 | "Postpone network selection by %d seconds since all networks are disabled", |
| 2623 | time_to_reenable); |
| 2624 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
| 2625 | eloop_register_timeout(time_to_reenable, 0, |
| 2626 | wpas_network_reenabled, wpa_s, NULL); |
| 2627 | return 0; |
| 2628 | } |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2629 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2630 | if (wpa_s->p2p_mgmt) |
| 2631 | return 0; /* no normal connection on p2p_mgmt interface */ |
| 2632 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2633 | wpa_s->owe_transition_search = 0; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2634 | #ifdef CONFIG_OWE |
| 2635 | os_free(wpa_s->owe_trans_scan_freq); |
| 2636 | wpa_s->owe_trans_scan_freq = NULL; |
| 2637 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2638 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2639 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2640 | #ifdef CONFIG_MESH |
| 2641 | if (wpa_s->ifmsh) { |
| 2642 | wpa_msg(wpa_s, MSG_INFO, |
| 2643 | "Avoiding join because we already joined a mesh group"); |
| 2644 | return 0; |
| 2645 | } |
| 2646 | #endif /* CONFIG_MESH */ |
| 2647 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2648 | if (selected) { |
| 2649 | int skip; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2650 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2651 | if (skip) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2652 | if (new_scan) |
| 2653 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2654 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2655 | } |
| 2656 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2657 | wpa_s->suitable_network++; |
| 2658 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2659 | if (ssid != wpa_s->current_ssid && |
| 2660 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 2661 | wpa_s->own_disconnect_req = 1; |
| 2662 | wpa_supplicant_deauthenticate( |
| 2663 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2664 | } |
| 2665 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2666 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2667 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2668 | return -1; |
| 2669 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2670 | wpa_s->supp_pbc_active = false; |
| 2671 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2672 | if (new_scan) |
| 2673 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2674 | /* |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2675 | * Do not allow other virtual radios to trigger operations based |
| 2676 | * on these scan results since we do not want them to start |
| 2677 | * other associations at the same time. |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2678 | */ |
| 2679 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2680 | } else { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2681 | wpa_s->no_suitable_network++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2682 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
| 2683 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
| 2684 | if (ssid) { |
| 2685 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
| 2686 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2687 | if (new_scan) |
| 2688 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2689 | } else if (own_request) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2690 | if (wpa_s->support_6ghz && trigger_6ghz_scan && data && |
| 2691 | wpas_trigger_6ghz_scan(wpa_s, data) < 0) |
| 2692 | return 1; |
| 2693 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2694 | /* |
| 2695 | * No SSID found. If SCAN results are as a result of |
| 2696 | * own scan request and not due to a scan request on |
| 2697 | * another shared interface, try another scan. |
| 2698 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2699 | int timeout_sec = wpa_s->scan_interval; |
| 2700 | int timeout_usec = 0; |
| 2701 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2702 | int res; |
| 2703 | |
| 2704 | res = wpas_p2p_scan_no_go_seen(wpa_s); |
| 2705 | if (res == 2) |
| 2706 | return 2; |
| 2707 | if (res == 1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2708 | return 0; |
| 2709 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2710 | if (wpas_p2p_retry_limit_exceeded(wpa_s)) |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2711 | return 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2712 | |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 2713 | if (wpa_s->p2p_in_provisioning || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 2714 | wpa_s->show_group_started || |
| 2715 | wpa_s->p2p_in_invitation) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2716 | /* |
| 2717 | * Use shorter wait during P2P Provisioning |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 2718 | * state and during P2P join-a-group operation |
| 2719 | * to speed up group formation. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2720 | */ |
| 2721 | timeout_sec = 0; |
| 2722 | timeout_usec = 250000; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2723 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2724 | timeout_usec); |
| 2725 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2726 | } |
| 2727 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2728 | #ifdef CONFIG_INTERWORKING |
| 2729 | if (wpa_s->conf->auto_interworking && |
| 2730 | wpa_s->conf->interworking && |
| 2731 | wpa_s->conf->cred) { |
| 2732 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " |
| 2733 | "start ANQP fetch since no matching " |
| 2734 | "networks found"); |
| 2735 | wpa_s->network_select = 1; |
| 2736 | wpa_s->auto_network_select = 1; |
| 2737 | interworking_start_fetch_anqp(wpa_s); |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2738 | return 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2739 | } |
| 2740 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2741 | #ifdef CONFIG_WPS |
| 2742 | if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) { |
| 2743 | wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing"); |
| 2744 | timeout_sec = 0; |
| 2745 | timeout_usec = 500000; |
| 2746 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2747 | timeout_usec); |
| 2748 | return 0; |
| 2749 | } |
| 2750 | #endif /* CONFIG_WPS */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2751 | #ifdef CONFIG_OWE |
| 2752 | if (wpa_s->owe_transition_search) { |
| 2753 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2754 | "OWE: Use shorter wait during transition mode search"); |
| 2755 | timeout_sec = 0; |
| 2756 | timeout_usec = 500000; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2757 | if (wpa_s->owe_trans_scan_freq) { |
| 2758 | os_free(wpa_s->next_scan_freqs); |
| 2759 | wpa_s->next_scan_freqs = |
| 2760 | wpa_s->owe_trans_scan_freq; |
| 2761 | wpa_s->owe_trans_scan_freq = NULL; |
| 2762 | timeout_usec = 100000; |
| 2763 | } |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2764 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2765 | timeout_usec); |
| 2766 | return 0; |
| 2767 | } |
| 2768 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2769 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
| 2770 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2771 | timeout_usec); |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 2772 | |
| 2773 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 2774 | WPA_EVENT_NETWORK_NOT_FOUND); |
Sunil Ravi | 07c1762 | 2021-01-11 12:00:53 -0800 | [diff] [blame] | 2775 | wpas_notify_network_not_found(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2776 | } |
| 2777 | } |
| 2778 | return 0; |
| 2779 | } |
| 2780 | |
| 2781 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2782 | static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
| 2783 | union wpa_event_data *data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2784 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2786 | int res; |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 2787 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2788 | res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2789 | if (res == 2) { |
| 2790 | /* |
| 2791 | * Interface may have been removed, so must not dereference |
| 2792 | * wpa_s after this. |
| 2793 | */ |
| 2794 | return 1; |
| 2795 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2796 | |
| 2797 | if (res < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | /* |
| 2799 | * If no scan results could be fetched, then no need to |
| 2800 | * notify those interfaces that did not actually request |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2801 | * this scan. Similarly, if scan results started a new operation on this |
| 2802 | * interface, do not notify other interfaces to avoid concurrent |
| 2803 | * operations during a connection attempt. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2804 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2805 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
| 2808 | /* |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2809 | * Check other interfaces to see if they share the same radio. If |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | * so, they get updated with this same scan info. |
| 2811 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2812 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 2813 | radio_list) { |
| 2814 | if (ifs != wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " |
| 2816 | "sibling", ifs->ifname); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2817 | res = _wpa_supplicant_event_scan_results(ifs, data, 0, |
| 2818 | res > 0); |
| 2819 | if (res < 0) |
| 2820 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2821 | } |
| 2822 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2823 | |
| 2824 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 2828 | |
| 2829 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2830 | int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
| 2831 | { |
| 2832 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 2833 | return -1; |
| 2834 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2835 | struct os_reltime now; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2836 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2837 | wpa_s->ignore_post_flush_scan_res = 0; |
| 2838 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 2839 | if (wpa_s->last_scan_res_used == 0) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2840 | return -1; |
| 2841 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2842 | os_get_reltime(&now); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2843 | if (os_reltime_expired(&now, &wpa_s->last_scan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2844 | wpa_s->conf->scan_res_valid_for_connect)) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2845 | wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); |
| 2846 | return -1; |
| 2847 | } |
| 2848 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2849 | return wpas_select_network_from_last_scan(wpa_s, 0, 1, false, NULL); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2850 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 2851 | } |
| 2852 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2853 | |
| 2854 | int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
| 2855 | { |
| 2856 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 2857 | return -1; |
| 2858 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2859 | return wpas_select_network_from_last_scan(wpa_s, 1, 1, false, NULL); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2860 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 2861 | } |
| 2862 | |
| 2863 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2864 | #ifdef CONFIG_WNM |
| 2865 | |
| 2866 | static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) |
| 2867 | { |
| 2868 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2869 | |
| 2870 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 2871 | return; |
| 2872 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2873 | if (!wpa_s->no_keep_alive) { |
| 2874 | wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, |
| 2875 | MAC2STR(wpa_s->bssid)); |
| 2876 | /* TODO: could skip this if normal data traffic has been sent */ |
| 2877 | /* TODO: Consider using some more appropriate data frame for |
| 2878 | * this */ |
| 2879 | if (wpa_s->l2) |
| 2880 | l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, |
| 2881 | (u8 *) "", 0); |
| 2882 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2883 | |
| 2884 | #ifdef CONFIG_SME |
| 2885 | if (wpa_s->sme.bss_max_idle_period) { |
| 2886 | unsigned int msec; |
| 2887 | msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ |
| 2888 | if (msec > 100) |
| 2889 | msec -= 100; |
| 2890 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, |
| 2891 | wnm_bss_keep_alive, wpa_s, NULL); |
| 2892 | } |
| 2893 | #endif /* CONFIG_SME */ |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 2898 | const u8 *ies, size_t ies_len) |
| 2899 | { |
| 2900 | struct ieee802_11_elems elems; |
| 2901 | |
| 2902 | if (ies == NULL) |
| 2903 | return; |
| 2904 | |
| 2905 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) |
| 2906 | return; |
| 2907 | |
| 2908 | #ifdef CONFIG_SME |
| 2909 | if (elems.bss_max_idle_period) { |
| 2910 | unsigned int msec; |
| 2911 | wpa_s->sme.bss_max_idle_period = |
| 2912 | WPA_GET_LE16(elems.bss_max_idle_period); |
| 2913 | wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " |
| 2914 | "TU)%s", wpa_s->sme.bss_max_idle_period, |
| 2915 | (elems.bss_max_idle_period[2] & 0x01) ? |
| 2916 | " (protected keep-live required)" : ""); |
| 2917 | if (wpa_s->sme.bss_max_idle_period == 0) |
| 2918 | wpa_s->sme.bss_max_idle_period = 1; |
| 2919 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { |
| 2920 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); |
| 2921 | /* msec times 1000 */ |
| 2922 | msec = wpa_s->sme.bss_max_idle_period * 1024; |
| 2923 | if (msec > 100) |
| 2924 | msec -= 100; |
| 2925 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, |
| 2926 | wnm_bss_keep_alive, wpa_s, |
| 2927 | NULL); |
| 2928 | } |
| 2929 | } |
| 2930 | #endif /* CONFIG_SME */ |
| 2931 | } |
| 2932 | |
| 2933 | #endif /* CONFIG_WNM */ |
| 2934 | |
| 2935 | |
| 2936 | void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) |
| 2937 | { |
| 2938 | #ifdef CONFIG_WNM |
| 2939 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); |
| 2940 | #endif /* CONFIG_WNM */ |
| 2941 | } |
| 2942 | |
| 2943 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2944 | #ifdef CONFIG_INTERWORKING |
| 2945 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2946 | static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map, |
| 2947 | size_t len) |
| 2948 | { |
| 2949 | int res; |
| 2950 | |
| 2951 | wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len); |
| 2952 | res = wpa_drv_set_qos_map(wpa_s, qos_map, len); |
| 2953 | if (res) { |
| 2954 | wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver"); |
| 2955 | } |
| 2956 | |
| 2957 | return res; |
| 2958 | } |
| 2959 | |
| 2960 | |
| 2961 | static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 2962 | const u8 *ies, size_t ies_len) |
| 2963 | { |
| 2964 | struct ieee802_11_elems elems; |
| 2965 | |
| 2966 | if (ies == NULL) |
| 2967 | return; |
| 2968 | |
| 2969 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) |
| 2970 | return; |
| 2971 | |
| 2972 | if (elems.qos_map_set) { |
| 2973 | wpas_qos_map_set(wpa_s, elems.qos_map_set, |
| 2974 | elems.qos_map_set_len); |
| 2975 | } |
| 2976 | } |
| 2977 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 2978 | #endif /* CONFIG_INTERWORKING */ |
| 2979 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2980 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2981 | static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s) |
| 2982 | { |
| 2983 | if (wpa_s->enabled_4addr_mode) { |
| 2984 | wpa_printf(MSG_DEBUG, "4addr mode already set"); |
| 2985 | return; |
| 2986 | } |
| 2987 | |
| 2988 | if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) { |
| 2989 | wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode"); |
| 2990 | goto fail; |
| 2991 | } |
| 2992 | wpa_s->enabled_4addr_mode = 1; |
| 2993 | wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode"); |
| 2994 | return; |
| 2995 | |
| 2996 | fail: |
| 2997 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2998 | } |
| 2999 | |
| 3000 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3001 | static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 3002 | const u8 *ies, size_t ies_len) |
| 3003 | { |
| 3004 | struct ieee802_11_elems elems; |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3005 | const u8 *map_sub_elem, *pos; |
| 3006 | size_t len; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3007 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3008 | wpa_s->multi_ap_ie = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3009 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3010 | if (!ies || |
| 3011 | ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed || |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3012 | !elems.multi_ap || elems.multi_ap_len < 7) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3013 | return; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3014 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3015 | pos = elems.multi_ap + 4; |
| 3016 | len = elems.multi_ap_len - 4; |
| 3017 | |
| 3018 | map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE); |
| 3019 | if (!map_sub_elem || map_sub_elem[1] < 1) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3020 | return; |
| 3021 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3022 | wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS); |
| 3023 | wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] & |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3024 | MULTI_AP_FRONTHAUL_BSS); |
| 3025 | wpa_s->multi_ap_ie = 1; |
| 3026 | } |
| 3027 | |
| 3028 | |
| 3029 | static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s) |
| 3030 | { |
| 3031 | if (!wpa_s->current_ssid || |
| 3032 | !wpa_s->current_ssid->multi_ap_backhaul_sta) |
| 3033 | return; |
| 3034 | |
| 3035 | if (!wpa_s->multi_ap_ie) { |
| 3036 | wpa_printf(MSG_INFO, |
| 3037 | "AP does not include valid Multi-AP element"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3038 | goto fail; |
| 3039 | } |
| 3040 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3041 | if (!wpa_s->multi_ap_backhaul) { |
| 3042 | if (wpa_s->multi_ap_fronthaul && |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3043 | wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
| 3044 | wpa_printf(MSG_INFO, |
| 3045 | "WPS active, accepting fronthaul-only BSS"); |
| 3046 | /* Don't set 4addr mode in this case, so just return */ |
| 3047 | return; |
| 3048 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3049 | wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS"); |
| 3050 | goto fail; |
| 3051 | } |
| 3052 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3053 | wpa_supplicant_set_4addr_mode(wpa_s); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3054 | return; |
| 3055 | |
| 3056 | fail: |
| 3057 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3058 | } |
| 3059 | |
| 3060 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3061 | #ifdef CONFIG_FST |
| 3062 | static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s, |
| 3063 | const u8 *ie, size_t ie_len) |
| 3064 | { |
| 3065 | struct mb_ies_info mb_ies; |
| 3066 | |
| 3067 | if (!ie || !ie_len || !wpa_s->fst) |
| 3068 | return -ENOENT; |
| 3069 | |
| 3070 | os_memset(&mb_ies, 0, sizeof(mb_ies)); |
| 3071 | |
| 3072 | while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) { |
| 3073 | size_t len; |
| 3074 | |
| 3075 | len = 2 + ie[1]; |
| 3076 | if (len > ie_len) { |
| 3077 | wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found", |
| 3078 | ie, ie_len); |
| 3079 | break; |
| 3080 | } |
| 3081 | |
| 3082 | if (ie[0] == WLAN_EID_MULTI_BAND) { |
| 3083 | wpa_printf(MSG_DEBUG, "MB IE of %u bytes found", |
| 3084 | (unsigned int) len); |
| 3085 | mb_ies.ies[mb_ies.nof_ies].ie = ie + 2; |
| 3086 | mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2; |
| 3087 | mb_ies.nof_ies++; |
| 3088 | } |
| 3089 | |
| 3090 | ie_len -= len; |
| 3091 | ie += len; |
| 3092 | } |
| 3093 | |
| 3094 | if (mb_ies.nof_ies > 0) { |
| 3095 | wpabuf_free(wpa_s->received_mb_ies); |
| 3096 | wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies); |
| 3097 | return 0; |
| 3098 | } |
| 3099 | |
| 3100 | return -ENOENT; |
| 3101 | } |
| 3102 | #endif /* CONFIG_FST */ |
| 3103 | |
| 3104 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3105 | static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s, |
| 3106 | union wpa_event_data *data) |
| 3107 | { |
| 3108 | int sel; |
| 3109 | const u8 *p; |
| 3110 | int l, len; |
| 3111 | bool found = false; |
| 3112 | struct wpa_ie_data ie; |
| 3113 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 3114 | struct wpa_bss *bss = wpa_s->current_bss; |
| 3115 | int pmf; |
| 3116 | |
| 3117 | if (!ssid) |
| 3118 | return 0; |
| 3119 | |
| 3120 | p = data->assoc_info.req_ies; |
| 3121 | l = data->assoc_info.req_ies_len; |
| 3122 | |
| 3123 | while (p && l >= 2) { |
| 3124 | len = p[1] + 2; |
| 3125 | if (len > l) { |
| 3126 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 3127 | p, l); |
| 3128 | break; |
| 3129 | } |
| 3130 | if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 3131 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || |
| 3132 | (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 && |
| 3133 | (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) || |
| 3134 | (p[0] == WLAN_EID_RSN && p[1] >= 2))) { |
| 3135 | found = true; |
| 3136 | break; |
| 3137 | } |
| 3138 | l -= len; |
| 3139 | p += len; |
| 3140 | } |
| 3141 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3142 | if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) { |
| 3143 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3144 | return 0; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3145 | } |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3146 | |
| 3147 | wpa_hexdump(MSG_DEBUG, |
| 3148 | "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq", |
| 3149 | p, l); |
| 3150 | |
| 3151 | /* Update proto from (Re)Association Request frame info */ |
| 3152 | wpa_s->wpa_proto = ie.proto; |
| 3153 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto); |
| 3154 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, |
| 3155 | !!(wpa_s->wpa_proto & |
| 3156 | (WPA_PROTO_RSN | WPA_PROTO_OSEN))); |
| 3157 | |
| 3158 | /* Update AKMP suite from (Re)Association Request frame info */ |
| 3159 | sel = ie.key_mgmt; |
| 3160 | if (ssid->key_mgmt) |
| 3161 | sel &= ssid->key_mgmt; |
| 3162 | |
| 3163 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3164 | "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x", |
| 3165 | ie.key_mgmt, ssid->key_mgmt, sel); |
| 3166 | if (ie.key_mgmt && !sel) { |
| 3167 | wpa_supplicant_deauthenticate( |
| 3168 | wpa_s, WLAN_REASON_AKMP_NOT_VALID); |
| 3169 | return -1; |
| 3170 | } |
| 3171 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3172 | #ifdef CONFIG_OCV |
| 3173 | if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || |
| 3174 | (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv) |
| 3175 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, |
| 3176 | !!(ie.capabilities & WPA_CAPABILITY_OCVC)); |
| 3177 | #endif /* CONFIG_OCV */ |
| 3178 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3179 | /* |
| 3180 | * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a |
| 3181 | * different AKM. |
| 3182 | */ |
| 3183 | if (wpa_s->key_mgmt != ie.key_mgmt && |
| 3184 | wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) { |
| 3185 | if (!ssid->psk_set) { |
| 3186 | wpa_dbg(wpa_s, MSG_INFO, |
| 3187 | "No PSK available for association"); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3188 | wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3189 | return -1; |
| 3190 | } |
| 3191 | |
| 3192 | wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL); |
| 3193 | if (wpa_s->conf->key_mgmt_offload && |
| 3194 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3195 | wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0, |
| 3196 | ssid->psk, PMK_LEN, KEY_FLAG_PMK)) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3197 | wpa_dbg(wpa_s, MSG_ERROR, |
| 3198 | "WPA: Cannot set PMK for key management offload"); |
| 3199 | } |
| 3200 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3201 | wpa_s->key_mgmt = ie.key_mgmt; |
| 3202 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
| 3203 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d", |
| 3204 | wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto), |
| 3205 | wpa_s->wpa_proto); |
| 3206 | |
| 3207 | /* Update pairwise cipher from (Re)Association Request frame info */ |
| 3208 | sel = ie.pairwise_cipher; |
| 3209 | if (ssid->pairwise_cipher) |
| 3210 | sel &= ssid->pairwise_cipher; |
| 3211 | |
| 3212 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3213 | "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x", |
| 3214 | ie.pairwise_cipher, ssid->pairwise_cipher, sel); |
| 3215 | if (ie.pairwise_cipher && !sel) { |
| 3216 | wpa_supplicant_deauthenticate( |
| 3217 | wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID); |
| 3218 | return -1; |
| 3219 | } |
| 3220 | |
| 3221 | wpa_s->pairwise_cipher = ie.pairwise_cipher; |
| 3222 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
| 3223 | wpa_s->pairwise_cipher); |
| 3224 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s", |
| 3225 | wpa_cipher_txt(wpa_s->pairwise_cipher)); |
| 3226 | |
| 3227 | /* Update other parameters based on AP's WPA IE/RSNE, if available */ |
| 3228 | if (!bss) { |
| 3229 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3230 | "WPA: current_bss == NULL - skip AP IE check"); |
| 3231 | return 0; |
| 3232 | } |
| 3233 | |
| 3234 | /* Update GTK and IGTK from AP's RSNE */ |
| 3235 | found = false; |
| 3236 | |
| 3237 | if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) { |
| 3238 | const u8 *bss_rsn; |
| 3239 | |
| 3240 | bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 3241 | if (bss_rsn) { |
| 3242 | p = bss_rsn; |
| 3243 | len = 2 + bss_rsn[1]; |
| 3244 | found = true; |
| 3245 | } |
| 3246 | } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) { |
| 3247 | const u8 *bss_wpa; |
| 3248 | |
| 3249 | bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 3250 | if (bss_wpa) { |
| 3251 | p = bss_wpa; |
| 3252 | len = 2 + bss_wpa[1]; |
| 3253 | found = true; |
| 3254 | } |
| 3255 | } |
| 3256 | |
| 3257 | if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) |
| 3258 | return 0; |
| 3259 | |
| 3260 | pmf = wpas_get_ssid_pmf(wpa_s, ssid); |
| 3261 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
| 3262 | pmf == MGMT_FRAME_PROTECTION_REQUIRED) { |
| 3263 | /* AP does not support MFP, local configuration requires it */ |
| 3264 | wpa_supplicant_deauthenticate( |
| 3265 | wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB); |
| 3266 | return -1; |
| 3267 | } |
| 3268 | if ((ie.capabilities & WPA_CAPABILITY_MFPR) && |
| 3269 | pmf == NO_MGMT_FRAME_PROTECTION) { |
| 3270 | /* AP requires MFP, local configuration disables it */ |
| 3271 | wpa_supplicant_deauthenticate( |
| 3272 | wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB); |
| 3273 | return -1; |
| 3274 | } |
| 3275 | |
| 3276 | /* Update PMF from local configuration now that MFP validation was done |
| 3277 | * above */ |
| 3278 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf); |
| 3279 | |
| 3280 | /* Update GTK from AP's RSNE */ |
| 3281 | sel = ie.group_cipher; |
| 3282 | if (ssid->group_cipher) |
| 3283 | sel &= ssid->group_cipher; |
| 3284 | |
| 3285 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3286 | "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x", |
| 3287 | ie.group_cipher, ssid->group_cipher, sel); |
| 3288 | if (ie.group_cipher && !sel) { |
| 3289 | wpa_supplicant_deauthenticate( |
| 3290 | wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID); |
| 3291 | return -1; |
| 3292 | } |
| 3293 | |
| 3294 | wpa_s->group_cipher = ie.group_cipher; |
| 3295 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); |
| 3296 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s", |
| 3297 | wpa_cipher_txt(wpa_s->group_cipher)); |
| 3298 | |
| 3299 | /* Update IGTK from AP RSN IE */ |
| 3300 | sel = ie.mgmt_group_cipher; |
| 3301 | if (ssid->group_mgmt_cipher) |
| 3302 | sel &= ssid->group_mgmt_cipher; |
| 3303 | |
| 3304 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3305 | "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x", |
| 3306 | ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel); |
| 3307 | |
| 3308 | if (pmf == NO_MGMT_FRAME_PROTECTION || |
| 3309 | !(ie.capabilities & WPA_CAPABILITY_MFPC)) { |
| 3310 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3311 | "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x", |
| 3312 | ie.capabilities); |
| 3313 | ie.mgmt_group_cipher = 0; |
| 3314 | } |
| 3315 | |
| 3316 | if (ie.mgmt_group_cipher && !sel) { |
| 3317 | wpa_supplicant_deauthenticate( |
| 3318 | wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED); |
| 3319 | return -1; |
| 3320 | } |
| 3321 | |
| 3322 | wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher; |
| 3323 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, |
| 3324 | wpa_s->mgmt_group_cipher); |
| 3325 | if (wpa_s->mgmt_group_cipher) |
| 3326 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s", |
| 3327 | wpa_cipher_txt(wpa_s->mgmt_group_cipher)); |
| 3328 | else |
| 3329 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher"); |
| 3330 | |
| 3331 | return 0; |
| 3332 | } |
| 3333 | |
| 3334 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3335 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
| 3336 | union wpa_event_data *data) |
| 3337 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3338 | int l, len, found = 0, found_x = 0, wpa_found, rsn_found; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3339 | const u8 *p; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3340 | u8 bssid[ETH_ALEN]; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3341 | bool bssid_known; |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3342 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3343 | struct wpa_ie_data ie; |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3344 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3345 | |
| 3346 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3347 | bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3348 | if (data->assoc_info.req_ies) |
| 3349 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, |
| 3350 | data->assoc_info.req_ies_len); |
| 3351 | if (data->assoc_info.resp_ies) { |
| 3352 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
| 3353 | data->assoc_info.resp_ies_len); |
| 3354 | #ifdef CONFIG_TDLS |
| 3355 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, |
| 3356 | data->assoc_info.resp_ies_len); |
| 3357 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3358 | #ifdef CONFIG_WNM |
| 3359 | wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 3360 | data->assoc_info.resp_ies_len); |
| 3361 | #endif /* CONFIG_WNM */ |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3362 | #ifdef CONFIG_INTERWORKING |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3363 | interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 3364 | data->assoc_info.resp_ies_len); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3365 | #endif /* CONFIG_INTERWORKING */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3366 | if (wpa_s->hw_capab == CAPAB_VHT && |
| 3367 | get_ie(data->assoc_info.resp_ies, |
| 3368 | data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP)) |
| 3369 | wpa_s->ieee80211ac = 1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3370 | |
| 3371 | multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 3372 | data->assoc_info.resp_ies_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3373 | } |
| 3374 | if (data->assoc_info.beacon_ies) |
| 3375 | wpa_hexdump(MSG_DEBUG, "beacon_ies", |
| 3376 | data->assoc_info.beacon_ies, |
| 3377 | data->assoc_info.beacon_ies_len); |
| 3378 | if (data->assoc_info.freq) |
| 3379 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
| 3380 | data->assoc_info.freq); |
| 3381 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3382 | wpa_s->connection_set = 0; |
| 3383 | if (data->assoc_info.req_ies && data->assoc_info.resp_ies) { |
| 3384 | struct ieee802_11_elems req_elems, resp_elems; |
| 3385 | |
| 3386 | if (ieee802_11_parse_elems(data->assoc_info.req_ies, |
| 3387 | data->assoc_info.req_ies_len, |
| 3388 | &req_elems, 0) != ParseFailed && |
| 3389 | ieee802_11_parse_elems(data->assoc_info.resp_ies, |
| 3390 | data->assoc_info.resp_ies_len, |
| 3391 | &resp_elems, 0) != ParseFailed) { |
| 3392 | wpa_s->connection_set = 1; |
Kai Shi | 4fa8e77 | 2020-08-12 19:02:21 -0700 | [diff] [blame] | 3393 | wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) || |
| 3394 | supp_rates_11b_only(&resp_elems); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3395 | wpa_s->connection_ht = req_elems.ht_capabilities && |
| 3396 | resp_elems.ht_capabilities; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3397 | /* Do not include subset of VHT on 2.4 GHz vendor |
| 3398 | * extension in consideration for reporting VHT |
| 3399 | * association. */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3400 | wpa_s->connection_vht = req_elems.vht_capabilities && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3401 | resp_elems.vht_capabilities && |
| 3402 | (!data->assoc_info.freq || |
| 3403 | wpas_freq_to_band(data->assoc_info.freq) != |
| 3404 | BAND_2_4_GHZ); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3405 | wpa_s->connection_he = req_elems.he_capabilities && |
| 3406 | resp_elems.he_capabilities; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3407 | wpa_s->connection_eht = req_elems.eht_capabilities && |
| 3408 | resp_elems.eht_capabilities; |
Kai Shi | 1e98503 | 2020-01-13 16:39:49 -0800 | [diff] [blame] | 3409 | |
| 3410 | int max_nss_rx_req = get_max_nss_capability(&req_elems, 1); |
| 3411 | int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1); |
| 3412 | wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ? |
| 3413 | max_nss_rx_req : max_nss_rx_resp; |
| 3414 | int max_nss_tx_req = get_max_nss_capability(&req_elems, 0); |
| 3415 | int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0); |
| 3416 | wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ? |
| 3417 | max_nss_tx_req : max_nss_tx_resp; |
| 3418 | |
| 3419 | struct supported_chan_width sta_supported_chan_width = |
| 3420 | get_supported_channel_width(&req_elems); |
| 3421 | enum chan_width ap_operation_chan_width = |
| 3422 | get_operation_channel_width(&resp_elems); |
Veerendranath Jakkam | 3fba995 | 2022-07-02 03:00:08 +0530 | [diff] [blame] | 3423 | if (wpa_s->connection_vht || wpa_s->connection_he || |
| 3424 | wpa_s->connection_eht) { |
Kai Shi | 1e98503 | 2020-01-13 16:39:49 -0800 | [diff] [blame] | 3425 | wpa_s->connection_channel_bandwidth = |
| 3426 | get_sta_operation_chan_width(ap_operation_chan_width, |
| 3427 | sta_supported_chan_width); |
| 3428 | } else if (wpa_s->connection_ht) { |
| 3429 | wpa_s->connection_channel_bandwidth = (ap_operation_chan_width |
| 3430 | == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20; |
| 3431 | } else { |
| 3432 | wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20; |
| 3433 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3434 | if (req_elems.rrm_enabled) |
| 3435 | wpa_s->rrm.rrm_used = 1; |
Ainy Kumari | 322d4fd | 2024-02-14 13:05:40 +0530 | [diff] [blame] | 3436 | wpa_s->ap_t2lm_negotiation_support = |
| 3437 | is_ap_t2lm_negotiation_supported(resp_elems.basic_mle, |
| 3438 | resp_elems.basic_mle_len); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3442 | p = data->assoc_info.req_ies; |
| 3443 | l = data->assoc_info.req_ies_len; |
| 3444 | |
| 3445 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ |
| 3446 | while (p && l >= 2) { |
| 3447 | len = p[1] + 2; |
| 3448 | if (len > l) { |
| 3449 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 3450 | p, l); |
| 3451 | break; |
| 3452 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3453 | if (!found && |
| 3454 | ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 3455 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || |
| 3456 | (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 && |
| 3457 | (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) || |
| 3458 | (p[0] == WLAN_EID_RSN && p[1] >= 2))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) |
| 3460 | break; |
| 3461 | found = 1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3462 | wpa_find_assoc_pmkid(wpa_s, |
| 3463 | data->assoc_info.authorized); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3464 | } |
| 3465 | if (!found_x && p[0] == WLAN_EID_RSNX) { |
| 3466 | if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len)) |
| 3467 | break; |
| 3468 | found_x = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3469 | } |
| 3470 | l -= len; |
| 3471 | p += len; |
| 3472 | } |
| 3473 | if (!found && data->assoc_info.req_ies) |
| 3474 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3475 | if (!found_x && data->assoc_info.req_ies) |
| 3476 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3477 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3478 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3479 | /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed |
| 3480 | * to a different security type, update the current supplicant configuration to use the AKM |
| 3481 | * and pairwise suites from the assoc IE passed by the driver. |
| 3482 | */ |
| 3483 | if (wpas_driver_bss_selection(wpa_s)) { |
| 3484 | if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) { |
| 3485 | /* Check if firmware has roamed to a different security network */ |
| 3486 | if(wpa_s->key_mgmt != ie.key_mgmt) { |
| 3487 | wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE", |
| 3488 | ie.key_mgmt); |
| 3489 | wpa_s->key_mgmt = ie.key_mgmt; |
| 3490 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
| 3491 | |
| 3492 | if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) { |
| 3493 | /* Restore PMK as it can get overwritten if the previous |
| 3494 | * association was to 802.1X. |
| 3495 | */ |
| 3496 | if ((!(wpa_s->drv_flags & |
| 3497 | WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) && |
| 3498 | (wpa_s->current_ssid) && |
| 3499 | (wpa_s->current_ssid->psk_set)) { |
| 3500 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 3501 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get " |
| 3502 | "BSSID"); |
| 3503 | wpa_supplicant_deauthenticate( |
| 3504 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3505 | return -1; |
| 3506 | } |
| 3507 | wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk, |
| 3508 | PMK_LEN, NULL, bssid); |
| 3509 | } |
| 3510 | } |
| 3511 | } |
| 3512 | if(wpa_s->pairwise_cipher != ie.pairwise_cipher) { |
| 3513 | wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x " |
| 3514 | "from Assoc IE", ie.pairwise_cipher); |
| 3515 | wpa_s->pairwise_cipher = ie.pairwise_cipher; |
| 3516 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
| 3517 | wpa_s->pairwise_cipher); |
| 3518 | } |
| 3519 | // TODO: Notify the framework about security type change b/230766005 |
| 3520 | } |
| 3521 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3522 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3523 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3524 | #ifdef CONFIG_FILS |
| 3525 | #ifdef CONFIG_SME |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3526 | if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS || |
| 3527 | wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) && |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3528 | (!data->assoc_info.resp_frame || |
| 3529 | fils_process_assoc_resp(wpa_s->wpa, |
| 3530 | data->assoc_info.resp_frame, |
| 3531 | data->assoc_info.resp_frame_len) < 0)) { |
| 3532 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); |
| 3533 | return -1; |
| 3534 | } |
| 3535 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3536 | |
| 3537 | /* Additional processing for FILS when SME is in driver */ |
| 3538 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS && |
| 3539 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
| 3540 | wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3541 | #endif /* CONFIG_FILS */ |
| 3542 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3543 | #ifdef CONFIG_OWE |
| 3544 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3545 | !(wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OWE_OFFLOAD_STA) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3546 | (!bssid_known || |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3547 | owe_process_assoc_resp(wpa_s->wpa, |
| 3548 | wpa_s->valid_links ? |
| 3549 | wpa_s->ap_mld_addr : bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3550 | data->assoc_info.resp_ies, |
| 3551 | data->assoc_info.resp_ies_len) < 0)) { |
| 3552 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); |
| 3553 | return -1; |
| 3554 | } |
| 3555 | #endif /* CONFIG_OWE */ |
| 3556 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3557 | #ifdef CONFIG_DPP2 |
| 3558 | wpa_sm_set_dpp_z(wpa_s->wpa, NULL); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3559 | if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && |
| 3560 | wpa_s->dpp_pfs) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3561 | struct ieee802_11_elems elems; |
| 3562 | |
| 3563 | if (ieee802_11_parse_elems(data->assoc_info.resp_ies, |
| 3564 | data->assoc_info.resp_ies_len, |
| 3565 | &elems, 0) == ParseFailed || |
| 3566 | !elems.owe_dh) |
| 3567 | goto no_pfs; |
| 3568 | if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh, |
| 3569 | elems.owe_dh_len) < 0) { |
| 3570 | wpa_supplicant_deauthenticate(wpa_s, |
| 3571 | WLAN_REASON_UNSPECIFIED); |
| 3572 | return -1; |
| 3573 | } |
| 3574 | |
| 3575 | wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret); |
| 3576 | } |
| 3577 | no_pfs: |
| 3578 | #endif /* CONFIG_DPP2 */ |
| 3579 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3580 | #ifdef CONFIG_IEEE80211R |
| 3581 | #ifdef CONFIG_SME |
| 3582 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3583 | if (!bssid_known || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3584 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, |
| 3585 | data->assoc_info.resp_ies, |
| 3586 | data->assoc_info.resp_ies_len, |
| 3587 | bssid) < 0) { |
| 3588 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
| 3589 | "Reassociation Response failed"); |
| 3590 | wpa_supplicant_deauthenticate( |
| 3591 | wpa_s, WLAN_REASON_INVALID_IE); |
| 3592 | return -1; |
| 3593 | } |
| 3594 | } |
| 3595 | |
| 3596 | p = data->assoc_info.resp_ies; |
| 3597 | l = data->assoc_info.resp_ies_len; |
| 3598 | |
| 3599 | #ifdef CONFIG_WPS_STRICT |
| 3600 | if (p && wpa_s->current_ssid && |
| 3601 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
| 3602 | struct wpabuf *wps; |
| 3603 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); |
| 3604 | if (wps == NULL) { |
| 3605 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
| 3606 | "include WPS IE in (Re)Association Response"); |
| 3607 | return -1; |
| 3608 | } |
| 3609 | |
| 3610 | if (wps_validate_assoc_resp(wps) < 0) { |
| 3611 | wpabuf_free(wps); |
| 3612 | wpa_supplicant_deauthenticate( |
| 3613 | wpa_s, WLAN_REASON_INVALID_IE); |
| 3614 | return -1; |
| 3615 | } |
| 3616 | wpabuf_free(wps); |
| 3617 | } |
| 3618 | #endif /* CONFIG_WPS_STRICT */ |
| 3619 | |
| 3620 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
| 3621 | while (p && l >= 2) { |
| 3622 | len = p[1] + 2; |
| 3623 | if (len > l) { |
| 3624 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 3625 | p, l); |
| 3626 | break; |
| 3627 | } |
| 3628 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
| 3629 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { |
| 3630 | wpa_s->sme.ft_used = 1; |
| 3631 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, |
| 3632 | MOBILITY_DOMAIN_ID_LEN); |
| 3633 | break; |
| 3634 | } |
| 3635 | l -= len; |
| 3636 | p += len; |
| 3637 | } |
| 3638 | #endif /* CONFIG_SME */ |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3639 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 3640 | if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) || |
| 3641 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) || |
| 3642 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) || |
Vinayak Yadawad | f473bef | 2024-04-04 15:33:29 +0530 | [diff] [blame] | 3643 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384) || |
| 3644 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE_EXT_KEY)) && |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3645 | wpa_ft_is_completed(wpa_s->wpa)) { |
| 3646 | return 0; |
| 3647 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3648 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3649 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3650 | /* Process FT when SME is in the driver */ |
| 3651 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 3652 | wpa_ft_is_completed(wpa_s->wpa)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3653 | if (!bssid_known || |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3654 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, |
| 3655 | data->assoc_info.resp_ies, |
| 3656 | data->assoc_info.resp_ies_len, |
| 3657 | bssid) < 0) { |
| 3658 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
| 3659 | "Reassociation Response failed"); |
| 3660 | wpa_supplicant_deauthenticate( |
| 3661 | wpa_s, WLAN_REASON_INVALID_IE); |
| 3662 | return -1; |
| 3663 | } |
| 3664 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); |
| 3665 | } |
| 3666 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3667 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
| 3668 | data->assoc_info.resp_ies_len); |
| 3669 | #endif /* CONFIG_IEEE80211R */ |
| 3670 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 3671 | #ifndef CONFIG_NO_ROBUST_AV |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3672 | if (bssid_known) |
| 3673 | wpas_handle_assoc_resp_mscs(wpa_s, bssid, |
| 3674 | data->assoc_info.resp_ies, |
| 3675 | data->assoc_info.resp_ies_len); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 3676 | #endif /* CONFIG_NO_ROBUST_AV */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3677 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3678 | /* WPA/RSN IE from Beacon/ProbeResp */ |
| 3679 | p = data->assoc_info.beacon_ies; |
| 3680 | l = data->assoc_info.beacon_ies_len; |
| 3681 | |
| 3682 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. |
| 3683 | */ |
| 3684 | wpa_found = rsn_found = 0; |
| 3685 | while (p && l >= 2) { |
| 3686 | len = p[1] + 2; |
| 3687 | if (len > l) { |
| 3688 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", |
| 3689 | p, l); |
| 3690 | break; |
| 3691 | } |
| 3692 | if (!wpa_found && |
| 3693 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 3694 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { |
| 3695 | wpa_found = 1; |
| 3696 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); |
| 3697 | } |
| 3698 | |
| 3699 | if (!rsn_found && |
| 3700 | p[0] == WLAN_EID_RSN && p[1] >= 2) { |
| 3701 | rsn_found = 1; |
| 3702 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); |
| 3703 | } |
| 3704 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3705 | if (p[0] == WLAN_EID_RSNX && p[1] >= 1) |
| 3706 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len); |
| 3707 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3708 | l -= len; |
| 3709 | p += len; |
| 3710 | } |
| 3711 | |
| 3712 | if (!wpa_found && data->assoc_info.beacon_ies) |
| 3713 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3714 | if (!rsn_found && data->assoc_info.beacon_ies) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3715 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3716 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0); |
| 3717 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3718 | if (wpa_found || rsn_found) |
| 3719 | wpa_s->ap_ies_from_associnfo = 1; |
| 3720 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 3721 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
| 3722 | wpa_s->assoc_freq != data->assoc_info.freq) { |
| 3723 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " |
| 3724 | "%u to %u MHz", |
| 3725 | wpa_s->assoc_freq, data->assoc_info.freq); |
| 3726 | wpa_supplicant_update_scan_results(wpa_s); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 3727 | } |
| 3728 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3729 | wpa_s->assoc_freq = data->assoc_info.freq; |
| 3730 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 3731 | #ifndef CONFIG_NO_ROBUST_AV |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3732 | wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies, |
| 3733 | data->assoc_info.resp_ies_len); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 3734 | #endif /* CONFIG_NO_ROBUST_AV */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3735 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3736 | return 0; |
| 3737 | } |
| 3738 | |
| 3739 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3740 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) |
| 3741 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3742 | const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3743 | |
| 3744 | if (!wpa_s->current_bss || !wpa_s->current_ssid) |
| 3745 | return -1; |
| 3746 | |
| 3747 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) |
| 3748 | return 0; |
| 3749 | |
| 3750 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| 3751 | WPA_IE_VENDOR_TYPE); |
| 3752 | bss_rsn = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSN); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3753 | bss_rsnx = wpa_bss_get_ie(wpa_s->current_bss, WLAN_EID_RSNX); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3754 | |
| 3755 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, |
| 3756 | bss_wpa ? 2 + bss_wpa[1] : 0) || |
| 3757 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3758 | bss_rsn ? 2 + bss_rsn[1] : 0) || |
| 3759 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx, |
| 3760 | bss_rsnx ? 2 + bss_rsnx[1] : 0)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3761 | return -1; |
| 3762 | |
| 3763 | return 0; |
| 3764 | } |
| 3765 | |
| 3766 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3767 | static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s, |
| 3768 | union wpa_event_data *data) |
| 3769 | { |
| 3770 | #ifdef CONFIG_FST |
| 3771 | struct assoc_info *ai = data ? &data->assoc_info : NULL; |
| 3772 | struct wpa_bss *bss = wpa_s->current_bss; |
| 3773 | const u8 *ieprb, *iebcn; |
| 3774 | |
| 3775 | wpabuf_free(wpa_s->received_mb_ies); |
| 3776 | wpa_s->received_mb_ies = NULL; |
| 3777 | |
| 3778 | if (ai && |
| 3779 | !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) { |
| 3780 | wpa_printf(MSG_DEBUG, |
| 3781 | "FST: MB IEs updated from Association Response frame"); |
| 3782 | return; |
| 3783 | } |
| 3784 | |
| 3785 | if (ai && |
| 3786 | !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) { |
| 3787 | wpa_printf(MSG_DEBUG, |
| 3788 | "FST: MB IEs updated from association event Beacon IEs"); |
| 3789 | return; |
| 3790 | } |
| 3791 | |
| 3792 | if (!bss) |
| 3793 | return; |
| 3794 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3795 | ieprb = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3796 | iebcn = ieprb + bss->ie_len; |
| 3797 | |
| 3798 | if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len)) |
| 3799 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE"); |
| 3800 | else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len)) |
| 3801 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE"); |
| 3802 | #endif /* CONFIG_FST */ |
| 3803 | } |
| 3804 | |
| 3805 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 3806 | static unsigned int wpas_ml_parse_assoc(struct wpa_supplicant *wpa_s, |
| 3807 | struct ieee802_11_elems *elems, |
| 3808 | struct ml_sta_link_info *ml_info) |
| 3809 | { |
| 3810 | struct wpabuf *mlbuf; |
| 3811 | struct ieee80211_eht_ml *ml; |
| 3812 | size_t ml_len; |
| 3813 | struct eht_ml_basic_common_info *common_info; |
| 3814 | const u8 *pos; |
| 3815 | u16 eml_capa = 0, mld_capa = 0; |
| 3816 | const u16 control = |
| 3817 | host_to_le16(MULTI_LINK_CONTROL_TYPE_BASIC | |
| 3818 | BASIC_MULTI_LINK_CTRL_PRES_LINK_ID | |
| 3819 | BASIC_MULTI_LINK_CTRL_PRES_BSS_PARAM_CH_COUNT); |
| 3820 | u8 expected_common_info_len = 9; |
| 3821 | unsigned int i = 0; |
| 3822 | u16 ml_control; |
| 3823 | |
| 3824 | if (!wpa_s->valid_links || !elems->basic_mle || !elems->basic_mle_len) |
| 3825 | return 0; |
| 3826 | |
| 3827 | mlbuf = ieee802_11_defrag(elems->basic_mle, elems->basic_mle_len, true); |
| 3828 | if (!mlbuf) |
| 3829 | return 0; |
| 3830 | |
| 3831 | ml = (struct ieee80211_eht_ml *) wpabuf_head(mlbuf); |
| 3832 | ml_len = wpabuf_len(mlbuf); |
| 3833 | if (ml_len < sizeof(*ml)) |
| 3834 | goto out; |
| 3835 | |
| 3836 | os_memset(ml_info, 0, sizeof(*ml_info) * MAX_NUM_MLD_LINKS); |
| 3837 | |
| 3838 | ml_control = le_to_host16(ml->ml_control); |
| 3839 | |
| 3840 | if ((ml_control & control) != control) { |
| 3841 | wpa_printf(MSG_DEBUG, "MLD: Invalid presence BM=0x%x", |
| 3842 | ml_control); |
| 3843 | goto out; |
| 3844 | } |
| 3845 | |
| 3846 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) { |
| 3847 | wpa_printf(MSG_DEBUG, "MLD: EML capabilities included"); |
| 3848 | expected_common_info_len += 2; |
| 3849 | } |
| 3850 | |
| 3851 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) { |
| 3852 | wpa_printf(MSG_DEBUG, "MLD: MLD capabilities included"); |
| 3853 | expected_common_info_len += 2; |
| 3854 | } |
| 3855 | |
| 3856 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) { |
| 3857 | wpa_printf(MSG_DEBUG, |
| 3858 | "MLD: Unexpected: medium sync delay info present"); |
| 3859 | expected_common_info_len += 2; |
| 3860 | } |
| 3861 | |
| 3862 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_AP_MLD_ID) { |
| 3863 | wpa_printf(MSG_DEBUG, |
| 3864 | "MLD: Unexpected: MLD ID present"); |
| 3865 | expected_common_info_len++; |
| 3866 | } |
| 3867 | |
| 3868 | if (sizeof(*ml) + expected_common_info_len > ml_len) { |
| 3869 | wpa_printf(MSG_DEBUG, |
| 3870 | "MLD: Not enough bytes for common info. ml_len=%zu", |
| 3871 | ml_len); |
| 3872 | goto out; |
| 3873 | } |
| 3874 | |
| 3875 | common_info = (struct eht_ml_basic_common_info *) ml->variable; |
| 3876 | if (common_info->len != expected_common_info_len) { |
| 3877 | wpa_printf(MSG_DEBUG, |
| 3878 | "MLD: Invalid common info len=%u. expected=%u", |
| 3879 | common_info->len, expected_common_info_len); |
| 3880 | goto out; |
| 3881 | } |
| 3882 | |
| 3883 | wpa_printf(MSG_DEBUG, "MLD: address: " MACSTR, |
| 3884 | MAC2STR(common_info->mld_addr)); |
| 3885 | |
| 3886 | if (!ether_addr_equal(wpa_s->ap_mld_addr, common_info->mld_addr)) { |
| 3887 | wpa_printf(MSG_DEBUG, "MLD: Mismatching MLD address (expected " |
| 3888 | MACSTR ")", MAC2STR(wpa_s->ap_mld_addr)); |
| 3889 | goto out; |
| 3890 | } |
| 3891 | |
| 3892 | pos = common_info->variable; |
| 3893 | |
| 3894 | /* Store the information for the association link */ |
| 3895 | ml_info[i].link_id = *pos; |
| 3896 | pos++; |
| 3897 | |
| 3898 | /* Skip the BSS Parameters Change Count */ |
| 3899 | pos++; |
| 3900 | |
| 3901 | /* Skip the Medium Synchronization Delay Information if present */ |
| 3902 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MSD_INFO) |
| 3903 | pos += 2; |
| 3904 | |
| 3905 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_EML_CAPA) { |
| 3906 | eml_capa = WPA_GET_LE16(pos); |
| 3907 | pos += 2; |
| 3908 | } |
| 3909 | |
| 3910 | if (ml_control & BASIC_MULTI_LINK_CTRL_PRES_MLD_CAPA) { |
| 3911 | mld_capa = WPA_GET_LE16(pos); |
| 3912 | pos += 2; |
| 3913 | } |
| 3914 | |
| 3915 | wpa_printf(MSG_DEBUG, |
| 3916 | "MLD: link_id=%u, eml=0x%x, mld=0x%x", |
| 3917 | ml_info[i].link_id, eml_capa, mld_capa); |
| 3918 | |
| 3919 | i++; |
| 3920 | |
| 3921 | pos = ((u8 *) common_info) + common_info->len; |
| 3922 | ml_len -= sizeof(*ml) + common_info->len; |
| 3923 | while (ml_len > 2 && i < MAX_NUM_MLD_LINKS) { |
| 3924 | u8 sub_elem_len = pos[1]; |
| 3925 | u8 sta_info_len; |
| 3926 | u8 nstr_bitmap_len = 0; |
| 3927 | u16 ctrl; |
| 3928 | const u8 *end; |
| 3929 | |
| 3930 | wpa_printf(MSG_DEBUG, "MLD: Subelement len=%u", sub_elem_len); |
| 3931 | |
| 3932 | if (sub_elem_len > ml_len - 2) { |
| 3933 | wpa_printf(MSG_DEBUG, |
| 3934 | "MLD: Invalid link info len: %u > %zu", |
| 3935 | 2 + sub_elem_len, ml_len); |
| 3936 | goto out; |
| 3937 | } |
| 3938 | |
| 3939 | switch (*pos) { |
| 3940 | case EHT_ML_SUB_ELEM_PER_STA_PROFILE: |
| 3941 | break; |
| 3942 | case EHT_ML_SUB_ELEM_FRAGMENT: |
| 3943 | case EHT_ML_SUB_ELEM_VENDOR: |
| 3944 | wpa_printf(MSG_DEBUG, |
| 3945 | "MLD: Skip subelement id=%u, len=%u", |
| 3946 | *pos, sub_elem_len); |
| 3947 | pos += 2 + sub_elem_len; |
| 3948 | ml_len -= 2 + sub_elem_len; |
| 3949 | continue; |
| 3950 | default: |
| 3951 | wpa_printf(MSG_DEBUG, "MLD: Unknown subelement ID=%u", |
| 3952 | *pos); |
| 3953 | goto out; |
| 3954 | } |
| 3955 | |
| 3956 | end = pos + 2 + sub_elem_len; |
| 3957 | |
| 3958 | /* Skip the subelement ID and the length */ |
| 3959 | pos += 2; |
| 3960 | ml_len -= 2; |
| 3961 | |
| 3962 | if (end - pos < 2) |
| 3963 | goto out; |
| 3964 | |
| 3965 | /* Get the station control field */ |
| 3966 | ctrl = WPA_GET_LE16(pos); |
| 3967 | |
| 3968 | pos += 2; |
| 3969 | ml_len -= 2; |
| 3970 | |
| 3971 | if (!(ctrl & EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK)) { |
| 3972 | wpa_printf(MSG_DEBUG, |
| 3973 | "MLD: Per STA complete profile expected"); |
| 3974 | goto out; |
| 3975 | } |
| 3976 | |
| 3977 | if (!(ctrl & EHT_PER_STA_CTRL_MAC_ADDR_PRESENT_MSK)) { |
| 3978 | wpa_printf(MSG_DEBUG, |
| 3979 | "MLD: Per STA MAC address not present"); |
| 3980 | goto out; |
| 3981 | } |
| 3982 | |
| 3983 | if (!(ctrl & EHT_PER_STA_CTRL_TSF_OFFSET_PRESENT_MSK)) { |
| 3984 | wpa_printf(MSG_DEBUG, |
| 3985 | "MLD: Per STA TSF offset not present"); |
| 3986 | goto out; |
| 3987 | } |
| 3988 | |
| 3989 | if (!(ctrl & EHT_PER_STA_CTRL_BEACON_INTERVAL_PRESENT_MSK)) { |
| 3990 | wpa_printf(MSG_DEBUG, |
| 3991 | "MLD: Beacon interval not present"); |
| 3992 | goto out; |
| 3993 | } |
| 3994 | |
| 3995 | if (!(ctrl & EHT_PER_STA_CTRL_DTIM_INFO_PRESENT_MSK)) { |
| 3996 | wpa_printf(MSG_DEBUG, |
| 3997 | "MLD: DTIM information not present"); |
| 3998 | goto out; |
| 3999 | } |
| 4000 | |
| 4001 | if (ctrl & EHT_PER_STA_CTRL_NSTR_LINK_PAIR_PRESENT_MSK) { |
| 4002 | if (ctrl & EHT_PER_STA_CTRL_NSTR_BM_SIZE_MSK) |
| 4003 | nstr_bitmap_len = 2; |
| 4004 | else |
| 4005 | nstr_bitmap_len = 1; |
| 4006 | } |
| 4007 | |
| 4008 | if (!(ctrl & EHT_PER_STA_CTRL_BSS_PARAM_CNT_PRESENT_MSK)) { |
| 4009 | wpa_printf(MSG_DEBUG, |
| 4010 | "MLD: BSS params change count not present"); |
| 4011 | goto out; |
| 4012 | } |
| 4013 | |
| 4014 | sta_info_len = 1 + ETH_ALEN + 8 + 2 + 2 + 1 + nstr_bitmap_len; |
| 4015 | if (sta_info_len > ml_len || sta_info_len > end - pos || |
| 4016 | sta_info_len + 2 > sub_elem_len || |
| 4017 | sta_info_len != *pos) { |
| 4018 | wpa_printf(MSG_DEBUG, |
| 4019 | "MLD: Invalid STA info len=%u, len=%u", |
| 4020 | sta_info_len, *pos); |
| 4021 | goto out; |
| 4022 | } |
| 4023 | |
| 4024 | /* Get the link address */ |
| 4025 | wpa_printf(MSG_DEBUG, |
| 4026 | "MLD: link addr: " MACSTR " nstr BM len=%u", |
| 4027 | MAC2STR(pos + 1), nstr_bitmap_len); |
| 4028 | |
| 4029 | ml_info[i].link_id = ctrl & EHT_PER_STA_CTRL_LINK_ID_MSK; |
| 4030 | os_memcpy(ml_info[i].bssid, pos + 1, ETH_ALEN); |
| 4031 | |
| 4032 | pos += sta_info_len; |
| 4033 | ml_len -= sta_info_len; |
| 4034 | |
| 4035 | wpa_printf(MSG_DEBUG, "MLD: sub_elem_len=%u, sta_info_len=%u", |
| 4036 | sub_elem_len, sta_info_len); |
| 4037 | |
| 4038 | sub_elem_len -= sta_info_len + 2; |
| 4039 | if (sub_elem_len < 4) { |
| 4040 | wpa_printf(MSG_DEBUG, "MLD: Per STA profile too short"); |
| 4041 | goto out; |
| 4042 | } |
| 4043 | |
| 4044 | wpa_hexdump(MSG_MSGDUMP, "MLD: STA profile", pos, sub_elem_len); |
| 4045 | ml_info[i].status = WPA_GET_LE16(pos + 2); |
| 4046 | |
| 4047 | pos += sub_elem_len; |
| 4048 | ml_len -= sub_elem_len; |
| 4049 | |
| 4050 | i++; |
| 4051 | } |
| 4052 | |
| 4053 | wpabuf_free(mlbuf); |
| 4054 | return i; |
| 4055 | out: |
| 4056 | wpabuf_free(mlbuf); |
| 4057 | return 0; |
| 4058 | } |
| 4059 | |
| 4060 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4061 | static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s) |
| 4062 | { |
| 4063 | struct driver_sta_mlo_info mlo; |
| 4064 | int i; |
| 4065 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4066 | os_memset(&mlo, 0, sizeof(mlo)); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4067 | if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) { |
| 4068 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info"); |
| 4069 | wpa_supplicant_deauthenticate(wpa_s, |
| 4070 | WLAN_REASON_DEAUTH_LEAVING); |
| 4071 | return -1; |
| 4072 | } |
| 4073 | |
| 4074 | if (wpa_s->valid_links == mlo.valid_links) { |
| 4075 | bool match = true; |
| 4076 | |
| 4077 | if (!mlo.valid_links) |
| 4078 | return 0; |
| 4079 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 4080 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 4081 | if (!(mlo.valid_links & BIT(i))) |
| 4082 | continue; |
| 4083 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4084 | if (!ether_addr_equal(wpa_s->links[i].addr, |
| 4085 | mlo.links[i].addr) || |
| 4086 | !ether_addr_equal(wpa_s->links[i].bssid, |
| 4087 | mlo.links[i].bssid)) { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4088 | match = false; |
| 4089 | break; |
| 4090 | } |
| 4091 | } |
| 4092 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4093 | if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4094 | ether_addr_equal(wpa_s->ap_mld_addr, mlo.ap_mld_addr)) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4095 | return 0; |
| 4096 | } |
| 4097 | |
| 4098 | wpa_s->valid_links = mlo.valid_links; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4099 | wpa_s->mlo_assoc_link_id = mlo.assoc_link_id; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4100 | os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN); |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 4101 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 4102 | if (!(wpa_s->valid_links & BIT(i))) |
| 4103 | continue; |
| 4104 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4105 | os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN); |
| 4106 | os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN); |
| 4107 | wpa_s->links[i].freq = mlo.links[i].freq; |
| 4108 | wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid); |
| 4109 | } |
| 4110 | |
| 4111 | return 0; |
| 4112 | } |
| 4113 | |
| 4114 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4115 | static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s) |
| 4116 | { |
| 4117 | struct driver_sta_mlo_info drv_mlo; |
| 4118 | struct wpa_sm_mlo wpa_mlo; |
| 4119 | const u8 *bss_rsn = NULL, *bss_rsnx = NULL; |
| 4120 | int i; |
| 4121 | |
| 4122 | os_memset(&drv_mlo, 0, sizeof(drv_mlo)); |
| 4123 | if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) { |
| 4124 | wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info"); |
| 4125 | return -1; |
| 4126 | } |
| 4127 | |
| 4128 | os_memset(&wpa_mlo, 0, sizeof(wpa_mlo)); |
| 4129 | if (!drv_mlo.valid_links) |
| 4130 | goto out; |
| 4131 | |
| 4132 | os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN); |
| 4133 | wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id; |
| 4134 | wpa_mlo.valid_links = drv_mlo.valid_links; |
| 4135 | wpa_mlo.req_links = drv_mlo.req_links; |
| 4136 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 4137 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4138 | struct wpa_bss *bss; |
| 4139 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 4140 | if (!(drv_mlo.req_links & BIT(i))) |
| 4141 | continue; |
| 4142 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4143 | bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid); |
| 4144 | if (!bss) { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 4145 | wpa_supplicant_update_scan_results(wpa_s); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4146 | bss = wpa_supplicant_get_new_bss( |
| 4147 | wpa_s, drv_mlo.links[i].bssid); |
| 4148 | } |
| 4149 | |
| 4150 | if (!bss) { |
| 4151 | wpa_dbg(wpa_s, MSG_INFO, |
| 4152 | "Failed to get MLO link %d BSS", i); |
| 4153 | return -1; |
| 4154 | } |
| 4155 | |
| 4156 | bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 4157 | bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
| 4158 | |
| 4159 | wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL; |
| 4160 | wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0; |
| 4161 | wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL; |
| 4162 | wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0; |
| 4163 | |
| 4164 | os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid, |
| 4165 | ETH_ALEN); |
| 4166 | os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr, |
| 4167 | ETH_ALEN); |
| 4168 | } |
| 4169 | |
| 4170 | out: |
| 4171 | return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo); |
| 4172 | } |
| 4173 | |
| 4174 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4175 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
| 4176 | union wpa_event_data *data) |
| 4177 | { |
| 4178 | u8 bssid[ETH_ALEN]; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 4179 | int ft_completed, already_authorized; |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 4180 | int new_bss = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4181 | #if defined(CONFIG_FILS) || defined(CONFIG_MBO) |
| 4182 | struct wpa_bss *bss; |
| 4183 | #endif /* CONFIG_FILS || CONFIG_MBO */ |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4184 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 4185 | struct wpa_ie_data ie; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4186 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4187 | |
| 4188 | #ifdef CONFIG_AP |
| 4189 | if (wpa_s->ap_iface) { |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 4190 | if (!data) |
| 4191 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4192 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], |
| 4193 | data->assoc_info.addr, |
| 4194 | data->assoc_info.req_ies, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4195 | data->assoc_info.req_ies_len, NULL, 0, |
| 4196 | NULL, data->assoc_info.reassoc); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4197 | return; |
| 4198 | } |
| 4199 | #endif /* CONFIG_AP */ |
| 4200 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 4201 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4202 | wpa_s->own_reconnect_req = 0; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 4203 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4204 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 4205 | if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) { |
| 4206 | struct wpa_ft_ies parse; |
| 4207 | /* Check for FT reassociation is done by the driver */ |
| 4208 | #ifdef CONFIG_IEEE80211R |
| 4209 | int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt); |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 4210 | if (wpa_key_mgmt_ft(wpa_s->key_mgmt) && (wpa_s->key_mgmt == ie.key_mgmt)) { |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 4211 | if (wpa_ft_parse_ies(data->assoc_info.resp_ies, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4212 | data->assoc_info.resp_ies_len, &parse, use_sha384, false) < 0) { |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 4213 | wpa_printf(MSG_DEBUG, "Failed to parse FT IEs"); |
| 4214 | return; |
| 4215 | } |
| 4216 | if (parse.rsn_pmkid != NULL) { |
| 4217 | wpa_set_ft_completed(wpa_s->wpa); |
| 4218 | wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver"); |
| 4219 | } |
| 4220 | } |
| 4221 | #endif /* CONFIG_IEEE80211R */ |
| 4222 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4223 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 4224 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4225 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4226 | |
| 4227 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 4228 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); |
| 4229 | wpa_supplicant_deauthenticate( |
| 4230 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 4231 | return; |
| 4232 | } |
| 4233 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 4234 | if (wpa_drv_get_mlo_info(wpa_s) < 0) { |
| 4235 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info"); |
| 4236 | wpa_supplicant_deauthenticate(wpa_s, |
| 4237 | WLAN_REASON_DEAUTH_LEAVING); |
| 4238 | return; |
| 4239 | } |
| 4240 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 4241 | if (ft_completed && |
| 4242 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) { |
| 4243 | wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR, |
| 4244 | MAC2STR(bssid)); |
| 4245 | if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) { |
| 4246 | wpa_printf(MSG_ERROR, |
| 4247 | "Can't find target AP's information!"); |
| 4248 | return; |
| 4249 | } |
| 4250 | wpa_supplicant_assoc_update_ie(wpa_s); |
| 4251 | } |
| 4252 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4253 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
| 4254 | return; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4255 | /* |
| 4256 | * FILS authentication can share the same mechanism to mark the |
| 4257 | * connection fully authenticated, so set ft_completed also based on |
| 4258 | * FILS result. |
| 4259 | */ |
| 4260 | if (!ft_completed) |
| 4261 | ft_completed = wpa_fils_is_completed(wpa_s->wpa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4262 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4263 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 4264 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
| 4265 | /* |
| 4266 | * For driver based roaming, insert PSK during |
| 4267 | * the initial association |
| 4268 | */ |
| 4269 | if (is_zero_ether_addr(wpa_s->bssid) && |
| 4270 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
| 4271 | /* |
| 4272 | * In case the driver wants to handle re-assocs, |
| 4273 | * pass it down the PMK. |
| 4274 | */ |
| 4275 | wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver"); |
| 4276 | wpa_sm_install_pmk(wpa_s->wpa); |
| 4277 | } |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 4278 | } |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 4279 | #endif |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4280 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4281 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4282 | if (!ether_addr_equal(bssid, wpa_s->bssid)) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4283 | if (os_reltime_initialized(&wpa_s->session_start)) { |
| 4284 | os_reltime_age(&wpa_s->session_start, |
| 4285 | &wpa_s->session_length); |
| 4286 | wpa_s->session_start.sec = 0; |
| 4287 | wpa_s->session_start.usec = 0; |
| 4288 | wpas_notify_session_length(wpa_s); |
| 4289 | } else { |
| 4290 | wpas_notify_auth_changed(wpa_s); |
| 4291 | os_get_reltime(&wpa_s->session_start); |
| 4292 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4293 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
| 4294 | MACSTR, MAC2STR(bssid)); |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 4295 | new_bss = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4296 | random_add_randomness(bssid, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4297 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
| 4298 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4299 | wpas_notify_bssid_changed(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4300 | |
| 4301 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
| 4302 | wpa_clear_keys(wpa_s, bssid); |
| 4303 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4304 | if (wpa_supplicant_select_config(wpa_s, data) < 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4305 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4306 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 4307 | return; |
| 4308 | } |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 4309 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4310 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4311 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 4312 | data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0) |
| 4313 | return; |
| 4314 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4315 | multi_ap_set_4addr_mode(wpa_s); |
| 4316 | |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 4317 | if (wpa_s->conf->ap_scan == 1 && |
| 4318 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 4319 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss) |
| 4320 | wpa_msg(wpa_s, MSG_WARNING, |
| 4321 | "WPA/RSN IEs not updated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4322 | } |
| 4323 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4324 | wpas_fst_update_mb_assoc(wpa_s, data); |
| 4325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4326 | #ifdef CONFIG_SME |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 4327 | /* |
| 4328 | * Cache the current AP's BSSID (for non-MLO connection) or MLD address |
| 4329 | * (for MLO connection) as the previous BSSID for subsequent |
| 4330 | * reassociation requests handled by SME-in-wpa_supplicant. |
| 4331 | */ |
| 4332 | os_memcpy(wpa_s->sme.prev_bssid, |
| 4333 | wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4334 | wpa_s->sme.prev_bssid_set = 1; |
Dmitry Shmidt | 0c08fdc | 2014-06-20 10:16:40 -0700 | [diff] [blame] | 4335 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4336 | #endif /* CONFIG_SME */ |
| 4337 | |
| 4338 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
| 4339 | if (wpa_s->current_ssid) { |
| 4340 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be |
| 4341 | * initialized before association, but for other modes, |
| 4342 | * initialize PC/SC here, if the current configuration needs |
| 4343 | * smartcard or SIM/USIM. */ |
| 4344 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); |
| 4345 | } |
| 4346 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4347 | |
| 4348 | if (wpa_sm_set_ml_info(wpa_s)) { |
| 4349 | wpa_dbg(wpa_s, MSG_INFO, |
| 4350 | "Failed to set MLO connection info to wpa_sm"); |
| 4351 | wpa_supplicant_deauthenticate(wpa_s, |
| 4352 | WLAN_REASON_DEAUTH_LEAVING); |
| 4353 | return; |
| 4354 | } |
| 4355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4356 | if (wpa_s->l2) |
| 4357 | l2_packet_notify_auth_start(wpa_s->l2); |
| 4358 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 4359 | already_authorized = data && data->assoc_info.authorized; |
| 4360 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4361 | /* |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 4362 | * Set portEnabled first to false in order to get EAP state machine out |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4363 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE |
| 4364 | * state machine may transit to AUTHENTICATING state based on obsolete |
| 4365 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to |
| 4366 | * AUTHENTICATED without ever giving chance to EAP state machine to |
| 4367 | * reset the state. |
| 4368 | */ |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 4369 | if (!ft_completed && !already_authorized) { |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 4370 | eapol_sm_notify_portEnabled(wpa_s->eapol, false); |
| 4371 | eapol_sm_notify_portValid(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4372 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4373 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 4374 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || |
| 4375 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4376 | already_authorized || wpa_s->drv_authorized_port) |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 4377 | eapol_sm_notify_eap_success(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4378 | /* 802.1X::portControl = Auto */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 4379 | eapol_sm_notify_portEnabled(wpa_s->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4380 | wpa_s->eapol_received = 0; |
| 4381 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 4382 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
| 4383 | (wpa_s->current_ssid && |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4384 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) { |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 4385 | if (wpa_s->current_ssid && |
| 4386 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4387 | (wpa_s->drv_flags & |
| 4388 | WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { |
| 4389 | /* |
| 4390 | * Set the key after having received joined-IBSS event |
| 4391 | * from the driver. |
| 4392 | */ |
| 4393 | wpa_supplicant_set_wpa_none_key(wpa_s, |
| 4394 | wpa_s->current_ssid); |
| 4395 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4396 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 4397 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 4398 | } else if (!ft_completed) { |
| 4399 | /* Timeout for receiving the first EAPOL packet */ |
| 4400 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); |
| 4401 | } |
| 4402 | wpa_supplicant_cancel_scan(wpa_s); |
| 4403 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4404 | if (ft_completed) { |
| 4405 | /* |
| 4406 | * FT protocol completed - make sure EAPOL state machine ends |
| 4407 | * up in authenticated. |
| 4408 | */ |
| 4409 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 4410 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 4411 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
| 4412 | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4413 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) && |
| 4414 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 4415 | if (already_authorized) { |
| 4416 | /* |
| 4417 | * We are done; the driver will take care of RSN 4-way |
| 4418 | * handshake. |
| 4419 | */ |
| 4420 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 4421 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 4422 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
| 4423 | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
| 4424 | } else { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4425 | /* Update port, WPA_COMPLETED state from the |
| 4426 | * EVENT_PORT_AUTHORIZED handler when the driver is done |
| 4427 | * with the 4-way handshake. |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 4428 | */ |
Sunil Ravi | 167279a | 2023-05-31 01:12:34 +0000 | [diff] [blame] | 4429 | wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4430 | wpa_msg(wpa_s, MSG_INFO, |
| 4431 | "ASSOC INFO: wait for driver port authorized indication"); |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 4432 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4433 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4434 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
| 4435 | /* |
| 4436 | * The driver will take care of RSN 4-way handshake, so we need |
| 4437 | * to allow EAPOL supplicant to complete its work without |
| 4438 | * waiting for WPA supplicant. |
| 4439 | */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 4440 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4441 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4442 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 4443 | if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) { |
| 4444 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 4445 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x", |
| 4446 | wpa_s->key_mgmt); |
| 4447 | wpa_supplicant_deauthenticate( |
| 4448 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 4449 | return; |
| 4450 | } |
| 4451 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
| 4452 | wpa_s->assoc_freq = data->assoc_info.freq; |
| 4453 | wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid); |
| 4454 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 4455 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 4456 | |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 4457 | wpa_s->last_eapol_matches_bssid = 0; |
| 4458 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4459 | #ifdef CONFIG_TESTING_OPTIONS |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4460 | if (wpa_s->rsne_override_eapol) { |
| 4461 | wpa_printf(MSG_DEBUG, |
| 4462 | "TESTING: RSNE EAPOL-Key msg 2/4 override"); |
| 4463 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, |
| 4464 | wpabuf_head(wpa_s->rsne_override_eapol), |
| 4465 | wpabuf_len(wpa_s->rsne_override_eapol)); |
| 4466 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4467 | if (wpa_s->rsnxe_override_eapol) { |
| 4468 | wpa_printf(MSG_DEBUG, |
| 4469 | "TESTING: RSNXE EAPOL-Key msg 2/4 override"); |
| 4470 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, |
| 4471 | wpabuf_head(wpa_s->rsnxe_override_eapol), |
| 4472 | wpabuf_len(wpa_s->rsnxe_override_eapol)); |
| 4473 | } |
| 4474 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4475 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4476 | if (wpa_s->pending_eapol_rx) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4477 | struct os_reltime now, age; |
| 4478 | os_get_reltime(&now); |
| 4479 | os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4480 | if (age.sec == 0 && age.usec < 200000 && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4481 | ether_addr_equal(wpa_s->pending_eapol_rx_src, |
| 4482 | wpa_s->valid_links ? wpa_s->ap_mld_addr : |
| 4483 | bssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4484 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
| 4485 | "frame that was received just before " |
| 4486 | "association notification"); |
| 4487 | wpa_supplicant_rx_eapol( |
| 4488 | wpa_s, wpa_s->pending_eapol_rx_src, |
| 4489 | wpabuf_head(wpa_s->pending_eapol_rx), |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 4490 | wpabuf_len(wpa_s->pending_eapol_rx), |
| 4491 | wpa_s->pending_eapol_encrypted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4492 | } |
| 4493 | wpabuf_free(wpa_s->pending_eapol_rx); |
| 4494 | wpa_s->pending_eapol_rx = NULL; |
| 4495 | } |
| 4496 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4497 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4498 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 4499 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4500 | wpa_s->current_ssid && |
| 4501 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4502 | /* Set static WEP keys again */ |
| 4503 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); |
| 4504 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4505 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4506 | |
| 4507 | #ifdef CONFIG_IBSS_RSN |
| 4508 | if (wpa_s->current_ssid && |
| 4509 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && |
| 4510 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
| 4511 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
| 4512 | wpa_s->ibss_rsn == NULL) { |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 4513 | wpa_s->ibss_rsn = ibss_rsn_init(wpa_s, wpa_s->current_ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4514 | if (!wpa_s->ibss_rsn) { |
| 4515 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); |
| 4516 | wpa_supplicant_deauthenticate( |
| 4517 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 4518 | return; |
| 4519 | } |
| 4520 | |
| 4521 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); |
| 4522 | } |
| 4523 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4524 | |
| 4525 | wpas_wps_notify_assoc(wpa_s, bssid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4526 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4527 | #ifndef CONFIG_NO_WMM_AC |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4528 | if (data) { |
| 4529 | wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies, |
| 4530 | data->assoc_info.resp_ies_len, |
| 4531 | &data->assoc_info.wmm_params); |
| 4532 | |
| 4533 | if (wpa_s->reassoc_same_bss) |
| 4534 | wmm_ac_restore_tspecs(wpa_s); |
| 4535 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4536 | #endif /* CONFIG_NO_WMM_AC */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4537 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4538 | #if defined(CONFIG_FILS) || defined(CONFIG_MBO) |
| 4539 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 4540 | #endif /* CONFIG_FILS || CONFIG_MBO */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4541 | #ifdef CONFIG_FILS |
| 4542 | if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4543 | const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss); |
| 4544 | |
| 4545 | if (fils_cache_id) |
| 4546 | wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id); |
| 4547 | } |
| 4548 | #endif /* CONFIG_FILS */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4549 | |
| 4550 | #ifdef CONFIG_MBO |
| 4551 | wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid); |
| 4552 | #endif /* CONFIG_MBO */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4553 | |
| 4554 | #ifdef CONFIG_DPP2 |
| 4555 | wpa_s->dpp_pfs_fallback = 0; |
| 4556 | #endif /* CONFIG_DPP2 */ |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4557 | |
| 4558 | if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode) |
| 4559 | wpa_supplicant_set_4addr_mode(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4563 | static int disconnect_reason_recoverable(u16 reason_code) |
| 4564 | { |
| 4565 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || |
| 4566 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || |
| 4567 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; |
| 4568 | } |
| 4569 | |
| 4570 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4571 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4572 | u16 reason_code, |
| 4573 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4574 | { |
| 4575 | const u8 *bssid; |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 4576 | |
| 4577 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 4578 | /* |
| 4579 | * At least Host AP driver and a Prism3 card seemed to be |
| 4580 | * generating streams of disconnected events when configuring |
| 4581 | * IBSS for WPA-None. Ignore them for now. |
| 4582 | */ |
| 4583 | return; |
| 4584 | } |
| 4585 | |
| 4586 | bssid = wpa_s->bssid; |
| 4587 | if (is_zero_ether_addr(bssid)) |
| 4588 | bssid = wpa_s->pending_bssid; |
| 4589 | |
| 4590 | if (!is_zero_ether_addr(bssid) || |
| 4591 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 4592 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
| 4593 | " reason=%d%s", |
| 4594 | MAC2STR(bssid), reason_code, |
| 4595 | locally_generated ? " locally_generated=1" : ""); |
| 4596 | } |
| 4597 | } |
| 4598 | |
| 4599 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4600 | static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, |
| 4601 | int locally_generated) |
| 4602 | { |
| 4603 | if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4604 | !wpa_s->new_connection || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4605 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 4606 | wpa_key_mgmt_sae(wpa_s->key_mgmt)) |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4607 | return 0; /* Not in initial 4-way handshake with PSK */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4608 | |
| 4609 | /* |
| 4610 | * It looks like connection was lost while trying to go through PSK |
| 4611 | * 4-way handshake. Filter out known disconnection cases that are caused |
| 4612 | * by something else than PSK mismatch to avoid confusing reports. |
| 4613 | */ |
| 4614 | |
| 4615 | if (locally_generated) { |
| 4616 | if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) |
| 4617 | return 0; |
| 4618 | } |
| 4619 | |
| 4620 | return 1; |
| 4621 | } |
| 4622 | |
| 4623 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 4624 | static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, |
| 4625 | u16 reason_code, |
| 4626 | int locally_generated) |
| 4627 | { |
| 4628 | const u8 *bssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4629 | struct wpa_bss *fast_reconnect = NULL; |
| 4630 | struct wpa_ssid *fast_reconnect_ssid = NULL; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4631 | struct wpa_bss *curr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4632 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4633 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 4634 | /* |
| 4635 | * At least Host AP driver and a Prism3 card seemed to be |
| 4636 | * generating streams of disconnected events when configuring |
| 4637 | * IBSS for WPA-None. Ignore them for now. |
| 4638 | */ |
| 4639 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
| 4640 | "IBSS/WPA-None mode"); |
| 4641 | return; |
| 4642 | } |
| 4643 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4644 | if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING && |
| 4645 | reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY && |
| 4646 | locally_generated) |
| 4647 | /* |
| 4648 | * Remove the inactive AP (which is probably out of range) from |
| 4649 | * the BSS list after marking disassociation. In particular |
| 4650 | * mac80211-based drivers use the |
| 4651 | * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in |
| 4652 | * locally generated disconnection events for cases where the |
| 4653 | * AP does not reply anymore. |
| 4654 | */ |
| 4655 | curr = wpa_s->current_bss; |
| 4656 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4657 | if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4658 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
| 4659 | "pre-shared key may be incorrect"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4660 | if (wpas_p2p_4way_hs_failed(wpa_s) > 0) |
| 4661 | return; /* P2P group removed */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4662 | wpas_auth_failed(wpa_s, "WRONG_KEY", wpa_s->pending_bssid); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4663 | wpas_notify_psk_mismatch(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4664 | #ifdef CONFIG_DPP2 |
| 4665 | wpas_dpp_send_conn_status_result(wpa_s, |
| 4666 | DPP_STATUS_AUTH_FAILURE); |
| 4667 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4668 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 4669 | if (!wpa_s->disconnected && |
| 4670 | (!wpa_s->auto_reconnect_disabled || |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4671 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4672 | wpas_wps_searching(wpa_s) || |
| 4673 | wpas_wps_reenable_networks_pending(wpa_s))) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4674 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4675 | "reconnect (wps=%d/%d wpa_state=%d)", |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4676 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4677 | wpas_wps_searching(wpa_s), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4678 | wpa_s->wpa_state); |
| 4679 | if (wpa_s->wpa_state == WPA_COMPLETED && |
| 4680 | wpa_s->current_ssid && |
| 4681 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4682 | (wpa_s->own_reconnect_req || |
| 4683 | (!locally_generated && |
| 4684 | disconnect_reason_recoverable(reason_code)))) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4685 | /* |
| 4686 | * It looks like the AP has dropped association with |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4687 | * us, but could allow us to get back in. This is also |
| 4688 | * triggered for cases where local reconnection request |
| 4689 | * is used to force reassociation with the same BSS. |
| 4690 | * Try to reconnect to the same BSS without a full scan |
| 4691 | * to save time for some common cases. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4692 | */ |
| 4693 | fast_reconnect = wpa_s->current_bss; |
| 4694 | fast_reconnect_ssid = wpa_s->current_ssid; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4695 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4696 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4697 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4698 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " |
| 4699 | "immediate scan"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4700 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4701 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4702 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4703 | "try to re-connect"); |
| 4704 | wpa_s->reassociate = 0; |
| 4705 | wpa_s->disconnected = 1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4706 | if (!wpa_s->pno) |
| 4707 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4708 | } |
| 4709 | bssid = wpa_s->bssid; |
| 4710 | if (is_zero_ether_addr(bssid)) |
| 4711 | bssid = wpa_s->pending_bssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4712 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 4713 | wpas_connection_failed(wpa_s, bssid, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4714 | wpa_sm_notify_disassoc(wpa_s->wpa); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4715 | ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE); |
| 4716 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4717 | if (locally_generated) |
| 4718 | wpa_s->disconnect_reason = -reason_code; |
| 4719 | else |
| 4720 | wpa_s->disconnect_reason = reason_code; |
| 4721 | wpas_notify_disconnect_reason(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4722 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
| 4723 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4724 | wpa_clear_keys(wpa_s, wpa_s->bssid); |
| 4725 | } |
| 4726 | wpa_supplicant_mark_disassoc(wpa_s); |
| 4727 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4728 | if (curr) |
| 4729 | wpa_bss_remove(wpa_s, curr, "Connection to AP lost"); |
| 4730 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4731 | if (fast_reconnect && |
| 4732 | !wpas_network_disabled(wpa_s, fast_reconnect_ssid) && |
| 4733 | !disallowed_bssid(wpa_s, fast_reconnect->bssid) && |
| 4734 | !disallowed_ssid(wpa_s, fast_reconnect->ssid, |
| 4735 | fast_reconnect->ssid_len) && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4736 | !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4737 | !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4738 | #ifndef CONFIG_NO_SCAN_PROCESSING |
| 4739 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
| 4740 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, |
| 4741 | fast_reconnect_ssid) < 0) { |
| 4742 | /* Recover through full scan */ |
| 4743 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
| 4744 | } |
| 4745 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4746 | } else if (fast_reconnect) { |
| 4747 | /* |
| 4748 | * Could not reconnect to the same BSS due to network being |
| 4749 | * disabled. Use a new scan to match the alternative behavior |
| 4750 | * above, i.e., to continue automatic reconnection attempt in a |
| 4751 | * way that enforces disabled network rules. |
| 4752 | */ |
| 4753 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4754 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
| 4757 | |
| 4758 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4759 | void wpa_supplicant_delayed_mic_error_report(void *eloop_ctx, void *sock_ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4760 | { |
| 4761 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 4762 | |
| 4763 | if (!wpa_s->pending_mic_error_report) |
| 4764 | return; |
| 4765 | |
| 4766 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
| 4767 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
| 4768 | wpa_s->pending_mic_error_report = 0; |
| 4769 | } |
| 4770 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 4771 | |
| 4772 | |
| 4773 | static void |
| 4774 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, |
| 4775 | union wpa_event_data *data) |
| 4776 | { |
| 4777 | int pairwise; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4778 | struct os_reltime t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4779 | |
| 4780 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); |
| 4781 | pairwise = (data && data->michael_mic_failure.unicast); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4782 | os_get_reltime(&t); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 4783 | if ((os_reltime_initialized(&wpa_s->last_michael_mic_error) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4784 | !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4785 | wpa_s->pending_mic_error_report) { |
| 4786 | if (wpa_s->pending_mic_error_report) { |
| 4787 | /* |
| 4788 | * Send the pending MIC error report immediately since |
| 4789 | * we are going to start countermeasures and AP better |
| 4790 | * do the same. |
| 4791 | */ |
| 4792 | wpa_sm_key_request(wpa_s->wpa, 1, |
| 4793 | wpa_s->pending_mic_error_pairwise); |
| 4794 | } |
| 4795 | |
| 4796 | /* Send the new MIC error report immediately since we are going |
| 4797 | * to start countermeasures and AP better do the same. |
| 4798 | */ |
| 4799 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 4800 | |
| 4801 | /* initialize countermeasures */ |
| 4802 | wpa_s->countermeasures = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4803 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4804 | wpa_bssid_ignore_add(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4805 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4806 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
| 4807 | |
| 4808 | /* |
| 4809 | * Need to wait for completion of request frame. We do not get |
| 4810 | * any callback for the message completion, so just wait a |
| 4811 | * short while and hope for the best. */ |
| 4812 | os_sleep(0, 10000); |
| 4813 | |
| 4814 | wpa_drv_set_countermeasures(wpa_s, 1); |
| 4815 | wpa_supplicant_deauthenticate(wpa_s, |
| 4816 | WLAN_REASON_MICHAEL_MIC_FAILURE); |
| 4817 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, |
| 4818 | wpa_s, NULL); |
| 4819 | eloop_register_timeout(60, 0, |
| 4820 | wpa_supplicant_stop_countermeasures, |
| 4821 | wpa_s, NULL); |
| 4822 | /* TODO: mark the AP rejected for 60 second. STA is |
| 4823 | * allowed to associate with another AP.. */ |
| 4824 | } else { |
| 4825 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
| 4826 | if (wpa_s->mic_errors_seen) { |
| 4827 | /* |
| 4828 | * Reduce the effectiveness of Michael MIC error |
| 4829 | * reports as a means for attacking against TKIP if |
| 4830 | * more than one MIC failure is noticed with the same |
| 4831 | * PTK. We delay the transmission of the reports by a |
| 4832 | * random time between 0 and 60 seconds in order to |
| 4833 | * force the attacker wait 60 seconds before getting |
| 4834 | * the information on whether a frame resulted in a MIC |
| 4835 | * failure. |
| 4836 | */ |
| 4837 | u8 rval[4]; |
| 4838 | int sec; |
| 4839 | |
| 4840 | if (os_get_random(rval, sizeof(rval)) < 0) |
| 4841 | sec = os_random() % 60; |
| 4842 | else |
| 4843 | sec = WPA_GET_BE32(rval) % 60; |
| 4844 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
| 4845 | "report %d seconds", sec); |
| 4846 | wpa_s->pending_mic_error_report = 1; |
| 4847 | wpa_s->pending_mic_error_pairwise = pairwise; |
| 4848 | eloop_cancel_timeout( |
| 4849 | wpa_supplicant_delayed_mic_error_report, |
| 4850 | wpa_s, NULL); |
| 4851 | eloop_register_timeout( |
| 4852 | sec, os_random() % 1000000, |
| 4853 | wpa_supplicant_delayed_mic_error_report, |
| 4854 | wpa_s, NULL); |
| 4855 | } else { |
| 4856 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 4857 | } |
| 4858 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 4859 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 4860 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 4861 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4862 | wpa_s->last_michael_mic_error = t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4863 | wpa_s->mic_errors_seen++; |
| 4864 | } |
| 4865 | |
| 4866 | |
| 4867 | #ifdef CONFIG_TERMINATE_ONLASTIF |
| 4868 | static int any_interfaces(struct wpa_supplicant *head) |
| 4869 | { |
| 4870 | struct wpa_supplicant *wpa_s; |
| 4871 | |
| 4872 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) |
| 4873 | if (!wpa_s->interface_removed) |
| 4874 | return 1; |
| 4875 | return 0; |
| 4876 | } |
| 4877 | #endif /* CONFIG_TERMINATE_ONLASTIF */ |
| 4878 | |
| 4879 | |
| 4880 | static void |
| 4881 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, |
| 4882 | union wpa_event_data *data) |
| 4883 | { |
| 4884 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) |
| 4885 | return; |
| 4886 | |
| 4887 | switch (data->interface_status.ievent) { |
| 4888 | case EVENT_INTERFACE_ADDED: |
| 4889 | if (!wpa_s->interface_removed) |
| 4890 | break; |
| 4891 | wpa_s->interface_removed = 0; |
| 4892 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
| 4893 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
| 4894 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
| 4895 | "driver after interface was added"); |
| 4896 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4897 | |
| 4898 | #ifdef CONFIG_P2P |
| 4899 | if (!wpa_s->global->p2p && |
| 4900 | !wpa_s->global->p2p_disabled && |
| 4901 | !wpa_s->conf->p2p_disabled && |
| 4902 | (wpa_s->drv_flags & |
| 4903 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
| 4904 | wpas_p2p_add_p2pdev_interface( |
| 4905 | wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) { |
| 4906 | wpa_printf(MSG_INFO, |
| 4907 | "P2P: Failed to enable P2P Device interface"); |
| 4908 | /* Try to continue without. P2P will be disabled. */ |
| 4909 | } |
| 4910 | #endif /* CONFIG_P2P */ |
| 4911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4912 | break; |
| 4913 | case EVENT_INTERFACE_REMOVED: |
| 4914 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
| 4915 | wpa_s->interface_removed = 1; |
| 4916 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4917 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4918 | l2_packet_deinit(wpa_s->l2); |
| 4919 | wpa_s->l2 = NULL; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4920 | |
| 4921 | #ifdef CONFIG_P2P |
| 4922 | if (wpa_s->global->p2p && |
| 4923 | wpa_s->global->p2p_init_wpa_s->parent == wpa_s && |
| 4924 | (wpa_s->drv_flags & |
| 4925 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) { |
| 4926 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4927 | "Removing P2P Device interface"); |
| 4928 | wpa_supplicant_remove_iface( |
| 4929 | wpa_s->global, wpa_s->global->p2p_init_wpa_s, |
| 4930 | 0); |
| 4931 | wpa_s->global->p2p_init_wpa_s = NULL; |
| 4932 | } |
| 4933 | #endif /* CONFIG_P2P */ |
| 4934 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4935 | #ifdef CONFIG_MATCH_IFACE |
| 4936 | if (wpa_s->matched) { |
| 4937 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); |
| 4938 | break; |
| 4939 | } |
| 4940 | #endif /* CONFIG_MATCH_IFACE */ |
| 4941 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4942 | #ifdef CONFIG_TERMINATE_ONLASTIF |
| 4943 | /* check if last interface */ |
| 4944 | if (!any_interfaces(wpa_s->global->ifaces)) |
| 4945 | eloop_terminate(); |
| 4946 | #endif /* CONFIG_TERMINATE_ONLASTIF */ |
| 4947 | break; |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4952 | #ifdef CONFIG_TDLS |
| 4953 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, |
| 4954 | union wpa_event_data *data) |
| 4955 | { |
| 4956 | if (data == NULL) |
| 4957 | return; |
| 4958 | switch (data->tdls.oper) { |
| 4959 | case TDLS_REQUEST_SETUP: |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4960 | wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); |
| 4961 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 4962 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); |
| 4963 | else |
| 4964 | wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4965 | break; |
| 4966 | case TDLS_REQUEST_TEARDOWN: |
Sunil Dutt | 6a9f522 | 2013-09-30 17:10:18 +0300 | [diff] [blame] | 4967 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 4968 | wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, |
| 4969 | data->tdls.reason_code); |
| 4970 | else |
| 4971 | wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, |
| 4972 | data->tdls.peer); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4973 | break; |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 4974 | case TDLS_REQUEST_DISCOVER: |
| 4975 | wpa_tdls_send_discovery_request(wpa_s->wpa, |
| 4976 | data->tdls.peer); |
| 4977 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4978 | } |
| 4979 | } |
| 4980 | #endif /* CONFIG_TDLS */ |
| 4981 | |
| 4982 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4983 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4984 | static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, |
| 4985 | union wpa_event_data *data) |
| 4986 | { |
| 4987 | if (data == NULL) |
| 4988 | return; |
| 4989 | switch (data->wnm.oper) { |
| 4990 | case WNM_OPER_SLEEP: |
| 4991 | wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " |
| 4992 | "(action=%d, intval=%d)", |
| 4993 | data->wnm.sleep_action, data->wnm.sleep_intval); |
| 4994 | ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4995 | data->wnm.sleep_intval, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4996 | break; |
| 4997 | } |
| 4998 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4999 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5000 | |
| 5001 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5002 | #ifdef CONFIG_IEEE80211R |
| 5003 | static void |
| 5004 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, |
| 5005 | union wpa_event_data *data) |
| 5006 | { |
| 5007 | if (data == NULL) |
| 5008 | return; |
| 5009 | |
| 5010 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, |
| 5011 | data->ft_ies.ies_len, |
| 5012 | data->ft_ies.ft_action, |
| 5013 | data->ft_ies.target_ap, |
| 5014 | data->ft_ies.ric_ies, |
| 5015 | data->ft_ies.ric_ies_len) < 0) { |
| 5016 | /* TODO: prevent MLME/driver from trying to associate? */ |
| 5017 | } |
| 5018 | } |
| 5019 | #endif /* CONFIG_IEEE80211R */ |
| 5020 | |
| 5021 | |
| 5022 | #ifdef CONFIG_IBSS_RSN |
| 5023 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, |
| 5024 | union wpa_event_data *data) |
| 5025 | { |
| 5026 | struct wpa_ssid *ssid; |
| 5027 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 5028 | return; |
| 5029 | if (data == NULL) |
| 5030 | return; |
| 5031 | ssid = wpa_s->current_ssid; |
| 5032 | if (ssid == NULL) |
| 5033 | return; |
| 5034 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 5035 | return; |
| 5036 | |
| 5037 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
| 5038 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5039 | |
| 5040 | |
| 5041 | static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, |
| 5042 | union wpa_event_data *data) |
| 5043 | { |
| 5044 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5045 | |
| 5046 | if (ssid == NULL) |
| 5047 | return; |
| 5048 | |
| 5049 | /* check if the ssid is correctly configured as IBSS/RSN */ |
| 5050 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 5051 | return; |
| 5052 | |
| 5053 | ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, |
| 5054 | data->rx_mgmt.frame_len); |
| 5055 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5056 | #endif /* CONFIG_IBSS_RSN */ |
| 5057 | |
| 5058 | |
| 5059 | #ifdef CONFIG_IEEE80211R |
| 5060 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, |
| 5061 | size_t len) |
| 5062 | { |
| 5063 | const u8 *sta_addr, *target_ap_addr; |
| 5064 | u16 status; |
| 5065 | |
| 5066 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); |
| 5067 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
| 5068 | return; /* only SME case supported for now */ |
| 5069 | if (len < 1 + 2 * ETH_ALEN + 2) |
| 5070 | return; |
| 5071 | if (data[0] != 2) |
| 5072 | return; /* Only FT Action Response is supported for now */ |
| 5073 | sta_addr = data + 1; |
| 5074 | target_ap_addr = data + 1 + ETH_ALEN; |
| 5075 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); |
| 5076 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
| 5077 | MACSTR " TargetAP " MACSTR " status %u", |
| 5078 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); |
| 5079 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5080 | if (!ether_addr_equal(sta_addr, wpa_s->own_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5081 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
| 5082 | " in FT Action Response", MAC2STR(sta_addr)); |
| 5083 | return; |
| 5084 | } |
| 5085 | |
| 5086 | if (status) { |
| 5087 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
| 5088 | "failure (status code %d)", status); |
| 5089 | /* TODO: report error to FT code(?) */ |
| 5090 | return; |
| 5091 | } |
| 5092 | |
| 5093 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, |
| 5094 | len - (1 + 2 * ETH_ALEN + 2), 1, |
| 5095 | target_ap_addr, NULL, 0) < 0) |
| 5096 | return; |
| 5097 | |
| 5098 | #ifdef CONFIG_SME |
| 5099 | { |
| 5100 | struct wpa_bss *bss; |
| 5101 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); |
| 5102 | if (bss) |
| 5103 | wpa_s->sme.freq = bss->freq; |
| 5104 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
| 5105 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
| 5106 | WLAN_AUTH_FT); |
| 5107 | } |
| 5108 | #endif /* CONFIG_SME */ |
| 5109 | } |
| 5110 | #endif /* CONFIG_IEEE80211R */ |
| 5111 | |
| 5112 | |
| 5113 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
| 5114 | struct unprot_deauth *e) |
| 5115 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5116 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " |
| 5117 | "dropped: " MACSTR " -> " MACSTR |
| 5118 | " (reason code %u)", |
| 5119 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); |
| 5120 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | |
| 5124 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, |
| 5125 | struct unprot_disassoc *e) |
| 5126 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5127 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " |
| 5128 | "dropped: " MACSTR " -> " MACSTR |
| 5129 | " (reason code %u)", |
| 5130 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); |
| 5131 | sme_event_unprot_disconnect(wpa_s, e->sa, e->da, e->reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5135 | static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 5136 | u16 reason_code, int locally_generated, |
| 5137 | const u8 *ie, size_t ie_len, int deauth) |
| 5138 | { |
| 5139 | #ifdef CONFIG_AP |
| 5140 | if (wpa_s->ap_iface && addr) { |
| 5141 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); |
| 5142 | return; |
| 5143 | } |
| 5144 | |
| 5145 | if (wpa_s->ap_iface) { |
| 5146 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); |
| 5147 | return; |
| 5148 | } |
| 5149 | #endif /* CONFIG_AP */ |
| 5150 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5151 | if (!locally_generated) |
| 5152 | wpa_s->own_disconnect_req = 0; |
| 5153 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5154 | wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); |
| 5155 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5156 | if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || |
| 5157 | ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 5158 | (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && |
| 5159 | eapol_sm_failed(wpa_s->eapol))) && |
| 5160 | !wpa_s->eap_expected_failure)) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5161 | wpas_auth_failed(wpa_s, "AUTH_FAILED", addr); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5162 | |
| 5163 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 5164 | if (deauth && reason_code > 0) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5165 | if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, |
| 5166 | locally_generated) > 0) { |
| 5167 | /* |
| 5168 | * The interface was removed, so cannot continue |
| 5169 | * processing any additional operations after this. |
| 5170 | */ |
| 5171 | return; |
| 5172 | } |
| 5173 | } |
| 5174 | #endif /* CONFIG_P2P */ |
| 5175 | |
| 5176 | wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, |
| 5177 | locally_generated); |
| 5178 | } |
| 5179 | |
| 5180 | |
| 5181 | static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, |
| 5182 | struct disassoc_info *info) |
| 5183 | { |
| 5184 | u16 reason_code = 0; |
| 5185 | int locally_generated = 0; |
| 5186 | const u8 *addr = NULL; |
| 5187 | const u8 *ie = NULL; |
| 5188 | size_t ie_len = 0; |
| 5189 | |
| 5190 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); |
| 5191 | |
| 5192 | if (info) { |
| 5193 | addr = info->addr; |
| 5194 | ie = info->ie; |
| 5195 | ie_len = info->ie_len; |
| 5196 | reason_code = info->reason_code; |
| 5197 | locally_generated = info->locally_generated; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5198 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code, |
| 5199 | reason2str(reason_code), |
| 5200 | locally_generated ? " locally_generated=1" : ""); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5201 | if (addr) |
| 5202 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
| 5203 | MAC2STR(addr)); |
| 5204 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", |
| 5205 | ie, ie_len); |
| 5206 | } |
| 5207 | |
| 5208 | #ifdef CONFIG_AP |
| 5209 | if (wpa_s->ap_iface && info && info->addr) { |
| 5210 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); |
| 5211 | return; |
| 5212 | } |
| 5213 | |
| 5214 | if (wpa_s->ap_iface) { |
| 5215 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); |
| 5216 | return; |
| 5217 | } |
| 5218 | #endif /* CONFIG_AP */ |
| 5219 | |
| 5220 | #ifdef CONFIG_P2P |
| 5221 | if (info) { |
| 5222 | wpas_p2p_disassoc_notif( |
| 5223 | wpa_s, info->addr, reason_code, info->ie, info->ie_len, |
| 5224 | locally_generated); |
| 5225 | } |
| 5226 | #endif /* CONFIG_P2P */ |
| 5227 | |
| 5228 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 5229 | sme_event_disassoc(wpa_s, info); |
| 5230 | |
| 5231 | wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, |
| 5232 | ie, ie_len, 0); |
| 5233 | } |
| 5234 | |
| 5235 | |
| 5236 | static void wpas_event_deauth(struct wpa_supplicant *wpa_s, |
| 5237 | struct deauth_info *info) |
| 5238 | { |
| 5239 | u16 reason_code = 0; |
| 5240 | int locally_generated = 0; |
| 5241 | const u8 *addr = NULL; |
| 5242 | const u8 *ie = NULL; |
| 5243 | size_t ie_len = 0; |
| 5244 | |
| 5245 | wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); |
| 5246 | |
| 5247 | if (info) { |
| 5248 | addr = info->addr; |
| 5249 | ie = info->ie; |
| 5250 | ie_len = info->ie_len; |
| 5251 | reason_code = info->reason_code; |
| 5252 | locally_generated = info->locally_generated; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5253 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", |
| 5254 | reason_code, reason2str(reason_code), |
| 5255 | locally_generated ? " locally_generated=1" : ""); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5256 | if (addr) { |
| 5257 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
| 5258 | MAC2STR(addr)); |
| 5259 | } |
| 5260 | wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", |
| 5261 | ie, ie_len); |
| 5262 | } |
| 5263 | |
| 5264 | wpa_reset_ft_completed(wpa_s->wpa); |
| 5265 | |
| 5266 | wpas_event_disconnect(wpa_s, addr, reason_code, |
| 5267 | locally_generated, ie, ie_len, 1); |
| 5268 | } |
| 5269 | |
| 5270 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 5271 | static const char * reg_init_str(enum reg_change_initiator init) |
| 5272 | { |
| 5273 | switch (init) { |
| 5274 | case REGDOM_SET_BY_CORE: |
| 5275 | return "CORE"; |
| 5276 | case REGDOM_SET_BY_USER: |
| 5277 | return "USER"; |
| 5278 | case REGDOM_SET_BY_DRIVER: |
| 5279 | return "DRIVER"; |
| 5280 | case REGDOM_SET_BY_COUNTRY_IE: |
| 5281 | return "COUNTRY_IE"; |
| 5282 | case REGDOM_BEACON_HINT: |
| 5283 | return "BEACON_HINT"; |
| 5284 | } |
| 5285 | return "?"; |
| 5286 | } |
| 5287 | |
| 5288 | |
| 5289 | static const char * reg_type_str(enum reg_type type) |
| 5290 | { |
| 5291 | switch (type) { |
| 5292 | case REGDOM_TYPE_UNKNOWN: |
| 5293 | return "UNKNOWN"; |
| 5294 | case REGDOM_TYPE_COUNTRY: |
| 5295 | return "COUNTRY"; |
| 5296 | case REGDOM_TYPE_WORLD: |
| 5297 | return "WORLD"; |
| 5298 | case REGDOM_TYPE_CUSTOM_WORLD: |
| 5299 | return "CUSTOM_WORLD"; |
| 5300 | case REGDOM_TYPE_INTERSECTION: |
| 5301 | return "INTERSECTION"; |
| 5302 | } |
| 5303 | return "?"; |
| 5304 | } |
| 5305 | |
| 5306 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5307 | static void wpas_beacon_hint(struct wpa_supplicant *wpa_s, const char *title, |
| 5308 | struct frequency_attrs *attrs) |
| 5309 | { |
| 5310 | if (!attrs->freq) |
| 5311 | return; |
| 5312 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_REGDOM_BEACON_HINT |
| 5313 | "%s freq=%u max_tx_power=%u%s%s%s", |
| 5314 | title, attrs->freq, attrs->max_tx_power, |
| 5315 | attrs->disabled ? " disabled=1" : "", |
| 5316 | attrs->no_ir ? " no_ir=1" : "", |
| 5317 | attrs->radar ? " radar=1" : ""); |
| 5318 | } |
| 5319 | |
| 5320 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5321 | void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s, |
| 5322 | struct channel_list_changed *info) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5323 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5324 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5325 | u8 dfs_domain; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5326 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5327 | /* |
| 5328 | * To allow backwards compatibility with higher level layers that |
| 5329 | * assumed the REGDOM_CHANGE event is sent over the initially added |
| 5330 | * interface. Find the highest parent of this interface and use it to |
| 5331 | * send the event. |
| 5332 | */ |
| 5333 | for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent) |
| 5334 | ; |
| 5335 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5336 | if (info) { |
| 5337 | wpa_msg(ifs, MSG_INFO, |
| 5338 | WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s", |
| 5339 | reg_init_str(info->initiator), reg_type_str(info->type), |
| 5340 | info->alpha2[0] ? " alpha2=" : "", |
| 5341 | info->alpha2[0] ? info->alpha2 : ""); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5342 | |
| 5343 | if (info->initiator == REGDOM_BEACON_HINT) { |
| 5344 | wpas_beacon_hint(ifs, "before", |
| 5345 | &info->beacon_hint_before); |
| 5346 | wpas_beacon_hint(ifs, "after", |
| 5347 | &info->beacon_hint_after); |
| 5348 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5349 | } |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 5350 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5351 | if (wpa_s->drv_priv == NULL) |
| 5352 | return; /* Ignore event during drv initialization */ |
| 5353 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 5354 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 5355 | radio_list) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5356 | bool was_6ghz_enabled; |
| 5357 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5358 | wpa_printf(MSG_DEBUG, "%s: Updating hw mode", |
| 5359 | ifs->ifname); |
| 5360 | free_hw_features(ifs); |
| 5361 | ifs->hw.modes = wpa_drv_get_hw_feature_data( |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5362 | ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 5363 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5364 | was_6ghz_enabled = ifs->is_6ghz_enabled; |
| 5365 | ifs->is_6ghz_enabled = wpas_is_6ghz_supported(ifs, true); |
| 5366 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5367 | /* Restart PNO/sched_scan with updated channel list */ |
| 5368 | if (ifs->pno) { |
| 5369 | wpas_stop_pno(ifs); |
| 5370 | wpas_start_pno(ifs); |
| 5371 | } else if (ifs->sched_scanning && !ifs->pno_sched_pending) { |
| 5372 | wpa_dbg(ifs, MSG_DEBUG, |
| 5373 | "Channel list changed - restart sched_scan"); |
| 5374 | wpas_scan_restart_sched_scan(ifs); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5375 | } else if (ifs->scanning && !was_6ghz_enabled && |
| 5376 | ifs->is_6ghz_enabled) { |
| 5377 | /* Look for APs in the 6 GHz band */ |
| 5378 | wpa_dbg(ifs, MSG_INFO, |
| 5379 | "Channel list changed - trigger 6 GHz-only scan"); |
| 5380 | ifs->crossed_6ghz_dom = true; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5381 | } |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 5382 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5383 | |
| 5384 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5385 | } |
| 5386 | |
| 5387 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5388 | static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5389 | const u8 *frame, size_t len, int freq, |
| 5390 | int rssi) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5391 | { |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 5392 | const struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5393 | const u8 *payload; |
| 5394 | size_t plen; |
| 5395 | u8 category; |
| 5396 | |
| 5397 | if (len < IEEE80211_HDRLEN + 2) |
| 5398 | return; |
| 5399 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 5400 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 5401 | payload = frame + IEEE80211_HDRLEN; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5402 | category = *payload++; |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 5403 | plen = len - IEEE80211_HDRLEN - 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5404 | |
| 5405 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR |
| 5406 | " Category=%u DataLen=%d freq=%d MHz", |
| 5407 | MAC2STR(mgmt->sa), category, (int) plen, freq); |
| 5408 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5409 | #ifndef CONFIG_NO_WMM_AC |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5410 | if (category == WLAN_ACTION_WMM) { |
| 5411 | wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen); |
| 5412 | return; |
| 5413 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5414 | #endif /* CONFIG_NO_WMM_AC */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5415 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5416 | #ifdef CONFIG_IEEE80211R |
| 5417 | if (category == WLAN_ACTION_FT) { |
| 5418 | ft_rx_action(wpa_s, payload, plen); |
| 5419 | return; |
| 5420 | } |
| 5421 | #endif /* CONFIG_IEEE80211R */ |
| 5422 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5423 | #ifdef CONFIG_SME |
| 5424 | if (category == WLAN_ACTION_SA_QUERY) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5425 | sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5426 | return; |
| 5427 | } |
| 5428 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5429 | |
| 5430 | #ifdef CONFIG_WNM |
| 5431 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
| 5432 | ieee802_11_rx_wnm_action(wpa_s, mgmt, len); |
| 5433 | return; |
| 5434 | } |
| 5435 | #endif /* CONFIG_WNM */ |
| 5436 | |
| 5437 | #ifdef CONFIG_GAS |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5438 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
| 5439 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5440 | gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid, |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 5441 | mgmt->u.action.category, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5442 | payload, plen, freq) == 0) |
| 5443 | return; |
| 5444 | #endif /* CONFIG_GAS */ |
| 5445 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5446 | #ifdef CONFIG_GAS_SERVER |
| 5447 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
| 5448 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && |
| 5449 | gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid, |
| 5450 | mgmt->u.action.category, |
| 5451 | payload, plen, freq) == 0) |
| 5452 | return; |
| 5453 | #endif /* CONFIG_GAS_SERVER */ |
| 5454 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5455 | #ifdef CONFIG_TDLS |
| 5456 | if (category == WLAN_ACTION_PUBLIC && plen >= 4 && |
| 5457 | payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { |
| 5458 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5459 | "TDLS: Received Discovery Response from " MACSTR, |
| 5460 | MAC2STR(mgmt->sa)); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5461 | if (wpa_s->valid_links && |
| 5462 | wpa_tdls_process_discovery_response(wpa_s->wpa, mgmt->sa, |
| 5463 | &payload[1], plen - 1)) |
| 5464 | wpa_dbg(wpa_s, MSG_ERROR, |
| 5465 | "TDLS: Discovery Response process failed for " |
| 5466 | MACSTR, MAC2STR(mgmt->sa)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5467 | return; |
| 5468 | } |
| 5469 | #endif /* CONFIG_TDLS */ |
| 5470 | |
| 5471 | #ifdef CONFIG_INTERWORKING |
| 5472 | if (category == WLAN_ACTION_QOS && plen >= 1 && |
| 5473 | payload[0] == QOS_QOS_MAP_CONFIG) { |
| 5474 | const u8 *pos = payload + 1; |
| 5475 | size_t qlen = plen - 1; |
| 5476 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from " |
| 5477 | MACSTR, MAC2STR(mgmt->sa)); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5478 | if (ether_addr_equal(mgmt->sa, wpa_s->bssid) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5479 | qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET && |
| 5480 | pos[1] <= qlen - 2 && pos[1] >= 16) |
| 5481 | wpas_qos_map_set(wpa_s, pos + 2, pos[1]); |
| 5482 | return; |
| 5483 | } |
| 5484 | #endif /* CONFIG_INTERWORKING */ |
| 5485 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5486 | #ifndef CONFIG_NO_RRM |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5487 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5488 | payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) { |
| 5489 | wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5490 | mgmt->da, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5491 | payload + 1, |
| 5492 | plen - 1); |
| 5493 | return; |
| 5494 | } |
| 5495 | |
| 5496 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5497 | payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) { |
| 5498 | wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1); |
| 5499 | return; |
| 5500 | } |
| 5501 | |
| 5502 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
| 5503 | payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) { |
| 5504 | wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa, |
| 5505 | payload + 1, plen - 1, |
| 5506 | rssi); |
| 5507 | return; |
| 5508 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5509 | #endif /* CONFIG_NO_RRM */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5510 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5511 | #ifdef CONFIG_FST |
| 5512 | if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) { |
| 5513 | fst_rx_action(wpa_s->fst, mgmt, len); |
| 5514 | return; |
| 5515 | } |
| 5516 | #endif /* CONFIG_FST */ |
| 5517 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5518 | #ifdef CONFIG_NAN_USD |
| 5519 | if (category == WLAN_ACTION_PUBLIC && plen >= 5 && |
| 5520 | payload[0] == WLAN_PA_VENDOR_SPECIFIC && |
| 5521 | WPA_GET_BE32(&payload[1]) == NAN_SDF_VENDOR_TYPE) { |
| 5522 | payload += 5; |
| 5523 | plen -= 5; |
| 5524 | wpas_nan_usd_rx_sdf(wpa_s, mgmt->sa, freq, payload, plen); |
| 5525 | return; |
| 5526 | } |
| 5527 | #endif /* CONFIG_NAN_USD */ |
| 5528 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5529 | #ifdef CONFIG_DPP |
| 5530 | if (category == WLAN_ACTION_PUBLIC && plen >= 5 && |
| 5531 | payload[0] == WLAN_PA_VENDOR_SPECIFIC && |
| 5532 | WPA_GET_BE24(&payload[1]) == OUI_WFA && |
| 5533 | payload[4] == DPP_OUI_TYPE) { |
| 5534 | payload++; |
| 5535 | plen--; |
| 5536 | wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq); |
| 5537 | return; |
| 5538 | } |
| 5539 | #endif /* CONFIG_DPP */ |
| 5540 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5541 | #ifndef CONFIG_NO_ROBUST_AV |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5542 | if (category == WLAN_ACTION_ROBUST_AV_STREAMING && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5543 | payload[0] == ROBUST_AV_SCS_RESP) { |
| 5544 | wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa, |
| 5545 | payload + 1, plen - 1); |
| 5546 | return; |
| 5547 | } |
| 5548 | |
| 5549 | if (category == WLAN_ACTION_ROBUST_AV_STREAMING && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5550 | payload[0] == ROBUST_AV_MSCS_RESP) { |
| 5551 | wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa, |
| 5552 | payload + 1, plen - 1); |
| 5553 | return; |
| 5554 | } |
| 5555 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5556 | if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 && |
| 5557 | WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) { |
| 5558 | wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa, |
| 5559 | payload + 4, plen - 4); |
| 5560 | return; |
| 5561 | } |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5562 | #endif /* CONFIG_NO_ROBUST_AV */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5563 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5564 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 5565 | category, payload, plen, freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5566 | if (wpa_s->ifmsh) |
| 5567 | mesh_mpm_action_rx(wpa_s, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5568 | } |
| 5569 | |
| 5570 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5571 | static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s, |
| 5572 | union wpa_event_data *event) |
| 5573 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5574 | struct wpa_freq_range_list *list; |
| 5575 | char *str = NULL; |
| 5576 | |
| 5577 | list = &event->freq_range; |
| 5578 | |
| 5579 | if (list->num) |
| 5580 | str = freq_range_list_str(list); |
| 5581 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s", |
| 5582 | str ? str : ""); |
| 5583 | |
| 5584 | #ifdef CONFIG_P2P |
| 5585 | if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) { |
| 5586 | wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range", |
| 5587 | __func__); |
| 5588 | } else { |
| 5589 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Update channel list based on frequency avoid event"); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5590 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5591 | /* |
| 5592 | * The update channel flow will also take care of moving a GO |
| 5593 | * from the unsafe frequency if needed. |
| 5594 | */ |
| 5595 | wpas_p2p_update_channel_list(wpa_s, |
| 5596 | WPAS_P2P_CHANNEL_UPDATE_AVOID); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5597 | } |
| 5598 | #endif /* CONFIG_P2P */ |
| 5599 | |
| 5600 | os_free(str); |
| 5601 | } |
| 5602 | |
| 5603 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5604 | static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5605 | { |
Sunil Ravi | 167279a | 2023-05-31 01:12:34 +0000 | [diff] [blame] | 5606 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5607 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 5608 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 5609 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
| 5610 | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5611 | wpa_s->drv_authorized_port = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5612 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5613 | } |
| 5614 | |
| 5615 | |
| 5616 | static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s, |
| 5617 | int freq) |
| 5618 | { |
| 5619 | size_t i; |
| 5620 | int j; |
| 5621 | |
| 5622 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 5623 | const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i]; |
| 5624 | |
| 5625 | for (j = 0; j < mode->num_channels; j++) { |
| 5626 | const struct hostapd_channel_data *chan; |
| 5627 | |
| 5628 | chan = &mode->channels[j]; |
| 5629 | if (chan->freq == freq) |
| 5630 | return chan->dfs_cac_ms; |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | return 0; |
| 5635 | } |
| 5636 | |
| 5637 | |
| 5638 | static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s, |
| 5639 | struct dfs_event *radar) |
| 5640 | { |
| 5641 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5642 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5643 | wpas_ap_event_dfs_cac_started(wpa_s, radar); |
| 5644 | } else |
| 5645 | #endif /* NEED_AP_MLME && CONFIG_AP */ |
| 5646 | { |
| 5647 | unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq); |
| 5648 | |
| 5649 | cac_time /= 1000; /* convert from ms to sec */ |
| 5650 | if (!cac_time) |
| 5651 | cac_time = 10 * 60; /* max timeout: 10 minutes */ |
| 5652 | |
| 5653 | /* Restart auth timeout: CAC time added to initial timeout */ |
| 5654 | wpas_auth_timeout_restart(wpa_s, cac_time); |
| 5655 | } |
| 5656 | } |
| 5657 | |
| 5658 | |
| 5659 | static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s, |
| 5660 | struct dfs_event *radar) |
| 5661 | { |
| 5662 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5663 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5664 | wpas_ap_event_dfs_cac_finished(wpa_s, radar); |
| 5665 | } else |
| 5666 | #endif /* NEED_AP_MLME && CONFIG_AP */ |
| 5667 | { |
| 5668 | /* Restart auth timeout with original value after CAC is |
| 5669 | * finished */ |
| 5670 | wpas_auth_timeout_restart(wpa_s, 0); |
| 5671 | } |
| 5672 | } |
| 5673 | |
| 5674 | |
| 5675 | static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s, |
| 5676 | struct dfs_event *radar) |
| 5677 | { |
| 5678 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5679 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5680 | wpas_ap_event_dfs_cac_aborted(wpa_s, radar); |
| 5681 | } else |
| 5682 | #endif /* NEED_AP_MLME && CONFIG_AP */ |
| 5683 | { |
| 5684 | /* Restart auth timeout with original value after CAC is |
| 5685 | * aborted */ |
| 5686 | wpas_auth_timeout_restart(wpa_s, 0); |
| 5687 | } |
| 5688 | } |
| 5689 | |
| 5690 | |
| 5691 | static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s, |
| 5692 | union wpa_event_data *data) |
| 5693 | { |
| 5694 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5695 | "Connection authorized by device, previous state %d", |
| 5696 | wpa_s->wpa_state); |
| 5697 | |
| 5698 | wpa_supplicant_event_port_authorized(wpa_s); |
| 5699 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5700 | wpa_s->last_eapol_matches_bssid = 1; |
| 5701 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5702 | wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr); |
| 5703 | wpa_sm_set_ptk_kck_kek(wpa_s->wpa, data->assoc_info.ptk_kck, |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5704 | data->assoc_info.ptk_kck_len, |
| 5705 | data->assoc_info.ptk_kek, |
| 5706 | data->assoc_info.ptk_kek_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5707 | #ifdef CONFIG_FILS |
| 5708 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) { |
| 5709 | struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); |
| 5710 | const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss); |
| 5711 | |
| 5712 | /* Update ERP next sequence number */ |
| 5713 | eapol_sm_update_erp_next_seq_num( |
| 5714 | wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num); |
| 5715 | |
| 5716 | if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) { |
| 5717 | /* Add the new PMK and PMKID to the PMKSA cache */ |
| 5718 | wpa_sm_pmksa_cache_add(wpa_s->wpa, |
| 5719 | data->assoc_info.fils_pmk, |
| 5720 | data->assoc_info.fils_pmk_len, |
| 5721 | data->assoc_info.fils_pmkid, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5722 | wpa_s->valid_links ? |
| 5723 | wpa_s->ap_mld_addr : |
| 5724 | wpa_s->bssid, |
| 5725 | fils_cache_id); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5726 | } else if (data->assoc_info.fils_pmkid) { |
| 5727 | /* Update the current PMKSA used for this connection */ |
| 5728 | pmksa_cache_set_current(wpa_s->wpa, |
| 5729 | data->assoc_info.fils_pmkid, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 5730 | NULL, NULL, 0, NULL, 0, true); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5731 | } |
| 5732 | } |
| 5733 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5734 | } |
| 5735 | |
| 5736 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5737 | static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code) |
| 5738 | { |
| 5739 | switch (code) { |
| 5740 | case STA_CONNECT_FAIL_REASON_UNSPECIFIED: |
| 5741 | return ""; |
| 5742 | case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND: |
| 5743 | return "no_bss_found"; |
| 5744 | case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL: |
| 5745 | return "auth_tx_fail"; |
| 5746 | case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED: |
| 5747 | return "auth_no_ack_received"; |
| 5748 | case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED: |
| 5749 | return "auth_no_resp_received"; |
| 5750 | case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL: |
| 5751 | return "assoc_req_tx_fail"; |
| 5752 | case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED: |
| 5753 | return "assoc_no_ack_received"; |
| 5754 | case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED: |
| 5755 | return "assoc_no_resp_received"; |
| 5756 | default: |
| 5757 | return "unknown_reason"; |
| 5758 | } |
| 5759 | } |
| 5760 | |
| 5761 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5762 | static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s, |
| 5763 | union wpa_event_data *data) |
| 5764 | { |
| 5765 | const u8 *bssid = data->assoc_reject.bssid; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5766 | struct ieee802_11_elems elems; |
| 5767 | const u8 *link_bssids[MAX_NUM_MLD_LINKS]; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5768 | #ifdef CONFIG_MBO |
| 5769 | struct wpa_bss *reject_bss; |
| 5770 | #endif /* CONFIG_MBO */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5771 | |
| 5772 | if (!bssid || is_zero_ether_addr(bssid)) |
| 5773 | bssid = wpa_s->pending_bssid; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5774 | #ifdef CONFIG_MBO |
| 5775 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 5776 | reject_bss = wpa_s->current_bss; |
| 5777 | else |
| 5778 | reject_bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 5779 | #endif /* CONFIG_MBO */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5780 | |
| 5781 | if (data->assoc_reject.bssid) |
| 5782 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5783 | "bssid=" MACSTR " status_code=%u%s%s%s%s%s", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5784 | MAC2STR(data->assoc_reject.bssid), |
| 5785 | data->assoc_reject.status_code, |
| 5786 | data->assoc_reject.timed_out ? " timeout" : "", |
| 5787 | data->assoc_reject.timeout_reason ? "=" : "", |
| 5788 | data->assoc_reject.timeout_reason ? |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5789 | data->assoc_reject.timeout_reason : "", |
| 5790 | data->assoc_reject.reason_code != |
| 5791 | STA_CONNECT_FAIL_REASON_UNSPECIFIED ? |
| 5792 | " qca_driver_reason=" : "", |
| 5793 | connect_fail_reason(data->assoc_reject.reason_code)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5794 | else |
| 5795 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5796 | "status_code=%u%s%s%s%s%s", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5797 | data->assoc_reject.status_code, |
| 5798 | data->assoc_reject.timed_out ? " timeout" : "", |
| 5799 | data->assoc_reject.timeout_reason ? "=" : "", |
| 5800 | data->assoc_reject.timeout_reason ? |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5801 | data->assoc_reject.timeout_reason : "", |
| 5802 | data->assoc_reject.reason_code != |
| 5803 | STA_CONNECT_FAIL_REASON_UNSPECIFIED ? |
| 5804 | " qca_driver_reason=" : "", |
| 5805 | connect_fail_reason(data->assoc_reject.reason_code)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5806 | wpa_s->assoc_status_code = data->assoc_reject.status_code; |
Sunil Ravi | e06118e | 2021-01-03 08:39:46 -0800 | [diff] [blame] | 5807 | wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out, |
| 5808 | data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5809 | |
| 5810 | #ifdef CONFIG_OWE |
| 5811 | if (data->assoc_reject.status_code == |
| 5812 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && |
| 5813 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && |
| 5814 | wpa_s->current_ssid && |
| 5815 | wpa_s->current_ssid->owe_group == 0 && |
| 5816 | wpa_s->last_owe_group != 21) { |
| 5817 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5818 | struct wpa_bss *bss = wpa_s->current_bss; |
| 5819 | |
| 5820 | if (!bss) { |
| 5821 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 5822 | if (!bss) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5823 | wpas_connection_failed(wpa_s, bssid, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5824 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5825 | return; |
| 5826 | } |
| 5827 | } |
| 5828 | wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group"); |
| 5829 | wpas_connect_work_done(wpa_s); |
| 5830 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5831 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 5832 | return; |
| 5833 | } |
| 5834 | #endif /* CONFIG_OWE */ |
| 5835 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5836 | #ifdef CONFIG_DPP2 |
| 5837 | /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is |
| 5838 | * the status code defined in the DPP R2 tech spec. |
| 5839 | * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an |
| 5840 | * interoperability workaround with older hostapd implementation. */ |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5841 | if (DPP_VERSION > 1 && wpa_s->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5842 | (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP || |
| 5843 | ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) && |
| 5844 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5845 | wpa_s->current_ssid->dpp_pfs == 0 && |
| 5846 | (data->assoc_reject.status_code == |
| 5847 | WLAN_STATUS_ASSOC_DENIED_UNSPEC || |
| 5848 | data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) { |
| 5849 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5850 | struct wpa_bss *bss = wpa_s->current_bss; |
| 5851 | |
| 5852 | wpa_s->current_ssid->dpp_pfs_fallback ^= 1; |
| 5853 | if (!bss) |
| 5854 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 5855 | if (!bss || wpa_s->dpp_pfs_fallback) { |
| 5856 | wpa_printf(MSG_DEBUG, |
| 5857 | "DPP: Updated PFS policy for next try"); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5858 | wpas_connection_failed(wpa_s, bssid, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5859 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5860 | return; |
| 5861 | } |
| 5862 | wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy"); |
| 5863 | wpa_s->dpp_pfs_fallback = 1; |
| 5864 | wpas_connect_work_done(wpa_s); |
| 5865 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5866 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 5867 | return; |
| 5868 | } |
| 5869 | #endif /* CONFIG_DPP2 */ |
| 5870 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5871 | #ifdef CONFIG_MBO |
| 5872 | if (data->assoc_reject.status_code == |
| 5873 | WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS && |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5874 | reject_bss && data->assoc_reject.resp_ies) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5875 | const u8 *rssi_rej; |
| 5876 | |
| 5877 | rssi_rej = mbo_get_attr_from_ies( |
| 5878 | data->assoc_reject.resp_ies, |
| 5879 | data->assoc_reject.resp_ies_len, |
| 5880 | OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT); |
| 5881 | if (rssi_rej && rssi_rej[1] == 2) { |
| 5882 | wpa_printf(MSG_DEBUG, |
| 5883 | "OCE: RSSI-based association rejection from " |
| 5884 | MACSTR " (Delta RSSI: %u, Retry Delay: %u)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5885 | MAC2STR(reject_bss->bssid), |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5886 | rssi_rej[2], rssi_rej[3]); |
| 5887 | wpa_bss_tmp_disallow(wpa_s, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5888 | reject_bss->bssid, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5889 | rssi_rej[3], |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5890 | rssi_rej[2] + reject_bss->level); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5891 | } |
| 5892 | } |
| 5893 | #endif /* CONFIG_MBO */ |
| 5894 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5895 | /* Check for other failed links in the response */ |
| 5896 | os_memset(link_bssids, 0, sizeof(link_bssids)); |
| 5897 | if (ieee802_11_parse_elems(data->assoc_reject.resp_ies, |
| 5898 | data->assoc_reject.resp_ies_len, |
| 5899 | &elems, 1) != ParseFailed) { |
| 5900 | struct ml_sta_link_info ml_info[MAX_NUM_MLD_LINKS]; |
| 5901 | unsigned int n_links, i, idx; |
| 5902 | |
| 5903 | idx = 0; |
| 5904 | n_links = wpas_ml_parse_assoc(wpa_s, &elems, ml_info); |
| 5905 | |
| 5906 | for (i = 1; i < n_links; i++) { |
| 5907 | /* The status cannot be success here. |
| 5908 | * Add the link to the failed list if it is reporting |
| 5909 | * an error. The only valid "non-error" status is |
| 5910 | * TX_LINK_NOT_ACCEPTED as that means this link may |
| 5911 | * still accept an association from us. |
| 5912 | */ |
| 5913 | if (ml_info[i].status != |
| 5914 | WLAN_STATUS_DENIED_TX_LINK_NOT_ACCEPTED) { |
| 5915 | link_bssids[idx] = ml_info[i].bssid; |
| 5916 | idx++; |
| 5917 | } |
| 5918 | } |
| 5919 | } |
| 5920 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5921 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5922 | sme_event_assoc_reject(wpa_s, data, link_bssids); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5923 | return; |
| 5924 | } |
| 5925 | |
| 5926 | /* Driver-based SME cases */ |
| 5927 | |
| 5928 | #ifdef CONFIG_SAE |
| 5929 | if (wpa_s->current_ssid && |
| 5930 | wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) && |
| 5931 | !data->assoc_reject.timed_out) { |
| 5932 | wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry"); |
| 5933 | wpa_sm_aborted_cached(wpa_s->wpa); |
| 5934 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); |
| 5935 | } |
| 5936 | #endif /* CONFIG_SAE */ |
| 5937 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5938 | #ifdef CONFIG_DPP |
| 5939 | if (wpa_s->current_ssid && |
| 5940 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP && |
| 5941 | !data->assoc_reject.timed_out) { |
| 5942 | wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry"); |
| 5943 | wpa_sm_aborted_cached(wpa_s->wpa); |
| 5944 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); |
| 5945 | } |
| 5946 | #endif /* CONFIG_DPP */ |
| 5947 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5948 | #ifdef CONFIG_FILS |
| 5949 | /* Update ERP next sequence number */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 5950 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5951 | fils_pmksa_cache_flush(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5952 | eapol_sm_update_erp_next_seq_num( |
| 5953 | wpa_s->eapol, |
| 5954 | data->assoc_reject.fils_erp_next_seq_num); |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 5955 | fils_connection_failure(wpa_s); |
| 5956 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5957 | #endif /* CONFIG_FILS */ |
| 5958 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5959 | wpas_connection_failed(wpa_s, bssid, link_bssids); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5960 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5961 | } |
| 5962 | |
| 5963 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5964 | static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s, |
| 5965 | struct unprot_beacon *data) |
| 5966 | { |
| 5967 | struct wpabuf *buf; |
| 5968 | int res; |
| 5969 | |
| 5970 | if (!data || wpa_s->wpa_state != WPA_COMPLETED || |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 5971 | !ether_addr_equal(data->sa, wpa_s->bssid)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5972 | return; |
| 5973 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR, |
| 5974 | MAC2STR(data->sa)); |
| 5975 | |
| 5976 | buf = wpabuf_alloc(4); |
| 5977 | if (!buf) |
| 5978 | return; |
| 5979 | |
| 5980 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 5981 | wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ); |
| 5982 | wpabuf_put_u8(buf, 1); /* Dialog Token */ |
| 5983 | wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE); |
| 5984 | |
| 5985 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 5986 | wpa_s->own_addr, wpa_s->bssid, |
| 5987 | wpabuf_head(buf), wpabuf_len(buf), 0); |
| 5988 | if (res < 0) |
| 5989 | wpa_printf(MSG_DEBUG, |
| 5990 | "Failed to send WNM-Notification Request frame"); |
| 5991 | |
| 5992 | wpabuf_free(buf); |
| 5993 | } |
| 5994 | |
| 5995 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 5996 | static const char * bitmap_to_str(u8 value, char *buf) |
| 5997 | { |
| 5998 | char *pos = buf; |
| 5999 | int i, k = 0; |
| 6000 | |
| 6001 | for (i = 7; i >= 0; i--) |
| 6002 | pos[k++] = (value & BIT(i)) ? '1' : '0'; |
| 6003 | |
| 6004 | pos[8] = '\0'; |
| 6005 | return pos; |
| 6006 | } |
| 6007 | |
| 6008 | |
| 6009 | static void wpas_tid_link_map(struct wpa_supplicant *wpa_s, |
| 6010 | struct tid_link_map_info *info) |
| 6011 | { |
| 6012 | char map_info[1000], *pos, *end; |
| 6013 | int res, i; |
| 6014 | |
| 6015 | pos = map_info; |
| 6016 | end = pos + sizeof(map_info); |
| 6017 | res = os_snprintf(map_info, sizeof(map_info), "default=%d", |
| 6018 | info->default_map); |
| 6019 | if (os_snprintf_error(end - pos, res)) |
| 6020 | return; |
| 6021 | pos += res; |
| 6022 | |
| 6023 | if (!info->default_map) { |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 6024 | for (i = 0; i < MAX_NUM_MLD_LINKS && end > pos; i++) { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 6025 | char uplink_map_str[9]; |
| 6026 | char downlink_map_str[9]; |
| 6027 | |
Sunil Ravi | 8861141 | 2024-06-28 17:34:56 +0000 | [diff] [blame] | 6028 | if (!(info->valid_links & BIT(i))) |
| 6029 | continue; |
| 6030 | |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 6031 | bitmap_to_str(info->t2lmap[i].uplink, uplink_map_str); |
| 6032 | bitmap_to_str(info->t2lmap[i].downlink, |
| 6033 | downlink_map_str); |
| 6034 | |
| 6035 | res = os_snprintf(pos, end - pos, |
| 6036 | " link_id=%d up_link=%s down_link=%s", |
| 6037 | i, uplink_map_str, |
| 6038 | downlink_map_str); |
| 6039 | if (os_snprintf_error(end - pos, res)) |
| 6040 | return; |
| 6041 | pos += res; |
| 6042 | } |
| 6043 | } |
| 6044 | |
Veerendranath Jakkam | bc2fa49 | 2023-05-25 01:26:50 +0530 | [diff] [blame] | 6045 | wpas_notify_mlo_info_change_reason(wpa_s, MLO_TID_TO_LINK_MAP); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 6046 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_T2LM_UPDATE "%s", map_info); |
| 6047 | } |
| 6048 | |
| 6049 | |
| 6050 | static void wpas_link_reconfig(struct wpa_supplicant *wpa_s) |
| 6051 | { |
| 6052 | u8 bssid[ETH_ALEN]; |
| 6053 | |
| 6054 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 6055 | wpa_printf(MSG_ERROR, "LINK_RECONFIG: Failed to get BSSID"); |
| 6056 | wpa_supplicant_deauthenticate(wpa_s, |
| 6057 | WLAN_REASON_DEAUTH_LEAVING); |
| 6058 | return; |
| 6059 | } |
| 6060 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 6061 | if (!ether_addr_equal(bssid, wpa_s->bssid)) { |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 6062 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
| 6063 | wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid); |
| 6064 | wpas_notify_bssid_changed(wpa_s); |
| 6065 | } |
| 6066 | |
| 6067 | if (wpa_drv_get_mlo_info(wpa_s) < 0) { |
| 6068 | wpa_printf(MSG_ERROR, |
| 6069 | "LINK_RECONFIG: Failed to get MLO connection info"); |
| 6070 | wpa_supplicant_deauthenticate(wpa_s, |
| 6071 | WLAN_REASON_DEAUTH_LEAVING); |
| 6072 | return; |
| 6073 | } |
| 6074 | |
| 6075 | if (wpa_sm_set_ml_info(wpa_s)) { |
| 6076 | wpa_printf(MSG_ERROR, |
| 6077 | "LINK_RECONFIG: Failed to set MLO connection info to wpa_sm"); |
| 6078 | wpa_supplicant_deauthenticate(wpa_s, |
| 6079 | WLAN_REASON_DEAUTH_LEAVING); |
| 6080 | return; |
| 6081 | } |
| 6082 | |
Veerendranath Jakkam | bc2fa49 | 2023-05-25 01:26:50 +0530 | [diff] [blame] | 6083 | wpas_notify_mlo_info_change_reason(wpa_s, MLO_LINK_RECONFIG_AP_REMOVAL); |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 6084 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_LINK_RECONFIG "valid_links=0x%x", |
| 6085 | wpa_s->valid_links); |
| 6086 | } |
| 6087 | |
| 6088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6089 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
| 6090 | union wpa_event_data *data) |
| 6091 | { |
| 6092 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | af9da31 | 2015-04-03 10:03:11 -0700 | [diff] [blame] | 6093 | int resched; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6094 | struct os_reltime age, clear_at; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6095 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 6096 | int level = MSG_DEBUG; |
| 6097 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6098 | |
| 6099 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
| 6100 | event != EVENT_INTERFACE_ENABLED && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6101 | event != EVENT_INTERFACE_STATUS && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6102 | event != EVENT_SCAN_RESULTS && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6103 | event != EVENT_SCHED_SCAN_STOPPED) { |
| 6104 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6105 | "Ignore event %s (%d) while interface is disabled", |
| 6106 | event_to_string(event), event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6107 | return; |
| 6108 | } |
| 6109 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6110 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6111 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6112 | const struct ieee80211_hdr *hdr; |
| 6113 | u16 fc; |
| 6114 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
| 6115 | fc = le_to_host16(hdr->frame_control); |
| 6116 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 6117 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 6118 | level = MSG_EXCESSIVE; |
| 6119 | } |
| 6120 | |
| 6121 | wpa_dbg(wpa_s, level, "Event %s (%d) received", |
| 6122 | event_to_string(event), event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6123 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6124 | |
| 6125 | switch (event) { |
| 6126 | case EVENT_AUTH: |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6127 | #ifdef CONFIG_FST |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 6128 | if (!wpas_fst_update_mbie(wpa_s, data->auth.ies, |
| 6129 | data->auth.ies_len)) |
| 6130 | wpa_printf(MSG_DEBUG, |
| 6131 | "FST: MB IEs updated from auth IE"); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6132 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6133 | sme_event_auth(wpa_s, data); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6134 | wpa_s->auth_status_code = data->auth.status_code; |
| 6135 | wpas_notify_auth_status_code(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6136 | break; |
| 6137 | case EVENT_ASSOC: |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 6138 | #ifdef CONFIG_TESTING_OPTIONS |
| 6139 | if (wpa_s->ignore_auth_resp) { |
| 6140 | wpa_printf(MSG_INFO, |
| 6141 | "EVENT_ASSOC - ignore_auth_resp active!"); |
| 6142 | break; |
| 6143 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6144 | if (wpa_s->testing_resend_assoc) { |
| 6145 | wpa_printf(MSG_INFO, |
| 6146 | "EVENT_DEAUTH - testing_resend_assoc"); |
| 6147 | break; |
| 6148 | } |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 6149 | #endif /* CONFIG_TESTING_OPTIONS */ |
Vamsi Krishna | 3481262 | 2020-12-03 22:15:29 +0530 | [diff] [blame] | 6150 | if (wpa_s->disconnected) { |
| 6151 | wpa_printf(MSG_INFO, |
| 6152 | "Ignore unexpected EVENT_ASSOC in disconnected state"); |
| 6153 | break; |
| 6154 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6155 | wpa_supplicant_event_assoc(wpa_s, data); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6156 | wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6157 | if (data && |
| 6158 | (data->assoc_info.authorized || |
| 6159 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 6160 | wpa_fils_is_completed(wpa_s->wpa)))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6161 | wpa_supplicant_event_assoc_auth(wpa_s, data); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6162 | if (data) { |
| 6163 | wpa_msg(wpa_s, MSG_INFO, |
| 6164 | WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u", |
| 6165 | data->assoc_info.subnet_status); |
| 6166 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6167 | break; |
| 6168 | case EVENT_DISASSOC: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6169 | wpas_event_disassoc(wpa_s, |
| 6170 | data ? &data->disassoc_info : NULL); |
| 6171 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6172 | case EVENT_DEAUTH: |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 6173 | #ifdef CONFIG_TESTING_OPTIONS |
| 6174 | if (wpa_s->ignore_auth_resp) { |
| 6175 | wpa_printf(MSG_INFO, |
| 6176 | "EVENT_DEAUTH - ignore_auth_resp active!"); |
| 6177 | break; |
| 6178 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6179 | if (wpa_s->testing_resend_assoc) { |
| 6180 | wpa_printf(MSG_INFO, |
| 6181 | "EVENT_DEAUTH - testing_resend_assoc"); |
| 6182 | break; |
| 6183 | } |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 6184 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6185 | wpas_event_deauth(wpa_s, |
| 6186 | data ? &data->deauth_info : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6187 | break; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 6188 | case EVENT_LINK_RECONFIG: |
| 6189 | wpas_link_reconfig(wpa_s); |
| 6190 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6191 | case EVENT_MICHAEL_MIC_FAILURE: |
| 6192 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); |
| 6193 | break; |
| 6194 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6195 | case EVENT_SCAN_STARTED: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6196 | if (wpa_s->own_scan_requested || |
| 6197 | (data && !data->scan_info.external_scan)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6198 | struct os_reltime diff; |
| 6199 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6200 | os_get_reltime(&wpa_s->scan_start_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6201 | os_reltime_sub(&wpa_s->scan_start_time, |
| 6202 | &wpa_s->scan_trigger_time, &diff); |
| 6203 | wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds", |
| 6204 | diff.sec, diff.usec); |
| 6205 | wpa_s->own_scan_requested = 0; |
| 6206 | wpa_s->own_scan_running = 1; |
| 6207 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 6208 | wpa_s->manual_scan_use_id) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6209 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 6210 | WPA_EVENT_SCAN_STARTED "id=%u", |
| 6211 | wpa_s->manual_scan_id); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6212 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6213 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 6214 | WPA_EVENT_SCAN_STARTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6215 | } |
| 6216 | } else { |
| 6217 | wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6218 | wpa_s->radio->external_scan_req_interface = wpa_s; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6219 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6220 | } |
| 6221 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6222 | case EVENT_SCAN_RESULTS: |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6223 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 6224 | wpa_s->scan_res_handler = NULL; |
| 6225 | wpa_s->own_scan_running = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6226 | wpa_s->radio->external_scan_req_interface = NULL; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6227 | wpa_s->last_scan_req = NORMAL_SCAN_REQ; |
| 6228 | break; |
| 6229 | } |
| 6230 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6231 | if (!(data && data->scan_info.external_scan) && |
| 6232 | os_reltime_initialized(&wpa_s->scan_start_time)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6233 | struct os_reltime now, diff; |
| 6234 | os_get_reltime(&now); |
| 6235 | os_reltime_sub(&now, &wpa_s->scan_start_time, &diff); |
| 6236 | wpa_s->scan_start_time.sec = 0; |
| 6237 | wpa_s->scan_start_time.usec = 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6238 | wpa_s->wps_scan_done = true; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6239 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds", |
| 6240 | diff.sec, diff.usec); |
| 6241 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6242 | if (wpa_supplicant_event_scan_results(wpa_s, data)) |
| 6243 | break; /* interface may have been removed */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6244 | if (!(data && data->scan_info.external_scan)) |
| 6245 | wpa_s->own_scan_running = 0; |
| 6246 | if (data && data->scan_info.nl_scan_event) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6247 | wpa_s->radio->external_scan_req_interface = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6248 | radio_work_check_next(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6249 | break; |
| 6250 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 6251 | case EVENT_ASSOCINFO: |
| 6252 | wpa_supplicant_event_associnfo(wpa_s, data); |
| 6253 | break; |
| 6254 | case EVENT_INTERFACE_STATUS: |
| 6255 | wpa_supplicant_event_interface_status(wpa_s, data); |
| 6256 | break; |
| 6257 | case EVENT_PMKID_CANDIDATE: |
| 6258 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); |
| 6259 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6260 | #ifdef CONFIG_TDLS |
| 6261 | case EVENT_TDLS: |
| 6262 | wpa_supplicant_event_tdls(wpa_s, data); |
| 6263 | break; |
| 6264 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6265 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6266 | case EVENT_WNM: |
| 6267 | wpa_supplicant_event_wnm(wpa_s, data); |
| 6268 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6269 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6270 | #ifdef CONFIG_IEEE80211R |
| 6271 | case EVENT_FT_RESPONSE: |
| 6272 | wpa_supplicant_event_ft_response(wpa_s, data); |
| 6273 | break; |
| 6274 | #endif /* CONFIG_IEEE80211R */ |
| 6275 | #ifdef CONFIG_IBSS_RSN |
| 6276 | case EVENT_IBSS_RSN_START: |
| 6277 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); |
| 6278 | break; |
| 6279 | #endif /* CONFIG_IBSS_RSN */ |
| 6280 | case EVENT_ASSOC_REJECT: |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6281 | wpas_event_assoc_reject(wpa_s, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6282 | break; |
| 6283 | case EVENT_AUTH_TIMED_OUT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6284 | /* It is possible to get this event from earlier connection */ |
| 6285 | if (wpa_s->current_ssid && |
| 6286 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { |
| 6287 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6288 | "Ignore AUTH_TIMED_OUT in mesh configuration"); |
| 6289 | break; |
| 6290 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6291 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 6292 | sme_event_auth_timed_out(wpa_s, data); |
| 6293 | break; |
| 6294 | case EVENT_ASSOC_TIMED_OUT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6295 | /* It is possible to get this event from earlier connection */ |
| 6296 | if (wpa_s->current_ssid && |
| 6297 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { |
| 6298 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6299 | "Ignore ASSOC_TIMED_OUT in mesh configuration"); |
| 6300 | break; |
| 6301 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6302 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 6303 | sme_event_assoc_timed_out(wpa_s, data); |
| 6304 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6305 | case EVENT_TX_STATUS: |
| 6306 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
| 6307 | " type=%d stype=%d", |
| 6308 | MAC2STR(data->tx_status.dst), |
| 6309 | data->tx_status.type, data->tx_status.stype); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6310 | #ifdef CONFIG_PASN |
| 6311 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 6312 | data->tx_status.stype == WLAN_FC_STYPE_AUTH && |
| 6313 | wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data, |
| 6314 | data->tx_status.data_len, |
| 6315 | data->tx_status.ack) == 0) |
| 6316 | break; |
| 6317 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6318 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6319 | if (wpa_s->ap_iface == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6320 | #ifdef CONFIG_OFFCHANNEL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6321 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 6322 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6323 | offchannel_send_action_tx_status( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6324 | wpa_s, data->tx_status.dst, |
| 6325 | data->tx_status.data, |
| 6326 | data->tx_status.data_len, |
| 6327 | data->tx_status.ack ? |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6328 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
| 6329 | OFFCHANNEL_SEND_ACTION_NO_ACK); |
| 6330 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6331 | break; |
| 6332 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6333 | #endif /* CONFIG_AP */ |
| 6334 | #ifdef CONFIG_OFFCHANNEL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6335 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6336 | MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6337 | /* |
| 6338 | * Catch TX status events for Action frames we sent via group |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6339 | * interface in GO mode, or via standalone AP interface. |
| 6340 | * Note, wpa_s->p2pdev will be the same as wpa_s->parent, |
| 6341 | * except when the primary interface is used as a GO interface |
| 6342 | * (for drivers which do not have group interface concurrency) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6343 | */ |
| 6344 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 6345 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 6346 | ether_addr_equal(wpa_s->p2pdev->pending_action_dst, |
| 6347 | data->tx_status.dst)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6348 | offchannel_send_action_tx_status( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6349 | wpa_s->p2pdev, data->tx_status.dst, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6350 | data->tx_status.data, |
| 6351 | data->tx_status.data_len, |
| 6352 | data->tx_status.ack ? |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6353 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
| 6354 | OFFCHANNEL_SEND_ACTION_NO_ACK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6355 | break; |
| 6356 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6357 | #endif /* CONFIG_OFFCHANNEL */ |
| 6358 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6359 | switch (data->tx_status.type) { |
| 6360 | case WLAN_FC_TYPE_MGMT: |
| 6361 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, |
| 6362 | data->tx_status.data_len, |
| 6363 | data->tx_status.stype, |
| 6364 | data->tx_status.ack); |
| 6365 | break; |
| 6366 | case WLAN_FC_TYPE_DATA: |
| 6367 | ap_tx_status(wpa_s, data->tx_status.dst, |
| 6368 | data->tx_status.data, |
| 6369 | data->tx_status.data_len, |
| 6370 | data->tx_status.ack); |
| 6371 | break; |
| 6372 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6373 | #endif /* CONFIG_AP */ |
| 6374 | break; |
| 6375 | #ifdef CONFIG_AP |
| 6376 | case EVENT_EAPOL_TX_STATUS: |
| 6377 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, |
| 6378 | data->eapol_tx_status.data, |
| 6379 | data->eapol_tx_status.data_len, |
| 6380 | data->eapol_tx_status.ack); |
| 6381 | break; |
| 6382 | case EVENT_DRIVER_CLIENT_POLL_OK: |
| 6383 | ap_client_poll_ok(wpa_s, data->client_poll.addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6384 | break; |
| 6385 | case EVENT_RX_FROM_UNKNOWN: |
| 6386 | if (wpa_s->ap_iface == NULL) |
| 6387 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6388 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
| 6389 | data->rx_from_unknown.wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6390 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6391 | #endif /* CONFIG_AP */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6392 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6393 | case EVENT_LINK_CH_SWITCH_STARTED: |
| 6394 | case EVENT_LINK_CH_SWITCH: |
| 6395 | if (!data || !wpa_s->current_ssid || |
| 6396 | !(wpa_s->valid_links & BIT(data->ch_switch.link_id))) |
| 6397 | break; |
| 6398 | |
| 6399 | wpa_msg(wpa_s, MSG_INFO, |
| 6400 | "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d", |
| 6401 | event == EVENT_LINK_CH_SWITCH ? |
| 6402 | WPA_EVENT_LINK_CHANNEL_SWITCH : |
| 6403 | WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED, |
| 6404 | data->ch_switch.freq, |
| 6405 | data->ch_switch.link_id, |
| 6406 | data->ch_switch.ht_enabled, |
| 6407 | data->ch_switch.ch_offset, |
| 6408 | channel_width_to_string(data->ch_switch.ch_width), |
| 6409 | data->ch_switch.cf1, |
| 6410 | data->ch_switch.cf2); |
| 6411 | if (event == EVENT_LINK_CH_SWITCH_STARTED) |
| 6412 | break; |
| 6413 | |
| 6414 | wpa_s->links[data->ch_switch.link_id].freq = |
| 6415 | data->ch_switch.freq; |
| 6416 | if (wpa_s->links[data->ch_switch.link_id].bss && |
| 6417 | wpa_s->links[data->ch_switch.link_id].bss->freq != |
| 6418 | data->ch_switch.freq) { |
| 6419 | wpa_s->links[data->ch_switch.link_id].bss->freq = |
| 6420 | data->ch_switch.freq; |
| 6421 | notify_bss_changes( |
| 6422 | wpa_s, WPA_BSS_FREQ_CHANGED_FLAG, |
| 6423 | wpa_s->links[data->ch_switch.link_id].bss); |
Shuibing Dai | 0db6bb1 | 2023-09-28 17:53:17 -0700 | [diff] [blame] | 6424 | if (data->ch_switch.freq) |
| 6425 | wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6426 | } |
| 6427 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6428 | case EVENT_CH_SWITCH_STARTED: |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6429 | case EVENT_CH_SWITCH: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6430 | if (!data || !wpa_s->current_ssid) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6431 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6432 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6433 | wpa_msg(wpa_s, MSG_INFO, |
| 6434 | "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d", |
| 6435 | event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH : |
| 6436 | WPA_EVENT_CHANNEL_SWITCH_STARTED, |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 6437 | data->ch_switch.freq, |
| 6438 | data->ch_switch.ht_enabled, |
| 6439 | data->ch_switch.ch_offset, |
| 6440 | channel_width_to_string(data->ch_switch.ch_width), |
| 6441 | data->ch_switch.cf1, |
| 6442 | data->ch_switch.cf2); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6443 | if (event == EVENT_CH_SWITCH_STARTED) |
| 6444 | break; |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 6445 | |
Sunil Ravi | 65a724b | 2022-05-24 11:06:09 -0700 | [diff] [blame] | 6446 | if (wpa_s->assoc_freq && data->ch_switch.freq && |
| 6447 | (int) wpa_s->assoc_freq != data->ch_switch.freq) { |
| 6448 | wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq); |
| 6449 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6450 | wpa_s->assoc_freq = data->ch_switch.freq; |
| 6451 | wpa_s->current_ssid->frequency = data->ch_switch.freq; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6452 | if (wpa_s->current_bss && |
| 6453 | wpa_s->current_bss->freq != data->ch_switch.freq) { |
| 6454 | wpa_s->current_bss->freq = data->ch_switch.freq; |
| 6455 | notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG, |
| 6456 | wpa_s->current_bss); |
| 6457 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6458 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6459 | #ifdef CONFIG_SME |
| 6460 | switch (data->ch_switch.ch_offset) { |
| 6461 | case 1: |
| 6462 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE; |
| 6463 | break; |
| 6464 | case -1: |
| 6465 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW; |
| 6466 | break; |
| 6467 | default: |
| 6468 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN; |
| 6469 | break; |
| 6470 | } |
| 6471 | #endif /* CONFIG_SME */ |
| 6472 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6473 | #ifdef CONFIG_AP |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6474 | if (wpa_s->current_ssid->mode == WPAS_MODE_AP || |
| 6475 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO || |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6476 | wpa_s->current_ssid->mode == WPAS_MODE_MESH || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6477 | wpa_s->current_ssid->mode == |
| 6478 | WPAS_MODE_P2P_GROUP_FORMATION) { |
| 6479 | wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, |
| 6480 | data->ch_switch.ht_enabled, |
| 6481 | data->ch_switch.ch_offset, |
| 6482 | data->ch_switch.ch_width, |
| 6483 | data->ch_switch.cf1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6484 | data->ch_switch.cf2, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 6485 | data->ch_switch.punct_bitmap, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6486 | 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6487 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6488 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6489 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6490 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 6491 | sme_event_ch_switch(wpa_s); |
| 6492 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6493 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 6494 | wnm_clear_coloc_intf_reporting(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6495 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6496 | #ifdef CONFIG_AP |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6497 | #ifdef NEED_AP_MLME |
| 6498 | case EVENT_DFS_RADAR_DETECTED: |
| 6499 | if (data) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6500 | wpas_ap_event_dfs_radar_detected(wpa_s, |
| 6501 | &data->dfs_event); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6502 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6503 | case EVENT_DFS_NOP_FINISHED: |
| 6504 | if (data) |
| 6505 | wpas_ap_event_dfs_cac_nop_finished(wpa_s, |
| 6506 | &data->dfs_event); |
| 6507 | break; |
| 6508 | #endif /* NEED_AP_MLME */ |
| 6509 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 6510 | case EVENT_DFS_CAC_STARTED: |
| 6511 | if (data) |
| 6512 | wpas_event_dfs_cac_started(wpa_s, &data->dfs_event); |
| 6513 | break; |
| 6514 | case EVENT_DFS_CAC_FINISHED: |
| 6515 | if (data) |
| 6516 | wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event); |
| 6517 | break; |
| 6518 | case EVENT_DFS_CAC_ABORTED: |
| 6519 | if (data) |
| 6520 | wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event); |
| 6521 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6522 | case EVENT_RX_MGMT: { |
| 6523 | u16 fc, stype; |
| 6524 | const struct ieee80211_mgmt *mgmt; |
| 6525 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 6526 | #ifdef CONFIG_TESTING_OPTIONS |
| 6527 | if (wpa_s->ext_mgmt_frame_handling) { |
| 6528 | struct rx_mgmt *rx = &data->rx_mgmt; |
| 6529 | size_t hex_len = 2 * rx->frame_len + 1; |
| 6530 | char *hex = os_malloc(hex_len); |
| 6531 | if (hex) { |
| 6532 | wpa_snprintf_hex(hex, hex_len, |
| 6533 | rx->frame, rx->frame_len); |
| 6534 | wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s", |
| 6535 | rx->freq, rx->datarate, rx->ssi_signal, |
| 6536 | hex); |
| 6537 | os_free(hex); |
| 6538 | } |
| 6539 | break; |
| 6540 | } |
| 6541 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 6542 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6543 | mgmt = (const struct ieee80211_mgmt *) |
| 6544 | data->rx_mgmt.frame; |
| 6545 | fc = le_to_host16(mgmt->frame_control); |
| 6546 | stype = WLAN_FC_GET_STYPE(fc); |
| 6547 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6548 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6549 | if (wpa_s->ap_iface == NULL) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6550 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6551 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6552 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6553 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6554 | const u8 *src = mgmt->sa; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6555 | const u8 *ie; |
| 6556 | size_t ie_len; |
| 6557 | |
| 6558 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; |
| 6559 | ie_len = data->rx_mgmt.frame_len - |
| 6560 | IEEE80211_HDRLEN; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6561 | wpas_p2p_probe_req_rx( |
| 6562 | wpa_s, src, mgmt->da, |
| 6563 | mgmt->bssid, ie, ie_len, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6564 | data->rx_mgmt.freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6565 | data->rx_mgmt.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6566 | break; |
| 6567 | } |
| 6568 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6569 | #ifdef CONFIG_IBSS_RSN |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6570 | if (wpa_s->current_ssid && |
| 6571 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && |
| 6572 | stype == WLAN_FC_STYPE_AUTH && |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6573 | data->rx_mgmt.frame_len >= 30) { |
| 6574 | wpa_supplicant_event_ibss_auth(wpa_s, data); |
| 6575 | break; |
| 6576 | } |
| 6577 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6578 | |
| 6579 | if (stype == WLAN_FC_STYPE_ACTION) { |
| 6580 | wpas_event_rx_mgmt_action( |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 6581 | wpa_s, data->rx_mgmt.frame, |
| 6582 | data->rx_mgmt.frame_len, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6583 | data->rx_mgmt.freq, |
| 6584 | data->rx_mgmt.ssi_signal); |
| 6585 | break; |
| 6586 | } |
| 6587 | |
| 6588 | if (wpa_s->ifmsh) { |
| 6589 | mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6590 | break; |
| 6591 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6592 | #ifdef CONFIG_PASN |
| 6593 | if (stype == WLAN_FC_STYPE_AUTH && |
| 6594 | wpas_pasn_auth_rx(wpa_s, mgmt, |
| 6595 | data->rx_mgmt.frame_len) != -2) |
| 6596 | break; |
| 6597 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6598 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6599 | #ifdef CONFIG_SAE |
| 6600 | if (stype == WLAN_FC_STYPE_AUTH && |
| 6601 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 6602 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) { |
| 6603 | sme_external_auth_mgmt_rx( |
| 6604 | wpa_s, data->rx_mgmt.frame, |
| 6605 | data->rx_mgmt.frame_len); |
| 6606 | break; |
| 6607 | } |
| 6608 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6609 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
| 6610 | "management frame in non-AP mode"); |
| 6611 | break; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6612 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6613 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6614 | |
| 6615 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6616 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
| 6617 | const u8 *ie; |
| 6618 | size_t ie_len; |
| 6619 | |
| 6620 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; |
| 6621 | ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6622 | |
| 6623 | wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, |
| 6624 | mgmt->bssid, ie, ie_len, |
| 6625 | data->rx_mgmt.ssi_signal); |
| 6626 | } |
| 6627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6628 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6629 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6630 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6631 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6632 | case EVENT_RX_PROBE_REQ: |
| 6633 | if (data->rx_probe_req.sa == NULL || |
| 6634 | data->rx_probe_req.ie == NULL) |
| 6635 | break; |
| 6636 | #ifdef CONFIG_AP |
| 6637 | if (wpa_s->ap_iface) { |
| 6638 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], |
| 6639 | data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6640 | data->rx_probe_req.da, |
| 6641 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6642 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6643 | data->rx_probe_req.ie_len, |
| 6644 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6645 | break; |
| 6646 | } |
| 6647 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6648 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6649 | data->rx_probe_req.da, |
| 6650 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6651 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6652 | data->rx_probe_req.ie_len, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 6653 | 0, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6654 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6655 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6656 | case EVENT_REMAIN_ON_CHANNEL: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6657 | #ifdef CONFIG_OFFCHANNEL |
| 6658 | offchannel_remain_on_channel_cb( |
| 6659 | wpa_s, data->remain_on_channel.freq, |
| 6660 | data->remain_on_channel.duration); |
| 6661 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6662 | wpas_p2p_remain_on_channel_cb( |
| 6663 | wpa_s, data->remain_on_channel.freq, |
| 6664 | data->remain_on_channel.duration); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6665 | #ifdef CONFIG_DPP |
| 6666 | wpas_dpp_remain_on_channel_cb( |
| 6667 | wpa_s, data->remain_on_channel.freq, |
| 6668 | data->remain_on_channel.duration); |
| 6669 | #endif /* CONFIG_DPP */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 6670 | #ifdef CONFIG_NAN_USD |
| 6671 | wpas_nan_usd_remain_on_channel_cb( |
| 6672 | wpa_s, data->remain_on_channel.freq, |
| 6673 | data->remain_on_channel.duration); |
| 6674 | #endif /* CONFIG_NAN_USD */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6675 | break; |
| 6676 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6677 | #ifdef CONFIG_OFFCHANNEL |
| 6678 | offchannel_cancel_remain_on_channel_cb( |
| 6679 | wpa_s, data->remain_on_channel.freq); |
| 6680 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6681 | wpas_p2p_cancel_remain_on_channel_cb( |
| 6682 | wpa_s, data->remain_on_channel.freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6683 | #ifdef CONFIG_DPP |
| 6684 | wpas_dpp_cancel_remain_on_channel_cb( |
| 6685 | wpa_s, data->remain_on_channel.freq); |
| 6686 | #endif /* CONFIG_DPP */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 6687 | #ifdef CONFIG_NAN_USD |
| 6688 | wpas_nan_usd_cancel_remain_on_channel_cb( |
| 6689 | wpa_s, data->remain_on_channel.freq); |
| 6690 | #endif /* CONFIG_NAN_USD */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6691 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6692 | case EVENT_EAPOL_RX: |
| 6693 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, |
| 6694 | data->eapol_rx.data, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 6695 | data->eapol_rx.data_len, |
| 6696 | data->eapol_rx.encrypted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | break; |
| 6698 | case EVENT_SIGNAL_CHANGE: |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 6699 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6700 | "above=%d signal=%d noise=%d txrate=%lu", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 6701 | data->signal_change.above_threshold, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6702 | data->signal_change.data.signal, |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 6703 | data->signal_change.current_noise, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6704 | data->signal_change.data.current_tx_rate); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6705 | wpa_bss_update_level(wpa_s->current_bss, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6706 | data->signal_change.data.signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6707 | bgscan_notify_signal_change( |
| 6708 | wpa_s, data->signal_change.above_threshold, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6709 | data->signal_change.data.signal, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6710 | data->signal_change.current_noise, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6711 | data->signal_change.data.current_tx_rate); |
| 6712 | os_memcpy(&wpa_s->last_signal_info, data, |
| 6713 | sizeof(struct wpa_signal_info)); |
| 6714 | wpas_notify_signal_change(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6715 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6716 | case EVENT_INTERFACE_MAC_CHANGED: |
| 6717 | wpa_supplicant_update_mac_addr(wpa_s); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6718 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6719 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6720 | case EVENT_INTERFACE_ENABLED: |
| 6721 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
| 6722 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6723 | u8 addr[ETH_ALEN]; |
| 6724 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6725 | eloop_cancel_timeout(wpas_clear_disabled_interface, |
| 6726 | wpa_s, NULL); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6727 | os_memcpy(addr, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6728 | wpa_supplicant_update_mac_addr(wpa_s); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 6729 | if (!ether_addr_equal(addr, wpa_s->own_addr)) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6730 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 6731 | else |
| 6732 | wpa_sm_pmksa_cache_reconfig(wpa_s->wpa); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6733 | wpa_supplicant_set_default_scan_ies(wpa_s); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6734 | if (wpa_s->p2p_mgmt) { |
| 6735 | wpa_supplicant_set_state(wpa_s, |
| 6736 | WPA_DISCONNECTED); |
| 6737 | break; |
| 6738 | } |
| 6739 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6740 | #ifdef CONFIG_AP |
| 6741 | if (!wpa_s->ap_iface) { |
| 6742 | wpa_supplicant_set_state(wpa_s, |
| 6743 | WPA_DISCONNECTED); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6744 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6745 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 6746 | } else |
| 6747 | wpa_supplicant_set_state(wpa_s, |
| 6748 | WPA_COMPLETED); |
| 6749 | #else /* CONFIG_AP */ |
| 6750 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 6751 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 6752 | #endif /* CONFIG_AP */ |
| 6753 | } |
| 6754 | break; |
| 6755 | case EVENT_INTERFACE_DISABLED: |
| 6756 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6757 | #ifdef CONFIG_P2P |
| 6758 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 6759 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group && |
| 6760 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) { |
| 6761 | /* |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6762 | * Mark interface disabled if this happens to end up not |
| 6763 | * being removed as a separate P2P group interface. |
| 6764 | */ |
| 6765 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
| 6766 | /* |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6767 | * The interface was externally disabled. Remove |
| 6768 | * it assuming an external entity will start a |
| 6769 | * new session if needed. |
| 6770 | */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6771 | if (wpa_s->current_ssid && |
| 6772 | wpa_s->current_ssid->p2p_group) |
| 6773 | wpas_p2p_interface_unavailable(wpa_s); |
| 6774 | else |
| 6775 | wpas_p2p_disconnect(wpa_s); |
| 6776 | /* |
| 6777 | * wpa_s instance may have been freed, so must not use |
| 6778 | * it here anymore. |
| 6779 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6780 | break; |
| 6781 | } |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 6782 | if (wpa_s->p2p_scan_work && wpa_s->global->p2p && |
| 6783 | p2p_in_progress(wpa_s->global->p2p) > 1) { |
| 6784 | /* This radio work will be cancelled, so clear P2P |
| 6785 | * state as well. |
| 6786 | */ |
| 6787 | p2p_stop_find(wpa_s->global->p2p); |
| 6788 | } |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6789 | #endif /* CONFIG_P2P */ |
| 6790 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6791 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 6792 | /* |
| 6793 | * Indicate disconnection to keep ctrl_iface events |
| 6794 | * consistent. |
| 6795 | */ |
| 6796 | wpa_supplicant_event_disassoc( |
| 6797 | wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1); |
| 6798 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6799 | wpa_supplicant_mark_disassoc(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6800 | os_reltime_age(&wpa_s->last_scan, &age); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6801 | if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) { |
| 6802 | clear_at.sec = wpa_s->conf->scan_res_valid_for_connect; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6803 | clear_at.usec = 0; |
| 6804 | } else { |
| 6805 | struct os_reltime tmp; |
| 6806 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6807 | tmp.sec = wpa_s->conf->scan_res_valid_for_connect; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6808 | tmp.usec = 0; |
| 6809 | os_reltime_sub(&tmp, &age, &clear_at); |
| 6810 | } |
| 6811 | eloop_register_timeout(clear_at.sec, clear_at.usec, |
| 6812 | wpas_clear_disabled_interface, |
| 6813 | wpa_s, NULL); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 6814 | radio_remove_works(wpa_s, NULL, 0); |
| 6815 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6816 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
| 6817 | break; |
| 6818 | case EVENT_CHANNEL_LIST_CHANGED: |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 6819 | wpa_supplicant_update_channel_list( |
| 6820 | wpa_s, &data->channel_list_changed); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6821 | break; |
| 6822 | case EVENT_INTERFACE_UNAVAILABLE: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6823 | wpas_p2p_interface_unavailable(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6824 | break; |
| 6825 | case EVENT_BEST_CHANNEL: |
| 6826 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
| 6827 | "(%d %d %d)", |
| 6828 | data->best_chan.freq_24, data->best_chan.freq_5, |
| 6829 | data->best_chan.freq_overall); |
| 6830 | wpa_s->best_24_freq = data->best_chan.freq_24; |
| 6831 | wpa_s->best_5_freq = data->best_chan.freq_5; |
| 6832 | wpa_s->best_overall_freq = data->best_chan.freq_overall; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6833 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, |
| 6834 | data->best_chan.freq_5, |
| 6835 | data->best_chan.freq_overall); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6836 | break; |
| 6837 | case EVENT_UNPROT_DEAUTH: |
| 6838 | wpa_supplicant_event_unprot_deauth(wpa_s, |
| 6839 | &data->unprot_deauth); |
| 6840 | break; |
| 6841 | case EVENT_UNPROT_DISASSOC: |
| 6842 | wpa_supplicant_event_unprot_disassoc(wpa_s, |
| 6843 | &data->unprot_disassoc); |
| 6844 | break; |
| 6845 | case EVENT_STATION_LOW_ACK: |
| 6846 | #ifdef CONFIG_AP |
| 6847 | if (wpa_s->ap_iface && data) |
| 6848 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], |
| 6849 | data->low_ack.addr); |
| 6850 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6851 | #ifdef CONFIG_TDLS |
| 6852 | if (data) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6853 | wpa_tdls_disable_unreachable_link(wpa_s->wpa, |
| 6854 | data->low_ack.addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6855 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6856 | break; |
| 6857 | case EVENT_IBSS_PEER_LOST: |
| 6858 | #ifdef CONFIG_IBSS_RSN |
| 6859 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); |
| 6860 | #endif /* CONFIG_IBSS_RSN */ |
| 6861 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6862 | case EVENT_DRIVER_GTK_REKEY: |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 6863 | if (!ether_addr_equal(data->driver_gtk_rekey.bssid, |
| 6864 | wpa_s->bssid)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6865 | break; |
| 6866 | if (!wpa_s->wpa) |
| 6867 | break; |
| 6868 | wpa_sm_update_replay_ctr(wpa_s->wpa, |
| 6869 | data->driver_gtk_rekey.replay_ctr); |
| 6870 | break; |
| 6871 | case EVENT_SCHED_SCAN_STOPPED: |
| 6872 | wpa_s->sched_scanning = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6873 | resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6874 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 6875 | |
| 6876 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 6877 | break; |
| 6878 | |
| 6879 | /* |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6880 | * If the driver stopped scanning without being requested to, |
| 6881 | * request a new scan to continue scanning for networks. |
| 6882 | */ |
| 6883 | if (!wpa_s->sched_scan_stop_req && |
| 6884 | wpa_s->wpa_state == WPA_SCANNING) { |
| 6885 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6886 | "Restart scanning after unexpected sched_scan stop event"); |
| 6887 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
| 6888 | break; |
| 6889 | } |
| 6890 | |
| 6891 | wpa_s->sched_scan_stop_req = 0; |
| 6892 | |
| 6893 | /* |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 6894 | * Start a new sched scan to continue searching for more SSIDs |
| 6895 | * either if timed out or PNO schedule scan is pending. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6896 | */ |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 6897 | if (wpa_s->sched_scan_timed_out) { |
| 6898 | wpa_supplicant_req_sched_scan(wpa_s); |
| 6899 | } else if (wpa_s->pno_sched_pending) { |
| 6900 | wpa_s->pno_sched_pending = 0; |
| 6901 | wpas_start_pno(wpa_s); |
Dmitry Shmidt | af9da31 | 2015-04-03 10:03:11 -0700 | [diff] [blame] | 6902 | } else if (resched) { |
| 6903 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 6904 | } |
| 6905 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6906 | break; |
| 6907 | case EVENT_WPS_BUTTON_PUSHED: |
| 6908 | #ifdef CONFIG_WPS |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6909 | wpas_wps_start_pbc(wpa_s, NULL, 0, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6910 | #endif /* CONFIG_WPS */ |
| 6911 | break; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6912 | case EVENT_AVOID_FREQUENCIES: |
| 6913 | wpa_supplicant_notify_avoid_freq(wpa_s, data); |
| 6914 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6915 | case EVENT_CONNECT_FAILED_REASON: |
| 6916 | #ifdef CONFIG_AP |
| 6917 | if (!wpa_s->ap_iface || !data) |
| 6918 | break; |
| 6919 | hostapd_event_connect_failed_reason( |
| 6920 | wpa_s->ap_iface->bss[0], |
| 6921 | data->connect_failed_reason.addr, |
| 6922 | data->connect_failed_reason.code); |
| 6923 | #endif /* CONFIG_AP */ |
| 6924 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6925 | case EVENT_NEW_PEER_CANDIDATE: |
| 6926 | #ifdef CONFIG_MESH |
| 6927 | if (!wpa_s->ifmsh || !data) |
| 6928 | break; |
| 6929 | wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer, |
| 6930 | data->mesh_peer.ies, |
| 6931 | data->mesh_peer.ie_len); |
| 6932 | #endif /* CONFIG_MESH */ |
| 6933 | break; |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 6934 | case EVENT_SURVEY: |
| 6935 | #ifdef CONFIG_AP |
| 6936 | if (!wpa_s->ap_iface) |
| 6937 | break; |
| 6938 | hostapd_event_get_survey(wpa_s->ap_iface, |
| 6939 | &data->survey_results); |
| 6940 | #endif /* CONFIG_AP */ |
| 6941 | break; |
| 6942 | case EVENT_ACS_CHANNEL_SELECTED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6943 | #ifdef CONFIG_AP |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 6944 | #ifdef CONFIG_ACS |
| 6945 | if (!wpa_s->ap_iface) |
| 6946 | break; |
| 6947 | hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0], |
| 6948 | &data->acs_selected_channels); |
| 6949 | #endif /* CONFIG_ACS */ |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6950 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 6951 | break; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 6952 | case EVENT_P2P_LO_STOP: |
| 6953 | #ifdef CONFIG_P2P |
| 6954 | wpa_s->p2p_lo_started = 0; |
| 6955 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP |
| 6956 | P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d", |
| 6957 | data->p2p_lo_stop.reason_code); |
| 6958 | #endif /* CONFIG_P2P */ |
| 6959 | break; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6960 | case EVENT_BEACON_LOSS: |
| 6961 | if (!wpa_s->current_bss || !wpa_s->current_ssid) |
| 6962 | break; |
| 6963 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS); |
| 6964 | bgscan_notify_beacon_loss(wpa_s); |
| 6965 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6966 | case EVENT_EXTERNAL_AUTH: |
| 6967 | #ifdef CONFIG_SAE |
| 6968 | if (!wpa_s->current_ssid) { |
| 6969 | wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL"); |
| 6970 | break; |
| 6971 | } |
| 6972 | sme_external_auth_trigger(wpa_s, data); |
| 6973 | #endif /* CONFIG_SAE */ |
| 6974 | break; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6975 | #ifdef CONFIG_PASN |
| 6976 | case EVENT_PASN_AUTH: |
| 6977 | wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth); |
| 6978 | break; |
| 6979 | #endif /* CONFIG_PASN */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6980 | case EVENT_PORT_AUTHORIZED: |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 6981 | #ifdef CONFIG_AP |
| 6982 | if (wpa_s->ap_iface && wpa_s->ap_iface->bss[0]) { |
| 6983 | struct sta_info *sta; |
| 6984 | |
| 6985 | sta = ap_get_sta(wpa_s->ap_iface->bss[0], |
| 6986 | data->port_authorized.sta_addr); |
| 6987 | if (sta) |
| 6988 | ap_sta_set_authorized(wpa_s->ap_iface->bss[0], |
| 6989 | sta, 1); |
| 6990 | else |
| 6991 | wpa_printf(MSG_DEBUG, |
| 6992 | "No STA info matching port authorized event found"); |
| 6993 | break; |
| 6994 | } |
| 6995 | #endif /* CONFIG_AP */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6996 | #ifndef CONFIG_NO_WPA |
| 6997 | if (data->port_authorized.td_bitmap_len) { |
| 6998 | wpa_printf(MSG_DEBUG, |
| 6999 | "WPA3: Transition Disable bitmap from the driver event: 0x%x", |
| 7000 | data->port_authorized.td_bitmap[0]); |
| 7001 | wpas_transition_disable( |
| 7002 | wpa_s, data->port_authorized.td_bitmap[0]); |
| 7003 | } |
| 7004 | #endif /* CONFIG_NO_WPA */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7005 | wpa_supplicant_event_port_authorized(wpa_s); |
| 7006 | break; |
| 7007 | case EVENT_STATION_OPMODE_CHANGED: |
| 7008 | #ifdef CONFIG_AP |
| 7009 | if (!wpa_s->ap_iface || !data) |
| 7010 | break; |
| 7011 | |
| 7012 | hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0], |
| 7013 | data->sta_opmode.addr, |
| 7014 | data->sta_opmode.smps_mode, |
| 7015 | data->sta_opmode.chan_width, |
| 7016 | data->sta_opmode.rx_nss); |
| 7017 | #endif /* CONFIG_AP */ |
| 7018 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7019 | case EVENT_UNPROT_BEACON: |
| 7020 | wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon); |
| 7021 | break; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7022 | case EVENT_TX_WAIT_EXPIRE: |
| 7023 | #ifdef CONFIG_DPP |
| 7024 | wpas_dpp_tx_wait_expire(wpa_s); |
| 7025 | #endif /* CONFIG_DPP */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame^] | 7026 | #ifdef CONFIG_NAN_USD |
| 7027 | wpas_nan_usd_tx_wait_expire(wpa_s); |
| 7028 | #endif /* CONFIG_NAN_USD */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7029 | break; |
Sunil Ravi | 640215c | 2023-06-28 23:08:09 +0000 | [diff] [blame] | 7030 | case EVENT_TID_LINK_MAP: |
| 7031 | if (data) |
| 7032 | wpas_tid_link_map(wpa_s, &data->t2l_map_info); |
| 7033 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7034 | default: |
| 7035 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
| 7036 | break; |
| 7037 | } |
| 7038 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7039 | |
| 7040 | |
| 7041 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, |
| 7042 | union wpa_event_data *data) |
| 7043 | { |
| 7044 | struct wpa_supplicant *wpa_s; |
| 7045 | |
| 7046 | if (event != EVENT_INTERFACE_STATUS) |
| 7047 | return; |
| 7048 | |
| 7049 | wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname); |
| 7050 | if (wpa_s && wpa_s->driver->get_ifindex) { |
| 7051 | unsigned int ifindex; |
| 7052 | |
| 7053 | ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv); |
| 7054 | if (ifindex != data->interface_status.ifindex) { |
| 7055 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 7056 | "interface status ifindex %d mismatch (%d)", |
| 7057 | ifindex, data->interface_status.ifindex); |
| 7058 | return; |
| 7059 | } |
| 7060 | } |
| 7061 | #ifdef CONFIG_MATCH_IFACE |
| 7062 | else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) { |
| 7063 | struct wpa_interface *wpa_i; |
| 7064 | |
| 7065 | wpa_i = wpa_supplicant_match_iface( |
| 7066 | ctx, data->interface_status.ifname); |
| 7067 | if (!wpa_i) |
| 7068 | return; |
| 7069 | wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL); |
| 7070 | os_free(wpa_i); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7071 | } |
| 7072 | #endif /* CONFIG_MATCH_IFACE */ |
| 7073 | |
| 7074 | if (wpa_s) |
| 7075 | wpa_supplicant_event(wpa_s, event, data); |
| 7076 | } |