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