From patchwork Mon Oct 7 16:32:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arowa Suliman X-Patchwork-Id: 1993742 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=lGxBiTa5; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=UpFpLP0+; 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 4XMl9B65fCz1xvJ for ; Tue, 8 Oct 2024 03:34:20 +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:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=jeAB1sGUDFhsMQRmqKZS3zwkPHFUiFutmzeEjvNUZtw=; b=lGxBiTa5ouiEgt 2ugrodnqmYlqzmgPrys6Tn1XRWwfm394v/5YnlSb5GpoA084zT1WSgFhlxqcEepRA/dHk3GvzSdyF p7w7K6IbstJw9j9vSQ5JsaC9HciV0nvCUifo3gn8unpid+cqY1jwVDfQQjosj0VX1U1eMjTLOaXuC vXSZLXmyYPkl/jzJriFu64B0xWsS1zlH6HxDoBw5NdP7rg/62/NgXe9ZGqzngtYsrH+On0SMcY1He w/mZIJb2/hJnmxcgvJwRAdd6ltLnkLqKmOplhfxDdYKoXuHoeOwyyEOrNYY0zSvAMesUmvUQ+W3Ve AfCiBpOvxgGBcd3HQStA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1sxqg1-00000003Afv-29Kl; Mon, 07 Oct 2024 16:33:41 +0000 Received: from mail-io1-xd29.google.com ([2607:f8b0:4864:20::d29]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1sxqfw-00000003AfV-45i3 for hostap@lists.infradead.org; Mon, 07 Oct 2024 16:33:38 +0000 Received: by mail-io1-xd29.google.com with SMTP id ca18e2360f4ac-82ceab75c27so300738639f.1 for ; Mon, 07 Oct 2024 09:33:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1728318815; x=1728923615; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=qIxagPC6ceJUusug9EVu0et7e8UKH2o++NinQ1TNUs4=; b=UpFpLP0+V4qkPK5iigaah8t8X53q2pqYOPqDA/JSmaXAp59+B+Vmy4zKYE+yMBotaX I5EFMQjfisdc7DjeqhFlw+4Cn2IsFdzu/XNyHi02AXCWugERmI1AmPSn8HjH1IVVpOSl 529Mmb5Qyjms+fgjv3BvmlPPoEdTJP6p6cHEA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728318815; x=1728923615; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qIxagPC6ceJUusug9EVu0et7e8UKH2o++NinQ1TNUs4=; b=hMbT5shuTjb/MuGfxArbKvWO2Tcx+BZ9Fa6xK/MtBidsz0ZDL0tTEhFMDSCVZ//Qiq raz1Tm1oV8w4zHzwIrHSDZ/+RMmDxF9xKk/Eox+TNkc9EoTu9DaHGpzvrYgaRhPQkkFr yAYgnySgZn71dTFRwg/3amZAK381tgys9lHA7tCWKccEbF9Y6Tb4daMfIF9dUmicc0Se ss0gh/VXG0lj0C9YQ2/rDUwNRjcMzC66FFeLGCDgDiEVdJp+OJGUe3nIDw//pq6YowOK OSBUpZBK68hI97+NzBLYCOXKDkInuhYHDcNMUI0h1xCLWhXydaZSUAQ87qdj7YjIocv/ NDPA== X-Gm-Message-State: AOJu0YzYRAYuVRhfHOMgaSXkism72sJ9Xdv1UpcCLgRRpMUQbIbmzZIW xiLu8rV/kSWZJQGbFy6UQXYtlWafPPMRIDb/Mpw09pjdkp9cuUpdRo1f38VLVUj54ekcz7yIdNU = X-Google-Smtp-Source: AGHT+IH9k9o32X9pxgsfo5VznEZ1p+i+0VxOJ+ZTOmtHcHKokty9XMAiqLfc40G6UoqaNXMcXx4NaQ== X-Received: by 2002:a05:6602:3fd5:b0:82d:1cf:5e0c with SMTP id ca18e2360f4ac-834f7c76aa6mr1099313539f.4.1728318815182; Mon, 07 Oct 2024 09:33:35 -0700 (PDT) Received: from arowa.c.googlers.com.com (39.173.198.104.bc.googleusercontent.com. [104.198.173.39]) by smtp.gmail.com with ESMTPSA id 8926c6da1cb9f-4db8e5868f6sm225843173.112.2024.10.07.09.33.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2024 09:33:34 -0700 (PDT) From: Arowa Suliman X-Google-Original-From: Arowa Suliman To: hostap@lists.infradead.org Cc: Arowa Suliman , Arowa Suliman Subject: [PATCH] wpa_supplicant_select_network: check last scan ssids Date: Mon, 7 Oct 2024 16:32:54 +0000 Message-ID: <20241007163329.3060529-1-arowa@google.com> X-Mailer: git-send-email 2.47.0.rc0.187.ge670bccf7e-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241007_093337_068909_045F5663 X-CRM114-Status: GOOD ( 20.80 ) X-Spam-Score: -2.3 (--) 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: This recent patch [1] introduced a redundant scan when selecting a hidden network that was previously scanned and found. This occurs because the code only checks for the condition `(wpa_s->no_suitable [...] Content analysis details: (-2.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -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 Message has at least one valid DKIM or DK signature -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.2 DKIMWL_WL_HIGH DKIMwl.org - High trust sender -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:d29 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 This recent patch [1] introduced a redundant scan when selecting a hidden network that was previously scanned and found. This occurs because the code only checks for the condition `(wpa_s->no_suitable_network || wpa_s->last_scan_external)`, which doesn't cover the case where the last scan successfully found the hidden SSID. This patch saves the scanned SSIDs from the last scan and updates the condition to check if the hidden SSID was included. If the hidden SSID is not found in `last_scan_ssids`, it triggers a new scan (`request_new_scan = true`). [1] https://w1.fi/cgit/hostap/commit/?id=92374d59d4efea5c8b61ed2ceef141c26bcd7f99 Signed-off-by: Arowa Suliman --- wpa_supplicant/events.c | 19 ++++++++++++++- wpa_supplicant/wpa_supplicant.c | 40 +++++++++++++++++++++++++++---- wpa_supplicant/wpa_supplicant_i.h | 8 +++++++ 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/wpa_supplicant/events.c b/wpa_supplicant/events.c index 7947b6f08..0557926b4 100644 --- a/wpa_supplicant/events.c +++ b/wpa_supplicant/events.c @@ -2490,6 +2490,7 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, int ap = 0; bool trigger_6ghz_scan; bool short_ssid_match_found = false; + size_t idx; #ifndef CONFIG_NO_RANDOM_POOL size_t i, num; #endif /* CONFIG_NO_RANDOM_POOL */ @@ -2555,7 +2556,23 @@ static int _wpa_supplicant_event_scan_results(struct wpa_supplicant *wpa_s, } #endif /* CONFIG_NO_RANDOM_POOL */ - wpa_s->last_scan_external = data && data->scan_info.external_scan; + if (data) { + wpa_s->last_scan_external = data->scan_info.external_scan; + wpa_s->last_scan_num_ssids = data->scan_info.num_ssids; + for (idx = 0; idx < wpa_s->last_scan_num_ssids; idx++) { + /* Copy the SSID and its length */ + if (data->scan_info.ssids[idx].ssid_len > SSID_MAX_LEN) + continue; + + os_memcpy(wpa_s->last_scan_ssids[idx].ssid, + data->scan_info.ssids[idx].ssid, + data->scan_info.ssids[idx].ssid_len); + wpa_s->last_scan_ssids[idx].ssid[data->scan_info.ssids[idx].ssid_len] = + '\0'; + wpa_s->last_scan_ssids[idx].ssid_len = + data->scan_info.ssids[idx].ssid_len; + } + } if (update_only) { ret = 1; diff --git a/wpa_supplicant/wpa_supplicant.c b/wpa_supplicant/wpa_supplicant.c index 031268a41..8bbbe2d07 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -5116,7 +5116,12 @@ void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s, struct wpa_ssid *other_ssid; int disconnected = 0; + int i; bool request_new_scan = false; + bool ssid_scanned = false; + const char *current_ssid_name; + const char *prev_ssid_name; + if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) { if (wpa_s->wpa_state >= WPA_AUTHENTICATING) @@ -5162,11 +5167,36 @@ void wpa_supplicant_select_network(struct wpa_supplicant *wpa_s, (ssid->mode == WPAS_MODE_MESH || ssid->mode == WPAS_MODE_AP) ? ssid : NULL; - if (ssid->scan_ssid && - (wpa_s->no_suitable_network || wpa_s->last_scan_external)) { - wpa_printf(MSG_DEBUG, - "Request a new scan for hidden network"); - request_new_scan = true; + if (ssid->scan_ssid) { + /* Check if the previous scan included the selected network */ + if (wpa_s->last_scan_num_ssids > 1) { + current_ssid_name = wpa_ssid_txt(ssid->ssid, ssid->ssid_len); + ssid_scanned = false; + /* Iterate through the previous scan SSIDs */ + for (i = 0; i < wpa_s->last_scan_num_ssids; i++) { + prev_ssid_name = wpa_ssid_txt( + wpa_s->last_scan_ssids[i].ssid, + wpa_s->last_scan_ssids[i].ssid_len); + if (os_strcmp(current_ssid_name, prev_ssid_name) == 0) { + ssid_scanned = true; + break; + } + } + if (!ssid_scanned) { + /* SSID not found in previous scan, request a new scan */ + request_new_scan = true; + } + } else { + /* No previous scan or wildcard scan, request a new scan */ + request_new_scan = true; + } + + if (request_new_scan) { + wpa_printf(MSG_DEBUG, "Request a new scan for hidden network"); + } else { + wpa_printf(MSG_DEBUG, + "Hidden network was scanned for in last scan"); + } } else if ((ssid->key_mgmt & WPA_KEY_MGMT_OWE) && !ssid->owe_only) { wpa_printf(MSG_DEBUG, diff --git a/wpa_supplicant/wpa_supplicant_i.h b/wpa_supplicant/wpa_supplicant_i.h index 1f41c149e..b9f7e398b 100644 --- a/wpa_supplicant/wpa_supplicant_i.h +++ b/wpa_supplicant/wpa_supplicant_i.h @@ -668,6 +668,11 @@ struct ml_sta_link_info { u16 status; }; +struct last_scan_ssid { + u8 ssid[SSID_MAX_LEN + 1]; + size_t ssid_len; +}; + /** * struct wpa_supplicant - Internal data for wpa_supplicant interface @@ -806,6 +811,9 @@ struct wpa_supplicant { size_t last_scan_res_size; struct os_reltime last_scan; bool last_scan_external; + struct last_scan_ssid last_scan_ssids[WPAS_MAX_SCAN_SSIDS]; + size_t last_scan_num_ssids; + const struct wpa_driver_ops *driver; int interface_removed; /* whether the network interface has been