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