From patchwork Tue Nov 5 05:36:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arowa Suliman X-Patchwork-Id: 2006649 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=cPuTEKDI; 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=H4UbfDD2; 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 4XjHCQ13BQz1xyM for ; Tue, 5 Nov 2024 16:37:06 +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=Mtl+yyeNtsJpSEMtyncwYDsi13JSN8D8K23IeHmMeYo=; b=cPuTEKDIFiGJOg 58GCpZ3c/PzPOQ6L5UGaKxfYM/qJVy9/gCfa8QeR2Zb+xaKPPp8iK391AI2J1NbS6qqYS3HxkOjd1 MNEhjWngvMP4aALXqSdgWEq+4S3W48U9MuFYBv2QKMjdYjKDzofF1m3AOkqc3m/kNpjvZBwbQOn+V hLRcHzN7B+n2SdAWZzh2KjeFEhNUFnegPCv6Lnpc6kVH0iV2qlMmvi8Ib5rlpvD/T5v5dMJu2gmFG d+hPavMP+hzHzfOmcxi5TfwskcjD9LmBvcj6qeSYDZvgoEkJUPpXfjERAP5LZTpoITqcnIe9M6lVv h/CdwLdiCgEB81RkeOgQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t8CEz-0000000Fwqh-0jBg; Tue, 05 Nov 2024 05:36:33 +0000 Received: from mail-il1-x12e.google.com ([2607:f8b0:4864:20::12e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t8CEw-0000000Fwq8-1VQI for hostap@lists.infradead.org; Tue, 05 Nov 2024 05:36:31 +0000 Received: by mail-il1-x12e.google.com with SMTP id e9e14a558f8ab-3a6c2077afcso7495205ab.0 for ; Mon, 04 Nov 2024 21:36:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1730784988; x=1731389788; 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=8cDfjMU/9Q6ANmSh3kEY6tIPzYjMiKRDiXc9e0zZGlY=; b=H4UbfDD29KoLmJHK2SS4Dz1KCmNxwqdafzrdq6/zeolkCJuZIFS4EcqjeW5sFKLdkk kMPNa8U/38Zxq8TmQto6qWe9r4/EzB2kBdS2LN1CsnXXlRm8R7GA7wAgjmlo7RQBlnjM lj+6j/u5irYq5eqyKITsYugwgqWMNpj+x86iQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730784988; x=1731389788; 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=8cDfjMU/9Q6ANmSh3kEY6tIPzYjMiKRDiXc9e0zZGlY=; b=FhLJ2p0wYusfHJOHURfa8NWlykWbTMxq2hiaeosIcdTjap0XDHp1FAllxf98lJv1J3 H89qDtS4I+1O18+AbIanGvWGKBmMmk7rIqrqmltrsGdoS0lZZeE9hnjZX2rdlC97vR1H WGxuANjhiHHXPxO1Ihu5PlU4qK9lbVg2FLJ69n5U8Wxf9WaWFJrpkDOSYKjuwDfNtKLL 0udFXYzIX9eCECYudAjSXlirwcW1ndJutxbzz4+84AYEtcp6BqdHSdgDLqaTORMcKhFP L/XY+ac8UwwMy+np1yUZP9fCXmog2H8UW79PkVQXBrGeJZeKAVo5eEGDFd/YvIbF9ska DljA== X-Gm-Message-State: AOJu0Yxm2pBH9bC1hPZ9v2ZNzu3KtfwjsTnQ+fVaGc2vj8X9mXZqAZAM ZC3s8cUeuEMycdy7uecru9Cuhe9fmBHA9MBxfk4kanqKvSBhUoqX9xj0J58Yljc4+a4Rs5vlD6k = X-Google-Smtp-Source: AGHT+IEqRQ0/AXTa7N5zQoa/UXC1cTbmpyKunUNLOqREpZE9wnpb7G+5U3HLkOaNxug1eFci2ey+Rw== X-Received: by 2002:a05:6e02:1aaf:b0:3a6:ac42:95c2 with SMTP id e9e14a558f8ab-3a6ac4297d7mr156806025ab.5.1730784988130; Mon, 04 Nov 2024 21:36:28 -0800 (PST) Received: from arowa.c.googlers.com.com (2.82.29.34.bc.googleusercontent.com. [34.29.82.2]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-3a6bd51f610sm18228155ab.73.2024.11.04.21.36.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 21:36:27 -0800 (PST) From: Arowa Suliman X-Google-Original-From: Arowa Suliman To: hostap@lists.infradead.org Cc: Arowa Suliman , Arowa Suliman Subject: [PATCH v2] wpa_supplicant_select_network: check last scan ssids Date: Tue, 5 Nov 2024 05:36:11 +0000 Message-ID: <20241105053622.498097-1-arowa@google.com> X-Mailer: git-send-email 2.47.0.199.ga7371fff76-goog MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241104_213630_456553_34C5A1C1 X-CRM114-Status: GOOD ( 23.25 ) X-Spam-Score: -2.4 (--) 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.4 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_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.3 DKIMWL_WL_HIGH DKIMwl.org - High trust sender 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`, the code checks if the SSID was found in earlier scan results. If not, it triggers a new scan. If the SSID is found, a new scan is avoided, resulting in faster connection times. [1] https://w1.fi/cgit/hostap/commit/?id=92374d59d4efea5c8b61ed2ceef141c26bcd7f99 Signed-off-by: Arowa Suliman --- wpa_supplicant/events.c | 19 +++++++++- wpa_supplicant/wpa_supplicant.c | 60 ++++++++++++++++++++++++++++--- wpa_supplicant/wpa_supplicant_i.h | 8 +++++ 3 files changed, 81 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..b5420498c 100644 --- a/wpa_supplicant/wpa_supplicant.c +++ b/wpa_supplicant/wpa_supplicant.c @@ -5104,6 +5104,30 @@ void wpa_supplicant_disable_network(struct wpa_supplicant *wpa_s, } } +/** + * Checks whether the ssid was discovered in the last scan. + * @wpa_s: wpa_supplicant structure for a network interface. + * @ssid: wpa_ssid structure for a configured network. + * Returns: true if ssid found, false otherwise. + */ +static inline bool check_ssid_last_scan(struct wpa_supplicant *wpa_s, + struct wpa_ssid *ssid) +{ + int i; + + if (wpa_s->last_scan_res != NULL && + wpa_s->last_scan_res_used != 0) { + for (i = 0; i < wpa_s->last_scan_res_used; i++) { + if (os_memcmp(wpa_s->last_scan_res[i]->ssid, + ssid->ssid, ssid->ssid_len) == 0) { + return true; + } + } + } + + return false; +} + /** * wpa_supplicant_select_network - Attempt association with a network @@ -5116,7 +5140,10 @@ 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; + if (ssid && ssid != wpa_s->current_ssid && wpa_s->current_ssid) { if (wpa_s->wpa_state >= WPA_AUTHENTICATING) @@ -5162,11 +5189,34 @@ 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) { + ssid_scanned = false; + /* Iterate through the previous scan SSIDs */ + for (i = 0; i < wpa_s->last_scan_num_ssids; i++) { + if (os_memcmp(wpa_s->last_scan_ssids[i].ssid, + ssid->ssid, ssid->ssid_len) == 0) { + ssid_scanned = true; + break; + } + } + } + + if (!ssid_scanned) { + /* Check if ssid is found in previous scan */ + if (check_ssid_last_scan(wpa_s, ssid)) { + wpa_printf(MSG_DEBUG, + "Hidden network was found in last scan results"); + } else { + request_new_scan = true; + 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