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" |
| 25 | #include "p2p/p2p.h" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 26 | #include "fst/fst.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 27 | #include "wnm_sta.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 28 | #include "notify.h" |
| 29 | #include "common/ieee802_11_defs.h" |
| 30 | #include "common/ieee802_11_common.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 31 | #include "common/gas_server.h" |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 32 | #include "common/dpp.h" |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 33 | #include "common/ptksa_cache.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "crypto/random.h" |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 35 | #include "bssid_ignore.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "wpas_glue.h" |
| 37 | #include "wps_supplicant.h" |
| 38 | #include "ibss_rsn.h" |
| 39 | #include "sme.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 40 | #include "gas_query.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 41 | #include "p2p_supplicant.h" |
| 42 | #include "bgscan.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 43 | #include "autoscan.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 44 | #include "ap.h" |
| 45 | #include "bss.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 46 | #include "scan.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 47 | #include "offchannel.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 48 | #include "interworking.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 49 | #include "mesh.h" |
| 50 | #include "mesh_mpm.h" |
| 51 | #include "wmm_ac.h" |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 52 | #include "dpp_supplicant.h" |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 53 | #include "rsn_supp/wpa_i.h" |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 54 | |
| 55 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 56 | #define MAX_OWE_TRANSITION_BSS_SELECT_COUNT 5 |
| 57 | |
| 58 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 59 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 60 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 61 | int new_scan, int own_request); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 62 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 63 | |
| 64 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 65 | 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] | 66 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 67 | struct os_reltime now; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 68 | |
| 69 | if (ssid == NULL || ssid->disabled_until.sec == 0) |
| 70 | return 0; |
| 71 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 72 | os_get_reltime(&now); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 73 | if (ssid->disabled_until.sec > now.sec) |
| 74 | return ssid->disabled_until.sec - now.sec; |
| 75 | |
| 76 | wpas_clear_temp_disabled(wpa_s, ssid, 0); |
| 77 | |
| 78 | return 0; |
| 79 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 80 | |
| 81 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 82 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 83 | /** |
| 84 | * wpas_reenabled_network_time - Time until first network is re-enabled |
| 85 | * @wpa_s: Pointer to wpa_supplicant data |
| 86 | * Returns: If all enabled networks are temporarily disabled, returns the time |
| 87 | * (in sec) until the first network is re-enabled. Otherwise returns 0. |
| 88 | * |
| 89 | * This function is used in case all enabled networks are temporarily disabled, |
| 90 | * in which case it returns the time (in sec) that the first network will be |
| 91 | * re-enabled. The function assumes that at least one network is enabled. |
| 92 | */ |
| 93 | static int wpas_reenabled_network_time(struct wpa_supplicant *wpa_s) |
| 94 | { |
| 95 | struct wpa_ssid *ssid; |
| 96 | int disabled_for, res = 0; |
| 97 | |
| 98 | #ifdef CONFIG_INTERWORKING |
| 99 | if (wpa_s->conf->auto_interworking && wpa_s->conf->interworking && |
| 100 | wpa_s->conf->cred) |
| 101 | return 0; |
| 102 | #endif /* CONFIG_INTERWORKING */ |
| 103 | |
| 104 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 105 | if (ssid->disabled) |
| 106 | continue; |
| 107 | |
| 108 | disabled_for = wpas_temp_disabled(wpa_s, ssid); |
| 109 | if (!disabled_for) |
| 110 | return 0; |
| 111 | |
| 112 | if (!res || disabled_for < res) |
| 113 | res = disabled_for; |
| 114 | } |
| 115 | |
| 116 | return res; |
| 117 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 118 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 119 | |
| 120 | |
| 121 | void wpas_network_reenabled(void *eloop_ctx, void *timeout_ctx) |
| 122 | { |
| 123 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 124 | |
| 125 | if (wpa_s->disconnected || wpa_s->wpa_state != WPA_SCANNING) |
| 126 | return; |
| 127 | |
| 128 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 129 | "Try to associate due to network getting re-enabled"); |
| 130 | if (wpa_supplicant_fast_associate(wpa_s) != 1) { |
| 131 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 132 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 137 | static struct wpa_bss * wpa_supplicant_get_new_bss( |
| 138 | struct wpa_supplicant *wpa_s, const u8 *bssid) |
| 139 | { |
| 140 | struct wpa_bss *bss = NULL; |
| 141 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 142 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 143 | if (ssid && ssid->ssid_len > 0) |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 144 | bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len); |
| 145 | if (!bss) |
| 146 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 147 | |
| 148 | return bss; |
| 149 | } |
| 150 | |
| 151 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 152 | static struct wpa_bss * |
| 153 | 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] | 154 | { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 155 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 156 | |
| 157 | if (!bss) { |
| 158 | wpa_supplicant_update_scan_results(wpa_s); |
| 159 | |
| 160 | /* Get the BSS from the new scan results */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 161 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | if (bss) |
| 165 | wpa_s->current_bss = bss; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 166 | |
| 167 | return bss; |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 171 | static void wpa_supplicant_update_link_bss(struct wpa_supplicant *wpa_s, |
| 172 | u8 link_id, const u8 *bssid) |
| 173 | { |
| 174 | struct wpa_bss *bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 175 | |
| 176 | if (!bss) { |
| 177 | wpa_supplicant_update_scan_results(wpa_s); |
| 178 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 179 | } |
| 180 | |
| 181 | if (bss) |
| 182 | wpa_s->links[link_id].bss = bss; |
| 183 | } |
| 184 | |
| 185 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 186 | static int wpa_supplicant_select_config(struct wpa_supplicant *wpa_s, |
| 187 | union wpa_event_data *data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 188 | { |
| 189 | struct wpa_ssid *ssid, *old_ssid; |
Dmitry Shmidt | 9d9e602 | 2015-04-23 10:34:55 -0700 | [diff] [blame] | 190 | u8 drv_ssid[SSID_MAX_LEN]; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 191 | size_t drv_ssid_len; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 192 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 193 | |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 194 | if (wpa_s->conf->ap_scan == 1 && wpa_s->current_ssid) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 195 | wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 196 | |
| 197 | if (wpa_s->current_ssid->ssid_len == 0) |
| 198 | return 0; /* current profile still in use */ |
| 199 | res = wpa_drv_get_ssid(wpa_s, drv_ssid); |
| 200 | if (res < 0) { |
| 201 | wpa_msg(wpa_s, MSG_INFO, |
| 202 | "Failed to read SSID from driver"); |
| 203 | return 0; /* try to use current profile */ |
| 204 | } |
| 205 | drv_ssid_len = res; |
| 206 | |
| 207 | if (drv_ssid_len == wpa_s->current_ssid->ssid_len && |
| 208 | os_memcmp(drv_ssid, wpa_s->current_ssid->ssid, |
| 209 | drv_ssid_len) == 0) |
| 210 | return 0; /* current profile still in use */ |
| 211 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 212 | #ifdef CONFIG_OWE |
| 213 | if ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
| 214 | wpa_s->current_bss && |
| 215 | (wpa_s->current_bss->flags & WPA_BSS_OWE_TRANSITION) && |
| 216 | drv_ssid_len == wpa_s->current_bss->ssid_len && |
| 217 | os_memcmp(drv_ssid, wpa_s->current_bss->ssid, |
| 218 | drv_ssid_len) == 0) |
| 219 | return 0; /* current profile still in use */ |
| 220 | #endif /* CONFIG_OWE */ |
| 221 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 222 | wpa_msg(wpa_s, MSG_DEBUG, |
| 223 | "Driver-initiated BSS selection changed the SSID to %s", |
| 224 | wpa_ssid_txt(drv_ssid, drv_ssid_len)); |
| 225 | /* continue selecting a new network profile */ |
Jouni Malinen | 5c879ee | 2014-08-18 11:04:56 -0700 | [diff] [blame] | 226 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 227 | |
| 228 | wpa_dbg(wpa_s, MSG_DEBUG, "Select network based on association " |
| 229 | "information"); |
| 230 | ssid = wpa_supplicant_get_ssid(wpa_s); |
| 231 | if (ssid == NULL) { |
| 232 | wpa_msg(wpa_s, MSG_INFO, |
| 233 | "No network configuration found for the current AP"); |
| 234 | return -1; |
| 235 | } |
| 236 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 237 | if (wpas_network_disabled(wpa_s, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 238 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is disabled"); |
| 239 | return -1; |
| 240 | } |
| 241 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 242 | if (disallowed_bssid(wpa_s, wpa_s->bssid) || |
| 243 | disallowed_ssid(wpa_s, ssid->ssid, ssid->ssid_len)) { |
| 244 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS is disallowed"); |
| 245 | return -1; |
| 246 | } |
| 247 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 248 | res = wpas_temp_disabled(wpa_s, ssid); |
| 249 | if (res > 0) { |
| 250 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is temporarily " |
| 251 | "disabled for %d second(s)", res); |
| 252 | return -1; |
| 253 | } |
| 254 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 255 | wpa_dbg(wpa_s, MSG_DEBUG, "Network configuration found for the " |
| 256 | "current AP"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 257 | if (wpa_key_mgmt_wpa_any(ssid->key_mgmt)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 258 | u8 wpa_ie[80]; |
| 259 | size_t wpa_ie_len = sizeof(wpa_ie); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 260 | bool skip_default_rsne; |
| 261 | |
| 262 | /* Do not override RSNE/RSNXE with the default values if the |
| 263 | * driver indicated the actual values used in the |
| 264 | * (Re)Association Request frame. */ |
| 265 | skip_default_rsne = data && data->assoc_info.req_ies; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 266 | if (wpa_supplicant_set_suites(wpa_s, NULL, ssid, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 267 | wpa_ie, &wpa_ie_len, |
| 268 | skip_default_rsne) < 0) |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 269 | wpa_dbg(wpa_s, MSG_DEBUG, "Could not set WPA suites"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 270 | } else { |
| 271 | wpa_supplicant_set_non_wpa_policy(wpa_s, ssid); |
| 272 | } |
| 273 | |
| 274 | if (wpa_s->current_ssid && wpa_s->current_ssid != ssid) |
| 275 | eapol_sm_invalidate_cached_session(wpa_s->eapol); |
| 276 | old_ssid = wpa_s->current_ssid; |
| 277 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 278 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 279 | wpa_supplicant_update_current_bss(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 280 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 281 | wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid); |
| 282 | wpa_supplicant_initiate_eapol(wpa_s); |
| 283 | if (old_ssid != wpa_s->current_ssid) |
| 284 | wpas_notify_network_changed(wpa_s); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 290 | void wpa_supplicant_stop_countermeasures(void *eloop_ctx, void *sock_ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 291 | { |
| 292 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 293 | |
| 294 | if (wpa_s->countermeasures) { |
| 295 | wpa_s->countermeasures = 0; |
| 296 | wpa_drv_set_countermeasures(wpa_s, 0); |
| 297 | wpa_msg(wpa_s, MSG_INFO, "WPA: TKIP countermeasures stopped"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 298 | |
| 299 | /* |
| 300 | * It is possible that the device is sched scanning, which means |
| 301 | * that a connection attempt will be done only when we receive |
| 302 | * scan results. However, in this case, it would be preferable |
| 303 | * to scan and connect immediately, so cancel the sched_scan and |
| 304 | * issue a regular scan flow. |
| 305 | */ |
| 306 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 307 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 312 | void wpas_reset_mlo_info(struct wpa_supplicant *wpa_s) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 313 | { |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 314 | if (!wpa_s->valid_links) |
| 315 | return; |
| 316 | |
| 317 | wpa_s->valid_links = 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 318 | wpa_s->mlo_assoc_link_id = 0; |
| 319 | os_memset(wpa_s->ap_mld_addr, 0, ETH_ALEN); |
| 320 | os_memset(wpa_s->links, 0, sizeof(wpa_s->links)); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 324 | void wpa_supplicant_mark_disassoc(struct wpa_supplicant *wpa_s) |
| 325 | { |
| 326 | int bssid_changed; |
| 327 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 328 | wnm_bss_keep_alive_deinit(wpa_s); |
| 329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 330 | #ifdef CONFIG_IBSS_RSN |
| 331 | ibss_rsn_deinit(wpa_s->ibss_rsn); |
| 332 | wpa_s->ibss_rsn = NULL; |
| 333 | #endif /* CONFIG_IBSS_RSN */ |
| 334 | |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 335 | #ifdef CONFIG_AP |
| 336 | wpa_supplicant_ap_deinit(wpa_s); |
| 337 | #endif /* CONFIG_AP */ |
| 338 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 339 | #ifdef CONFIG_HS20 |
| 340 | /* Clear possibly configured frame filters */ |
| 341 | wpa_drv_configure_frame_filters(wpa_s, 0); |
| 342 | #endif /* CONFIG_HS20 */ |
| 343 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 344 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 345 | return; |
| 346 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 347 | if (os_reltime_initialized(&wpa_s->session_start)) { |
| 348 | os_reltime_age(&wpa_s->session_start, &wpa_s->session_length); |
| 349 | wpa_s->session_start.sec = 0; |
| 350 | wpa_s->session_start.usec = 0; |
| 351 | wpas_notify_session_length(wpa_s); |
| 352 | } |
| 353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 355 | bssid_changed = !is_zero_ether_addr(wpa_s->bssid); |
| 356 | os_memset(wpa_s->bssid, 0, ETH_ALEN); |
| 357 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 358 | sme_clear_on_disassoc(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 359 | wpa_s->current_bss = NULL; |
| 360 | wpa_s->assoc_freq = 0; |
Dmitry Shmidt | c55524a | 2011-07-07 11:18:38 -0700 | [diff] [blame] | 361 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | if (bssid_changed) |
| 363 | wpas_notify_bssid_changed(wpa_s); |
| 364 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 365 | eapol_sm_notify_portEnabled(wpa_s->eapol, false); |
| 366 | eapol_sm_notify_portValid(wpa_s->eapol, false); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 367 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 368 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 369 | 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] | 370 | eapol_sm_notify_eap_success(wpa_s->eapol, false); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 371 | wpa_s->drv_authorized_port = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 372 | wpa_s->ap_ies_from_associnfo = 0; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 373 | wpa_s->current_ssid = NULL; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 374 | eapol_sm_notify_config(wpa_s->eapol, NULL, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 375 | wpa_s->key_mgmt = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 376 | wpa_s->allowed_key_mgmts = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 377 | |
| 378 | wpas_rrm_reset(wpa_s); |
Dmitry Shmidt | b70d0bb | 2015-11-16 10:43:06 -0800 | [diff] [blame] | 379 | wpa_s->wnmsleep_used = 0; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 380 | wnm_clear_coloc_intf_reporting(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 381 | wpa_s->disable_mbo_oce = 0; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 382 | |
| 383 | #ifdef CONFIG_TESTING_OPTIONS |
| 384 | wpa_s->last_tk_alg = WPA_ALG_NONE; |
| 385 | os_memset(wpa_s->last_tk, 0, sizeof(wpa_s->last_tk)); |
| 386 | #endif /* CONFIG_TESTING_OPTIONS */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 387 | wpa_s->ieee80211ac = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 388 | |
| 389 | if (wpa_s->enabled_4addr_mode && wpa_drv_set_4addr_mode(wpa_s, 0) == 0) |
| 390 | wpa_s->enabled_4addr_mode = 0; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 391 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 392 | wpa_s->wps_scan_done = false; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 393 | wpas_reset_mlo_info(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 397 | 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] | 398 | { |
| 399 | struct wpa_ie_data ie; |
| 400 | int pmksa_set = -1; |
| 401 | size_t i; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 402 | struct rsn_pmksa_cache_entry *cur_pmksa; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 403 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 404 | /* Start with assumption of no PMKSA cache entry match for cases other |
| 405 | * than SAE. In particular, this is needed to generate the PMKSA cache |
| 406 | * entries for Suite B cases with driver-based roaming indication. */ |
| 407 | cur_pmksa = pmksa_cache_get_current(wpa_s->wpa); |
| 408 | if (cur_pmksa && !wpa_key_mgmt_sae(cur_pmksa->akmp)) |
| 409 | pmksa_cache_clear_current(wpa_s->wpa); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 410 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 411 | if (wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0 || |
| 412 | ie.pmkid == NULL) |
| 413 | return; |
| 414 | |
| 415 | for (i = 0; i < ie.num_pmkid; i++) { |
| 416 | pmksa_set = pmksa_cache_set_current(wpa_s->wpa, |
| 417 | ie.pmkid + i * PMKID_LEN, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 418 | NULL, NULL, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 419 | if (pmksa_set == 0) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 420 | eapol_sm_notify_pmkid_attempt(wpa_s->eapol); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 421 | if (authorized) |
| 422 | wpa_sm_set_pmk_from_pmksa(wpa_s->wpa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 423 | break; |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID from assoc IE %sfound from " |
| 428 | "PMKSA cache", pmksa_set == 0 ? "" : "not "); |
| 429 | } |
| 430 | |
| 431 | |
| 432 | static void wpa_supplicant_event_pmkid_candidate(struct wpa_supplicant *wpa_s, |
| 433 | union wpa_event_data *data) |
| 434 | { |
| 435 | if (data == NULL) { |
| 436 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: No data in PMKID candidate " |
| 437 | "event"); |
| 438 | return; |
| 439 | } |
| 440 | wpa_dbg(wpa_s, MSG_DEBUG, "RSN: PMKID candidate event - bssid=" MACSTR |
| 441 | " index=%d preauth=%d", |
| 442 | MAC2STR(data->pmkid_candidate.bssid), |
| 443 | data->pmkid_candidate.index, |
| 444 | data->pmkid_candidate.preauth); |
| 445 | |
| 446 | pmksa_candidate_add(wpa_s->wpa, data->pmkid_candidate.bssid, |
| 447 | data->pmkid_candidate.index, |
| 448 | data->pmkid_candidate.preauth); |
| 449 | } |
| 450 | |
| 451 | |
| 452 | static int wpa_supplicant_dynamic_keys(struct wpa_supplicant *wpa_s) |
| 453 | { |
| 454 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 455 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) |
| 456 | return 0; |
| 457 | |
| 458 | #ifdef IEEE8021X_EAPOL |
| 459 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 460 | wpa_s->current_ssid && |
| 461 | !(wpa_s->current_ssid->eapol_flags & |
| 462 | (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 463 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST))) { |
| 464 | /* IEEE 802.1X, but not using dynamic WEP keys (i.e., either |
| 465 | * plaintext or static WEP keys). */ |
| 466 | return 0; |
| 467 | } |
| 468 | #endif /* IEEE8021X_EAPOL */ |
| 469 | |
| 470 | return 1; |
| 471 | } |
| 472 | |
| 473 | |
| 474 | /** |
| 475 | * wpa_supplicant_scard_init - Initialize SIM/USIM access with PC/SC |
| 476 | * @wpa_s: pointer to wpa_supplicant data |
| 477 | * @ssid: Configuration data for the network |
| 478 | * Returns: 0 on success, -1 on failure |
| 479 | * |
| 480 | * This function is called when starting authentication with a network that is |
| 481 | * configured to use PC/SC for SIM/USIM access (EAP-SIM or EAP-AKA). |
| 482 | */ |
| 483 | int wpa_supplicant_scard_init(struct wpa_supplicant *wpa_s, |
| 484 | struct wpa_ssid *ssid) |
| 485 | { |
| 486 | #ifdef IEEE8021X_EAPOL |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 487 | #ifdef PCSC_FUNCS |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 488 | int aka = 0, sim = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 490 | if ((ssid != NULL && ssid->eap.pcsc == NULL) || |
| 491 | wpa_s->scard != NULL || wpa_s->conf->external_sim) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 492 | return 0; |
| 493 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 494 | if (ssid == NULL || ssid->eap.eap_methods == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 495 | sim = 1; |
| 496 | aka = 1; |
| 497 | } else { |
| 498 | struct eap_method_type *eap = ssid->eap.eap_methods; |
| 499 | while (eap->vendor != EAP_VENDOR_IETF || |
| 500 | eap->method != EAP_TYPE_NONE) { |
| 501 | if (eap->vendor == EAP_VENDOR_IETF) { |
| 502 | if (eap->method == EAP_TYPE_SIM) |
| 503 | sim = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 504 | else if (eap->method == EAP_TYPE_AKA || |
| 505 | eap->method == EAP_TYPE_AKA_PRIME) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 506 | aka = 1; |
| 507 | } |
| 508 | eap++; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_SIM) == NULL) |
| 513 | sim = 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 514 | if (eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA) == NULL && |
| 515 | eap_peer_get_eap_method(EAP_VENDOR_IETF, EAP_TYPE_AKA_PRIME) == |
| 516 | NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 517 | aka = 0; |
| 518 | |
| 519 | if (!sim && !aka) { |
| 520 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to " |
| 521 | "use SIM, but neither EAP-SIM nor EAP-AKA are " |
| 522 | "enabled"); |
| 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected network is configured to use SIM " |
| 527 | "(sim=%d aka=%d) - initialize PCSC", sim, aka); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 528 | |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 529 | wpa_s->scard = scard_init(wpa_s->conf->pcsc_reader); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 530 | if (wpa_s->scard == NULL) { |
| 531 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initialize SIM " |
| 532 | "(pcsc-lite)"); |
| 533 | return -1; |
| 534 | } |
| 535 | wpa_sm_set_scard_ctx(wpa_s->wpa, wpa_s->scard); |
| 536 | eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 537 | #endif /* PCSC_FUNCS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 538 | #endif /* IEEE8021X_EAPOL */ |
| 539 | |
| 540 | return 0; |
| 541 | } |
| 542 | |
| 543 | |
| 544 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 545 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 546 | #ifdef CONFIG_WEP |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 547 | static int has_wep_key(struct wpa_ssid *ssid) |
| 548 | { |
| 549 | int i; |
| 550 | |
| 551 | for (i = 0; i < NUM_WEP_KEYS; i++) { |
| 552 | if (ssid->wep_key_len[i]) |
| 553 | return 1; |
| 554 | } |
| 555 | |
| 556 | return 0; |
| 557 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 558 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 559 | |
| 560 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 561 | static int wpa_supplicant_match_privacy(struct wpa_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 562 | struct wpa_ssid *ssid) |
| 563 | { |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 564 | int privacy = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 565 | |
| 566 | if (ssid->mixed_cell) |
| 567 | return 1; |
| 568 | |
| 569 | #ifdef CONFIG_WPS |
| 570 | if (ssid->key_mgmt & WPA_KEY_MGMT_WPS) |
| 571 | return 1; |
| 572 | #endif /* CONFIG_WPS */ |
| 573 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 574 | #ifdef CONFIG_OWE |
| 575 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only) |
| 576 | return 1; |
| 577 | #endif /* CONFIG_OWE */ |
| 578 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 579 | #ifdef CONFIG_WEP |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 580 | if (has_wep_key(ssid)) |
| 581 | privacy = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 582 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 583 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 584 | #ifdef IEEE8021X_EAPOL |
| 585 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
| 586 | ssid->eapol_flags & (EAPOL_FLAG_REQUIRE_KEY_UNICAST | |
| 587 | EAPOL_FLAG_REQUIRE_KEY_BROADCAST)) |
| 588 | privacy = 1; |
| 589 | #endif /* IEEE8021X_EAPOL */ |
| 590 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 591 | if (wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 592 | privacy = 1; |
| 593 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 594 | if (ssid->key_mgmt & WPA_KEY_MGMT_OSEN) |
| 595 | privacy = 1; |
| 596 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 597 | if (bss->caps & IEEE80211_CAP_PRIVACY) |
| 598 | return privacy; |
| 599 | return !privacy; |
| 600 | } |
| 601 | |
| 602 | |
| 603 | static int wpa_supplicant_ssid_bss_match(struct wpa_supplicant *wpa_s, |
| 604 | struct wpa_ssid *ssid, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 605 | struct wpa_bss *bss, int debug_print) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 606 | { |
| 607 | struct wpa_ie_data ie; |
| 608 | int proto_match = 0; |
| 609 | const u8 *rsn_ie, *wpa_ie; |
| 610 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 611 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 612 | int wep_ok; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 613 | #endif /* CONFIG_WEP */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 614 | bool is_6ghz_bss_or_mld = is_6ghz_freq(bss->freq) || |
| 615 | !is_zero_ether_addr(bss->mld_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 616 | |
| 617 | ret = wpas_wps_ssid_bss_match(wpa_s, ssid, bss); |
| 618 | if (ret >= 0) |
| 619 | return ret; |
| 620 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 621 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 622 | /* Allow TSN if local configuration accepts WEP use without WPA/WPA2 */ |
| 623 | wep_ok = !wpa_key_mgmt_wpa(ssid->key_mgmt) && |
| 624 | (((ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
| 625 | ssid->wep_key_len[ssid->wep_tx_keyidx] > 0) || |
| 626 | (ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 627 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 628 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 629 | rsn_ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 630 | if (is_6ghz_bss_or_mld && !rsn_ie) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 631 | if (debug_print) |
| 632 | wpa_dbg(wpa_s, MSG_DEBUG, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 633 | " skip - 6 GHz/MLD BSS without RSNE"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 634 | return 0; |
| 635 | } |
| 636 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 637 | while ((ssid->proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) && rsn_ie) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 638 | proto_match++; |
| 639 | |
| 640 | if (wpa_parse_wpa_ie(rsn_ie, 2 + rsn_ie[1], &ie)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 641 | if (debug_print) |
| 642 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 643 | " skip RSN IE - parse failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 644 | break; |
| 645 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 646 | if (!ie.has_pairwise) |
| 647 | ie.pairwise_cipher = wpa_default_rsn_cipher(bss->freq); |
| 648 | if (!ie.has_group) |
| 649 | ie.group_cipher = wpa_default_rsn_cipher(bss->freq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 650 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 651 | if (is_6ghz_bss_or_mld) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 652 | /* WEP and TKIP are not allowed on 6 GHz */ |
| 653 | ie.pairwise_cipher &= ~(WPA_CIPHER_WEP40 | |
| 654 | WPA_CIPHER_WEP104 | |
| 655 | WPA_CIPHER_TKIP); |
| 656 | ie.group_cipher &= ~(WPA_CIPHER_WEP40 | |
| 657 | WPA_CIPHER_WEP104 | |
| 658 | WPA_CIPHER_TKIP); |
| 659 | } |
| 660 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 661 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 662 | if (wep_ok && |
| 663 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) |
| 664 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 665 | if (debug_print) |
| 666 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 667 | " selected based on TSN in RSN IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 668 | return 1; |
| 669 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 670 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 671 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 672 | if (!(ie.proto & ssid->proto) && |
| 673 | !(ssid->proto & WPA_PROTO_OSEN)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 674 | if (debug_print) |
| 675 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 676 | " skip RSN IE - proto mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 677 | break; |
| 678 | } |
| 679 | |
| 680 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 681 | if (debug_print) |
| 682 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 683 | " skip RSN IE - PTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 684 | break; |
| 685 | } |
| 686 | |
| 687 | if (!(ie.group_cipher & ssid->group_cipher)) { |
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 - GTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 691 | break; |
| 692 | } |
| 693 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 694 | if (ssid->group_mgmt_cipher && |
| 695 | !(ie.mgmt_group_cipher & ssid->group_mgmt_cipher)) { |
| 696 | if (debug_print) |
| 697 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 698 | " skip RSN IE - group mgmt cipher mismatch"); |
| 699 | break; |
| 700 | } |
| 701 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 702 | if (is_6ghz_bss_or_mld) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 703 | /* MFPC must be supported on 6 GHz */ |
| 704 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC)) { |
| 705 | if (debug_print) |
| 706 | wpa_dbg(wpa_s, MSG_DEBUG, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 707 | " skip RSNE - 6 GHz/MLD without MFPC"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 708 | break; |
| 709 | } |
| 710 | |
| 711 | /* WPA PSK is not allowed on the 6 GHz band */ |
| 712 | ie.key_mgmt &= ~(WPA_KEY_MGMT_PSK | |
| 713 | WPA_KEY_MGMT_FT_PSK | |
| 714 | WPA_KEY_MGMT_PSK_SHA256); |
| 715 | } |
| 716 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 717 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 718 | if (debug_print) |
| 719 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 720 | " skip RSN IE - key mgmt mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 721 | break; |
| 722 | } |
| 723 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 724 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 725 | wpas_get_ssid_pmf(wpa_s, ssid) == |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 726 | MGMT_FRAME_PROTECTION_REQUIRED) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 727 | if (debug_print) |
| 728 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 729 | " skip RSN IE - no mgmt frame protection"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 730 | break; |
| 731 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 732 | if ((ie.capabilities & WPA_CAPABILITY_MFPR) && |
| 733 | wpas_get_ssid_pmf(wpa_s, ssid) == |
| 734 | NO_MGMT_FRAME_PROTECTION) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 735 | if (debug_print) |
| 736 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 737 | " skip RSN IE - no mgmt frame protection enabled but AP requires it"); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 738 | break; |
| 739 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 740 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 741 | if (debug_print) |
| 742 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 743 | " selected based on RSN IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 744 | return 1; |
| 745 | } |
| 746 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 747 | if (is_6ghz_bss_or_mld) { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 748 | if (debug_print) |
| 749 | wpa_dbg(wpa_s, MSG_DEBUG, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 750 | " skip - 6 GHz/MLD BSS without matching RSNE"); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 751 | return 0; |
| 752 | } |
| 753 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 754 | if (wpas_get_ssid_pmf(wpa_s, ssid) == MGMT_FRAME_PROTECTION_REQUIRED && |
| 755 | (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE) || ssid->owe_only)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 756 | if (debug_print) |
| 757 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 758 | " skip - MFP Required but network not MFP Capable"); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 759 | return 0; |
| 760 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 761 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 762 | wpa_ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 763 | while ((ssid->proto & WPA_PROTO_WPA) && wpa_ie) { |
| 764 | proto_match++; |
| 765 | |
| 766 | if (wpa_parse_wpa_ie(wpa_ie, 2 + wpa_ie[1], &ie)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 767 | if (debug_print) |
| 768 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 769 | " skip WPA IE - parse failed"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 770 | break; |
| 771 | } |
| 772 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 773 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 774 | if (wep_ok && |
| 775 | (ie.group_cipher & (WPA_CIPHER_WEP40 | WPA_CIPHER_WEP104))) |
| 776 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 777 | if (debug_print) |
| 778 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 779 | " selected based on TSN in WPA IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 780 | return 1; |
| 781 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 782 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 783 | |
| 784 | if (!(ie.proto & ssid->proto)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 785 | if (debug_print) |
| 786 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 787 | " skip WPA IE - proto mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 788 | break; |
| 789 | } |
| 790 | |
| 791 | if (!(ie.pairwise_cipher & ssid->pairwise_cipher)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 792 | if (debug_print) |
| 793 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 794 | " skip WPA IE - PTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 795 | break; |
| 796 | } |
| 797 | |
| 798 | if (!(ie.group_cipher & ssid->group_cipher)) { |
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 - GTK cipher mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 802 | break; |
| 803 | } |
| 804 | |
| 805 | if (!(ie.key_mgmt & ssid->key_mgmt)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 806 | if (debug_print) |
| 807 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 808 | " skip WPA IE - key mgmt mismatch"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 809 | break; |
| 810 | } |
| 811 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 812 | if (debug_print) |
| 813 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 814 | " selected based on WPA IE"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 815 | return 1; |
| 816 | } |
| 817 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 818 | if ((ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA) && !wpa_ie && |
| 819 | !rsn_ie) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 820 | if (debug_print) |
| 821 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 822 | " allow for non-WPA IEEE 802.1X"); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 823 | return 1; |
| 824 | } |
| 825 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 826 | #ifdef CONFIG_OWE |
| 827 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only && |
| 828 | !wpa_ie && !rsn_ie) { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 829 | if (wpa_s->owe_transition_select && |
| 830 | wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE) && |
| 831 | ssid->owe_transition_bss_select_count + 1 <= |
| 832 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT) { |
| 833 | ssid->owe_transition_bss_select_count++; |
| 834 | if (debug_print) |
| 835 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 836 | " skip OWE transition BSS (selection count %d does not exceed %d)", |
| 837 | ssid->owe_transition_bss_select_count, |
| 838 | MAX_OWE_TRANSITION_BSS_SELECT_COUNT); |
| 839 | wpa_s->owe_transition_search = 1; |
| 840 | return 0; |
| 841 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 842 | if (debug_print) |
| 843 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 844 | " allow in OWE transition mode"); |
| 845 | return 1; |
| 846 | } |
| 847 | #endif /* CONFIG_OWE */ |
| 848 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 849 | if ((ssid->proto & (WPA_PROTO_WPA | WPA_PROTO_RSN)) && |
| 850 | wpa_key_mgmt_wpa(ssid->key_mgmt) && proto_match == 0) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 851 | if (debug_print) |
| 852 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 853 | " skip - no WPA/RSN proto match"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 854 | return 0; |
| 855 | } |
| 856 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 857 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && |
| 858 | wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 859 | if (debug_print) |
| 860 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in OSEN"); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 861 | return 1; |
| 862 | } |
| 863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 864 | if (!wpa_key_mgmt_wpa(ssid->key_mgmt)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 865 | if (debug_print) |
| 866 | wpa_dbg(wpa_s, MSG_DEBUG, " allow in non-WPA/WPA2"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 867 | return 1; |
| 868 | } |
| 869 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 870 | if (debug_print) |
| 871 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 872 | " reject due to mismatch with WPA/WPA2"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 873 | |
| 874 | return 0; |
| 875 | } |
| 876 | |
| 877 | |
| 878 | static int freq_allowed(int *freqs, int freq) |
| 879 | { |
| 880 | int i; |
| 881 | |
| 882 | if (freqs == NULL) |
| 883 | return 1; |
| 884 | |
| 885 | for (i = 0; freqs[i]; i++) |
| 886 | if (freqs[i] == freq) |
| 887 | return 1; |
| 888 | return 0; |
| 889 | } |
| 890 | |
| 891 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 892 | static int rate_match(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 893 | struct wpa_bss *bss, int debug_print) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 894 | { |
| 895 | const struct hostapd_hw_modes *mode = NULL, *modes; |
| 896 | const u8 scan_ie[2] = { WLAN_EID_SUPP_RATES, WLAN_EID_EXT_SUPP_RATES }; |
| 897 | const u8 *rate_ie; |
| 898 | int i, j, k; |
| 899 | |
| 900 | if (bss->freq == 0) |
| 901 | return 1; /* Cannot do matching without knowing band */ |
| 902 | |
| 903 | modes = wpa_s->hw.modes; |
| 904 | if (modes == NULL) { |
| 905 | /* |
| 906 | * The driver does not provide any additional information |
| 907 | * about the utilized hardware, so allow the connection attempt |
| 908 | * to continue. |
| 909 | */ |
| 910 | return 1; |
| 911 | } |
| 912 | |
| 913 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 914 | for (j = 0; j < modes[i].num_channels; j++) { |
| 915 | int freq = modes[i].channels[j].freq; |
| 916 | if (freq == bss->freq) { |
| 917 | if (mode && |
| 918 | mode->mode == HOSTAPD_MODE_IEEE80211G) |
| 919 | break; /* do not allow 802.11b replace |
| 920 | * 802.11g */ |
| 921 | mode = &modes[i]; |
| 922 | break; |
| 923 | } |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | if (mode == NULL) |
| 928 | return 0; |
| 929 | |
| 930 | for (i = 0; i < (int) sizeof(scan_ie); i++) { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 931 | rate_ie = wpa_bss_get_ie(bss, scan_ie[i]); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 932 | if (rate_ie == NULL) |
| 933 | continue; |
| 934 | |
| 935 | for (j = 2; j < rate_ie[1] + 2; j++) { |
| 936 | int flagged = !!(rate_ie[j] & 0x80); |
| 937 | int r = (rate_ie[j] & 0x7f) * 5; |
| 938 | |
| 939 | /* |
| 940 | * IEEE Std 802.11n-2009 7.3.2.2: |
| 941 | * The new BSS Membership selector value is encoded |
| 942 | * like a legacy basic rate, but it is not a rate and |
| 943 | * only indicates if the BSS members are required to |
| 944 | * support the mandatory features of Clause 20 [HT PHY] |
| 945 | * in order to join the BSS. |
| 946 | */ |
| 947 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 948 | BSS_MEMBERSHIP_SELECTOR_HT_PHY)) { |
| 949 | if (!ht_supported(mode)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 950 | if (debug_print) |
| 951 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 952 | " hardware does not support HT PHY"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 953 | return 0; |
| 954 | } |
| 955 | continue; |
| 956 | } |
| 957 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 958 | /* There's also a VHT selector for 802.11ac */ |
| 959 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 960 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY)) { |
| 961 | if (!vht_supported(mode)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 962 | if (debug_print) |
| 963 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 964 | " hardware does not support VHT PHY"); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 965 | return 0; |
| 966 | } |
| 967 | continue; |
| 968 | } |
| 969 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 970 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 971 | BSS_MEMBERSHIP_SELECTOR_HE_PHY)) { |
| 972 | if (!he_supported(mode, IEEE80211_MODE_INFRA)) { |
| 973 | if (debug_print) |
| 974 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 975 | " hardware does not support HE PHY"); |
| 976 | return 0; |
| 977 | } |
| 978 | continue; |
| 979 | } |
| 980 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 981 | #ifdef CONFIG_SAE |
| 982 | if (flagged && ((rate_ie[j] & 0x7f) == |
| 983 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E_ONLY)) { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 984 | if (wpa_s->conf->sae_pwe == |
| 985 | SAE_PWE_HUNT_AND_PECK && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 986 | !ssid->sae_password_id && |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 987 | !is_6ghz_freq(bss->freq) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 988 | wpa_key_mgmt_sae(ssid->key_mgmt)) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 989 | if (debug_print) |
| 990 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 991 | " SAE H2E disabled"); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 992 | #ifdef CONFIG_TESTING_OPTIONS |
| 993 | if (wpa_s->ignore_sae_h2e_only) { |
| 994 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 995 | "TESTING: Ignore SAE H2E requirement mismatch"); |
| 996 | continue; |
| 997 | } |
| 998 | #endif /* CONFIG_TESTING_OPTIONS */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 999 | return 0; |
| 1000 | } |
| 1001 | continue; |
| 1002 | } |
| 1003 | #endif /* CONFIG_SAE */ |
| 1004 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1005 | if (!flagged) |
| 1006 | continue; |
| 1007 | |
| 1008 | /* check for legacy basic rates */ |
| 1009 | for (k = 0; k < mode->num_rates; k++) { |
| 1010 | if (mode->rates[k] == r) |
| 1011 | break; |
| 1012 | } |
| 1013 | if (k == mode->num_rates) { |
| 1014 | /* |
| 1015 | * IEEE Std 802.11-2007 7.3.2.2 demands that in |
| 1016 | * order to join a BSS all required rates |
| 1017 | * have to be supported by the hardware. |
| 1018 | */ |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1019 | if (debug_print) |
| 1020 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1021 | " hardware does not support required rate %d.%d Mbps (freq=%d mode==%d num_rates=%d)", |
| 1022 | r / 10, r % 10, |
| 1023 | bss->freq, mode->mode, mode->num_rates); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1024 | return 0; |
| 1025 | } |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | return 1; |
| 1030 | } |
| 1031 | |
| 1032 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 1033 | /* |
| 1034 | * Test whether BSS is in an ESS. |
| 1035 | * This is done differently in DMG (60 GHz) and non-DMG bands |
| 1036 | */ |
| 1037 | static int bss_is_ess(struct wpa_bss *bss) |
| 1038 | { |
| 1039 | if (bss_is_dmg(bss)) { |
| 1040 | return (bss->caps & IEEE80211_CAP_DMG_MASK) == |
| 1041 | IEEE80211_CAP_DMG_AP; |
| 1042 | } |
| 1043 | |
| 1044 | return ((bss->caps & (IEEE80211_CAP_ESS | IEEE80211_CAP_IBSS)) == |
| 1045 | IEEE80211_CAP_ESS); |
| 1046 | } |
| 1047 | |
| 1048 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1049 | static int match_mac_mask(const u8 *addr_a, const u8 *addr_b, const u8 *mask) |
| 1050 | { |
| 1051 | size_t i; |
| 1052 | |
| 1053 | for (i = 0; i < ETH_ALEN; i++) { |
| 1054 | if ((addr_a[i] & mask[i]) != (addr_b[i] & mask[i])) |
| 1055 | return 0; |
| 1056 | } |
| 1057 | return 1; |
| 1058 | } |
| 1059 | |
| 1060 | |
| 1061 | static int addr_in_list(const u8 *addr, const u8 *list, size_t num) |
| 1062 | { |
| 1063 | size_t i; |
| 1064 | |
| 1065 | for (i = 0; i < num; i++) { |
| 1066 | const u8 *a = list + i * ETH_ALEN * 2; |
| 1067 | const u8 *m = a + ETH_ALEN; |
| 1068 | |
| 1069 | if (match_mac_mask(a, addr, m)) |
| 1070 | return 1; |
| 1071 | } |
| 1072 | return 0; |
| 1073 | } |
| 1074 | |
| 1075 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1076 | static void owe_trans_ssid(struct wpa_supplicant *wpa_s, struct wpa_bss *bss, |
| 1077 | const u8 **ret_ssid, size_t *ret_ssid_len) |
| 1078 | { |
| 1079 | #ifdef CONFIG_OWE |
| 1080 | const u8 *owe, *pos, *end, *bssid; |
| 1081 | u8 ssid_len; |
| 1082 | struct wpa_bss *open_bss; |
| 1083 | |
| 1084 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 1085 | if (!owe || !wpa_bss_get_ie(bss, WLAN_EID_RSN)) |
| 1086 | return; |
| 1087 | |
| 1088 | pos = owe + 6; |
| 1089 | end = owe + 2 + owe[1]; |
| 1090 | |
| 1091 | if (end - pos < ETH_ALEN + 1) |
| 1092 | return; |
| 1093 | bssid = pos; |
| 1094 | pos += ETH_ALEN; |
| 1095 | ssid_len = *pos++; |
| 1096 | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) |
| 1097 | return; |
| 1098 | |
| 1099 | /* Match the profile SSID against the OWE transition mode SSID on the |
| 1100 | * open network. */ |
| 1101 | wpa_dbg(wpa_s, MSG_DEBUG, "OWE: transition mode BSSID: " MACSTR |
| 1102 | " SSID: %s", MAC2STR(bssid), wpa_ssid_txt(pos, ssid_len)); |
| 1103 | *ret_ssid = pos; |
| 1104 | *ret_ssid_len = ssid_len; |
| 1105 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1106 | if (!(bss->flags & WPA_BSS_OWE_TRANSITION)) { |
| 1107 | struct wpa_ssid *ssid; |
| 1108 | |
| 1109 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1110 | if (wpas_network_disabled(wpa_s, ssid)) |
| 1111 | continue; |
| 1112 | if (ssid->ssid_len == ssid_len && |
| 1113 | os_memcmp(ssid->ssid, pos, ssid_len) == 0) { |
| 1114 | /* OWE BSS in transition mode for a currently |
| 1115 | * enabled OWE network. */ |
| 1116 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1117 | "OWE: transition mode OWE SSID for active OWE profile"); |
| 1118 | bss->flags |= WPA_BSS_OWE_TRANSITION; |
| 1119 | break; |
| 1120 | } |
| 1121 | } |
| 1122 | } |
| 1123 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1124 | if (bss->ssid_len > 0) |
| 1125 | return; |
| 1126 | |
| 1127 | open_bss = wpa_bss_get_bssid_latest(wpa_s, bssid); |
| 1128 | if (!open_bss) |
| 1129 | return; |
| 1130 | if (ssid_len != open_bss->ssid_len || |
| 1131 | os_memcmp(pos, open_bss->ssid, ssid_len) != 0) { |
| 1132 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1133 | "OWE: transition mode SSID mismatch: %s", |
| 1134 | wpa_ssid_txt(open_bss->ssid, open_bss->ssid_len)); |
| 1135 | return; |
| 1136 | } |
| 1137 | |
| 1138 | owe = wpa_bss_get_vendor_ie(open_bss, OWE_IE_VENDOR_TYPE); |
| 1139 | if (!owe || wpa_bss_get_ie(open_bss, WLAN_EID_RSN)) { |
| 1140 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1141 | "OWE: transition mode open BSS unexpected info"); |
| 1142 | return; |
| 1143 | } |
| 1144 | |
| 1145 | pos = owe + 6; |
| 1146 | end = owe + 2 + owe[1]; |
| 1147 | |
| 1148 | if (end - pos < ETH_ALEN + 1) |
| 1149 | return; |
| 1150 | if (os_memcmp(pos, bss->bssid, ETH_ALEN) != 0) { |
| 1151 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1152 | "OWE: transition mode BSSID mismatch: " MACSTR, |
| 1153 | MAC2STR(pos)); |
| 1154 | return; |
| 1155 | } |
| 1156 | pos += ETH_ALEN; |
| 1157 | ssid_len = *pos++; |
| 1158 | if (end - pos < ssid_len || ssid_len > SSID_MAX_LEN) |
| 1159 | return; |
| 1160 | wpa_dbg(wpa_s, MSG_DEBUG, "OWE: learned transition mode OWE SSID: %s", |
| 1161 | wpa_ssid_txt(pos, ssid_len)); |
| 1162 | os_memcpy(bss->ssid, pos, ssid_len); |
| 1163 | bss->ssid_len = ssid_len; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1164 | bss->flags |= WPA_BSS_OWE_TRANSITION; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1165 | #endif /* CONFIG_OWE */ |
| 1166 | } |
| 1167 | |
| 1168 | |
Sunil Ravi | 26978f3 | 2021-04-30 15:19:18 -0700 | [diff] [blame] | 1169 | int disabled_freq(struct wpa_supplicant *wpa_s, int freq) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1170 | { |
| 1171 | int i, j; |
| 1172 | |
| 1173 | if (!wpa_s->hw.modes || !wpa_s->hw.num_modes) |
| 1174 | return 0; |
| 1175 | |
| 1176 | for (j = 0; j < wpa_s->hw.num_modes; j++) { |
| 1177 | struct hostapd_hw_modes *mode = &wpa_s->hw.modes[j]; |
| 1178 | |
| 1179 | for (i = 0; i < mode->num_channels; i++) { |
| 1180 | struct hostapd_channel_data *chan = &mode->channels[i]; |
| 1181 | |
| 1182 | if (chan->freq == freq) |
| 1183 | return !!(chan->flag & HOSTAPD_CHAN_DISABLED); |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | return 1; |
| 1188 | } |
| 1189 | |
| 1190 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1191 | static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 1192 | const u8 *match_ssid, size_t match_ssid_len, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1193 | struct wpa_bss *bss, int bssid_ignore_count, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1194 | bool debug_print); |
| 1195 | |
| 1196 | |
| 1197 | #ifdef CONFIG_SAE_PK |
| 1198 | static bool sae_pk_acceptable_bss_with_pk(struct wpa_supplicant *wpa_s, |
| 1199 | struct wpa_bss *orig_bss, |
| 1200 | struct wpa_ssid *ssid, |
| 1201 | const u8 *match_ssid, |
| 1202 | size_t match_ssid_len) |
| 1203 | { |
| 1204 | struct wpa_bss *bss; |
| 1205 | |
| 1206 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
| 1207 | int count; |
| 1208 | const u8 *ie; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1209 | |
| 1210 | if (bss == orig_bss) |
| 1211 | continue; |
| 1212 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1213 | if (!(ieee802_11_rsnx_capab(ie, WLAN_RSNX_CAPAB_SAE_PK))) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1214 | continue; |
| 1215 | |
| 1216 | /* TODO: Could be more thorough in checking what kind of |
| 1217 | * signal strength or throughput estimate would be acceptable |
| 1218 | * compared to the originally selected BSS. */ |
| 1219 | if (bss->est_throughput < 2000) |
| 1220 | return false; |
| 1221 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1222 | count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1223 | if (wpa_scan_res_ok(wpa_s, ssid, match_ssid, match_ssid_len, |
| 1224 | bss, count, 0)) |
| 1225 | return true; |
| 1226 | } |
| 1227 | |
| 1228 | return false; |
| 1229 | } |
| 1230 | #endif /* CONFIG_SAE_PK */ |
| 1231 | |
| 1232 | |
| 1233 | static bool wpa_scan_res_ok(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid, |
| 1234 | const u8 *match_ssid, size_t match_ssid_len, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1235 | struct wpa_bss *bss, int bssid_ignore_count, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1236 | bool debug_print) |
| 1237 | { |
| 1238 | int res; |
| 1239 | bool wpa, check_ssid, osen, rsn_osen = false; |
| 1240 | struct wpa_ie_data data; |
| 1241 | #ifdef CONFIG_MBO |
| 1242 | const u8 *assoc_disallow; |
| 1243 | #endif /* CONFIG_MBO */ |
| 1244 | #ifdef CONFIG_SAE |
| 1245 | u8 rsnxe_capa = 0; |
| 1246 | #endif /* CONFIG_SAE */ |
| 1247 | const u8 *ie; |
| 1248 | |
| 1249 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 1250 | wpa = ie && ie[1]; |
| 1251 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 1252 | wpa |= ie && ie[1]; |
| 1253 | if (ie && wpa_parse_wpa_ie_rsn(ie, 2 + ie[1], &data) == 0 && |
| 1254 | (data.key_mgmt & WPA_KEY_MGMT_OSEN)) |
| 1255 | rsn_osen = true; |
| 1256 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 1257 | osen = ie != NULL; |
| 1258 | |
| 1259 | #ifdef CONFIG_SAE |
| 1260 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
| 1261 | if (ie && ie[1] >= 1) |
| 1262 | rsnxe_capa = ie[2]; |
| 1263 | #endif /* CONFIG_SAE */ |
| 1264 | |
| 1265 | check_ssid = wpa || ssid->ssid_len > 0; |
| 1266 | |
| 1267 | if (wpas_network_disabled(wpa_s, ssid)) { |
| 1268 | if (debug_print) |
| 1269 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - disabled"); |
| 1270 | return false; |
| 1271 | } |
| 1272 | |
| 1273 | res = wpas_temp_disabled(wpa_s, ssid); |
| 1274 | if (res > 0) { |
| 1275 | if (debug_print) |
| 1276 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1277 | " skip - disabled temporarily for %d second(s)", |
| 1278 | res); |
| 1279 | return false; |
| 1280 | } |
| 1281 | |
| 1282 | #ifdef CONFIG_WPS |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1283 | if ((ssid->key_mgmt & WPA_KEY_MGMT_WPS) && bssid_ignore_count) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1284 | if (debug_print) |
| 1285 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1286 | " skip - BSSID ignored (WPS)"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
| 1289 | |
| 1290 | if (wpa && ssid->ssid_len == 0 && |
| 1291 | wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss)) |
| 1292 | check_ssid = false; |
| 1293 | |
| 1294 | if (!wpa && (ssid->key_mgmt & WPA_KEY_MGMT_WPS)) { |
| 1295 | /* Only allow wildcard SSID match if an AP advertises active |
| 1296 | * WPS operation that matches our mode. */ |
| 1297 | check_ssid = ssid->ssid_len > 0 || |
| 1298 | !wpas_wps_ssid_wildcard_ok(wpa_s, ssid, bss); |
| 1299 | } |
| 1300 | #endif /* CONFIG_WPS */ |
| 1301 | |
| 1302 | if (ssid->bssid_set && ssid->ssid_len == 0 && |
| 1303 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) == 0) |
| 1304 | check_ssid = false; |
| 1305 | |
| 1306 | if (check_ssid && |
| 1307 | (match_ssid_len != ssid->ssid_len || |
| 1308 | os_memcmp(match_ssid, ssid->ssid, match_ssid_len) != 0)) { |
| 1309 | if (debug_print) |
| 1310 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID mismatch"); |
| 1311 | return false; |
| 1312 | } |
| 1313 | |
| 1314 | if (ssid->bssid_set && |
| 1315 | os_memcmp(bss->bssid, ssid->bssid, ETH_ALEN) != 0) { |
| 1316 | if (debug_print) |
| 1317 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID mismatch"); |
| 1318 | return false; |
| 1319 | } |
| 1320 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1321 | /* check the list of BSSIDs to ignore */ |
| 1322 | if (ssid->num_bssid_ignore && |
| 1323 | addr_in_list(bss->bssid, ssid->bssid_ignore, |
| 1324 | ssid->num_bssid_ignore)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1325 | if (debug_print) |
| 1326 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1327 | " skip - BSSID configured to be ignored"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1328 | return false; |
| 1329 | } |
| 1330 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1331 | /* if there is a list of accepted BSSIDs, only accept those APs */ |
| 1332 | if (ssid->num_bssid_accept && |
| 1333 | !addr_in_list(bss->bssid, ssid->bssid_accept, |
| 1334 | ssid->num_bssid_accept)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1335 | if (debug_print) |
| 1336 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1337 | " skip - BSSID not in list of accepted values"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1338 | return false; |
| 1339 | } |
| 1340 | |
| 1341 | if (!wpa_supplicant_ssid_bss_match(wpa_s, ssid, bss, debug_print)) |
| 1342 | return false; |
| 1343 | |
| 1344 | if (!osen && !wpa && |
| 1345 | !(ssid->key_mgmt & WPA_KEY_MGMT_NONE) && |
| 1346 | !(ssid->key_mgmt & WPA_KEY_MGMT_WPS) && |
| 1347 | !(ssid->key_mgmt & WPA_KEY_MGMT_OWE) && |
| 1348 | !(ssid->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) { |
| 1349 | if (debug_print) |
| 1350 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1351 | " skip - non-WPA network not allowed"); |
| 1352 | return false; |
| 1353 | } |
| 1354 | |
| 1355 | #ifdef CONFIG_WEP |
| 1356 | if (wpa && !wpa_key_mgmt_wpa(ssid->key_mgmt) && has_wep_key(ssid)) { |
| 1357 | if (debug_print) |
| 1358 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1359 | " skip - ignore WPA/WPA2 AP for WEP network block"); |
| 1360 | return false; |
| 1361 | } |
| 1362 | #endif /* CONFIG_WEP */ |
| 1363 | |
| 1364 | if ((ssid->key_mgmt & WPA_KEY_MGMT_OSEN) && !osen && !rsn_osen) { |
| 1365 | if (debug_print) |
| 1366 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1367 | " skip - non-OSEN network not allowed"); |
| 1368 | return false; |
| 1369 | } |
| 1370 | |
| 1371 | if (!wpa_supplicant_match_privacy(bss, ssid)) { |
| 1372 | if (debug_print) |
| 1373 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - privacy mismatch"); |
| 1374 | return false; |
| 1375 | } |
| 1376 | |
| 1377 | if (ssid->mode != WPAS_MODE_MESH && !bss_is_ess(bss) && |
| 1378 | !bss_is_pbss(bss)) { |
| 1379 | if (debug_print) |
| 1380 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1381 | " skip - not ESS, PBSS, or MBSS"); |
| 1382 | return false; |
| 1383 | } |
| 1384 | |
| 1385 | if (ssid->pbss != 2 && ssid->pbss != bss_is_pbss(bss)) { |
| 1386 | if (debug_print) |
| 1387 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1388 | " skip - PBSS mismatch (ssid %d bss %d)", |
| 1389 | ssid->pbss, bss_is_pbss(bss)); |
| 1390 | return false; |
| 1391 | } |
| 1392 | |
| 1393 | if (!freq_allowed(ssid->freq_list, bss->freq)) { |
| 1394 | if (debug_print) |
| 1395 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1396 | " skip - frequency not allowed"); |
| 1397 | return false; |
| 1398 | } |
| 1399 | |
| 1400 | #ifdef CONFIG_MESH |
| 1401 | if (ssid->mode == WPAS_MODE_MESH && ssid->frequency > 0 && |
| 1402 | ssid->frequency != bss->freq) { |
| 1403 | if (debug_print) |
| 1404 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1405 | " skip - frequency not allowed (mesh)"); |
| 1406 | return false; |
| 1407 | } |
| 1408 | #endif /* CONFIG_MESH */ |
| 1409 | |
| 1410 | if (!rate_match(wpa_s, ssid, bss, debug_print)) { |
| 1411 | if (debug_print) |
| 1412 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1413 | " skip - rate sets do not match"); |
| 1414 | return false; |
| 1415 | } |
| 1416 | |
| 1417 | #ifdef CONFIG_SAE |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1418 | /* When using SAE Password Identifier and when operationg on the 6 GHz |
| 1419 | * band, only H2E is allowed. */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1420 | if ((wpa_s->conf->sae_pwe == SAE_PWE_HASH_TO_ELEMENT || |
| 1421 | is_6ghz_freq(bss->freq) || ssid->sae_password_id) && |
| 1422 | wpa_s->conf->sae_pwe != SAE_PWE_FORCE_HUNT_AND_PECK && |
| 1423 | wpa_key_mgmt_sae(ssid->key_mgmt) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 1424 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 1425 | !(wpa_key_mgmt_wpa_psk_no_sae(ssid->key_mgmt)) && |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 1426 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1427 | !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_H2E))) { |
| 1428 | if (debug_print) |
| 1429 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1430 | " skip - SAE H2E required, but not supported by the AP"); |
| 1431 | return false; |
| 1432 | } |
| 1433 | #endif /* CONFIG_SAE */ |
| 1434 | |
| 1435 | #ifdef CONFIG_SAE_PK |
| 1436 | if (ssid->sae_pk == SAE_PK_MODE_ONLY && |
| 1437 | !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK))) { |
| 1438 | if (debug_print) |
| 1439 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1440 | " skip - SAE-PK required, but not supported by the AP"); |
| 1441 | return false; |
| 1442 | } |
| 1443 | #endif /* CONFIG_SAE_PK */ |
| 1444 | |
| 1445 | #ifndef CONFIG_IBSS_RSN |
| 1446 | if (ssid->mode == WPAS_MODE_IBSS && |
| 1447 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | WPA_KEY_MGMT_WPA_NONE))) { |
| 1448 | if (debug_print) |
| 1449 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1450 | " skip - IBSS RSN not supported in the build"); |
| 1451 | return false; |
| 1452 | } |
| 1453 | #endif /* !CONFIG_IBSS_RSN */ |
| 1454 | |
| 1455 | #ifdef CONFIG_P2P |
| 1456 | if (ssid->p2p_group && |
| 1457 | !wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) && |
| 1458 | !wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) { |
| 1459 | if (debug_print) |
| 1460 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - no P2P IE seen"); |
| 1461 | return false; |
| 1462 | } |
| 1463 | |
| 1464 | if (!is_zero_ether_addr(ssid->go_p2p_dev_addr)) { |
| 1465 | struct wpabuf *p2p_ie; |
| 1466 | u8 dev_addr[ETH_ALEN]; |
| 1467 | |
| 1468 | ie = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE); |
| 1469 | if (!ie) { |
| 1470 | if (debug_print) |
| 1471 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1472 | " skip - no P2P element"); |
| 1473 | return false; |
| 1474 | } |
| 1475 | p2p_ie = wpa_bss_get_vendor_ie_multi(bss, P2P_IE_VENDOR_TYPE); |
| 1476 | if (!p2p_ie) { |
| 1477 | if (debug_print) |
| 1478 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1479 | " skip - could not fetch P2P element"); |
| 1480 | return false; |
| 1481 | } |
| 1482 | |
| 1483 | if (p2p_parse_dev_addr_in_p2p_ie(p2p_ie, dev_addr) < 0 || |
| 1484 | os_memcmp(dev_addr, ssid->go_p2p_dev_addr, ETH_ALEN) != 0) { |
| 1485 | if (debug_print) |
| 1486 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1487 | " skip - no matching GO P2P Device Address in P2P element"); |
| 1488 | wpabuf_free(p2p_ie); |
| 1489 | return false; |
| 1490 | } |
| 1491 | wpabuf_free(p2p_ie); |
| 1492 | } |
| 1493 | |
| 1494 | /* |
| 1495 | * TODO: skip the AP if its P2P IE has Group Formation bit set in the |
| 1496 | * P2P Group Capability Bitmap and we are not in Group Formation with |
| 1497 | * that device. |
| 1498 | */ |
| 1499 | #endif /* CONFIG_P2P */ |
| 1500 | |
| 1501 | if (os_reltime_before(&bss->last_update, &wpa_s->scan_min_time)) { |
| 1502 | struct os_reltime diff; |
| 1503 | |
| 1504 | os_reltime_sub(&wpa_s->scan_min_time, &bss->last_update, &diff); |
| 1505 | if (debug_print) |
| 1506 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1507 | " skip - scan result not recent enough (%u.%06u seconds too old)", |
| 1508 | (unsigned int) diff.sec, |
| 1509 | (unsigned int) diff.usec); |
| 1510 | return false; |
| 1511 | } |
| 1512 | #ifdef CONFIG_MBO |
| 1513 | #ifdef CONFIG_TESTING_OPTIONS |
| 1514 | if (wpa_s->ignore_assoc_disallow) |
| 1515 | goto skip_assoc_disallow; |
| 1516 | #endif /* CONFIG_TESTING_OPTIONS */ |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 1517 | assoc_disallow = wpas_mbo_check_assoc_disallow(bss); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1518 | if (assoc_disallow && assoc_disallow[1] >= 1) { |
| 1519 | if (debug_print) |
| 1520 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1521 | " skip - MBO association disallowed (reason %u)", |
| 1522 | assoc_disallow[2]); |
| 1523 | return false; |
| 1524 | } |
| 1525 | |
| 1526 | if (wpa_is_bss_tmp_disallowed(wpa_s, bss)) { |
| 1527 | if (debug_print) |
| 1528 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1529 | " skip - AP temporarily disallowed"); |
| 1530 | return false; |
| 1531 | } |
| 1532 | #ifdef CONFIG_TESTING_OPTIONS |
| 1533 | skip_assoc_disallow: |
| 1534 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 1535 | #endif /* CONFIG_MBO */ |
| 1536 | |
| 1537 | #ifdef CONFIG_DPP |
| 1538 | if ((ssid->key_mgmt & WPA_KEY_MGMT_DPP) && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1539 | !wpa_sm_pmksa_exists(wpa_s->wpa, bss->bssid, wpa_s->own_addr, |
| 1540 | ssid) && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1541 | (!ssid->dpp_connector || !ssid->dpp_netaccesskey || |
| 1542 | !ssid->dpp_csign)) { |
| 1543 | if (debug_print) |
| 1544 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1545 | " skip - no PMKSA entry for DPP"); |
| 1546 | return false; |
| 1547 | } |
| 1548 | #endif /* CONFIG_DPP */ |
| 1549 | |
| 1550 | #ifdef CONFIG_SAE_PK |
| 1551 | if (ssid->sae_pk == SAE_PK_MODE_AUTOMATIC && |
| 1552 | wpa_key_mgmt_sae(ssid->key_mgmt) && |
| 1553 | ((ssid->sae_password && |
| 1554 | sae_pk_valid_password(ssid->sae_password)) || |
| 1555 | (!ssid->sae_password && ssid->passphrase && |
| 1556 | sae_pk_valid_password(ssid->passphrase))) && |
| 1557 | !(rsnxe_capa & BIT(WLAN_RSNX_CAPAB_SAE_PK)) && |
| 1558 | sae_pk_acceptable_bss_with_pk(wpa_s, bss, ssid, match_ssid, |
| 1559 | match_ssid_len)) { |
| 1560 | if (debug_print) |
| 1561 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1562 | " skip - another acceptable BSS with SAE-PK in the same ESS"); |
| 1563 | return false; |
| 1564 | } |
| 1565 | #endif /* CONFIG_SAE_PK */ |
| 1566 | |
| 1567 | if (bss->ssid_len == 0) { |
| 1568 | if (debug_print) |
| 1569 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1570 | " skip - no SSID known for the BSS"); |
| 1571 | return false; |
| 1572 | } |
| 1573 | |
| 1574 | /* Matching configuration found */ |
| 1575 | return true; |
| 1576 | } |
| 1577 | |
| 1578 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 1579 | struct wpa_ssid * wpa_scan_res_match(struct wpa_supplicant *wpa_s, |
| 1580 | int i, struct wpa_bss *bss, |
| 1581 | struct wpa_ssid *group, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1582 | int only_first_ssid, int debug_print) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1583 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1584 | u8 wpa_ie_len, rsn_ie_len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1585 | const u8 *ie; |
| 1586 | struct wpa_ssid *ssid; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1587 | int osen; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1588 | const u8 *match_ssid; |
| 1589 | size_t match_ssid_len; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1590 | int bssid_ignore_count; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1591 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1592 | ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1593 | wpa_ie_len = ie ? ie[1] : 0; |
| 1594 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1595 | ie = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1596 | rsn_ie_len = ie ? ie[1] : 0; |
| 1597 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1598 | ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE); |
| 1599 | osen = ie != NULL; |
| 1600 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1601 | if (debug_print) { |
| 1602 | wpa_dbg(wpa_s, MSG_DEBUG, "%d: " MACSTR |
| 1603 | " ssid='%s' wpa_ie_len=%u rsn_ie_len=%u caps=0x%x level=%d freq=%d %s%s%s", |
| 1604 | i, MAC2STR(bss->bssid), |
| 1605 | wpa_ssid_txt(bss->ssid, bss->ssid_len), |
| 1606 | wpa_ie_len, rsn_ie_len, bss->caps, bss->level, |
| 1607 | bss->freq, |
| 1608 | wpa_bss_get_vendor_ie(bss, WPS_IE_VENDOR_TYPE) ? |
| 1609 | " wps" : "", |
| 1610 | (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) || |
| 1611 | wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) |
| 1612 | ? " p2p" : "", |
| 1613 | osen ? " osen=1" : ""); |
| 1614 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1616 | bssid_ignore_count = wpa_bssid_ignore_is_listed(wpa_s, bss->bssid); |
| 1617 | if (bssid_ignore_count) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1618 | int limit = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1619 | if (wpa_supplicant_enabled_networks(wpa_s) == 1) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1620 | /* |
| 1621 | * When only a single network is enabled, we can |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1622 | * trigger BSSID ignoring on the first failure. This |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1623 | * should not be done with multiple enabled networks to |
| 1624 | * avoid getting forced to move into a worse ESS on |
| 1625 | * single error if there are no other BSSes of the |
| 1626 | * current ESS. |
| 1627 | */ |
| 1628 | limit = 0; |
| 1629 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1630 | if (bssid_ignore_count > limit) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1631 | if (debug_print) { |
| 1632 | wpa_dbg(wpa_s, MSG_DEBUG, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1633 | " skip - BSSID ignored (count=%d limit=%d)", |
| 1634 | bssid_ignore_count, limit); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1635 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1636 | return NULL; |
| 1637 | } |
| 1638 | } |
| 1639 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1640 | match_ssid = bss->ssid; |
| 1641 | match_ssid_len = bss->ssid_len; |
| 1642 | owe_trans_ssid(wpa_s, bss, &match_ssid, &match_ssid_len); |
| 1643 | |
| 1644 | if (match_ssid_len == 0) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1645 | if (debug_print) |
| 1646 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID not known"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1647 | return NULL; |
| 1648 | } |
| 1649 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1650 | if (disallowed_bssid(wpa_s, bss->bssid)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1651 | if (debug_print) |
| 1652 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - BSSID disallowed"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1653 | return NULL; |
| 1654 | } |
| 1655 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1656 | if (disallowed_ssid(wpa_s, match_ssid, match_ssid_len)) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1657 | if (debug_print) |
| 1658 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - SSID disallowed"); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1659 | return NULL; |
| 1660 | } |
| 1661 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1662 | if (disabled_freq(wpa_s, bss->freq)) { |
| 1663 | if (debug_print) |
| 1664 | wpa_dbg(wpa_s, MSG_DEBUG, " skip - channel disabled"); |
| 1665 | return NULL; |
| 1666 | } |
| 1667 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1668 | for (ssid = group; ssid; ssid = only_first_ssid ? NULL : ssid->pnext) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1669 | 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] | 1670 | bss, bssid_ignore_count, debug_print)) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1671 | return ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
| 1674 | /* No matching configuration found */ |
| 1675 | return NULL; |
| 1676 | } |
| 1677 | |
| 1678 | |
| 1679 | static struct wpa_bss * |
| 1680 | wpa_supplicant_select_bss(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1681 | struct wpa_ssid *group, |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1682 | struct wpa_ssid **selected_ssid, |
| 1683 | int only_first_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1684 | { |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1685 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1686 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1687 | if (wpa_s->current_ssid) { |
| 1688 | struct wpa_ssid *ssid; |
| 1689 | |
| 1690 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1691 | "Scan results matching the currently selected network"); |
| 1692 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 1693 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
| 1694 | |
| 1695 | ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
| 1696 | only_first_ssid, 0); |
| 1697 | if (ssid != wpa_s->current_ssid) |
| 1698 | continue; |
| 1699 | wpa_dbg(wpa_s, MSG_DEBUG, "%u: " MACSTR |
| 1700 | " freq=%d level=%d snr=%d est_throughput=%u", |
| 1701 | i, MAC2STR(bss->bssid), bss->freq, bss->level, |
| 1702 | bss->snr, bss->est_throughput); |
| 1703 | } |
| 1704 | } |
| 1705 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1706 | if (only_first_ssid) |
| 1707 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to find BSS matching pre-selected network id=%d", |
| 1708 | group->id); |
| 1709 | else |
| 1710 | wpa_dbg(wpa_s, MSG_DEBUG, "Selecting BSS from priority group %d", |
| 1711 | group->priority); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1712 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1713 | for (i = 0; i < wpa_s->last_scan_res_used; i++) { |
| 1714 | struct wpa_bss *bss = wpa_s->last_scan_res[i]; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1715 | |
| 1716 | wpa_s->owe_transition_select = 1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1717 | *selected_ssid = wpa_scan_res_match(wpa_s, i, bss, group, |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1718 | only_first_ssid, 1); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1719 | wpa_s->owe_transition_select = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1720 | if (!*selected_ssid) |
| 1721 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1722 | wpa_dbg(wpa_s, MSG_DEBUG, " selected %sBSS " MACSTR |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1723 | " ssid='%s'", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1724 | bss == wpa_s->current_bss ? "current ": "", |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1725 | MAC2STR(bss->bssid), |
| 1726 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| 1727 | return bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1728 | } |
| 1729 | |
| 1730 | return NULL; |
| 1731 | } |
| 1732 | |
| 1733 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 1734 | struct wpa_bss * wpa_supplicant_pick_network(struct wpa_supplicant *wpa_s, |
| 1735 | struct wpa_ssid **selected_ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1736 | { |
| 1737 | struct wpa_bss *selected = NULL; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1738 | size_t prio; |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1739 | struct wpa_ssid *next_ssid = NULL; |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1740 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1741 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1742 | if (wpa_s->last_scan_res == NULL || |
| 1743 | wpa_s->last_scan_res_used == 0) |
| 1744 | return NULL; /* no scan results from last update */ |
| 1745 | |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1746 | if (wpa_s->next_ssid) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1747 | /* check that next_ssid is still valid */ |
| 1748 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1749 | if (ssid == wpa_s->next_ssid) |
| 1750 | break; |
| 1751 | } |
| 1752 | next_ssid = ssid; |
| 1753 | wpa_s->next_ssid = NULL; |
| 1754 | } |
| 1755 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1756 | while (selected == NULL) { |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1757 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { |
| 1758 | if (next_ssid && next_ssid->priority == |
| 1759 | wpa_s->conf->pssid[prio]->priority) { |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1760 | selected = wpa_supplicant_select_bss( |
Dmitry Shmidt | 4582d2a | 2014-02-28 11:14:23 -0800 | [diff] [blame] | 1761 | wpa_s, next_ssid, selected_ssid, 1); |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1762 | if (selected) |
| 1763 | break; |
| 1764 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | selected = wpa_supplicant_select_bss( |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 1766 | wpa_s, wpa_s->conf->pssid[prio], |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1767 | selected_ssid, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1768 | if (selected) |
| 1769 | break; |
| 1770 | } |
| 1771 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1772 | if (selected == NULL && wpa_s->bssid_ignore && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1773 | !wpa_s->countermeasures) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1774 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1775 | "No APs found - clear BSSID ignore list and try again"); |
| 1776 | wpa_bssid_ignore_clear(wpa_s); |
| 1777 | wpa_s->bssid_ignore_cleared = true; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1778 | } else if (selected == NULL) |
| 1779 | break; |
| 1780 | } |
| 1781 | |
Dmitry Shmidt | 912c6ec | 2015-03-30 13:16:51 -0700 | [diff] [blame] | 1782 | ssid = *selected_ssid; |
| 1783 | if (selected && ssid && ssid->mem_only_psk && !ssid->psk_set && |
| 1784 | !ssid->passphrase && !ssid->ext_psk) { |
| 1785 | const char *field_name, *txt = NULL; |
| 1786 | |
| 1787 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1788 | "PSK/passphrase not yet available for the selected network"); |
| 1789 | |
| 1790 | wpas_notify_network_request(wpa_s, ssid, |
| 1791 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL); |
| 1792 | |
| 1793 | field_name = wpa_supplicant_ctrl_req_to_string( |
| 1794 | WPA_CTRL_REQ_PSK_PASSPHRASE, NULL, &txt); |
| 1795 | if (field_name == NULL) |
| 1796 | return NULL; |
| 1797 | |
| 1798 | wpas_send_ctrl_req(wpa_s, ssid, field_name, txt); |
| 1799 | |
| 1800 | selected = NULL; |
| 1801 | } |
| 1802 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1803 | return selected; |
| 1804 | } |
| 1805 | |
| 1806 | |
| 1807 | static void wpa_supplicant_req_new_scan(struct wpa_supplicant *wpa_s, |
| 1808 | int timeout_sec, int timeout_usec) |
| 1809 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1810 | if (!wpa_supplicant_enabled_networks(wpa_s)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1811 | /* |
| 1812 | * No networks are enabled; short-circuit request so |
| 1813 | * we don't wait timeout seconds before transitioning |
| 1814 | * to INACTIVE state. |
| 1815 | */ |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1816 | wpa_dbg(wpa_s, MSG_DEBUG, "Short-circuit new scan request " |
| 1817 | "since there are no enabled networks"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1818 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 1819 | return; |
| 1820 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1821 | |
| 1822 | wpa_s->scan_for_connection = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1823 | wpa_supplicant_req_scan(wpa_s, timeout_sec, timeout_usec); |
| 1824 | } |
| 1825 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1826 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1827 | int wpa_supplicant_connect(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1828 | struct wpa_bss *selected, |
| 1829 | struct wpa_ssid *ssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1830 | { |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1831 | if ((eap_is_wps_pbc_enrollee(&ssid->eap) && |
| 1832 | wpas_wps_partner_link_overlap_detect(wpa_s)) || |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1833 | wpas_wps_scan_pbc_overlap(wpa_s, selected, ssid)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1834 | wpa_msg(wpa_s, MSG_INFO, WPS_EVENT_OVERLAP |
| 1835 | "PBC session overlap"); |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1836 | wpas_notify_wps_event_pbc_overlap(wpa_s); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1837 | wpa_s->wps_overlap = true; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1838 | #ifdef CONFIG_P2P |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1839 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT || |
| 1840 | wpa_s->p2p_in_provisioning) { |
| 1841 | eloop_register_timeout(0, 0, wpas_p2p_pbc_overlap_cb, |
| 1842 | wpa_s, NULL); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1843 | return -1; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 1844 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1845 | #endif /* CONFIG_P2P */ |
| 1846 | |
| 1847 | #ifdef CONFIG_WPS |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1848 | wpas_wps_pbc_overlap(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1849 | wpas_wps_cancel(wpa_s); |
| 1850 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1851 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1854 | wpa_msg(wpa_s, MSG_DEBUG, |
| 1855 | "Considering connect request: reassociate: %d selected: " |
| 1856 | MACSTR " bssid: " MACSTR " pending: " MACSTR |
| 1857 | " wpa_state: %s ssid=%p current_ssid=%p", |
| 1858 | wpa_s->reassociate, MAC2STR(selected->bssid), |
| 1859 | MAC2STR(wpa_s->bssid), MAC2STR(wpa_s->pending_bssid), |
| 1860 | wpa_supplicant_state_txt(wpa_s->wpa_state), |
| 1861 | ssid, wpa_s->current_ssid); |
| 1862 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1863 | /* |
| 1864 | * Do not trigger new association unless the BSSID has changed or if |
| 1865 | * reassociation is requested. If we are in process of associating with |
| 1866 | * the selected BSSID, do not trigger new attempt. |
| 1867 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1868 | if (wpa_s->reassociate || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1869 | (os_memcmp(selected->bssid, wpa_s->bssid, ETH_ALEN) != 0 && |
| 1870 | ((wpa_s->wpa_state != WPA_ASSOCIATING && |
| 1871 | wpa_s->wpa_state != WPA_AUTHENTICATING) || |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1872 | (!is_zero_ether_addr(wpa_s->pending_bssid) && |
| 1873 | os_memcmp(selected->bssid, wpa_s->pending_bssid, ETH_ALEN) != |
| 1874 | 0) || |
| 1875 | (is_zero_ether_addr(wpa_s->pending_bssid) && |
| 1876 | ssid != wpa_s->current_ssid)))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1877 | if (wpa_supplicant_scard_init(wpa_s, ssid)) { |
| 1878 | wpa_supplicant_req_new_scan(wpa_s, 10, 0); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1879 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1880 | } |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1881 | wpa_msg(wpa_s, MSG_DEBUG, "Request association with " MACSTR, |
| 1882 | MAC2STR(selected->bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1883 | wpa_supplicant_associate(wpa_s, selected, ssid); |
| 1884 | } else { |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 1885 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated or trying to " |
| 1886 | "connect with the selected AP"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1887 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1888 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 1889 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1890 | } |
| 1891 | |
| 1892 | |
| 1893 | static struct wpa_ssid * |
| 1894 | wpa_supplicant_pick_new_network(struct wpa_supplicant *wpa_s) |
| 1895 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1896 | size_t prio; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1897 | struct wpa_ssid *ssid; |
| 1898 | |
| 1899 | for (prio = 0; prio < wpa_s->conf->num_prio; prio++) { |
| 1900 | for (ssid = wpa_s->conf->pssid[prio]; ssid; ssid = ssid->pnext) |
| 1901 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1902 | if (wpas_network_disabled(wpa_s, ssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1903 | continue; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1904 | #ifndef CONFIG_IBSS_RSN |
| 1905 | if (ssid->mode == WPAS_MODE_IBSS && |
| 1906 | !(ssid->key_mgmt & (WPA_KEY_MGMT_NONE | |
| 1907 | WPA_KEY_MGMT_WPA_NONE))) { |
| 1908 | wpa_msg(wpa_s, MSG_INFO, |
| 1909 | "IBSS RSN not supported in the build - cannot use the profile for SSID '%s'", |
| 1910 | wpa_ssid_txt(ssid->ssid, |
| 1911 | ssid->ssid_len)); |
| 1912 | continue; |
| 1913 | } |
| 1914 | #endif /* !CONFIG_IBSS_RSN */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 1915 | if (ssid->mode == WPAS_MODE_IBSS || |
| 1916 | ssid->mode == WPAS_MODE_AP || |
| 1917 | ssid->mode == WPAS_MODE_MESH) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1918 | return ssid; |
| 1919 | } |
| 1920 | } |
| 1921 | return NULL; |
| 1922 | } |
| 1923 | |
| 1924 | |
| 1925 | /* TODO: move the rsn_preauth_scan_result*() to be called from notify.c based |
| 1926 | * on BSS added and BSS changed events */ |
| 1927 | static void wpa_supplicant_rsn_preauth_scan_results( |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1928 | struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1929 | { |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1930 | struct wpa_bss *bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1931 | |
| 1932 | if (rsn_preauth_scan_results(wpa_s->wpa) < 0) |
| 1933 | return; |
| 1934 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1935 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1936 | const u8 *ssid, *rsn; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1937 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1938 | ssid = wpa_bss_get_ie(bss, WLAN_EID_SSID); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1939 | if (ssid == NULL) |
| 1940 | continue; |
| 1941 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1942 | rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1943 | if (rsn == NULL) |
| 1944 | continue; |
| 1945 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1946 | rsn_preauth_scan_result(wpa_s->wpa, bss->bssid, ssid, rsn); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | } |
| 1950 | |
| 1951 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1952 | #ifndef CONFIG_NO_ROAMING |
| 1953 | |
| 1954 | static int wpas_get_snr_signal_info(u32 frequency, int avg_signal, int noise) |
| 1955 | { |
| 1956 | if (noise == WPA_INVALID_NOISE) |
| 1957 | noise = IS_5GHZ(frequency) ? DEFAULT_NOISE_FLOOR_5GHZ : |
| 1958 | DEFAULT_NOISE_FLOOR_2GHZ; |
| 1959 | return avg_signal - noise; |
| 1960 | } |
| 1961 | |
| 1962 | |
| 1963 | static unsigned int |
| 1964 | wpas_get_est_throughput_from_bss_snr(const struct wpa_supplicant *wpa_s, |
| 1965 | const struct wpa_bss *bss, int snr) |
| 1966 | { |
| 1967 | int rate = wpa_bss_get_max_rate(bss); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1968 | const u8 *ies = wpa_bss_ie_ptr(bss); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1969 | size_t ie_len = bss->ie_len ? bss->ie_len : bss->beacon_ie_len; |
| 1970 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1971 | return wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, bss->freq); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1972 | } |
| 1973 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1974 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1975 | int wpa_supplicant_need_to_roam_within_ess(struct wpa_supplicant *wpa_s, |
| 1976 | struct wpa_bss *current_bss, |
| 1977 | struct wpa_bss *selected) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1978 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1979 | int min_diff, diff; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 1980 | int to_5ghz, to_6ghz; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1981 | int cur_level; |
| 1982 | unsigned int cur_est, sel_est; |
| 1983 | struct wpa_signal_info si; |
| 1984 | int cur_snr = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1985 | int ret = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1986 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1987 | wpa_dbg(wpa_s, MSG_DEBUG, "Considering within-ESS reassociation"); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1988 | wpa_dbg(wpa_s, MSG_DEBUG, "Current BSS: " MACSTR |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1989 | " freq=%d level=%d snr=%d est_throughput=%u", |
| 1990 | MAC2STR(current_bss->bssid), |
| 1991 | current_bss->freq, current_bss->level, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1992 | current_bss->snr, current_bss->est_throughput); |
| 1993 | wpa_dbg(wpa_s, MSG_DEBUG, "Selected BSS: " MACSTR |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1994 | " freq=%d level=%d snr=%d est_throughput=%u", |
| 1995 | MAC2STR(selected->bssid), selected->freq, selected->level, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1996 | selected->snr, selected->est_throughput); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1997 | |
| 1998 | if (wpa_s->current_ssid->bssid_set && |
| 1999 | os_memcmp(selected->bssid, wpa_s->current_ssid->bssid, ETH_ALEN) == |
| 2000 | 0) { |
| 2001 | wpa_dbg(wpa_s, MSG_DEBUG, "Allow reassociation - selected BSS " |
| 2002 | "has preferred BSSID"); |
| 2003 | return 1; |
| 2004 | } |
| 2005 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2006 | cur_level = current_bss->level; |
| 2007 | cur_est = current_bss->est_throughput; |
| 2008 | sel_est = selected->est_throughput; |
| 2009 | |
| 2010 | /* |
| 2011 | * Try to poll the signal from the driver since this will allow to get |
| 2012 | * more accurate values. In some cases, there can be big differences |
| 2013 | * between the RSSI of the Probe Response frames of the AP we are |
| 2014 | * associated with and the Beacon frames we hear from the same AP after |
| 2015 | * association. This can happen, e.g., when there are two antennas that |
| 2016 | * hear the AP very differently. If the driver chooses to hear the |
| 2017 | * Probe Response frames during the scan on the "bad" antenna because |
| 2018 | * it wants to save power, but knows to choose the other antenna after |
| 2019 | * association, we will hear our AP with a low RSSI as part of the |
| 2020 | * scan even when we can hear it decently on the other antenna. To cope |
| 2021 | * with this, ask the driver to teach us how it hears the AP. Also, the |
| 2022 | * scan results may be a bit old, since we can very quickly get fresh |
| 2023 | * information about our currently associated AP. |
| 2024 | */ |
| 2025 | if (wpa_drv_signal_poll(wpa_s, &si) == 0 && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2026 | (si.data.avg_beacon_signal || si.data.avg_signal)) { |
| 2027 | cur_level = si.data.avg_beacon_signal ? |
| 2028 | si.data.avg_beacon_signal : si.data.avg_signal; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2029 | cur_snr = wpas_get_snr_signal_info(si.frequency, cur_level, |
| 2030 | si.current_noise); |
| 2031 | |
| 2032 | cur_est = wpas_get_est_throughput_from_bss_snr(wpa_s, |
| 2033 | current_bss, |
| 2034 | cur_snr); |
| 2035 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2036 | "Using signal poll values for the current BSS: level=%d snr=%d est_throughput=%u", |
| 2037 | cur_level, cur_snr, cur_est); |
| 2038 | } |
| 2039 | |
| 2040 | if (sel_est > cur_est + 5000) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2041 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2042 | "Allow reassociation - selected BSS has better estimated throughput"); |
| 2043 | return 1; |
| 2044 | } |
| 2045 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2046 | to_5ghz = selected->freq > 4000 && current_bss->freq < 4000; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2047 | to_6ghz = is_6ghz_freq(selected->freq) && |
| 2048 | !is_6ghz_freq(current_bss->freq); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 2049 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2050 | if (cur_level < 0 && |
| 2051 | cur_level > selected->level + to_5ghz * 2 + to_6ghz * 2 && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2052 | sel_est < cur_est * 1.2) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2053 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip roam - Current BSS has better " |
| 2054 | "signal level"); |
| 2055 | return 0; |
| 2056 | } |
| 2057 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2058 | if (cur_est > sel_est + 5000) { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2059 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2060 | "Skip roam - Current BSS has better estimated throughput"); |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2061 | return 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2062 | } |
| 2063 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2064 | if (cur_snr > GREAT_SNR) { |
| 2065 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2066 | "Skip roam - Current BSS has good SNR (%u > %u)", |
| 2067 | cur_snr, GREAT_SNR); |
| 2068 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2069 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2070 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2071 | if (cur_level < -85) /* ..-86 dBm */ |
| 2072 | min_diff = 1; |
| 2073 | else if (cur_level < -80) /* -85..-81 dBm */ |
| 2074 | min_diff = 2; |
| 2075 | else if (cur_level < -75) /* -80..-76 dBm */ |
| 2076 | min_diff = 3; |
| 2077 | else if (cur_level < -70) /* -75..-71 dBm */ |
| 2078 | min_diff = 4; |
| 2079 | else if (cur_level < 0) /* -70..-1 dBm */ |
| 2080 | min_diff = 5; |
| 2081 | else /* unspecified units (not in dBm) */ |
| 2082 | min_diff = 2; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2083 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2084 | if (cur_est > sel_est * 1.5) |
| 2085 | min_diff += 10; |
| 2086 | else if (cur_est > sel_est * 1.2) |
| 2087 | min_diff += 5; |
| 2088 | else if (cur_est > sel_est * 1.1) |
| 2089 | min_diff += 2; |
| 2090 | else if (cur_est > sel_est) |
| 2091 | min_diff++; |
| 2092 | else if (sel_est > cur_est * 1.5) |
| 2093 | min_diff -= 10; |
| 2094 | else if (sel_est > cur_est * 1.2) |
| 2095 | min_diff -= 5; |
| 2096 | else if (sel_est > cur_est * 1.1) |
| 2097 | min_diff -= 2; |
| 2098 | else if (sel_est > cur_est) |
| 2099 | min_diff--; |
| 2100 | |
| 2101 | if (to_5ghz) |
| 2102 | min_diff -= 2; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2103 | if (to_6ghz) |
| 2104 | min_diff -= 2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2105 | diff = selected->level - cur_level; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 2106 | if (diff < min_diff) { |
| 2107 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2108 | "Skip roam - too small difference in signal level (%d < %d)", |
| 2109 | diff, min_diff); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2110 | ret = 0; |
| 2111 | } else { |
| 2112 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2113 | "Allow reassociation due to difference in signal level (%d >= %d)", |
| 2114 | diff, min_diff); |
| 2115 | ret = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2116 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2117 | wpa_msg_ctrl(wpa_s, MSG_INFO, "%scur_bssid=" MACSTR |
| 2118 | " cur_freq=%d cur_level=%d cur_est=%d sel_bssid=" MACSTR |
| 2119 | " sel_freq=%d sel_level=%d sel_est=%d", |
| 2120 | ret ? WPA_EVENT_DO_ROAM : WPA_EVENT_SKIP_ROAM, |
| 2121 | MAC2STR(current_bss->bssid), |
| 2122 | current_bss->freq, cur_level, cur_est, |
| 2123 | MAC2STR(selected->bssid), |
| 2124 | selected->freq, selected->level, sel_est); |
| 2125 | return ret; |
| 2126 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2127 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2128 | #endif /* CONFIG_NO_ROAMING */ |
| 2129 | |
| 2130 | |
| 2131 | static int wpa_supplicant_need_to_roam(struct wpa_supplicant *wpa_s, |
| 2132 | struct wpa_bss *selected, |
| 2133 | struct wpa_ssid *ssid) |
| 2134 | { |
| 2135 | struct wpa_bss *current_bss = NULL; |
| 2136 | |
| 2137 | if (wpa_s->reassociate) |
| 2138 | return 1; /* explicit request to reassociate */ |
| 2139 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 2140 | return 1; /* we are not associated; continue */ |
| 2141 | if (wpa_s->current_ssid == NULL) |
| 2142 | return 1; /* unknown current SSID */ |
| 2143 | if (wpa_s->current_ssid != ssid) |
| 2144 | return 1; /* different network block */ |
| 2145 | |
| 2146 | if (wpas_driver_bss_selection(wpa_s)) |
| 2147 | return 0; /* Driver-based roaming */ |
| 2148 | |
| 2149 | if (wpa_s->current_ssid->ssid) |
| 2150 | current_bss = wpa_bss_get(wpa_s, wpa_s->bssid, |
| 2151 | wpa_s->current_ssid->ssid, |
| 2152 | wpa_s->current_ssid->ssid_len); |
| 2153 | if (!current_bss) |
| 2154 | current_bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); |
| 2155 | |
| 2156 | if (!current_bss) |
| 2157 | return 1; /* current BSS not seen in scan results */ |
| 2158 | |
| 2159 | if (current_bss == selected) |
| 2160 | return 0; |
| 2161 | |
| 2162 | if (selected->last_update_idx > current_bss->last_update_idx) |
| 2163 | return 1; /* current BSS not seen in the last scan */ |
| 2164 | |
| 2165 | #ifndef CONFIG_NO_ROAMING |
| 2166 | return wpa_supplicant_need_to_roam_within_ess(wpa_s, current_bss, |
| 2167 | selected); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2168 | #else /* CONFIG_NO_ROAMING */ |
Dmitry Shmidt | efdec2e | 2011-08-16 11:55:46 -0700 | [diff] [blame] | 2169 | return 0; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2170 | #endif /* CONFIG_NO_ROAMING */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2171 | } |
| 2172 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 2173 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2174 | /* |
| 2175 | * Return a negative value if no scan results could be fetched or if scan |
| 2176 | * results should not be shared with other virtual interfaces. |
| 2177 | * Return 0 if scan results were fetched and may be shared with other |
| 2178 | * interfaces. |
| 2179 | * Return 1 if scan results may be shared with other virtual interfaces but may |
| 2180 | * not trigger any operations. |
| 2181 | * Return 2 if the interface was removed and cannot be used. |
| 2182 | */ |
Dmitry Shmidt | f6c92c4 | 2012-01-26 12:57:43 -0800 | [diff] [blame] | 2183 | static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 2184 | union wpa_event_data *data, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2185 | int own_request, int update_only) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2186 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2187 | struct wpa_scan_results *scan_res = NULL; |
| 2188 | int ret = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2189 | int ap = 0; |
Dmitry Shmidt | 4530cfd | 2012-09-09 15:20:40 -0700 | [diff] [blame] | 2190 | #ifndef CONFIG_NO_RANDOM_POOL |
| 2191 | size_t i, num; |
| 2192 | #endif /* CONFIG_NO_RANDOM_POOL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2193 | |
| 2194 | #ifdef CONFIG_AP |
| 2195 | if (wpa_s->ap_iface) |
| 2196 | ap = 1; |
| 2197 | #endif /* CONFIG_AP */ |
| 2198 | |
| 2199 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 2200 | |
| 2201 | scan_res = wpa_supplicant_get_scan_results(wpa_s, |
| 2202 | data ? &data->scan_info : |
| 2203 | NULL, 1); |
| 2204 | if (scan_res == NULL) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2205 | if (wpa_s->conf->ap_scan == 2 || ap || |
| 2206 | wpa_s->scan_res_handler == scan_only_handler) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2207 | return -1; |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 2208 | if (!own_request) |
| 2209 | return -1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2210 | if (data && data->scan_info.external_scan) |
| 2211 | return -1; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2212 | if (wpa_s->scan_res_fail_handler) { |
| 2213 | void (*handler)(struct wpa_supplicant *wpa_s); |
| 2214 | |
| 2215 | handler = wpa_s->scan_res_fail_handler; |
| 2216 | wpa_s->scan_res_fail_handler = NULL; |
| 2217 | handler(wpa_s); |
| 2218 | } else { |
| 2219 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2220 | "Failed to get scan results - try scanning again"); |
| 2221 | wpa_supplicant_req_new_scan(wpa_s, 1, 0); |
| 2222 | } |
| 2223 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2224 | ret = -1; |
| 2225 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | #ifndef CONFIG_NO_RANDOM_POOL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2229 | num = scan_res->num; |
| 2230 | if (num > 10) |
| 2231 | num = 10; |
| 2232 | for (i = 0; i < num; i++) { |
| 2233 | u8 buf[5]; |
| 2234 | struct wpa_scan_res *res = scan_res->res[i]; |
| 2235 | buf[0] = res->bssid[5]; |
| 2236 | buf[1] = res->qual & 0xff; |
| 2237 | buf[2] = res->noise & 0xff; |
| 2238 | buf[3] = res->level & 0xff; |
| 2239 | buf[4] = res->tsf & 0xff; |
| 2240 | random_add_randomness(buf, sizeof(buf)); |
| 2241 | } |
| 2242 | #endif /* CONFIG_NO_RANDOM_POOL */ |
| 2243 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2244 | if (update_only) { |
| 2245 | ret = 1; |
| 2246 | goto scan_work_done; |
| 2247 | } |
| 2248 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2249 | if (own_request && wpa_s->scan_res_handler && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2250 | !(data && data->scan_info.external_scan)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2251 | void (*scan_res_handler)(struct wpa_supplicant *wpa_s, |
| 2252 | struct wpa_scan_results *scan_res); |
| 2253 | |
| 2254 | scan_res_handler = wpa_s->scan_res_handler; |
| 2255 | wpa_s->scan_res_handler = NULL; |
| 2256 | scan_res_handler(wpa_s, scan_res); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2257 | ret = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2258 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2261 | 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] | 2262 | wpa_s->own_scan_running, |
| 2263 | data ? data->scan_info.external_scan : 0); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2264 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2265 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running && |
| 2266 | own_request && !(data && data->scan_info.external_scan)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2267 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", |
| 2268 | wpa_s->manual_scan_id); |
| 2269 | wpa_s->manual_scan_use_id = 0; |
| 2270 | } else { |
| 2271 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
| 2272 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2273 | wpas_notify_scan_results(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2274 | |
| 2275 | wpas_notify_scan_done(wpa_s, 1); |
| 2276 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2277 | if (ap) { |
| 2278 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore scan results in AP mode"); |
| 2279 | #ifdef CONFIG_AP |
| 2280 | if (wpa_s->ap_iface->scan_cb) |
| 2281 | wpa_s->ap_iface->scan_cb(wpa_s->ap_iface); |
| 2282 | #endif /* CONFIG_AP */ |
| 2283 | goto scan_work_done; |
| 2284 | } |
| 2285 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2286 | if (data && data->scan_info.external_scan) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2287 | 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] | 2288 | wpa_scan_results_free(scan_res); |
| 2289 | return 0; |
| 2290 | } |
| 2291 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2292 | if (wnm_scan_process(wpa_s, 1) > 0) |
| 2293 | goto scan_work_done; |
| 2294 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2295 | if (sme_proc_obss_scan(wpa_s) > 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2296 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2297 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2298 | if (own_request && data && |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2299 | wpas_beacon_rep_scan_process(wpa_s, scan_res, &data->scan_info) > 0) |
| 2300 | goto scan_work_done; |
| 2301 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2302 | if ((wpa_s->conf->ap_scan == 2 && !wpas_wps_searching(wpa_s))) |
| 2303 | goto scan_work_done; |
| 2304 | |
| 2305 | if (autoscan_notify_scan(wpa_s, scan_res)) |
| 2306 | goto scan_work_done; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2307 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2308 | if (wpa_s->disconnected) { |
| 2309 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2310 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2313 | if (!wpas_driver_bss_selection(wpa_s) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2314 | bgscan_notify_scan(wpa_s, scan_res) == 1) |
| 2315 | goto scan_work_done; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2316 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2317 | wpas_wps_update_ap_info(wpa_s, scan_res); |
| 2318 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2319 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING && |
| 2320 | wpa_s->wpa_state < WPA_COMPLETED) |
| 2321 | goto scan_work_done; |
| 2322 | |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2323 | wpa_scan_results_free(scan_res); |
| 2324 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2325 | if (own_request && wpa_s->scan_work) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2326 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 2327 | wpa_s->scan_work = NULL; |
| 2328 | radio_work_done(work); |
| 2329 | } |
| 2330 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2331 | os_free(wpa_s->last_scan_freqs); |
| 2332 | wpa_s->last_scan_freqs = NULL; |
| 2333 | wpa_s->num_last_scan_freqs = 0; |
| 2334 | if (own_request && data && |
| 2335 | data->scan_info.freqs && data->scan_info.num_freqs) { |
| 2336 | wpa_s->last_scan_freqs = os_malloc(sizeof(int) * |
| 2337 | data->scan_info.num_freqs); |
| 2338 | if (wpa_s->last_scan_freqs) { |
| 2339 | os_memcpy(wpa_s->last_scan_freqs, |
| 2340 | data->scan_info.freqs, |
| 2341 | sizeof(int) * data->scan_info.num_freqs); |
| 2342 | wpa_s->num_last_scan_freqs = data->scan_info.num_freqs; |
| 2343 | } |
| 2344 | } |
| 2345 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2346 | if (wpa_s->supp_pbc_active && !wpas_wps_partner_link_scan_done(wpa_s)) |
| 2347 | return ret; |
| 2348 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2349 | return wpas_select_network_from_last_scan(wpa_s, 1, own_request); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2350 | |
| 2351 | scan_work_done: |
| 2352 | wpa_scan_results_free(scan_res); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2353 | if (own_request && wpa_s->scan_work) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2354 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 2355 | wpa_s->scan_work = NULL; |
| 2356 | radio_work_done(work); |
| 2357 | } |
| 2358 | return ret; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2362 | static int wpas_select_network_from_last_scan(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2363 | int new_scan, int own_request) |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2364 | { |
| 2365 | struct wpa_bss *selected; |
| 2366 | struct wpa_ssid *ssid = NULL; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 2367 | int time_to_reenable = wpas_reenabled_network_time(wpa_s); |
| 2368 | |
| 2369 | if (time_to_reenable > 0) { |
| 2370 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2371 | "Postpone network selection by %d seconds since all networks are disabled", |
| 2372 | time_to_reenable); |
| 2373 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
| 2374 | eloop_register_timeout(time_to_reenable, 0, |
| 2375 | wpas_network_reenabled, wpa_s, NULL); |
| 2376 | return 0; |
| 2377 | } |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2378 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 2379 | if (wpa_s->p2p_mgmt) |
| 2380 | return 0; /* no normal connection on p2p_mgmt interface */ |
| 2381 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2382 | wpa_s->owe_transition_search = 0; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2383 | selected = wpa_supplicant_pick_network(wpa_s, &ssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2384 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 2385 | #ifdef CONFIG_MESH |
| 2386 | if (wpa_s->ifmsh) { |
| 2387 | wpa_msg(wpa_s, MSG_INFO, |
| 2388 | "Avoiding join because we already joined a mesh group"); |
| 2389 | return 0; |
| 2390 | } |
| 2391 | #endif /* CONFIG_MESH */ |
| 2392 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2393 | if (selected) { |
| 2394 | int skip; |
Dmitry Shmidt | 9bce59c | 2012-09-11 15:06:38 -0700 | [diff] [blame] | 2395 | skip = !wpa_supplicant_need_to_roam(wpa_s, selected, ssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2396 | if (skip) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2397 | if (new_scan) |
| 2398 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2399 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2400 | } |
| 2401 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2402 | wpa_s->suitable_network++; |
| 2403 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2404 | if (ssid != wpa_s->current_ssid && |
| 2405 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 2406 | wpa_s->own_disconnect_req = 1; |
| 2407 | wpa_supplicant_deauthenticate( |
| 2408 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2409 | } |
| 2410 | |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2411 | if (wpa_supplicant_connect(wpa_s, selected, ssid) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2412 | wpa_dbg(wpa_s, MSG_DEBUG, "Connect failed"); |
Dmitry Shmidt | 44da025 | 2011-08-23 12:30:30 -0700 | [diff] [blame] | 2413 | return -1; |
| 2414 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2415 | wpa_s->supp_pbc_active = false; |
| 2416 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2417 | if (new_scan) |
| 2418 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2419 | /* |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2420 | * Do not allow other virtual radios to trigger operations based |
| 2421 | * on these scan results since we do not want them to start |
| 2422 | * other associations at the same time. |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2423 | */ |
| 2424 | return 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2425 | } else { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 2426 | wpa_s->no_suitable_network++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2427 | wpa_dbg(wpa_s, MSG_DEBUG, "No suitable network found"); |
| 2428 | ssid = wpa_supplicant_pick_new_network(wpa_s); |
| 2429 | if (ssid) { |
| 2430 | wpa_dbg(wpa_s, MSG_DEBUG, "Setup a new network"); |
| 2431 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2432 | if (new_scan) |
| 2433 | wpa_supplicant_rsn_preauth_scan_results(wpa_s); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2434 | } else if (own_request) { |
| 2435 | /* |
| 2436 | * No SSID found. If SCAN results are as a result of |
| 2437 | * own scan request and not due to a scan request on |
| 2438 | * another shared interface, try another scan. |
| 2439 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2440 | int timeout_sec = wpa_s->scan_interval; |
| 2441 | int timeout_usec = 0; |
| 2442 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2443 | int res; |
| 2444 | |
| 2445 | res = wpas_p2p_scan_no_go_seen(wpa_s); |
| 2446 | if (res == 2) |
| 2447 | return 2; |
| 2448 | if (res == 1) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2449 | return 0; |
| 2450 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2451 | if (wpas_p2p_retry_limit_exceeded(wpa_s)) |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 2452 | return 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2453 | |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 2454 | if (wpa_s->p2p_in_provisioning || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 2455 | wpa_s->show_group_started || |
| 2456 | wpa_s->p2p_in_invitation) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2457 | /* |
| 2458 | * Use shorter wait during P2P Provisioning |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 2459 | * state and during P2P join-a-group operation |
| 2460 | * to speed up group formation. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2461 | */ |
| 2462 | timeout_sec = 0; |
| 2463 | timeout_usec = 250000; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2464 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2465 | timeout_usec); |
| 2466 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2467 | } |
| 2468 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2469 | #ifdef CONFIG_INTERWORKING |
| 2470 | if (wpa_s->conf->auto_interworking && |
| 2471 | wpa_s->conf->interworking && |
| 2472 | wpa_s->conf->cred) { |
| 2473 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: " |
| 2474 | "start ANQP fetch since no matching " |
| 2475 | "networks found"); |
| 2476 | wpa_s->network_select = 1; |
| 2477 | wpa_s->auto_network_select = 1; |
| 2478 | interworking_start_fetch_anqp(wpa_s); |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2479 | return 1; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 2480 | } |
| 2481 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2482 | #ifdef CONFIG_WPS |
| 2483 | if (wpa_s->after_wps > 0 || wpas_wps_searching(wpa_s)) { |
| 2484 | wpa_dbg(wpa_s, MSG_DEBUG, "Use shorter wait during WPS processing"); |
| 2485 | timeout_sec = 0; |
| 2486 | timeout_usec = 500000; |
| 2487 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2488 | timeout_usec); |
| 2489 | return 0; |
| 2490 | } |
| 2491 | #endif /* CONFIG_WPS */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2492 | #ifdef CONFIG_OWE |
| 2493 | if (wpa_s->owe_transition_search) { |
| 2494 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2495 | "OWE: Use shorter wait during transition mode search"); |
| 2496 | timeout_sec = 0; |
| 2497 | timeout_usec = 500000; |
| 2498 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2499 | timeout_usec); |
| 2500 | return 0; |
| 2501 | } |
| 2502 | #endif /* CONFIG_OWE */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2503 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
| 2504 | wpa_supplicant_req_new_scan(wpa_s, timeout_sec, |
| 2505 | timeout_usec); |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 2506 | |
| 2507 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 2508 | WPA_EVENT_NETWORK_NOT_FOUND); |
Sunil Ravi | 07c1762 | 2021-01-11 12:00:53 -0800 | [diff] [blame] | 2509 | wpas_notify_network_not_found(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2510 | } |
| 2511 | } |
| 2512 | return 0; |
| 2513 | } |
| 2514 | |
| 2515 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2516 | static int wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, |
| 2517 | union wpa_event_data *data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2518 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2519 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2520 | int res; |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 2521 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2522 | res = _wpa_supplicant_event_scan_results(wpa_s, data, 1, 0); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2523 | if (res == 2) { |
| 2524 | /* |
| 2525 | * Interface may have been removed, so must not dereference |
| 2526 | * wpa_s after this. |
| 2527 | */ |
| 2528 | return 1; |
| 2529 | } |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2530 | |
| 2531 | if (res < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2532 | /* |
| 2533 | * If no scan results could be fetched, then no need to |
| 2534 | * notify those interfaces that did not actually request |
Jouni Malinen | 89ca702 | 2012-09-14 13:03:12 -0700 | [diff] [blame] | 2535 | * this scan. Similarly, if scan results started a new operation on this |
| 2536 | * interface, do not notify other interfaces to avoid concurrent |
| 2537 | * operations during a connection attempt. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2538 | */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2539 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2540 | } |
| 2541 | |
| 2542 | /* |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2543 | * Check other interfaces to see if they share the same radio. If |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2544 | * so, they get updated with this same scan info. |
| 2545 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 2546 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 2547 | radio_list) { |
| 2548 | if (ifs != wpa_s) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2549 | wpa_printf(MSG_DEBUG, "%s: Updating scan results from " |
| 2550 | "sibling", ifs->ifname); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2551 | res = _wpa_supplicant_event_scan_results(ifs, data, 0, |
| 2552 | res > 0); |
| 2553 | if (res < 0) |
| 2554 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2555 | } |
| 2556 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2557 | |
| 2558 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 2562 | |
| 2563 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2564 | int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
| 2565 | { |
| 2566 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 2567 | return -1; |
| 2568 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2569 | struct os_reltime now; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2570 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 2571 | wpa_s->ignore_post_flush_scan_res = 0; |
| 2572 | |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 2573 | if (wpa_s->last_scan_res_used == 0) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2574 | return -1; |
| 2575 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2576 | os_get_reltime(&now); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2577 | if (os_reltime_expired(&now, &wpa_s->last_scan, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2578 | wpa_s->conf->scan_res_valid_for_connect)) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2579 | wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); |
| 2580 | return -1; |
| 2581 | } |
| 2582 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2583 | return wpas_select_network_from_last_scan(wpa_s, 0, 1); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2584 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 2585 | } |
| 2586 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2587 | |
| 2588 | int wpa_wps_supplicant_fast_associate(struct wpa_supplicant *wpa_s) |
| 2589 | { |
| 2590 | #ifdef CONFIG_NO_SCAN_PROCESSING |
| 2591 | return -1; |
| 2592 | #else /* CONFIG_NO_SCAN_PROCESSING */ |
| 2593 | return wpas_select_network_from_last_scan(wpa_s, 1, 1); |
| 2594 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 2595 | } |
| 2596 | |
| 2597 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2598 | #ifdef CONFIG_WNM |
| 2599 | |
| 2600 | static void wnm_bss_keep_alive(void *eloop_ctx, void *sock_ctx) |
| 2601 | { |
| 2602 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 2603 | |
| 2604 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 2605 | return; |
| 2606 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2607 | if (!wpa_s->no_keep_alive) { |
| 2608 | wpa_printf(MSG_DEBUG, "WNM: Send keep-alive to AP " MACSTR, |
| 2609 | MAC2STR(wpa_s->bssid)); |
| 2610 | /* TODO: could skip this if normal data traffic has been sent */ |
| 2611 | /* TODO: Consider using some more appropriate data frame for |
| 2612 | * this */ |
| 2613 | if (wpa_s->l2) |
| 2614 | l2_packet_send(wpa_s->l2, wpa_s->bssid, 0x0800, |
| 2615 | (u8 *) "", 0); |
| 2616 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2617 | |
| 2618 | #ifdef CONFIG_SME |
| 2619 | if (wpa_s->sme.bss_max_idle_period) { |
| 2620 | unsigned int msec; |
| 2621 | msec = wpa_s->sme.bss_max_idle_period * 1024; /* times 1000 */ |
| 2622 | if (msec > 100) |
| 2623 | msec -= 100; |
| 2624 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, |
| 2625 | wnm_bss_keep_alive, wpa_s, NULL); |
| 2626 | } |
| 2627 | #endif /* CONFIG_SME */ |
| 2628 | } |
| 2629 | |
| 2630 | |
| 2631 | static void wnm_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 2632 | const u8 *ies, size_t ies_len) |
| 2633 | { |
| 2634 | struct ieee802_11_elems elems; |
| 2635 | |
| 2636 | if (ies == NULL) |
| 2637 | return; |
| 2638 | |
| 2639 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) |
| 2640 | return; |
| 2641 | |
| 2642 | #ifdef CONFIG_SME |
| 2643 | if (elems.bss_max_idle_period) { |
| 2644 | unsigned int msec; |
| 2645 | wpa_s->sme.bss_max_idle_period = |
| 2646 | WPA_GET_LE16(elems.bss_max_idle_period); |
| 2647 | wpa_printf(MSG_DEBUG, "WNM: BSS Max Idle Period: %u (* 1000 " |
| 2648 | "TU)%s", wpa_s->sme.bss_max_idle_period, |
| 2649 | (elems.bss_max_idle_period[2] & 0x01) ? |
| 2650 | " (protected keep-live required)" : ""); |
| 2651 | if (wpa_s->sme.bss_max_idle_period == 0) |
| 2652 | wpa_s->sme.bss_max_idle_period = 1; |
| 2653 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { |
| 2654 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); |
| 2655 | /* msec times 1000 */ |
| 2656 | msec = wpa_s->sme.bss_max_idle_period * 1024; |
| 2657 | if (msec > 100) |
| 2658 | msec -= 100; |
| 2659 | eloop_register_timeout(msec / 1000, msec % 1000 * 1000, |
| 2660 | wnm_bss_keep_alive, wpa_s, |
| 2661 | NULL); |
| 2662 | } |
| 2663 | } |
| 2664 | #endif /* CONFIG_SME */ |
| 2665 | } |
| 2666 | |
| 2667 | #endif /* CONFIG_WNM */ |
| 2668 | |
| 2669 | |
| 2670 | void wnm_bss_keep_alive_deinit(struct wpa_supplicant *wpa_s) |
| 2671 | { |
| 2672 | #ifdef CONFIG_WNM |
| 2673 | eloop_cancel_timeout(wnm_bss_keep_alive, wpa_s, NULL); |
| 2674 | #endif /* CONFIG_WNM */ |
| 2675 | } |
| 2676 | |
| 2677 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2678 | #ifdef CONFIG_INTERWORKING |
| 2679 | |
| 2680 | static int wpas_qos_map_set(struct wpa_supplicant *wpa_s, const u8 *qos_map, |
| 2681 | size_t len) |
| 2682 | { |
| 2683 | int res; |
| 2684 | |
| 2685 | wpa_hexdump(MSG_DEBUG, "Interworking: QoS Map Set", qos_map, len); |
| 2686 | res = wpa_drv_set_qos_map(wpa_s, qos_map, len); |
| 2687 | if (res) { |
| 2688 | wpa_printf(MSG_DEBUG, "Interworking: Failed to configure QoS Map Set to the driver"); |
| 2689 | } |
| 2690 | |
| 2691 | return res; |
| 2692 | } |
| 2693 | |
| 2694 | |
| 2695 | static void interworking_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 2696 | const u8 *ies, size_t ies_len) |
| 2697 | { |
| 2698 | struct ieee802_11_elems elems; |
| 2699 | |
| 2700 | if (ies == NULL) |
| 2701 | return; |
| 2702 | |
| 2703 | if (ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed) |
| 2704 | return; |
| 2705 | |
| 2706 | if (elems.qos_map_set) { |
| 2707 | wpas_qos_map_set(wpa_s, elems.qos_map_set, |
| 2708 | elems.qos_map_set_len); |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | #endif /* CONFIG_INTERWORKING */ |
| 2713 | |
| 2714 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2715 | static void wpa_supplicant_set_4addr_mode(struct wpa_supplicant *wpa_s) |
| 2716 | { |
| 2717 | if (wpa_s->enabled_4addr_mode) { |
| 2718 | wpa_printf(MSG_DEBUG, "4addr mode already set"); |
| 2719 | return; |
| 2720 | } |
| 2721 | |
| 2722 | if (wpa_drv_set_4addr_mode(wpa_s, 1) < 0) { |
| 2723 | wpa_msg(wpa_s, MSG_ERROR, "Failed to set 4addr mode"); |
| 2724 | goto fail; |
| 2725 | } |
| 2726 | wpa_s->enabled_4addr_mode = 1; |
| 2727 | wpa_msg(wpa_s, MSG_INFO, "Successfully set 4addr mode"); |
| 2728 | return; |
| 2729 | |
| 2730 | fail: |
| 2731 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2732 | } |
| 2733 | |
| 2734 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2735 | static void multi_ap_process_assoc_resp(struct wpa_supplicant *wpa_s, |
| 2736 | const u8 *ies, size_t ies_len) |
| 2737 | { |
| 2738 | struct ieee802_11_elems elems; |
| 2739 | const u8 *map_sub_elem, *pos; |
| 2740 | size_t len; |
| 2741 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2742 | wpa_s->multi_ap_ie = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2743 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2744 | if (!ies || |
| 2745 | ieee802_11_parse_elems(ies, ies_len, &elems, 1) == ParseFailed || |
| 2746 | !elems.multi_ap || elems.multi_ap_len < 7) |
| 2747 | return; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2748 | |
| 2749 | pos = elems.multi_ap + 4; |
| 2750 | len = elems.multi_ap_len - 4; |
| 2751 | |
| 2752 | map_sub_elem = get_ie(pos, len, MULTI_AP_SUB_ELEM_TYPE); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2753 | if (!map_sub_elem || map_sub_elem[1] < 1) |
| 2754 | return; |
| 2755 | |
| 2756 | wpa_s->multi_ap_backhaul = !!(map_sub_elem[2] & MULTI_AP_BACKHAUL_BSS); |
| 2757 | wpa_s->multi_ap_fronthaul = !!(map_sub_elem[2] & |
| 2758 | MULTI_AP_FRONTHAUL_BSS); |
| 2759 | wpa_s->multi_ap_ie = 1; |
| 2760 | } |
| 2761 | |
| 2762 | |
| 2763 | static void multi_ap_set_4addr_mode(struct wpa_supplicant *wpa_s) |
| 2764 | { |
| 2765 | if (!wpa_s->current_ssid || |
| 2766 | !wpa_s->current_ssid->multi_ap_backhaul_sta) |
| 2767 | return; |
| 2768 | |
| 2769 | if (!wpa_s->multi_ap_ie) { |
| 2770 | wpa_printf(MSG_INFO, |
| 2771 | "AP does not include valid Multi-AP element"); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2772 | goto fail; |
| 2773 | } |
| 2774 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2775 | if (!wpa_s->multi_ap_backhaul) { |
| 2776 | if (wpa_s->multi_ap_fronthaul && |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2777 | wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_WPS) { |
| 2778 | wpa_printf(MSG_INFO, |
| 2779 | "WPS active, accepting fronthaul-only BSS"); |
| 2780 | /* Don't set 4addr mode in this case, so just return */ |
| 2781 | return; |
| 2782 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2783 | wpa_printf(MSG_INFO, "AP doesn't support backhaul BSS"); |
| 2784 | goto fail; |
| 2785 | } |
| 2786 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2787 | wpa_supplicant_set_4addr_mode(wpa_s); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2788 | return; |
| 2789 | |
| 2790 | fail: |
| 2791 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 2792 | } |
| 2793 | |
| 2794 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 2795 | #ifdef CONFIG_FST |
| 2796 | static int wpas_fst_update_mbie(struct wpa_supplicant *wpa_s, |
| 2797 | const u8 *ie, size_t ie_len) |
| 2798 | { |
| 2799 | struct mb_ies_info mb_ies; |
| 2800 | |
| 2801 | if (!ie || !ie_len || !wpa_s->fst) |
| 2802 | return -ENOENT; |
| 2803 | |
| 2804 | os_memset(&mb_ies, 0, sizeof(mb_ies)); |
| 2805 | |
| 2806 | while (ie_len >= 2 && mb_ies.nof_ies < MAX_NOF_MB_IES_SUPPORTED) { |
| 2807 | size_t len; |
| 2808 | |
| 2809 | len = 2 + ie[1]; |
| 2810 | if (len > ie_len) { |
| 2811 | wpa_hexdump(MSG_DEBUG, "FST: Truncated IE found", |
| 2812 | ie, ie_len); |
| 2813 | break; |
| 2814 | } |
| 2815 | |
| 2816 | if (ie[0] == WLAN_EID_MULTI_BAND) { |
| 2817 | wpa_printf(MSG_DEBUG, "MB IE of %u bytes found", |
| 2818 | (unsigned int) len); |
| 2819 | mb_ies.ies[mb_ies.nof_ies].ie = ie + 2; |
| 2820 | mb_ies.ies[mb_ies.nof_ies].ie_len = len - 2; |
| 2821 | mb_ies.nof_ies++; |
| 2822 | } |
| 2823 | |
| 2824 | ie_len -= len; |
| 2825 | ie += len; |
| 2826 | } |
| 2827 | |
| 2828 | if (mb_ies.nof_ies > 0) { |
| 2829 | wpabuf_free(wpa_s->received_mb_ies); |
| 2830 | wpa_s->received_mb_ies = mb_ies_by_info(&mb_ies); |
| 2831 | return 0; |
| 2832 | } |
| 2833 | |
| 2834 | return -ENOENT; |
| 2835 | } |
| 2836 | #endif /* CONFIG_FST */ |
| 2837 | |
| 2838 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2839 | static int wpa_supplicant_use_own_rsne_params(struct wpa_supplicant *wpa_s, |
| 2840 | union wpa_event_data *data) |
| 2841 | { |
| 2842 | int sel; |
| 2843 | const u8 *p; |
| 2844 | int l, len; |
| 2845 | bool found = false; |
| 2846 | struct wpa_ie_data ie; |
| 2847 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 2848 | struct wpa_bss *bss = wpa_s->current_bss; |
| 2849 | int pmf; |
| 2850 | |
| 2851 | if (!ssid) |
| 2852 | return 0; |
| 2853 | |
| 2854 | p = data->assoc_info.req_ies; |
| 2855 | l = data->assoc_info.req_ies_len; |
| 2856 | |
| 2857 | while (p && l >= 2) { |
| 2858 | len = p[1] + 2; |
| 2859 | if (len > l) { |
| 2860 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 2861 | p, l); |
| 2862 | break; |
| 2863 | } |
| 2864 | if (((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 2865 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || |
| 2866 | (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 && |
| 2867 | (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) || |
| 2868 | (p[0] == WLAN_EID_RSN && p[1] >= 2))) { |
| 2869 | found = true; |
| 2870 | break; |
| 2871 | } |
| 2872 | l -= len; |
| 2873 | p += len; |
| 2874 | } |
| 2875 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2876 | if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) { |
| 2877 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, 0); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2878 | return 0; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2879 | } |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2880 | |
| 2881 | wpa_hexdump(MSG_DEBUG, |
| 2882 | "WPA: Update cipher suite selection based on IEs in driver-generated WPA/RSNE in AssocReq", |
| 2883 | p, l); |
| 2884 | |
| 2885 | /* Update proto from (Re)Association Request frame info */ |
| 2886 | wpa_s->wpa_proto = ie.proto; |
| 2887 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PROTO, wpa_s->wpa_proto); |
| 2888 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_RSN_ENABLED, |
| 2889 | !!(wpa_s->wpa_proto & |
| 2890 | (WPA_PROTO_RSN | WPA_PROTO_OSEN))); |
| 2891 | |
| 2892 | /* Update AKMP suite from (Re)Association Request frame info */ |
| 2893 | sel = ie.key_mgmt; |
| 2894 | if (ssid->key_mgmt) |
| 2895 | sel &= ssid->key_mgmt; |
| 2896 | |
| 2897 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2898 | "WPA: AP key_mgmt 0x%x network key_mgmt 0x%x; available key_mgmt 0x%x", |
| 2899 | ie.key_mgmt, ssid->key_mgmt, sel); |
| 2900 | if (ie.key_mgmt && !sel) { |
| 2901 | wpa_supplicant_deauthenticate( |
| 2902 | wpa_s, WLAN_REASON_AKMP_NOT_VALID); |
| 2903 | return -1; |
| 2904 | } |
| 2905 | |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 2906 | #ifdef CONFIG_OCV |
| 2907 | if (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) || |
| 2908 | (wpa_s->drv_flags2 & WPA_DRIVER_FLAGS2_OCV)) && ssid->ocv) |
| 2909 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_OCV, |
| 2910 | !!(ie.capabilities & WPA_CAPABILITY_OCVC)); |
| 2911 | #endif /* CONFIG_OCV */ |
| 2912 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2913 | /* |
| 2914 | * Update PMK in wpa_sm and the driver if roamed to WPA/WPA2 PSK from a |
| 2915 | * different AKM. |
| 2916 | */ |
| 2917 | if (wpa_s->key_mgmt != ie.key_mgmt && |
| 2918 | wpa_key_mgmt_wpa_psk_no_sae(ie.key_mgmt)) { |
| 2919 | if (!ssid->psk_set) { |
| 2920 | wpa_dbg(wpa_s, MSG_INFO, |
| 2921 | "No PSK available for association"); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2922 | wpas_auth_failed(wpa_s, "NO_PSK_AVAILABLE", NULL); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2923 | return -1; |
| 2924 | } |
| 2925 | |
| 2926 | wpa_sm_set_pmk(wpa_s->wpa, ssid->psk, PMK_LEN, NULL, NULL); |
| 2927 | if (wpa_s->conf->key_mgmt_offload && |
| 2928 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD) && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2929 | wpa_drv_set_key(wpa_s, -1, 0, NULL, 0, 0, NULL, 0, |
| 2930 | ssid->psk, PMK_LEN, KEY_FLAG_PMK)) |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2931 | wpa_dbg(wpa_s, MSG_ERROR, |
| 2932 | "WPA: Cannot set PMK for key management offload"); |
| 2933 | } |
| 2934 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2935 | wpa_s->key_mgmt = ie.key_mgmt; |
| 2936 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
| 2937 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using KEY_MGMT %s and proto %d", |
| 2938 | wpa_key_mgmt_txt(wpa_s->key_mgmt, wpa_s->wpa_proto), |
| 2939 | wpa_s->wpa_proto); |
| 2940 | |
| 2941 | /* Update pairwise cipher from (Re)Association Request frame info */ |
| 2942 | sel = ie.pairwise_cipher; |
| 2943 | if (ssid->pairwise_cipher) |
| 2944 | sel &= ssid->pairwise_cipher; |
| 2945 | |
| 2946 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2947 | "WPA: AP pairwise cipher 0x%x network pairwise cipher 0x%x; available pairwise cipher 0x%x", |
| 2948 | ie.pairwise_cipher, ssid->pairwise_cipher, sel); |
| 2949 | if (ie.pairwise_cipher && !sel) { |
| 2950 | wpa_supplicant_deauthenticate( |
| 2951 | wpa_s, WLAN_REASON_PAIRWISE_CIPHER_NOT_VALID); |
| 2952 | return -1; |
| 2953 | } |
| 2954 | |
| 2955 | wpa_s->pairwise_cipher = ie.pairwise_cipher; |
| 2956 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
| 2957 | wpa_s->pairwise_cipher); |
| 2958 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using PTK %s", |
| 2959 | wpa_cipher_txt(wpa_s->pairwise_cipher)); |
| 2960 | |
| 2961 | /* Update other parameters based on AP's WPA IE/RSNE, if available */ |
| 2962 | if (!bss) { |
| 2963 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 2964 | "WPA: current_bss == NULL - skip AP IE check"); |
| 2965 | return 0; |
| 2966 | } |
| 2967 | |
| 2968 | /* Update GTK and IGTK from AP's RSNE */ |
| 2969 | found = false; |
| 2970 | |
| 2971 | if (wpa_s->wpa_proto & (WPA_PROTO_RSN | WPA_PROTO_OSEN)) { |
| 2972 | const u8 *bss_rsn; |
| 2973 | |
| 2974 | bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 2975 | if (bss_rsn) { |
| 2976 | p = bss_rsn; |
| 2977 | len = 2 + bss_rsn[1]; |
| 2978 | found = true; |
| 2979 | } |
| 2980 | } else if (wpa_s->wpa_proto & WPA_PROTO_WPA) { |
| 2981 | const u8 *bss_wpa; |
| 2982 | |
| 2983 | bss_wpa = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE); |
| 2984 | if (bss_wpa) { |
| 2985 | p = bss_wpa; |
| 2986 | len = 2 + bss_wpa[1]; |
| 2987 | found = true; |
| 2988 | } |
| 2989 | } |
| 2990 | |
| 2991 | if (!found || wpa_parse_wpa_ie(p, len, &ie) < 0) |
| 2992 | return 0; |
| 2993 | |
| 2994 | pmf = wpas_get_ssid_pmf(wpa_s, ssid); |
| 2995 | if (!(ie.capabilities & WPA_CAPABILITY_MFPC) && |
| 2996 | pmf == MGMT_FRAME_PROTECTION_REQUIRED) { |
| 2997 | /* AP does not support MFP, local configuration requires it */ |
| 2998 | wpa_supplicant_deauthenticate( |
| 2999 | wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB); |
| 3000 | return -1; |
| 3001 | } |
| 3002 | if ((ie.capabilities & WPA_CAPABILITY_MFPR) && |
| 3003 | pmf == NO_MGMT_FRAME_PROTECTION) { |
| 3004 | /* AP requires MFP, local configuration disables it */ |
| 3005 | wpa_supplicant_deauthenticate( |
| 3006 | wpa_s, WLAN_REASON_INVALID_RSN_IE_CAPAB); |
| 3007 | return -1; |
| 3008 | } |
| 3009 | |
| 3010 | /* Update PMF from local configuration now that MFP validation was done |
| 3011 | * above */ |
| 3012 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MFP, pmf); |
| 3013 | |
| 3014 | /* Update GTK from AP's RSNE */ |
| 3015 | sel = ie.group_cipher; |
| 3016 | if (ssid->group_cipher) |
| 3017 | sel &= ssid->group_cipher; |
| 3018 | |
| 3019 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3020 | "WPA: AP group cipher 0x%x network group cipher 0x%x; available group cipher 0x%x", |
| 3021 | ie.group_cipher, ssid->group_cipher, sel); |
| 3022 | if (ie.group_cipher && !sel) { |
| 3023 | wpa_supplicant_deauthenticate( |
| 3024 | wpa_s, WLAN_REASON_GROUP_CIPHER_NOT_VALID); |
| 3025 | return -1; |
| 3026 | } |
| 3027 | |
| 3028 | wpa_s->group_cipher = ie.group_cipher; |
| 3029 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_GROUP, wpa_s->group_cipher); |
| 3030 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using GTK %s", |
| 3031 | wpa_cipher_txt(wpa_s->group_cipher)); |
| 3032 | |
| 3033 | /* Update IGTK from AP RSN IE */ |
| 3034 | sel = ie.mgmt_group_cipher; |
| 3035 | if (ssid->group_mgmt_cipher) |
| 3036 | sel &= ssid->group_mgmt_cipher; |
| 3037 | |
| 3038 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3039 | "WPA: AP mgmt_group_cipher 0x%x network mgmt_group_cipher 0x%x; available mgmt_group_cipher 0x%x", |
| 3040 | ie.mgmt_group_cipher, ssid->group_mgmt_cipher, sel); |
| 3041 | |
| 3042 | if (pmf == NO_MGMT_FRAME_PROTECTION || |
| 3043 | !(ie.capabilities & WPA_CAPABILITY_MFPC)) { |
| 3044 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3045 | "WPA: STA/AP is not MFP capable; AP RSNE caps 0x%x", |
| 3046 | ie.capabilities); |
| 3047 | ie.mgmt_group_cipher = 0; |
| 3048 | } |
| 3049 | |
| 3050 | if (ie.mgmt_group_cipher && !sel) { |
| 3051 | wpa_supplicant_deauthenticate( |
| 3052 | wpa_s, WLAN_REASON_CIPHER_SUITE_REJECTED); |
| 3053 | return -1; |
| 3054 | } |
| 3055 | |
| 3056 | wpa_s->mgmt_group_cipher = ie.mgmt_group_cipher; |
| 3057 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_MGMT_GROUP, |
| 3058 | wpa_s->mgmt_group_cipher); |
| 3059 | if (wpa_s->mgmt_group_cipher) |
| 3060 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: using MGMT group cipher %s", |
| 3061 | wpa_cipher_txt(wpa_s->mgmt_group_cipher)); |
| 3062 | else |
| 3063 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: not using MGMT group cipher"); |
| 3064 | |
| 3065 | return 0; |
| 3066 | } |
| 3067 | |
| 3068 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | static int wpa_supplicant_event_associnfo(struct wpa_supplicant *wpa_s, |
| 3070 | union wpa_event_data *data) |
| 3071 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3072 | int l, len, found = 0, found_x = 0, wpa_found, rsn_found; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3073 | const u8 *p; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3074 | u8 bssid[ETH_ALEN]; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3075 | bool bssid_known; |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3076 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3077 | struct wpa_ie_data ie; |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3078 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3079 | |
| 3080 | wpa_dbg(wpa_s, MSG_DEBUG, "Association info event"); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3081 | bssid_known = wpa_drv_get_bssid(wpa_s, bssid) == 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3082 | if (data->assoc_info.req_ies) |
| 3083 | wpa_hexdump(MSG_DEBUG, "req_ies", data->assoc_info.req_ies, |
| 3084 | data->assoc_info.req_ies_len); |
| 3085 | if (data->assoc_info.resp_ies) { |
| 3086 | wpa_hexdump(MSG_DEBUG, "resp_ies", data->assoc_info.resp_ies, |
| 3087 | data->assoc_info.resp_ies_len); |
| 3088 | #ifdef CONFIG_TDLS |
| 3089 | wpa_tdls_assoc_resp_ies(wpa_s->wpa, data->assoc_info.resp_ies, |
| 3090 | data->assoc_info.resp_ies_len); |
| 3091 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3092 | #ifdef CONFIG_WNM |
| 3093 | wnm_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 3094 | data->assoc_info.resp_ies_len); |
| 3095 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3096 | #ifdef CONFIG_INTERWORKING |
| 3097 | interworking_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 3098 | data->assoc_info.resp_ies_len); |
| 3099 | #endif /* CONFIG_INTERWORKING */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3100 | if (wpa_s->hw_capab == CAPAB_VHT && |
| 3101 | get_ie(data->assoc_info.resp_ies, |
| 3102 | data->assoc_info.resp_ies_len, WLAN_EID_VHT_CAP)) |
| 3103 | wpa_s->ieee80211ac = 1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3104 | |
| 3105 | multi_ap_process_assoc_resp(wpa_s, data->assoc_info.resp_ies, |
| 3106 | data->assoc_info.resp_ies_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3107 | } |
| 3108 | if (data->assoc_info.beacon_ies) |
| 3109 | wpa_hexdump(MSG_DEBUG, "beacon_ies", |
| 3110 | data->assoc_info.beacon_ies, |
| 3111 | data->assoc_info.beacon_ies_len); |
| 3112 | if (data->assoc_info.freq) |
| 3113 | wpa_dbg(wpa_s, MSG_DEBUG, "freq=%u MHz", |
| 3114 | data->assoc_info.freq); |
| 3115 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3116 | wpa_s->connection_set = 0; |
| 3117 | if (data->assoc_info.req_ies && data->assoc_info.resp_ies) { |
| 3118 | struct ieee802_11_elems req_elems, resp_elems; |
| 3119 | |
| 3120 | if (ieee802_11_parse_elems(data->assoc_info.req_ies, |
| 3121 | data->assoc_info.req_ies_len, |
| 3122 | &req_elems, 0) != ParseFailed && |
| 3123 | ieee802_11_parse_elems(data->assoc_info.resp_ies, |
| 3124 | data->assoc_info.resp_ies_len, |
| 3125 | &resp_elems, 0) != ParseFailed) { |
| 3126 | wpa_s->connection_set = 1; |
Kai Shi | 4fa8e77 | 2020-08-12 19:02:21 -0700 | [diff] [blame] | 3127 | wpa_s->connection_11b_only = supp_rates_11b_only(&req_elems) || |
| 3128 | supp_rates_11b_only(&resp_elems); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3129 | wpa_s->connection_ht = req_elems.ht_capabilities && |
| 3130 | resp_elems.ht_capabilities; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3131 | /* Do not include subset of VHT on 2.4 GHz vendor |
| 3132 | * extension in consideration for reporting VHT |
| 3133 | * association. */ |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3134 | wpa_s->connection_vht = req_elems.vht_capabilities && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3135 | resp_elems.vht_capabilities && |
| 3136 | (!data->assoc_info.freq || |
| 3137 | wpas_freq_to_band(data->assoc_info.freq) != |
| 3138 | BAND_2_4_GHZ); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3139 | wpa_s->connection_he = req_elems.he_capabilities && |
| 3140 | resp_elems.he_capabilities; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3141 | wpa_s->connection_eht = req_elems.eht_capabilities && |
| 3142 | resp_elems.eht_capabilities; |
Kai Shi | 1e98503 | 2020-01-13 16:39:49 -0800 | [diff] [blame] | 3143 | |
| 3144 | int max_nss_rx_req = get_max_nss_capability(&req_elems, 1); |
| 3145 | int max_nss_rx_resp = get_max_nss_capability(&resp_elems, 1); |
| 3146 | wpa_s->connection_max_nss_rx = (max_nss_rx_resp > max_nss_rx_req) ? |
| 3147 | max_nss_rx_req : max_nss_rx_resp; |
| 3148 | int max_nss_tx_req = get_max_nss_capability(&req_elems, 0); |
| 3149 | int max_nss_tx_resp = get_max_nss_capability(&resp_elems, 0); |
| 3150 | wpa_s->connection_max_nss_tx = (max_nss_tx_resp > max_nss_tx_req) ? |
| 3151 | max_nss_tx_req : max_nss_tx_resp; |
| 3152 | |
| 3153 | struct supported_chan_width sta_supported_chan_width = |
| 3154 | get_supported_channel_width(&req_elems); |
| 3155 | enum chan_width ap_operation_chan_width = |
| 3156 | get_operation_channel_width(&resp_elems); |
Veerendranath Jakkam | 3fba995 | 2022-07-02 03:00:08 +0530 | [diff] [blame] | 3157 | if (wpa_s->connection_vht || wpa_s->connection_he || |
| 3158 | wpa_s->connection_eht) { |
Kai Shi | 1e98503 | 2020-01-13 16:39:49 -0800 | [diff] [blame] | 3159 | wpa_s->connection_channel_bandwidth = |
| 3160 | get_sta_operation_chan_width(ap_operation_chan_width, |
| 3161 | sta_supported_chan_width); |
| 3162 | } else if (wpa_s->connection_ht) { |
| 3163 | wpa_s->connection_channel_bandwidth = (ap_operation_chan_width |
| 3164 | == CHAN_WIDTH_40) ? CHAN_WIDTH_40 : CHAN_WIDTH_20; |
| 3165 | } else { |
| 3166 | wpa_s->connection_channel_bandwidth = CHAN_WIDTH_20; |
| 3167 | } |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3168 | } |
| 3169 | } |
| 3170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3171 | p = data->assoc_info.req_ies; |
| 3172 | l = data->assoc_info.req_ies_len; |
| 3173 | |
| 3174 | /* Go through the IEs and make a copy of the WPA/RSN IE, if present. */ |
| 3175 | while (p && l >= 2) { |
| 3176 | len = p[1] + 2; |
| 3177 | if (len > l) { |
| 3178 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 3179 | p, l); |
| 3180 | break; |
| 3181 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3182 | if (!found && |
| 3183 | ((p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 3184 | (os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0)) || |
| 3185 | (p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 4 && |
| 3186 | (os_memcmp(&p[2], "\x50\x6F\x9A\x12", 4) == 0)) || |
| 3187 | (p[0] == WLAN_EID_RSN && p[1] >= 2))) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3188 | if (wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, p, len)) |
| 3189 | break; |
| 3190 | found = 1; |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3191 | wpa_find_assoc_pmkid(wpa_s, |
| 3192 | data->assoc_info.authorized); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3193 | } |
| 3194 | if (!found_x && p[0] == WLAN_EID_RSNX) { |
| 3195 | if (wpa_sm_set_assoc_rsnxe(wpa_s->wpa, p, len)) |
| 3196 | break; |
| 3197 | found_x = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3198 | } |
| 3199 | l -= len; |
| 3200 | p += len; |
| 3201 | } |
| 3202 | if (!found && data->assoc_info.req_ies) |
| 3203 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3204 | if (!found_x && data->assoc_info.req_ies) |
| 3205 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3206 | |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3207 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3208 | /* The WPA/RSN IE has been updated at this point. Since the Firmware could have roamed |
| 3209 | * to a different security type, update the current supplicant configuration to use the AKM |
| 3210 | * and pairwise suites from the assoc IE passed by the driver. |
| 3211 | */ |
| 3212 | if (wpas_driver_bss_selection(wpa_s)) { |
| 3213 | if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) { |
| 3214 | /* Check if firmware has roamed to a different security network */ |
| 3215 | if(wpa_s->key_mgmt != ie.key_mgmt) { |
| 3216 | wpa_dbg(wpa_s, MSG_DEBUG, "Update to AKM suite 0x%x from Assoc IE", |
| 3217 | ie.key_mgmt); |
| 3218 | wpa_s->key_mgmt = ie.key_mgmt; |
| 3219 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_KEY_MGMT, wpa_s->key_mgmt); |
| 3220 | |
| 3221 | if (wpa_key_mgmt_wpa_psk_no_sae(wpa_s->key_mgmt)) { |
| 3222 | /* Restore PMK as it can get overwritten if the previous |
| 3223 | * association was to 802.1X. |
| 3224 | */ |
| 3225 | if ((!(wpa_s->drv_flags & |
| 3226 | WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) && |
| 3227 | (wpa_s->current_ssid) && |
| 3228 | (wpa_s->current_ssid->psk_set)) { |
| 3229 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 3230 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get " |
| 3231 | "BSSID"); |
| 3232 | wpa_supplicant_deauthenticate( |
| 3233 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3234 | return -1; |
| 3235 | } |
| 3236 | wpa_sm_set_pmk(wpa_s->wpa, wpa_s->current_ssid->psk, |
| 3237 | PMK_LEN, NULL, bssid); |
| 3238 | } |
| 3239 | } |
| 3240 | } |
| 3241 | if(wpa_s->pairwise_cipher != ie.pairwise_cipher) { |
| 3242 | wpa_dbg(wpa_s, MSG_DEBUG, "Update to pairwise cipher suite 0x%x " |
| 3243 | "from Assoc IE", ie.pairwise_cipher); |
| 3244 | wpa_s->pairwise_cipher = ie.pairwise_cipher; |
| 3245 | wpa_sm_set_param(wpa_s->wpa, WPA_PARAM_PAIRWISE, |
| 3246 | wpa_s->pairwise_cipher); |
| 3247 | } |
| 3248 | // TODO: Notify the framework about security type change b/230766005 |
| 3249 | } |
| 3250 | } |
Winnie Chen | 4138eec | 2022-11-10 16:32:53 +0800 | [diff] [blame] | 3251 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Vinayak Yadawad | 1470908 | 2022-03-17 14:25:11 +0530 | [diff] [blame] | 3252 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3253 | #ifdef CONFIG_FILS |
| 3254 | #ifdef CONFIG_SME |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3255 | if ((wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS || |
| 3256 | wpa_s->sme.auth_alg == WPA_AUTH_ALG_FILS_SK_PFS) && |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3257 | (!data->assoc_info.resp_frame || |
| 3258 | fils_process_assoc_resp(wpa_s->wpa, |
| 3259 | data->assoc_info.resp_frame, |
| 3260 | data->assoc_info.resp_frame_len) < 0)) { |
| 3261 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); |
| 3262 | return -1; |
| 3263 | } |
| 3264 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3265 | |
| 3266 | /* Additional processing for FILS when SME is in driver */ |
| 3267 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS && |
| 3268 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
| 3269 | wpa_sm_set_reset_fils_completed(wpa_s->wpa, 1); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3270 | #endif /* CONFIG_FILS */ |
| 3271 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3272 | #ifdef CONFIG_OWE |
| 3273 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3274 | (!bssid_known || |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 3275 | owe_process_assoc_resp(wpa_s->wpa, |
| 3276 | wpa_s->valid_links ? |
| 3277 | wpa_s->ap_mld_addr : bssid, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3278 | data->assoc_info.resp_ies, |
| 3279 | data->assoc_info.resp_ies_len) < 0)) { |
| 3280 | wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_UNSPECIFIED); |
| 3281 | return -1; |
| 3282 | } |
| 3283 | #endif /* CONFIG_OWE */ |
| 3284 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3285 | #ifdef CONFIG_DPP2 |
| 3286 | wpa_sm_set_dpp_z(wpa_s->wpa, NULL); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3287 | if (DPP_VERSION > 1 && wpa_s->key_mgmt == WPA_KEY_MGMT_DPP && |
| 3288 | wpa_s->dpp_pfs) { |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 3289 | struct ieee802_11_elems elems; |
| 3290 | |
| 3291 | if (ieee802_11_parse_elems(data->assoc_info.resp_ies, |
| 3292 | data->assoc_info.resp_ies_len, |
| 3293 | &elems, 0) == ParseFailed || |
| 3294 | !elems.owe_dh) |
| 3295 | goto no_pfs; |
| 3296 | if (dpp_pfs_process(wpa_s->dpp_pfs, elems.owe_dh, |
| 3297 | elems.owe_dh_len) < 0) { |
| 3298 | wpa_supplicant_deauthenticate(wpa_s, |
| 3299 | WLAN_REASON_UNSPECIFIED); |
| 3300 | return -1; |
| 3301 | } |
| 3302 | |
| 3303 | wpa_sm_set_dpp_z(wpa_s->wpa, wpa_s->dpp_pfs->secret); |
| 3304 | } |
| 3305 | no_pfs: |
| 3306 | #endif /* CONFIG_DPP2 */ |
| 3307 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3308 | #ifdef CONFIG_IEEE80211R |
| 3309 | #ifdef CONFIG_SME |
| 3310 | if (wpa_s->sme.auth_alg == WPA_AUTH_ALG_FT) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3311 | if (!bssid_known || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3312 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, |
| 3313 | data->assoc_info.resp_ies, |
| 3314 | data->assoc_info.resp_ies_len, |
| 3315 | bssid) < 0) { |
| 3316 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
| 3317 | "Reassociation Response failed"); |
| 3318 | wpa_supplicant_deauthenticate( |
| 3319 | wpa_s, WLAN_REASON_INVALID_IE); |
| 3320 | return -1; |
| 3321 | } |
| 3322 | } |
| 3323 | |
| 3324 | p = data->assoc_info.resp_ies; |
| 3325 | l = data->assoc_info.resp_ies_len; |
| 3326 | |
| 3327 | #ifdef CONFIG_WPS_STRICT |
| 3328 | if (p && wpa_s->current_ssid && |
| 3329 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
| 3330 | struct wpabuf *wps; |
| 3331 | wps = ieee802_11_vendor_ie_concat(p, l, WPS_IE_VENDOR_TYPE); |
| 3332 | if (wps == NULL) { |
| 3333 | wpa_msg(wpa_s, MSG_INFO, "WPS-STRICT: AP did not " |
| 3334 | "include WPS IE in (Re)Association Response"); |
| 3335 | return -1; |
| 3336 | } |
| 3337 | |
| 3338 | if (wps_validate_assoc_resp(wps) < 0) { |
| 3339 | wpabuf_free(wps); |
| 3340 | wpa_supplicant_deauthenticate( |
| 3341 | wpa_s, WLAN_REASON_INVALID_IE); |
| 3342 | return -1; |
| 3343 | } |
| 3344 | wpabuf_free(wps); |
| 3345 | } |
| 3346 | #endif /* CONFIG_WPS_STRICT */ |
| 3347 | |
| 3348 | /* Go through the IEs and make a copy of the MDIE, if present. */ |
| 3349 | while (p && l >= 2) { |
| 3350 | len = p[1] + 2; |
| 3351 | if (len > l) { |
| 3352 | wpa_hexdump(MSG_DEBUG, "Truncated IE in assoc_info", |
| 3353 | p, l); |
| 3354 | break; |
| 3355 | } |
| 3356 | if (p[0] == WLAN_EID_MOBILITY_DOMAIN && |
| 3357 | p[1] >= MOBILITY_DOMAIN_ID_LEN) { |
| 3358 | wpa_s->sme.ft_used = 1; |
| 3359 | os_memcpy(wpa_s->sme.mobility_domain, p + 2, |
| 3360 | MOBILITY_DOMAIN_ID_LEN); |
| 3361 | break; |
| 3362 | } |
| 3363 | l -= len; |
| 3364 | p += len; |
| 3365 | } |
| 3366 | #endif /* CONFIG_SME */ |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3367 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 3368 | if (((wpa_s->key_mgmt == WPA_KEY_MGMT_FT_PSK) || |
| 3369 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X) || |
| 3370 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_SAE) || |
| 3371 | (wpa_s->key_mgmt == WPA_KEY_MGMT_FT_IEEE8021X_SHA384)) && |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3372 | wpa_ft_is_completed(wpa_s->wpa)) { |
| 3373 | return 0; |
| 3374 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3375 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3376 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3377 | /* Process FT when SME is in the driver */ |
| 3378 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 3379 | wpa_ft_is_completed(wpa_s->wpa)) { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3380 | if (!bssid_known || |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 3381 | wpa_ft_validate_reassoc_resp(wpa_s->wpa, |
| 3382 | data->assoc_info.resp_ies, |
| 3383 | data->assoc_info.resp_ies_len, |
| 3384 | bssid) < 0) { |
| 3385 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Validation of " |
| 3386 | "Reassociation Response failed"); |
| 3387 | wpa_supplicant_deauthenticate( |
| 3388 | wpa_s, WLAN_REASON_INVALID_IE); |
| 3389 | return -1; |
| 3390 | } |
| 3391 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Reassociation Response done"); |
| 3392 | } |
| 3393 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3394 | wpa_sm_set_ft_params(wpa_s->wpa, data->assoc_info.resp_ies, |
| 3395 | data->assoc_info.resp_ies_len); |
| 3396 | #endif /* CONFIG_IEEE80211R */ |
| 3397 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3398 | if (bssid_known) |
| 3399 | wpas_handle_assoc_resp_mscs(wpa_s, bssid, |
| 3400 | data->assoc_info.resp_ies, |
| 3401 | data->assoc_info.resp_ies_len); |
| 3402 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3403 | /* WPA/RSN IE from Beacon/ProbeResp */ |
| 3404 | p = data->assoc_info.beacon_ies; |
| 3405 | l = data->assoc_info.beacon_ies_len; |
| 3406 | |
| 3407 | /* Go through the IEs and make a copy of the WPA/RSN IEs, if present. |
| 3408 | */ |
| 3409 | wpa_found = rsn_found = 0; |
| 3410 | while (p && l >= 2) { |
| 3411 | len = p[1] + 2; |
| 3412 | if (len > l) { |
| 3413 | wpa_hexdump(MSG_DEBUG, "Truncated IE in beacon_ies", |
| 3414 | p, l); |
| 3415 | break; |
| 3416 | } |
| 3417 | if (!wpa_found && |
| 3418 | p[0] == WLAN_EID_VENDOR_SPECIFIC && p[1] >= 6 && |
| 3419 | os_memcmp(&p[2], "\x00\x50\xF2\x01\x01\x00", 6) == 0) { |
| 3420 | wpa_found = 1; |
| 3421 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, p, len); |
| 3422 | } |
| 3423 | |
| 3424 | if (!rsn_found && |
| 3425 | p[0] == WLAN_EID_RSN && p[1] >= 2) { |
| 3426 | rsn_found = 1; |
| 3427 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, p, len); |
| 3428 | } |
| 3429 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3430 | if (p[0] == WLAN_EID_RSNX && p[1] >= 1) |
| 3431 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, p, len); |
| 3432 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3433 | l -= len; |
| 3434 | p += len; |
| 3435 | } |
| 3436 | |
| 3437 | if (!wpa_found && data->assoc_info.beacon_ies) |
| 3438 | wpa_sm_set_ap_wpa_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3439 | if (!rsn_found && data->assoc_info.beacon_ies) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3440 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, NULL, 0); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3441 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, NULL, 0); |
| 3442 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3443 | if (wpa_found || rsn_found) |
| 3444 | wpa_s->ap_ies_from_associnfo = 1; |
| 3445 | |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 3446 | if (wpa_s->assoc_freq && data->assoc_info.freq && |
| 3447 | wpa_s->assoc_freq != data->assoc_info.freq) { |
| 3448 | wpa_printf(MSG_DEBUG, "Operating frequency changed from " |
| 3449 | "%u to %u MHz", |
| 3450 | wpa_s->assoc_freq, data->assoc_info.freq); |
| 3451 | wpa_supplicant_update_scan_results(wpa_s); |
| 3452 | } |
| 3453 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3454 | wpa_s->assoc_freq = data->assoc_info.freq; |
| 3455 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3456 | wpas_handle_assoc_resp_qos_mgmt(wpa_s, data->assoc_info.resp_ies, |
| 3457 | data->assoc_info.resp_ies_len); |
| 3458 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | return 0; |
| 3460 | } |
| 3461 | |
| 3462 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3463 | static int wpa_supplicant_assoc_update_ie(struct wpa_supplicant *wpa_s) |
| 3464 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3465 | const u8 *bss_wpa = NULL, *bss_rsn = NULL, *bss_rsnx = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3466 | |
| 3467 | if (!wpa_s->current_bss || !wpa_s->current_ssid) |
| 3468 | return -1; |
| 3469 | |
| 3470 | if (!wpa_key_mgmt_wpa_any(wpa_s->current_ssid->key_mgmt)) |
| 3471 | return 0; |
| 3472 | |
| 3473 | bss_wpa = wpa_bss_get_vendor_ie(wpa_s->current_bss, |
| 3474 | WPA_IE_VENDOR_TYPE); |
| 3475 | 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] | 3476 | 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] | 3477 | |
| 3478 | if (wpa_sm_set_ap_wpa_ie(wpa_s->wpa, bss_wpa, |
| 3479 | bss_wpa ? 2 + bss_wpa[1] : 0) || |
| 3480 | wpa_sm_set_ap_rsn_ie(wpa_s->wpa, bss_rsn, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3481 | bss_rsn ? 2 + bss_rsn[1] : 0) || |
| 3482 | wpa_sm_set_ap_rsnxe(wpa_s->wpa, bss_rsnx, |
| 3483 | bss_rsnx ? 2 + bss_rsnx[1] : 0)) |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3484 | return -1; |
| 3485 | |
| 3486 | return 0; |
| 3487 | } |
| 3488 | |
| 3489 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3490 | static void wpas_fst_update_mb_assoc(struct wpa_supplicant *wpa_s, |
| 3491 | union wpa_event_data *data) |
| 3492 | { |
| 3493 | #ifdef CONFIG_FST |
| 3494 | struct assoc_info *ai = data ? &data->assoc_info : NULL; |
| 3495 | struct wpa_bss *bss = wpa_s->current_bss; |
| 3496 | const u8 *ieprb, *iebcn; |
| 3497 | |
| 3498 | wpabuf_free(wpa_s->received_mb_ies); |
| 3499 | wpa_s->received_mb_ies = NULL; |
| 3500 | |
| 3501 | if (ai && |
| 3502 | !wpas_fst_update_mbie(wpa_s, ai->resp_ies, ai->resp_ies_len)) { |
| 3503 | wpa_printf(MSG_DEBUG, |
| 3504 | "FST: MB IEs updated from Association Response frame"); |
| 3505 | return; |
| 3506 | } |
| 3507 | |
| 3508 | if (ai && |
| 3509 | !wpas_fst_update_mbie(wpa_s, ai->beacon_ies, ai->beacon_ies_len)) { |
| 3510 | wpa_printf(MSG_DEBUG, |
| 3511 | "FST: MB IEs updated from association event Beacon IEs"); |
| 3512 | return; |
| 3513 | } |
| 3514 | |
| 3515 | if (!bss) |
| 3516 | return; |
| 3517 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3518 | ieprb = wpa_bss_ie_ptr(bss); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3519 | iebcn = ieprb + bss->ie_len; |
| 3520 | |
| 3521 | if (!wpas_fst_update_mbie(wpa_s, ieprb, bss->ie_len)) |
| 3522 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss IE"); |
| 3523 | else if (!wpas_fst_update_mbie(wpa_s, iebcn, bss->beacon_ie_len)) |
| 3524 | wpa_printf(MSG_DEBUG, "FST: MB IEs updated from bss beacon IE"); |
| 3525 | #endif /* CONFIG_FST */ |
| 3526 | } |
| 3527 | |
| 3528 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3529 | static int wpa_drv_get_mlo_info(struct wpa_supplicant *wpa_s) |
| 3530 | { |
| 3531 | struct driver_sta_mlo_info mlo; |
| 3532 | int i; |
| 3533 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3534 | os_memset(&mlo, 0, sizeof(mlo)); |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3535 | if (wpas_drv_get_sta_mlo_info(wpa_s, &mlo)) { |
| 3536 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO link info"); |
| 3537 | wpa_supplicant_deauthenticate(wpa_s, |
| 3538 | WLAN_REASON_DEAUTH_LEAVING); |
| 3539 | return -1; |
| 3540 | } |
| 3541 | |
| 3542 | if (wpa_s->valid_links == mlo.valid_links) { |
| 3543 | bool match = true; |
| 3544 | |
| 3545 | if (!mlo.valid_links) |
| 3546 | return 0; |
| 3547 | |
| 3548 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 3549 | if (!(mlo.valid_links & BIT(i))) |
| 3550 | continue; |
| 3551 | |
| 3552 | if (os_memcmp(wpa_s->links[i].addr, mlo.links[i].addr, |
| 3553 | ETH_ALEN) != 0 || |
| 3554 | os_memcmp(wpa_s->links[i].bssid, mlo.links[i].bssid, |
| 3555 | ETH_ALEN) != 0) { |
| 3556 | match = false; |
| 3557 | break; |
| 3558 | } |
| 3559 | } |
| 3560 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3561 | if (match && wpa_s->mlo_assoc_link_id == mlo.assoc_link_id && |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3562 | os_memcmp(wpa_s->ap_mld_addr, mlo.ap_mld_addr, |
| 3563 | ETH_ALEN) == 0) |
| 3564 | return 0; |
| 3565 | } |
| 3566 | |
| 3567 | wpa_s->valid_links = mlo.valid_links; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3568 | wpa_s->mlo_assoc_link_id = mlo.assoc_link_id; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3569 | os_memcpy(wpa_s->ap_mld_addr, mlo.ap_mld_addr, ETH_ALEN); |
| 3570 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 3571 | if (!(wpa_s->valid_links & BIT(i))) |
| 3572 | continue; |
| 3573 | |
| 3574 | os_memcpy(wpa_s->links[i].addr, mlo.links[i].addr, ETH_ALEN); |
| 3575 | os_memcpy(wpa_s->links[i].bssid, mlo.links[i].bssid, ETH_ALEN); |
| 3576 | wpa_s->links[i].freq = mlo.links[i].freq; |
| 3577 | wpa_supplicant_update_link_bss(wpa_s, i, mlo.links[i].bssid); |
| 3578 | } |
| 3579 | |
| 3580 | return 0; |
| 3581 | } |
| 3582 | |
| 3583 | |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3584 | static int wpa_sm_set_ml_info(struct wpa_supplicant *wpa_s) |
| 3585 | { |
| 3586 | struct driver_sta_mlo_info drv_mlo; |
| 3587 | struct wpa_sm_mlo wpa_mlo; |
| 3588 | const u8 *bss_rsn = NULL, *bss_rsnx = NULL; |
| 3589 | int i; |
| 3590 | |
| 3591 | os_memset(&drv_mlo, 0, sizeof(drv_mlo)); |
| 3592 | if (wpas_drv_get_sta_mlo_info(wpa_s, &drv_mlo)) { |
| 3593 | wpa_dbg(wpa_s, MSG_INFO, "Failed to get MLO link info"); |
| 3594 | return -1; |
| 3595 | } |
| 3596 | |
| 3597 | os_memset(&wpa_mlo, 0, sizeof(wpa_mlo)); |
| 3598 | if (!drv_mlo.valid_links) |
| 3599 | goto out; |
| 3600 | |
| 3601 | os_memcpy(wpa_mlo.ap_mld_addr, drv_mlo.ap_mld_addr, ETH_ALEN); |
| 3602 | wpa_mlo.assoc_link_id = drv_mlo.assoc_link_id; |
| 3603 | wpa_mlo.valid_links = drv_mlo.valid_links; |
| 3604 | wpa_mlo.req_links = drv_mlo.req_links; |
| 3605 | |
| 3606 | for (i = 0; i < MAX_NUM_MLD_LINKS; i++) { |
| 3607 | struct wpa_bss *bss; |
| 3608 | |
| 3609 | if (!(drv_mlo.req_links & BIT(i))) |
| 3610 | continue; |
| 3611 | |
| 3612 | bss = wpa_supplicant_get_new_bss(wpa_s, drv_mlo.links[i].bssid); |
| 3613 | if (!bss) { |
| 3614 | wpa_supplicant_update_scan_results(wpa_s); |
| 3615 | bss = wpa_supplicant_get_new_bss( |
| 3616 | wpa_s, drv_mlo.links[i].bssid); |
| 3617 | } |
| 3618 | |
| 3619 | if (!bss) { |
| 3620 | wpa_dbg(wpa_s, MSG_INFO, |
| 3621 | "Failed to get MLO link %d BSS", i); |
| 3622 | return -1; |
| 3623 | } |
| 3624 | |
| 3625 | bss_rsn = wpa_bss_get_ie(bss, WLAN_EID_RSN); |
| 3626 | bss_rsnx = wpa_bss_get_ie(bss, WLAN_EID_RSNX); |
| 3627 | |
| 3628 | wpa_mlo.links[i].ap_rsne = bss_rsn ? (u8 *) bss_rsn : NULL; |
| 3629 | wpa_mlo.links[i].ap_rsne_len = bss_rsn ? 2 + bss_rsn[1] : 0; |
| 3630 | wpa_mlo.links[i].ap_rsnxe = bss_rsnx ? (u8 *) bss_rsnx : NULL; |
| 3631 | wpa_mlo.links[i].ap_rsnxe_len = bss_rsnx ? 2 + bss_rsnx[1] : 0; |
| 3632 | |
| 3633 | os_memcpy(wpa_mlo.links[i].bssid, drv_mlo.links[i].bssid, |
| 3634 | ETH_ALEN); |
| 3635 | os_memcpy(wpa_mlo.links[i].addr, drv_mlo.links[i].addr, |
| 3636 | ETH_ALEN); |
| 3637 | } |
| 3638 | |
| 3639 | out: |
| 3640 | return wpa_sm_set_mlo_params(wpa_s->wpa, &wpa_mlo); |
| 3641 | } |
| 3642 | |
| 3643 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3644 | static void wpa_supplicant_event_assoc(struct wpa_supplicant *wpa_s, |
| 3645 | union wpa_event_data *data) |
| 3646 | { |
| 3647 | u8 bssid[ETH_ALEN]; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 3648 | int ft_completed, already_authorized; |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 3649 | int new_bss = 0; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3650 | #if defined(CONFIG_FILS) || defined(CONFIG_MBO) |
| 3651 | struct wpa_bss *bss; |
| 3652 | #endif /* CONFIG_FILS || CONFIG_MBO */ |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3653 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3654 | struct wpa_ie_data ie; |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3655 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3656 | |
| 3657 | #ifdef CONFIG_AP |
| 3658 | if (wpa_s->ap_iface) { |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 3659 | if (!data) |
| 3660 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3661 | hostapd_notif_assoc(wpa_s->ap_iface->bss[0], |
| 3662 | data->assoc_info.addr, |
| 3663 | data->assoc_info.req_ies, |
| 3664 | data->assoc_info.req_ies_len, |
| 3665 | data->assoc_info.reassoc); |
| 3666 | return; |
| 3667 | } |
| 3668 | #endif /* CONFIG_AP */ |
| 3669 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 3670 | eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3671 | wpa_s->own_reconnect_req = 0; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 3672 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3673 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3674 | if (!(wpa_sm_parse_own_wpa_ie(wpa_s->wpa, &ie) < 0)) { |
| 3675 | struct wpa_ft_ies parse; |
| 3676 | /* Check for FT reassociation is done by the driver */ |
| 3677 | #ifdef CONFIG_IEEE80211R |
| 3678 | int use_sha384 = wpa_key_mgmt_sha384(wpa_s->wpa->key_mgmt); |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 3679 | 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] | 3680 | if (wpa_ft_parse_ies(data->assoc_info.resp_ies, |
| 3681 | data->assoc_info.resp_ies_len, &parse, use_sha384) < 0) { |
| 3682 | wpa_printf(MSG_DEBUG, "Failed to parse FT IEs"); |
| 3683 | return; |
| 3684 | } |
| 3685 | if (parse.rsn_pmkid != NULL) { |
| 3686 | wpa_set_ft_completed(wpa_s->wpa); |
| 3687 | wpa_dbg(wpa_s, MSG_DEBUG, "Assume FT reassoc completed by the driver"); |
| 3688 | } |
| 3689 | } |
| 3690 | #endif /* CONFIG_IEEE80211R */ |
| 3691 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3692 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3693 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3694 | ft_completed = wpa_ft_is_completed(wpa_s->wpa); |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3695 | |
| 3696 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 3697 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID"); |
| 3698 | wpa_supplicant_deauthenticate( |
| 3699 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3700 | return; |
| 3701 | } |
| 3702 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 3703 | if (wpa_drv_get_mlo_info(wpa_s) < 0) { |
| 3704 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get MLO connection info"); |
| 3705 | wpa_supplicant_deauthenticate(wpa_s, |
| 3706 | WLAN_REASON_DEAUTH_LEAVING); |
| 3707 | return; |
| 3708 | } |
| 3709 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 3710 | if (ft_completed && |
| 3711 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION)) { |
| 3712 | wpa_msg(wpa_s, MSG_INFO, "Attempt to roam to " MACSTR, |
| 3713 | MAC2STR(bssid)); |
| 3714 | if (!wpa_supplicant_update_current_bss(wpa_s, bssid)) { |
| 3715 | wpa_printf(MSG_ERROR, |
| 3716 | "Can't find target AP's information!"); |
| 3717 | return; |
| 3718 | } |
| 3719 | wpa_supplicant_assoc_update_ie(wpa_s); |
| 3720 | } |
| 3721 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3722 | if (data && wpa_supplicant_event_associnfo(wpa_s, data) < 0) |
| 3723 | return; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3724 | /* |
| 3725 | * FILS authentication can share the same mechanism to mark the |
| 3726 | * connection fully authenticated, so set ft_completed also based on |
| 3727 | * FILS result. |
| 3728 | */ |
| 3729 | if (!ft_completed) |
| 3730 | ft_completed = wpa_fils_is_completed(wpa_s->wpa); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3731 | |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3732 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 3733 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
| 3734 | /* |
| 3735 | * For driver based roaming, insert PSK during |
| 3736 | * the initial association |
| 3737 | */ |
| 3738 | if (is_zero_ether_addr(wpa_s->bssid) && |
| 3739 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
| 3740 | /* |
| 3741 | * In case the driver wants to handle re-assocs, |
| 3742 | * pass it down the PMK. |
| 3743 | */ |
| 3744 | wpa_dbg(wpa_s, MSG_DEBUG, "Pass the PMK to the driver"); |
| 3745 | wpa_sm_install_pmk(wpa_s->wpa); |
| 3746 | } |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3747 | } |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 3748 | #endif |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3749 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3750 | wpa_supplicant_set_state(wpa_s, WPA_ASSOCIATED); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3751 | if (os_memcmp(bssid, wpa_s->bssid, ETH_ALEN) != 0) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3752 | if (os_reltime_initialized(&wpa_s->session_start)) { |
| 3753 | os_reltime_age(&wpa_s->session_start, |
| 3754 | &wpa_s->session_length); |
| 3755 | wpa_s->session_start.sec = 0; |
| 3756 | wpa_s->session_start.usec = 0; |
| 3757 | wpas_notify_session_length(wpa_s); |
| 3758 | } else { |
| 3759 | wpas_notify_auth_changed(wpa_s); |
| 3760 | os_get_reltime(&wpa_s->session_start); |
| 3761 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3762 | wpa_dbg(wpa_s, MSG_DEBUG, "Associated to a new BSS: BSSID=" |
| 3763 | MACSTR, MAC2STR(bssid)); |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 3764 | new_bss = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3765 | random_add_randomness(bssid, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3766 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
| 3767 | os_memset(wpa_s->pending_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3768 | wpas_notify_bssid_changed(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3769 | |
| 3770 | if (wpa_supplicant_dynamic_keys(wpa_s) && !ft_completed) { |
| 3771 | wpa_clear_keys(wpa_s, bssid); |
| 3772 | } |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3773 | if (wpa_supplicant_select_config(wpa_s, data) < 0) { |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3774 | wpa_supplicant_deauthenticate( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3775 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3776 | return; |
| 3777 | } |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 3778 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3779 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3780 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 3781 | data && wpa_supplicant_use_own_rsne_params(wpa_s, data) < 0) |
| 3782 | return; |
| 3783 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3784 | multi_ap_set_4addr_mode(wpa_s); |
| 3785 | |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 3786 | if (wpa_s->conf->ap_scan == 1 && |
| 3787 | wpa_s->drv_flags & WPA_DRIVER_FLAGS_BSS_SELECTION) { |
Amarnath Hullur Subramanyam | a82c83c | 2015-09-18 06:57:06 -0700 | [diff] [blame] | 3788 | if (wpa_supplicant_assoc_update_ie(wpa_s) < 0 && new_bss) |
| 3789 | wpa_msg(wpa_s, MSG_WARNING, |
| 3790 | "WPA/RSN IEs not updated"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3791 | } |
| 3792 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3793 | wpas_fst_update_mb_assoc(wpa_s, data); |
| 3794 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3795 | #ifdef CONFIG_SME |
| 3796 | os_memcpy(wpa_s->sme.prev_bssid, bssid, ETH_ALEN); |
| 3797 | wpa_s->sme.prev_bssid_set = 1; |
Dmitry Shmidt | 0c08fdc | 2014-06-20 10:16:40 -0700 | [diff] [blame] | 3798 | wpa_s->sme.last_unprot_disconnect.sec = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3799 | #endif /* CONFIG_SME */ |
| 3800 | |
| 3801 | wpa_msg(wpa_s, MSG_INFO, "Associated with " MACSTR, MAC2STR(bssid)); |
| 3802 | if (wpa_s->current_ssid) { |
| 3803 | /* When using scanning (ap_scan=1), SIM PC/SC interface can be |
| 3804 | * initialized before association, but for other modes, |
| 3805 | * initialize PC/SC here, if the current configuration needs |
| 3806 | * smartcard or SIM/USIM. */ |
| 3807 | wpa_supplicant_scard_init(wpa_s, wpa_s->current_ssid); |
| 3808 | } |
| 3809 | wpa_sm_notify_assoc(wpa_s->wpa, bssid); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3810 | |
| 3811 | if (wpa_sm_set_ml_info(wpa_s)) { |
| 3812 | wpa_dbg(wpa_s, MSG_INFO, |
| 3813 | "Failed to set MLO connection info to wpa_sm"); |
| 3814 | wpa_supplicant_deauthenticate(wpa_s, |
| 3815 | WLAN_REASON_DEAUTH_LEAVING); |
| 3816 | return; |
| 3817 | } |
| 3818 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3819 | if (wpa_s->l2) |
| 3820 | l2_packet_notify_auth_start(wpa_s->l2); |
| 3821 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 3822 | already_authorized = data && data->assoc_info.authorized; |
| 3823 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3824 | /* |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3825 | * 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] | 3826 | * of the SUCCESS state and eapSuccess cleared. Without this, EAPOL PAE |
| 3827 | * state machine may transit to AUTHENTICATING state based on obsolete |
| 3828 | * eapSuccess and then trigger BE_AUTH to SUCCESS and PAE to |
| 3829 | * AUTHENTICATED without ever giving chance to EAP state machine to |
| 3830 | * reset the state. |
| 3831 | */ |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 3832 | if (!ft_completed && !already_authorized) { |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3833 | eapol_sm_notify_portEnabled(wpa_s->eapol, false); |
| 3834 | eapol_sm_notify_portValid(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3836 | if (wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 3837 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP || |
| 3838 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE || ft_completed || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3839 | already_authorized || wpa_s->drv_authorized_port) |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3840 | eapol_sm_notify_eap_success(wpa_s->eapol, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3841 | /* 802.1X::portControl = Auto */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3842 | eapol_sm_notify_portEnabled(wpa_s->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3843 | wpa_s->eapol_received = 0; |
| 3844 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 3845 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE || |
| 3846 | (wpa_s->current_ssid && |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3847 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS)) { |
Dmitry Shmidt | 09f57ba | 2014-06-10 16:07:13 -0700 | [diff] [blame] | 3848 | if (wpa_s->current_ssid && |
| 3849 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE && |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3850 | (wpa_s->drv_flags & |
| 3851 | WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { |
| 3852 | /* |
| 3853 | * Set the key after having received joined-IBSS event |
| 3854 | * from the driver. |
| 3855 | */ |
| 3856 | wpa_supplicant_set_wpa_none_key(wpa_s, |
| 3857 | wpa_s->current_ssid); |
| 3858 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3859 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 3860 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 3861 | } else if (!ft_completed) { |
| 3862 | /* Timeout for receiving the first EAPOL packet */ |
| 3863 | wpa_supplicant_req_auth_timeout(wpa_s, 10, 0); |
| 3864 | } |
| 3865 | wpa_supplicant_cancel_scan(wpa_s); |
| 3866 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 3867 | if (ft_completed) { |
| 3868 | /* |
| 3869 | * FT protocol completed - make sure EAPOL state machine ends |
| 3870 | * up in authenticated. |
| 3871 | */ |
| 3872 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 3873 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3874 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
| 3875 | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 3876 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK) && |
| 3877 | wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt)) { |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 3878 | if (already_authorized) { |
| 3879 | /* |
| 3880 | * We are done; the driver will take care of RSN 4-way |
| 3881 | * handshake. |
| 3882 | */ |
| 3883 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 3884 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
| 3885 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
| 3886 | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
| 3887 | } else { |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3888 | /* Update port, WPA_COMPLETED state from the |
| 3889 | * EVENT_PORT_AUTHORIZED handler when the driver is done |
| 3890 | * with the 4-way handshake. |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 3891 | */ |
Sunil Ravi | 167279a | 2023-05-31 01:12:34 +0000 | [diff] [blame^] | 3892 | wpa_supplicant_set_state(wpa_s, WPA_4WAY_HANDSHAKE); |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3893 | wpa_msg(wpa_s, MSG_INFO, |
| 3894 | "ASSOC INFO: wait for driver port authorized indication"); |
Vinayak Yadawad | f49b169 | 2022-06-16 16:39:46 +0530 | [diff] [blame] | 3895 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3896 | } else if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3897 | wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) { |
| 3898 | /* |
| 3899 | * The driver will take care of RSN 4-way handshake, so we need |
| 3900 | * to allow EAPOL supplicant to complete its work without |
| 3901 | * waiting for WPA supplicant. |
| 3902 | */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 3903 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3904 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3905 | #if defined(CONFIG_DRIVER_NL80211_BRCM) || defined(CONFIG_DRIVER_NL80211_SYNA) |
Mir Ali | eaaf04e | 2021-06-07 12:17:29 +0530 | [diff] [blame] | 3906 | if (ft_completed && wpa_key_mgmt_ft(wpa_s->key_mgmt)) { |
| 3907 | if (wpa_drv_get_bssid(wpa_s, bssid) < 0) { |
| 3908 | wpa_dbg(wpa_s, MSG_ERROR, "Failed to get BSSID, key_mgmt: 0x%0x", |
| 3909 | wpa_s->key_mgmt); |
| 3910 | wpa_supplicant_deauthenticate( |
| 3911 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3912 | return; |
| 3913 | } |
| 3914 | os_memcpy(wpa_s->bssid, bssid, ETH_ALEN); |
| 3915 | wpa_s->assoc_freq = data->assoc_info.freq; |
| 3916 | wpa_sm_notify_brcm_ft_reassoc(wpa_s->wpa, bssid); |
| 3917 | } |
Andy Kuo | aba17c1 | 2022-04-14 16:05:31 +0800 | [diff] [blame] | 3918 | #endif /* CONFIG_DRIVER_NL80211_BRCM || CONFIG_DRIVER_NL80211_SYNA */ |
| 3919 | |
Jouni Malinen | a05074c | 2012-12-21 21:35:35 +0200 | [diff] [blame] | 3920 | wpa_s->last_eapol_matches_bssid = 0; |
| 3921 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3922 | #ifdef CONFIG_TESTING_OPTIONS |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3923 | if (wpa_s->rsne_override_eapol) { |
| 3924 | wpa_printf(MSG_DEBUG, |
| 3925 | "TESTING: RSNE EAPOL-Key msg 2/4 override"); |
| 3926 | wpa_sm_set_assoc_wpa_ie(wpa_s->wpa, |
| 3927 | wpabuf_head(wpa_s->rsne_override_eapol), |
| 3928 | wpabuf_len(wpa_s->rsne_override_eapol)); |
| 3929 | } |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 3930 | if (wpa_s->rsnxe_override_eapol) { |
| 3931 | wpa_printf(MSG_DEBUG, |
| 3932 | "TESTING: RSNXE EAPOL-Key msg 2/4 override"); |
| 3933 | wpa_sm_set_assoc_rsnxe(wpa_s->wpa, |
| 3934 | wpabuf_head(wpa_s->rsnxe_override_eapol), |
| 3935 | wpabuf_len(wpa_s->rsnxe_override_eapol)); |
| 3936 | } |
| 3937 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3938 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3939 | if (wpa_s->pending_eapol_rx) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3940 | struct os_reltime now, age; |
| 3941 | os_get_reltime(&now); |
| 3942 | os_reltime_sub(&now, &wpa_s->pending_eapol_rx_time, &age); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3943 | if (age.sec == 0 && age.usec < 200000 && |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3944 | os_memcmp(wpa_s->pending_eapol_rx_src, |
| 3945 | wpa_s->valid_links ? wpa_s->ap_mld_addr : bssid, |
| 3946 | ETH_ALEN) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3947 | wpa_dbg(wpa_s, MSG_DEBUG, "Process pending EAPOL " |
| 3948 | "frame that was received just before " |
| 3949 | "association notification"); |
| 3950 | wpa_supplicant_rx_eapol( |
| 3951 | wpa_s, wpa_s->pending_eapol_rx_src, |
| 3952 | wpabuf_head(wpa_s->pending_eapol_rx), |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 3953 | wpabuf_len(wpa_s->pending_eapol_rx), |
| 3954 | wpa_s->pending_eapol_encrypted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3955 | } |
| 3956 | wpabuf_free(wpa_s->pending_eapol_rx); |
| 3957 | wpa_s->pending_eapol_rx = NULL; |
| 3958 | } |
| 3959 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3960 | #ifdef CONFIG_WEP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3961 | if ((wpa_s->key_mgmt == WPA_KEY_MGMT_NONE || |
| 3962 | wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) && |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 3963 | wpa_s->current_ssid && |
| 3964 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SET_KEYS_AFTER_ASSOC_DONE)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3965 | /* Set static WEP keys again */ |
| 3966 | wpa_set_wep_keys(wpa_s, wpa_s->current_ssid); |
| 3967 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3968 | #endif /* CONFIG_WEP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3969 | |
| 3970 | #ifdef CONFIG_IBSS_RSN |
| 3971 | if (wpa_s->current_ssid && |
| 3972 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && |
| 3973 | wpa_s->key_mgmt != WPA_KEY_MGMT_NONE && |
| 3974 | wpa_s->key_mgmt != WPA_KEY_MGMT_WPA_NONE && |
| 3975 | wpa_s->ibss_rsn == NULL) { |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 3976 | 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] | 3977 | if (!wpa_s->ibss_rsn) { |
| 3978 | wpa_msg(wpa_s, MSG_INFO, "Failed to init IBSS RSN"); |
| 3979 | wpa_supplicant_deauthenticate( |
| 3980 | wpa_s, WLAN_REASON_DEAUTH_LEAVING); |
| 3981 | return; |
| 3982 | } |
| 3983 | |
| 3984 | ibss_rsn_set_psk(wpa_s->ibss_rsn, wpa_s->current_ssid->psk); |
| 3985 | } |
| 3986 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 3987 | |
| 3988 | wpas_wps_notify_assoc(wpa_s, bssid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3989 | |
| 3990 | if (data) { |
| 3991 | wmm_ac_notify_assoc(wpa_s, data->assoc_info.resp_ies, |
| 3992 | data->assoc_info.resp_ies_len, |
| 3993 | &data->assoc_info.wmm_params); |
| 3994 | |
| 3995 | if (wpa_s->reassoc_same_bss) |
| 3996 | wmm_ac_restore_tspecs(wpa_s); |
| 3997 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3998 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3999 | #if defined(CONFIG_FILS) || defined(CONFIG_MBO) |
| 4000 | bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 4001 | #endif /* CONFIG_FILS || CONFIG_MBO */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4002 | #ifdef CONFIG_FILS |
| 4003 | if (wpa_key_mgmt_fils(wpa_s->key_mgmt)) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4004 | const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss); |
| 4005 | |
| 4006 | if (fils_cache_id) |
| 4007 | wpa_sm_set_fils_cache_id(wpa_s->wpa, fils_cache_id); |
| 4008 | } |
| 4009 | #endif /* CONFIG_FILS */ |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4010 | |
| 4011 | #ifdef CONFIG_MBO |
| 4012 | wpas_mbo_check_pmf(wpa_s, bss, wpa_s->current_ssid); |
| 4013 | #endif /* CONFIG_MBO */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4014 | |
| 4015 | #ifdef CONFIG_DPP2 |
| 4016 | wpa_s->dpp_pfs_fallback = 0; |
| 4017 | #endif /* CONFIG_DPP2 */ |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4018 | |
| 4019 | if (wpa_s->current_ssid && wpa_s->current_ssid->enable_4addr_mode) |
| 4020 | wpa_supplicant_set_4addr_mode(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
| 4023 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4024 | static int disconnect_reason_recoverable(u16 reason_code) |
| 4025 | { |
| 4026 | return reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY || |
| 4027 | reason_code == WLAN_REASON_CLASS2_FRAME_FROM_NONAUTH_STA || |
| 4028 | reason_code == WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA; |
| 4029 | } |
| 4030 | |
| 4031 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4032 | static void wpa_supplicant_event_disassoc(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4033 | u16 reason_code, |
| 4034 | int locally_generated) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4035 | { |
| 4036 | const u8 *bssid; |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 4037 | |
| 4038 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 4039 | /* |
| 4040 | * At least Host AP driver and a Prism3 card seemed to be |
| 4041 | * generating streams of disconnected events when configuring |
| 4042 | * IBSS for WPA-None. Ignore them for now. |
| 4043 | */ |
| 4044 | return; |
| 4045 | } |
| 4046 | |
| 4047 | bssid = wpa_s->bssid; |
| 4048 | if (is_zero_ether_addr(bssid)) |
| 4049 | bssid = wpa_s->pending_bssid; |
| 4050 | |
| 4051 | if (!is_zero_ether_addr(bssid) || |
| 4052 | wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 4053 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_DISCONNECTED "bssid=" MACSTR |
| 4054 | " reason=%d%s", |
| 4055 | MAC2STR(bssid), reason_code, |
| 4056 | locally_generated ? " locally_generated=1" : ""); |
| 4057 | } |
| 4058 | } |
| 4059 | |
| 4060 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4061 | static int could_be_psk_mismatch(struct wpa_supplicant *wpa_s, u16 reason_code, |
| 4062 | int locally_generated) |
| 4063 | { |
| 4064 | if (wpa_s->wpa_state != WPA_4WAY_HANDSHAKE || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4065 | !wpa_s->new_connection || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4066 | !wpa_key_mgmt_wpa_psk(wpa_s->key_mgmt) || |
| 4067 | wpa_key_mgmt_sae(wpa_s->key_mgmt)) |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 4068 | return 0; /* Not in initial 4-way handshake with PSK */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4069 | |
| 4070 | /* |
| 4071 | * It looks like connection was lost while trying to go through PSK |
| 4072 | * 4-way handshake. Filter out known disconnection cases that are caused |
| 4073 | * by something else than PSK mismatch to avoid confusing reports. |
| 4074 | */ |
| 4075 | |
| 4076 | if (locally_generated) { |
| 4077 | if (reason_code == WLAN_REASON_IE_IN_4WAY_DIFFERS) |
| 4078 | return 0; |
| 4079 | } |
| 4080 | |
| 4081 | return 1; |
| 4082 | } |
| 4083 | |
| 4084 | |
Jouni Malinen | 2b89da8 | 2012-08-31 22:04:41 +0300 | [diff] [blame] | 4085 | static void wpa_supplicant_event_disassoc_finish(struct wpa_supplicant *wpa_s, |
| 4086 | u16 reason_code, |
| 4087 | int locally_generated) |
| 4088 | { |
| 4089 | const u8 *bssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4090 | int authenticating; |
| 4091 | u8 prev_pending_bssid[ETH_ALEN]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4092 | struct wpa_bss *fast_reconnect = NULL; |
| 4093 | struct wpa_ssid *fast_reconnect_ssid = NULL; |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 4094 | struct wpa_ssid *last_ssid; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4095 | struct wpa_bss *curr = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4096 | |
| 4097 | authenticating = wpa_s->wpa_state == WPA_AUTHENTICATING; |
| 4098 | os_memcpy(prev_pending_bssid, wpa_s->pending_bssid, ETH_ALEN); |
| 4099 | |
| 4100 | if (wpa_s->key_mgmt == WPA_KEY_MGMT_WPA_NONE) { |
| 4101 | /* |
| 4102 | * At least Host AP driver and a Prism3 card seemed to be |
| 4103 | * generating streams of disconnected events when configuring |
| 4104 | * IBSS for WPA-None. Ignore them for now. |
| 4105 | */ |
| 4106 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - ignore in " |
| 4107 | "IBSS/WPA-None mode"); |
| 4108 | return; |
| 4109 | } |
| 4110 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4111 | if (!wpa_s->disconnected && wpa_s->wpa_state >= WPA_AUTHENTICATING && |
| 4112 | reason_code == WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY && |
| 4113 | locally_generated) |
| 4114 | /* |
| 4115 | * Remove the inactive AP (which is probably out of range) from |
| 4116 | * the BSS list after marking disassociation. In particular |
| 4117 | * mac80211-based drivers use the |
| 4118 | * WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY reason code in |
| 4119 | * locally generated disconnection events for cases where the |
| 4120 | * AP does not reply anymore. |
| 4121 | */ |
| 4122 | curr = wpa_s->current_bss; |
| 4123 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 4124 | if (could_be_psk_mismatch(wpa_s, reason_code, locally_generated)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4125 | wpa_msg(wpa_s, MSG_INFO, "WPA: 4-Way Handshake failed - " |
| 4126 | "pre-shared key may be incorrect"); |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4127 | if (wpas_p2p_4way_hs_failed(wpa_s) > 0) |
| 4128 | return; /* P2P group removed */ |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4129 | wpas_auth_failed(wpa_s, "WRONG_KEY", prev_pending_bssid); |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 4130 | wpas_notify_psk_mismatch(wpa_s); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4131 | #ifdef CONFIG_DPP2 |
| 4132 | wpas_dpp_send_conn_status_result(wpa_s, |
| 4133 | DPP_STATUS_AUTH_FAILURE); |
| 4134 | #endif /* CONFIG_DPP2 */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4135 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 4136 | if (!wpa_s->disconnected && |
| 4137 | (!wpa_s->auto_reconnect_disabled || |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4138 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 4139 | wpas_wps_searching(wpa_s) || |
| 4140 | wpas_wps_reenable_networks_pending(wpa_s))) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4141 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect enabled: try to " |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4142 | "reconnect (wps=%d/%d wpa_state=%d)", |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4143 | wpa_s->key_mgmt == WPA_KEY_MGMT_WPS, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4144 | wpas_wps_searching(wpa_s), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4145 | wpa_s->wpa_state); |
| 4146 | if (wpa_s->wpa_state == WPA_COMPLETED && |
| 4147 | wpa_s->current_ssid && |
| 4148 | wpa_s->current_ssid->mode == WPAS_MODE_INFRA && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4149 | (wpa_s->own_reconnect_req || |
| 4150 | (!locally_generated && |
| 4151 | disconnect_reason_recoverable(reason_code)))) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4152 | /* |
| 4153 | * It looks like the AP has dropped association with |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4154 | * us, but could allow us to get back in. This is also |
| 4155 | * triggered for cases where local reconnection request |
| 4156 | * is used to force reassociation with the same BSS. |
| 4157 | * Try to reconnect to the same BSS without a full scan |
| 4158 | * to save time for some common cases. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4159 | */ |
| 4160 | fast_reconnect = wpa_s->current_bss; |
| 4161 | fast_reconnect_ssid = wpa_s->current_ssid; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4162 | } else if (wpa_s->wpa_state >= WPA_ASSOCIATING) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4163 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4164 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4165 | wpa_dbg(wpa_s, MSG_DEBUG, "Do not request new " |
| 4166 | "immediate scan"); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4167 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4168 | } else { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4169 | wpa_dbg(wpa_s, MSG_DEBUG, "Auto connect disabled: do not " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4170 | "try to re-connect"); |
| 4171 | wpa_s->reassociate = 0; |
| 4172 | wpa_s->disconnected = 1; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4173 | if (!wpa_s->pno) |
| 4174 | wpa_supplicant_cancel_sched_scan(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4175 | } |
| 4176 | bssid = wpa_s->bssid; |
| 4177 | if (is_zero_ether_addr(bssid)) |
| 4178 | bssid = wpa_s->pending_bssid; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4179 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) |
| 4180 | wpas_connection_failed(wpa_s, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4181 | wpa_sm_notify_disassoc(wpa_s->wpa); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4182 | ptksa_cache_flush(wpa_s->ptksa, wpa_s->bssid, WPA_CIPHER_NONE); |
| 4183 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4184 | if (locally_generated) |
| 4185 | wpa_s->disconnect_reason = -reason_code; |
| 4186 | else |
| 4187 | wpa_s->disconnect_reason = reason_code; |
| 4188 | wpas_notify_disconnect_reason(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4189 | if (wpa_supplicant_dynamic_keys(wpa_s)) { |
| 4190 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnect event - remove keys"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4191 | wpa_clear_keys(wpa_s, wpa_s->bssid); |
| 4192 | } |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 4193 | last_ssid = wpa_s->current_ssid; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4194 | wpa_supplicant_mark_disassoc(wpa_s); |
| 4195 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4196 | if (curr) |
| 4197 | wpa_bss_remove(wpa_s, curr, "Connection to AP lost"); |
| 4198 | |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 4199 | if (authenticating && (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4200 | sme_disassoc_while_authenticating(wpa_s, prev_pending_bssid); |
Jouni Malinen | f8a26a8 | 2012-09-01 17:20:27 +0300 | [diff] [blame] | 4201 | wpa_s->current_ssid = last_ssid; |
| 4202 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4203 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4204 | if (fast_reconnect && |
| 4205 | !wpas_network_disabled(wpa_s, fast_reconnect_ssid) && |
| 4206 | !disallowed_bssid(wpa_s, fast_reconnect->bssid) && |
| 4207 | !disallowed_ssid(wpa_s, fast_reconnect->ssid, |
| 4208 | fast_reconnect->ssid_len) && |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4209 | !wpas_temp_disabled(wpa_s, fast_reconnect_ssid) && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4210 | !wpa_is_bss_tmp_disallowed(wpa_s, fast_reconnect)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4211 | #ifndef CONFIG_NO_SCAN_PROCESSING |
| 4212 | wpa_dbg(wpa_s, MSG_DEBUG, "Try to reconnect to the same BSS"); |
| 4213 | if (wpa_supplicant_connect(wpa_s, fast_reconnect, |
| 4214 | fast_reconnect_ssid) < 0) { |
| 4215 | /* Recover through full scan */ |
| 4216 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
| 4217 | } |
| 4218 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4219 | } else if (fast_reconnect) { |
| 4220 | /* |
| 4221 | * Could not reconnect to the same BSS due to network being |
| 4222 | * disabled. Use a new scan to match the alternative behavior |
| 4223 | * above, i.e., to continue automatic reconnection attempt in a |
| 4224 | * way that enforces disabled network rules. |
| 4225 | */ |
| 4226 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4227 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4228 | } |
| 4229 | |
| 4230 | |
| 4231 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4232 | 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] | 4233 | { |
| 4234 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 4235 | |
| 4236 | if (!wpa_s->pending_mic_error_report) |
| 4237 | return; |
| 4238 | |
| 4239 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Sending pending MIC error report"); |
| 4240 | wpa_sm_key_request(wpa_s->wpa, 1, wpa_s->pending_mic_error_pairwise); |
| 4241 | wpa_s->pending_mic_error_report = 0; |
| 4242 | } |
| 4243 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 4244 | |
| 4245 | |
| 4246 | static void |
| 4247 | wpa_supplicant_event_michael_mic_failure(struct wpa_supplicant *wpa_s, |
| 4248 | union wpa_event_data *data) |
| 4249 | { |
| 4250 | int pairwise; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4251 | struct os_reltime t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4252 | |
| 4253 | wpa_msg(wpa_s, MSG_WARNING, "Michael MIC failure detected"); |
| 4254 | pairwise = (data && data->michael_mic_failure.unicast); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4255 | os_get_reltime(&t); |
| 4256 | if ((wpa_s->last_michael_mic_error.sec && |
| 4257 | !os_reltime_expired(&t, &wpa_s->last_michael_mic_error, 60)) || |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4258 | wpa_s->pending_mic_error_report) { |
| 4259 | if (wpa_s->pending_mic_error_report) { |
| 4260 | /* |
| 4261 | * Send the pending MIC error report immediately since |
| 4262 | * we are going to start countermeasures and AP better |
| 4263 | * do the same. |
| 4264 | */ |
| 4265 | wpa_sm_key_request(wpa_s->wpa, 1, |
| 4266 | wpa_s->pending_mic_error_pairwise); |
| 4267 | } |
| 4268 | |
| 4269 | /* Send the new MIC error report immediately since we are going |
| 4270 | * to start countermeasures and AP better do the same. |
| 4271 | */ |
| 4272 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 4273 | |
| 4274 | /* initialize countermeasures */ |
| 4275 | wpa_s->countermeasures = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4276 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4277 | wpa_bssid_ignore_add(wpa_s, wpa_s->bssid); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4278 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4279 | wpa_msg(wpa_s, MSG_WARNING, "TKIP countermeasures started"); |
| 4280 | |
| 4281 | /* |
| 4282 | * Need to wait for completion of request frame. We do not get |
| 4283 | * any callback for the message completion, so just wait a |
| 4284 | * short while and hope for the best. */ |
| 4285 | os_sleep(0, 10000); |
| 4286 | |
| 4287 | wpa_drv_set_countermeasures(wpa_s, 1); |
| 4288 | wpa_supplicant_deauthenticate(wpa_s, |
| 4289 | WLAN_REASON_MICHAEL_MIC_FAILURE); |
| 4290 | eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, |
| 4291 | wpa_s, NULL); |
| 4292 | eloop_register_timeout(60, 0, |
| 4293 | wpa_supplicant_stop_countermeasures, |
| 4294 | wpa_s, NULL); |
| 4295 | /* TODO: mark the AP rejected for 60 second. STA is |
| 4296 | * allowed to associate with another AP.. */ |
| 4297 | } else { |
| 4298 | #ifdef CONFIG_DELAYED_MIC_ERROR_REPORT |
| 4299 | if (wpa_s->mic_errors_seen) { |
| 4300 | /* |
| 4301 | * Reduce the effectiveness of Michael MIC error |
| 4302 | * reports as a means for attacking against TKIP if |
| 4303 | * more than one MIC failure is noticed with the same |
| 4304 | * PTK. We delay the transmission of the reports by a |
| 4305 | * random time between 0 and 60 seconds in order to |
| 4306 | * force the attacker wait 60 seconds before getting |
| 4307 | * the information on whether a frame resulted in a MIC |
| 4308 | * failure. |
| 4309 | */ |
| 4310 | u8 rval[4]; |
| 4311 | int sec; |
| 4312 | |
| 4313 | if (os_get_random(rval, sizeof(rval)) < 0) |
| 4314 | sec = os_random() % 60; |
| 4315 | else |
| 4316 | sec = WPA_GET_BE32(rval) % 60; |
| 4317 | wpa_dbg(wpa_s, MSG_DEBUG, "WPA: Delay MIC error " |
| 4318 | "report %d seconds", sec); |
| 4319 | wpa_s->pending_mic_error_report = 1; |
| 4320 | wpa_s->pending_mic_error_pairwise = pairwise; |
| 4321 | eloop_cancel_timeout( |
| 4322 | wpa_supplicant_delayed_mic_error_report, |
| 4323 | wpa_s, NULL); |
| 4324 | eloop_register_timeout( |
| 4325 | sec, os_random() % 1000000, |
| 4326 | wpa_supplicant_delayed_mic_error_report, |
| 4327 | wpa_s, NULL); |
| 4328 | } else { |
| 4329 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 4330 | } |
| 4331 | #else /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 4332 | wpa_sm_key_request(wpa_s->wpa, 1, pairwise); |
| 4333 | #endif /* CONFIG_DELAYED_MIC_ERROR_REPORT */ |
| 4334 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4335 | wpa_s->last_michael_mic_error = t; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4336 | wpa_s->mic_errors_seen++; |
| 4337 | } |
| 4338 | |
| 4339 | |
| 4340 | #ifdef CONFIG_TERMINATE_ONLASTIF |
| 4341 | static int any_interfaces(struct wpa_supplicant *head) |
| 4342 | { |
| 4343 | struct wpa_supplicant *wpa_s; |
| 4344 | |
| 4345 | for (wpa_s = head; wpa_s != NULL; wpa_s = wpa_s->next) |
| 4346 | if (!wpa_s->interface_removed) |
| 4347 | return 1; |
| 4348 | return 0; |
| 4349 | } |
| 4350 | #endif /* CONFIG_TERMINATE_ONLASTIF */ |
| 4351 | |
| 4352 | |
| 4353 | static void |
| 4354 | wpa_supplicant_event_interface_status(struct wpa_supplicant *wpa_s, |
| 4355 | union wpa_event_data *data) |
| 4356 | { |
| 4357 | if (os_strcmp(wpa_s->ifname, data->interface_status.ifname) != 0) |
| 4358 | return; |
| 4359 | |
| 4360 | switch (data->interface_status.ievent) { |
| 4361 | case EVENT_INTERFACE_ADDED: |
| 4362 | if (!wpa_s->interface_removed) |
| 4363 | break; |
| 4364 | wpa_s->interface_removed = 0; |
| 4365 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was added"); |
| 4366 | if (wpa_supplicant_driver_init(wpa_s) < 0) { |
| 4367 | wpa_msg(wpa_s, MSG_INFO, "Failed to initialize the " |
| 4368 | "driver after interface was added"); |
| 4369 | } |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4370 | |
| 4371 | #ifdef CONFIG_P2P |
| 4372 | if (!wpa_s->global->p2p && |
| 4373 | !wpa_s->global->p2p_disabled && |
| 4374 | !wpa_s->conf->p2p_disabled && |
| 4375 | (wpa_s->drv_flags & |
| 4376 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE) && |
| 4377 | wpas_p2p_add_p2pdev_interface( |
| 4378 | wpa_s, wpa_s->global->params.conf_p2p_dev) < 0) { |
| 4379 | wpa_printf(MSG_INFO, |
| 4380 | "P2P: Failed to enable P2P Device interface"); |
| 4381 | /* Try to continue without. P2P will be disabled. */ |
| 4382 | } |
| 4383 | #endif /* CONFIG_P2P */ |
| 4384 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4385 | break; |
| 4386 | case EVENT_INTERFACE_REMOVED: |
| 4387 | wpa_dbg(wpa_s, MSG_DEBUG, "Configured interface was removed"); |
| 4388 | wpa_s->interface_removed = 1; |
| 4389 | wpa_supplicant_mark_disassoc(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4390 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4391 | l2_packet_deinit(wpa_s->l2); |
| 4392 | wpa_s->l2 = NULL; |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 4393 | |
| 4394 | #ifdef CONFIG_P2P |
| 4395 | if (wpa_s->global->p2p && |
| 4396 | wpa_s->global->p2p_init_wpa_s->parent == wpa_s && |
| 4397 | (wpa_s->drv_flags & |
| 4398 | WPA_DRIVER_FLAGS_DEDICATED_P2P_DEVICE)) { |
| 4399 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4400 | "Removing P2P Device interface"); |
| 4401 | wpa_supplicant_remove_iface( |
| 4402 | wpa_s->global, wpa_s->global->p2p_init_wpa_s, |
| 4403 | 0); |
| 4404 | wpa_s->global->p2p_init_wpa_s = NULL; |
| 4405 | } |
| 4406 | #endif /* CONFIG_P2P */ |
| 4407 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4408 | #ifdef CONFIG_MATCH_IFACE |
| 4409 | if (wpa_s->matched) { |
| 4410 | wpa_supplicant_remove_iface(wpa_s->global, wpa_s, 0); |
| 4411 | break; |
| 4412 | } |
| 4413 | #endif /* CONFIG_MATCH_IFACE */ |
| 4414 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4415 | #ifdef CONFIG_TERMINATE_ONLASTIF |
| 4416 | /* check if last interface */ |
| 4417 | if (!any_interfaces(wpa_s->global->ifaces)) |
| 4418 | eloop_terminate(); |
| 4419 | #endif /* CONFIG_TERMINATE_ONLASTIF */ |
| 4420 | break; |
| 4421 | } |
| 4422 | } |
| 4423 | |
| 4424 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4425 | #ifdef CONFIG_TDLS |
| 4426 | static void wpa_supplicant_event_tdls(struct wpa_supplicant *wpa_s, |
| 4427 | union wpa_event_data *data) |
| 4428 | { |
| 4429 | if (data == NULL) |
| 4430 | return; |
| 4431 | switch (data->tdls.oper) { |
| 4432 | case TDLS_REQUEST_SETUP: |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4433 | wpa_tdls_remove(wpa_s->wpa, data->tdls.peer); |
| 4434 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 4435 | wpa_tdls_start(wpa_s->wpa, data->tdls.peer); |
| 4436 | else |
| 4437 | wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, data->tdls.peer); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4438 | break; |
| 4439 | case TDLS_REQUEST_TEARDOWN: |
Sunil Dutt | 6a9f522 | 2013-09-30 17:10:18 +0300 | [diff] [blame] | 4440 | if (wpa_tdls_is_external_setup(wpa_s->wpa)) |
| 4441 | wpa_tdls_teardown_link(wpa_s->wpa, data->tdls.peer, |
| 4442 | data->tdls.reason_code); |
| 4443 | else |
| 4444 | wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, |
| 4445 | data->tdls.peer); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4446 | break; |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 4447 | case TDLS_REQUEST_DISCOVER: |
| 4448 | wpa_tdls_send_discovery_request(wpa_s->wpa, |
| 4449 | data->tdls.peer); |
| 4450 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4451 | } |
| 4452 | } |
| 4453 | #endif /* CONFIG_TDLS */ |
| 4454 | |
| 4455 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4456 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4457 | static void wpa_supplicant_event_wnm(struct wpa_supplicant *wpa_s, |
| 4458 | union wpa_event_data *data) |
| 4459 | { |
| 4460 | if (data == NULL) |
| 4461 | return; |
| 4462 | switch (data->wnm.oper) { |
| 4463 | case WNM_OPER_SLEEP: |
| 4464 | wpa_printf(MSG_DEBUG, "Start sending WNM-Sleep Request " |
| 4465 | "(action=%d, intval=%d)", |
| 4466 | data->wnm.sleep_action, data->wnm.sleep_intval); |
| 4467 | ieee802_11_send_wnmsleep_req(wpa_s, data->wnm.sleep_action, |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4468 | data->wnm.sleep_intval, NULL); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4469 | break; |
| 4470 | } |
| 4471 | } |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4472 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 4473 | |
| 4474 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4475 | #ifdef CONFIG_IEEE80211R |
| 4476 | static void |
| 4477 | wpa_supplicant_event_ft_response(struct wpa_supplicant *wpa_s, |
| 4478 | union wpa_event_data *data) |
| 4479 | { |
| 4480 | if (data == NULL) |
| 4481 | return; |
| 4482 | |
| 4483 | if (wpa_ft_process_response(wpa_s->wpa, data->ft_ies.ies, |
| 4484 | data->ft_ies.ies_len, |
| 4485 | data->ft_ies.ft_action, |
| 4486 | data->ft_ies.target_ap, |
| 4487 | data->ft_ies.ric_ies, |
| 4488 | data->ft_ies.ric_ies_len) < 0) { |
| 4489 | /* TODO: prevent MLME/driver from trying to associate? */ |
| 4490 | } |
| 4491 | } |
| 4492 | #endif /* CONFIG_IEEE80211R */ |
| 4493 | |
| 4494 | |
| 4495 | #ifdef CONFIG_IBSS_RSN |
| 4496 | static void wpa_supplicant_event_ibss_rsn_start(struct wpa_supplicant *wpa_s, |
| 4497 | union wpa_event_data *data) |
| 4498 | { |
| 4499 | struct wpa_ssid *ssid; |
| 4500 | if (wpa_s->wpa_state < WPA_ASSOCIATED) |
| 4501 | return; |
| 4502 | if (data == NULL) |
| 4503 | return; |
| 4504 | ssid = wpa_s->current_ssid; |
| 4505 | if (ssid == NULL) |
| 4506 | return; |
| 4507 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 4508 | return; |
| 4509 | |
| 4510 | ibss_rsn_start(wpa_s->ibss_rsn, data->ibss_rsn_start.peer); |
| 4511 | } |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4512 | |
| 4513 | |
| 4514 | static void wpa_supplicant_event_ibss_auth(struct wpa_supplicant *wpa_s, |
| 4515 | union wpa_event_data *data) |
| 4516 | { |
| 4517 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 4518 | |
| 4519 | if (ssid == NULL) |
| 4520 | return; |
| 4521 | |
| 4522 | /* check if the ssid is correctly configured as IBSS/RSN */ |
| 4523 | if (ssid->mode != WPAS_MODE_IBSS || !wpa_key_mgmt_wpa(ssid->key_mgmt)) |
| 4524 | return; |
| 4525 | |
| 4526 | ibss_rsn_handle_auth(wpa_s->ibss_rsn, data->rx_mgmt.frame, |
| 4527 | data->rx_mgmt.frame_len); |
| 4528 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4529 | #endif /* CONFIG_IBSS_RSN */ |
| 4530 | |
| 4531 | |
| 4532 | #ifdef CONFIG_IEEE80211R |
| 4533 | static void ft_rx_action(struct wpa_supplicant *wpa_s, const u8 *data, |
| 4534 | size_t len) |
| 4535 | { |
| 4536 | const u8 *sta_addr, *target_ap_addr; |
| 4537 | u16 status; |
| 4538 | |
| 4539 | wpa_hexdump(MSG_MSGDUMP, "FT: RX Action", data, len); |
| 4540 | if (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME)) |
| 4541 | return; /* only SME case supported for now */ |
| 4542 | if (len < 1 + 2 * ETH_ALEN + 2) |
| 4543 | return; |
| 4544 | if (data[0] != 2) |
| 4545 | return; /* Only FT Action Response is supported for now */ |
| 4546 | sta_addr = data + 1; |
| 4547 | target_ap_addr = data + 1 + ETH_ALEN; |
| 4548 | status = WPA_GET_LE16(data + 1 + 2 * ETH_ALEN); |
| 4549 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Received FT Action Response: STA " |
| 4550 | MACSTR " TargetAP " MACSTR " status %u", |
| 4551 | MAC2STR(sta_addr), MAC2STR(target_ap_addr), status); |
| 4552 | |
| 4553 | if (os_memcmp(sta_addr, wpa_s->own_addr, ETH_ALEN) != 0) { |
| 4554 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: Foreign STA Address " MACSTR |
| 4555 | " in FT Action Response", MAC2STR(sta_addr)); |
| 4556 | return; |
| 4557 | } |
| 4558 | |
| 4559 | if (status) { |
| 4560 | wpa_dbg(wpa_s, MSG_DEBUG, "FT: FT Action Response indicates " |
| 4561 | "failure (status code %d)", status); |
| 4562 | /* TODO: report error to FT code(?) */ |
| 4563 | return; |
| 4564 | } |
| 4565 | |
| 4566 | if (wpa_ft_process_response(wpa_s->wpa, data + 1 + 2 * ETH_ALEN + 2, |
| 4567 | len - (1 + 2 * ETH_ALEN + 2), 1, |
| 4568 | target_ap_addr, NULL, 0) < 0) |
| 4569 | return; |
| 4570 | |
| 4571 | #ifdef CONFIG_SME |
| 4572 | { |
| 4573 | struct wpa_bss *bss; |
| 4574 | bss = wpa_bss_get_bssid(wpa_s, target_ap_addr); |
| 4575 | if (bss) |
| 4576 | wpa_s->sme.freq = bss->freq; |
| 4577 | wpa_s->sme.auth_alg = WPA_AUTH_ALG_FT; |
| 4578 | sme_associate(wpa_s, WPAS_MODE_INFRA, target_ap_addr, |
| 4579 | WLAN_AUTH_FT); |
| 4580 | } |
| 4581 | #endif /* CONFIG_SME */ |
| 4582 | } |
| 4583 | #endif /* CONFIG_IEEE80211R */ |
| 4584 | |
| 4585 | |
| 4586 | static void wpa_supplicant_event_unprot_deauth(struct wpa_supplicant *wpa_s, |
| 4587 | struct unprot_deauth *e) |
| 4588 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4589 | wpa_printf(MSG_DEBUG, "Unprotected Deauthentication frame " |
| 4590 | "dropped: " MACSTR " -> " MACSTR |
| 4591 | " (reason code %u)", |
| 4592 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); |
| 4593 | 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] | 4594 | } |
| 4595 | |
| 4596 | |
| 4597 | static void wpa_supplicant_event_unprot_disassoc(struct wpa_supplicant *wpa_s, |
| 4598 | struct unprot_disassoc *e) |
| 4599 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4600 | wpa_printf(MSG_DEBUG, "Unprotected Disassociation frame " |
| 4601 | "dropped: " MACSTR " -> " MACSTR |
| 4602 | " (reason code %u)", |
| 4603 | MAC2STR(e->sa), MAC2STR(e->da), e->reason_code); |
| 4604 | 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] | 4605 | } |
| 4606 | |
| 4607 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4608 | static void wpas_event_disconnect(struct wpa_supplicant *wpa_s, const u8 *addr, |
| 4609 | u16 reason_code, int locally_generated, |
| 4610 | const u8 *ie, size_t ie_len, int deauth) |
| 4611 | { |
| 4612 | #ifdef CONFIG_AP |
| 4613 | if (wpa_s->ap_iface && addr) { |
| 4614 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], addr); |
| 4615 | return; |
| 4616 | } |
| 4617 | |
| 4618 | if (wpa_s->ap_iface) { |
| 4619 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore deauth event in AP mode"); |
| 4620 | return; |
| 4621 | } |
| 4622 | #endif /* CONFIG_AP */ |
| 4623 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4624 | if (!locally_generated) |
| 4625 | wpa_s->own_disconnect_req = 0; |
| 4626 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4627 | wpa_supplicant_event_disassoc(wpa_s, reason_code, locally_generated); |
| 4628 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4629 | if (((reason_code == WLAN_REASON_IEEE_802_1X_AUTH_FAILED || |
| 4630 | ((wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) || |
| 4631 | (wpa_s->key_mgmt & WPA_KEY_MGMT_IEEE8021X_NO_WPA)) && |
| 4632 | eapol_sm_failed(wpa_s->eapol))) && |
| 4633 | !wpa_s->eap_expected_failure)) |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 4634 | wpas_auth_failed(wpa_s, "AUTH_FAILED", addr); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4635 | |
| 4636 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 391c59f | 2013-09-03 12:16:28 -0700 | [diff] [blame] | 4637 | if (deauth && reason_code > 0) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4638 | if (wpas_p2p_deauth_notif(wpa_s, addr, reason_code, ie, ie_len, |
| 4639 | locally_generated) > 0) { |
| 4640 | /* |
| 4641 | * The interface was removed, so cannot continue |
| 4642 | * processing any additional operations after this. |
| 4643 | */ |
| 4644 | return; |
| 4645 | } |
| 4646 | } |
| 4647 | #endif /* CONFIG_P2P */ |
| 4648 | |
| 4649 | wpa_supplicant_event_disassoc_finish(wpa_s, reason_code, |
| 4650 | locally_generated); |
| 4651 | } |
| 4652 | |
| 4653 | |
| 4654 | static void wpas_event_disassoc(struct wpa_supplicant *wpa_s, |
| 4655 | struct disassoc_info *info) |
| 4656 | { |
| 4657 | u16 reason_code = 0; |
| 4658 | int locally_generated = 0; |
| 4659 | const u8 *addr = NULL; |
| 4660 | const u8 *ie = NULL; |
| 4661 | size_t ie_len = 0; |
| 4662 | |
| 4663 | wpa_dbg(wpa_s, MSG_DEBUG, "Disassociation notification"); |
| 4664 | |
| 4665 | if (info) { |
| 4666 | addr = info->addr; |
| 4667 | ie = info->ie; |
| 4668 | ie_len = info->ie_len; |
| 4669 | reason_code = info->reason_code; |
| 4670 | locally_generated = info->locally_generated; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4671 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", reason_code, |
| 4672 | reason2str(reason_code), |
| 4673 | locally_generated ? " locally_generated=1" : ""); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4674 | if (addr) |
| 4675 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
| 4676 | MAC2STR(addr)); |
| 4677 | wpa_hexdump(MSG_DEBUG, "Disassociation frame IE(s)", |
| 4678 | ie, ie_len); |
| 4679 | } |
| 4680 | |
| 4681 | #ifdef CONFIG_AP |
| 4682 | if (wpa_s->ap_iface && info && info->addr) { |
| 4683 | hostapd_notif_disassoc(wpa_s->ap_iface->bss[0], info->addr); |
| 4684 | return; |
| 4685 | } |
| 4686 | |
| 4687 | if (wpa_s->ap_iface) { |
| 4688 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore disassoc event in AP mode"); |
| 4689 | return; |
| 4690 | } |
| 4691 | #endif /* CONFIG_AP */ |
| 4692 | |
| 4693 | #ifdef CONFIG_P2P |
| 4694 | if (info) { |
| 4695 | wpas_p2p_disassoc_notif( |
| 4696 | wpa_s, info->addr, reason_code, info->ie, info->ie_len, |
| 4697 | locally_generated); |
| 4698 | } |
| 4699 | #endif /* CONFIG_P2P */ |
| 4700 | |
| 4701 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 4702 | sme_event_disassoc(wpa_s, info); |
| 4703 | |
| 4704 | wpas_event_disconnect(wpa_s, addr, reason_code, locally_generated, |
| 4705 | ie, ie_len, 0); |
| 4706 | } |
| 4707 | |
| 4708 | |
| 4709 | static void wpas_event_deauth(struct wpa_supplicant *wpa_s, |
| 4710 | struct deauth_info *info) |
| 4711 | { |
| 4712 | u16 reason_code = 0; |
| 4713 | int locally_generated = 0; |
| 4714 | const u8 *addr = NULL; |
| 4715 | const u8 *ie = NULL; |
| 4716 | size_t ie_len = 0; |
| 4717 | |
| 4718 | wpa_dbg(wpa_s, MSG_DEBUG, "Deauthentication notification"); |
| 4719 | |
| 4720 | if (info) { |
| 4721 | addr = info->addr; |
| 4722 | ie = info->ie; |
| 4723 | ie_len = info->ie_len; |
| 4724 | reason_code = info->reason_code; |
| 4725 | locally_generated = info->locally_generated; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4726 | wpa_dbg(wpa_s, MSG_DEBUG, " * reason %u (%s)%s", |
| 4727 | reason_code, reason2str(reason_code), |
| 4728 | locally_generated ? " locally_generated=1" : ""); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 4729 | if (addr) { |
| 4730 | wpa_dbg(wpa_s, MSG_DEBUG, " * address " MACSTR, |
| 4731 | MAC2STR(addr)); |
| 4732 | } |
| 4733 | wpa_hexdump(MSG_DEBUG, "Deauthentication frame IE(s)", |
| 4734 | ie, ie_len); |
| 4735 | } |
| 4736 | |
| 4737 | wpa_reset_ft_completed(wpa_s->wpa); |
| 4738 | |
| 4739 | wpas_event_disconnect(wpa_s, addr, reason_code, |
| 4740 | locally_generated, ie, ie_len, 1); |
| 4741 | } |
| 4742 | |
| 4743 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 4744 | static const char * reg_init_str(enum reg_change_initiator init) |
| 4745 | { |
| 4746 | switch (init) { |
| 4747 | case REGDOM_SET_BY_CORE: |
| 4748 | return "CORE"; |
| 4749 | case REGDOM_SET_BY_USER: |
| 4750 | return "USER"; |
| 4751 | case REGDOM_SET_BY_DRIVER: |
| 4752 | return "DRIVER"; |
| 4753 | case REGDOM_SET_BY_COUNTRY_IE: |
| 4754 | return "COUNTRY_IE"; |
| 4755 | case REGDOM_BEACON_HINT: |
| 4756 | return "BEACON_HINT"; |
| 4757 | } |
| 4758 | return "?"; |
| 4759 | } |
| 4760 | |
| 4761 | |
| 4762 | static const char * reg_type_str(enum reg_type type) |
| 4763 | { |
| 4764 | switch (type) { |
| 4765 | case REGDOM_TYPE_UNKNOWN: |
| 4766 | return "UNKNOWN"; |
| 4767 | case REGDOM_TYPE_COUNTRY: |
| 4768 | return "COUNTRY"; |
| 4769 | case REGDOM_TYPE_WORLD: |
| 4770 | return "WORLD"; |
| 4771 | case REGDOM_TYPE_CUSTOM_WORLD: |
| 4772 | return "CUSTOM_WORLD"; |
| 4773 | case REGDOM_TYPE_INTERSECTION: |
| 4774 | return "INTERSECTION"; |
| 4775 | } |
| 4776 | return "?"; |
| 4777 | } |
| 4778 | |
| 4779 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4780 | void wpa_supplicant_update_channel_list(struct wpa_supplicant *wpa_s, |
| 4781 | struct channel_list_changed *info) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4782 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4783 | struct wpa_supplicant *ifs; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4784 | u8 dfs_domain; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4785 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4786 | /* |
| 4787 | * To allow backwards compatibility with higher level layers that |
| 4788 | * assumed the REGDOM_CHANGE event is sent over the initially added |
| 4789 | * interface. Find the highest parent of this interface and use it to |
| 4790 | * send the event. |
| 4791 | */ |
| 4792 | for (ifs = wpa_s; ifs->parent && ifs != ifs->parent; ifs = ifs->parent) |
| 4793 | ; |
| 4794 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4795 | if (info) { |
| 4796 | wpa_msg(ifs, MSG_INFO, |
| 4797 | WPA_EVENT_REGDOM_CHANGE "init=%s type=%s%s%s", |
| 4798 | reg_init_str(info->initiator), reg_type_str(info->type), |
| 4799 | info->alpha2[0] ? " alpha2=" : "", |
| 4800 | info->alpha2[0] ? info->alpha2 : ""); |
| 4801 | } |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 4802 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4803 | if (wpa_s->drv_priv == NULL) |
| 4804 | return; /* Ignore event during drv initialization */ |
| 4805 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 4806 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, struct wpa_supplicant, |
| 4807 | radio_list) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4808 | wpa_printf(MSG_DEBUG, "%s: Updating hw mode", |
| 4809 | ifs->ifname); |
| 4810 | free_hw_features(ifs); |
| 4811 | ifs->hw.modes = wpa_drv_get_hw_feature_data( |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4812 | ifs, &ifs->hw.num_modes, &ifs->hw.flags, &dfs_domain); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 4813 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 4814 | /* Restart PNO/sched_scan with updated channel list */ |
| 4815 | if (ifs->pno) { |
| 4816 | wpas_stop_pno(ifs); |
| 4817 | wpas_start_pno(ifs); |
| 4818 | } else if (ifs->sched_scanning && !ifs->pno_sched_pending) { |
| 4819 | wpa_dbg(ifs, MSG_DEBUG, |
| 4820 | "Channel list changed - restart sched_scan"); |
| 4821 | wpas_scan_restart_sched_scan(ifs); |
| 4822 | } |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 4823 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4824 | |
| 4825 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DRIVER); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4829 | static void wpas_event_rx_mgmt_action(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4830 | const u8 *frame, size_t len, int freq, |
| 4831 | int rssi) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4832 | { |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 4833 | const struct ieee80211_mgmt *mgmt; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4834 | const u8 *payload; |
| 4835 | size_t plen; |
| 4836 | u8 category; |
| 4837 | |
| 4838 | if (len < IEEE80211_HDRLEN + 2) |
| 4839 | return; |
| 4840 | |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 4841 | mgmt = (const struct ieee80211_mgmt *) frame; |
| 4842 | payload = frame + IEEE80211_HDRLEN; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4843 | category = *payload++; |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 4844 | plen = len - IEEE80211_HDRLEN - 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4845 | |
| 4846 | wpa_dbg(wpa_s, MSG_DEBUG, "Received Action frame: SA=" MACSTR |
| 4847 | " Category=%u DataLen=%d freq=%d MHz", |
| 4848 | MAC2STR(mgmt->sa), category, (int) plen, freq); |
| 4849 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4850 | if (category == WLAN_ACTION_WMM) { |
| 4851 | wmm_ac_rx_action(wpa_s, mgmt->da, mgmt->sa, payload, plen); |
| 4852 | return; |
| 4853 | } |
| 4854 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4855 | #ifdef CONFIG_IEEE80211R |
| 4856 | if (category == WLAN_ACTION_FT) { |
| 4857 | ft_rx_action(wpa_s, payload, plen); |
| 4858 | return; |
| 4859 | } |
| 4860 | #endif /* CONFIG_IEEE80211R */ |
| 4861 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4862 | #ifdef CONFIG_SME |
| 4863 | if (category == WLAN_ACTION_SA_QUERY) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4864 | sme_sa_query_rx(wpa_s, mgmt->da, mgmt->sa, payload, plen); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4865 | return; |
| 4866 | } |
| 4867 | #endif /* CONFIG_SME */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4868 | |
| 4869 | #ifdef CONFIG_WNM |
| 4870 | if (mgmt->u.action.category == WLAN_ACTION_WNM) { |
| 4871 | ieee802_11_rx_wnm_action(wpa_s, mgmt, len); |
| 4872 | return; |
| 4873 | } |
| 4874 | #endif /* CONFIG_WNM */ |
| 4875 | |
| 4876 | #ifdef CONFIG_GAS |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4877 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
| 4878 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4879 | gas_query_rx(wpa_s->gas, mgmt->da, mgmt->sa, mgmt->bssid, |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 4880 | mgmt->u.action.category, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4881 | payload, plen, freq) == 0) |
| 4882 | return; |
| 4883 | #endif /* CONFIG_GAS */ |
| 4884 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4885 | #ifdef CONFIG_GAS_SERVER |
| 4886 | if ((mgmt->u.action.category == WLAN_ACTION_PUBLIC || |
| 4887 | mgmt->u.action.category == WLAN_ACTION_PROTECTED_DUAL) && |
| 4888 | gas_server_rx(wpa_s->gas_server, mgmt->da, mgmt->sa, mgmt->bssid, |
| 4889 | mgmt->u.action.category, |
| 4890 | payload, plen, freq) == 0) |
| 4891 | return; |
| 4892 | #endif /* CONFIG_GAS_SERVER */ |
| 4893 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4894 | #ifdef CONFIG_TDLS |
| 4895 | if (category == WLAN_ACTION_PUBLIC && plen >= 4 && |
| 4896 | payload[0] == WLAN_TDLS_DISCOVERY_RESPONSE) { |
| 4897 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 4898 | "TDLS: Received Discovery Response from " MACSTR, |
| 4899 | MAC2STR(mgmt->sa)); |
| 4900 | return; |
| 4901 | } |
| 4902 | #endif /* CONFIG_TDLS */ |
| 4903 | |
| 4904 | #ifdef CONFIG_INTERWORKING |
| 4905 | if (category == WLAN_ACTION_QOS && plen >= 1 && |
| 4906 | payload[0] == QOS_QOS_MAP_CONFIG) { |
| 4907 | const u8 *pos = payload + 1; |
| 4908 | size_t qlen = plen - 1; |
| 4909 | wpa_dbg(wpa_s, MSG_DEBUG, "Interworking: Received QoS Map Configure frame from " |
| 4910 | MACSTR, MAC2STR(mgmt->sa)); |
| 4911 | if (os_memcmp(mgmt->sa, wpa_s->bssid, ETH_ALEN) == 0 && |
| 4912 | qlen > 2 && pos[0] == WLAN_EID_QOS_MAP_SET && |
| 4913 | pos[1] <= qlen - 2 && pos[1] >= 16) |
| 4914 | wpas_qos_map_set(wpa_s, pos + 2, pos[1]); |
| 4915 | return; |
| 4916 | } |
| 4917 | #endif /* CONFIG_INTERWORKING */ |
| 4918 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4919 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4920 | payload[0] == WLAN_RRM_RADIO_MEASUREMENT_REQUEST) { |
| 4921 | wpas_rrm_handle_radio_measurement_request(wpa_s, mgmt->sa, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4922 | mgmt->da, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4923 | payload + 1, |
| 4924 | plen - 1); |
| 4925 | return; |
| 4926 | } |
| 4927 | |
| 4928 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4929 | payload[0] == WLAN_RRM_NEIGHBOR_REPORT_RESPONSE) { |
| 4930 | wpas_rrm_process_neighbor_rep(wpa_s, payload + 1, plen - 1); |
| 4931 | return; |
| 4932 | } |
| 4933 | |
| 4934 | if (category == WLAN_ACTION_RADIO_MEASUREMENT && |
| 4935 | payload[0] == WLAN_RRM_LINK_MEASUREMENT_REQUEST) { |
| 4936 | wpas_rrm_handle_link_measurement_request(wpa_s, mgmt->sa, |
| 4937 | payload + 1, plen - 1, |
| 4938 | rssi); |
| 4939 | return; |
| 4940 | } |
| 4941 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4942 | #ifdef CONFIG_FST |
| 4943 | if (mgmt->u.action.category == WLAN_ACTION_FST && wpa_s->fst) { |
| 4944 | fst_rx_action(wpa_s->fst, mgmt, len); |
| 4945 | return; |
| 4946 | } |
| 4947 | #endif /* CONFIG_FST */ |
| 4948 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 4949 | #ifdef CONFIG_DPP |
| 4950 | if (category == WLAN_ACTION_PUBLIC && plen >= 5 && |
| 4951 | payload[0] == WLAN_PA_VENDOR_SPECIFIC && |
| 4952 | WPA_GET_BE24(&payload[1]) == OUI_WFA && |
| 4953 | payload[4] == DPP_OUI_TYPE) { |
| 4954 | payload++; |
| 4955 | plen--; |
| 4956 | wpas_dpp_rx_action(wpa_s, mgmt->sa, payload, plen, freq); |
| 4957 | return; |
| 4958 | } |
| 4959 | #endif /* CONFIG_DPP */ |
| 4960 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4961 | if (category == WLAN_ACTION_ROBUST_AV_STREAMING && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4962 | payload[0] == ROBUST_AV_SCS_RESP) { |
| 4963 | wpas_handle_robust_av_scs_recv_action(wpa_s, mgmt->sa, |
| 4964 | payload + 1, plen - 1); |
| 4965 | return; |
| 4966 | } |
| 4967 | |
| 4968 | if (category == WLAN_ACTION_ROBUST_AV_STREAMING && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4969 | payload[0] == ROBUST_AV_MSCS_RESP) { |
| 4970 | wpas_handle_robust_av_recv_action(wpa_s, mgmt->sa, |
| 4971 | payload + 1, plen - 1); |
| 4972 | return; |
| 4973 | } |
| 4974 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4975 | if (category == WLAN_ACTION_VENDOR_SPECIFIC_PROTECTED && plen > 4 && |
| 4976 | WPA_GET_BE32(payload) == QM_ACTION_VENDOR_TYPE) { |
| 4977 | wpas_handle_qos_mgmt_recv_action(wpa_s, mgmt->sa, |
| 4978 | payload + 4, plen - 4); |
| 4979 | return; |
| 4980 | } |
| 4981 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4982 | wpas_p2p_rx_action(wpa_s, mgmt->da, mgmt->sa, mgmt->bssid, |
| 4983 | category, payload, plen, freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4984 | if (wpa_s->ifmsh) |
| 4985 | mesh_mpm_action_rx(wpa_s, mgmt, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4986 | } |
| 4987 | |
| 4988 | |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4989 | static void wpa_supplicant_notify_avoid_freq(struct wpa_supplicant *wpa_s, |
| 4990 | union wpa_event_data *event) |
| 4991 | { |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 4992 | struct wpa_freq_range_list *list; |
| 4993 | char *str = NULL; |
| 4994 | |
| 4995 | list = &event->freq_range; |
| 4996 | |
| 4997 | if (list->num) |
| 4998 | str = freq_range_list_str(list); |
| 4999 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_AVOID_FREQ "ranges=%s", |
| 5000 | str ? str : ""); |
| 5001 | |
| 5002 | #ifdef CONFIG_P2P |
| 5003 | if (freq_range_list_parse(&wpa_s->global->p2p_go_avoid_freq, str)) { |
| 5004 | wpa_dbg(wpa_s, MSG_ERROR, "%s: Failed to parse freq range", |
| 5005 | __func__); |
| 5006 | } else { |
| 5007 | 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] | 5008 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5009 | /* |
| 5010 | * The update channel flow will also take care of moving a GO |
| 5011 | * from the unsafe frequency if needed. |
| 5012 | */ |
| 5013 | wpas_p2p_update_channel_list(wpa_s, |
| 5014 | WPAS_P2P_CHANNEL_UPDATE_AVOID); |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 5015 | } |
| 5016 | #endif /* CONFIG_P2P */ |
| 5017 | |
| 5018 | os_free(str); |
| 5019 | } |
| 5020 | |
| 5021 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5022 | static void wpa_supplicant_event_port_authorized(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5023 | { |
Sunil Ravi | 167279a | 2023-05-31 01:12:34 +0000 | [diff] [blame^] | 5024 | if (wpa_s->wpa_state >= WPA_ASSOCIATED) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5025 | wpa_supplicant_cancel_auth_timeout(wpa_s); |
| 5026 | wpa_supplicant_set_state(wpa_s, WPA_COMPLETED); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 5027 | eapol_sm_notify_portValid(wpa_s->eapol, true); |
| 5028 | eapol_sm_notify_eap_success(wpa_s->eapol, true); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5029 | wpa_s->drv_authorized_port = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5030 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | |
| 5034 | static unsigned int wpas_event_cac_ms(const struct wpa_supplicant *wpa_s, |
| 5035 | int freq) |
| 5036 | { |
| 5037 | size_t i; |
| 5038 | int j; |
| 5039 | |
| 5040 | for (i = 0; i < wpa_s->hw.num_modes; i++) { |
| 5041 | const struct hostapd_hw_modes *mode = &wpa_s->hw.modes[i]; |
| 5042 | |
| 5043 | for (j = 0; j < mode->num_channels; j++) { |
| 5044 | const struct hostapd_channel_data *chan; |
| 5045 | |
| 5046 | chan = &mode->channels[j]; |
| 5047 | if (chan->freq == freq) |
| 5048 | return chan->dfs_cac_ms; |
| 5049 | } |
| 5050 | } |
| 5051 | |
| 5052 | return 0; |
| 5053 | } |
| 5054 | |
| 5055 | |
| 5056 | static void wpas_event_dfs_cac_started(struct wpa_supplicant *wpa_s, |
| 5057 | struct dfs_event *radar) |
| 5058 | { |
| 5059 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5060 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5061 | wpas_ap_event_dfs_cac_started(wpa_s, radar); |
| 5062 | } else |
| 5063 | #endif /* NEED_AP_MLME && CONFIG_AP */ |
| 5064 | { |
| 5065 | unsigned int cac_time = wpas_event_cac_ms(wpa_s, radar->freq); |
| 5066 | |
| 5067 | cac_time /= 1000; /* convert from ms to sec */ |
| 5068 | if (!cac_time) |
| 5069 | cac_time = 10 * 60; /* max timeout: 10 minutes */ |
| 5070 | |
| 5071 | /* Restart auth timeout: CAC time added to initial timeout */ |
| 5072 | wpas_auth_timeout_restart(wpa_s, cac_time); |
| 5073 | } |
| 5074 | } |
| 5075 | |
| 5076 | |
| 5077 | static void wpas_event_dfs_cac_finished(struct wpa_supplicant *wpa_s, |
| 5078 | struct dfs_event *radar) |
| 5079 | { |
| 5080 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5081 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5082 | wpas_ap_event_dfs_cac_finished(wpa_s, radar); |
| 5083 | } else |
| 5084 | #endif /* NEED_AP_MLME && CONFIG_AP */ |
| 5085 | { |
| 5086 | /* Restart auth timeout with original value after CAC is |
| 5087 | * finished */ |
| 5088 | wpas_auth_timeout_restart(wpa_s, 0); |
| 5089 | } |
| 5090 | } |
| 5091 | |
| 5092 | |
| 5093 | static void wpas_event_dfs_cac_aborted(struct wpa_supplicant *wpa_s, |
| 5094 | struct dfs_event *radar) |
| 5095 | { |
| 5096 | #if defined(NEED_AP_MLME) && defined(CONFIG_AP) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5097 | if (wpa_s->ap_iface || wpa_s->ifmsh) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5098 | wpas_ap_event_dfs_cac_aborted(wpa_s, radar); |
| 5099 | } else |
| 5100 | #endif /* NEED_AP_MLME && CONFIG_AP */ |
| 5101 | { |
| 5102 | /* Restart auth timeout with original value after CAC is |
| 5103 | * aborted */ |
| 5104 | wpas_auth_timeout_restart(wpa_s, 0); |
| 5105 | } |
| 5106 | } |
| 5107 | |
| 5108 | |
| 5109 | static void wpa_supplicant_event_assoc_auth(struct wpa_supplicant *wpa_s, |
| 5110 | union wpa_event_data *data) |
| 5111 | { |
| 5112 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5113 | "Connection authorized by device, previous state %d", |
| 5114 | wpa_s->wpa_state); |
| 5115 | |
| 5116 | wpa_supplicant_event_port_authorized(wpa_s); |
| 5117 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5118 | wpa_s->last_eapol_matches_bssid = 1; |
| 5119 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5120 | wpa_sm_set_rx_replay_ctr(wpa_s->wpa, data->assoc_info.key_replay_ctr); |
| 5121 | 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] | 5122 | data->assoc_info.ptk_kck_len, |
| 5123 | data->assoc_info.ptk_kek, |
| 5124 | data->assoc_info.ptk_kek_len); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5125 | #ifdef CONFIG_FILS |
| 5126 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) { |
| 5127 | struct wpa_bss *bss = wpa_bss_get_bssid(wpa_s, wpa_s->bssid); |
| 5128 | const u8 *fils_cache_id = wpa_bss_get_fils_cache_id(bss); |
| 5129 | |
| 5130 | /* Update ERP next sequence number */ |
| 5131 | eapol_sm_update_erp_next_seq_num( |
| 5132 | wpa_s->eapol, data->assoc_info.fils_erp_next_seq_num); |
| 5133 | |
| 5134 | if (data->assoc_info.fils_pmk && data->assoc_info.fils_pmkid) { |
| 5135 | /* Add the new PMK and PMKID to the PMKSA cache */ |
| 5136 | wpa_sm_pmksa_cache_add(wpa_s->wpa, |
| 5137 | data->assoc_info.fils_pmk, |
| 5138 | data->assoc_info.fils_pmk_len, |
| 5139 | data->assoc_info.fils_pmkid, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5140 | wpa_s->valid_links ? |
| 5141 | wpa_s->ap_mld_addr : |
| 5142 | wpa_s->bssid, |
| 5143 | fils_cache_id); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5144 | } else if (data->assoc_info.fils_pmkid) { |
| 5145 | /* Update the current PMKSA used for this connection */ |
| 5146 | pmksa_cache_set_current(wpa_s->wpa, |
| 5147 | data->assoc_info.fils_pmkid, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5148 | NULL, NULL, 0, NULL, 0); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5149 | } |
| 5150 | } |
| 5151 | #endif /* CONFIG_FILS */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5155 | static const char * connect_fail_reason(enum sta_connect_fail_reason_codes code) |
| 5156 | { |
| 5157 | switch (code) { |
| 5158 | case STA_CONNECT_FAIL_REASON_UNSPECIFIED: |
| 5159 | return ""; |
| 5160 | case STA_CONNECT_FAIL_REASON_NO_BSS_FOUND: |
| 5161 | return "no_bss_found"; |
| 5162 | case STA_CONNECT_FAIL_REASON_AUTH_TX_FAIL: |
| 5163 | return "auth_tx_fail"; |
| 5164 | case STA_CONNECT_FAIL_REASON_AUTH_NO_ACK_RECEIVED: |
| 5165 | return "auth_no_ack_received"; |
| 5166 | case STA_CONNECT_FAIL_REASON_AUTH_NO_RESP_RECEIVED: |
| 5167 | return "auth_no_resp_received"; |
| 5168 | case STA_CONNECT_FAIL_REASON_ASSOC_REQ_TX_FAIL: |
| 5169 | return "assoc_req_tx_fail"; |
| 5170 | case STA_CONNECT_FAIL_REASON_ASSOC_NO_ACK_RECEIVED: |
| 5171 | return "assoc_no_ack_received"; |
| 5172 | case STA_CONNECT_FAIL_REASON_ASSOC_NO_RESP_RECEIVED: |
| 5173 | return "assoc_no_resp_received"; |
| 5174 | default: |
| 5175 | return "unknown_reason"; |
| 5176 | } |
| 5177 | } |
| 5178 | |
| 5179 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5180 | static void wpas_event_assoc_reject(struct wpa_supplicant *wpa_s, |
| 5181 | union wpa_event_data *data) |
| 5182 | { |
| 5183 | const u8 *bssid = data->assoc_reject.bssid; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5184 | #ifdef CONFIG_MBO |
| 5185 | struct wpa_bss *reject_bss; |
| 5186 | #endif /* CONFIG_MBO */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5187 | |
| 5188 | if (!bssid || is_zero_ether_addr(bssid)) |
| 5189 | bssid = wpa_s->pending_bssid; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5190 | #ifdef CONFIG_MBO |
| 5191 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 5192 | reject_bss = wpa_s->current_bss; |
| 5193 | else |
| 5194 | reject_bss = wpa_bss_get_bssid(wpa_s, bssid); |
| 5195 | #endif /* CONFIG_MBO */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5196 | |
| 5197 | if (data->assoc_reject.bssid) |
| 5198 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5199 | "bssid=" MACSTR " status_code=%u%s%s%s%s%s", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5200 | MAC2STR(data->assoc_reject.bssid), |
| 5201 | data->assoc_reject.status_code, |
| 5202 | data->assoc_reject.timed_out ? " timeout" : "", |
| 5203 | data->assoc_reject.timeout_reason ? "=" : "", |
| 5204 | data->assoc_reject.timeout_reason ? |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5205 | data->assoc_reject.timeout_reason : "", |
| 5206 | data->assoc_reject.reason_code != |
| 5207 | STA_CONNECT_FAIL_REASON_UNSPECIFIED ? |
| 5208 | " qca_driver_reason=" : "", |
| 5209 | connect_fail_reason(data->assoc_reject.reason_code)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5210 | else |
| 5211 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_ASSOC_REJECT |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5212 | "status_code=%u%s%s%s%s%s", |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5213 | data->assoc_reject.status_code, |
| 5214 | data->assoc_reject.timed_out ? " timeout" : "", |
| 5215 | data->assoc_reject.timeout_reason ? "=" : "", |
| 5216 | data->assoc_reject.timeout_reason ? |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5217 | data->assoc_reject.timeout_reason : "", |
| 5218 | data->assoc_reject.reason_code != |
| 5219 | STA_CONNECT_FAIL_REASON_UNSPECIFIED ? |
| 5220 | " qca_driver_reason=" : "", |
| 5221 | connect_fail_reason(data->assoc_reject.reason_code)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5222 | wpa_s->assoc_status_code = data->assoc_reject.status_code; |
Sunil Ravi | e06118e | 2021-01-03 08:39:46 -0800 | [diff] [blame] | 5223 | wpas_notify_assoc_status_code(wpa_s, bssid, data->assoc_reject.timed_out, |
| 5224 | data->assoc_reject.resp_ies, data->assoc_reject.resp_ies_len); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5225 | |
| 5226 | #ifdef CONFIG_OWE |
| 5227 | if (data->assoc_reject.status_code == |
| 5228 | WLAN_STATUS_FINITE_CYCLIC_GROUP_NOT_SUPPORTED && |
| 5229 | wpa_s->key_mgmt == WPA_KEY_MGMT_OWE && |
| 5230 | wpa_s->current_ssid && |
| 5231 | wpa_s->current_ssid->owe_group == 0 && |
| 5232 | wpa_s->last_owe_group != 21) { |
| 5233 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5234 | struct wpa_bss *bss = wpa_s->current_bss; |
| 5235 | |
| 5236 | if (!bss) { |
| 5237 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 5238 | if (!bss) { |
| 5239 | wpas_connection_failed(wpa_s, bssid); |
| 5240 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5241 | return; |
| 5242 | } |
| 5243 | } |
| 5244 | wpa_printf(MSG_DEBUG, "OWE: Try next supported DH group"); |
| 5245 | wpas_connect_work_done(wpa_s); |
| 5246 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5247 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 5248 | return; |
| 5249 | } |
| 5250 | #endif /* CONFIG_OWE */ |
| 5251 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5252 | #ifdef CONFIG_DPP2 |
| 5253 | /* Try to follow AP's PFS policy. WLAN_STATUS_ASSOC_DENIED_UNSPEC is |
| 5254 | * the status code defined in the DPP R2 tech spec. |
| 5255 | * WLAN_STATUS_AKMP_NOT_VALID is addressed in the same manner as an |
| 5256 | * interoperability workaround with older hostapd implementation. */ |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5257 | if (DPP_VERSION > 1 && wpa_s->current_ssid && |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5258 | (wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP || |
| 5259 | ((wpa_s->current_ssid->key_mgmt & WPA_KEY_MGMT_DPP) && |
| 5260 | wpa_s->key_mgmt == WPA_KEY_MGMT_DPP)) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5261 | wpa_s->current_ssid->dpp_pfs == 0 && |
| 5262 | (data->assoc_reject.status_code == |
| 5263 | WLAN_STATUS_ASSOC_DENIED_UNSPEC || |
| 5264 | data->assoc_reject.status_code == WLAN_STATUS_AKMP_NOT_VALID)) { |
| 5265 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 5266 | struct wpa_bss *bss = wpa_s->current_bss; |
| 5267 | |
| 5268 | wpa_s->current_ssid->dpp_pfs_fallback ^= 1; |
| 5269 | if (!bss) |
| 5270 | bss = wpa_supplicant_get_new_bss(wpa_s, bssid); |
| 5271 | if (!bss || wpa_s->dpp_pfs_fallback) { |
| 5272 | wpa_printf(MSG_DEBUG, |
| 5273 | "DPP: Updated PFS policy for next try"); |
| 5274 | wpas_connection_failed(wpa_s, bssid); |
| 5275 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5276 | return; |
| 5277 | } |
| 5278 | wpa_printf(MSG_DEBUG, "DPP: Try again with updated PFS policy"); |
| 5279 | wpa_s->dpp_pfs_fallback = 1; |
| 5280 | wpas_connect_work_done(wpa_s); |
| 5281 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5282 | wpa_supplicant_connect(wpa_s, bss, ssid); |
| 5283 | return; |
| 5284 | } |
| 5285 | #endif /* CONFIG_DPP2 */ |
| 5286 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5287 | #ifdef CONFIG_MBO |
| 5288 | if (data->assoc_reject.status_code == |
| 5289 | WLAN_STATUS_DENIED_POOR_CHANNEL_CONDITIONS && |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5290 | reject_bss && data->assoc_reject.resp_ies) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5291 | const u8 *rssi_rej; |
| 5292 | |
| 5293 | rssi_rej = mbo_get_attr_from_ies( |
| 5294 | data->assoc_reject.resp_ies, |
| 5295 | data->assoc_reject.resp_ies_len, |
| 5296 | OCE_ATTR_ID_RSSI_BASED_ASSOC_REJECT); |
| 5297 | if (rssi_rej && rssi_rej[1] == 2) { |
| 5298 | wpa_printf(MSG_DEBUG, |
| 5299 | "OCE: RSSI-based association rejection from " |
| 5300 | MACSTR " (Delta RSSI: %u, Retry Delay: %u)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5301 | MAC2STR(reject_bss->bssid), |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5302 | rssi_rej[2], rssi_rej[3]); |
| 5303 | wpa_bss_tmp_disallow(wpa_s, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5304 | reject_bss->bssid, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5305 | rssi_rej[3], |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5306 | rssi_rej[2] + reject_bss->level); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5307 | } |
| 5308 | } |
| 5309 | #endif /* CONFIG_MBO */ |
| 5310 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5311 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) { |
| 5312 | sme_event_assoc_reject(wpa_s, data); |
| 5313 | return; |
| 5314 | } |
| 5315 | |
| 5316 | /* Driver-based SME cases */ |
| 5317 | |
| 5318 | #ifdef CONFIG_SAE |
| 5319 | if (wpa_s->current_ssid && |
| 5320 | wpa_key_mgmt_sae(wpa_s->current_ssid->key_mgmt) && |
| 5321 | !data->assoc_reject.timed_out) { |
| 5322 | wpa_dbg(wpa_s, MSG_DEBUG, "SAE: Drop PMKSA cache entry"); |
| 5323 | wpa_sm_aborted_cached(wpa_s->wpa); |
| 5324 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); |
| 5325 | } |
| 5326 | #endif /* CONFIG_SAE */ |
| 5327 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5328 | #ifdef CONFIG_DPP |
| 5329 | if (wpa_s->current_ssid && |
| 5330 | wpa_s->current_ssid->key_mgmt == WPA_KEY_MGMT_DPP && |
| 5331 | !data->assoc_reject.timed_out) { |
| 5332 | wpa_dbg(wpa_s, MSG_DEBUG, "DPP: Drop PMKSA cache entry"); |
| 5333 | wpa_sm_aborted_cached(wpa_s->wpa); |
| 5334 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, wpa_s->current_ssid); |
| 5335 | } |
| 5336 | #endif /* CONFIG_DPP */ |
| 5337 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5338 | #ifdef CONFIG_FILS |
| 5339 | /* Update ERP next sequence number */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 5340 | if (wpa_s->auth_alg == WPA_AUTH_ALG_FILS) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5341 | fils_pmksa_cache_flush(wpa_s); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5342 | eapol_sm_update_erp_next_seq_num( |
| 5343 | wpa_s->eapol, |
| 5344 | data->assoc_reject.fils_erp_next_seq_num); |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 5345 | fils_connection_failure(wpa_s); |
| 5346 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5347 | #endif /* CONFIG_FILS */ |
| 5348 | |
| 5349 | wpas_connection_failed(wpa_s, bssid); |
| 5350 | wpa_supplicant_mark_disassoc(wpa_s); |
| 5351 | } |
| 5352 | |
| 5353 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5354 | static void wpas_event_unprot_beacon(struct wpa_supplicant *wpa_s, |
| 5355 | struct unprot_beacon *data) |
| 5356 | { |
| 5357 | struct wpabuf *buf; |
| 5358 | int res; |
| 5359 | |
| 5360 | if (!data || wpa_s->wpa_state != WPA_COMPLETED || |
| 5361 | os_memcmp(data->sa, wpa_s->bssid, ETH_ALEN) != 0) |
| 5362 | return; |
| 5363 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_UNPROT_BEACON MACSTR, |
| 5364 | MAC2STR(data->sa)); |
| 5365 | |
| 5366 | buf = wpabuf_alloc(4); |
| 5367 | if (!buf) |
| 5368 | return; |
| 5369 | |
| 5370 | wpabuf_put_u8(buf, WLAN_ACTION_WNM); |
| 5371 | wpabuf_put_u8(buf, WNM_NOTIFICATION_REQ); |
| 5372 | wpabuf_put_u8(buf, 1); /* Dialog Token */ |
| 5373 | wpabuf_put_u8(buf, WNM_NOTIF_TYPE_BEACON_PROTECTION_FAILURE); |
| 5374 | |
| 5375 | res = wpa_drv_send_action(wpa_s, wpa_s->assoc_freq, 0, wpa_s->bssid, |
| 5376 | wpa_s->own_addr, wpa_s->bssid, |
| 5377 | wpabuf_head(buf), wpabuf_len(buf), 0); |
| 5378 | if (res < 0) |
| 5379 | wpa_printf(MSG_DEBUG, |
| 5380 | "Failed to send WNM-Notification Request frame"); |
| 5381 | |
| 5382 | wpabuf_free(buf); |
| 5383 | } |
| 5384 | |
| 5385 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5386 | void wpa_supplicant_event(void *ctx, enum wpa_event_type event, |
| 5387 | union wpa_event_data *data) |
| 5388 | { |
| 5389 | struct wpa_supplicant *wpa_s = ctx; |
Dmitry Shmidt | af9da31 | 2015-04-03 10:03:11 -0700 | [diff] [blame] | 5390 | int resched; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5391 | struct os_reltime age, clear_at; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5392 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 5393 | int level = MSG_DEBUG; |
| 5394 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5395 | |
| 5396 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED && |
| 5397 | event != EVENT_INTERFACE_ENABLED && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5398 | event != EVENT_INTERFACE_STATUS && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5399 | event != EVENT_SCAN_RESULTS && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5400 | event != EVENT_SCHED_SCAN_STOPPED) { |
| 5401 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5402 | "Ignore event %s (%d) while interface is disabled", |
| 5403 | event_to_string(event), event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5404 | return; |
| 5405 | } |
| 5406 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5407 | #ifndef CONFIG_NO_STDOUT_DEBUG |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5408 | if (event == EVENT_RX_MGMT && data->rx_mgmt.frame_len >= 24) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5409 | const struct ieee80211_hdr *hdr; |
| 5410 | u16 fc; |
| 5411 | hdr = (const struct ieee80211_hdr *) data->rx_mgmt.frame; |
| 5412 | fc = le_to_host16(hdr->frame_control); |
| 5413 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 5414 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_BEACON) |
| 5415 | level = MSG_EXCESSIVE; |
| 5416 | } |
| 5417 | |
| 5418 | wpa_dbg(wpa_s, level, "Event %s (%d) received", |
| 5419 | event_to_string(event), event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5420 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5421 | |
| 5422 | switch (event) { |
| 5423 | case EVENT_AUTH: |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5424 | #ifdef CONFIG_FST |
Dmitry Shmidt | 55840ad | 2015-12-14 12:45:46 -0800 | [diff] [blame] | 5425 | if (!wpas_fst_update_mbie(wpa_s, data->auth.ies, |
| 5426 | data->auth.ies_len)) |
| 5427 | wpa_printf(MSG_DEBUG, |
| 5428 | "FST: MB IEs updated from auth IE"); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5429 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5430 | sme_event_auth(wpa_s, data); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5431 | wpa_s->auth_status_code = data->auth.status_code; |
| 5432 | wpas_notify_auth_status_code(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5433 | break; |
| 5434 | case EVENT_ASSOC: |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5435 | #ifdef CONFIG_TESTING_OPTIONS |
| 5436 | if (wpa_s->ignore_auth_resp) { |
| 5437 | wpa_printf(MSG_INFO, |
| 5438 | "EVENT_ASSOC - ignore_auth_resp active!"); |
| 5439 | break; |
| 5440 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5441 | if (wpa_s->testing_resend_assoc) { |
| 5442 | wpa_printf(MSG_INFO, |
| 5443 | "EVENT_DEAUTH - testing_resend_assoc"); |
| 5444 | break; |
| 5445 | } |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5446 | #endif /* CONFIG_TESTING_OPTIONS */ |
Vamsi Krishna | 3481262 | 2020-12-03 22:15:29 +0530 | [diff] [blame] | 5447 | if (wpa_s->disconnected) { |
| 5448 | wpa_printf(MSG_INFO, |
| 5449 | "Ignore unexpected EVENT_ASSOC in disconnected state"); |
| 5450 | break; |
| 5451 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5452 | wpa_supplicant_event_assoc(wpa_s, data); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5453 | wpa_s->assoc_status_code = WLAN_STATUS_SUCCESS; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5454 | if (data && |
| 5455 | (data->assoc_info.authorized || |
| 5456 | (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 5457 | wpa_fils_is_completed(wpa_s->wpa)))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5458 | wpa_supplicant_event_assoc_auth(wpa_s, data); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 5459 | if (data) { |
| 5460 | wpa_msg(wpa_s, MSG_INFO, |
| 5461 | WPA_EVENT_SUBNET_STATUS_UPDATE "status=%u", |
| 5462 | data->assoc_info.subnet_status); |
| 5463 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5464 | break; |
| 5465 | case EVENT_DISASSOC: |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5466 | wpas_event_disassoc(wpa_s, |
| 5467 | data ? &data->disassoc_info : NULL); |
| 5468 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5469 | case EVENT_DEAUTH: |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5470 | #ifdef CONFIG_TESTING_OPTIONS |
| 5471 | if (wpa_s->ignore_auth_resp) { |
| 5472 | wpa_printf(MSG_INFO, |
| 5473 | "EVENT_DEAUTH - ignore_auth_resp active!"); |
| 5474 | break; |
| 5475 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5476 | if (wpa_s->testing_resend_assoc) { |
| 5477 | wpa_printf(MSG_INFO, |
| 5478 | "EVENT_DEAUTH - testing_resend_assoc"); |
| 5479 | break; |
| 5480 | } |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5481 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5482 | wpas_event_deauth(wpa_s, |
| 5483 | data ? &data->deauth_info : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5484 | break; |
| 5485 | case EVENT_MICHAEL_MIC_FAILURE: |
| 5486 | wpa_supplicant_event_michael_mic_failure(wpa_s, data); |
| 5487 | break; |
| 5488 | #ifndef CONFIG_NO_SCAN_PROCESSING |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5489 | case EVENT_SCAN_STARTED: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5490 | if (wpa_s->own_scan_requested || |
| 5491 | (data && !data->scan_info.external_scan)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5492 | struct os_reltime diff; |
| 5493 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5494 | os_get_reltime(&wpa_s->scan_start_time); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5495 | os_reltime_sub(&wpa_s->scan_start_time, |
| 5496 | &wpa_s->scan_trigger_time, &diff); |
| 5497 | wpa_dbg(wpa_s, MSG_DEBUG, "Own scan request started a scan in %ld.%06ld seconds", |
| 5498 | diff.sec, diff.usec); |
| 5499 | wpa_s->own_scan_requested = 0; |
| 5500 | wpa_s->own_scan_running = 1; |
| 5501 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 5502 | wpa_s->manual_scan_use_id) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5503 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 5504 | WPA_EVENT_SCAN_STARTED "id=%u", |
| 5505 | wpa_s->manual_scan_id); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5506 | } else { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5507 | wpa_msg_ctrl(wpa_s, MSG_INFO, |
| 5508 | WPA_EVENT_SCAN_STARTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5509 | } |
| 5510 | } else { |
| 5511 | wpa_dbg(wpa_s, MSG_DEBUG, "External program started a scan"); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5512 | wpa_s->radio->external_scan_req_interface = wpa_s; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5513 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_STARTED); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5514 | } |
| 5515 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5516 | case EVENT_SCAN_RESULTS: |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5517 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 5518 | wpa_s->scan_res_handler = NULL; |
| 5519 | wpa_s->own_scan_running = 0; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5520 | wpa_s->radio->external_scan_req_interface = NULL; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5521 | wpa_s->last_scan_req = NORMAL_SCAN_REQ; |
| 5522 | break; |
| 5523 | } |
| 5524 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5525 | if (!(data && data->scan_info.external_scan) && |
| 5526 | os_reltime_initialized(&wpa_s->scan_start_time)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5527 | struct os_reltime now, diff; |
| 5528 | os_get_reltime(&now); |
| 5529 | os_reltime_sub(&now, &wpa_s->scan_start_time, &diff); |
| 5530 | wpa_s->scan_start_time.sec = 0; |
| 5531 | wpa_s->scan_start_time.usec = 0; |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5532 | wpa_s->wps_scan_done = true; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5533 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan completed in %ld.%06ld seconds", |
| 5534 | diff.sec, diff.usec); |
| 5535 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5536 | if (wpa_supplicant_event_scan_results(wpa_s, data)) |
| 5537 | break; /* interface may have been removed */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5538 | if (!(data && data->scan_info.external_scan)) |
| 5539 | wpa_s->own_scan_running = 0; |
| 5540 | if (data && data->scan_info.nl_scan_event) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5541 | wpa_s->radio->external_scan_req_interface = NULL; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5542 | radio_work_check_next(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5543 | break; |
| 5544 | #endif /* CONFIG_NO_SCAN_PROCESSING */ |
| 5545 | case EVENT_ASSOCINFO: |
| 5546 | wpa_supplicant_event_associnfo(wpa_s, data); |
| 5547 | break; |
| 5548 | case EVENT_INTERFACE_STATUS: |
| 5549 | wpa_supplicant_event_interface_status(wpa_s, data); |
| 5550 | break; |
| 5551 | case EVENT_PMKID_CANDIDATE: |
| 5552 | wpa_supplicant_event_pmkid_candidate(wpa_s, data); |
| 5553 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5554 | #ifdef CONFIG_TDLS |
| 5555 | case EVENT_TDLS: |
| 5556 | wpa_supplicant_event_tdls(wpa_s, data); |
| 5557 | break; |
| 5558 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5559 | #ifdef CONFIG_WNM |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5560 | case EVENT_WNM: |
| 5561 | wpa_supplicant_event_wnm(wpa_s, data); |
| 5562 | break; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5563 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5564 | #ifdef CONFIG_IEEE80211R |
| 5565 | case EVENT_FT_RESPONSE: |
| 5566 | wpa_supplicant_event_ft_response(wpa_s, data); |
| 5567 | break; |
| 5568 | #endif /* CONFIG_IEEE80211R */ |
| 5569 | #ifdef CONFIG_IBSS_RSN |
| 5570 | case EVENT_IBSS_RSN_START: |
| 5571 | wpa_supplicant_event_ibss_rsn_start(wpa_s, data); |
| 5572 | break; |
| 5573 | #endif /* CONFIG_IBSS_RSN */ |
| 5574 | case EVENT_ASSOC_REJECT: |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5575 | wpas_event_assoc_reject(wpa_s, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5576 | break; |
| 5577 | case EVENT_AUTH_TIMED_OUT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5578 | /* It is possible to get this event from earlier connection */ |
| 5579 | if (wpa_s->current_ssid && |
| 5580 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { |
| 5581 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5582 | "Ignore AUTH_TIMED_OUT in mesh configuration"); |
| 5583 | break; |
| 5584 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5585 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 5586 | sme_event_auth_timed_out(wpa_s, data); |
| 5587 | break; |
| 5588 | case EVENT_ASSOC_TIMED_OUT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5589 | /* It is possible to get this event from earlier connection */ |
| 5590 | if (wpa_s->current_ssid && |
| 5591 | wpa_s->current_ssid->mode == WPAS_MODE_MESH) { |
| 5592 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 5593 | "Ignore ASSOC_TIMED_OUT in mesh configuration"); |
| 5594 | break; |
| 5595 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5596 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 5597 | sme_event_assoc_timed_out(wpa_s, data); |
| 5598 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5599 | case EVENT_TX_STATUS: |
| 5600 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS dst=" MACSTR |
| 5601 | " type=%d stype=%d", |
| 5602 | MAC2STR(data->tx_status.dst), |
| 5603 | data->tx_status.type, data->tx_status.stype); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5604 | #ifdef CONFIG_PASN |
| 5605 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 5606 | data->tx_status.stype == WLAN_FC_STYPE_AUTH && |
| 5607 | wpas_pasn_auth_tx_status(wpa_s, data->tx_status.data, |
| 5608 | data->tx_status.data_len, |
| 5609 | data->tx_status.ack) == 0) |
| 5610 | break; |
| 5611 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5612 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5613 | if (wpa_s->ap_iface == NULL) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5614 | #ifdef CONFIG_OFFCHANNEL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 5616 | data->tx_status.stype == WLAN_FC_STYPE_ACTION) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5617 | offchannel_send_action_tx_status( |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5618 | wpa_s, data->tx_status.dst, |
| 5619 | data->tx_status.data, |
| 5620 | data->tx_status.data_len, |
| 5621 | data->tx_status.ack ? |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5622 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
| 5623 | OFFCHANNEL_SEND_ACTION_NO_ACK); |
| 5624 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5625 | break; |
| 5626 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5627 | #endif /* CONFIG_AP */ |
| 5628 | #ifdef CONFIG_OFFCHANNEL |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5629 | wpa_dbg(wpa_s, MSG_DEBUG, "EVENT_TX_STATUS pending_dst=" |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5630 | MACSTR, MAC2STR(wpa_s->p2pdev->pending_action_dst)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5631 | /* |
| 5632 | * Catch TX status events for Action frames we sent via group |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5633 | * interface in GO mode, or via standalone AP interface. |
| 5634 | * Note, wpa_s->p2pdev will be the same as wpa_s->parent, |
| 5635 | * except when the primary interface is used as a GO interface |
| 5636 | * (for drivers which do not have group interface concurrency) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5637 | */ |
| 5638 | if (data->tx_status.type == WLAN_FC_TYPE_MGMT && |
| 5639 | data->tx_status.stype == WLAN_FC_STYPE_ACTION && |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5640 | os_memcmp(wpa_s->p2pdev->pending_action_dst, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5641 | data->tx_status.dst, ETH_ALEN) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5642 | offchannel_send_action_tx_status( |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5643 | wpa_s->p2pdev, data->tx_status.dst, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5644 | data->tx_status.data, |
| 5645 | data->tx_status.data_len, |
| 5646 | data->tx_status.ack ? |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5647 | OFFCHANNEL_SEND_ACTION_SUCCESS : |
| 5648 | OFFCHANNEL_SEND_ACTION_NO_ACK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5649 | break; |
| 5650 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5651 | #endif /* CONFIG_OFFCHANNEL */ |
| 5652 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5653 | switch (data->tx_status.type) { |
| 5654 | case WLAN_FC_TYPE_MGMT: |
| 5655 | ap_mgmt_tx_cb(wpa_s, data->tx_status.data, |
| 5656 | data->tx_status.data_len, |
| 5657 | data->tx_status.stype, |
| 5658 | data->tx_status.ack); |
| 5659 | break; |
| 5660 | case WLAN_FC_TYPE_DATA: |
| 5661 | ap_tx_status(wpa_s, data->tx_status.dst, |
| 5662 | data->tx_status.data, |
| 5663 | data->tx_status.data_len, |
| 5664 | data->tx_status.ack); |
| 5665 | break; |
| 5666 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5667 | #endif /* CONFIG_AP */ |
| 5668 | break; |
| 5669 | #ifdef CONFIG_AP |
| 5670 | case EVENT_EAPOL_TX_STATUS: |
| 5671 | ap_eapol_tx_status(wpa_s, data->eapol_tx_status.dst, |
| 5672 | data->eapol_tx_status.data, |
| 5673 | data->eapol_tx_status.data_len, |
| 5674 | data->eapol_tx_status.ack); |
| 5675 | break; |
| 5676 | case EVENT_DRIVER_CLIENT_POLL_OK: |
| 5677 | ap_client_poll_ok(wpa_s, data->client_poll.addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5678 | break; |
| 5679 | case EVENT_RX_FROM_UNKNOWN: |
| 5680 | if (wpa_s->ap_iface == NULL) |
| 5681 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5682 | ap_rx_from_unknown_sta(wpa_s, data->rx_from_unknown.addr, |
| 5683 | data->rx_from_unknown.wds); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5684 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5685 | #endif /* CONFIG_AP */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5686 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 5687 | case EVENT_LINK_CH_SWITCH_STARTED: |
| 5688 | case EVENT_LINK_CH_SWITCH: |
| 5689 | if (!data || !wpa_s->current_ssid || |
| 5690 | !(wpa_s->valid_links & BIT(data->ch_switch.link_id))) |
| 5691 | break; |
| 5692 | |
| 5693 | wpa_msg(wpa_s, MSG_INFO, |
| 5694 | "%sfreq=%d link_id=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d", |
| 5695 | event == EVENT_LINK_CH_SWITCH ? |
| 5696 | WPA_EVENT_LINK_CHANNEL_SWITCH : |
| 5697 | WPA_EVENT_LINK_CHANNEL_SWITCH_STARTED, |
| 5698 | data->ch_switch.freq, |
| 5699 | data->ch_switch.link_id, |
| 5700 | data->ch_switch.ht_enabled, |
| 5701 | data->ch_switch.ch_offset, |
| 5702 | channel_width_to_string(data->ch_switch.ch_width), |
| 5703 | data->ch_switch.cf1, |
| 5704 | data->ch_switch.cf2); |
| 5705 | if (event == EVENT_LINK_CH_SWITCH_STARTED) |
| 5706 | break; |
| 5707 | |
| 5708 | wpa_s->links[data->ch_switch.link_id].freq = |
| 5709 | data->ch_switch.freq; |
| 5710 | if (wpa_s->links[data->ch_switch.link_id].bss && |
| 5711 | wpa_s->links[data->ch_switch.link_id].bss->freq != |
| 5712 | data->ch_switch.freq) { |
| 5713 | wpa_s->links[data->ch_switch.link_id].bss->freq = |
| 5714 | data->ch_switch.freq; |
| 5715 | notify_bss_changes( |
| 5716 | wpa_s, WPA_BSS_FREQ_CHANGED_FLAG, |
| 5717 | wpa_s->links[data->ch_switch.link_id].bss); |
| 5718 | } |
| 5719 | break; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5720 | case EVENT_CH_SWITCH_STARTED: |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5721 | case EVENT_CH_SWITCH: |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5722 | if (!data || !wpa_s->current_ssid) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5723 | break; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5724 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5725 | wpa_msg(wpa_s, MSG_INFO, |
| 5726 | "%sfreq=%d ht_enabled=%d ch_offset=%d ch_width=%s cf1=%d cf2=%d", |
| 5727 | event == EVENT_CH_SWITCH ? WPA_EVENT_CHANNEL_SWITCH : |
| 5728 | WPA_EVENT_CHANNEL_SWITCH_STARTED, |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 5729 | data->ch_switch.freq, |
| 5730 | data->ch_switch.ht_enabled, |
| 5731 | data->ch_switch.ch_offset, |
| 5732 | channel_width_to_string(data->ch_switch.ch_width), |
| 5733 | data->ch_switch.cf1, |
| 5734 | data->ch_switch.cf2); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5735 | if (event == EVENT_CH_SWITCH_STARTED) |
| 5736 | break; |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 5737 | |
Sunil Ravi | 65a724b | 2022-05-24 11:06:09 -0700 | [diff] [blame] | 5738 | if (wpa_s->assoc_freq && data->ch_switch.freq && |
| 5739 | (int) wpa_s->assoc_freq != data->ch_switch.freq) { |
| 5740 | wpas_notify_frequency_changed(wpa_s, data->ch_switch.freq); |
| 5741 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5742 | wpa_s->assoc_freq = data->ch_switch.freq; |
| 5743 | wpa_s->current_ssid->frequency = data->ch_switch.freq; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5744 | if (wpa_s->current_bss && |
| 5745 | wpa_s->current_bss->freq != data->ch_switch.freq) { |
| 5746 | wpa_s->current_bss->freq = data->ch_switch.freq; |
| 5747 | notify_bss_changes(wpa_s, WPA_BSS_FREQ_CHANGED_FLAG, |
| 5748 | wpa_s->current_bss); |
| 5749 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5750 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5751 | #ifdef CONFIG_SME |
| 5752 | switch (data->ch_switch.ch_offset) { |
| 5753 | case 1: |
| 5754 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_ABOVE; |
| 5755 | break; |
| 5756 | case -1: |
| 5757 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_BELOW; |
| 5758 | break; |
| 5759 | default: |
| 5760 | wpa_s->sme.ht_sec_chan = HT_SEC_CHAN_UNKNOWN; |
| 5761 | break; |
| 5762 | } |
| 5763 | #endif /* CONFIG_SME */ |
| 5764 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5765 | #ifdef CONFIG_AP |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5766 | if (wpa_s->current_ssid->mode == WPAS_MODE_AP || |
| 5767 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO || |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5768 | wpa_s->current_ssid->mode == WPAS_MODE_MESH || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5769 | wpa_s->current_ssid->mode == |
| 5770 | WPAS_MODE_P2P_GROUP_FORMATION) { |
| 5771 | wpas_ap_ch_switch(wpa_s, data->ch_switch.freq, |
| 5772 | data->ch_switch.ht_enabled, |
| 5773 | data->ch_switch.ch_offset, |
| 5774 | data->ch_switch.ch_width, |
| 5775 | data->ch_switch.cf1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5776 | data->ch_switch.cf2, |
Sunil Ravi | 036cec5 | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 5777 | data->ch_switch.punct_bitmap, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5778 | 1); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5779 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5780 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5781 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5782 | if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) |
| 5783 | sme_event_ch_switch(wpa_s); |
| 5784 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5785 | wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_CS); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 5786 | wnm_clear_coloc_intf_reporting(wpa_s); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5787 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5788 | #ifdef CONFIG_AP |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5789 | #ifdef NEED_AP_MLME |
| 5790 | case EVENT_DFS_RADAR_DETECTED: |
| 5791 | if (data) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5792 | wpas_ap_event_dfs_radar_detected(wpa_s, |
| 5793 | &data->dfs_event); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5794 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5795 | case EVENT_DFS_NOP_FINISHED: |
| 5796 | if (data) |
| 5797 | wpas_ap_event_dfs_cac_nop_finished(wpa_s, |
| 5798 | &data->dfs_event); |
| 5799 | break; |
| 5800 | #endif /* NEED_AP_MLME */ |
| 5801 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5802 | case EVENT_DFS_CAC_STARTED: |
| 5803 | if (data) |
| 5804 | wpas_event_dfs_cac_started(wpa_s, &data->dfs_event); |
| 5805 | break; |
| 5806 | case EVENT_DFS_CAC_FINISHED: |
| 5807 | if (data) |
| 5808 | wpas_event_dfs_cac_finished(wpa_s, &data->dfs_event); |
| 5809 | break; |
| 5810 | case EVENT_DFS_CAC_ABORTED: |
| 5811 | if (data) |
| 5812 | wpas_event_dfs_cac_aborted(wpa_s, &data->dfs_event); |
| 5813 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5814 | case EVENT_RX_MGMT: { |
| 5815 | u16 fc, stype; |
| 5816 | const struct ieee80211_mgmt *mgmt; |
| 5817 | |
Dmitry Shmidt | 818ea48 | 2014-03-10 13:15:21 -0700 | [diff] [blame] | 5818 | #ifdef CONFIG_TESTING_OPTIONS |
| 5819 | if (wpa_s->ext_mgmt_frame_handling) { |
| 5820 | struct rx_mgmt *rx = &data->rx_mgmt; |
| 5821 | size_t hex_len = 2 * rx->frame_len + 1; |
| 5822 | char *hex = os_malloc(hex_len); |
| 5823 | if (hex) { |
| 5824 | wpa_snprintf_hex(hex, hex_len, |
| 5825 | rx->frame, rx->frame_len); |
| 5826 | wpa_msg(wpa_s, MSG_INFO, "MGMT-RX freq=%d datarate=%u ssi_signal=%d %s", |
| 5827 | rx->freq, rx->datarate, rx->ssi_signal, |
| 5828 | hex); |
| 5829 | os_free(hex); |
| 5830 | } |
| 5831 | break; |
| 5832 | } |
| 5833 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 5834 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5835 | mgmt = (const struct ieee80211_mgmt *) |
| 5836 | data->rx_mgmt.frame; |
| 5837 | fc = le_to_host16(mgmt->frame_control); |
| 5838 | stype = WLAN_FC_GET_STYPE(fc); |
| 5839 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5840 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5841 | if (wpa_s->ap_iface == NULL) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5842 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5843 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5844 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5845 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5846 | const u8 *src = mgmt->sa; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5847 | const u8 *ie; |
| 5848 | size_t ie_len; |
| 5849 | |
| 5850 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; |
| 5851 | ie_len = data->rx_mgmt.frame_len - |
| 5852 | IEEE80211_HDRLEN; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5853 | wpas_p2p_probe_req_rx( |
| 5854 | wpa_s, src, mgmt->da, |
| 5855 | mgmt->bssid, ie, ie_len, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5856 | data->rx_mgmt.freq, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5857 | data->rx_mgmt.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5858 | break; |
| 5859 | } |
| 5860 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5861 | #ifdef CONFIG_IBSS_RSN |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5862 | if (wpa_s->current_ssid && |
| 5863 | wpa_s->current_ssid->mode == WPAS_MODE_IBSS && |
| 5864 | stype == WLAN_FC_STYPE_AUTH && |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5865 | data->rx_mgmt.frame_len >= 30) { |
| 5866 | wpa_supplicant_event_ibss_auth(wpa_s, data); |
| 5867 | break; |
| 5868 | } |
| 5869 | #endif /* CONFIG_IBSS_RSN */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5870 | |
| 5871 | if (stype == WLAN_FC_STYPE_ACTION) { |
| 5872 | wpas_event_rx_mgmt_action( |
Dmitry Shmidt | 623d63a | 2014-06-13 11:05:14 -0700 | [diff] [blame] | 5873 | wpa_s, data->rx_mgmt.frame, |
| 5874 | data->rx_mgmt.frame_len, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5875 | data->rx_mgmt.freq, |
| 5876 | data->rx_mgmt.ssi_signal); |
| 5877 | break; |
| 5878 | } |
| 5879 | |
| 5880 | if (wpa_s->ifmsh) { |
| 5881 | mesh_mpm_mgmt_rx(wpa_s, &data->rx_mgmt); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5882 | break; |
| 5883 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5884 | #ifdef CONFIG_PASN |
| 5885 | if (stype == WLAN_FC_STYPE_AUTH && |
| 5886 | wpas_pasn_auth_rx(wpa_s, mgmt, |
| 5887 | data->rx_mgmt.frame_len) != -2) |
| 5888 | break; |
| 5889 | #endif /* CONFIG_PASN */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5890 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5891 | #ifdef CONFIG_SAE |
| 5892 | if (stype == WLAN_FC_STYPE_AUTH && |
| 5893 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) && |
| 5894 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE)) { |
| 5895 | sme_external_auth_mgmt_rx( |
| 5896 | wpa_s, data->rx_mgmt.frame, |
| 5897 | data->rx_mgmt.frame_len); |
| 5898 | break; |
| 5899 | } |
| 5900 | #endif /* CONFIG_SAE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5901 | wpa_dbg(wpa_s, MSG_DEBUG, "AP: ignore received " |
| 5902 | "management frame in non-AP mode"); |
| 5903 | break; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5904 | #ifdef CONFIG_AP |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5905 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5906 | |
| 5907 | if (stype == WLAN_FC_STYPE_PROBE_REQ && |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5908 | data->rx_mgmt.frame_len > IEEE80211_HDRLEN) { |
| 5909 | const u8 *ie; |
| 5910 | size_t ie_len; |
| 5911 | |
| 5912 | ie = data->rx_mgmt.frame + IEEE80211_HDRLEN; |
| 5913 | ie_len = data->rx_mgmt.frame_len - IEEE80211_HDRLEN; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5914 | |
| 5915 | wpas_notify_preq(wpa_s, mgmt->sa, mgmt->da, |
| 5916 | mgmt->bssid, ie, ie_len, |
| 5917 | data->rx_mgmt.ssi_signal); |
| 5918 | } |
| 5919 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5920 | ap_mgmt_rx(wpa_s, &data->rx_mgmt); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5921 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5922 | break; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5923 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5924 | case EVENT_RX_PROBE_REQ: |
| 5925 | if (data->rx_probe_req.sa == NULL || |
| 5926 | data->rx_probe_req.ie == NULL) |
| 5927 | break; |
| 5928 | #ifdef CONFIG_AP |
| 5929 | if (wpa_s->ap_iface) { |
| 5930 | hostapd_probe_req_rx(wpa_s->ap_iface->bss[0], |
| 5931 | data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5932 | data->rx_probe_req.da, |
| 5933 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5934 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5935 | data->rx_probe_req.ie_len, |
| 5936 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5937 | break; |
| 5938 | } |
| 5939 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5940 | wpas_p2p_probe_req_rx(wpa_s, data->rx_probe_req.sa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5941 | data->rx_probe_req.da, |
| 5942 | data->rx_probe_req.bssid, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5943 | data->rx_probe_req.ie, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5944 | data->rx_probe_req.ie_len, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 5945 | 0, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5946 | data->rx_probe_req.ssi_signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5947 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | case EVENT_REMAIN_ON_CHANNEL: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5949 | #ifdef CONFIG_OFFCHANNEL |
| 5950 | offchannel_remain_on_channel_cb( |
| 5951 | wpa_s, data->remain_on_channel.freq, |
| 5952 | data->remain_on_channel.duration); |
| 5953 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5954 | wpas_p2p_remain_on_channel_cb( |
| 5955 | wpa_s, data->remain_on_channel.freq, |
| 5956 | data->remain_on_channel.duration); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5957 | #ifdef CONFIG_DPP |
| 5958 | wpas_dpp_remain_on_channel_cb( |
| 5959 | wpa_s, data->remain_on_channel.freq, |
| 5960 | data->remain_on_channel.duration); |
| 5961 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5962 | break; |
| 5963 | case EVENT_CANCEL_REMAIN_ON_CHANNEL: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5964 | #ifdef CONFIG_OFFCHANNEL |
| 5965 | offchannel_cancel_remain_on_channel_cb( |
| 5966 | wpa_s, data->remain_on_channel.freq); |
| 5967 | #endif /* CONFIG_OFFCHANNEL */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5968 | wpas_p2p_cancel_remain_on_channel_cb( |
| 5969 | wpa_s, data->remain_on_channel.freq); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5970 | #ifdef CONFIG_DPP |
| 5971 | wpas_dpp_cancel_remain_on_channel_cb( |
| 5972 | wpa_s, data->remain_on_channel.freq); |
| 5973 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5974 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5975 | case EVENT_EAPOL_RX: |
| 5976 | wpa_supplicant_rx_eapol(wpa_s, data->eapol_rx.src, |
| 5977 | data->eapol_rx.data, |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 5978 | data->eapol_rx.data_len, |
| 5979 | data->eapol_rx.encrypted); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5980 | break; |
| 5981 | case EVENT_SIGNAL_CHANGE: |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 5982 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SIGNAL_CHANGE |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5983 | "above=%d signal=%d noise=%d txrate=%lu", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 5984 | data->signal_change.above_threshold, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5985 | data->signal_change.data.signal, |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 5986 | data->signal_change.current_noise, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5987 | data->signal_change.data.current_tx_rate); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5988 | wpa_bss_update_level(wpa_s->current_bss, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5989 | data->signal_change.data.signal); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5990 | bgscan_notify_signal_change( |
| 5991 | wpa_s, data->signal_change.above_threshold, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5992 | data->signal_change.data.signal, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5993 | data->signal_change.current_noise, |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 5994 | data->signal_change.data.current_tx_rate); |
| 5995 | os_memcpy(&wpa_s->last_signal_info, data, |
| 5996 | sizeof(struct wpa_signal_info)); |
| 5997 | wpas_notify_signal_change(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5998 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5999 | case EVENT_INTERFACE_MAC_CHANGED: |
| 6000 | wpa_supplicant_update_mac_addr(wpa_s); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6001 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6002 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6003 | case EVENT_INTERFACE_ENABLED: |
| 6004 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was enabled"); |
| 6005 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6006 | u8 addr[ETH_ALEN]; |
| 6007 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6008 | eloop_cancel_timeout(wpas_clear_disabled_interface, |
| 6009 | wpa_s, NULL); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6010 | os_memcpy(addr, wpa_s->own_addr, ETH_ALEN); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6011 | wpa_supplicant_update_mac_addr(wpa_s); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6012 | if (os_memcmp(addr, wpa_s->own_addr, ETH_ALEN) != 0) |
| 6013 | wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL); |
| 6014 | else |
| 6015 | wpa_sm_pmksa_cache_reconfig(wpa_s->wpa); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6016 | wpa_supplicant_set_default_scan_ies(wpa_s); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6017 | if (wpa_s->p2p_mgmt) { |
| 6018 | wpa_supplicant_set_state(wpa_s, |
| 6019 | WPA_DISCONNECTED); |
| 6020 | break; |
| 6021 | } |
| 6022 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6023 | #ifdef CONFIG_AP |
| 6024 | if (!wpa_s->ap_iface) { |
| 6025 | wpa_supplicant_set_state(wpa_s, |
| 6026 | WPA_DISCONNECTED); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6027 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6028 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 6029 | } else |
| 6030 | wpa_supplicant_set_state(wpa_s, |
| 6031 | WPA_COMPLETED); |
| 6032 | #else /* CONFIG_AP */ |
| 6033 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 6034 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 6035 | #endif /* CONFIG_AP */ |
| 6036 | } |
| 6037 | break; |
| 6038 | case EVENT_INTERFACE_DISABLED: |
| 6039 | wpa_dbg(wpa_s, MSG_DEBUG, "Interface was disabled"); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6040 | #ifdef CONFIG_P2P |
| 6041 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_GO || |
| 6042 | (wpa_s->current_ssid && wpa_s->current_ssid->p2p_group && |
| 6043 | wpa_s->current_ssid->mode == WPAS_MODE_P2P_GO)) { |
| 6044 | /* |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6045 | * Mark interface disabled if this happens to end up not |
| 6046 | * being removed as a separate P2P group interface. |
| 6047 | */ |
| 6048 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
| 6049 | /* |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6050 | * The interface was externally disabled. Remove |
| 6051 | * it assuming an external entity will start a |
| 6052 | * new session if needed. |
| 6053 | */ |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6054 | if (wpa_s->current_ssid && |
| 6055 | wpa_s->current_ssid->p2p_group) |
| 6056 | wpas_p2p_interface_unavailable(wpa_s); |
| 6057 | else |
| 6058 | wpas_p2p_disconnect(wpa_s); |
| 6059 | /* |
| 6060 | * wpa_s instance may have been freed, so must not use |
| 6061 | * it here anymore. |
| 6062 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6063 | break; |
| 6064 | } |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 6065 | if (wpa_s->p2p_scan_work && wpa_s->global->p2p && |
| 6066 | p2p_in_progress(wpa_s->global->p2p) > 1) { |
| 6067 | /* This radio work will be cancelled, so clear P2P |
| 6068 | * state as well. |
| 6069 | */ |
| 6070 | p2p_stop_find(wpa_s->global->p2p); |
| 6071 | } |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6072 | #endif /* CONFIG_P2P */ |
| 6073 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6074 | if (wpa_s->wpa_state >= WPA_AUTHENTICATING) { |
| 6075 | /* |
| 6076 | * Indicate disconnection to keep ctrl_iface events |
| 6077 | * consistent. |
| 6078 | */ |
| 6079 | wpa_supplicant_event_disassoc( |
| 6080 | wpa_s, WLAN_REASON_DEAUTH_LEAVING, 1); |
| 6081 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6082 | wpa_supplicant_mark_disassoc(wpa_s); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6083 | os_reltime_age(&wpa_s->last_scan, &age); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6084 | if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) { |
| 6085 | clear_at.sec = wpa_s->conf->scan_res_valid_for_connect; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6086 | clear_at.usec = 0; |
| 6087 | } else { |
| 6088 | struct os_reltime tmp; |
| 6089 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6090 | tmp.sec = wpa_s->conf->scan_res_valid_for_connect; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6091 | tmp.usec = 0; |
| 6092 | os_reltime_sub(&tmp, &age, &clear_at); |
| 6093 | } |
| 6094 | eloop_register_timeout(clear_at.sec, clear_at.usec, |
| 6095 | wpas_clear_disabled_interface, |
| 6096 | wpa_s, NULL); |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 6097 | radio_remove_works(wpa_s, NULL, 0); |
| 6098 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6099 | wpa_supplicant_set_state(wpa_s, WPA_INTERFACE_DISABLED); |
| 6100 | break; |
| 6101 | case EVENT_CHANNEL_LIST_CHANGED: |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 6102 | wpa_supplicant_update_channel_list( |
| 6103 | wpa_s, &data->channel_list_changed); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6104 | break; |
| 6105 | case EVENT_INTERFACE_UNAVAILABLE: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | wpas_p2p_interface_unavailable(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6107 | break; |
| 6108 | case EVENT_BEST_CHANNEL: |
| 6109 | wpa_dbg(wpa_s, MSG_DEBUG, "Best channel event received " |
| 6110 | "(%d %d %d)", |
| 6111 | data->best_chan.freq_24, data->best_chan.freq_5, |
| 6112 | data->best_chan.freq_overall); |
| 6113 | wpa_s->best_24_freq = data->best_chan.freq_24; |
| 6114 | wpa_s->best_5_freq = data->best_chan.freq_5; |
| 6115 | wpa_s->best_overall_freq = data->best_chan.freq_overall; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6116 | wpas_p2p_update_best_channels(wpa_s, data->best_chan.freq_24, |
| 6117 | data->best_chan.freq_5, |
| 6118 | data->best_chan.freq_overall); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6119 | break; |
| 6120 | case EVENT_UNPROT_DEAUTH: |
| 6121 | wpa_supplicant_event_unprot_deauth(wpa_s, |
| 6122 | &data->unprot_deauth); |
| 6123 | break; |
| 6124 | case EVENT_UNPROT_DISASSOC: |
| 6125 | wpa_supplicant_event_unprot_disassoc(wpa_s, |
| 6126 | &data->unprot_disassoc); |
| 6127 | break; |
| 6128 | case EVENT_STATION_LOW_ACK: |
| 6129 | #ifdef CONFIG_AP |
| 6130 | if (wpa_s->ap_iface && data) |
| 6131 | hostapd_event_sta_low_ack(wpa_s->ap_iface->bss[0], |
| 6132 | data->low_ack.addr); |
| 6133 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6134 | #ifdef CONFIG_TDLS |
| 6135 | if (data) |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6136 | wpa_tdls_disable_unreachable_link(wpa_s->wpa, |
| 6137 | data->low_ack.addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6138 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6139 | break; |
| 6140 | case EVENT_IBSS_PEER_LOST: |
| 6141 | #ifdef CONFIG_IBSS_RSN |
| 6142 | ibss_rsn_stop(wpa_s->ibss_rsn, data->ibss_peer_lost.peer); |
| 6143 | #endif /* CONFIG_IBSS_RSN */ |
| 6144 | break; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6145 | case EVENT_DRIVER_GTK_REKEY: |
| 6146 | if (os_memcmp(data->driver_gtk_rekey.bssid, |
| 6147 | wpa_s->bssid, ETH_ALEN)) |
| 6148 | break; |
| 6149 | if (!wpa_s->wpa) |
| 6150 | break; |
| 6151 | wpa_sm_update_replay_ctr(wpa_s->wpa, |
| 6152 | data->driver_gtk_rekey.replay_ctr); |
| 6153 | break; |
| 6154 | case EVENT_SCHED_SCAN_STOPPED: |
| 6155 | wpa_s->sched_scanning = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6156 | resched = wpa_s->scanning && wpas_scan_scheduled(wpa_s); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6157 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 6158 | |
| 6159 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) |
| 6160 | break; |
| 6161 | |
| 6162 | /* |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6163 | * If the driver stopped scanning without being requested to, |
| 6164 | * request a new scan to continue scanning for networks. |
| 6165 | */ |
| 6166 | if (!wpa_s->sched_scan_stop_req && |
| 6167 | wpa_s->wpa_state == WPA_SCANNING) { |
| 6168 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6169 | "Restart scanning after unexpected sched_scan stop event"); |
| 6170 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
| 6171 | break; |
| 6172 | } |
| 6173 | |
| 6174 | wpa_s->sched_scan_stop_req = 0; |
| 6175 | |
| 6176 | /* |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 6177 | * Start a new sched scan to continue searching for more SSIDs |
| 6178 | * either if timed out or PNO schedule scan is pending. |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6179 | */ |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 6180 | if (wpa_s->sched_scan_timed_out) { |
| 6181 | wpa_supplicant_req_sched_scan(wpa_s); |
| 6182 | } else if (wpa_s->pno_sched_pending) { |
| 6183 | wpa_s->pno_sched_pending = 0; |
| 6184 | wpas_start_pno(wpa_s); |
Dmitry Shmidt | af9da31 | 2015-04-03 10:03:11 -0700 | [diff] [blame] | 6185 | } else if (resched) { |
| 6186 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 6187 | } |
| 6188 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6189 | break; |
| 6190 | case EVENT_WPS_BUTTON_PUSHED: |
| 6191 | #ifdef CONFIG_WPS |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6192 | wpas_wps_start_pbc(wpa_s, NULL, 0, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6193 | #endif /* CONFIG_WPS */ |
| 6194 | break; |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 6195 | case EVENT_AVOID_FREQUENCIES: |
| 6196 | wpa_supplicant_notify_avoid_freq(wpa_s, data); |
| 6197 | break; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 6198 | case EVENT_CONNECT_FAILED_REASON: |
| 6199 | #ifdef CONFIG_AP |
| 6200 | if (!wpa_s->ap_iface || !data) |
| 6201 | break; |
| 6202 | hostapd_event_connect_failed_reason( |
| 6203 | wpa_s->ap_iface->bss[0], |
| 6204 | data->connect_failed_reason.addr, |
| 6205 | data->connect_failed_reason.code); |
| 6206 | #endif /* CONFIG_AP */ |
| 6207 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6208 | case EVENT_NEW_PEER_CANDIDATE: |
| 6209 | #ifdef CONFIG_MESH |
| 6210 | if (!wpa_s->ifmsh || !data) |
| 6211 | break; |
| 6212 | wpa_mesh_notify_peer(wpa_s, data->mesh_peer.peer, |
| 6213 | data->mesh_peer.ies, |
| 6214 | data->mesh_peer.ie_len); |
| 6215 | #endif /* CONFIG_MESH */ |
| 6216 | break; |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 6217 | case EVENT_SURVEY: |
| 6218 | #ifdef CONFIG_AP |
| 6219 | if (!wpa_s->ap_iface) |
| 6220 | break; |
| 6221 | hostapd_event_get_survey(wpa_s->ap_iface, |
| 6222 | &data->survey_results); |
| 6223 | #endif /* CONFIG_AP */ |
| 6224 | break; |
| 6225 | case EVENT_ACS_CHANNEL_SELECTED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6226 | #ifdef CONFIG_AP |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 6227 | #ifdef CONFIG_ACS |
| 6228 | if (!wpa_s->ap_iface) |
| 6229 | break; |
| 6230 | hostapd_acs_channel_selected(wpa_s->ap_iface->bss[0], |
| 6231 | &data->acs_selected_channels); |
| 6232 | #endif /* CONFIG_ACS */ |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6233 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 6234 | break; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 6235 | case EVENT_P2P_LO_STOP: |
| 6236 | #ifdef CONFIG_P2P |
| 6237 | wpa_s->p2p_lo_started = 0; |
| 6238 | wpa_msg(wpa_s, MSG_INFO, P2P_EVENT_LISTEN_OFFLOAD_STOP |
| 6239 | P2P_LISTEN_OFFLOAD_STOP_REASON "reason=%d", |
| 6240 | data->p2p_lo_stop.reason_code); |
| 6241 | #endif /* CONFIG_P2P */ |
| 6242 | break; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6243 | case EVENT_BEACON_LOSS: |
| 6244 | if (!wpa_s->current_bss || !wpa_s->current_ssid) |
| 6245 | break; |
| 6246 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_BEACON_LOSS); |
| 6247 | bgscan_notify_beacon_loss(wpa_s); |
| 6248 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6249 | case EVENT_EXTERNAL_AUTH: |
| 6250 | #ifdef CONFIG_SAE |
| 6251 | if (!wpa_s->current_ssid) { |
| 6252 | wpa_printf(MSG_DEBUG, "SAE: current_ssid is NULL"); |
| 6253 | break; |
| 6254 | } |
| 6255 | sme_external_auth_trigger(wpa_s, data); |
| 6256 | #endif /* CONFIG_SAE */ |
| 6257 | break; |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 6258 | #ifdef CONFIG_PASN |
| 6259 | case EVENT_PASN_AUTH: |
| 6260 | wpas_pasn_auth_trigger(wpa_s, &data->pasn_auth); |
| 6261 | break; |
| 6262 | #endif /* CONFIG_PASN */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6263 | case EVENT_PORT_AUTHORIZED: |
Sunil Ravi | 77d572f | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 6264 | #ifndef CONFIG_NO_WPA |
| 6265 | if (data->port_authorized.td_bitmap_len) { |
| 6266 | wpa_printf(MSG_DEBUG, |
| 6267 | "WPA3: Transition Disable bitmap from the driver event: 0x%x", |
| 6268 | data->port_authorized.td_bitmap[0]); |
| 6269 | wpas_transition_disable( |
| 6270 | wpa_s, data->port_authorized.td_bitmap[0]); |
| 6271 | } |
| 6272 | #endif /* CONFIG_NO_WPA */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6273 | wpa_supplicant_event_port_authorized(wpa_s); |
| 6274 | break; |
| 6275 | case EVENT_STATION_OPMODE_CHANGED: |
| 6276 | #ifdef CONFIG_AP |
| 6277 | if (!wpa_s->ap_iface || !data) |
| 6278 | break; |
| 6279 | |
| 6280 | hostapd_event_sta_opmode_changed(wpa_s->ap_iface->bss[0], |
| 6281 | data->sta_opmode.addr, |
| 6282 | data->sta_opmode.smps_mode, |
| 6283 | data->sta_opmode.chan_width, |
| 6284 | data->sta_opmode.rx_nss); |
| 6285 | #endif /* CONFIG_AP */ |
| 6286 | break; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6287 | case EVENT_UNPROT_BEACON: |
| 6288 | wpas_event_unprot_beacon(wpa_s, &data->unprot_beacon); |
| 6289 | break; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6290 | case EVENT_TX_WAIT_EXPIRE: |
| 6291 | #ifdef CONFIG_DPP |
| 6292 | wpas_dpp_tx_wait_expire(wpa_s); |
| 6293 | #endif /* CONFIG_DPP */ |
| 6294 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6295 | default: |
| 6296 | wpa_msg(wpa_s, MSG_INFO, "Unknown event %d", event); |
| 6297 | break; |
| 6298 | } |
| 6299 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6300 | |
| 6301 | |
| 6302 | void wpa_supplicant_event_global(void *ctx, enum wpa_event_type event, |
| 6303 | union wpa_event_data *data) |
| 6304 | { |
| 6305 | struct wpa_supplicant *wpa_s; |
| 6306 | |
| 6307 | if (event != EVENT_INTERFACE_STATUS) |
| 6308 | return; |
| 6309 | |
| 6310 | wpa_s = wpa_supplicant_get_iface(ctx, data->interface_status.ifname); |
| 6311 | if (wpa_s && wpa_s->driver->get_ifindex) { |
| 6312 | unsigned int ifindex; |
| 6313 | |
| 6314 | ifindex = wpa_s->driver->get_ifindex(wpa_s->drv_priv); |
| 6315 | if (ifindex != data->interface_status.ifindex) { |
| 6316 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 6317 | "interface status ifindex %d mismatch (%d)", |
| 6318 | ifindex, data->interface_status.ifindex); |
| 6319 | return; |
| 6320 | } |
| 6321 | } |
| 6322 | #ifdef CONFIG_MATCH_IFACE |
| 6323 | else if (data->interface_status.ievent == EVENT_INTERFACE_ADDED) { |
| 6324 | struct wpa_interface *wpa_i; |
| 6325 | |
| 6326 | wpa_i = wpa_supplicant_match_iface( |
| 6327 | ctx, data->interface_status.ifname); |
| 6328 | if (!wpa_i) |
| 6329 | return; |
| 6330 | wpa_s = wpa_supplicant_add_iface(ctx, wpa_i, NULL); |
| 6331 | os_free(wpa_i); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6332 | } |
| 6333 | #endif /* CONFIG_MATCH_IFACE */ |
| 6334 | |
| 6335 | if (wpa_s) |
| 6336 | wpa_supplicant_event(wpa_s, event, data); |
| 6337 | } |