From f7bbad5768474ebd3c6d658c4a520e9fed10a705 Mon Sep 17 00:00:00 2001 From: Mikael Kanstrup Date: Wed, 4 Nov 2020 10:30:27 +0100 Subject: [PATCH] wpa_supplicant: Configurable fast-associate timer threshold For Android the default value of 5 seconds is usually too short for scan results from last scan initiated from settings app to be considered for fast-associate. Make the fast-associate timer value configurable so that a suitable value can be set based on a systems regular scan interval. Signed-off-by: Mikael Kanstrup --- wpa_supplicant/config.c | 2 ++ wpa_supplicant/config.h | 10 ++++++++++ wpa_supplicant/config_file.c | 5 +++++ wpa_supplicant/events.c | 8 ++++---- wpa_supplicant/wpa_cli.c | 6 ++++-- wpa_supplicant/wpa_supplicant.conf | 3 +++ wpa_supplicant/wpa_supplicant_i.h | 3 --- 7 files changed, 28 insertions(+), 9 deletions(-) diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 60129cf48..bc3d8ffd6 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -4309,6 +4309,7 @@ struct wpa_config * wpa_config_alloc_empty(const char *ctrl_interface, config->ap_isolate = DEFAULT_AP_ISOLATE; config->access_network_type = DEFAULT_ACCESS_NETWORK_TYPE; config->scan_cur_freq = DEFAULT_SCAN_CUR_FREQ; + config->scan_res_valid_for_connect = DEFAULT_SCAN_RES_VALID_FOR_CONNECT; config->wmm_ac_params[0] = ac_be; config->wmm_ac_params[1] = ac_bk; config->wmm_ac_params[2] = ac_vi; @@ -5105,6 +5106,7 @@ static const struct global_parse_data global_fields[] = { { FUNC(freq_list), 0 }, { FUNC(initial_freq_list), 0}, { INT(scan_cur_freq), 0 }, + { INT(scan_res_valid_for_connect), 0}, { INT(sched_scan_interval), 0 }, { INT(sched_scan_start_delay), 0 }, { INT(tdls_external_control), 0}, diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index c902ffbfa..aac4a9dff 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -45,6 +45,7 @@ #define DEFAULT_DISASSOC_IMMINENT_RSSI_THRESHOLD -75 #define DEFAULT_OCE_SUPPORT OCE_STA #define DEFAULT_EXTENDED_KEY_ID 0 +#define DEFAULT_SCAN_RES_VALID_FOR_CONNECT 5 #include "config_ssid.h" #include "wps/wps.h" @@ -937,6 +938,15 @@ struct wpa_config { */ int scan_cur_freq; + /** + * scan_res_valid_for_connect - Seconds scans are valid for association + * + * This configures the number of seconds old scan results are considered + * valid for association. When scan results are older than this value + * a new scan is triggered prior to the association. + */ + int scan_res_valid_for_connect; + /** * changed_parameters - Bitmap of changed parameters since last update */ diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c index 9ddd9ecfd..6f02ad32f 100644 --- a/wpa_supplicant/config_file.c +++ b/wpa_supplicant/config_file.c @@ -1487,6 +1487,11 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config) if (config->scan_cur_freq != DEFAULT_SCAN_CUR_FREQ) fprintf(f, "scan_cur_freq=%d\n", config->scan_cur_freq); + if (config->scan_res_valid_for_connect != + DEFAULT_SCAN_RES_VALID_FOR_CONNECT) + fprintf(f, "scan_res_valid_for_connect=%d\n", + config->scan_res_valid_for_connect); + if (config->sched_scan_interval) fprintf(f, "sched_scan_interval=%u\n", config->sched_scan_interval); diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 7bacc203e..aadb05409 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -2449,7 +2449,7 @@ int wpa_supplicant_fast_associate(struct wpa_supplicant *wpa_s) os_get_reltime(&now); if (os_reltime_expired(&now, &wpa_s->last_scan, - SCAN_RES_VALID_FOR_CONNECT)) { + wpa_s->conf->scan_res_valid_for_connect)) { wpa_printf(MSG_DEBUG, "Fast associate: Old scan results"); return -1; } @@ -5313,13 +5313,13 @@ void wpa_supplicant_event(void *ctx, enum wpa_event_type event, } wpa_supplicant_mark_disassoc(wpa_s); os_reltime_age(&wpa_s->last_scan, &age); - if (age.sec >= SCAN_RES_VALID_FOR_CONNECT) { - clear_at.sec = SCAN_RES_VALID_FOR_CONNECT; + if (age.sec >= wpa_s->conf->scan_res_valid_for_connect) { + clear_at.sec = wpa_s->conf->scan_res_valid_for_connect; clear_at.usec = 0; } else { struct os_reltime tmp; - tmp.sec = SCAN_RES_VALID_FOR_CONNECT; + tmp.sec = wpa_s->conf->scan_res_valid_for_connect; tmp.usec = 0; os_reltime_sub(&tmp, &age, &clear_at); } diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index ec2eeb1cc..a5f7ef353 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -493,7 +493,8 @@ static char ** wpa_cli_complete_set(const char *str, int pos) "p2p_go_max_inactivity", "auto_interworking", "okc", "pmf", "sae_groups", "dtim_period", "beacon_int", "ap_vendor_elements", "ignore_old_scan_res", "freq_list", - "scan_cur_freq", "sched_scan_interval", + "scan_cur_freq", "scan_res_valid_for_connect", + "sched_scan_interval", "tdls_external_control", "osu_dir", "wowlan_triggers", "p2p_search_delay", "mac_addr", "rand_addr_lifetime", "preassoc_mac_addr", "key_mgmt_offload", "passive_scan", @@ -589,7 +590,8 @@ static char ** wpa_cli_complete_get(const char *str, int pos) "wps_nfc_dev_pw_id", "ext_password_backend", "p2p_go_max_inactivity", "auto_interworking", "okc", "pmf", "dtim_period", "beacon_int", "ignore_old_scan_res", - "scan_cur_freq", "sched_scan_interval", + "scan_cur_freq", "scan_res_valid_for_connect", + "sched_scan_interval", "sched_scan_start_delay", "tdls_external_control", "osu_dir", "wowlan_triggers", "p2p_search_delay", "mac_addr", "rand_addr_lifetime", diff --git a/wpa_supplicant/wpa_supplicant.conf b/wpa_supplicant/wpa_supplicant.conf index 46f78755d..7a9eac139 100644 --- a/wpa_supplicant/wpa_supplicant.conf +++ b/wpa_supplicant/wpa_supplicant.conf @@ -458,6 +458,9 @@ fast_reauth=1 # 1: Scan current operating frequency if another VIF on the same radio # is already associated. +# Seconds to consider old scan results valid for association (default: 5) +#scan_res_valid_for_connect=5 + # MAC address policy default # 0 = use permanent MAC address # 1 = use random MAC address for each ESS connection diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index f70f3c853..dc37f5f26 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -49,9 +49,6 @@ struct ctrl_iface_global_priv; struct wpas_dbus_priv; struct wpas_binder_priv; -/* How many seconds to consider old scan results valid for association. */ -#define SCAN_RES_VALID_FOR_CONNECT 5 - /** * struct wpa_interface - Parameters for wpa_supplicant_add_iface() */