From patchwork Sun Mar 24 17:21:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Krishna Chaitanya X-Patchwork-Id: 1915325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=FjmD2/m7; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZbtxJ7No; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V2jYw2n19z1yWy for ; Mon, 25 Mar 2024 04:22:41 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=wC+aeJkfINRrEDgH9WKe1Wluw2wz/zzhG81k54WpQro=; b=FjmD2/m7pYywgR 0c4iPRITT9CWBrJh5wocYu3SsX395Z+uOEAsDQ7wQcQQSmtDKldls1dTaMQSTb8Qr6nyfgv2MJP4k 9ZChc9yElQFvUMnbqBEhtFUyfyCdIi9AZZE4lqjLBnfevI97WG/0tXz8uLm81P3qkWiuuQL0+I2Rb p2UIkIsdiA3b08sBPM1zkM6O6iPiEWO1gbQB1Omc55p7tfdmWHMwvIq+/zPYmpUMnbLU18SjrA7/L PWCDZIokCNIt/6Fd2lir3xQPi857p2fBhQ3g+G9aU6FNjAGQXoQzveKVu0ngx6jSQBZ32gUQCNucF 2UzWGSRHqNmRZygIKncQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1roRXE-0000000D5Hv-1uUQ; Sun, 24 Mar 2024 17:21:28 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1roRX9-0000000D5Go-1Vmk for hostap@lists.infradead.org; Sun, 24 Mar 2024 17:21:25 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1e0878b76f3so16256425ad.0 for ; Sun, 24 Mar 2024 10:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711300881; x=1711905681; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=TuWfmXczX7PW749weAMZDG+5GxsmOI1z0oOPo6T4UeY=; b=ZbtxJ7No5LOByvLNleQ885jWHLC+/edW/e1bvose0Kt6a688KWJSaPhOyZbDJj+lXY gMX4B+NJwhxyjL3s8vFli/axmwOxtW+ifJX3MVIAlhG99kFlKAy1t8qhqn7LAzefMFQn Z/ne7BvvTPwFhOUW0PvgvtUhmBKS9ri4yASz3RYYvgAiEslKSFCAz9pvPzXeQ5Sx70iw nUlQGtXTmnH520DYvqr+ZJomlZf+4dkc/PFP9XKtgWYwOguoc6lf+swgBIRowgw3pf3a c0cpMquoWbOUuxbMIsrmxlTMJCNreLbuJE3eUKOyqbquS5VOH8xN4qMRjQiSiqLwz0H0 3VYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711300881; x=1711905681; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TuWfmXczX7PW749weAMZDG+5GxsmOI1z0oOPo6T4UeY=; b=Z3qO+vNS+DD2+O/3ujHLgstdfIFlnJGymz/b+8x+8q0m9NzbgKgmXKY5lXOtTodsOj qsO12lOjd0S/n+VnrbKuXzttDyxiXorebzHZxejDAQeoJ0PWB3wkVH+MnyIZYpt72wui KlwsmasHcfVdUVlT8Zajt9s3p6P0moqg0mfu8W53K0z8XgH2fGa5sCudikXkyPTWPmX5 UdZEZt9t/A7pvdUf8fkA1Z6uDo29pGhicsK9MtS5XONQNPMlrR8/7g8ecqHLiF4AgZSn ZOdQBgg+4BLMW1zGQdKeQwstMLrYYkR0qaEhYt1ZoYcimuNwcQaGWL2vNVSa4qawcLv8 OQxg== X-Gm-Message-State: AOJu0Yyzf+6Uo901qvCYFzHlVeMf5xRavLOieVcfgM3cfmIuaEXdOIF4 QdkiZ2gAFBDkmcjGcVtPTSNJX5muRf8HLPZnvBdPqf8vrXew+T667sgw4AAu X-Google-Smtp-Source: AGHT+IEkMz4pLfLyKlhYnEbbiET4gzrBTuXz5IxtYb7+HyignY04csoLwjpPNYOCdo2+GFea0xkkIQ== X-Received: by 2002:a17:902:f54d:b0:1e0:b697:d3ae with SMTP id h13-20020a170902f54d00b001e0b697d3aemr2419632plf.19.1711300881095; Sun, 24 Mar 2024 10:21:21 -0700 (PDT) Received: from smtp.gmail.com ([49.205.251.115]) by smtp.gmail.com with ESMTPSA id x15-20020a170902ec8f00b001def088c036sm3267016plg.19.2024.03.24.10.21.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Mar 2024 10:21:20 -0700 (PDT) From: Chaitanya Tata X-Google-Original-From: Chaitanya Tata To: hostap@lists.infradead.org Subject: [PATCH v2] wpa_supplicant: Add an option to disable SNR capping Date: Sun, 24 Mar 2024 22:51:16 +0530 Message-Id: <20240324172116.99904-1-Chaitanya.Tata@nordicsemi.no> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240324_102123_639940_AAC79A08 X-CRM114-Status: GOOD ( 25.94 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: When selecting a network the default behaviour of WPA supplicant is to prefer higher throughput, it does this by capping the SNR. But in certain environments, reliability is important over throughput and choosing a lower SNR (thought it is greater than "Great SNR") might be sub-optimal. Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [chaitanya.mgit(at)gmail.com] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:62b listed in] [list.dnswl.org] X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When selecting a network the default behaviour of WPA supplicant is to prefer higher throughput, it does this by capping the SNR. But in certain environments, reliability is important over throughput and choosing a lower SNR (thought it is greater than "Great SNR") might be sub-optimal. Introduce a configuration option to choose between the two options (throughput or reliability). Signed-off-by: Chaitanya Tata --- v2: Move to runtime configuration --- tests/hwsim/test_wpas_config.py | 3 ++- wpa_supplicant/config.c | 1 + wpa_supplicant/config.h | 8 ++++++++ wpa_supplicant/config_file.c | 2 ++ wpa_supplicant/p2p_supplicant.c | 1 + wpa_supplicant/scan.c | 16 ++++++++++++++-- wpa_supplicant/scan.h | 4 ++++ wpa_supplicant/wpa_cli.c | 4 +++- wpa_supplicant/wpa_supplicant.conf | 9 +++++++++ 9 files changed, 44 insertions(+), 4 deletions(-) diff --git a/tests/hwsim/test_wpas_config.py b/tests/hwsim/test_wpas_config.py index 2b6ab2ac0..decbdce4e 100644 --- a/tests/hwsim/test_wpas_config.py +++ b/tests/hwsim/test_wpas_config.py @@ -129,7 +129,8 @@ config_checks = [("ap_scan", "0"), ("p2p_device_random_mac_addr", "1"), ("p2p_device_persistent_mac_addr", "02:12:34:56:78:9a"), ("p2p_interface_random_mac_addr", "1"), - ("openssl_ciphers", "DEFAULT")] + ("openssl_ciphers", "DEFAULT"), + ("nw_sel_strategy", "1")] def supported_param(capa, field): mesh_params = ["user_mpm", "max_peer_links", "mesh_max_inactivity"] diff --git a/wpa_supplicant/config.c b/wpa_supplicant/config.c index 2c756136c..80544a698 100644 --- a/wpa_supplicant/config.c +++ b/wpa_supplicant/config.c @@ -5589,6 +5589,7 @@ static const struct global_parse_data global_fields[] = { { FUNC(mld_connect_bssid_pref), 0 }, #endif /* CONFIG_TESTING_OPTIONS */ { INT_RANGE(ft_prepend_pmkid, 0, 1), CFG_CHANGED_FT_PREPEND_PMKID }, + { INT(nw_sel_strategy), 0 }, /* NOTE: When adding new parameters here, add_interface() in * wpa_supplicant/dbus_new_introspect.c may need to be modified to * increase the size of the iface->xml buffer. */ diff --git a/wpa_supplicant/config.h b/wpa_supplicant/config.h index 8981305c2..38b4e920e 100644 --- a/wpa_supplicant/config.h +++ b/wpa_supplicant/config.h @@ -1801,6 +1801,14 @@ struct wpa_config { int mld_force_single_link; #endif /* CONFIG_TESTING_OPTIONS */ + + /** + * nw_sel_strategy - Network selection strategy for scan results + * + * 0 = use the network with higher band preference + * 1 = use the network with highest SNR (no cap) + */ + int nw_sel_strategy; }; diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c index 1a2c0c9be..3130e6ba7 100644 --- a/wpa_supplicant/config_file.c +++ b/wpa_supplicant/config_file.c @@ -1625,6 +1625,8 @@ static void wpa_config_write_global(FILE *f, struct wpa_config *config) #endif /* CONFIG_TESTING_OPTIONS */ if (config->ft_prepend_pmkid) fprintf(f, "ft_prepend_pmkid=%d", config->ft_prepend_pmkid); + if (config->nw_sel_strategy) + fprintf(f, "nw_sel_strategy=%d\n", config->nw_sel_strategy); } #endif /* CONFIG_NO_CONFIG_WRITE */ diff --git a/wpa_supplicant/p2p_supplicant.c b/wpa_supplicant/p2p_supplicant.c index 70025f1e4..472fe0ae8 100644 --- a/wpa_supplicant/p2p_supplicant.c +++ b/wpa_supplicant/p2p_supplicant.c @@ -2217,6 +2217,7 @@ do { \ d->go_venue_group = s->go_venue_group; d->go_venue_type = s->go_venue_type; d->p2p_add_cli_chan = s->p2p_add_cli_chan; + d->nw_sel_strategy = s->nw_sel_strategy; } diff --git a/wpa_supplicant/scan.c b/wpa_supplicant/scan.c index 2db4d8b91..f171c7af4 100644 --- a/wpa_supplicant/scan.c +++ b/wpa_supplicant/scan.c @@ -24,6 +24,9 @@ #include "scan.h" #include "mesh.h" +/* qsort_r is non-standard, so, use qsort and a global variable */ +static int nw_sel_strategy; + static struct wpabuf * wpa_supplicant_extra_ies(struct wpa_supplicant *wpa_s); @@ -2376,6 +2379,7 @@ static int wpa_scan_result_compar(const void *a, const void *b) int snr_a, snr_b, snr_a_full, snr_b_full; size_t ies_len; const u8 *rsne_a, *rsne_b; + unsigned short snr_cap; /* WPA/WPA2 support preferred */ wpa_a = wpa_scan_get_vendor_ie(wa, WPA_IE_VENDOR_TYPE) != NULL || @@ -2396,6 +2400,12 @@ static int wpa_scan_result_compar(const void *a, const void *b) (wb->caps & IEEE80211_CAP_PRIVACY) == 0) return -1; + if (nw_sel_strategy == 1) { + snr_cap = DISABLE_SNR_CAP; + } else { + snr_cap = GREAT_SNR; + } + if (wa->flags & wb->flags & WPA_SCAN_LEVEL_DBM) { /* * The scan result estimates SNR over 20 MHz, while Data frames @@ -2406,12 +2416,12 @@ static int wpa_scan_result_compar(const void *a, const void *b) snr_a_full = wpas_adjust_snr_by_chanwidth((const u8 *) (wa + 1), ies_len, wa->max_cw, wa->snr); - snr_a = MIN(snr_a_full, GREAT_SNR); + snr_a = MIN(snr_a_full, snr_cap); ies_len = wb->ie_len ? wb->ie_len : wb->beacon_ie_len; snr_b_full = wpas_adjust_snr_by_chanwidth((const u8 *) (wb + 1), ies_len, wb->max_cw, wb->snr); - snr_b = MIN(snr_b_full, GREAT_SNR); + snr_b = MIN(snr_b_full, snr_cap); } else { /* Level is not in dBm, so we can't calculate * SNR. Just use raw level (units unknown). */ @@ -3182,6 +3192,8 @@ wpa_supplicant_get_scan_results(struct wpa_supplicant *wpa_s, size_t i; int (*compar)(const void *, const void *) = wpa_scan_result_compar; + nw_sel_strategy = wpa_s->conf->nw_sel_strategy; + scan_res = wpa_drv_get_scan_results(wpa_s, bssid); if (scan_res == NULL) { wpa_dbg(wpa_s, MSG_DEBUG, "Failed to get scan results"); diff --git a/wpa_supplicant/scan.h b/wpa_supplicant/scan.h index d4c06c1ae..13b771a1e 100644 --- a/wpa_supplicant/scan.h +++ b/wpa_supplicant/scan.h @@ -30,6 +30,10 @@ */ #define GREAT_SNR 25 +/* Disabled capping of SNR for network selection */ +#define DISABLE_SNR_CAP 999 + + /* * IEEE Sts 802.11ax-2021, 9.4.2.161 (Transmit Power Envelope element) indicates * no max TX power limit if Maximum Transmit Power field is 63.5 dBm. diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c index 60f85624f..f71a37abf 100644 --- a/wpa_supplicant/wpa_cli.c +++ b/wpa_supplicant/wpa_cli.c @@ -517,6 +517,7 @@ static char ** wpa_cli_complete_set(const char *str, int pos) #endif /* CONFIG_TESTING_OPTIONS */ "relative_rssi", "relative_band_adjust", "extended_key_id", + "nw_sel_strategy" }; int i, num_fields = ARRAY_SIZE(fields); @@ -617,7 +618,8 @@ static char ** wpa_cli_complete_get(const char *str, int pos) "tdls_external_control", "osu_dir", "wowlan_triggers", "p2p_search_delay", "mac_addr", "rand_addr_lifetime", "preassoc_mac_addr", "key_mgmt_offload", "passive_scan", - "reassoc_same_bss_optim", "extended_key_id" + "reassoc_same_bss_optim", "extended_key_id", + "nw_sel_strategy" }; int i, num_fields = ARRAY_SIZE(fields); diff --git a/wpa_supplicant/wpa_supplicant.conf b/wpa_supplicant/wpa_supplicant.conf index 2e36845f1..f65ab57ee 100644 --- a/wpa_supplicant/wpa_supplicant.conf +++ b/wpa_supplicant/wpa_supplicant.conf @@ -132,6 +132,15 @@ ap_scan=1 # 1: Do passive scans. #passive_scan=0 +# Network selection strategy +# +# 0 : Prefer the network with the higher band to get the best throughput. +# Cap the SNR value for comparing two networks to 25, and use the +# network with the higher band to get the best throughput. +# 1 : Prefer the network with the highest SNR ( +# Use the network with the highest SNR value without any capping. +nw_sel_strategy=0 + # MPM residency # By default, wpa_supplicant implements the mesh peering manager (MPM) for an # open mesh. However, if the driver can implement the MPM, you may set this to