From patchwork Thu Sep 28 12:41:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13402925 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 976C08BF4 for ; Thu, 28 Sep 2023 12:41:31 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1c60778a3bfso85235745ad.1 for ; Thu, 28 Sep 2023 05:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695904890; x=1696509690; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NUb2MfgnYrGbuZMByEg3cptxC6yq1OsAu+tX/YWyt3U=; b=ggdqCIEGcB1uSGPIj8w8YdyWzvb57/r8xPyDHdQibGLH2YbeuKam/KIo9I6XZf2XB5 ktSGrDGhzjRVuonUBZzq/dl2TfkxdtPxmdGbJubfujIaMVAuWYA+8MUqsy8uO/4UzC1C X+nOODrlwTNbyL++JGmw2cNm5x1ED1osR+0nqGSFdpAGx+fnR1Xtim5utuTpUJJjOBq7 pNY8FM6x3UxeCDNCL/SEvszUztZ/FarzUGgAUVXnW7kkZytGN9BC5JLLY/cc0ejXxM1x oNL4wxMlM7IjK0s9Kz0Gt7I48J6Q8SHq+wy05U14FBHt443xyVw5qLa4dqm0sOaW9U5Q scwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695904890; x=1696509690; 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=NUb2MfgnYrGbuZMByEg3cptxC6yq1OsAu+tX/YWyt3U=; b=bSjnyk6J2UBWg6AonAxZoFAtGS3Yu51jw+XO52Yf4wNwWmsaApfqoSJ3x4CkArqKFR iWmvetTd4cX0W4ugTZ7fSGhiPpVfez0gf/1RziwCtL3aiMNYZBec/hTzgUM7CTumhmcr fSyTgL3Wfn6dUTu5Zp/jCqSmj+Bu2wP1xo2GqjKMfWdWq/3VLYO0eKD/2zPcOjBQkpzL 0PF650OQ9tY20U7DT4arELpzFZze18Rnl6CAgK8WEsuJzn7H6y6CJq3uh6SNizzXDLCp R3wMzfYIQAYmu8l51NpficFPhk3SM6H68DAr3GsGaseQxP8tptLHd0ZVRe73QyUGANcX I7AQ== X-Gm-Message-State: AOJu0YwbeEMIgIL3utcz8O+hBI8dPgQdlL9W2txKF4822Oz+3SrXa9gV TNjPDLj0rRBBuDu3IJaCTAP0Lg5JSDg= X-Google-Smtp-Source: AGHT+IFsD1CoXY/6eGP/QN47RUW8bA838B7TIJZEA0VtVkZK2byFlp0gS8KHxs8ZKux+P/CJLzIGow== X-Received: by 2002:a17:902:d50e:b0:1b8:8af0:416f with SMTP id b14-20020a170902d50e00b001b88af0416fmr1238741plg.1.1695904890477; Thu, 28 Sep 2023 05:41:30 -0700 (PDT) Received: from localhost.localdomain ([50.39.172.77]) by smtp.gmail.com with ESMTPSA id iw15-20020a170903044f00b001c5d09e9437sm14983105plb.25.2023.09.28.05.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:41:30 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 1/4] scan: allow splitting of scans with defined frequencies Date: Thu, 28 Sep 2023 05:41:25 -0700 Message-Id: <20230928124128.3793788-1-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Currently the only way a scan can be split is if the request does not specify any frequencies, implying the request should scan the entire spectrum. This allows the scan logic to issue an extra request if 6GHz becomes available during the 2.4 or 5GHz scans. This restriction was somewhat arbitrary and done to let periodic scans pick up 6GHz APs through a single scan request. But now with the addition of allowing user-disabled bands periodic scans will need to specify a frequency list in case a given band has been disabled. This will break the scan splitting code which is why this prep work is being done. The main difference now is the original scan frequencies are tracked with the scan request. The reason for this is so if a request comes in with a limited set of 6GHz frequences IWD won't end up scanning the full 6GHz spectrum later on. --- src/scan.c | 56 +++++++++++++++++++++--------------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) v2: * Use _auto_ for allowed frequencies in scan_cmds_add() diff --git a/src/scan.c b/src/scan.c index 915e2875..e6c105c0 100644 --- a/src/scan.c +++ b/src/scan.c @@ -107,6 +107,8 @@ struct scan_request { * and save these since there may be additional scan commands to run. */ struct scan_freq_set *freqs_scanned; + /* Entire list of frequencies to scan */ + struct scan_freq_set *scan_freqs; }; struct scan_context { @@ -170,6 +172,7 @@ static void scan_request_free(struct wiphy_radio_work_item *item) l_queue_destroy(sr->cmds, (l_queue_destroy_func_t) l_genl_msg_unref); scan_freq_set_free(sr->freqs_scanned); + scan_freq_set_free(sr->scan_freqs); l_free(sr); } @@ -341,20 +344,6 @@ static bool scan_mac_address_randomization_is_disabled(void) return disabled; } -static struct scan_freq_set *scan_get_allowed_freqs(struct scan_context *sc) -{ - struct scan_freq_set *allowed = scan_freq_set_new(); - - scan_freq_set_merge(allowed, wiphy_get_supported_freqs(sc->wiphy)); - - if (!wiphy_constrain_freq_set(sc->wiphy, allowed)) { - scan_freq_set_free(allowed); - allowed = NULL; - } - - return allowed; -} - static struct l_genl_msg *scan_build_cmd(struct scan_context *sc, bool ignore_flush_flag, bool is_passive, const struct scan_parameters *params, @@ -582,22 +571,28 @@ static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc, bool passive, const struct scan_parameters *params) { + uint32_t bands = BAND_FREQ_2_4_GHZ | BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ; unsigned int i; struct scan_freq_set *subsets[2] = { 0 }; - struct scan_freq_set *allowed = scan_get_allowed_freqs(sc); + _auto_(scan_freq_set_free) struct scan_freq_set *allowed = + wiphy_get_allowed_freqs(sc->wiphy, bands); const struct scan_freq_set *supported = wiphy_get_supported_freqs(sc->wiphy); /* - * If 6GHz is not possible, or already allowed, or the frequencies are - * explicit don't break up the request. + * No frequencies, just include the entire supported list and let the + * kernel filter out any disabled frequencies */ + if (!params->freqs) + sr->scan_freqs = scan_freq_set_clone(supported, bands); + else + sr->scan_freqs = scan_freq_set_clone(params->freqs, bands); + + /* If 6GHz is not possible or already allowed don't split the request */ if (!(scan_freq_set_get_bands(supported) & BAND_FREQ_6_GHZ) || - (scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ) || - params->freqs) { - scan_freq_set_free(allowed); + (scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ)) { scan_build_next_cmd(sr->cmds, sc, passive, - params, params->freqs); + params, sr->scan_freqs); return; } @@ -613,10 +608,8 @@ static void scan_cmds_add(struct scan_request *sr, struct scan_context *sc, * extra 6GHz-only passive scan can be appended to this request * at that time. */ - subsets[0] = scan_freq_set_clone(allowed, BAND_FREQ_2_4_GHZ); - subsets[1] = scan_freq_set_clone(allowed, BAND_FREQ_5_GHZ); - - scan_freq_set_free(allowed); + subsets[0] = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_2_4_GHZ); + subsets[1] = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_5_GHZ); for(i = 0; i < L_ARRAY_SIZE(subsets); i++) { if (!scan_freq_set_isempty(subsets[i])) @@ -1918,9 +1911,8 @@ static void scan_wiphy_watch(struct wiphy *wiphy, struct scan_request *sr = NULL; struct l_genl_msg *msg = NULL; struct scan_parameters params = { 0 }; - struct scan_freq_set *freqs_6ghz; struct scan_freq_set *allowed; - bool allow_6g; + _auto_(scan_freq_set_free) struct scan_freq_set *freqs_6ghz = NULL; /* Only care about completed regulatory dumps */ if (event != WIPHY_STATE_WATCH_EVENT_REGDOM_DONE) @@ -1934,14 +1926,14 @@ static void scan_wiphy_watch(struct wiphy *wiphy, if (!sr) return; - allowed = scan_get_allowed_freqs(sc); - allow_6g = scan_freq_set_get_bands(allowed) & BAND_FREQ_6_GHZ; + allowed = wiphy_get_allowed_freqs(sc->wiphy, BAND_FREQ_6_GHZ); + freqs_6ghz = scan_freq_set_clone(sr->scan_freqs, BAND_FREQ_6_GHZ); /* * This update did not allow 6GHz, or the original request was * not expecting 6GHz. The periodic scan should now be ended. */ - if (!allow_6g || !sr->split) { + if (!allowed || scan_freq_set_isempty(freqs_6ghz) || !sr->split) { scan_get_results(sc, sr, sr->freqs_scanned); goto free_allowed; } @@ -1951,13 +1943,9 @@ static void scan_wiphy_watch(struct wiphy *wiphy, * Create a new 6GHz passive scan request and append to the * command list */ - freqs_6ghz = scan_freq_set_clone(allowed, BAND_FREQ_6_GHZ); - msg = scan_build_cmd(sc, false, true, ¶ms, freqs_6ghz); l_queue_push_tail(sr->cmds, msg); - scan_freq_set_free(freqs_6ghz); - /* * If this periodic scan is at the top of the queue, continue * running it. From patchwork Thu Sep 28 12:41:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13402926 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02E47328B8 for ; Thu, 28 Sep 2023 12:41:31 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-1c451541f23so103761495ad.2 for ; Thu, 28 Sep 2023 05:41:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695904891; x=1696509691; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=USqwvpXESzvG8tqUOH7kTr8KSNigfK06yyXHTjF2Wpo=; b=jB6CmRq2mPS61SfyjJwDqaVy30yUrpdNPecBpZANg0MmomBU5oNKOWSVdAjiA7tRJJ qchO4eS9ocGqbd/aANJoejBn16v/zx4ifuknuCH7qXNThfZCvF2SSfKxQuQcvIgk+IpB Q10JznfT6XhxTRGmSkiGl8YQI0XNuiVq2+I7kvkDb41JZH9w6NDGABlDXij/257DRB7X evjePm8YhB7XyXLnl7B2KQxI1nh3NGzyfNsXXWEPcdFBAuM7eRdoDtNsCLwKDQTCI7HH lI0xLEYBrYAO0a6B0Y7WJERZis6abz0Z5CernO3vEFJAm7fkzGMCBrFZTOYBtSihTHTq qlkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695904891; x=1696509691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=USqwvpXESzvG8tqUOH7kTr8KSNigfK06yyXHTjF2Wpo=; b=IwlM8brjcGOiu+844UswaJbCzy18sE6WRrChdPJIjLQ983xzqo8sLM955+uUu1cIT+ T3fJ9ewLDq6wxZPeEcjN77hwuXmAxM/hElJL/5ksBtkMAYzGg1yaW6q0r3Pf3OwSiIeX GYyI1II2yxG1mXVAbUdx8UH8qMX2qmaGB3yX8bnIvzYfeJJzB3lZmaF2aXIm2bomMOzZ MjoXIVGq25A897wl3smbhWziqB288Qd0JgTgCIXa8N4y9pLp/wBxJDKWiF7kBv6Dainu mkVEOmto1OKcjmOVfEyZVLJp0mXt8enTCt43E/J1avI6S5Jx8g/f2d0EfWQIJGDa15IH aeug== X-Gm-Message-State: AOJu0YyxYh+K0J3gF1zVT7G1fvGmLyKsUoz+uwSSnAF69by9WF2hNM4E L8xFpWCGCLQS9kDsfhvRYOziaCdXAKw= X-Google-Smtp-Source: AGHT+IE08JoKn6Soxv9WUYcSBRE0CW6CEeC5BGnA7eyiyiNfL9XEblyCB4gWXPhwt/Q55x2j0V2wWQ== X-Received: by 2002:a17:902:b282:b0:1c3:2ee6:380d with SMTP id u2-20020a170902b28200b001c32ee6380dmr1098591plr.48.1695904890938; Thu, 28 Sep 2023 05:41:30 -0700 (PDT) Received: from localhost.localdomain ([50.39.172.77]) by smtp.gmail.com with ESMTPSA id iw15-20020a170903044f00b001c5d09e9437sm14983105plb.25.2023.09.28.05.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:41:30 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 2/4] scan: filter user-disabled bands for periodic scans. Date: Thu, 28 Sep 2023 05:41:26 -0700 Message-Id: <20230928124128.3793788-2-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230928124128.3793788-1-prestwoj@gmail.com> References: <20230928124128.3793788-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To support user-disabled bands periodic scans need to specify a frequency list filtered by any bands that are disabled. This was needed in scan.c since periodic scans don't provide a frequency list in the scan request. If no bands are disabled the allowed freqs API should still result in the same scan behavior as if a frequency list is left out i.e. IWD just filters the frequencies as opposed to the kernel. --- src/scan.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) v2: * Simplified how the freq set is built. Instead just clone based off supported and the band mask. This retains any currently disabled 6ghz frequencies without having to create a new set and merge diff --git a/src/scan.c b/src/scan.c index e6c105c0..93047a6b 100644 --- a/src/scan.c +++ b/src/scan.c @@ -987,9 +987,43 @@ static void scan_periodic_destroy(void *user_data) sc->sp.id = 0; } +static struct scan_freq_set *scan_periodic_get_freqs(struct scan_context *sc) +{ + uint32_t band_mask = 0; + struct scan_freq_set *freqs; + const struct scan_freq_set *supported = + wiphy_get_supported_freqs(sc->wiphy); + + if (RANK_2G_FACTOR) + band_mask |= BAND_FREQ_2_4_GHZ; + if (RANK_5G_FACTOR) + band_mask |= BAND_FREQ_5_GHZ; + if (RANK_6G_FACTOR) + band_mask |= BAND_FREQ_6_GHZ; + + freqs = scan_freq_set_clone(supported, band_mask); + if (scan_freq_set_isempty(freqs)) { + scan_freq_set_free(freqs); + freqs = NULL; + } + + return freqs; +} + static bool scan_periodic_queue(struct scan_context *sc) { struct scan_parameters params = {}; + struct scan_freq_set *freqs = scan_periodic_get_freqs(sc); + + /* + * If this happens its due to the user disabling all bands. This will + * cause IWD to never issue another periodic scan so warn the user of + * this. + */ + if (L_WARN_ON(!freqs)) + return false; + + params.freqs = freqs; if (sc->sp.needs_active_scan && known_networks_has_hidden()) { params.randomize_mac_addr_hint = true; @@ -1007,6 +1041,8 @@ static bool scan_periodic_queue(struct scan_context *sc) scan_periodic_notify, sc, scan_periodic_destroy); + scan_freq_set_free(freqs); + return sc->sp.id != 0; } From patchwork Thu Sep 28 12:41:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13402928 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 793A2374EB for ; Thu, 28 Sep 2023 12:41:32 +0000 (UTC) Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-68c576d35feso11431000b3a.2 for ; Thu, 28 Sep 2023 05:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695904891; x=1696509691; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1TBti7/t+aGJLcMCcdxlyRovtfZ90qTdg6+WUx8k96I=; b=M+WslJ68+f91xvJ2xF4uLTTVrgF0pirwQPmDetmG1tuj2ATBrIBsoYZ+0S07CWhreV vT2sG04GQXtRvtFwKIpHQuCdpaiQbdirgGLMV00GmyYyUAAq4Qzq5R6V/Zq0qimwakHX QXrdke8DP372ZY78rydCX9PKdm0jQk1e/0il+JuMvxw9QR4mOIG8IfdTQpKwR6+a6oeP oEc2WDs1Q8xsSQeuOJV1dSHm/imzow/srYWlaVtw447lhV+znETQ00GQZpHdmA2hwBh+ W5ATdERfX1T7LDU1+bI6i12EwQuHM4SBpZVn6TAZ6RClnEpXDPqnneuLTvr92TNVxKpM GbCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695904891; x=1696509691; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1TBti7/t+aGJLcMCcdxlyRovtfZ90qTdg6+WUx8k96I=; b=gcCLqoU7lupRMJWM0fdEkAfwqEx/WMNvPfwbrmhgo0XR46xgL85Efb9Bp/03fz6AU7 BZ7DyyiEAIezjeNrt/T+fxv+XtYbg8Aq5JGIFinwu9yRfuWLw8UBj+2lD6dIBLIYDfI2 Dqu0XRtzTeaMYK6++wI81Eu7IaHcRXXeB89sd/0bUIr/iru3RHtY37b3SPdSoIr5YAKQ k/Ei5/PBk6Od6aN/ojTk7wJ02Pi0n68iam+8QE/wC7/JU1e6DOkBfIh3i3GyHQemAF5Z 5yWhs88rfcXHJM2nL8KuDaiqBvzaztkKHBKwv8hOhcUj/scj8WTS02TF+iLccieKI8x5 4Mkw== X-Gm-Message-State: AOJu0YzYsgTPtR+fssiPkXBUCeH7Jm2C0nhhv48ILBvDgwRDCO5mZyzW fbtbP7raJQAqdz9kVPaV/yiI/L3xopQ= X-Google-Smtp-Source: AGHT+IEwuqP5DQWlgDBMN1wkCA7NanTm8JIHRbn/4EyC1QiTweq7J3aL94U2eqL/bNfDc0/oTlwgig== X-Received: by 2002:a05:6a20:f3a4:b0:15e:9d1b:84bf with SMTP id qr36-20020a056a20f3a400b0015e9d1b84bfmr827218pzb.23.1695904891451; Thu, 28 Sep 2023 05:41:31 -0700 (PDT) Received: from localhost.localdomain ([50.39.172.77]) by smtp.gmail.com with ESMTPSA id iw15-20020a170903044f00b001c5d09e9437sm14983105plb.25.2023.09.28.05.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:41:31 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 3/4] station: support user-disabled bands Date: Thu, 28 Sep 2023 05:41:27 -0700 Message-Id: <20230928124128.3793788-3-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230928124128.3793788-1-prestwoj@gmail.com> References: <20230928124128.3793788-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This adds support to allow users to disable entire bands, preventing scanning and connecting on those frequencies. If the [Rank].BandModifier* options are set to 0.0 it will imply those bands should not be used for scanning, connecting or roaming. This now applies to autoconnect, quick, hidden, roam, and dbus scans. This is a station only feature meaning other modules like RRM, DPP, WSC or P2P may still utilize those bands. Trying to limit bands in those modules may sometimes conflict with the spec which is why it was not added there. In addition modules like DPP/WSC are only used in limited capacity for connecting so there is little benefit gained to disallowing those bands. --- src/station.c | 120 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 97 insertions(+), 23 deletions(-) v2: * Compute an allowed band mask in station_init rather than separate bools * Let all scan paths include frequencies which may be disabled but supported. This opens up the potential for 6ghz to be unlocked, and if a frequency is disabled the kernel filters it anyways. * Optimized the dbus scan subset creation. Clone the 5/6ghz sets based on supported freqs rather than foreach. * Added a warning after computing the subsets if none were created diff --git a/src/station.c b/src/station.c index 9e4ee69a..12823142 100644 --- a/src/station.c +++ b/src/station.c @@ -73,6 +73,7 @@ static bool supports_arp_evict_nocarrier; static bool supports_ndisc_evict_nocarrier; static struct watchlist event_watches; static uint32_t known_networks_watch; +static uint32_t allowed_bands; struct station { enum station_state state; @@ -1326,6 +1327,21 @@ static bool station_needs_hidden_network_scan(struct station *station) return !l_queue_isempty(station->hidden_bss_list_sorted); } +static struct scan_freq_set *station_get_allowed_freqs(struct station *station) +{ + const struct scan_freq_set *supported = + wiphy_get_supported_freqs(station->wiphy); + struct scan_freq_set *allowed = scan_freq_set_clone(supported, + allowed_bands); + + if (scan_freq_set_isempty(allowed)) { + scan_freq_set_free(allowed); + allowed = NULL; + } + + return allowed; +} + static uint32_t station_scan_trigger(struct station *station, struct scan_freq_set *freqs, scan_trigger_func_t triggered, @@ -1411,6 +1427,7 @@ static void station_quick_scan_destroy(void *userdata) static int station_quick_scan_trigger(struct station *station) { _auto_(scan_freq_set_free) struct scan_freq_set *known_freq_set = NULL; + _auto_(scan_freq_set_free) struct scan_freq_set *allowed = NULL; bool known_6ghz; if (wiphy_regdom_is_updating(station->wiphy)) { @@ -1440,9 +1457,14 @@ static int station_quick_scan_trigger(struct station *station) known_6ghz) return -ENOTSUP; - if (!wiphy_constrain_freq_set(station->wiphy, known_freq_set)) { + allowed = station_get_allowed_freqs(station); + if (L_WARN_ON(!allowed)) + return -ENOTSUP; + + scan_freq_set_constrain(known_freq_set, allowed); + + if (scan_freq_set_isempty(known_freq_set)) return -ENOTSUP; - } station->quick_scan_id = station_scan_trigger(station, known_freq_set, @@ -2656,6 +2678,11 @@ static int station_roam_scan(struct station *station, struct scan_freq_set *freq_set) { struct scan_parameters params = { .freqs = freq_set, .flush = true }; + _auto_(scan_freq_set_free) struct scan_freq_set *allowed = + station_get_allowed_freqs(station); + + if (L_WARN_ON(!allowed)) + return -ENOTSUP; l_debug("ifindex: %u", netdev_get_ifindex(station->netdev)); @@ -2666,8 +2693,14 @@ static int station_roam_scan(struct station *station, params.ssid_len = strlen(ssid); } - if (!freq_set) + if (!freq_set) { station->roam_scan_full = true; + params.freqs = allowed; + } else + scan_freq_set_constrain(freq_set, allowed); + + if (L_WARN_ON(scan_freq_set_isempty(params.freqs))) + return -ENOTSUP; station->roam_scan_id = scan_active_full(netdev_get_wdev_id(station->netdev), ¶ms, @@ -3597,6 +3630,7 @@ static struct l_dbus_message *station_dbus_connect_hidden_network( }; const char *ssid; struct network *network; + _auto_(scan_freq_set_free) struct scan_freq_set *allowed = NULL; l_debug(""); @@ -3647,6 +3681,11 @@ not_hidden: return dbus_error_not_hidden(message); } + allowed = station_get_allowed_freqs(station); + if (L_WARN_ON(!allowed)) + return dbus_error_not_supported(message); + + params.freqs = allowed; params.ssid = (const uint8_t *)ssid; params.ssid_len = strlen(ssid); @@ -4268,39 +4307,67 @@ int station_hide_network(struct station *station, struct network *network) return 0; } -static void station_add_one_freq(uint32_t freq, void *user_data) +static void station_add_2_4ghz_freq(uint32_t freq, void *user_data) { - struct station *station = user_data; + struct scan_freq_set *set = user_data; - if (freq > 3000) - scan_freq_set_add(station->scan_freqs_order[1], freq); - else if (!scan_freq_set_contains(station->scan_freqs_order[0], freq)) - scan_freq_set_add(station->scan_freqs_order[2], freq); + /* exclude social channels added in initial scan request */ + if (freq < 3000 && freq != 2412 && freq != 2437 && freq != 2462) + scan_freq_set_add(set, freq); } static void station_fill_scan_freq_subsets(struct station *station) { const struct scan_freq_set *supported = - wiphy_get_supported_freqs(station->wiphy); + wiphy_get_supported_freqs(station->wiphy); + unsigned int subset_idx = 0; /* * Scan the 2.4GHz "social channels" first, 5GHz second, if supported, * all other 2.4GHz channels last. To be refined as needed. */ - station->scan_freqs_order[0] = scan_freq_set_new(); - scan_freq_set_add(station->scan_freqs_order[0], 2412); - scan_freq_set_add(station->scan_freqs_order[0], 2437); - scan_freq_set_add(station->scan_freqs_order[0], 2462); - - station->scan_freqs_order[1] = scan_freq_set_new(); - station->scan_freqs_order[2] = scan_freq_set_new(); - scan_freq_set_foreach(supported, station_add_one_freq, station); - - if (scan_freq_set_isempty(station->scan_freqs_order[1])) { - scan_freq_set_free(station->scan_freqs_order[1]); - station->scan_freqs_order[1] = station->scan_freqs_order[2]; - station->scan_freqs_order[2] = NULL; + if (allowed_bands & BAND_FREQ_2_4_GHZ) { + station->scan_freqs_order[subset_idx] = scan_freq_set_new(); + scan_freq_set_add(station->scan_freqs_order[subset_idx], 2412); + scan_freq_set_add(station->scan_freqs_order[subset_idx], 2437); + scan_freq_set_add(station->scan_freqs_order[subset_idx], 2462); + subset_idx++; + } + + /* + * TODO: It may might sense to split up 5 and 6ghz into separate subsets + * since the channel set is so large. + */ + if (allowed_bands & (BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ)) { + uint32_t mask = allowed_bands & + (BAND_FREQ_5_GHZ | BAND_FREQ_6_GHZ); + struct scan_freq_set *set = scan_freq_set_clone(supported, + mask); + + /* 5/6ghz didn't add any frequencies */ + if (scan_freq_set_isempty(set)) { + scan_freq_set_free(set); + } else + station->scan_freqs_order[subset_idx++] = set; } + + /* Add remaining 2.4ghz channels to subset */ + if (allowed_bands & BAND_FREQ_2_4_GHZ) { + station->scan_freqs_order[subset_idx] = scan_freq_set_new(); + scan_freq_set_foreach(supported, station_add_2_4ghz_freq, + station->scan_freqs_order[subset_idx]); + } + + /* + * This has the unintended consequence of allowing DBus scans to + * scan the entire spectrum rather than cause IWD to be completely + * non-functional. Rather than prevent DBus scans from working at all + * print a warning here. + */ + if (station->scan_freqs_order[0] == NULL) + l_warn("All supported bands were disabled by user! IWD will not" + " function as expected"); + } static void station_wiphy_watch(struct wiphy *wiphy, @@ -5194,6 +5261,13 @@ static int station_init(void) station_known_networks_changed, NULL, NULL); + if (scan_get_band_rank_modifier(BAND_FREQ_2_4_GHZ)) + allowed_bands |= BAND_FREQ_2_4_GHZ; + if (scan_get_band_rank_modifier(BAND_FREQ_5_GHZ)) + allowed_bands |= BAND_FREQ_5_GHZ; + if (scan_get_band_rank_modifier(BAND_FREQ_6_GHZ)) + allowed_bands |= BAND_FREQ_6_GHZ; + return 0; } From patchwork Thu Sep 28 12:41:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Prestwood X-Patchwork-Id: 13402927 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CBFE1374EE for ; Thu, 28 Sep 2023 12:41:32 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-1c3bd829b86so104121285ad.0 for ; Thu, 28 Sep 2023 05:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695904892; x=1696509692; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=tCP5OJlr9budLtvEit5bo/WYeTF14cXms+AeuPeOOXE=; b=Fv5UKP4unw7yOE5b8+1zAjeiFINa0xaFludDG1IttwCTkdFxfA+GGArDJoeUS8QhJj RchP0OgD+kn7NOyJD0aFitjiK3rP6xIqDgmnITEsBaJVNIm2LTWtnWXGBSrZF2kbQYNJ xcYs3H8UlGmDTG2NySHOv6ooxvphYaeUPxNdIB2DRq7OcLQ6vHPA/f2haFrS2syQbU0L 9oGpKttp7xlmG2jVaOgebcqTZJNTf9rwGyf4TTSB9OGtoqpZQICuujHTxfkaY/Huv/K/ WKhiTiJXB9H8/KPjCcO4Kj41FCaOXk97+t3Md9I14JJ8uKbq9uOsZnK5/i13N+aTsdF+ AZFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695904892; x=1696509692; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=tCP5OJlr9budLtvEit5bo/WYeTF14cXms+AeuPeOOXE=; b=gJPir3CApunOrPxefKCV6gFYMpgyZfkV68o7c2Em/00J4sL/6T8s61Y+82DmGB1ukU b7LXbzC+R17C2wtezTCGu4r7HnRLbOxyT23s62s5BisjN/yDOfAO7nfAwmnJSzQekc9b BlxTcLn6bgP6+STS+KAETp9YICKB5VCxLbGGkQPoaVfmcJjuk4QkkoWJXFIM7pkJbh49 V5tkl/dV2oclC8eg/7Cx9o/JMSvEpuWPjfpKXIu0IS6WbZj3C+H/a/2OSM3hZ6aMR73x ursFAP9btVyJCvw5pFeTaKZ/TITRICJvG9RYv4mH1SYsbndwl4jV+ZcOe3VMfBbUVe9L xsGA== X-Gm-Message-State: AOJu0YylUZRysJ8CVDWyM8CiZnjMtfA8vm02XTHd7NnoV2YfwrTMUwXW WTTPj2M3OBFk1/xe/6hrkUM8A0lTAJo= X-Google-Smtp-Source: AGHT+IGb2r/ZHAS08V2al6Z86ESEhQ7lsAnaMwAyPn3PVF9gupmZAkeL5Ii8MGGURzbxxKsukLz3JA== X-Received: by 2002:a17:902:7d92:b0:1c4:4c0f:8d91 with SMTP id a18-20020a1709027d9200b001c44c0f8d91mr1000555plm.69.1695904891936; Thu, 28 Sep 2023 05:41:31 -0700 (PDT) Received: from localhost.localdomain ([50.39.172.77]) by smtp.gmail.com with ESMTPSA id iw15-20020a170903044f00b001c5d09e9437sm14983105plb.25.2023.09.28.05.41.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 05:41:31 -0700 (PDT) From: James Prestwood To: iwd@lists.linux.dev Cc: James Prestwood Subject: [PATCH v2 4/4] doc: document disabling bands with a 0.0 modifier Date: Thu, 28 Sep 2023 05:41:28 -0700 Message-Id: <20230928124128.3793788-4-prestwoj@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230928124128.3793788-1-prestwoj@gmail.com> References: <20230928124128.3793788-1-prestwoj@gmail.com> Precedence: bulk X-Mailing-List: iwd@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 --- src/iwd.config.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/iwd.config.rst b/src/iwd.config.rst index 294e4c7b..be2fd18c 100644 --- a/src/iwd.config.rst +++ b/src/iwd.config.rst @@ -297,6 +297,9 @@ autoconnect purposes. Increase or decrease the preference for 2.4GHz access points by increasing or decreasing the value of this modifier. + A value of 0.0 will disable the 2.4GHz band and prevent scanning or + connecting on those frequencies. + * - BandModifier5Ghz - Values: floating point value (default: **1.0**) @@ -306,6 +309,9 @@ autoconnect purposes. networks are highly RSSI sensitive, so it is still possible for IWD to prefer 2.4Ghz APs in certain circumstances. + A value of 0.0 will disable the 5GHz band and prevent scanning or + connecting on those frequencies. + * - BandModifier6Ghz - Values: floating point value (default: **1.0**) @@ -313,6 +319,9 @@ autoconnect purposes. or decreasing the value of this modifier. Since 6GHz networks are highly RSSI sensitive, this gives an option to prefer 6GHz APs over 5GHz APs. + A value of 0.0 will disable the 6GHz band and prevent scanning or + connecting on those frequencies. + Scan ----