Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * WPA Supplicant - Scanning |
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 "utils/includes.h" |
| 10 | |
| 11 | #include "utils/common.h" |
| 12 | #include "utils/eloop.h" |
| 13 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 3a787e6 | 2013-01-17 10:32:35 -0800 | [diff] [blame] | 14 | #include "common/wpa_ctrl.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | #include "config.h" |
| 16 | #include "wpa_supplicant_i.h" |
| 17 | #include "driver_i.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include "wps_supplicant.h" |
| 19 | #include "p2p_supplicant.h" |
| 20 | #include "p2p/p2p.h" |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 21 | #include "hs20_supplicant.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include "notify.h" |
| 23 | #include "bss.h" |
| 24 | #include "scan.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 25 | #include "mesh.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 26 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 27 | static struct wpabuf * wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s); |
| 28 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 29 | |
| 30 | static void wpa_supplicant_gen_assoc_event(struct wpa_supplicant *wpa_s) |
| 31 | { |
| 32 | struct wpa_ssid *ssid; |
| 33 | union wpa_event_data data; |
| 34 | |
| 35 | ssid = wpa_supplicant_get_ssid(wpa_s); |
| 36 | if (ssid == NULL) |
| 37 | return; |
| 38 | |
| 39 | if (wpa_s->current_ssid == NULL) { |
| 40 | wpa_s->current_ssid = ssid; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 41 | wpas_notify_network_changed(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 42 | } |
| 43 | wpa_supplicant_initiate_eapol(wpa_s); |
| 44 | wpa_dbg(wpa_s, MSG_DEBUG, "Already associated with a configured " |
| 45 | "network - generating associated event"); |
| 46 | os_memset(&data, 0, sizeof(data)); |
| 47 | wpa_supplicant_event(wpa_s, EVENT_ASSOC, &data); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | #ifdef CONFIG_WPS |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 52 | static int wpas_wps_in_use(struct wpa_supplicant *wpa_s, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 53 | enum wps_request_type *req_type) |
| 54 | { |
| 55 | struct wpa_ssid *ssid; |
| 56 | int wps = 0; |
| 57 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 58 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 59 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_WPS)) |
| 60 | continue; |
| 61 | |
| 62 | wps = 1; |
| 63 | *req_type = wpas_wps_get_req_type(ssid); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 64 | if (ssid->eap.phase1 && os_strstr(ssid->eap.phase1, "pbc=1")) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 65 | return 2; |
| 66 | } |
| 67 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 68 | #ifdef CONFIG_P2P |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 69 | if (!wpa_s->global->p2p_disabled && wpa_s->global->p2p && |
| 70 | !wpa_s->conf->p2p_disabled) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 71 | wpa_s->wps->dev.p2p = 1; |
| 72 | if (!wps) { |
| 73 | wps = 1; |
| 74 | *req_type = WPS_REQ_ENROLLEE_INFO; |
| 75 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 76 | } |
| 77 | #endif /* CONFIG_P2P */ |
| 78 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 79 | return wps; |
| 80 | } |
| 81 | #endif /* CONFIG_WPS */ |
| 82 | |
| 83 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 84 | static int wpa_setup_mac_addr_rand_params(struct wpa_driver_scan_params *params, |
| 85 | const u8 *mac_addr) |
| 86 | { |
| 87 | u8 *tmp; |
| 88 | |
| 89 | if (params->mac_addr) { |
| 90 | params->mac_addr_mask = NULL; |
| 91 | os_free(params->mac_addr); |
| 92 | params->mac_addr = NULL; |
| 93 | } |
| 94 | |
| 95 | params->mac_addr_rand = 1; |
| 96 | |
| 97 | if (!mac_addr) |
| 98 | return 0; |
| 99 | |
| 100 | tmp = os_malloc(2 * ETH_ALEN); |
| 101 | if (!tmp) |
| 102 | return -1; |
| 103 | |
| 104 | os_memcpy(tmp, mac_addr, 2 * ETH_ALEN); |
| 105 | params->mac_addr = tmp; |
| 106 | params->mac_addr_mask = tmp + ETH_ALEN; |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 111 | /** |
| 112 | * wpa_supplicant_enabled_networks - Check whether there are enabled networks |
| 113 | * @wpa_s: Pointer to wpa_supplicant data |
| 114 | * Returns: 0 if no networks are enabled, >0 if networks are enabled |
| 115 | * |
| 116 | * This function is used to figure out whether any networks (or Interworking |
| 117 | * with enabled credentials and auto_interworking) are present in the current |
| 118 | * configuration. |
| 119 | */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 120 | int wpa_supplicant_enabled_networks(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 121 | { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 122 | struct wpa_ssid *ssid = wpa_s->conf->ssid; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 123 | int count = 0, disabled = 0; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 124 | |
| 125 | if (wpa_s->p2p_mgmt) |
| 126 | return 0; /* no normal network profiles on p2p_mgmt interface */ |
| 127 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 128 | while (ssid) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 129 | if (!wpas_network_disabled(wpa_s, ssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 130 | count++; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 131 | else |
| 132 | disabled++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 133 | ssid = ssid->next; |
| 134 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 135 | if (wpa_s->conf->cred && wpa_s->conf->interworking && |
| 136 | wpa_s->conf->auto_interworking) |
| 137 | count++; |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 138 | if (count == 0 && disabled > 0) { |
| 139 | wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks (%d disabled " |
| 140 | "networks)", disabled); |
| 141 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 142 | return count; |
| 143 | } |
| 144 | |
| 145 | |
| 146 | static void wpa_supplicant_assoc_try(struct wpa_supplicant *wpa_s, |
| 147 | struct wpa_ssid *ssid) |
| 148 | { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 149 | int min_temp_disabled = 0; |
| 150 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 151 | while (ssid) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 152 | if (!wpas_network_disabled(wpa_s, ssid)) { |
| 153 | int temp_disabled = wpas_temp_disabled(wpa_s, ssid); |
| 154 | |
| 155 | if (temp_disabled <= 0) |
| 156 | break; |
| 157 | |
| 158 | if (!min_temp_disabled || |
| 159 | temp_disabled < min_temp_disabled) |
| 160 | min_temp_disabled = temp_disabled; |
| 161 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 162 | ssid = ssid->next; |
| 163 | } |
| 164 | |
| 165 | /* ap_scan=2 mode - try to associate with each SSID. */ |
| 166 | if (ssid == NULL) { |
| 167 | wpa_dbg(wpa_s, MSG_DEBUG, "wpa_supplicant_assoc_try: Reached " |
| 168 | "end of scan list - go back to beginning"); |
| 169 | wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 170 | wpa_supplicant_req_scan(wpa_s, min_temp_disabled, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | if (ssid->next) { |
| 174 | /* Continue from the next SSID on the next attempt. */ |
| 175 | wpa_s->prev_scan_ssid = ssid; |
| 176 | } else { |
| 177 | /* Start from the beginning of the SSID list. */ |
| 178 | wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; |
| 179 | } |
| 180 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
| 181 | } |
| 182 | |
| 183 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 184 | static void wpas_trigger_scan_cb(struct wpa_radio_work *work, int deinit) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 185 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 186 | struct wpa_supplicant *wpa_s = work->wpa_s; |
| 187 | struct wpa_driver_scan_params *params = work->ctx; |
| 188 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 189 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 190 | if (deinit) { |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 191 | if (!work->started) { |
| 192 | wpa_scan_free_params(params); |
| 193 | return; |
| 194 | } |
| 195 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 196 | wpas_notify_scan_done(wpa_s, 0); |
| 197 | wpa_s->scan_work = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 198 | return; |
| 199 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 200 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 201 | if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN) && |
| 202 | wpa_s->wpa_state <= WPA_SCANNING) |
| 203 | wpa_setup_mac_addr_rand_params(params, wpa_s->mac_addr_scan); |
| 204 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 205 | if (wpas_update_random_addr_disassoc(wpa_s) < 0) { |
| 206 | wpa_msg(wpa_s, MSG_INFO, |
| 207 | "Failed to assign random MAC address for a scan"); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 208 | wpa_scan_free_params(params); |
| 209 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=-1"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 210 | radio_work_done(work); |
| 211 | return; |
| 212 | } |
| 213 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 214 | wpa_supplicant_notify_scanning(wpa_s, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 215 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 216 | if (wpa_s->clear_driver_scan_cache) { |
| 217 | wpa_printf(MSG_DEBUG, |
| 218 | "Request driver to clear scan cache due to local BSS flush"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 219 | params->only_new_results = 1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 220 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 221 | ret = wpa_drv_scan(wpa_s, params); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 222 | /* |
| 223 | * Store the obtained vendor scan cookie (if any) in wpa_s context. |
| 224 | * The current design is to allow only one scan request on each |
| 225 | * interface, hence having this scan cookie stored in wpa_s context is |
| 226 | * fine for now. |
| 227 | * |
| 228 | * Revisit this logic if concurrent scan operations per interface |
| 229 | * is supported. |
| 230 | */ |
| 231 | if (ret == 0) |
| 232 | wpa_s->curr_scan_cookie = params->scan_cookie; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 233 | wpa_scan_free_params(params); |
| 234 | work->ctx = NULL; |
| 235 | if (ret) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 236 | int retry = wpa_s->last_scan_req != MANUAL_SCAN_REQ && |
| 237 | !wpa_s->beacon_rep_data.token; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 238 | |
| 239 | if (wpa_s->disconnected) |
| 240 | retry = 0; |
| 241 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 242 | /* do not retry if operation is not supported */ |
| 243 | if (ret == -EOPNOTSUPP) |
| 244 | retry = 0; |
| 245 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 246 | wpa_supplicant_notify_scanning(wpa_s, 0); |
| 247 | wpas_notify_scan_done(wpa_s, 0); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 248 | if (wpa_s->wpa_state == WPA_SCANNING) |
| 249 | wpa_supplicant_set_state(wpa_s, |
| 250 | wpa_s->scan_prev_wpa_state); |
| 251 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=%d%s", |
| 252 | ret, retry ? " retry=1" : ""); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 253 | radio_work_done(work); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 254 | |
| 255 | if (retry) { |
| 256 | /* Restore scan_req since we will try to scan again */ |
| 257 | wpa_s->scan_req = wpa_s->last_scan_req; |
| 258 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 259 | } else if (wpa_s->scan_res_handler) { |
| 260 | /* Clear the scan_res_handler */ |
| 261 | wpa_s->scan_res_handler = NULL; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 262 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 263 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 264 | #ifndef CONFIG_NO_RRM |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 265 | if (wpa_s->beacon_rep_data.token) |
| 266 | wpas_rrm_refuse_request(wpa_s); |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 267 | #endif /* CONFIG_NO_RRM */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 268 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 269 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 270 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 271 | |
| 272 | os_get_reltime(&wpa_s->scan_trigger_time); |
| 273 | wpa_s->scan_runs++; |
| 274 | wpa_s->normal_scans++; |
| 275 | wpa_s->own_scan_requested = 1; |
| 276 | wpa_s->clear_driver_scan_cache = 0; |
| 277 | wpa_s->scan_work = work; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 281 | /** |
| 282 | * wpa_supplicant_trigger_scan - Request driver to start a scan |
| 283 | * @wpa_s: Pointer to wpa_supplicant data |
| 284 | * @params: Scan parameters |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 285 | * @default_ies: Whether or not to use the default IEs in the Probe Request |
| 286 | * frames. Note that this will free any existing IEs set in @params, so this |
| 287 | * shouldn't be set if the IEs have already been set with |
| 288 | * wpa_supplicant_extra_ies(). Otherwise, wpabuf_free() will lead to a |
| 289 | * double-free. |
| 290 | * @next: Whether or not to perform this scan as the next radio work |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 291 | * Returns: 0 on success, -1 on failure |
| 292 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 293 | int wpa_supplicant_trigger_scan(struct wpa_supplicant *wpa_s, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 294 | struct wpa_driver_scan_params *params, |
| 295 | bool default_ies, bool next) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 296 | { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 297 | struct wpa_driver_scan_params *ctx; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 298 | struct wpabuf *ies = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 299 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 300 | if (wpa_s->scan_work) { |
| 301 | wpa_dbg(wpa_s, MSG_INFO, "Reject scan trigger since one is already pending"); |
| 302 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 303 | } |
| 304 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 305 | if (default_ies) { |
| 306 | if (params->extra_ies_len) { |
| 307 | os_free((u8 *) params->extra_ies); |
| 308 | params->extra_ies = NULL; |
| 309 | params->extra_ies_len = 0; |
| 310 | } |
| 311 | ies = wpa_supplicant_extra_ies(wpa_s); |
| 312 | if (ies) { |
| 313 | params->extra_ies = wpabuf_head(ies); |
| 314 | params->extra_ies_len = wpabuf_len(ies); |
| 315 | } |
| 316 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 317 | ctx = wpa_scan_clone_params(params); |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 318 | if (ies) { |
| 319 | wpabuf_free(ies); |
| 320 | params->extra_ies = NULL; |
| 321 | params->extra_ies_len = 0; |
| 322 | } |
| 323 | wpa_s->last_scan_all_chan = !params->freqs; |
| 324 | wpa_s->last_scan_non_coloc_6ghz = params->non_coloc_6ghz; |
Sunil Ravi | 7f76929 | 2024-07-23 22:21:32 +0000 | [diff] [blame] | 325 | |
| 326 | if (wpa_s->crossed_6ghz_dom) { |
| 327 | wpa_printf(MSG_DEBUG, "First scan after crossing 6 GHz domain"); |
| 328 | wpa_s->crossed_6ghz_dom = false; |
| 329 | } |
| 330 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 331 | if (!ctx || |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 332 | radio_add_work(wpa_s, 0, "scan", next, wpas_trigger_scan_cb, |
| 333 | ctx) < 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 334 | wpa_scan_free_params(ctx); |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 335 | wpa_msg(wpa_s, MSG_INFO, WPA_EVENT_SCAN_FAILED "ret=-1"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 336 | return -1; |
| 337 | } |
| 338 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 339 | wpa_s->wps_scan_done = false; |
| 340 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 341 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | |
| 345 | static void |
| 346 | wpa_supplicant_delayed_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
| 347 | { |
| 348 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 349 | |
| 350 | wpa_dbg(wpa_s, MSG_DEBUG, "Starting delayed sched scan"); |
| 351 | |
| 352 | if (wpa_supplicant_req_sched_scan(wpa_s)) |
| 353 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 354 | } |
| 355 | |
| 356 | |
| 357 | static void |
| 358 | wpa_supplicant_sched_scan_timeout(void *eloop_ctx, void *timeout_ctx) |
| 359 | { |
| 360 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 361 | |
| 362 | wpa_dbg(wpa_s, MSG_DEBUG, "Sched scan timeout - stopping it"); |
| 363 | |
| 364 | wpa_s->sched_scan_timed_out = 1; |
| 365 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 366 | } |
| 367 | |
| 368 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 369 | static int |
| 370 | wpa_supplicant_start_sched_scan(struct wpa_supplicant *wpa_s, |
| 371 | struct wpa_driver_scan_params *params) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 372 | { |
| 373 | int ret; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 374 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 375 | wpa_supplicant_notify_scanning(wpa_s, 1); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 376 | ret = wpa_drv_sched_scan(wpa_s, params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 377 | if (ret) |
| 378 | wpa_supplicant_notify_scanning(wpa_s, 0); |
Dmitry Shmidt | b96dad4 | 2013-11-05 10:07:29 -0800 | [diff] [blame] | 379 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 380 | wpa_s->sched_scanning = 1; |
| 381 | |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 386 | static int wpa_supplicant_stop_sched_scan(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 387 | { |
| 388 | int ret; |
| 389 | |
| 390 | ret = wpa_drv_stop_sched_scan(wpa_s); |
| 391 | if (ret) { |
| 392 | wpa_dbg(wpa_s, MSG_DEBUG, "stopping sched_scan failed!"); |
| 393 | /* TODO: what to do if stopping fails? */ |
| 394 | return -1; |
| 395 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 396 | |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | |
| 401 | static struct wpa_driver_scan_filter * |
| 402 | wpa_supplicant_build_filter_ssids(struct wpa_config *conf, size_t *num_ssids) |
| 403 | { |
| 404 | struct wpa_driver_scan_filter *ssids; |
| 405 | struct wpa_ssid *ssid; |
| 406 | size_t count; |
| 407 | |
| 408 | *num_ssids = 0; |
| 409 | if (!conf->filter_ssids) |
| 410 | return NULL; |
| 411 | |
| 412 | for (count = 0, ssid = conf->ssid; ssid; ssid = ssid->next) { |
| 413 | if (ssid->ssid && ssid->ssid_len) |
| 414 | count++; |
| 415 | } |
| 416 | if (count == 0) |
| 417 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 418 | ssids = os_calloc(count, sizeof(struct wpa_driver_scan_filter)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 419 | if (ssids == NULL) |
| 420 | return NULL; |
| 421 | |
| 422 | for (ssid = conf->ssid; ssid; ssid = ssid->next) { |
| 423 | if (!ssid->ssid || !ssid->ssid_len) |
| 424 | continue; |
| 425 | os_memcpy(ssids[*num_ssids].ssid, ssid->ssid, ssid->ssid_len); |
| 426 | ssids[*num_ssids].ssid_len = ssid->ssid_len; |
| 427 | (*num_ssids)++; |
| 428 | } |
| 429 | |
| 430 | return ssids; |
| 431 | } |
| 432 | |
| 433 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 434 | static void wpa_supplicant_optimize_freqs( |
| 435 | struct wpa_supplicant *wpa_s, struct wpa_driver_scan_params *params) |
| 436 | { |
| 437 | #ifdef CONFIG_P2P |
| 438 | if (params->freqs == NULL && wpa_s->p2p_in_provisioning && |
| 439 | wpa_s->go_params) { |
| 440 | /* Optimize provisioning state scan based on GO information */ |
| 441 | if (wpa_s->p2p_in_provisioning < 5 && |
| 442 | wpa_s->go_params->freq > 0) { |
| 443 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only GO " |
| 444 | "preferred frequency %d MHz", |
| 445 | wpa_s->go_params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 446 | params->freqs = os_calloc(2, sizeof(int)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 447 | if (params->freqs) |
| 448 | params->freqs[0] = wpa_s->go_params->freq; |
| 449 | } else if (wpa_s->p2p_in_provisioning < 8 && |
| 450 | wpa_s->go_params->freq_list[0]) { |
| 451 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Scan only common " |
| 452 | "channels"); |
| 453 | int_array_concat(¶ms->freqs, |
| 454 | wpa_s->go_params->freq_list); |
| 455 | if (params->freqs) |
| 456 | int_array_sort_unique(params->freqs); |
| 457 | } |
| 458 | wpa_s->p2p_in_provisioning++; |
| 459 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 460 | |
| 461 | if (params->freqs == NULL && wpa_s->p2p_in_invitation) { |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 462 | struct wpa_ssid *ssid = wpa_s->current_ssid; |
| 463 | |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 464 | /* |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 465 | * Perform a single-channel scan if the GO has already been |
| 466 | * discovered on another non-P2P interface. Note that a scan |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 467 | * initiated by a P2P interface (e.g., the device interface) |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 468 | * should already have sufficient IEs and scan results will be |
| 469 | * fetched on interface creation in that case. |
| 470 | */ |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 471 | if (wpa_s->p2p_in_invitation == 1 && ssid) { |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 472 | struct wpa_supplicant *ifs; |
| 473 | struct wpa_bss *bss = NULL; |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 474 | const u8 *bssid = ssid->bssid_set ? ssid->bssid : NULL; |
| 475 | |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 476 | dl_list_for_each(ifs, &wpa_s->radio->ifaces, |
| 477 | struct wpa_supplicant, radio_list) { |
| 478 | bss = wpa_bss_get(ifs, bssid, ssid->ssid, |
| 479 | ssid->ssid_len); |
| 480 | if (bss) |
| 481 | break; |
| 482 | } |
| 483 | if (bss && !disabled_freq(wpa_s, bss->freq)) { |
| 484 | params->freqs = os_calloc(2, sizeof(int)); |
Matthew Wang | afc981e | 2023-03-17 21:30:12 +0000 | [diff] [blame] | 485 | if (params->freqs) { |
| 486 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 487 | "P2P: Scan only the known GO frequency %d MHz during invitation", |
| 488 | bss->freq); |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 489 | params->freqs[0] = bss->freq; |
Matthew Wang | afc981e | 2023-03-17 21:30:12 +0000 | [diff] [blame] | 490 | } |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 491 | } |
| 492 | } |
Sunil Ravi | af8751c | 2023-03-29 11:35:17 -0700 | [diff] [blame] | 493 | |
Matthew Wang | dcf1945 | 2022-11-07 20:42:52 -0800 | [diff] [blame] | 494 | /* |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 495 | * Optimize scan based on GO information during persistent |
| 496 | * group reinvocation |
| 497 | */ |
Matthew Wang | afc981e | 2023-03-17 21:30:12 +0000 | [diff] [blame] | 498 | if (!params->freqs && wpa_s->p2p_in_invitation < 5 && |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 499 | wpa_s->p2p_invite_go_freq > 0) { |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 500 | if (wpa_s->p2p_invite_go_freq == 2 || |
| 501 | wpa_s->p2p_invite_go_freq == 5) { |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 502 | enum hostapd_hw_mode mode; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 503 | |
| 504 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 505 | "P2P: Scan only GO preferred band %d GHz during invitation", |
| 506 | wpa_s->p2p_invite_go_freq); |
| 507 | |
| 508 | if (!wpa_s->hw.modes) |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 509 | return; |
| 510 | mode = wpa_s->p2p_invite_go_freq == 5 ? |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 511 | HOSTAPD_MODE_IEEE80211A : |
| 512 | HOSTAPD_MODE_IEEE80211G; |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 513 | if (wpa_s->p2p_in_invitation <= 2) |
| 514 | wpa_add_scan_freqs_list(wpa_s, mode, |
| 515 | params, false, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 516 | false, true); |
| 517 | if (!params->freqs || params->freqs[0] == 0) |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 518 | wpa_add_scan_freqs_list(wpa_s, mode, |
| 519 | params, false, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 520 | false, false); |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 521 | } else { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 522 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 523 | "P2P: Scan only GO preferred frequency %d MHz during invitation", |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 524 | wpa_s->p2p_invite_go_freq); |
| 525 | params->freqs = os_calloc(2, sizeof(int)); |
| 526 | if (params->freqs) |
| 527 | params->freqs[0] = |
| 528 | wpa_s->p2p_invite_go_freq; |
| 529 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 530 | } |
| 531 | wpa_s->p2p_in_invitation++; |
| 532 | if (wpa_s->p2p_in_invitation > 20) { |
| 533 | /* |
| 534 | * This should not really happen since the variable is |
| 535 | * cleared on group removal, but if it does happen, make |
| 536 | * sure we do not get stuck in special invitation scan |
| 537 | * mode. |
| 538 | */ |
| 539 | wpa_dbg(wpa_s, MSG_DEBUG, "P2P: Clear p2p_in_invitation"); |
| 540 | wpa_s->p2p_in_invitation = 0; |
Matthew Wang | 06b4247 | 2022-11-10 06:56:31 +0000 | [diff] [blame] | 541 | wpa_s->p2p_retry_limit = 0; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 544 | #endif /* CONFIG_P2P */ |
| 545 | |
| 546 | #ifdef CONFIG_WPS |
| 547 | if (params->freqs == NULL && wpa_s->after_wps && wpa_s->wps_freq) { |
| 548 | /* |
| 549 | * Optimize post-provisioning scan based on channel used |
| 550 | * during provisioning. |
| 551 | */ |
| 552 | wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz " |
| 553 | "that was used during provisioning", wpa_s->wps_freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 554 | params->freqs = os_calloc(2, sizeof(int)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 555 | if (params->freqs) |
| 556 | params->freqs[0] = wpa_s->wps_freq; |
| 557 | wpa_s->after_wps--; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 558 | } else if (wpa_s->after_wps) |
| 559 | wpa_s->after_wps--; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 560 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 561 | if (params->freqs == NULL && wpa_s->known_wps_freq && wpa_s->wps_freq) |
| 562 | { |
| 563 | /* Optimize provisioning scan based on already known channel */ |
| 564 | wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Scan only frequency %u MHz", |
| 565 | wpa_s->wps_freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 566 | params->freqs = os_calloc(2, sizeof(int)); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 567 | if (params->freqs) |
| 568 | params->freqs[0] = wpa_s->wps_freq; |
| 569 | wpa_s->known_wps_freq = 0; /* only do this once */ |
| 570 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 571 | #endif /* CONFIG_WPS */ |
| 572 | } |
| 573 | |
| 574 | |
| 575 | #ifdef CONFIG_INTERWORKING |
| 576 | static void wpas_add_interworking_elements(struct wpa_supplicant *wpa_s, |
| 577 | struct wpabuf *buf) |
| 578 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 579 | wpabuf_put_u8(buf, WLAN_EID_INTERWORKING); |
| 580 | wpabuf_put_u8(buf, is_zero_ether_addr(wpa_s->conf->hessid) ? 1 : |
| 581 | 1 + ETH_ALEN); |
| 582 | wpabuf_put_u8(buf, wpa_s->conf->access_network_type); |
| 583 | /* No Venue Info */ |
| 584 | if (!is_zero_ether_addr(wpa_s->conf->hessid)) |
| 585 | wpabuf_put_data(buf, wpa_s->conf->hessid, ETH_ALEN); |
| 586 | } |
| 587 | #endif /* CONFIG_INTERWORKING */ |
| 588 | |
| 589 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 590 | #ifdef CONFIG_MBO |
| 591 | static void wpas_fils_req_param_add_max_channel(struct wpa_supplicant *wpa_s, |
| 592 | struct wpabuf **ie) |
| 593 | { |
| 594 | if (wpabuf_resize(ie, 5)) { |
| 595 | wpa_printf(MSG_DEBUG, |
| 596 | "Failed to allocate space for FILS Request Parameters element"); |
| 597 | return; |
| 598 | } |
| 599 | |
| 600 | /* FILS Request Parameters element */ |
| 601 | wpabuf_put_u8(*ie, WLAN_EID_EXTENSION); |
| 602 | wpabuf_put_u8(*ie, 3); /* FILS Request attribute length */ |
| 603 | wpabuf_put_u8(*ie, WLAN_EID_EXT_FILS_REQ_PARAMS); |
| 604 | /* Parameter control bitmap */ |
| 605 | wpabuf_put_u8(*ie, 0); |
| 606 | /* Max Channel Time field - contains the value of MaxChannelTime |
| 607 | * parameter of the MLME-SCAN.request primitive represented in units of |
| 608 | * TUs, as an unsigned integer. A Max Channel Time field value of 255 |
| 609 | * is used to indicate any duration of more than 254 TUs, or an |
| 610 | * unspecified or unknown duration. (IEEE Std 802.11ai-2016, 9.4.2.178) |
| 611 | */ |
| 612 | wpabuf_put_u8(*ie, 255); |
| 613 | } |
| 614 | #endif /* CONFIG_MBO */ |
| 615 | |
| 616 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 617 | void wpa_supplicant_set_default_scan_ies(struct wpa_supplicant *wpa_s) |
| 618 | { |
| 619 | struct wpabuf *default_ies = NULL; |
| 620 | u8 ext_capab[18]; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 621 | int ext_capab_len, frame_id; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 622 | enum wpa_driver_if_type type = WPA_IF_STATION; |
| 623 | |
| 624 | #ifdef CONFIG_P2P |
| 625 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) |
| 626 | type = WPA_IF_P2P_CLIENT; |
| 627 | #endif /* CONFIG_P2P */ |
| 628 | |
| 629 | wpa_drv_get_ext_capa(wpa_s, type); |
| 630 | |
| 631 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 632 | sizeof(ext_capab), NULL); |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 633 | if (ext_capab_len > 0 && |
| 634 | wpabuf_resize(&default_ies, ext_capab_len) == 0) |
| 635 | wpabuf_put_data(default_ies, ext_capab, ext_capab_len); |
| 636 | |
| 637 | #ifdef CONFIG_MBO |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 638 | if (wpa_s->enable_oce & OCE_STA) |
| 639 | wpas_fils_req_param_add_max_channel(wpa_s, &default_ies); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 640 | /* Send MBO and OCE capabilities */ |
| 641 | if (wpabuf_resize(&default_ies, 12) == 0) |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 642 | wpas_mbo_scan_ie(wpa_s, default_ies); |
| 643 | #endif /* CONFIG_MBO */ |
| 644 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 645 | if (type == WPA_IF_P2P_CLIENT) |
| 646 | frame_id = VENDOR_ELEM_PROBE_REQ_P2P; |
| 647 | else |
| 648 | frame_id = VENDOR_ELEM_PROBE_REQ; |
| 649 | |
| 650 | if (wpa_s->vendor_elem[frame_id]) { |
| 651 | size_t len; |
| 652 | |
| 653 | len = wpabuf_len(wpa_s->vendor_elem[frame_id]); |
| 654 | if (len > 0 && wpabuf_resize(&default_ies, len) == 0) |
| 655 | wpabuf_put_buf(default_ies, |
| 656 | wpa_s->vendor_elem[frame_id]); |
| 657 | } |
| 658 | |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 659 | if (default_ies) |
| 660 | wpa_drv_set_default_scan_ies(wpa_s, wpabuf_head(default_ies), |
| 661 | wpabuf_len(default_ies)); |
| 662 | wpabuf_free(default_ies); |
| 663 | } |
| 664 | |
| 665 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 666 | static struct wpabuf * wpa_supplicant_ml_probe_ie(int mld_id, u16 links) |
| 667 | { |
| 668 | struct wpabuf *extra_ie; |
| 669 | u16 control = MULTI_LINK_CONTROL_TYPE_PROBE_REQ; |
| 670 | size_t len = 3 + 4 + 4 * MAX_NUM_MLD_LINKS; |
| 671 | u8 link_id; |
| 672 | u8 *len_pos; |
| 673 | |
| 674 | if (mld_id >= 0) { |
| 675 | control |= EHT_ML_PRES_BM_PROBE_REQ_AP_MLD_ID; |
| 676 | len++; |
| 677 | } |
| 678 | |
| 679 | extra_ie = wpabuf_alloc(len); |
| 680 | if (!extra_ie) |
| 681 | return NULL; |
| 682 | |
| 683 | wpabuf_put_u8(extra_ie, WLAN_EID_EXTENSION); |
| 684 | len_pos = wpabuf_put(extra_ie, 1); |
| 685 | wpabuf_put_u8(extra_ie, WLAN_EID_EXT_MULTI_LINK); |
| 686 | |
| 687 | wpabuf_put_le16(extra_ie, control); |
| 688 | |
| 689 | /* common info length and MLD ID (if requested) */ |
| 690 | if (mld_id >= 0) { |
| 691 | wpabuf_put_u8(extra_ie, 2); |
| 692 | wpabuf_put_u8(extra_ie, mld_id); |
| 693 | |
| 694 | wpa_printf(MSG_DEBUG, "MLD: ML probe targeted at MLD ID %d", |
| 695 | mld_id); |
| 696 | } else { |
| 697 | wpabuf_put_u8(extra_ie, 1); |
| 698 | |
| 699 | wpa_printf(MSG_DEBUG, "MLD: ML probe targeted at receiving AP"); |
| 700 | } |
| 701 | |
| 702 | if (!links) |
| 703 | wpa_printf(MSG_DEBUG, "MLD: Probing all links"); |
| 704 | else |
| 705 | wpa_printf(MSG_DEBUG, "MLD: Probing links 0x%04x", links); |
| 706 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 707 | for_each_link(links, link_id) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 708 | wpabuf_put_u8(extra_ie, EHT_ML_SUB_ELEM_PER_STA_PROFILE); |
| 709 | |
| 710 | /* Subelement length includes only the control */ |
| 711 | wpabuf_put_u8(extra_ie, 2); |
| 712 | |
| 713 | control = link_id | EHT_PER_STA_CTRL_COMPLETE_PROFILE_MSK; |
| 714 | |
| 715 | wpabuf_put_le16(extra_ie, control); |
| 716 | } |
| 717 | |
| 718 | *len_pos = (u8 *) wpabuf_put(extra_ie, 0) - len_pos - 1; |
| 719 | |
| 720 | return extra_ie; |
| 721 | } |
| 722 | |
| 723 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 724 | static struct wpabuf * wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 725 | { |
| 726 | struct wpabuf *extra_ie = NULL; |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 727 | u8 ext_capab[18]; |
| 728 | int ext_capab_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 729 | #ifdef CONFIG_WPS |
| 730 | int wps = 0; |
| 731 | enum wps_request_type req_type = WPS_REQ_ENROLLEE_INFO; |
| 732 | #endif /* CONFIG_WPS */ |
| 733 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 734 | if (!is_zero_ether_addr(wpa_s->ml_probe_bssid)) { |
| 735 | extra_ie = wpa_supplicant_ml_probe_ie(wpa_s->ml_probe_mld_id, |
| 736 | wpa_s->ml_probe_links); |
| 737 | |
| 738 | /* No other elements should be included in the probe request */ |
| 739 | wpa_printf(MSG_DEBUG, "MLD: Scan including only ML element"); |
| 740 | return extra_ie; |
| 741 | } |
| 742 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 743 | #ifdef CONFIG_P2P |
| 744 | if (wpa_s->p2p_group_interface == P2P_GROUP_INTERFACE_CLIENT) |
| 745 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_P2P_CLIENT); |
| 746 | else |
| 747 | #endif /* CONFIG_P2P */ |
| 748 | wpa_drv_get_ext_capa(wpa_s, WPA_IF_STATION); |
| 749 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 750 | ext_capab_len = wpas_build_ext_capab(wpa_s, ext_capab, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 751 | sizeof(ext_capab), NULL); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 752 | if (ext_capab_len > 0 && |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 753 | (size_t) ext_capab_len < wpa_s->drv_max_probe_req_ie_len && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 754 | wpabuf_resize(&extra_ie, ext_capab_len) == 0) |
| 755 | wpabuf_put_data(extra_ie, ext_capab, ext_capab_len); |
| 756 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 757 | #ifdef CONFIG_INTERWORKING |
| 758 | if (wpa_s->conf->interworking && |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 759 | wpa_s->drv_max_probe_req_ie_len >= 2 && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 760 | wpabuf_resize(&extra_ie, 100) == 0) |
| 761 | wpas_add_interworking_elements(wpa_s, extra_ie); |
| 762 | #endif /* CONFIG_INTERWORKING */ |
| 763 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 764 | #ifdef CONFIG_MBO |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 765 | if ((wpa_s->enable_oce & OCE_STA) && |
| 766 | wpa_s->drv_max_probe_req_ie_len >= 5) |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 767 | wpas_fils_req_param_add_max_channel(wpa_s, &extra_ie); |
| 768 | #endif /* CONFIG_MBO */ |
| 769 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 770 | #ifdef CONFIG_WPS |
| 771 | wps = wpas_wps_in_use(wpa_s, &req_type); |
| 772 | |
| 773 | if (wps) { |
| 774 | struct wpabuf *wps_ie; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 775 | wps_ie = wps_build_probe_req_ie(wps == 2 ? DEV_PW_PUSHBUTTON : |
| 776 | DEV_PW_DEFAULT, |
| 777 | &wpa_s->wps->dev, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 778 | wpa_s->wps->uuid, req_type, |
| 779 | 0, NULL); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 780 | if (wps_ie && |
| 781 | wpabuf_len(wps_ie) <= wpa_s->drv_max_probe_req_ie_len && |
| 782 | wpabuf_resize(&extra_ie, wpabuf_len(wps_ie)) == 0) |
| 783 | wpabuf_put_buf(extra_ie, wps_ie); |
| 784 | wpabuf_free(wps_ie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | #ifdef CONFIG_P2P |
| 788 | if (wps) { |
| 789 | size_t ielen = p2p_scan_ie_buf_len(wpa_s->global->p2p); |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 790 | |
| 791 | if (ielen <= wpa_s->drv_max_probe_req_ie_len && |
| 792 | wpabuf_resize(&extra_ie, ielen) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 793 | wpas_p2p_scan_ie(wpa_s, extra_ie); |
| 794 | } |
| 795 | #endif /* CONFIG_P2P */ |
| 796 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 797 | wpa_supplicant_mesh_add_scan_ie(wpa_s, &extra_ie); |
| 798 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 799 | #endif /* CONFIG_WPS */ |
| 800 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 801 | #ifdef CONFIG_HS20 |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 802 | if (wpa_s->conf->hs20 && wpa_s->drv_max_probe_req_ie_len >= 9 && |
| 803 | wpabuf_resize(&extra_ie, 9) == 0) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 804 | wpas_hs20_add_indication(extra_ie, -1, 0); |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 805 | #endif /* CONFIG_HS20 */ |
| 806 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 807 | #ifdef CONFIG_FST |
| 808 | if (wpa_s->fst_ies && |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 809 | wpa_s->drv_max_probe_req_ie_len >= wpabuf_len(wpa_s->fst_ies) && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 810 | wpabuf_resize(&extra_ie, wpabuf_len(wpa_s->fst_ies)) == 0) |
| 811 | wpabuf_put_buf(extra_ie, wpa_s->fst_ies); |
| 812 | #endif /* CONFIG_FST */ |
| 813 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 814 | #ifdef CONFIG_MBO |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 815 | /* Send MBO and OCE capabilities */ |
| 816 | if (wpabuf_resize(&extra_ie, 12) == 0) |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 817 | wpas_mbo_scan_ie(wpa_s, extra_ie); |
| 818 | #endif /* CONFIG_MBO */ |
| 819 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 820 | if (wpa_s->vendor_elem[VENDOR_ELEM_PROBE_REQ]) { |
| 821 | struct wpabuf *buf = wpa_s->vendor_elem[VENDOR_ELEM_PROBE_REQ]; |
| 822 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 823 | if (wpa_s->drv_max_probe_req_ie_len >= wpabuf_len(buf) && |
| 824 | wpabuf_resize(&extra_ie, wpabuf_len(buf)) == 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 825 | wpabuf_put_buf(extra_ie, buf); |
| 826 | } |
| 827 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 828 | return extra_ie; |
| 829 | } |
| 830 | |
| 831 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 832 | #ifdef CONFIG_P2P |
| 833 | |
| 834 | /* |
| 835 | * Check whether there are any enabled networks or credentials that could be |
| 836 | * used for a non-P2P connection. |
| 837 | */ |
| 838 | static int non_p2p_network_enabled(struct wpa_supplicant *wpa_s) |
| 839 | { |
| 840 | struct wpa_ssid *ssid; |
| 841 | |
| 842 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 843 | if (wpas_network_disabled(wpa_s, ssid)) |
| 844 | continue; |
| 845 | if (!ssid->p2p_group) |
| 846 | return 1; |
| 847 | } |
| 848 | |
| 849 | if (wpa_s->conf->cred && wpa_s->conf->interworking && |
| 850 | wpa_s->conf->auto_interworking) |
| 851 | return 1; |
| 852 | |
| 853 | return 0; |
| 854 | } |
| 855 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 856 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 857 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 858 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 859 | int wpa_add_scan_freqs_list(struct wpa_supplicant *wpa_s, |
| 860 | enum hostapd_hw_mode band, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 861 | struct wpa_driver_scan_params *params, |
| 862 | bool is_6ghz, bool only_6ghz_psc, |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 863 | bool exclude_radar) |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 864 | { |
| 865 | /* Include only supported channels for the specified band */ |
| 866 | struct hostapd_hw_modes *mode; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 867 | int num_chans = 0; |
| 868 | int *freqs, i; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 869 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 870 | mode = get_mode(wpa_s->hw.modes, wpa_s->hw.num_modes, band, is_6ghz); |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 871 | if (!mode || !mode->num_channels) |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 872 | return -1; |
| 873 | |
| 874 | if (params->freqs) { |
| 875 | while (params->freqs[num_chans]) |
| 876 | num_chans++; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 877 | } |
| 878 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 879 | freqs = os_realloc(params->freqs, |
| 880 | (num_chans + mode->num_channels + 1) * sizeof(int)); |
| 881 | if (!freqs) |
| 882 | return -1; |
| 883 | |
| 884 | params->freqs = freqs; |
| 885 | for (i = 0; i < mode->num_channels; i++) { |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 886 | if (mode->channels[i].flag & HOSTAPD_CHAN_DISABLED) |
| 887 | continue; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 888 | if (exclude_radar && |
| 889 | (mode->channels[i].flag & HOSTAPD_CHAN_RADAR)) |
Matthew Wang | 3617311 | 2022-11-07 21:48:44 -0800 | [diff] [blame] | 890 | continue; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 891 | |
| 892 | if (is_6ghz && only_6ghz_psc && |
| 893 | !is_6ghz_psc_frequency(mode->channels[i].freq)) |
| 894 | continue; |
| 895 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 896 | params->freqs[num_chans++] = mode->channels[i].freq; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 897 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 898 | params->freqs[num_chans] = 0; |
| 899 | |
| 900 | return 0; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | |
| 904 | static void wpa_setband_scan_freqs(struct wpa_supplicant *wpa_s, |
| 905 | struct wpa_driver_scan_params *params) |
| 906 | { |
| 907 | if (wpa_s->hw.modes == NULL) |
| 908 | return; /* unknown what channels the driver supports */ |
| 909 | if (params->freqs) |
| 910 | return; /* already using a limited channel set */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 911 | |
| 912 | if (wpa_s->setband_mask & WPA_SETBAND_5G) |
| 913 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 914 | false, false, false); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 915 | if (wpa_s->setband_mask & WPA_SETBAND_2G) |
| 916 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211G, params, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 917 | false, false, false); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 918 | if (wpa_s->setband_mask & WPA_SETBAND_6G) |
| 919 | wpa_add_scan_freqs_list(wpa_s, HOSTAPD_MODE_IEEE80211A, params, |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 920 | true, false, false); |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 924 | static void wpa_add_scan_ssid(struct wpa_supplicant *wpa_s, |
| 925 | struct wpa_driver_scan_params *params, |
| 926 | size_t max_ssids, const u8 *ssid, size_t ssid_len) |
| 927 | { |
| 928 | unsigned int j; |
| 929 | |
| 930 | for (j = 0; j < params->num_ssids; j++) { |
| 931 | if (params->ssids[j].ssid_len == ssid_len && |
| 932 | params->ssids[j].ssid && |
| 933 | os_memcmp(params->ssids[j].ssid, ssid, ssid_len) == 0) |
| 934 | return; /* already in the list */ |
| 935 | } |
| 936 | |
| 937 | if (params->num_ssids + 1 > max_ssids) { |
| 938 | wpa_printf(MSG_DEBUG, "Over max scan SSIDs for manual request"); |
| 939 | return; |
| 940 | } |
| 941 | |
| 942 | wpa_printf(MSG_DEBUG, "Scan SSID (manual request): %s", |
| 943 | wpa_ssid_txt(ssid, ssid_len)); |
| 944 | |
| 945 | params->ssids[params->num_ssids].ssid = ssid; |
| 946 | params->ssids[params->num_ssids].ssid_len = ssid_len; |
| 947 | params->num_ssids++; |
| 948 | } |
| 949 | |
| 950 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 951 | void wpa_add_owe_scan_ssid(struct wpa_supplicant *wpa_s, |
| 952 | struct wpa_driver_scan_params *params, |
| 953 | const struct wpa_ssid *ssid, size_t max_ssids) |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 954 | { |
| 955 | #ifdef CONFIG_OWE |
| 956 | struct wpa_bss *bss; |
| 957 | |
| 958 | if (!(ssid->key_mgmt & WPA_KEY_MGMT_OWE)) |
| 959 | return; |
| 960 | |
| 961 | wpa_printf(MSG_DEBUG, "OWE: Look for transition mode AP. ssid=%s", |
| 962 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 963 | |
| 964 | dl_list_for_each(bss, &wpa_s->bss, struct wpa_bss, list) { |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 965 | const u8 *owe, *owe_bssid, *owe_ssid; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 966 | size_t owe_ssid_len; |
| 967 | |
| 968 | if (bss->ssid_len != ssid->ssid_len || |
| 969 | os_memcmp(bss->ssid, ssid->ssid, ssid->ssid_len) != 0) |
| 970 | continue; |
| 971 | |
| 972 | owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE); |
| 973 | if (!owe || owe[1] < 4) |
| 974 | continue; |
| 975 | |
Sunil Ravi | c0f5d41 | 2024-09-11 22:12:49 +0000 | [diff] [blame] | 976 | if (wpas_get_owe_trans_network(owe, &owe_bssid, &owe_ssid, |
| 977 | &owe_ssid_len)) |
| 978 | continue; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 979 | |
| 980 | wpa_printf(MSG_DEBUG, |
| 981 | "OWE: scan_ssids: transition mode OWE ssid=%s", |
| 982 | wpa_ssid_txt(owe_ssid, owe_ssid_len)); |
| 983 | |
| 984 | wpa_add_scan_ssid(wpa_s, params, max_ssids, |
| 985 | owe_ssid, owe_ssid_len); |
| 986 | return; |
| 987 | } |
| 988 | #endif /* CONFIG_OWE */ |
| 989 | } |
| 990 | |
| 991 | |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 992 | static void wpa_set_scan_ssids(struct wpa_supplicant *wpa_s, |
| 993 | struct wpa_driver_scan_params *params, |
| 994 | size_t max_ssids) |
| 995 | { |
| 996 | unsigned int i; |
| 997 | struct wpa_ssid *ssid; |
| 998 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 999 | /* |
| 1000 | * For devices with max_ssids greater than 1, leave the last slot empty |
| 1001 | * for adding the wildcard scan entry. |
| 1002 | */ |
| 1003 | max_ssids = max_ssids > 1 ? max_ssids - 1 : max_ssids; |
| 1004 | |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 1005 | for (i = 0; i < wpa_s->scan_id_count; i++) { |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 1006 | ssid = wpa_config_get_network(wpa_s->conf, wpa_s->scan_id[i]); |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1007 | if (!ssid) |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 1008 | continue; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1009 | if (ssid->scan_ssid) |
| 1010 | wpa_add_scan_ssid(wpa_s, params, max_ssids, |
| 1011 | ssid->ssid, ssid->ssid_len); |
| 1012 | /* |
| 1013 | * Also add the SSID of the OWE BSS, to allow discovery of |
| 1014 | * transition mode APs more quickly. |
| 1015 | */ |
| 1016 | wpa_add_owe_scan_ssid(wpa_s, params, ssid, max_ssids); |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | wpa_s->scan_id_count = 0; |
| 1020 | } |
| 1021 | |
| 1022 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1023 | static int wpa_set_ssids_from_scan_req(struct wpa_supplicant *wpa_s, |
| 1024 | struct wpa_driver_scan_params *params, |
| 1025 | size_t max_ssids) |
| 1026 | { |
| 1027 | unsigned int i; |
| 1028 | |
| 1029 | if (wpa_s->ssids_from_scan_req == NULL || |
| 1030 | wpa_s->num_ssids_from_scan_req == 0) |
| 1031 | return 0; |
| 1032 | |
| 1033 | if (wpa_s->num_ssids_from_scan_req > max_ssids) { |
| 1034 | wpa_s->num_ssids_from_scan_req = max_ssids; |
| 1035 | wpa_printf(MSG_DEBUG, "Over max scan SSIDs from scan req: %u", |
| 1036 | (unsigned int) max_ssids); |
| 1037 | } |
| 1038 | |
| 1039 | for (i = 0; i < wpa_s->num_ssids_from_scan_req; i++) { |
| 1040 | params->ssids[i].ssid = wpa_s->ssids_from_scan_req[i].ssid; |
| 1041 | params->ssids[i].ssid_len = |
| 1042 | wpa_s->ssids_from_scan_req[i].ssid_len; |
| 1043 | wpa_hexdump_ascii(MSG_DEBUG, "specific SSID", |
| 1044 | params->ssids[i].ssid, |
| 1045 | params->ssids[i].ssid_len); |
| 1046 | } |
| 1047 | |
| 1048 | params->num_ssids = wpa_s->num_ssids_from_scan_req; |
| 1049 | wpa_s->num_ssids_from_scan_req = 0; |
| 1050 | return 1; |
| 1051 | } |
| 1052 | |
| 1053 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1054 | static void wpa_supplicant_scan(void *eloop_ctx, void *timeout_ctx) |
| 1055 | { |
| 1056 | struct wpa_supplicant *wpa_s = eloop_ctx; |
| 1057 | struct wpa_ssid *ssid; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1058 | int ret, p2p_in_prog; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1059 | struct wpabuf *extra_ie = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1060 | struct wpa_driver_scan_params params; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1061 | struct wpa_driver_scan_params *scan_params; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1062 | size_t max_ssids; |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1063 | int connect_without_scan = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1064 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 1065 | wpa_s->ignore_post_flush_scan_res = 0; |
| 1066 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1067 | if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) { |
| 1068 | wpa_dbg(wpa_s, MSG_DEBUG, "Skip scan - interface disabled"); |
| 1069 | return; |
| 1070 | } |
| 1071 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1072 | if (wpa_s->disconnected && wpa_s->scan_req == NORMAL_SCAN_REQ) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 1073 | wpa_dbg(wpa_s, MSG_DEBUG, "Disconnected - do not scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1074 | wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED); |
| 1075 | return; |
| 1076 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1077 | |
Dmitry Shmidt | 5887a9d | 2012-09-14 10:47:43 -0700 | [diff] [blame] | 1078 | if (wpa_s->scanning) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1079 | /* |
| 1080 | * If we are already in scanning state, we shall reschedule the |
| 1081 | * the incoming scan request. |
| 1082 | */ |
| 1083 | wpa_dbg(wpa_s, MSG_DEBUG, "Already scanning - Reschedule the incoming scan req"); |
| 1084 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
Dmitry Shmidt | 5887a9d | 2012-09-14 10:47:43 -0700 | [diff] [blame] | 1085 | return; |
| 1086 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1087 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1088 | if (!wpa_supplicant_enabled_networks(wpa_s) && |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1089 | wpa_s->scan_req == NORMAL_SCAN_REQ) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1090 | wpa_dbg(wpa_s, MSG_DEBUG, "No enabled networks - do not scan"); |
| 1091 | wpa_supplicant_set_state(wpa_s, WPA_INACTIVE); |
| 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | if (wpa_s->conf->ap_scan != 0 && |
| 1096 | (wpa_s->drv_flags & WPA_DRIVER_FLAGS_WIRED)) { |
| 1097 | wpa_dbg(wpa_s, MSG_DEBUG, "Using wired authentication - " |
| 1098 | "overriding ap_scan configuration"); |
| 1099 | wpa_s->conf->ap_scan = 0; |
| 1100 | wpas_notify_ap_scan_changed(wpa_s); |
| 1101 | } |
| 1102 | |
| 1103 | if (wpa_s->conf->ap_scan == 0) { |
| 1104 | wpa_supplicant_gen_assoc_event(wpa_s); |
| 1105 | return; |
| 1106 | } |
| 1107 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1108 | ssid = NULL; |
| 1109 | if (wpa_s->scan_req != MANUAL_SCAN_REQ && |
| 1110 | wpa_s->connect_without_scan) { |
| 1111 | connect_without_scan = 1; |
| 1112 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
| 1113 | if (ssid == wpa_s->connect_without_scan) |
| 1114 | break; |
| 1115 | } |
| 1116 | } |
| 1117 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1118 | p2p_in_prog = wpas_p2p_in_progress(wpa_s); |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1119 | if (p2p_in_prog && p2p_in_prog != 2 && |
| 1120 | (!ssid || |
| 1121 | (ssid->mode != WPAS_MODE_AP && ssid->mode != WPAS_MODE_P2P_GO))) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1122 | wpa_dbg(wpa_s, MSG_DEBUG, "Delay station mode scan while P2P operation is in progress"); |
| 1123 | wpa_supplicant_req_scan(wpa_s, 5, 0); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1124 | return; |
| 1125 | } |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1126 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1127 | /* |
| 1128 | * Don't cancel the scan based on ongoing PNO; defer it. Some scans are |
| 1129 | * used for changing modes inside wpa_supplicant (roaming, |
| 1130 | * auto-reconnect, etc). Discarding the scan might hurt these processes. |
| 1131 | * The normal use case for PNO is to suspend the host immediately after |
| 1132 | * starting PNO, so the periodic 100 ms attempts to run the scan do not |
| 1133 | * normally happen in practice multiple times, i.e., this is simply |
| 1134 | * restarting scanning once the host is woken up and PNO stopped. |
| 1135 | */ |
| 1136 | if (wpa_s->pno || wpa_s->pno_sched_pending) { |
| 1137 | wpa_dbg(wpa_s, MSG_DEBUG, "Defer scan - PNO is in progress"); |
| 1138 | wpa_supplicant_req_scan(wpa_s, 0, 100000); |
| 1139 | return; |
| 1140 | } |
| 1141 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1142 | if (wpa_s->conf->ap_scan == 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1143 | max_ssids = 1; |
| 1144 | else { |
| 1145 | max_ssids = wpa_s->max_scan_ssids; |
| 1146 | if (max_ssids > WPAS_MAX_SCAN_SSIDS) |
| 1147 | max_ssids = WPAS_MAX_SCAN_SSIDS; |
| 1148 | } |
| 1149 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1150 | wpa_s->last_scan_req = wpa_s->scan_req; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1151 | wpa_s->scan_req = NORMAL_SCAN_REQ; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1152 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1153 | if (connect_without_scan) { |
| 1154 | wpa_s->connect_without_scan = NULL; |
| 1155 | if (ssid) { |
| 1156 | wpa_printf(MSG_DEBUG, "Start a pre-selected network " |
| 1157 | "without scan step"); |
| 1158 | wpa_supplicant_associate(wpa_s, NULL, ssid); |
| 1159 | return; |
| 1160 | } |
| 1161 | } |
| 1162 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1163 | os_memset(¶ms, 0, sizeof(params)); |
| 1164 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1165 | wpa_s->scan_prev_wpa_state = wpa_s->wpa_state; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1166 | if (wpa_s->wpa_state == WPA_DISCONNECTED || |
| 1167 | wpa_s->wpa_state == WPA_INACTIVE) |
| 1168 | wpa_supplicant_set_state(wpa_s, WPA_SCANNING); |
| 1169 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1170 | /* |
| 1171 | * If autoscan has set its own scanning parameters |
| 1172 | */ |
| 1173 | if (wpa_s->autoscan_params != NULL) { |
| 1174 | scan_params = wpa_s->autoscan_params; |
| 1175 | goto scan; |
| 1176 | } |
| 1177 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1178 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 1179 | wpa_set_ssids_from_scan_req(wpa_s, ¶ms, max_ssids)) { |
| 1180 | wpa_printf(MSG_DEBUG, "Use specific SSIDs from SCAN command"); |
| 1181 | goto ssid_list_set; |
| 1182 | } |
| 1183 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1184 | #ifdef CONFIG_P2P |
| 1185 | if ((wpa_s->p2p_in_provisioning || wpa_s->show_group_started) && |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1186 | wpa_s->go_params && !wpa_s->conf->passive_scan) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1187 | wpa_printf(MSG_DEBUG, "P2P: Use specific SSID for scan during P2P group formation (p2p_in_provisioning=%d show_group_started=%d)", |
| 1188 | wpa_s->p2p_in_provisioning, |
| 1189 | wpa_s->show_group_started); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1190 | params.ssids[0].ssid = wpa_s->go_params->ssid; |
| 1191 | params.ssids[0].ssid_len = wpa_s->go_params->ssid_len; |
| 1192 | params.num_ssids = 1; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1193 | params.bssid = wpa_s->go_params->peer_interface_addr; |
| 1194 | wpa_printf(MSG_DEBUG, "P2P: Use specific BSSID " MACSTR |
| 1195 | " (peer interface address) for scan", |
| 1196 | MAC2STR(params.bssid)); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1197 | goto ssid_list_set; |
| 1198 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1199 | |
| 1200 | if (wpa_s->p2p_in_invitation) { |
| 1201 | if (wpa_s->current_ssid) { |
| 1202 | wpa_printf(MSG_DEBUG, "P2P: Use specific SSID for scan during invitation"); |
| 1203 | params.ssids[0].ssid = wpa_s->current_ssid->ssid; |
| 1204 | params.ssids[0].ssid_len = |
| 1205 | wpa_s->current_ssid->ssid_len; |
| 1206 | params.num_ssids = 1; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1207 | if (wpa_s->current_ssid->bssid_set) { |
| 1208 | params.bssid = wpa_s->current_ssid->bssid; |
| 1209 | wpa_printf(MSG_DEBUG, "P2P: Use specific BSSID " |
| 1210 | MACSTR " for scan", |
| 1211 | MAC2STR(params.bssid)); |
| 1212 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 1213 | } else { |
| 1214 | wpa_printf(MSG_DEBUG, "P2P: No specific SSID known for scan during invitation"); |
| 1215 | } |
| 1216 | goto ssid_list_set; |
| 1217 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1218 | #endif /* CONFIG_P2P */ |
| 1219 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | /* Find the starting point from which to continue scanning */ |
| 1221 | ssid = wpa_s->conf->ssid; |
| 1222 | if (wpa_s->prev_scan_ssid != WILDCARD_SSID_SCAN) { |
| 1223 | while (ssid) { |
| 1224 | if (ssid == wpa_s->prev_scan_ssid) { |
| 1225 | ssid = ssid->next; |
| 1226 | break; |
| 1227 | } |
| 1228 | ssid = ssid->next; |
| 1229 | } |
| 1230 | } |
| 1231 | |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1232 | if (wpa_s->last_scan_req != MANUAL_SCAN_REQ && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1233 | #ifdef CONFIG_AP |
| 1234 | !wpa_s->ap_iface && |
| 1235 | #endif /* CONFIG_AP */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1236 | wpa_s->conf->ap_scan == 2) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 1237 | wpa_s->connect_without_scan = NULL; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1238 | wpa_s->prev_scan_wildcard = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1239 | wpa_supplicant_assoc_try(wpa_s, ssid); |
| 1240 | return; |
| 1241 | } else if (wpa_s->conf->ap_scan == 2) { |
| 1242 | /* |
| 1243 | * User-initiated scan request in ap_scan == 2; scan with |
| 1244 | * wildcard SSID. |
| 1245 | */ |
| 1246 | ssid = NULL; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1247 | } else if (wpa_s->reattach && wpa_s->current_ssid != NULL) { |
| 1248 | /* |
| 1249 | * Perform single-channel single-SSID scan for |
| 1250 | * reassociate-to-same-BSS operation. |
| 1251 | */ |
| 1252 | /* Setup SSID */ |
| 1253 | ssid = wpa_s->current_ssid; |
| 1254 | wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID", |
| 1255 | ssid->ssid, ssid->ssid_len); |
| 1256 | params.ssids[0].ssid = ssid->ssid; |
| 1257 | params.ssids[0].ssid_len = ssid->ssid_len; |
| 1258 | params.num_ssids = 1; |
| 1259 | |
| 1260 | /* |
| 1261 | * Allocate memory for frequency array, allocate one extra |
| 1262 | * slot for the zero-terminator. |
| 1263 | */ |
| 1264 | params.freqs = os_malloc(sizeof(int) * 2); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 1265 | if (params.freqs) { |
| 1266 | params.freqs[0] = wpa_s->assoc_freq; |
| 1267 | params.freqs[1] = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1268 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 1269 | |
| 1270 | /* |
| 1271 | * Reset the reattach flag so that we fall back to full scan if |
| 1272 | * this scan fails. |
| 1273 | */ |
| 1274 | wpa_s->reattach = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1275 | } else { |
| 1276 | struct wpa_ssid *start = ssid, *tssid; |
| 1277 | int freqs_set = 0; |
| 1278 | if (ssid == NULL && max_ssids > 1) |
| 1279 | ssid = wpa_s->conf->ssid; |
| 1280 | while (ssid) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1281 | if (!wpas_network_disabled(wpa_s, ssid) && |
| 1282 | ssid->scan_ssid) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1283 | wpa_hexdump_ascii(MSG_DEBUG, "Scan SSID", |
| 1284 | ssid->ssid, ssid->ssid_len); |
| 1285 | params.ssids[params.num_ssids].ssid = |
| 1286 | ssid->ssid; |
| 1287 | params.ssids[params.num_ssids].ssid_len = |
| 1288 | ssid->ssid_len; |
| 1289 | params.num_ssids++; |
| 1290 | if (params.num_ssids + 1 >= max_ssids) |
| 1291 | break; |
| 1292 | } |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 1293 | |
| 1294 | if (!wpas_network_disabled(wpa_s, ssid)) { |
| 1295 | /* |
| 1296 | * Also add the SSID of the OWE BSS, to allow |
| 1297 | * discovery of transition mode APs more |
| 1298 | * quickly. |
| 1299 | */ |
| 1300 | wpa_add_owe_scan_ssid(wpa_s, ¶ms, ssid, |
| 1301 | max_ssids); |
| 1302 | } |
| 1303 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1304 | ssid = ssid->next; |
| 1305 | if (ssid == start) |
| 1306 | break; |
| 1307 | if (ssid == NULL && max_ssids > 1 && |
| 1308 | start != wpa_s->conf->ssid) |
| 1309 | ssid = wpa_s->conf->ssid; |
| 1310 | } |
| 1311 | |
Dmitry Shmidt | c281702 | 2014-07-02 10:32:10 -0700 | [diff] [blame] | 1312 | if (wpa_s->scan_id_count && |
| 1313 | wpa_s->last_scan_req == MANUAL_SCAN_REQ) |
| 1314 | wpa_set_scan_ssids(wpa_s, ¶ms, max_ssids); |
| 1315 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1316 | for (tssid = wpa_s->conf->ssid; |
| 1317 | wpa_s->last_scan_req != MANUAL_SCAN_REQ && tssid; |
| 1318 | tssid = tssid->next) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1319 | if (wpas_network_disabled(wpa_s, tssid)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1320 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1321 | if (((params.freqs || !freqs_set) && |
| 1322 | tssid->scan_freq) && |
| 1323 | int_array_len(params.freqs) < 100) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1324 | int_array_concat(¶ms.freqs, |
| 1325 | tssid->scan_freq); |
| 1326 | } else { |
| 1327 | os_free(params.freqs); |
| 1328 | params.freqs = NULL; |
| 1329 | } |
| 1330 | freqs_set = 1; |
| 1331 | } |
| 1332 | int_array_sort_unique(params.freqs); |
| 1333 | } |
| 1334 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1335 | if (ssid && max_ssids == 1) { |
| 1336 | /* |
| 1337 | * If the driver is limited to 1 SSID at a time interleave |
| 1338 | * wildcard SSID scans with specific SSID scans to avoid |
| 1339 | * waiting a long time for a wildcard scan. |
| 1340 | */ |
| 1341 | if (!wpa_s->prev_scan_wildcard) { |
| 1342 | params.ssids[0].ssid = NULL; |
| 1343 | params.ssids[0].ssid_len = 0; |
| 1344 | wpa_s->prev_scan_wildcard = 1; |
| 1345 | wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for " |
| 1346 | "wildcard SSID (Interleave with specific)"); |
| 1347 | } else { |
| 1348 | wpa_s->prev_scan_ssid = ssid; |
| 1349 | wpa_s->prev_scan_wildcard = 0; |
| 1350 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1351 | "Starting AP scan for specific SSID: %s", |
| 1352 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1353 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 1354 | } else if (ssid) { |
| 1355 | /* max_ssids > 1 */ |
| 1356 | |
| 1357 | wpa_s->prev_scan_ssid = ssid; |
| 1358 | wpa_dbg(wpa_s, MSG_DEBUG, "Include wildcard SSID in " |
| 1359 | "the scan request"); |
| 1360 | params.num_ssids++; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1361 | } else if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 1362 | wpa_s->manual_scan_passive && params.num_ssids == 0) { |
| 1363 | wpa_dbg(wpa_s, MSG_DEBUG, "Use passive scan based on manual request"); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 1364 | } else if (wpa_s->conf->passive_scan) { |
| 1365 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1366 | "Use passive scan based on configuration"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1367 | } else { |
| 1368 | wpa_s->prev_scan_ssid = WILDCARD_SSID_SCAN; |
| 1369 | params.num_ssids++; |
| 1370 | wpa_dbg(wpa_s, MSG_DEBUG, "Starting AP scan for wildcard " |
| 1371 | "SSID"); |
| 1372 | } |
| 1373 | |
Dmitry Shmidt | 7a53dbb | 2015-06-11 13:13:53 -0700 | [diff] [blame] | 1374 | ssid_list_set: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1375 | wpa_supplicant_optimize_freqs(wpa_s, ¶ms); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1376 | extra_ie = wpa_supplicant_extra_ies(wpa_s); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1377 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1378 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1379 | wpa_s->manual_scan_only_new) { |
| 1380 | wpa_printf(MSG_DEBUG, |
| 1381 | "Request driver to clear scan cache due to manual only_new=1 scan"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1382 | params.only_new_results = 1; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1383 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1384 | |
| 1385 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && params.freqs == NULL && |
| 1386 | wpa_s->manual_scan_freqs) { |
| 1387 | wpa_dbg(wpa_s, MSG_DEBUG, "Limit manual scan to specified channels"); |
| 1388 | params.freqs = wpa_s->manual_scan_freqs; |
| 1389 | wpa_s->manual_scan_freqs = NULL; |
| 1390 | } |
| 1391 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1392 | if (params.freqs == NULL && wpa_s->select_network_scan_freqs) { |
| 1393 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1394 | "Limit select_network scan to specified channels"); |
| 1395 | params.freqs = wpa_s->select_network_scan_freqs; |
| 1396 | wpa_s->select_network_scan_freqs = NULL; |
| 1397 | } |
| 1398 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1399 | if (params.freqs == NULL && wpa_s->next_scan_freqs) { |
| 1400 | wpa_dbg(wpa_s, MSG_DEBUG, "Optimize scan based on previously " |
| 1401 | "generated frequency list"); |
| 1402 | params.freqs = wpa_s->next_scan_freqs; |
| 1403 | } else |
| 1404 | os_free(wpa_s->next_scan_freqs); |
| 1405 | wpa_s->next_scan_freqs = NULL; |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1406 | wpa_setband_scan_freqs(wpa_s, ¶ms); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1407 | |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 1408 | /* See if user specified frequencies. If so, scan only those. */ |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 1409 | if (wpa_s->last_scan_req == INITIAL_SCAN_REQ && |
| 1410 | wpa_s->conf->initial_freq_list && !params.freqs) { |
| 1411 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1412 | "Optimize scan based on conf->initial_freq_list"); |
| 1413 | int_array_concat(¶ms.freqs, wpa_s->conf->initial_freq_list); |
| 1414 | } else if (wpa_s->conf->freq_list && !params.freqs) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 1415 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1416 | "Optimize scan based on conf->freq_list"); |
| 1417 | int_array_concat(¶ms.freqs, wpa_s->conf->freq_list); |
| 1418 | } |
| 1419 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 1420 | /* Use current associated channel? */ |
| 1421 | if (wpa_s->conf->scan_cur_freq && !params.freqs) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1422 | unsigned int num = wpa_s->num_multichan_concurrent; |
| 1423 | |
| 1424 | params.freqs = os_calloc(num + 1, sizeof(int)); |
| 1425 | if (params.freqs) { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1426 | num = get_shared_radio_freqs(wpa_s, params.freqs, num, |
| 1427 | false); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1428 | if (num > 0) { |
| 1429 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan only the " |
| 1430 | "current operating channels since " |
| 1431 | "scan_cur_freq is enabled"); |
| 1432 | } else { |
| 1433 | os_free(params.freqs); |
| 1434 | params.freqs = NULL; |
| 1435 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 1439 | #ifdef CONFIG_MBO |
| 1440 | if (wpa_s->enable_oce & OCE_STA) |
| 1441 | params.oce_scan = 1; |
| 1442 | #endif /* CONFIG_MBO */ |
| 1443 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1444 | params.filter_ssids = wpa_supplicant_build_filter_ssids( |
| 1445 | wpa_s->conf, ¶ms.num_filter_ssids); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1446 | if (extra_ie) { |
| 1447 | params.extra_ies = wpabuf_head(extra_ie); |
| 1448 | params.extra_ies_len = wpabuf_len(extra_ie); |
| 1449 | } |
| 1450 | |
| 1451 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 1452 | if (wpa_s->p2p_in_provisioning || wpa_s->p2p_in_invitation || |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1453 | (wpa_s->show_group_started && wpa_s->go_params)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1454 | /* |
| 1455 | * The interface may not yet be in P2P mode, so we have to |
| 1456 | * explicitly request P2P probe to disable CCK rates. |
| 1457 | */ |
| 1458 | params.p2p_probe = 1; |
| 1459 | } |
| 1460 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1461 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1462 | if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCAN) && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1463 | wpa_s->wpa_state <= WPA_SCANNING) |
| 1464 | wpa_setup_mac_addr_rand_params(¶ms, wpa_s->mac_addr_scan); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1465 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1466 | if (!is_zero_ether_addr(wpa_s->next_scan_bssid)) { |
| 1467 | struct wpa_bss *bss; |
| 1468 | |
| 1469 | params.bssid = wpa_s->next_scan_bssid; |
| 1470 | bss = wpa_bss_get_bssid_latest(wpa_s, params.bssid); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1471 | if (!wpa_s->next_scan_bssid_wildcard_ssid && |
| 1472 | bss && bss->ssid_len && params.num_ssids == 1 && |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1473 | params.ssids[0].ssid_len == 0) { |
| 1474 | params.ssids[0].ssid = bss->ssid; |
| 1475 | params.ssids[0].ssid_len = bss->ssid_len; |
| 1476 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1477 | "Scan a previously specified BSSID " MACSTR |
| 1478 | " and SSID %s", |
| 1479 | MAC2STR(params.bssid), |
| 1480 | wpa_ssid_txt(bss->ssid, bss->ssid_len)); |
| 1481 | } else { |
| 1482 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1483 | "Scan a previously specified BSSID " MACSTR, |
| 1484 | MAC2STR(params.bssid)); |
| 1485 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1486 | } else if (!is_zero_ether_addr(wpa_s->ml_probe_bssid)) { |
| 1487 | wpa_printf(MSG_DEBUG, "Scanning for ML probe request"); |
| 1488 | params.bssid = wpa_s->ml_probe_bssid; |
| 1489 | params.min_probe_req_content = true; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1492 | |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 1493 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 1494 | wpa_s->manual_non_coloc_6ghz) { |
| 1495 | wpa_dbg(wpa_s, MSG_DEBUG, "Collocated 6 GHz logic is disabled"); |
| 1496 | params.non_coloc_6ghz = 1; |
| 1497 | } |
| 1498 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1499 | scan_params = ¶ms; |
| 1500 | |
| 1501 | scan: |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1502 | #ifdef CONFIG_P2P |
| 1503 | /* |
| 1504 | * If the driver does not support multi-channel concurrency and a |
| 1505 | * virtual interface that shares the same radio with the wpa_s interface |
| 1506 | * is operating there may not be need to scan other channels apart from |
| 1507 | * the current operating channel on the other virtual interface. Filter |
| 1508 | * out other channels in case we are trying to find a connection for a |
| 1509 | * station interface when we are not configured to prefer station |
| 1510 | * connection and a concurrent operation is already in process. |
| 1511 | */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1512 | if (wpa_s->scan_for_connection && |
| 1513 | wpa_s->last_scan_req == NORMAL_SCAN_REQ && |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1514 | !scan_params->freqs && !params.freqs && |
| 1515 | wpas_is_p2p_prioritized(wpa_s) && |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1516 | wpa_s->p2p_group_interface == NOT_P2P_GROUP_INTERFACE && |
| 1517 | non_p2p_network_enabled(wpa_s)) { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1518 | unsigned int num = wpa_s->num_multichan_concurrent; |
| 1519 | |
| 1520 | params.freqs = os_calloc(num + 1, sizeof(int)); |
| 1521 | if (params.freqs) { |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1522 | /* |
| 1523 | * Exclude the operating frequency of the current |
| 1524 | * interface since we're looking to transition off of |
| 1525 | * it. |
| 1526 | */ |
| 1527 | num = get_shared_radio_freqs(wpa_s, params.freqs, num, |
| 1528 | true); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1529 | if (num > 0 && num == wpa_s->num_multichan_concurrent) { |
| 1530 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan only the current operating channels since all channels are already used"); |
| 1531 | } else { |
| 1532 | os_free(params.freqs); |
| 1533 | params.freqs = NULL; |
| 1534 | } |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1535 | } |
| 1536 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1537 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1538 | if (!params.freqs && wpas_is_6ghz_supported(wpa_s, true) && |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 1539 | (wpa_s->p2p_in_invitation || wpa_s->p2p_in_provisioning)) |
| 1540 | wpas_p2p_scan_freqs(wpa_s, ¶ms, true); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1541 | #endif /* CONFIG_P2P */ |
| 1542 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1543 | ret = wpa_supplicant_trigger_scan(wpa_s, scan_params, false, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1544 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1545 | if (ret && wpa_s->last_scan_req == MANUAL_SCAN_REQ && params.freqs && |
| 1546 | !wpa_s->manual_scan_freqs) { |
| 1547 | /* Restore manual_scan_freqs for the next attempt */ |
| 1548 | wpa_s->manual_scan_freqs = params.freqs; |
| 1549 | params.freqs = NULL; |
| 1550 | } |
| 1551 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1552 | wpabuf_free(extra_ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1553 | os_free(params.freqs); |
| 1554 | os_free(params.filter_ssids); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1555 | os_free(params.mac_addr); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1556 | |
| 1557 | if (ret) { |
| 1558 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate AP scan"); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1559 | if (wpa_s->scan_prev_wpa_state != wpa_s->wpa_state) |
| 1560 | wpa_supplicant_set_state(wpa_s, |
| 1561 | wpa_s->scan_prev_wpa_state); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1562 | /* Restore scan_req since we will try to scan again */ |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 1563 | wpa_s->scan_req = wpa_s->last_scan_req; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1564 | wpa_supplicant_req_scan(wpa_s, 1, 0); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 1565 | } else { |
| 1566 | wpa_s->scan_for_connection = 0; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 1567 | #ifdef CONFIG_INTERWORKING |
| 1568 | wpa_s->interworking_fast_assoc_tried = 0; |
| 1569 | #endif /* CONFIG_INTERWORKING */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1570 | wpa_s->next_scan_bssid_wildcard_ssid = 0; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1571 | if (params.bssid) |
| 1572 | os_memset(wpa_s->next_scan_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1573 | } |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 1574 | |
| 1575 | wpa_s->ml_probe_mld_id = -1; |
| 1576 | wpa_s->ml_probe_links = 0; |
| 1577 | os_memset(wpa_s->ml_probe_bssid, 0, sizeof(wpa_s->ml_probe_bssid)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1581 | void wpa_supplicant_update_scan_int(struct wpa_supplicant *wpa_s, int sec) |
| 1582 | { |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 1583 | struct os_reltime remaining, new_int; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1584 | int cancelled; |
| 1585 | |
| 1586 | cancelled = eloop_cancel_timeout_one(wpa_supplicant_scan, wpa_s, NULL, |
| 1587 | &remaining); |
| 1588 | |
| 1589 | new_int.sec = sec; |
| 1590 | new_int.usec = 0; |
Dmitry Shmidt | fa3fc4a | 2013-11-21 13:34:38 -0800 | [diff] [blame] | 1591 | if (cancelled && os_reltime_before(&remaining, &new_int)) { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1592 | new_int.sec = remaining.sec; |
| 1593 | new_int.usec = remaining.usec; |
| 1594 | } |
| 1595 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1596 | if (cancelled) { |
| 1597 | eloop_register_timeout(new_int.sec, new_int.usec, |
| 1598 | wpa_supplicant_scan, wpa_s, NULL); |
| 1599 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 1600 | wpa_s->scan_interval = sec; |
| 1601 | } |
| 1602 | |
| 1603 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1604 | /** |
| 1605 | * wpa_supplicant_req_scan - Schedule a scan for neighboring access points |
| 1606 | * @wpa_s: Pointer to wpa_supplicant data |
| 1607 | * @sec: Number of seconds after which to scan |
| 1608 | * @usec: Number of microseconds after which to scan |
| 1609 | * |
| 1610 | * This function is used to schedule a scan for neighboring access points after |
| 1611 | * the specified time. |
| 1612 | */ |
| 1613 | void wpa_supplicant_req_scan(struct wpa_supplicant *wpa_s, int sec, int usec) |
| 1614 | { |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 1615 | int res; |
| 1616 | |
| 1617 | if (wpa_s->p2p_mgmt) { |
| 1618 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1619 | "Ignore scan request (%d.%06d sec) on p2p_mgmt interface", |
| 1620 | sec, usec); |
| 1621 | return; |
| 1622 | } |
| 1623 | |
| 1624 | res = eloop_deplete_timeout(sec, usec, wpa_supplicant_scan, wpa_s, |
| 1625 | NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1626 | if (res == 1) { |
| 1627 | wpa_dbg(wpa_s, MSG_DEBUG, "Rescheduling scan request: %d.%06d sec", |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1628 | sec, usec); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1629 | } else if (res == 0) { |
| 1630 | wpa_dbg(wpa_s, MSG_DEBUG, "Ignore new scan request for %d.%06d sec since an earlier request is scheduled to trigger sooner", |
| 1631 | sec, usec); |
| 1632 | } else { |
| 1633 | wpa_dbg(wpa_s, MSG_DEBUG, "Setting scan request: %d.%06d sec", |
| 1634 | sec, usec); |
| 1635 | eloop_register_timeout(sec, usec, wpa_supplicant_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1636 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | /** |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1641 | * wpa_supplicant_delayed_sched_scan - Request a delayed scheduled scan |
| 1642 | * @wpa_s: Pointer to wpa_supplicant data |
| 1643 | * @sec: Number of seconds after which to scan |
| 1644 | * @usec: Number of microseconds after which to scan |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1645 | * Returns: 0 on success or -1 otherwise |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1646 | * |
| 1647 | * This function is used to schedule periodic scans for neighboring |
| 1648 | * access points after the specified time. |
| 1649 | */ |
| 1650 | int wpa_supplicant_delayed_sched_scan(struct wpa_supplicant *wpa_s, |
| 1651 | int sec, int usec) |
| 1652 | { |
| 1653 | if (!wpa_s->sched_scan_supported) |
| 1654 | return -1; |
| 1655 | |
| 1656 | eloop_register_timeout(sec, usec, |
| 1657 | wpa_supplicant_delayed_sched_scan_timeout, |
| 1658 | wpa_s, NULL); |
| 1659 | |
| 1660 | return 0; |
| 1661 | } |
| 1662 | |
| 1663 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1664 | static void |
| 1665 | wpa_scan_set_relative_rssi_params(struct wpa_supplicant *wpa_s, |
| 1666 | struct wpa_driver_scan_params *params) |
| 1667 | { |
| 1668 | if (wpa_s->wpa_state != WPA_COMPLETED || |
| 1669 | !(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SCHED_SCAN_RELATIVE_RSSI) || |
| 1670 | wpa_s->srp.relative_rssi_set == 0) |
| 1671 | return; |
| 1672 | |
| 1673 | params->relative_rssi_set = 1; |
| 1674 | params->relative_rssi = wpa_s->srp.relative_rssi; |
| 1675 | |
| 1676 | if (wpa_s->srp.relative_adjust_rssi == 0) |
| 1677 | return; |
| 1678 | |
| 1679 | params->relative_adjust_band = wpa_s->srp.relative_adjust_band; |
| 1680 | params->relative_adjust_rssi = wpa_s->srp.relative_adjust_rssi; |
| 1681 | } |
| 1682 | |
| 1683 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1684 | /** |
| 1685 | * wpa_supplicant_req_sched_scan - Start a periodic scheduled scan |
| 1686 | * @wpa_s: Pointer to wpa_supplicant data |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1687 | * Returns: 0 is sched_scan was started or -1 otherwise |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1688 | * |
| 1689 | * This function is used to schedule periodic scans for neighboring |
| 1690 | * access points repeating the scan continuously. |
| 1691 | */ |
| 1692 | int wpa_supplicant_req_sched_scan(struct wpa_supplicant *wpa_s) |
| 1693 | { |
| 1694 | struct wpa_driver_scan_params params; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1695 | struct wpa_driver_scan_params *scan_params; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1696 | enum wpa_states prev_state; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1697 | struct wpa_ssid *ssid = NULL; |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1698 | struct wpabuf *extra_ie = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1699 | int ret; |
| 1700 | unsigned int max_sched_scan_ssids; |
| 1701 | int wildcard = 0; |
| 1702 | int need_ssids; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1703 | struct sched_scan_plan scan_plan; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1704 | |
| 1705 | if (!wpa_s->sched_scan_supported) |
| 1706 | return -1; |
| 1707 | |
| 1708 | if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS) |
| 1709 | max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS; |
| 1710 | else |
| 1711 | max_sched_scan_ssids = wpa_s->max_sched_scan_ssids; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1712 | if (max_sched_scan_ssids < 1 || wpa_s->conf->disable_scan_offload) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1713 | return -1; |
| 1714 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 1715 | wpa_s->sched_scan_stop_req = 0; |
| 1716 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1717 | if (wpa_s->sched_scanning) { |
| 1718 | wpa_dbg(wpa_s, MSG_DEBUG, "Already sched scanning"); |
| 1719 | return 0; |
| 1720 | } |
| 1721 | |
| 1722 | need_ssids = 0; |
| 1723 | for (ssid = wpa_s->conf->ssid; ssid; ssid = ssid->next) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1724 | if (!wpas_network_disabled(wpa_s, ssid) && !ssid->scan_ssid) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1725 | /* Use wildcard SSID to find this network */ |
| 1726 | wildcard = 1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1727 | } else if (!wpas_network_disabled(wpa_s, ssid) && |
| 1728 | ssid->ssid_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1729 | need_ssids++; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1730 | |
| 1731 | #ifdef CONFIG_WPS |
| 1732 | if (!wpas_network_disabled(wpa_s, ssid) && |
| 1733 | ssid->key_mgmt == WPA_KEY_MGMT_WPS) { |
| 1734 | /* |
| 1735 | * Normal scan is more reliable and faster for WPS |
| 1736 | * operations and since these are for short periods of |
| 1737 | * time, the benefit of trying to use sched_scan would |
| 1738 | * be limited. |
| 1739 | */ |
| 1740 | wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of " |
| 1741 | "sched_scan for WPS"); |
| 1742 | return -1; |
| 1743 | } |
| 1744 | #endif /* CONFIG_WPS */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1745 | } |
| 1746 | if (wildcard) |
| 1747 | need_ssids++; |
| 1748 | |
| 1749 | if (wpa_s->normal_scans < 3 && |
| 1750 | (need_ssids <= wpa_s->max_scan_ssids || |
| 1751 | wpa_s->max_scan_ssids >= (int) max_sched_scan_ssids)) { |
| 1752 | /* |
| 1753 | * When normal scan can speed up operations, use that for the |
| 1754 | * first operations before starting the sched_scan to allow |
| 1755 | * user space sleep more. We do this only if the normal scan |
| 1756 | * has functionality that is suitable for this or if the |
| 1757 | * sched_scan does not have better support for multiple SSIDs. |
| 1758 | */ |
| 1759 | wpa_dbg(wpa_s, MSG_DEBUG, "Use normal scan instead of " |
| 1760 | "sched_scan for initial scans (normal_scans=%d)", |
| 1761 | wpa_s->normal_scans); |
| 1762 | return -1; |
| 1763 | } |
| 1764 | |
| 1765 | os_memset(¶ms, 0, sizeof(params)); |
| 1766 | |
| 1767 | /* If we can't allocate space for the filters, we just don't filter */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1768 | params.filter_ssids = os_calloc(wpa_s->max_match_sets, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1769 | sizeof(struct wpa_driver_scan_filter)); |
| 1770 | |
| 1771 | prev_state = wpa_s->wpa_state; |
| 1772 | if (wpa_s->wpa_state == WPA_DISCONNECTED || |
| 1773 | wpa_s->wpa_state == WPA_INACTIVE) |
| 1774 | wpa_supplicant_set_state(wpa_s, WPA_SCANNING); |
| 1775 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1776 | if (wpa_s->autoscan_params != NULL) { |
| 1777 | scan_params = wpa_s->autoscan_params; |
| 1778 | goto scan; |
| 1779 | } |
| 1780 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1781 | /* Find the starting point from which to continue scanning */ |
| 1782 | ssid = wpa_s->conf->ssid; |
| 1783 | if (wpa_s->prev_sched_ssid) { |
| 1784 | while (ssid) { |
| 1785 | if (ssid == wpa_s->prev_sched_ssid) { |
| 1786 | ssid = ssid->next; |
| 1787 | break; |
| 1788 | } |
| 1789 | ssid = ssid->next; |
| 1790 | } |
| 1791 | } |
| 1792 | |
| 1793 | if (!ssid || !wpa_s->prev_sched_ssid) { |
| 1794 | wpa_dbg(wpa_s, MSG_DEBUG, "Beginning of SSID list"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1795 | wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2; |
| 1796 | wpa_s->first_sched_scan = 1; |
| 1797 | ssid = wpa_s->conf->ssid; |
| 1798 | wpa_s->prev_sched_ssid = ssid; |
| 1799 | } |
| 1800 | |
| 1801 | if (wildcard) { |
| 1802 | wpa_dbg(wpa_s, MSG_DEBUG, "Add wildcard SSID to sched_scan"); |
| 1803 | params.num_ssids++; |
| 1804 | } |
| 1805 | |
| 1806 | while (ssid) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1807 | if (wpas_network_disabled(wpa_s, ssid)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1808 | goto next; |
| 1809 | |
| 1810 | if (params.num_filter_ssids < wpa_s->max_match_sets && |
| 1811 | params.filter_ssids && ssid->ssid && ssid->ssid_len) { |
| 1812 | wpa_dbg(wpa_s, MSG_DEBUG, "add to filter ssid: %s", |
| 1813 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 1814 | os_memcpy(params.filter_ssids[params.num_filter_ssids].ssid, |
| 1815 | ssid->ssid, ssid->ssid_len); |
| 1816 | params.filter_ssids[params.num_filter_ssids].ssid_len = |
| 1817 | ssid->ssid_len; |
| 1818 | params.num_filter_ssids++; |
| 1819 | } else if (params.filter_ssids && ssid->ssid && ssid->ssid_len) |
| 1820 | { |
| 1821 | wpa_dbg(wpa_s, MSG_DEBUG, "Not enough room for SSID " |
| 1822 | "filter for sched_scan - drop filter"); |
| 1823 | os_free(params.filter_ssids); |
| 1824 | params.filter_ssids = NULL; |
| 1825 | params.num_filter_ssids = 0; |
| 1826 | } |
| 1827 | |
| 1828 | if (ssid->scan_ssid && ssid->ssid && ssid->ssid_len) { |
| 1829 | if (params.num_ssids == max_sched_scan_ssids) |
| 1830 | break; /* only room for broadcast SSID */ |
| 1831 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1832 | "add to active scan ssid: %s", |
| 1833 | wpa_ssid_txt(ssid->ssid, ssid->ssid_len)); |
| 1834 | params.ssids[params.num_ssids].ssid = |
| 1835 | ssid->ssid; |
| 1836 | params.ssids[params.num_ssids].ssid_len = |
| 1837 | ssid->ssid_len; |
| 1838 | params.num_ssids++; |
| 1839 | if (params.num_ssids >= max_sched_scan_ssids) { |
| 1840 | wpa_s->prev_sched_ssid = ssid; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1841 | do { |
| 1842 | ssid = ssid->next; |
| 1843 | } while (ssid && |
| 1844 | (wpas_network_disabled(wpa_s, ssid) || |
| 1845 | !ssid->scan_ssid)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1846 | break; |
| 1847 | } |
| 1848 | } |
| 1849 | |
| 1850 | next: |
| 1851 | wpa_s->prev_sched_ssid = ssid; |
| 1852 | ssid = ssid->next; |
| 1853 | } |
| 1854 | |
| 1855 | if (params.num_filter_ssids == 0) { |
| 1856 | os_free(params.filter_ssids); |
| 1857 | params.filter_ssids = NULL; |
| 1858 | } |
| 1859 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1860 | extra_ie = wpa_supplicant_extra_ies(wpa_s); |
| 1861 | if (extra_ie) { |
| 1862 | params.extra_ies = wpabuf_head(extra_ie); |
| 1863 | params.extra_ies_len = wpabuf_len(extra_ie); |
| 1864 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1865 | |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1866 | if (wpa_s->conf->filter_rssi) |
| 1867 | params.filter_rssi = wpa_s->conf->filter_rssi; |
| 1868 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1869 | /* See if user specified frequencies. If so, scan only those. */ |
| 1870 | if (wpa_s->conf->freq_list && !params.freqs) { |
| 1871 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1872 | "Optimize scan based on conf->freq_list"); |
| 1873 | int_array_concat(¶ms.freqs, wpa_s->conf->freq_list); |
| 1874 | } |
| 1875 | |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 1876 | #ifdef CONFIG_MBO |
| 1877 | if (wpa_s->enable_oce & OCE_STA) |
| 1878 | params.oce_scan = 1; |
| 1879 | #endif /* CONFIG_MBO */ |
| 1880 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1881 | scan_params = ¶ms; |
| 1882 | |
| 1883 | scan: |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1884 | wpa_s->sched_scan_timed_out = 0; |
| 1885 | |
| 1886 | /* |
| 1887 | * We cannot support multiple scan plans if the scan request includes |
| 1888 | * too many SSID's, so in this case use only the last scan plan and make |
| 1889 | * it run infinitely. It will be stopped by the timeout. |
| 1890 | */ |
| 1891 | if (wpa_s->sched_scan_plans_num == 1 || |
| 1892 | (wpa_s->sched_scan_plans_num && !ssid && wpa_s->first_sched_scan)) { |
| 1893 | params.sched_scan_plans = wpa_s->sched_scan_plans; |
| 1894 | params.sched_scan_plans_num = wpa_s->sched_scan_plans_num; |
| 1895 | } else if (wpa_s->sched_scan_plans_num > 1) { |
| 1896 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1897 | "Too many SSIDs. Default to using single scheduled_scan plan"); |
| 1898 | params.sched_scan_plans = |
| 1899 | &wpa_s->sched_scan_plans[wpa_s->sched_scan_plans_num - |
| 1900 | 1]; |
| 1901 | params.sched_scan_plans_num = 1; |
| 1902 | } else { |
| 1903 | if (wpa_s->conf->sched_scan_interval) |
| 1904 | scan_plan.interval = wpa_s->conf->sched_scan_interval; |
| 1905 | else |
| 1906 | scan_plan.interval = 10; |
| 1907 | |
| 1908 | if (scan_plan.interval > wpa_s->max_sched_scan_plan_interval) { |
| 1909 | wpa_printf(MSG_WARNING, |
| 1910 | "Scan interval too long(%u), use the maximum allowed(%u)", |
| 1911 | scan_plan.interval, |
| 1912 | wpa_s->max_sched_scan_plan_interval); |
| 1913 | scan_plan.interval = |
| 1914 | wpa_s->max_sched_scan_plan_interval; |
| 1915 | } |
| 1916 | |
| 1917 | scan_plan.iterations = 0; |
| 1918 | params.sched_scan_plans = &scan_plan; |
| 1919 | params.sched_scan_plans_num = 1; |
| 1920 | } |
| 1921 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1922 | params.sched_scan_start_delay = wpa_s->conf->sched_scan_start_delay; |
| 1923 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1924 | if (ssid || !wpa_s->first_sched_scan) { |
| 1925 | wpa_dbg(wpa_s, MSG_DEBUG, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1926 | "Starting sched scan after %u seconds: interval %u timeout %d", |
| 1927 | params.sched_scan_start_delay, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1928 | params.sched_scan_plans[0].interval, |
| 1929 | wpa_s->sched_scan_timeout); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1930 | } else { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1931 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 1932 | "Starting sched scan after %u seconds (no timeout)", |
| 1933 | params.sched_scan_start_delay); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1934 | } |
| 1935 | |
Dmitry Shmidt | b6e9aaf | 2013-05-20 14:49:44 -0700 | [diff] [blame] | 1936 | wpa_setband_scan_freqs(wpa_s, scan_params); |
| 1937 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1938 | if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_SCHED_SCAN) && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1939 | wpa_s->wpa_state <= WPA_SCANNING) |
| 1940 | wpa_setup_mac_addr_rand_params(¶ms, |
| 1941 | wpa_s->mac_addr_sched_scan); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1942 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 1943 | wpa_scan_set_relative_rssi_params(wpa_s, scan_params); |
| 1944 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1945 | ret = wpa_supplicant_start_sched_scan(wpa_s, scan_params); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 1946 | wpabuf_free(extra_ie); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1947 | os_free(params.filter_ssids); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 1948 | os_free(params.mac_addr); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1949 | if (ret) { |
| 1950 | wpa_msg(wpa_s, MSG_WARNING, "Failed to initiate sched scan"); |
| 1951 | if (prev_state != wpa_s->wpa_state) |
| 1952 | wpa_supplicant_set_state(wpa_s, prev_state); |
| 1953 | return ret; |
| 1954 | } |
| 1955 | |
| 1956 | /* If we have more SSIDs to scan, add a timeout so we scan them too */ |
| 1957 | if (ssid || !wpa_s->first_sched_scan) { |
| 1958 | wpa_s->sched_scan_timed_out = 0; |
| 1959 | eloop_register_timeout(wpa_s->sched_scan_timeout, 0, |
| 1960 | wpa_supplicant_sched_scan_timeout, |
| 1961 | wpa_s, NULL); |
| 1962 | wpa_s->first_sched_scan = 0; |
| 1963 | wpa_s->sched_scan_timeout /= 2; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 1964 | params.sched_scan_plans[0].interval *= 2; |
| 1965 | if ((unsigned int) wpa_s->sched_scan_timeout < |
| 1966 | params.sched_scan_plans[0].interval || |
| 1967 | params.sched_scan_plans[0].interval > |
| 1968 | wpa_s->max_sched_scan_plan_interval) { |
| 1969 | params.sched_scan_plans[0].interval = 10; |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1970 | wpa_s->sched_scan_timeout = max_sched_scan_ssids * 2; |
| 1971 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1972 | } |
| 1973 | |
Dmitry Shmidt | 2f02319 | 2013-03-12 12:44:17 -0700 | [diff] [blame] | 1974 | /* If there is no more ssids, start next time from the beginning */ |
| 1975 | if (!ssid) |
| 1976 | wpa_s->prev_sched_ssid = NULL; |
| 1977 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1978 | return 0; |
| 1979 | } |
| 1980 | |
| 1981 | |
| 1982 | /** |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1983 | * wpa_supplicant_cancel_scan - Cancel a scheduled scan request |
| 1984 | * @wpa_s: Pointer to wpa_supplicant data |
| 1985 | * |
| 1986 | * This function is used to cancel a scan request scheduled with |
| 1987 | * wpa_supplicant_req_scan(). |
| 1988 | */ |
| 1989 | void wpa_supplicant_cancel_scan(struct wpa_supplicant *wpa_s) |
| 1990 | { |
| 1991 | wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling scan request"); |
| 1992 | eloop_cancel_timeout(wpa_supplicant_scan, wpa_s, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1993 | } |
| 1994 | |
| 1995 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1996 | /** |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 1997 | * wpa_supplicant_cancel_delayed_sched_scan - Stop a delayed scheduled scan |
| 1998 | * @wpa_s: Pointer to wpa_supplicant data |
| 1999 | * |
| 2000 | * This function is used to stop a delayed scheduled scan. |
| 2001 | */ |
| 2002 | void wpa_supplicant_cancel_delayed_sched_scan(struct wpa_supplicant *wpa_s) |
| 2003 | { |
| 2004 | if (!wpa_s->sched_scan_supported) |
| 2005 | return; |
| 2006 | |
| 2007 | wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling delayed sched scan"); |
| 2008 | eloop_cancel_timeout(wpa_supplicant_delayed_sched_scan_timeout, |
| 2009 | wpa_s, NULL); |
| 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | /** |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2014 | * wpa_supplicant_cancel_sched_scan - Stop running scheduled scans |
| 2015 | * @wpa_s: Pointer to wpa_supplicant data |
| 2016 | * |
| 2017 | * This function is used to stop a periodic scheduled scan. |
| 2018 | */ |
| 2019 | void wpa_supplicant_cancel_sched_scan(struct wpa_supplicant *wpa_s) |
| 2020 | { |
| 2021 | if (!wpa_s->sched_scanning) |
| 2022 | return; |
| 2023 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2024 | if (wpa_s->sched_scanning) |
| 2025 | wpa_s->sched_scan_stop_req = 1; |
| 2026 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2027 | wpa_dbg(wpa_s, MSG_DEBUG, "Cancelling sched scan"); |
| 2028 | eloop_cancel_timeout(wpa_supplicant_sched_scan_timeout, wpa_s, NULL); |
| 2029 | wpa_supplicant_stop_sched_scan(wpa_s); |
| 2030 | } |
| 2031 | |
| 2032 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2033 | /** |
| 2034 | * wpa_supplicant_notify_scanning - Indicate possible scan state change |
| 2035 | * @wpa_s: Pointer to wpa_supplicant data |
| 2036 | * @scanning: Whether scanning is currently in progress |
| 2037 | * |
| 2038 | * This function is to generate scanning notifycations. It is called whenever |
| 2039 | * there may have been a change in scanning (scan started, completed, stopped). |
| 2040 | * wpas_notify_scanning() is called whenever the scanning state changed from the |
| 2041 | * previously notified state. |
| 2042 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2043 | void wpa_supplicant_notify_scanning(struct wpa_supplicant *wpa_s, |
| 2044 | int scanning) |
| 2045 | { |
| 2046 | if (wpa_s->scanning != scanning) { |
| 2047 | wpa_s->scanning = scanning; |
| 2048 | wpas_notify_scanning(wpa_s); |
| 2049 | } |
| 2050 | } |
| 2051 | |
| 2052 | |
| 2053 | static int wpa_scan_get_max_rate(const struct wpa_scan_res *res) |
| 2054 | { |
| 2055 | int rate = 0; |
| 2056 | const u8 *ie; |
| 2057 | int i; |
| 2058 | |
| 2059 | ie = wpa_scan_get_ie(res, WLAN_EID_SUPP_RATES); |
| 2060 | for (i = 0; ie && i < ie[1]; i++) { |
| 2061 | if ((ie[i + 2] & 0x7f) > rate) |
| 2062 | rate = ie[i + 2] & 0x7f; |
| 2063 | } |
| 2064 | |
| 2065 | ie = wpa_scan_get_ie(res, WLAN_EID_EXT_SUPP_RATES); |
| 2066 | for (i = 0; ie && i < ie[1]; i++) { |
| 2067 | if ((ie[i + 2] & 0x7f) > rate) |
| 2068 | rate = ie[i + 2] & 0x7f; |
| 2069 | } |
| 2070 | |
| 2071 | return rate; |
| 2072 | } |
| 2073 | |
| 2074 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2075 | /** |
| 2076 | * wpa_scan_get_ie - Fetch a specified information element from a scan result |
| 2077 | * @res: Scan result entry |
| 2078 | * @ie: Information element identitifier (WLAN_EID_*) |
| 2079 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 2080 | * |
| 2081 | * This function returns the first matching information element in the scan |
| 2082 | * result. |
| 2083 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2084 | const u8 * wpa_scan_get_ie(const struct wpa_scan_res *res, u8 ie) |
| 2085 | { |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 2086 | size_t ie_len = res->ie_len; |
| 2087 | |
| 2088 | /* Use the Beacon frame IEs if res->ie_len is not available */ |
| 2089 | if (!ie_len) |
| 2090 | ie_len = res->beacon_ie_len; |
| 2091 | |
| 2092 | return get_ie((const u8 *) (res + 1), ie_len, ie); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
| 2095 | |
Sunil Ravi | 89eba10 | 2022-09-13 21:04:37 -0700 | [diff] [blame] | 2096 | const u8 * wpa_scan_get_ml_ie(const struct wpa_scan_res *res, u8 type) |
| 2097 | { |
| 2098 | size_t ie_len = res->ie_len; |
| 2099 | |
| 2100 | /* Use the Beacon frame IEs if res->ie_len is not available */ |
| 2101 | if (!ie_len) |
| 2102 | ie_len = res->beacon_ie_len; |
| 2103 | |
| 2104 | return get_ml_ie((const u8 *) (res + 1), ie_len, type); |
| 2105 | } |
| 2106 | |
| 2107 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2108 | /** |
| 2109 | * wpa_scan_get_vendor_ie - Fetch vendor information element from a scan result |
| 2110 | * @res: Scan result entry |
| 2111 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 2112 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 2113 | * |
| 2114 | * This function returns the first matching information element in the scan |
| 2115 | * result. |
| 2116 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2117 | const u8 * wpa_scan_get_vendor_ie(const struct wpa_scan_res *res, |
| 2118 | u32 vendor_type) |
| 2119 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2120 | const u8 *ies; |
| 2121 | const struct element *elem; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2122 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2123 | ies = (const u8 *) (res + 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2124 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2125 | for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, res->ie_len) { |
| 2126 | if (elem->datalen >= 4 && |
| 2127 | vendor_type == WPA_GET_BE32(elem->data)) |
| 2128 | return &elem->id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | return NULL; |
| 2132 | } |
| 2133 | |
| 2134 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2135 | /** |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2136 | * wpa_scan_get_vendor_ie_beacon - Fetch vendor information from a scan result |
| 2137 | * @res: Scan result entry |
| 2138 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 2139 | * Returns: Pointer to the information element (id field) or %NULL if not found |
| 2140 | * |
| 2141 | * This function returns the first matching information element in the scan |
| 2142 | * result. |
| 2143 | * |
| 2144 | * This function is like wpa_scan_get_vendor_ie(), but uses IE buffer only |
| 2145 | * from Beacon frames instead of either Beacon or Probe Response frames. |
| 2146 | */ |
| 2147 | const u8 * wpa_scan_get_vendor_ie_beacon(const struct wpa_scan_res *res, |
| 2148 | u32 vendor_type) |
| 2149 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2150 | const u8 *ies; |
| 2151 | const struct element *elem; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2152 | |
| 2153 | if (res->beacon_ie_len == 0) |
| 2154 | return NULL; |
| 2155 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2156 | ies = (const u8 *) (res + 1); |
| 2157 | ies += res->ie_len; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2158 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2159 | for_each_element_id(elem, WLAN_EID_VENDOR_SPECIFIC, ies, |
| 2160 | res->beacon_ie_len) { |
| 2161 | if (elem->datalen >= 4 && |
| 2162 | vendor_type == WPA_GET_BE32(elem->data)) |
| 2163 | return &elem->id; |
Dmitry Shmidt | 9657139 | 2013-10-14 12:54:46 -0700 | [diff] [blame] | 2164 | } |
| 2165 | |
| 2166 | return NULL; |
| 2167 | } |
| 2168 | |
| 2169 | |
| 2170 | /** |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2171 | * wpa_scan_get_vendor_ie_multi - Fetch vendor IE data from a scan result |
| 2172 | * @res: Scan result entry |
| 2173 | * @vendor_type: Vendor type (four octets starting the IE payload) |
| 2174 | * Returns: Pointer to the information element payload or %NULL if not found |
| 2175 | * |
| 2176 | * This function returns concatenated payload of possibly fragmented vendor |
| 2177 | * specific information elements in the scan result. The caller is responsible |
| 2178 | * for freeing the returned buffer. |
| 2179 | */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2180 | struct wpabuf * wpa_scan_get_vendor_ie_multi(const struct wpa_scan_res *res, |
| 2181 | u32 vendor_type) |
| 2182 | { |
| 2183 | struct wpabuf *buf; |
| 2184 | const u8 *end, *pos; |
| 2185 | |
| 2186 | buf = wpabuf_alloc(res->ie_len); |
| 2187 | if (buf == NULL) |
| 2188 | return NULL; |
| 2189 | |
| 2190 | pos = (const u8 *) (res + 1); |
| 2191 | end = pos + res->ie_len; |
| 2192 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2193 | while (end - pos > 1) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2194 | u8 ie, len; |
| 2195 | |
| 2196 | ie = pos[0]; |
| 2197 | len = pos[1]; |
| 2198 | if (len > end - pos - 2) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2199 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2200 | pos += 2; |
| 2201 | if (ie == WLAN_EID_VENDOR_SPECIFIC && len >= 4 && |
| 2202 | vendor_type == WPA_GET_BE32(pos)) |
| 2203 | wpabuf_put_data(buf, pos + 4, len - 4); |
| 2204 | pos += len; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | if (wpabuf_len(buf) == 0) { |
| 2208 | wpabuf_free(buf); |
| 2209 | buf = NULL; |
| 2210 | } |
| 2211 | |
| 2212 | return buf; |
| 2213 | } |
| 2214 | |
| 2215 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2216 | static int wpas_channel_width_offset(enum chan_width cw) |
| 2217 | { |
| 2218 | switch (cw) { |
| 2219 | case CHAN_WIDTH_40: |
| 2220 | return 1; |
| 2221 | case CHAN_WIDTH_80: |
| 2222 | return 2; |
| 2223 | case CHAN_WIDTH_80P80: |
| 2224 | case CHAN_WIDTH_160: |
| 2225 | return 3; |
| 2226 | case CHAN_WIDTH_320: |
| 2227 | return 4; |
| 2228 | default: |
| 2229 | return 0; |
| 2230 | } |
| 2231 | } |
| 2232 | |
| 2233 | |
| 2234 | /** |
| 2235 | * wpas_channel_width_tx_pwr - Calculate the max transmit power at the channel |
| 2236 | * width |
| 2237 | * @ies: Information elements |
| 2238 | * @ies_len: Length of elements |
| 2239 | * @cw: The channel width |
| 2240 | * Returns: The max transmit power at the channel width, TX_POWER_NO_CONSTRAINT |
| 2241 | * if it is not constrained. |
| 2242 | * |
| 2243 | * This function is only used to estimate the actual signal RSSI when associated |
| 2244 | * based on the beacon RSSI at the STA. Beacon frames are transmitted on 20 MHz |
| 2245 | * channels, while the Data frames usually use higher channel width. Therefore |
| 2246 | * their RSSIs may be different. Assuming there is a fixed gap between the TX |
| 2247 | * power limit of the STA defined by the Transmit Power Envelope element and the |
| 2248 | * TX power of the AP, the difference in the TX power of X MHz and Y MHz at the |
| 2249 | * STA equals to the difference at the AP, and the difference in the signal RSSI |
| 2250 | * at the STA. tx_pwr is a floating point number in the standard, but the error |
| 2251 | * of casting to int is trivial in comparing two BSSes. |
| 2252 | */ |
| 2253 | static int wpas_channel_width_tx_pwr(const u8 *ies, size_t ies_len, |
| 2254 | enum chan_width cw) |
| 2255 | { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2256 | int offset = wpas_channel_width_offset(cw); |
| 2257 | const struct element *elem; |
| 2258 | int max_tx_power = TX_POWER_NO_CONSTRAINT, tx_pwr = 0; |
| 2259 | |
| 2260 | for_each_element_id(elem, WLAN_EID_TRANSMIT_POWER_ENVELOPE, ies, |
| 2261 | ies_len) { |
| 2262 | int max_tx_pwr_count; |
| 2263 | enum max_tx_pwr_interpretation tx_pwr_intrpn; |
| 2264 | enum reg_6g_client_type client_type; |
| 2265 | |
| 2266 | if (elem->datalen < 1) |
| 2267 | continue; |
| 2268 | |
| 2269 | /* |
| 2270 | * IEEE Std 802.11ax-2021, 9.4.2.161 (Transmit Power Envelope |
| 2271 | * element) defines Maximum Transmit Power Count (B0-B2), |
| 2272 | * Maximum Transmit Power Interpretation (B3-B5), and Maximum |
| 2273 | * Transmit Power Category (B6-B7). |
| 2274 | */ |
| 2275 | max_tx_pwr_count = elem->data[0] & 0x07; |
| 2276 | tx_pwr_intrpn = (elem->data[0] >> 3) & 0x07; |
| 2277 | client_type = (elem->data[0] >> 6) & 0x03; |
| 2278 | |
| 2279 | if (client_type != REG_DEFAULT_CLIENT) |
| 2280 | continue; |
| 2281 | |
| 2282 | if (tx_pwr_intrpn == LOCAL_EIRP || |
| 2283 | tx_pwr_intrpn == REGULATORY_CLIENT_EIRP) { |
| 2284 | int offs; |
| 2285 | |
| 2286 | max_tx_pwr_count = MIN(max_tx_pwr_count, 3); |
| 2287 | offs = MIN(offset, max_tx_pwr_count) + 1; |
| 2288 | if (elem->datalen <= offs) |
| 2289 | continue; |
| 2290 | tx_pwr = (signed char) elem->data[offs]; |
| 2291 | /* |
| 2292 | * Maximum Transmit Power subfield is encoded as an |
| 2293 | * 8-bit 2s complement signed integer in the range -64 |
| 2294 | * dBm to 63 dBm with a 0.5 dB step. 63.5 dBm means no |
| 2295 | * local maximum transmit power constraint. |
| 2296 | */ |
| 2297 | if (tx_pwr == 127) |
| 2298 | continue; |
| 2299 | tx_pwr /= 2; |
| 2300 | max_tx_power = MIN(max_tx_power, tx_pwr); |
| 2301 | } else if (tx_pwr_intrpn == LOCAL_EIRP_PSD || |
| 2302 | tx_pwr_intrpn == REGULATORY_CLIENT_EIRP_PSD) { |
| 2303 | if (elem->datalen < 2) |
| 2304 | continue; |
| 2305 | |
| 2306 | tx_pwr = (signed char) elem->data[1]; |
| 2307 | /* |
| 2308 | * Maximum Transmit PSD subfield is encoded as an 8-bit |
| 2309 | * 2s complement signed integer. -128 indicates that the |
| 2310 | * corresponding 20 MHz channel cannot be used for |
| 2311 | * transmission. +127 indicates that no maximum PSD |
| 2312 | * limit is specified for the corresponding 20 MHz |
| 2313 | * channel. |
| 2314 | */ |
| 2315 | if (tx_pwr == 127 || tx_pwr == -128) |
| 2316 | continue; |
| 2317 | |
| 2318 | /* |
| 2319 | * The Maximum Transmit PSD subfield indicates the |
| 2320 | * maximum transmit PSD for the 20 MHz channel. Suppose |
| 2321 | * the PSD value is X dBm/MHz, the TX power of N MHz is |
| 2322 | * X + 10*log10(N) = X + 10*log10(20) + 10*log10(N/20) = |
| 2323 | * X + 13 + 3*log2(N/20) |
| 2324 | */ |
| 2325 | tx_pwr = tx_pwr / 2 + 13 + offset * 3; |
| 2326 | max_tx_power = MIN(max_tx_power, tx_pwr); |
| 2327 | } |
| 2328 | } |
| 2329 | |
| 2330 | return max_tx_power; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | |
| 2334 | /** |
| 2335 | * Estimate the RSSI bump of channel width |cw| with respect to 20 MHz channel. |
| 2336 | * If the TX power has no constraint, it is unable to estimate the RSSI bump. |
| 2337 | */ |
| 2338 | int wpas_channel_width_rssi_bump(const u8 *ies, size_t ies_len, |
| 2339 | enum chan_width cw) |
| 2340 | { |
| 2341 | int max_20mhz_tx_pwr = wpas_channel_width_tx_pwr(ies, ies_len, |
| 2342 | CHAN_WIDTH_20); |
| 2343 | int max_cw_tx_pwr = wpas_channel_width_tx_pwr(ies, ies_len, cw); |
| 2344 | |
| 2345 | return (max_20mhz_tx_pwr == TX_POWER_NO_CONSTRAINT || |
| 2346 | max_cw_tx_pwr == TX_POWER_NO_CONSTRAINT) ? |
| 2347 | 0 : (max_cw_tx_pwr - max_20mhz_tx_pwr); |
| 2348 | } |
| 2349 | |
| 2350 | |
| 2351 | int wpas_adjust_snr_by_chanwidth(const u8 *ies, size_t ies_len, |
| 2352 | enum chan_width max_cw, int snr) |
| 2353 | { |
| 2354 | int rssi_bump = wpas_channel_width_rssi_bump(ies, ies_len, max_cw); |
| 2355 | /* |
| 2356 | * The noise has uniform power spectral density (PSD) across the |
| 2357 | * frequency band, its power is proportional to the channel width. |
| 2358 | * Suppose the PSD of noise is X dBm/MHz, the noise power of N MHz is |
| 2359 | * X + 10*log10(N), and the noise power bump with respect to 20 MHz is |
| 2360 | * 10*log10(N) - 10*log10(20) = 10*log10(N/20) = 3*log2(N/20) |
| 2361 | */ |
| 2362 | int noise_bump = 3 * wpas_channel_width_offset(max_cw); |
| 2363 | |
| 2364 | return snr + rssi_bump - noise_bump; |
| 2365 | } |
| 2366 | |
| 2367 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2368 | /* Compare function for sorting scan results. Return >0 if @b is considered |
| 2369 | * better. */ |
| 2370 | static int wpa_scan_result_compar(const void *a, const void *b) |
| 2371 | { |
| 2372 | struct wpa_scan_res **_wa = (void *) a; |
| 2373 | struct wpa_scan_res **_wb = (void *) b; |
| 2374 | struct wpa_scan_res *wa = *_wa; |
| 2375 | struct wpa_scan_res *wb = *_wb; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2376 | int wpa_a, wpa_b; |
| 2377 | int snr_a, snr_b, snr_a_full, snr_b_full; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2378 | size_t ies_len; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2379 | #ifndef CONFIG_NO_WPA |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2380 | const u8 *rsne_a, *rsne_b; |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2381 | #endif /* CONFIG_NO_WPA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2382 | |
| 2383 | /* WPA/WPA2 support preferred */ |
| 2384 | wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL || |
| 2385 | wpa_scan_get_ie(wa, WLAN_EID_RSN) != NULL; |
| 2386 | wpa_b = wpa_scan_get_vendor_ie(wb, WPA_IE_VENDOR_TYPE) != NULL || |
| 2387 | wpa_scan_get_ie(wb, WLAN_EID_RSN) != NULL; |
| 2388 | |
| 2389 | if (wpa_b && !wpa_a) |
| 2390 | return 1; |
| 2391 | if (!wpa_b && wpa_a) |
| 2392 | return -1; |
| 2393 | |
| 2394 | /* privacy support preferred */ |
| 2395 | if ((wa->caps & IEEE80211_CAP_PRIVACY) == 0 && |
| 2396 | (wb->caps & IEEE80211_CAP_PRIVACY)) |
| 2397 | return 1; |
| 2398 | if ((wa->caps & IEEE80211_CAP_PRIVACY) && |
| 2399 | (wb->caps & IEEE80211_CAP_PRIVACY) == 0) |
| 2400 | return -1; |
| 2401 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2402 | if (wa->flags & wb->flags & WPA_SCAN_LEVEL_DBM) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2403 | /* |
| 2404 | * The scan result estimates SNR over 20 MHz, while Data frames |
| 2405 | * usually use wider channel width. The TX power and noise power |
| 2406 | * are both affected by the channel width. |
| 2407 | */ |
| 2408 | ies_len = wa->ie_len ? wa->ie_len : wa->beacon_ie_len; |
| 2409 | snr_a_full = wpas_adjust_snr_by_chanwidth((const u8 *) (wa + 1), |
| 2410 | ies_len, wa->max_cw, |
| 2411 | wa->snr); |
| 2412 | snr_a = MIN(snr_a_full, GREAT_SNR); |
| 2413 | ies_len = wb->ie_len ? wb->ie_len : wb->beacon_ie_len; |
| 2414 | snr_b_full = wpas_adjust_snr_by_chanwidth((const u8 *) (wb + 1), |
| 2415 | ies_len, wb->max_cw, |
| 2416 | wb->snr); |
| 2417 | snr_b = MIN(snr_b_full, GREAT_SNR); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2418 | } else { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2419 | /* Level is not in dBm, so we can't calculate |
| 2420 | * SNR. Just use raw level (units unknown). */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2421 | snr_a = snr_a_full = wa->level; |
| 2422 | snr_b = snr_b_full = wb->level; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2423 | } |
| 2424 | |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2425 | #ifndef CONFIG_NO_WPA |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2426 | /* If SNR of a SAE BSS is good or at least as high as the PSK BSS, |
| 2427 | * prefer SAE over PSK for mixed WPA3-Personal transition mode and |
| 2428 | * WPA2-Personal deployments */ |
| 2429 | rsne_a = wpa_scan_get_ie(wa, WLAN_EID_RSN); |
| 2430 | rsne_b = wpa_scan_get_ie(wb, WLAN_EID_RSN); |
| 2431 | if (rsne_a && rsne_b) { |
| 2432 | struct wpa_ie_data data; |
| 2433 | bool psk_a = false, psk_b = false, sae_a = false, sae_b = false; |
| 2434 | |
| 2435 | if (wpa_parse_wpa_ie_rsn(rsne_a, 2 + rsne_a[1], &data) == 0) { |
| 2436 | psk_a = wpa_key_mgmt_wpa_psk_no_sae(data.key_mgmt); |
| 2437 | sae_a = wpa_key_mgmt_sae(data.key_mgmt); |
| 2438 | } |
| 2439 | if (wpa_parse_wpa_ie_rsn(rsne_b, 2 + rsne_b[1], &data) == 0) { |
| 2440 | psk_b = wpa_key_mgmt_wpa_psk_no_sae(data.key_mgmt); |
| 2441 | sae_b = wpa_key_mgmt_sae(data.key_mgmt); |
| 2442 | } |
| 2443 | |
| 2444 | if (sae_a && !sae_b && psk_b && |
| 2445 | (snr_a >= GREAT_SNR || snr_a >= snr_b)) |
| 2446 | return -1; |
| 2447 | if (sae_b && !sae_a && psk_a && |
| 2448 | (snr_b >= GREAT_SNR || snr_b >= snr_a)) |
| 2449 | return 1; |
| 2450 | } |
Sunil Ravi | 79e6c4f | 2025-01-04 00:47:06 +0000 | [diff] [blame] | 2451 | #endif /* CONFIG_NO_WPA */ |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2452 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2453 | /* If SNR is close, decide by max rate or frequency band. For cases |
| 2454 | * involving the 6 GHz band, use the throughput estimate irrespective |
| 2455 | * of the SNR difference since the LPI/VLP rules may result in |
| 2456 | * significant differences in SNR for cases where the estimated |
| 2457 | * throughput can be considerably higher with the lower SNR. */ |
| 2458 | if (snr_a && snr_b && (abs(snr_b - snr_a) < 7 || |
| 2459 | is_6ghz_freq(wa->freq) || |
| 2460 | is_6ghz_freq(wb->freq))) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2461 | if (wa->est_throughput != wb->est_throughput) |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 2462 | return (int) wb->est_throughput - |
| 2463 | (int) wa->est_throughput; |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 2464 | } |
| 2465 | if ((snr_a && snr_b && abs(snr_b - snr_a) < 5) || |
| 2466 | (wa->qual && wb->qual && abs(wb->qual - wa->qual) < 10)) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2467 | if (is_6ghz_freq(wa->freq) ^ is_6ghz_freq(wb->freq)) |
| 2468 | return is_6ghz_freq(wa->freq) ? -1 : 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2469 | if (IS_5GHZ(wa->freq) ^ IS_5GHZ(wb->freq)) |
| 2470 | return IS_5GHZ(wa->freq) ? -1 : 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2473 | /* all things being equal, use SNR; if SNRs are |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2474 | * identical, use quality values since some drivers may only report |
| 2475 | * that value and leave the signal level zero */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2476 | if (snr_b_full == snr_a_full) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2477 | return wb->qual - wa->qual; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2478 | return snr_b_full - snr_a_full; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | #ifdef CONFIG_WPS |
| 2483 | /* Compare function for sorting scan results when searching a WPS AP for |
| 2484 | * provisioning. Return >0 if @b is considered better. */ |
| 2485 | static int wpa_scan_result_wps_compar(const void *a, const void *b) |
| 2486 | { |
| 2487 | struct wpa_scan_res **_wa = (void *) a; |
| 2488 | struct wpa_scan_res **_wb = (void *) b; |
| 2489 | struct wpa_scan_res *wa = *_wa; |
| 2490 | struct wpa_scan_res *wb = *_wb; |
| 2491 | int uses_wps_a, uses_wps_b; |
| 2492 | struct wpabuf *wps_a, *wps_b; |
| 2493 | int res; |
| 2494 | |
| 2495 | /* Optimization - check WPS IE existence before allocated memory and |
| 2496 | * doing full reassembly. */ |
| 2497 | uses_wps_a = wpa_scan_get_vendor_ie(wa, WPS_IE_VENDOR_TYPE) != NULL; |
| 2498 | uses_wps_b = wpa_scan_get_vendor_ie(wb, WPS_IE_VENDOR_TYPE) != NULL; |
| 2499 | if (uses_wps_a && !uses_wps_b) |
| 2500 | return -1; |
| 2501 | if (!uses_wps_a && uses_wps_b) |
| 2502 | return 1; |
| 2503 | |
| 2504 | if (uses_wps_a && uses_wps_b) { |
| 2505 | wps_a = wpa_scan_get_vendor_ie_multi(wa, WPS_IE_VENDOR_TYPE); |
| 2506 | wps_b = wpa_scan_get_vendor_ie_multi(wb, WPS_IE_VENDOR_TYPE); |
| 2507 | res = wps_ap_priority_compar(wps_a, wps_b); |
| 2508 | wpabuf_free(wps_a); |
| 2509 | wpabuf_free(wps_b); |
| 2510 | if (res) |
| 2511 | return res; |
| 2512 | } |
| 2513 | |
| 2514 | /* |
| 2515 | * Do not use current AP security policy as a sorting criteria during |
| 2516 | * WPS provisioning step since the AP may get reconfigured at the |
| 2517 | * completion of provisioning. |
| 2518 | */ |
| 2519 | |
| 2520 | /* all things being equal, use signal level; if signal levels are |
| 2521 | * identical, use quality values since some drivers may only report |
| 2522 | * that value and leave the signal level zero */ |
| 2523 | if (wb->level == wa->level) |
| 2524 | return wb->qual - wa->qual; |
| 2525 | return wb->level - wa->level; |
| 2526 | } |
| 2527 | #endif /* CONFIG_WPS */ |
| 2528 | |
| 2529 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2530 | static void dump_scan_res(struct wpa_scan_results *scan_res) |
| 2531 | { |
| 2532 | #ifndef CONFIG_NO_STDOUT_DEBUG |
| 2533 | size_t i; |
| 2534 | |
| 2535 | if (scan_res->res == NULL || scan_res->num == 0) |
| 2536 | return; |
| 2537 | |
| 2538 | wpa_printf(MSG_EXCESSIVE, "Sorted scan results"); |
| 2539 | |
| 2540 | for (i = 0; i < scan_res->num; i++) { |
| 2541 | struct wpa_scan_res *r = scan_res->res[i]; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2542 | u8 *pos; |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2543 | const u8 *ssid_ie, *ssid = NULL; |
| 2544 | size_t ssid_len = 0; |
| 2545 | |
| 2546 | ssid_ie = wpa_scan_get_ie(r, WLAN_EID_SSID); |
| 2547 | if (ssid_ie) { |
| 2548 | ssid = ssid_ie + 2; |
| 2549 | ssid_len = ssid_ie[1]; |
| 2550 | } |
| 2551 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2552 | if (r->flags & WPA_SCAN_LEVEL_DBM) { |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2553 | int noise_valid = !(r->flags & WPA_SCAN_NOISE_INVALID); |
| 2554 | |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2555 | wpa_printf(MSG_EXCESSIVE, MACSTR |
| 2556 | " ssid=%s freq=%d qual=%d noise=%d%s level=%d snr=%d%s flags=0x%x age=%u est=%u", |
| 2557 | MAC2STR(r->bssid), |
| 2558 | wpa_ssid_txt(ssid, ssid_len), |
| 2559 | r->freq, r->qual, |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 2560 | r->noise, noise_valid ? "" : "~", r->level, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2561 | r->snr, r->snr >= GREAT_SNR ? "*" : "", |
| 2562 | r->flags, |
| 2563 | r->age, r->est_throughput); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2564 | } else { |
Sunil Ravi | a04bd25 | 2022-05-02 22:54:18 -0700 | [diff] [blame] | 2565 | wpa_printf(MSG_EXCESSIVE, MACSTR |
| 2566 | " ssid=%s freq=%d qual=%d noise=%d level=%d flags=0x%x age=%u est=%u", |
| 2567 | MAC2STR(r->bssid), |
| 2568 | wpa_ssid_txt(ssid, ssid_len), |
| 2569 | r->freq, r->qual, |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2570 | r->noise, r->level, r->flags, r->age, |
| 2571 | r->est_throughput); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2572 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2573 | pos = (u8 *) (r + 1); |
| 2574 | if (r->ie_len) |
| 2575 | wpa_hexdump(MSG_EXCESSIVE, "IEs", pos, r->ie_len); |
| 2576 | pos += r->ie_len; |
| 2577 | if (r->beacon_ie_len) |
| 2578 | wpa_hexdump(MSG_EXCESSIVE, "Beacon IEs", |
| 2579 | pos, r->beacon_ie_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2580 | } |
| 2581 | #endif /* CONFIG_NO_STDOUT_DEBUG */ |
| 2582 | } |
| 2583 | |
| 2584 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2585 | /** |
| 2586 | * wpa_supplicant_filter_bssid_match - Is the specified BSSID allowed |
| 2587 | * @wpa_s: Pointer to wpa_supplicant data |
| 2588 | * @bssid: BSSID to check |
| 2589 | * Returns: 0 if the BSSID is filtered or 1 if not |
| 2590 | * |
| 2591 | * This function is used to filter out specific BSSIDs from scan reslts mainly |
| 2592 | * for testing purposes (SET bssid_filter ctrl_iface command). |
| 2593 | */ |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2594 | int wpa_supplicant_filter_bssid_match(struct wpa_supplicant *wpa_s, |
| 2595 | const u8 *bssid) |
| 2596 | { |
| 2597 | size_t i; |
| 2598 | |
| 2599 | if (wpa_s->bssid_filter == NULL) |
| 2600 | return 1; |
| 2601 | |
| 2602 | for (i = 0; i < wpa_s->bssid_filter_count; i++) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2603 | if (ether_addr_equal(wpa_s->bssid_filter + i * ETH_ALEN, bssid)) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2604 | return 1; |
| 2605 | } |
| 2606 | |
| 2607 | return 0; |
| 2608 | } |
| 2609 | |
| 2610 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2611 | static void filter_scan_res(struct wpa_supplicant *wpa_s, |
| 2612 | struct wpa_scan_results *res) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2613 | { |
| 2614 | size_t i, j; |
| 2615 | |
| 2616 | if (wpa_s->bssid_filter == NULL) |
| 2617 | return; |
| 2618 | |
| 2619 | for (i = 0, j = 0; i < res->num; i++) { |
| 2620 | if (wpa_supplicant_filter_bssid_match(wpa_s, |
| 2621 | res->res[i]->bssid)) { |
| 2622 | res->res[j++] = res->res[i]; |
| 2623 | } else { |
| 2624 | os_free(res->res[i]); |
| 2625 | res->res[i] = NULL; |
| 2626 | } |
| 2627 | } |
| 2628 | |
| 2629 | if (res->num != j) { |
| 2630 | wpa_printf(MSG_DEBUG, "Filtered out %d scan results", |
| 2631 | (int) (res->num - j)); |
| 2632 | res->num = j; |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2637 | void scan_snr(struct wpa_scan_res *res) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2638 | { |
| 2639 | if (res->flags & WPA_SCAN_NOISE_INVALID) { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2640 | res->noise = is_6ghz_freq(res->freq) ? |
| 2641 | DEFAULT_NOISE_FLOOR_6GHZ : |
| 2642 | (IS_5GHZ(res->freq) ? |
| 2643 | DEFAULT_NOISE_FLOOR_5GHZ : DEFAULT_NOISE_FLOOR_2GHZ); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | if (res->flags & WPA_SCAN_LEVEL_DBM) { |
| 2647 | res->snr = res->level - res->noise; |
| 2648 | } else { |
| 2649 | /* Level is not in dBm, so we can't calculate |
| 2650 | * SNR. Just use raw level (units unknown). */ |
| 2651 | res->snr = res->level; |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2656 | /* Minimum SNR required to achieve a certain bitrate. */ |
| 2657 | struct minsnr_bitrate_entry { |
| 2658 | int minsnr; |
| 2659 | unsigned int bitrate; /* in Mbps */ |
| 2660 | }; |
| 2661 | |
| 2662 | /* VHT needs to be enabled in order to achieve MCS8 and MCS9 rates. */ |
| 2663 | static const int vht_mcs = 8; |
| 2664 | |
| 2665 | static const struct minsnr_bitrate_entry vht20_table[] = { |
| 2666 | { 0, 0 }, |
| 2667 | { 2, 6500 }, /* HT20 MCS0 */ |
| 2668 | { 5, 13000 }, /* HT20 MCS1 */ |
| 2669 | { 9, 19500 }, /* HT20 MCS2 */ |
| 2670 | { 11, 26000 }, /* HT20 MCS3 */ |
| 2671 | { 15, 39000 }, /* HT20 MCS4 */ |
| 2672 | { 18, 52000 }, /* HT20 MCS5 */ |
| 2673 | { 20, 58500 }, /* HT20 MCS6 */ |
| 2674 | { 25, 65000 }, /* HT20 MCS7 */ |
| 2675 | { 29, 78000 }, /* VHT20 MCS8 */ |
| 2676 | { -1, 78000 } /* SNR > 29 */ |
| 2677 | }; |
| 2678 | |
| 2679 | static const struct minsnr_bitrate_entry vht40_table[] = { |
| 2680 | { 0, 0 }, |
| 2681 | { 5, 13500 }, /* HT40 MCS0 */ |
| 2682 | { 8, 27000 }, /* HT40 MCS1 */ |
| 2683 | { 12, 40500 }, /* HT40 MCS2 */ |
| 2684 | { 14, 54000 }, /* HT40 MCS3 */ |
| 2685 | { 18, 81000 }, /* HT40 MCS4 */ |
| 2686 | { 21, 108000 }, /* HT40 MCS5 */ |
| 2687 | { 23, 121500 }, /* HT40 MCS6 */ |
| 2688 | { 28, 135000 }, /* HT40 MCS7 */ |
| 2689 | { 32, 162000 }, /* VHT40 MCS8 */ |
| 2690 | { 34, 180000 }, /* VHT40 MCS9 */ |
| 2691 | { -1, 180000 } /* SNR > 34 */ |
| 2692 | }; |
| 2693 | |
| 2694 | static const struct minsnr_bitrate_entry vht80_table[] = { |
| 2695 | { 0, 0 }, |
| 2696 | { 8, 29300 }, /* VHT80 MCS0 */ |
| 2697 | { 11, 58500 }, /* VHT80 MCS1 */ |
| 2698 | { 15, 87800 }, /* VHT80 MCS2 */ |
| 2699 | { 17, 117000 }, /* VHT80 MCS3 */ |
| 2700 | { 21, 175500 }, /* VHT80 MCS4 */ |
| 2701 | { 24, 234000 }, /* VHT80 MCS5 */ |
| 2702 | { 26, 263300 }, /* VHT80 MCS6 */ |
| 2703 | { 31, 292500 }, /* VHT80 MCS7 */ |
| 2704 | { 35, 351000 }, /* VHT80 MCS8 */ |
| 2705 | { 37, 390000 }, /* VHT80 MCS9 */ |
| 2706 | { -1, 390000 } /* SNR > 37 */ |
| 2707 | }; |
| 2708 | |
| 2709 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2710 | static const struct minsnr_bitrate_entry vht160_table[] = { |
| 2711 | { 0, 0 }, |
| 2712 | { 11, 58500 }, /* VHT160 MCS0 */ |
| 2713 | { 14, 117000 }, /* VHT160 MCS1 */ |
| 2714 | { 18, 175500 }, /* VHT160 MCS2 */ |
| 2715 | { 20, 234000 }, /* VHT160 MCS3 */ |
| 2716 | { 24, 351000 }, /* VHT160 MCS4 */ |
| 2717 | { 27, 468000 }, /* VHT160 MCS5 */ |
| 2718 | { 29, 526500 }, /* VHT160 MCS6 */ |
| 2719 | { 34, 585000 }, /* VHT160 MCS7 */ |
| 2720 | { 38, 702000 }, /* VHT160 MCS8 */ |
| 2721 | { 40, 780000 }, /* VHT160 MCS9 */ |
| 2722 | { -1, 780000 } /* SNR > 37 */ |
| 2723 | }; |
| 2724 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2725 | /* EHT needs to be enabled in order to achieve MCS12 and MCS13 rates. */ |
| 2726 | #define EHT_MCS 12 |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2727 | |
| 2728 | static const struct minsnr_bitrate_entry he20_table[] = { |
| 2729 | { 0, 0 }, |
| 2730 | { 2, 8600 }, /* HE20 MCS0 */ |
| 2731 | { 5, 17200 }, /* HE20 MCS1 */ |
| 2732 | { 9, 25800 }, /* HE20 MCS2 */ |
| 2733 | { 11, 34400 }, /* HE20 MCS3 */ |
| 2734 | { 15, 51600 }, /* HE20 MCS4 */ |
| 2735 | { 18, 68800 }, /* HE20 MCS5 */ |
| 2736 | { 20, 77400 }, /* HE20 MCS6 */ |
| 2737 | { 25, 86000 }, /* HE20 MCS7 */ |
| 2738 | { 29, 103200 }, /* HE20 MCS8 */ |
| 2739 | { 31, 114700 }, /* HE20 MCS9 */ |
| 2740 | { 34, 129000 }, /* HE20 MCS10 */ |
| 2741 | { 36, 143400 }, /* HE20 MCS11 */ |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2742 | { 39, 154900 }, /* EHT20 MCS12 */ |
| 2743 | { 42, 172100 }, /* EHT20 MCS13 */ |
| 2744 | { -1, 172100 } /* SNR > 42 */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2745 | }; |
| 2746 | |
| 2747 | static const struct minsnr_bitrate_entry he40_table[] = { |
| 2748 | { 0, 0 }, |
| 2749 | { 5, 17200 }, /* HE40 MCS0 */ |
| 2750 | { 8, 34400 }, /* HE40 MCS1 */ |
| 2751 | { 12, 51600 }, /* HE40 MCS2 */ |
| 2752 | { 14, 68800 }, /* HE40 MCS3 */ |
| 2753 | { 18, 103200 }, /* HE40 MCS4 */ |
| 2754 | { 21, 137600 }, /* HE40 MCS5 */ |
| 2755 | { 23, 154900 }, /* HE40 MCS6 */ |
| 2756 | { 28, 172100 }, /* HE40 MCS7 */ |
| 2757 | { 32, 206500 }, /* HE40 MCS8 */ |
| 2758 | { 34, 229400 }, /* HE40 MCS9 */ |
| 2759 | { 37, 258100 }, /* HE40 MCS10 */ |
| 2760 | { 39, 286800 }, /* HE40 MCS11 */ |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2761 | { 42, 309500 }, /* EHT40 MCS12 */ |
| 2762 | { 45, 344100 }, /* EHT40 MCS13 */ |
| 2763 | { -1, 344100 } /* SNR > 45 */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2764 | }; |
| 2765 | |
| 2766 | static const struct minsnr_bitrate_entry he80_table[] = { |
| 2767 | { 0, 0 }, |
| 2768 | { 8, 36000 }, /* HE80 MCS0 */ |
| 2769 | { 11, 72100 }, /* HE80 MCS1 */ |
| 2770 | { 15, 108100 }, /* HE80 MCS2 */ |
| 2771 | { 17, 144100 }, /* HE80 MCS3 */ |
| 2772 | { 21, 216200 }, /* HE80 MCS4 */ |
| 2773 | { 24, 288200 }, /* HE80 MCS5 */ |
| 2774 | { 26, 324300 }, /* HE80 MCS6 */ |
| 2775 | { 31, 360300 }, /* HE80 MCS7 */ |
| 2776 | { 35, 432400 }, /* HE80 MCS8 */ |
| 2777 | { 37, 480400 }, /* HE80 MCS9 */ |
| 2778 | { 40, 540400 }, /* HE80 MCS10 */ |
| 2779 | { 42, 600500 }, /* HE80 MCS11 */ |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2780 | { 45, 648500 }, /* EHT80 MCS12 */ |
| 2781 | { 48, 720600 }, /* EHT80 MCS13 */ |
| 2782 | { -1, 720600 } /* SNR > 48 */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2783 | }; |
| 2784 | |
| 2785 | |
| 2786 | static const struct minsnr_bitrate_entry he160_table[] = { |
| 2787 | { 0, 0 }, |
| 2788 | { 11, 72100 }, /* HE160 MCS0 */ |
| 2789 | { 14, 144100 }, /* HE160 MCS1 */ |
| 2790 | { 18, 216200 }, /* HE160 MCS2 */ |
| 2791 | { 20, 288200 }, /* HE160 MCS3 */ |
| 2792 | { 24, 432400 }, /* HE160 MCS4 */ |
| 2793 | { 27, 576500 }, /* HE160 MCS5 */ |
| 2794 | { 29, 648500 }, /* HE160 MCS6 */ |
| 2795 | { 34, 720600 }, /* HE160 MCS7 */ |
| 2796 | { 38, 864700 }, /* HE160 MCS8 */ |
| 2797 | { 40, 960800 }, /* HE160 MCS9 */ |
| 2798 | { 43, 1080900 }, /* HE160 MCS10 */ |
| 2799 | { 45, 1201000 }, /* HE160 MCS11 */ |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2800 | { 48, 1297100 }, /* EHT160 MCS12 */ |
| 2801 | { 51, 1441200 }, /* EHT160 MCS13 */ |
| 2802 | { -1, 1441200 } /* SNR > 51 */ |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2803 | }; |
| 2804 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2805 | /* See IEEE P802.11be/D2.0, Table 36-86: EHT-MCSs for 4x996-tone RU, NSS,u = 1 |
| 2806 | */ |
| 2807 | static const struct minsnr_bitrate_entry eht320_table[] = { |
| 2808 | { 0, 0 }, |
| 2809 | { 14, 144100 }, /* EHT320 MCS0 */ |
| 2810 | { 17, 288200 }, /* EHT320 MCS1 */ |
| 2811 | { 21, 432400 }, /* EHT320 MCS2 */ |
| 2812 | { 23, 576500 }, /* EHT320 MCS3 */ |
| 2813 | { 27, 864700 }, /* EHT320 MCS4 */ |
| 2814 | { 30, 1152900 }, /* EHT320 MCS5 */ |
| 2815 | { 32, 1297100 }, /* EHT320 MCS6 */ |
| 2816 | { 37, 1441200 }, /* EHT320 MCS7 */ |
| 2817 | { 41, 1729400 }, /* EHT320 MCS8 */ |
| 2818 | { 43, 1921500 }, /* EHT320 MCS9 */ |
| 2819 | { 46, 2161800 }, /* EHT320 MCS10 */ |
| 2820 | { 48, 2401900 }, /* EHT320 MCS11 */ |
| 2821 | { 51, 2594100 }, /* EHT320 MCS12 */ |
| 2822 | { 54, 2882400 }, /* EHT320 MCS13 */ |
| 2823 | { -1, 2882400 } /* SNR > 54 */ |
| 2824 | }; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2825 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2826 | static unsigned int interpolate_rate(int snr, int snr0, int snr1, |
| 2827 | int rate0, int rate1) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2828 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2829 | return rate0 + (snr - snr0) * (rate1 - rate0) / (snr1 - snr0); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2833 | static unsigned int max_rate(const struct minsnr_bitrate_entry table[], |
| 2834 | int snr, bool vht) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2835 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2836 | const struct minsnr_bitrate_entry *prev, *entry = table; |
| 2837 | |
| 2838 | while ((entry->minsnr != -1) && |
| 2839 | (snr >= entry->minsnr) && |
| 2840 | (vht || entry - table <= vht_mcs)) |
| 2841 | entry++; |
| 2842 | if (entry == table) |
| 2843 | return entry->bitrate; |
| 2844 | prev = entry - 1; |
| 2845 | if (entry->minsnr == -1 || (!vht && entry - table > vht_mcs)) |
| 2846 | return prev->bitrate; |
| 2847 | return interpolate_rate(snr, prev->minsnr, entry->minsnr, prev->bitrate, |
| 2848 | entry->bitrate); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2852 | static unsigned int max_ht20_rate(int snr, bool vht) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2853 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2854 | return max_rate(vht20_table, snr, vht); |
| 2855 | } |
| 2856 | |
| 2857 | |
| 2858 | static unsigned int max_ht40_rate(int snr, bool vht) |
| 2859 | { |
| 2860 | return max_rate(vht40_table, snr, vht); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | |
| 2864 | static unsigned int max_vht80_rate(int snr) |
| 2865 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2866 | return max_rate(vht80_table, snr, 1); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2867 | } |
| 2868 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2869 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2870 | static unsigned int max_vht160_rate(int snr) |
| 2871 | { |
| 2872 | return max_rate(vht160_table, snr, 1); |
| 2873 | } |
| 2874 | |
| 2875 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2876 | static unsigned int max_he_eht_rate(const struct minsnr_bitrate_entry table[], |
| 2877 | int snr, bool eht) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2878 | { |
| 2879 | const struct minsnr_bitrate_entry *prev, *entry = table; |
| 2880 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2881 | while (entry->minsnr != -1 && snr >= entry->minsnr && |
| 2882 | (eht || entry - table <= EHT_MCS)) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2883 | entry++; |
| 2884 | if (entry == table) |
| 2885 | return 0; |
| 2886 | prev = entry - 1; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 2887 | if (entry->minsnr == -1 || (!eht && entry - table > EHT_MCS)) |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2888 | return prev->bitrate; |
| 2889 | return interpolate_rate(snr, prev->minsnr, entry->minsnr, |
| 2890 | prev->bitrate, entry->bitrate); |
| 2891 | } |
| 2892 | |
| 2893 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2894 | unsigned int wpas_get_est_tpt(const struct wpa_supplicant *wpa_s, |
| 2895 | const u8 *ies, size_t ies_len, int rate, |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2896 | int snr, int freq, enum chan_width *max_cw) |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2897 | { |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2898 | struct hostapd_hw_modes *hw_mode; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2899 | unsigned int est, tmp; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2900 | const u8 *ie; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2901 | /* |
| 2902 | * No need to apply a bump to the noise here because the |
| 2903 | * minsnr_bitrate_entry tables are based on MCS tables where this has |
| 2904 | * been taken into account. |
| 2905 | */ |
| 2906 | int adjusted_snr; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2907 | bool ht40 = false, vht80 = false, vht160 = false; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2908 | |
| 2909 | /* Limit based on estimated SNR */ |
| 2910 | if (rate > 1 * 2 && snr < 1) |
| 2911 | rate = 1 * 2; |
| 2912 | else if (rate > 2 * 2 && snr < 4) |
| 2913 | rate = 2 * 2; |
| 2914 | else if (rate > 6 * 2 && snr < 5) |
| 2915 | rate = 6 * 2; |
| 2916 | else if (rate > 9 * 2 && snr < 6) |
| 2917 | rate = 9 * 2; |
| 2918 | else if (rate > 12 * 2 && snr < 7) |
| 2919 | rate = 12 * 2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2920 | else if (rate > 12 * 2 && snr < 8) |
| 2921 | rate = 14 * 2; |
| 2922 | else if (rate > 12 * 2 && snr < 9) |
| 2923 | rate = 16 * 2; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2924 | else if (rate > 18 * 2 && snr < 10) |
| 2925 | rate = 18 * 2; |
| 2926 | else if (rate > 24 * 2 && snr < 11) |
| 2927 | rate = 24 * 2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2928 | else if (rate > 24 * 2 && snr < 12) |
| 2929 | rate = 27 * 2; |
| 2930 | else if (rate > 24 * 2 && snr < 13) |
| 2931 | rate = 30 * 2; |
| 2932 | else if (rate > 24 * 2 && snr < 14) |
| 2933 | rate = 33 * 2; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2934 | else if (rate > 36 * 2 && snr < 15) |
| 2935 | rate = 36 * 2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2936 | else if (rate > 36 * 2 && snr < 16) |
| 2937 | rate = 39 * 2; |
| 2938 | else if (rate > 36 * 2 && snr < 17) |
| 2939 | rate = 42 * 2; |
| 2940 | else if (rate > 36 * 2 && snr < 18) |
| 2941 | rate = 45 * 2; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2942 | else if (rate > 48 * 2 && snr < 19) |
| 2943 | rate = 48 * 2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2944 | else if (rate > 48 * 2 && snr < 20) |
| 2945 | rate = 51 * 2; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2946 | else if (rate > 54 * 2 && snr < 21) |
| 2947 | rate = 54 * 2; |
| 2948 | est = rate * 500; |
| 2949 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2950 | hw_mode = get_mode_with_freq(wpa_s->hw.modes, wpa_s->hw.num_modes, |
| 2951 | freq); |
| 2952 | |
| 2953 | if (hw_mode && hw_mode->ht_capab) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2954 | ie = get_ie(ies, ies_len, WLAN_EID_HT_CAP); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2955 | if (ie) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2956 | *max_cw = CHAN_WIDTH_20; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2957 | tmp = max_ht20_rate(snr, false); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2958 | if (tmp > est) |
| 2959 | est = tmp; |
| 2960 | } |
| 2961 | } |
| 2962 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2963 | ie = get_ie(ies, ies_len, WLAN_EID_HT_OPERATION); |
| 2964 | if (ie && ie[1] >= 2 && |
| 2965 | (ie[3] & HT_INFO_HT_PARAM_SECONDARY_CHNL_OFF_MASK)) |
| 2966 | ht40 = true; |
| 2967 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2968 | if (hw_mode && |
| 2969 | (hw_mode->ht_capab & HT_CAP_INFO_SUPP_CHANNEL_WIDTH_SET)) { |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2970 | if (ht40) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 2971 | *max_cw = CHAN_WIDTH_40; |
| 2972 | adjusted_snr = snr + |
| 2973 | wpas_channel_width_rssi_bump(ies, ies_len, |
| 2974 | CHAN_WIDTH_40); |
| 2975 | tmp = max_ht40_rate(adjusted_snr, false); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2976 | if (tmp > est) |
| 2977 | est = tmp; |
| 2978 | } |
| 2979 | } |
| 2980 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 2981 | /* Determine VHT BSS bandwidth based on IEEE Std 802.11-2020, |
| 2982 | * Table 11-23 (VHT BSS bandwidth) */ |
| 2983 | ie = get_ie(ies, ies_len, WLAN_EID_VHT_OPERATION); |
| 2984 | if (ie && ie[1] >= 3) { |
| 2985 | u8 cw = ie[2] & VHT_OPMODE_CHANNEL_WIDTH_MASK; |
| 2986 | u8 seg0 = ie[3]; |
| 2987 | u8 seg1 = ie[4]; |
| 2988 | |
| 2989 | if (cw) |
| 2990 | vht80 = true; |
| 2991 | if (cw == 2 || |
| 2992 | (cw == 3 && (seg1 > 0 && abs(seg1 - seg0) == 16))) |
| 2993 | vht160 = true; |
| 2994 | if (cw == 1 && |
| 2995 | ((seg1 > 0 && abs(seg1 - seg0) == 8) || |
| 2996 | (seg1 > 0 && abs(seg1 - seg0) == 16))) |
| 2997 | vht160 = true; |
| 2998 | } |
| 2999 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3000 | if (hw_mode && hw_mode->vht_capab) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3001 | /* Use +1 to assume VHT is always faster than HT */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3002 | ie = get_ie(ies, ies_len, WLAN_EID_VHT_CAP); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3003 | if (ie) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3004 | if (*max_cw == CHAN_WIDTH_UNKNOWN) |
| 3005 | *max_cw = CHAN_WIDTH_20; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3006 | tmp = max_ht20_rate(snr, true) + 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3007 | if (tmp > est) |
| 3008 | est = tmp; |
| 3009 | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3010 | if (ht40) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3011 | *max_cw = CHAN_WIDTH_40; |
| 3012 | adjusted_snr = snr + |
| 3013 | wpas_channel_width_rssi_bump( |
| 3014 | ies, ies_len, CHAN_WIDTH_40); |
| 3015 | tmp = max_ht40_rate(adjusted_snr, true) + 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3016 | if (tmp > est) |
| 3017 | est = tmp; |
| 3018 | } |
| 3019 | |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3020 | if (vht80) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3021 | *max_cw = CHAN_WIDTH_80; |
| 3022 | adjusted_snr = snr + |
| 3023 | wpas_channel_width_rssi_bump( |
| 3024 | ies, ies_len, CHAN_WIDTH_80); |
| 3025 | tmp = max_vht80_rate(adjusted_snr) + 1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3026 | if (tmp > est) |
| 3027 | est = tmp; |
| 3028 | } |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3029 | |
| 3030 | if (vht160 && |
| 3031 | (hw_mode->vht_capab & |
| 3032 | (VHT_CAP_SUPP_CHAN_WIDTH_160MHZ | |
| 3033 | VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3034 | *max_cw = CHAN_WIDTH_160; |
| 3035 | adjusted_snr = snr + |
| 3036 | wpas_channel_width_rssi_bump( |
| 3037 | ies, ies_len, CHAN_WIDTH_160); |
| 3038 | tmp = max_vht160_rate(adjusted_snr) + 1; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3039 | if (tmp > est) |
| 3040 | est = tmp; |
| 3041 | } |
| 3042 | } |
| 3043 | } |
| 3044 | |
| 3045 | if (hw_mode && hw_mode->he_capab[IEEE80211_MODE_INFRA].he_supported) { |
| 3046 | /* Use +2 to assume HE is always faster than HT/VHT */ |
| 3047 | struct ieee80211_he_capabilities *he; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3048 | struct ieee80211_eht_capabilities *eht; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3049 | struct he_capabilities *own_he; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3050 | u8 cw, boost = 2; |
| 3051 | const u8 *eht_ie; |
| 3052 | bool is_eht = false; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3053 | |
| 3054 | ie = get_ie_ext(ies, ies_len, WLAN_EID_EXT_HE_CAPABILITIES); |
| 3055 | if (!ie || (ie[1] < 1 + IEEE80211_HE_CAPAB_MIN_LEN)) |
| 3056 | return est; |
| 3057 | he = (struct ieee80211_he_capabilities *) &ie[3]; |
| 3058 | own_he = &hw_mode->he_capab[IEEE80211_MODE_INFRA]; |
| 3059 | |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3060 | /* Use +3 to assume EHT is always faster than HE */ |
| 3061 | if (hw_mode->eht_capab[IEEE80211_MODE_INFRA].eht_supported) { |
| 3062 | eht_ie = get_ie_ext(ies, ies_len, |
| 3063 | WLAN_EID_EXT_EHT_CAPABILITIES); |
| 3064 | if (eht_ie && |
| 3065 | (eht_ie[1] >= 1 + IEEE80211_EHT_CAPAB_MIN_LEN)) { |
| 3066 | is_eht = true; |
| 3067 | boost = 3; |
| 3068 | } |
| 3069 | } |
| 3070 | |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3071 | if (*max_cw == CHAN_WIDTH_UNKNOWN) |
| 3072 | *max_cw = CHAN_WIDTH_20; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3073 | tmp = max_he_eht_rate(he20_table, snr, is_eht) + boost; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3074 | if (tmp > est) |
| 3075 | est = tmp; |
| 3076 | |
| 3077 | cw = he->he_phy_capab_info[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX] & |
| 3078 | own_he->phy_cap[HE_PHYCAP_CHANNEL_WIDTH_SET_IDX]; |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3079 | if ((cw & |
| 3080 | (IS_2P4GHZ(freq) ? |
| 3081 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_IN_2G : |
| 3082 | HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) && ht40) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3083 | if (*max_cw == CHAN_WIDTH_UNKNOWN || |
| 3084 | *max_cw < CHAN_WIDTH_40) |
| 3085 | *max_cw = CHAN_WIDTH_40; |
| 3086 | adjusted_snr = snr + wpas_channel_width_rssi_bump( |
| 3087 | ies, ies_len, CHAN_WIDTH_40); |
| 3088 | tmp = max_he_eht_rate(he40_table, adjusted_snr, |
| 3089 | is_eht) + boost; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3090 | if (tmp > est) |
| 3091 | est = tmp; |
| 3092 | } |
| 3093 | |
| 3094 | if (!IS_2P4GHZ(freq) && |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3095 | (cw & HE_PHYCAP_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G) && |
| 3096 | (!IS_5GHZ(freq) || vht80)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3097 | if (*max_cw == CHAN_WIDTH_UNKNOWN || |
| 3098 | *max_cw < CHAN_WIDTH_80) |
| 3099 | *max_cw = CHAN_WIDTH_80; |
| 3100 | adjusted_snr = snr + wpas_channel_width_rssi_bump( |
| 3101 | ies, ies_len, CHAN_WIDTH_80); |
| 3102 | tmp = max_he_eht_rate(he80_table, adjusted_snr, |
| 3103 | is_eht) + boost; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3104 | if (tmp > est) |
| 3105 | est = tmp; |
| 3106 | } |
| 3107 | |
| 3108 | if (!IS_2P4GHZ(freq) && |
| 3109 | (cw & (HE_PHYCAP_CHANNEL_WIDTH_SET_160MHZ_IN_5G | |
Sunil Ravi | b0ac25f | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3110 | HE_PHYCAP_CHANNEL_WIDTH_SET_80PLUS80MHZ_IN_5G)) && |
| 3111 | (!IS_5GHZ(freq) || vht160)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3112 | if (*max_cw == CHAN_WIDTH_UNKNOWN || |
| 3113 | *max_cw < CHAN_WIDTH_160) |
| 3114 | *max_cw = CHAN_WIDTH_160; |
| 3115 | adjusted_snr = snr + wpas_channel_width_rssi_bump( |
| 3116 | ies, ies_len, CHAN_WIDTH_160); |
| 3117 | tmp = max_he_eht_rate(he160_table, adjusted_snr, |
| 3118 | is_eht) + boost; |
Sunil Ravi | 38ad1ed | 2023-01-17 23:58:31 +0000 | [diff] [blame] | 3119 | if (tmp > est) |
| 3120 | est = tmp; |
| 3121 | } |
| 3122 | |
| 3123 | if (!is_eht) |
| 3124 | return est; |
| 3125 | |
| 3126 | eht = (struct ieee80211_eht_capabilities *) &eht_ie[3]; |
| 3127 | |
| 3128 | if (is_6ghz_freq(freq) && |
| 3129 | (eht->phy_cap[EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_IDX] & |
| 3130 | EHT_PHYCAP_320MHZ_IN_6GHZ_SUPPORT_MASK)) { |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3131 | if (*max_cw == CHAN_WIDTH_UNKNOWN || |
| 3132 | *max_cw < CHAN_WIDTH_320) |
| 3133 | *max_cw = CHAN_WIDTH_320; |
| 3134 | adjusted_snr = snr + wpas_channel_width_rssi_bump( |
| 3135 | ies, ies_len, CHAN_WIDTH_320); |
| 3136 | tmp = max_he_eht_rate(eht320_table, adjusted_snr, true); |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3137 | if (tmp > est) |
| 3138 | est = tmp; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3139 | } |
| 3140 | } |
| 3141 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3142 | return est; |
| 3143 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3144 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3145 | |
| 3146 | void scan_est_throughput(struct wpa_supplicant *wpa_s, |
| 3147 | struct wpa_scan_res *res) |
| 3148 | { |
| 3149 | int rate; /* max legacy rate in 500 kb/s units */ |
| 3150 | int snr = res->snr; |
| 3151 | const u8 *ies = (const void *) (res + 1); |
| 3152 | size_t ie_len = res->ie_len; |
| 3153 | |
| 3154 | if (res->est_throughput) |
| 3155 | return; |
| 3156 | |
| 3157 | /* Get maximum legacy rate */ |
| 3158 | rate = wpa_scan_get_max_rate(res); |
| 3159 | |
| 3160 | if (!ie_len) |
| 3161 | ie_len = res->beacon_ie_len; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3162 | res->est_throughput = wpas_get_est_tpt(wpa_s, ies, ie_len, rate, snr, |
| 3163 | res->freq, &res->max_cw); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3164 | |
| 3165 | /* TODO: channel utilization and AP load (e.g., from AP Beacon) */ |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3169 | /** |
| 3170 | * wpa_supplicant_get_scan_results - Get scan results |
| 3171 | * @wpa_s: Pointer to wpa_supplicant data |
| 3172 | * @info: Information about what was scanned or %NULL if not available |
| 3173 | * @new_scan: Whether a new scan was performed |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3174 | * @bssid: Return BSS entries only for a single BSSID, %NULL for all |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3175 | * Returns: Scan results, %NULL on failure |
| 3176 | * |
| 3177 | * This function request the current scan results from the driver and updates |
| 3178 | * the local BSS list wpa_s->bss. The caller is responsible for freeing the |
| 3179 | * results with wpa_scan_results_free(). |
| 3180 | */ |
| 3181 | struct wpa_scan_results * |
| 3182 | wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s, |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3183 | struct scan_info *info, int new_scan, |
| 3184 | const u8 *bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3185 | { |
| 3186 | struct wpa_scan_results *scan_res; |
| 3187 | size_t i; |
| 3188 | int (*compar)(const void *, const void *) = wpa_scan_result_compar; |
| 3189 | |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3190 | scan_res = wpa_drv_get_scan_results(wpa_s, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3191 | if (scan_res == NULL) { |
| 3192 | wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results"); |
| 3193 | return NULL; |
| 3194 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3195 | if (scan_res->fetch_time.sec == 0) { |
| 3196 | /* |
| 3197 | * Make sure we have a valid timestamp if the driver wrapper |
| 3198 | * does not set this. |
| 3199 | */ |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3200 | os_get_reltime(&scan_res->fetch_time); |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3201 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3202 | filter_scan_res(wpa_s, scan_res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3203 | |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3204 | for (i = 0; i < scan_res->num; i++) { |
| 3205 | struct wpa_scan_res *scan_res_item = scan_res->res[i]; |
| 3206 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3207 | scan_snr(scan_res_item); |
| 3208 | scan_est_throughput(wpa_s, scan_res_item); |
Dmitry Shmidt | 216983b | 2015-02-06 10:50:36 -0800 | [diff] [blame] | 3209 | } |
| 3210 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3211 | #ifdef CONFIG_WPS |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3212 | if (wpas_wps_searching(wpa_s)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3213 | wpa_dbg(wpa_s, MSG_DEBUG, "WPS: Order scan results with WPS " |
| 3214 | "provisioning rules"); |
| 3215 | compar = wpa_scan_result_wps_compar; |
| 3216 | } |
| 3217 | #endif /* CONFIG_WPS */ |
| 3218 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3219 | if (scan_res->res) { |
| 3220 | qsort(scan_res->res, scan_res->num, |
| 3221 | sizeof(struct wpa_scan_res *), compar); |
| 3222 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3223 | dump_scan_res(scan_res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3224 | |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3225 | if (wpa_s->ignore_post_flush_scan_res) { |
| 3226 | /* FLUSH command aborted an ongoing scan and these are the |
| 3227 | * results from the aborted scan. Do not process the results to |
| 3228 | * maintain flushed state. */ |
| 3229 | wpa_dbg(wpa_s, MSG_DEBUG, |
| 3230 | "Do not update BSS table based on pending post-FLUSH scan results"); |
| 3231 | wpa_s->ignore_post_flush_scan_res = 0; |
| 3232 | return scan_res; |
| 3233 | } |
| 3234 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3235 | wpa_bss_update_start(wpa_s); |
| 3236 | for (i = 0; i < scan_res->num; i++) |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3237 | wpa_bss_update_scan_res(wpa_s, scan_res->res[i], |
| 3238 | &scan_res->fetch_time); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3239 | wpa_bss_update_end(wpa_s, info, new_scan); |
| 3240 | |
| 3241 | return scan_res; |
| 3242 | } |
| 3243 | |
| 3244 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3245 | /** |
| 3246 | * wpa_supplicant_update_scan_results - Update scan results from the driver |
| 3247 | * @wpa_s: Pointer to wpa_supplicant data |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3248 | * @bssid: Update BSS entries only for a single BSSID, %NULL for all |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3249 | * Returns: 0 on success, -1 on failure |
| 3250 | * |
| 3251 | * This function updates the BSS table within wpa_supplicant based on the |
| 3252 | * currently available scan results from the driver without requesting a new |
| 3253 | * scan. This is used in cases where the driver indicates an association |
| 3254 | * (including roaming within ESS) and wpa_supplicant does not yet have the |
| 3255 | * needed information to complete the connection (e.g., to perform validation |
| 3256 | * steps in 4-way handshake). |
| 3257 | */ |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3258 | int wpa_supplicant_update_scan_results(struct wpa_supplicant *wpa_s, |
| 3259 | const u8 *bssid) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3260 | { |
| 3261 | struct wpa_scan_results *scan_res; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3262 | scan_res = wpa_supplicant_get_scan_results(wpa_s, NULL, 0, bssid); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3263 | if (scan_res == NULL) |
| 3264 | return -1; |
| 3265 | wpa_scan_results_free(scan_res); |
| 3266 | |
| 3267 | return 0; |
| 3268 | } |
Dmitry Shmidt | 3a787e6 | 2013-01-17 10:32:35 -0800 | [diff] [blame] | 3269 | |
| 3270 | |
| 3271 | /** |
| 3272 | * scan_only_handler - Reports scan results |
| 3273 | */ |
| 3274 | void scan_only_handler(struct wpa_supplicant *wpa_s, |
| 3275 | struct wpa_scan_results *scan_res) |
| 3276 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3277 | wpa_dbg(wpa_s, MSG_DEBUG, "Scan-only results received"); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3278 | if (wpa_s->last_scan_req == MANUAL_SCAN_REQ && |
| 3279 | wpa_s->manual_scan_use_id && wpa_s->own_scan_running) { |
| 3280 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS "id=%u", |
| 3281 | wpa_s->manual_scan_id); |
| 3282 | wpa_s->manual_scan_use_id = 0; |
| 3283 | } else { |
| 3284 | wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_SCAN_RESULTS); |
| 3285 | } |
Dmitry Shmidt | 3a787e6 | 2013-01-17 10:32:35 -0800 | [diff] [blame] | 3286 | wpas_notify_scan_results(wpa_s); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3287 | wpas_notify_scan_done(wpa_s, 1); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3288 | if (wpa_s->scan_work) { |
| 3289 | struct wpa_radio_work *work = wpa_s->scan_work; |
| 3290 | wpa_s->scan_work = NULL; |
| 3291 | radio_work_done(work); |
| 3292 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3293 | |
| 3294 | if (wpa_s->wpa_state == WPA_SCANNING) |
| 3295 | wpa_supplicant_set_state(wpa_s, wpa_s->scan_prev_wpa_state); |
Dmitry Shmidt | 3a787e6 | 2013-01-17 10:32:35 -0800 | [diff] [blame] | 3296 | } |
Dmitry Shmidt | 37d4d6a | 2013-03-18 13:09:42 -0700 | [diff] [blame] | 3297 | |
| 3298 | |
| 3299 | int wpas_scan_scheduled(struct wpa_supplicant *wpa_s) |
| 3300 | { |
| 3301 | return eloop_is_timeout_registered(wpa_supplicant_scan, wpa_s, NULL); |
| 3302 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3303 | |
| 3304 | |
| 3305 | struct wpa_driver_scan_params * |
| 3306 | wpa_scan_clone_params(const struct wpa_driver_scan_params *src) |
| 3307 | { |
| 3308 | struct wpa_driver_scan_params *params; |
| 3309 | size_t i; |
| 3310 | u8 *n; |
| 3311 | |
| 3312 | params = os_zalloc(sizeof(*params)); |
| 3313 | if (params == NULL) |
| 3314 | return NULL; |
| 3315 | |
| 3316 | for (i = 0; i < src->num_ssids; i++) { |
| 3317 | if (src->ssids[i].ssid) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3318 | n = os_memdup(src->ssids[i].ssid, |
| 3319 | src->ssids[i].ssid_len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3320 | if (n == NULL) |
| 3321 | goto failed; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3322 | params->ssids[i].ssid = n; |
| 3323 | params->ssids[i].ssid_len = src->ssids[i].ssid_len; |
| 3324 | } |
| 3325 | } |
| 3326 | params->num_ssids = src->num_ssids; |
| 3327 | |
| 3328 | if (src->extra_ies) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3329 | n = os_memdup(src->extra_ies, src->extra_ies_len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3330 | if (n == NULL) |
| 3331 | goto failed; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3332 | params->extra_ies = n; |
| 3333 | params->extra_ies_len = src->extra_ies_len; |
| 3334 | } |
| 3335 | |
| 3336 | if (src->freqs) { |
| 3337 | int len = int_array_len(src->freqs); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3338 | params->freqs = os_memdup(src->freqs, (len + 1) * sizeof(int)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3339 | if (params->freqs == NULL) |
| 3340 | goto failed; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3341 | } |
| 3342 | |
| 3343 | if (src->filter_ssids) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3344 | params->filter_ssids = os_memdup(src->filter_ssids, |
| 3345 | sizeof(*params->filter_ssids) * |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3346 | src->num_filter_ssids); |
| 3347 | if (params->filter_ssids == NULL) |
| 3348 | goto failed; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3349 | params->num_filter_ssids = src->num_filter_ssids; |
| 3350 | } |
| 3351 | |
| 3352 | params->filter_rssi = src->filter_rssi; |
| 3353 | params->p2p_probe = src->p2p_probe; |
| 3354 | params->only_new_results = src->only_new_results; |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3355 | params->low_priority = src->low_priority; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 3356 | params->duration = src->duration; |
| 3357 | params->duration_mandatory = src->duration_mandatory; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3358 | params->oce_scan = src->oce_scan; |
Sunil Ravi | 99c035e | 2024-07-12 01:42:03 +0000 | [diff] [blame] | 3359 | params->link_id = src->link_id; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3360 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3361 | if (src->sched_scan_plans_num > 0) { |
| 3362 | params->sched_scan_plans = |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3363 | os_memdup(src->sched_scan_plans, |
| 3364 | sizeof(*src->sched_scan_plans) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3365 | src->sched_scan_plans_num); |
| 3366 | if (!params->sched_scan_plans) |
| 3367 | goto failed; |
| 3368 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3369 | params->sched_scan_plans_num = src->sched_scan_plans_num; |
| 3370 | } |
| 3371 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3372 | if (src->mac_addr_rand && |
| 3373 | wpa_setup_mac_addr_rand_params(params, src->mac_addr)) |
| 3374 | goto failed; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3375 | |
| 3376 | if (src->bssid) { |
| 3377 | u8 *bssid; |
| 3378 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3379 | bssid = os_memdup(src->bssid, ETH_ALEN); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3380 | if (!bssid) |
| 3381 | goto failed; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3382 | params->bssid = bssid; |
| 3383 | } |
| 3384 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3385 | params->relative_rssi_set = src->relative_rssi_set; |
| 3386 | params->relative_rssi = src->relative_rssi; |
| 3387 | params->relative_adjust_band = src->relative_adjust_band; |
| 3388 | params->relative_adjust_rssi = src->relative_adjust_rssi; |
Hai Shalom | a20dcd7 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3389 | params->p2p_include_6ghz = src->p2p_include_6ghz; |
Sunil | 8cd6f4d | 2022-06-28 18:40:46 +0000 | [diff] [blame] | 3390 | params->non_coloc_6ghz = src->non_coloc_6ghz; |
Sunil Ravi | 2a14cf1 | 2023-11-21 00:54:38 +0000 | [diff] [blame] | 3391 | params->min_probe_req_content = src->min_probe_req_content; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3392 | return params; |
| 3393 | |
| 3394 | failed: |
| 3395 | wpa_scan_free_params(params); |
| 3396 | return NULL; |
| 3397 | } |
| 3398 | |
| 3399 | |
| 3400 | void wpa_scan_free_params(struct wpa_driver_scan_params *params) |
| 3401 | { |
| 3402 | size_t i; |
| 3403 | |
| 3404 | if (params == NULL) |
| 3405 | return; |
| 3406 | |
| 3407 | for (i = 0; i < params->num_ssids; i++) |
| 3408 | os_free((u8 *) params->ssids[i].ssid); |
| 3409 | os_free((u8 *) params->extra_ies); |
| 3410 | os_free(params->freqs); |
| 3411 | os_free(params->filter_ssids); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3412 | os_free(params->sched_scan_plans); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3413 | |
| 3414 | /* |
| 3415 | * Note: params->mac_addr_mask points to same memory allocation and |
| 3416 | * must not be freed separately. |
| 3417 | */ |
| 3418 | os_free((u8 *) params->mac_addr); |
| 3419 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3420 | os_free((u8 *) params->bssid); |
| 3421 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3422 | os_free(params); |
| 3423 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3424 | |
| 3425 | |
| 3426 | int wpas_start_pno(struct wpa_supplicant *wpa_s) |
| 3427 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3428 | int ret; |
| 3429 | size_t prio, i, num_ssid, num_match_ssid; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3430 | struct wpa_ssid *ssid; |
| 3431 | struct wpa_driver_scan_params params; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3432 | struct sched_scan_plan scan_plan; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3433 | unsigned int max_sched_scan_ssids; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3434 | |
| 3435 | if (!wpa_s->sched_scan_supported) |
| 3436 | return -1; |
| 3437 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3438 | if (wpa_s->max_sched_scan_ssids > WPAS_MAX_SCAN_SSIDS) |
| 3439 | max_sched_scan_ssids = WPAS_MAX_SCAN_SSIDS; |
| 3440 | else |
| 3441 | max_sched_scan_ssids = wpa_s->max_sched_scan_ssids; |
| 3442 | if (max_sched_scan_ssids < 1) |
| 3443 | return -1; |
| 3444 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3445 | if (wpa_s->pno || wpa_s->pno_sched_pending) |
| 3446 | return 0; |
| 3447 | |
| 3448 | if ((wpa_s->wpa_state > WPA_SCANNING) && |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3449 | (wpa_s->wpa_state < WPA_COMPLETED)) { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3450 | wpa_printf(MSG_ERROR, "PNO: In assoc process"); |
| 3451 | return -EAGAIN; |
| 3452 | } |
| 3453 | |
| 3454 | if (wpa_s->wpa_state == WPA_SCANNING) { |
| 3455 | wpa_supplicant_cancel_scan(wpa_s); |
| 3456 | if (wpa_s->sched_scanning) { |
| 3457 | wpa_printf(MSG_DEBUG, "Schedule PNO on completion of " |
| 3458 | "ongoing sched scan"); |
| 3459 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 3460 | wpa_s->pno_sched_pending = 1; |
| 3461 | return 0; |
| 3462 | } |
| 3463 | } |
| 3464 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3465 | if (wpa_s->sched_scan_stop_req) { |
| 3466 | wpa_printf(MSG_DEBUG, |
| 3467 | "Schedule PNO after previous sched scan has stopped"); |
| 3468 | wpa_s->pno_sched_pending = 1; |
| 3469 | return 0; |
| 3470 | } |
| 3471 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3472 | os_memset(¶ms, 0, sizeof(params)); |
| 3473 | |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3474 | num_ssid = num_match_ssid = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3475 | ssid = wpa_s->conf->ssid; |
| 3476 | while (ssid) { |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3477 | if (!wpas_network_disabled(wpa_s, ssid)) { |
| 3478 | num_match_ssid++; |
| 3479 | if (ssid->scan_ssid) |
| 3480 | num_ssid++; |
| 3481 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3482 | ssid = ssid->next; |
| 3483 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3484 | |
| 3485 | if (num_match_ssid == 0) { |
| 3486 | wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs"); |
| 3487 | return -1; |
| 3488 | } |
| 3489 | |
| 3490 | if (num_match_ssid > num_ssid) { |
| 3491 | params.num_ssids++; /* wildcard */ |
| 3492 | num_ssid++; |
| 3493 | } |
| 3494 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3495 | if (num_ssid > max_sched_scan_ssids) { |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3496 | wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from " |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3497 | "%u", max_sched_scan_ssids, (unsigned int) num_ssid); |
| 3498 | num_ssid = max_sched_scan_ssids; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3499 | } |
| 3500 | |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3501 | if (num_match_ssid > wpa_s->max_match_sets) { |
| 3502 | num_match_ssid = wpa_s->max_match_sets; |
| 3503 | wpa_dbg(wpa_s, MSG_DEBUG, "PNO: Too many SSIDs to match"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3504 | } |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3505 | params.filter_ssids = os_calloc(num_match_ssid, |
| 3506 | sizeof(struct wpa_driver_scan_filter)); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3507 | if (params.filter_ssids == NULL) |
| 3508 | return -1; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3509 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3510 | i = 0; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3511 | prio = 0; |
| 3512 | ssid = wpa_s->conf->pssid[prio]; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3513 | while (ssid) { |
| 3514 | if (!wpas_network_disabled(wpa_s, ssid)) { |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3515 | if (ssid->scan_ssid && params.num_ssids < num_ssid) { |
| 3516 | params.ssids[params.num_ssids].ssid = |
| 3517 | ssid->ssid; |
| 3518 | params.ssids[params.num_ssids].ssid_len = |
| 3519 | ssid->ssid_len; |
| 3520 | params.num_ssids++; |
| 3521 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3522 | os_memcpy(params.filter_ssids[i].ssid, ssid->ssid, |
| 3523 | ssid->ssid_len); |
| 3524 | params.filter_ssids[i].ssid_len = ssid->ssid_len; |
| 3525 | params.num_filter_ssids++; |
| 3526 | i++; |
Dmitry Shmidt | 6aa8ae4 | 2014-07-07 09:31:33 -0700 | [diff] [blame] | 3527 | if (i == num_match_ssid) |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3528 | break; |
| 3529 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3530 | if (ssid->pnext) |
| 3531 | ssid = ssid->pnext; |
| 3532 | else if (prio + 1 == wpa_s->conf->num_prio) |
| 3533 | break; |
| 3534 | else |
| 3535 | ssid = wpa_s->conf->pssid[++prio]; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
| 3538 | if (wpa_s->conf->filter_rssi) |
| 3539 | params.filter_rssi = wpa_s->conf->filter_rssi; |
| 3540 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3541 | if (wpa_s->sched_scan_plans_num) { |
| 3542 | params.sched_scan_plans = wpa_s->sched_scan_plans; |
| 3543 | params.sched_scan_plans_num = wpa_s->sched_scan_plans_num; |
| 3544 | } else { |
| 3545 | /* Set one scan plan that will run infinitely */ |
| 3546 | if (wpa_s->conf->sched_scan_interval) |
| 3547 | scan_plan.interval = wpa_s->conf->sched_scan_interval; |
| 3548 | else |
| 3549 | scan_plan.interval = 10; |
| 3550 | |
| 3551 | scan_plan.iterations = 0; |
| 3552 | params.sched_scan_plans = &scan_plan; |
| 3553 | params.sched_scan_plans_num = 1; |
| 3554 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3555 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3556 | params.sched_scan_start_delay = wpa_s->conf->sched_scan_start_delay; |
| 3557 | |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 3558 | if (params.freqs == NULL && wpa_s->manual_sched_scan_freqs) { |
| 3559 | wpa_dbg(wpa_s, MSG_DEBUG, "Limit sched scan to specified channels"); |
| 3560 | params.freqs = wpa_s->manual_sched_scan_freqs; |
| 3561 | } |
| 3562 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3563 | if ((wpa_s->mac_addr_rand_enable & MAC_ADDR_RAND_PNO) && |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3564 | wpa_s->wpa_state <= WPA_SCANNING) |
| 3565 | wpa_setup_mac_addr_rand_params(¶ms, wpa_s->mac_addr_pno); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3566 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 3567 | wpa_scan_set_relative_rssi_params(wpa_s, ¶ms); |
| 3568 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3569 | ret = wpa_supplicant_start_sched_scan(wpa_s, ¶ms); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3570 | os_free(params.filter_ssids); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3571 | os_free(params.mac_addr); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3572 | if (ret == 0) |
| 3573 | wpa_s->pno = 1; |
| 3574 | else |
| 3575 | wpa_msg(wpa_s, MSG_ERROR, "Failed to schedule PNO"); |
| 3576 | return ret; |
| 3577 | } |
| 3578 | |
| 3579 | |
| 3580 | int wpas_stop_pno(struct wpa_supplicant *wpa_s) |
| 3581 | { |
| 3582 | int ret = 0; |
| 3583 | |
| 3584 | if (!wpa_s->pno) |
| 3585 | return 0; |
| 3586 | |
| 3587 | ret = wpa_supplicant_stop_sched_scan(wpa_s); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3588 | wpa_s->sched_scan_stop_req = 1; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3589 | |
| 3590 | wpa_s->pno = 0; |
| 3591 | wpa_s->pno_sched_pending = 0; |
| 3592 | |
| 3593 | if (wpa_s->wpa_state == WPA_SCANNING) |
| 3594 | wpa_supplicant_req_scan(wpa_s, 0, 0); |
| 3595 | |
| 3596 | return ret; |
| 3597 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3598 | |
| 3599 | |
| 3600 | void wpas_mac_addr_rand_scan_clear(struct wpa_supplicant *wpa_s, |
| 3601 | unsigned int type) |
| 3602 | { |
| 3603 | type &= MAC_ADDR_RAND_ALL; |
| 3604 | wpa_s->mac_addr_rand_enable &= ~type; |
| 3605 | |
| 3606 | if (type & MAC_ADDR_RAND_SCAN) { |
| 3607 | os_free(wpa_s->mac_addr_scan); |
| 3608 | wpa_s->mac_addr_scan = NULL; |
| 3609 | } |
| 3610 | |
| 3611 | if (type & MAC_ADDR_RAND_SCHED_SCAN) { |
| 3612 | os_free(wpa_s->mac_addr_sched_scan); |
| 3613 | wpa_s->mac_addr_sched_scan = NULL; |
| 3614 | } |
| 3615 | |
| 3616 | if (type & MAC_ADDR_RAND_PNO) { |
| 3617 | os_free(wpa_s->mac_addr_pno); |
| 3618 | wpa_s->mac_addr_pno = NULL; |
| 3619 | } |
| 3620 | } |
| 3621 | |
| 3622 | |
| 3623 | int wpas_mac_addr_rand_scan_set(struct wpa_supplicant *wpa_s, |
| 3624 | unsigned int type, const u8 *addr, |
| 3625 | const u8 *mask) |
| 3626 | { |
| 3627 | u8 *tmp = NULL; |
| 3628 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3629 | if ((wpa_s->mac_addr_rand_supported & type) != type ) { |
| 3630 | wpa_printf(MSG_INFO, |
| 3631 | "scan: MAC randomization type %u != supported=%u", |
| 3632 | type, wpa_s->mac_addr_rand_supported); |
| 3633 | return -1; |
| 3634 | } |
| 3635 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3636 | wpas_mac_addr_rand_scan_clear(wpa_s, type); |
| 3637 | |
| 3638 | if (addr) { |
| 3639 | tmp = os_malloc(2 * ETH_ALEN); |
| 3640 | if (!tmp) |
| 3641 | return -1; |
| 3642 | os_memcpy(tmp, addr, ETH_ALEN); |
| 3643 | os_memcpy(tmp + ETH_ALEN, mask, ETH_ALEN); |
| 3644 | } |
| 3645 | |
| 3646 | if (type == MAC_ADDR_RAND_SCAN) { |
| 3647 | wpa_s->mac_addr_scan = tmp; |
| 3648 | } else if (type == MAC_ADDR_RAND_SCHED_SCAN) { |
| 3649 | wpa_s->mac_addr_sched_scan = tmp; |
| 3650 | } else if (type == MAC_ADDR_RAND_PNO) { |
| 3651 | wpa_s->mac_addr_pno = tmp; |
| 3652 | } else { |
| 3653 | wpa_printf(MSG_INFO, |
| 3654 | "scan: Invalid MAC randomization type=0x%x", |
| 3655 | type); |
| 3656 | os_free(tmp); |
| 3657 | return -1; |
| 3658 | } |
| 3659 | |
| 3660 | wpa_s->mac_addr_rand_enable |= type; |
| 3661 | return 0; |
| 3662 | } |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3663 | |
| 3664 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3665 | int wpas_mac_addr_rand_scan_get_mask(struct wpa_supplicant *wpa_s, |
| 3666 | unsigned int type, u8 *mask) |
| 3667 | { |
| 3668 | const u8 *to_copy; |
| 3669 | |
| 3670 | if ((wpa_s->mac_addr_rand_enable & type) != type) |
| 3671 | return -1; |
| 3672 | |
| 3673 | if (type == MAC_ADDR_RAND_SCAN) { |
| 3674 | to_copy = wpa_s->mac_addr_scan; |
| 3675 | } else if (type == MAC_ADDR_RAND_SCHED_SCAN) { |
| 3676 | to_copy = wpa_s->mac_addr_sched_scan; |
| 3677 | } else if (type == MAC_ADDR_RAND_PNO) { |
| 3678 | to_copy = wpa_s->mac_addr_pno; |
| 3679 | } else { |
| 3680 | wpa_printf(MSG_DEBUG, |
| 3681 | "scan: Invalid MAC randomization type=0x%x", |
| 3682 | type); |
| 3683 | return -1; |
| 3684 | } |
| 3685 | |
| 3686 | os_memcpy(mask, to_copy + ETH_ALEN, ETH_ALEN); |
| 3687 | return 0; |
| 3688 | } |
| 3689 | |
| 3690 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3691 | int wpas_abort_ongoing_scan(struct wpa_supplicant *wpa_s) |
| 3692 | { |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3693 | struct wpa_radio_work *work; |
| 3694 | struct wpa_radio *radio = wpa_s->radio; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 3695 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3696 | dl_list_for_each(work, &radio->work, struct wpa_radio_work, list) { |
| 3697 | if (work->wpa_s != wpa_s || !work->started || |
| 3698 | (os_strcmp(work->type, "scan") != 0 && |
| 3699 | os_strcmp(work->type, "p2p-scan") != 0)) |
| 3700 | continue; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3701 | wpa_dbg(wpa_s, MSG_DEBUG, "Abort an ongoing scan"); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3702 | return wpa_drv_abort_scan(wpa_s, wpa_s->curr_scan_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3703 | } |
| 3704 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3705 | wpa_dbg(wpa_s, MSG_DEBUG, "No ongoing scan/p2p-scan found to abort"); |
| 3706 | return -1; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3707 | } |
| 3708 | |
| 3709 | |
| 3710 | int wpas_sched_scan_plans_set(struct wpa_supplicant *wpa_s, const char *cmd) |
| 3711 | { |
| 3712 | struct sched_scan_plan *scan_plans = NULL; |
| 3713 | const char *token, *context = NULL; |
| 3714 | unsigned int num = 0; |
| 3715 | |
| 3716 | if (!cmd) |
| 3717 | return -1; |
| 3718 | |
| 3719 | if (!cmd[0]) { |
| 3720 | wpa_printf(MSG_DEBUG, "Clear sched scan plans"); |
| 3721 | os_free(wpa_s->sched_scan_plans); |
| 3722 | wpa_s->sched_scan_plans = NULL; |
| 3723 | wpa_s->sched_scan_plans_num = 0; |
| 3724 | return 0; |
| 3725 | } |
| 3726 | |
| 3727 | while ((token = cstr_token(cmd, " ", &context))) { |
| 3728 | int ret; |
| 3729 | struct sched_scan_plan *scan_plan, *n; |
| 3730 | |
| 3731 | n = os_realloc_array(scan_plans, num + 1, sizeof(*scan_plans)); |
| 3732 | if (!n) |
| 3733 | goto fail; |
| 3734 | |
| 3735 | scan_plans = n; |
| 3736 | scan_plan = &scan_plans[num]; |
| 3737 | num++; |
| 3738 | |
| 3739 | ret = sscanf(token, "%u:%u", &scan_plan->interval, |
| 3740 | &scan_plan->iterations); |
| 3741 | if (ret <= 0 || ret > 2 || !scan_plan->interval) { |
| 3742 | wpa_printf(MSG_ERROR, |
| 3743 | "Invalid sched scan plan input: %s", token); |
| 3744 | goto fail; |
| 3745 | } |
| 3746 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 3747 | if (scan_plan->interval > wpa_s->max_sched_scan_plan_interval) { |
| 3748 | wpa_printf(MSG_WARNING, |
| 3749 | "scan plan %u: Scan interval too long(%u), use the maximum allowed(%u)", |
| 3750 | num, scan_plan->interval, |
| 3751 | wpa_s->max_sched_scan_plan_interval); |
| 3752 | scan_plan->interval = |
| 3753 | wpa_s->max_sched_scan_plan_interval; |
| 3754 | } |
| 3755 | |
| 3756 | if (ret == 1) { |
| 3757 | scan_plan->iterations = 0; |
| 3758 | break; |
| 3759 | } |
| 3760 | |
| 3761 | if (!scan_plan->iterations) { |
| 3762 | wpa_printf(MSG_ERROR, |
| 3763 | "scan plan %u: Number of iterations cannot be zero", |
| 3764 | num); |
| 3765 | goto fail; |
| 3766 | } |
| 3767 | |
| 3768 | if (scan_plan->iterations > |
| 3769 | wpa_s->max_sched_scan_plan_iterations) { |
| 3770 | wpa_printf(MSG_WARNING, |
| 3771 | "scan plan %u: Too many iterations(%u), use the maximum allowed(%u)", |
| 3772 | num, scan_plan->iterations, |
| 3773 | wpa_s->max_sched_scan_plan_iterations); |
| 3774 | scan_plan->iterations = |
| 3775 | wpa_s->max_sched_scan_plan_iterations; |
| 3776 | } |
| 3777 | |
| 3778 | wpa_printf(MSG_DEBUG, |
| 3779 | "scan plan %u: interval=%u iterations=%u", |
| 3780 | num, scan_plan->interval, scan_plan->iterations); |
| 3781 | } |
| 3782 | |
| 3783 | if (!scan_plans) { |
| 3784 | wpa_printf(MSG_ERROR, "Invalid scan plans entry"); |
| 3785 | goto fail; |
| 3786 | } |
| 3787 | |
| 3788 | if (cstr_token(cmd, " ", &context) || scan_plans[num - 1].iterations) { |
| 3789 | wpa_printf(MSG_ERROR, |
| 3790 | "All scan plans but the last must specify a number of iterations"); |
| 3791 | goto fail; |
| 3792 | } |
| 3793 | |
| 3794 | wpa_printf(MSG_DEBUG, "scan plan %u (last plan): interval=%u", |
| 3795 | num, scan_plans[num - 1].interval); |
| 3796 | |
| 3797 | if (num > wpa_s->max_sched_scan_plans) { |
| 3798 | wpa_printf(MSG_WARNING, |
| 3799 | "Too many scheduled scan plans (only %u supported)", |
| 3800 | wpa_s->max_sched_scan_plans); |
| 3801 | wpa_printf(MSG_WARNING, |
| 3802 | "Use only the first %u scan plans, and the last one (in infinite loop)", |
| 3803 | wpa_s->max_sched_scan_plans - 1); |
| 3804 | os_memcpy(&scan_plans[wpa_s->max_sched_scan_plans - 1], |
| 3805 | &scan_plans[num - 1], sizeof(*scan_plans)); |
| 3806 | num = wpa_s->max_sched_scan_plans; |
| 3807 | } |
| 3808 | |
| 3809 | os_free(wpa_s->sched_scan_plans); |
| 3810 | wpa_s->sched_scan_plans = scan_plans; |
| 3811 | wpa_s->sched_scan_plans_num = num; |
| 3812 | |
| 3813 | return 0; |
| 3814 | |
| 3815 | fail: |
| 3816 | os_free(scan_plans); |
| 3817 | wpa_printf(MSG_ERROR, "invalid scan plans list"); |
| 3818 | return -1; |
| 3819 | } |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 3820 | |
| 3821 | |
| 3822 | /** |
| 3823 | * wpas_scan_reset_sched_scan - Reset sched_scan state |
| 3824 | * @wpa_s: Pointer to wpa_supplicant data |
| 3825 | * |
| 3826 | * This function is used to cancel a running scheduled scan and to reset an |
| 3827 | * internal scan state to continue with a regular scan on the following |
| 3828 | * wpa_supplicant_req_scan() calls. |
| 3829 | */ |
| 3830 | void wpas_scan_reset_sched_scan(struct wpa_supplicant *wpa_s) |
| 3831 | { |
| 3832 | wpa_s->normal_scans = 0; |
| 3833 | if (wpa_s->sched_scanning) { |
| 3834 | wpa_s->sched_scan_timed_out = 0; |
| 3835 | wpa_s->prev_sched_ssid = NULL; |
| 3836 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | |
| 3841 | void wpas_scan_restart_sched_scan(struct wpa_supplicant *wpa_s) |
| 3842 | { |
| 3843 | /* simulate timeout to restart the sched scan */ |
| 3844 | wpa_s->sched_scan_timed_out = 1; |
| 3845 | wpa_s->prev_sched_ssid = NULL; |
| 3846 | wpa_supplicant_cancel_sched_scan(wpa_s); |
| 3847 | } |