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