From patchwork Thu Jun 20 11:11:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felix Fietkau X-Patchwork-Id: 13705144 X-Patchwork-Delegate: johannes@sipsolutions.net Received: from nbd.name (nbd.name [46.4.11.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 56F0C1AB34D for ; Thu, 20 Jun 2024 11:24:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.4.11.11 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718882692; cv=none; b=EP0FhGQsBK+iyJexomqABy5vSFb/rpXd4KcHtGfUP9xzXao+4cZGKCSwZ5u7L9HFZIStHvLsjUsc79HKBfI+lRBxXuER5WKhOypboVVS6zSmJVPwdxNo5+2owGcxErR3mJPw7HxbL6tHGqv2WTsX8YNXjkWBImUWYoq8fko0FV8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718882692; c=relaxed/simple; bh=aPs1l6oNVH7KsBAgFiXbDsImKn/+fCorSfl9c5lbpBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BuwgCG7VTanboyrIBpyDru6kb7BBsNqFFvIzwzG+MMBeAMkrfBmsQR7Bo2e6a/jdlI1nuM+h+BIZhdVn4VlJEK8Qidy9r3QGuHq8BGrTomdYpggOIbXi1AswTHsw4SGFb3GuRGY78Ok/mwgBp43qDRYXNyx4EQ9dviO0gP2QOOc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name; spf=none smtp.mailfrom=nbd.name; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b=OyLCbZ3m; arc=none smtp.client-ip=46.4.11.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nbd.name Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=nbd.name Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b="OyLCbZ3m" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Z8GPMQ3+e8e1LRdC4JDZxr/6CKNOR5J/wAjrc6pDDYw=; b=OyLCbZ3m4fVHHCaR8ts9rodrEZ Xq+ilmSO5E2NOtt8MARqAnZJ+2EuOQZ3Vz7dZLb+2vHKDj4TbIwiRkHV7YJxG93v5lDYdaCRAE/nH 4DqrSXrhtbKg64/mrsghi+mPYd0q4WbjeGu7WLIFiYoByfRMwju0xn8pxjR8tD4g7LYU=; Received: from p4ff13dca.dip0.t-ipconnect.de ([79.241.61.202] helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1sKFhM-00Ei9k-2J; Thu, 20 Jun 2024 13:11:24 +0200 From: Felix Fietkau To: linux-wireless@vger.kernel.org Cc: johannes@sipsolutions.net, quic_adisi@quicinc.com, quic_periyasa@quicinc.com, ath12k@lists.infradead.org Subject: [PATCH 04/10] wifi: cfg80211: add helper for checking if a chandef is valid on a radio Date: Thu, 20 Jun 2024 13:11:16 +0200 Message-ID: <9db01ab6eac770040514b44dbfd23739df4f9a73.1718881762.git-series.nbd@nbd.name> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-wireless@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Check if the full channel width is in the radio's frequency range. Signed-off-by: Felix Fietkau --- include/net/cfg80211.h | 9 +++++++++ net/wireless/util.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 307b77e166c1..6ecc7f914bae 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6488,6 +6488,15 @@ static inline bool cfg80211_channel_is_psc(struct ieee80211_channel *chan) } /** + * cfg80211_radio_chandef_valid - Check if the radio supports the chandef + * + * @radio: wiphy radio + * @chandef: chandef for current channel + */ +bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio, + const struct cfg80211_chan_def *chandef); + +/** * ieee80211_get_response_rate - get basic rate for a given rate * * @sband: the band to look for rates in diff --git a/net/wireless/util.c b/net/wireless/util.c index 3da04ceb6054..a0bbb76be502 100644 --- a/net/wireless/util.c +++ b/net/wireless/util.c @@ -2879,3 +2879,38 @@ cfg80211_get_iftype_ext_capa(struct wiphy *wiphy, enum nl80211_iftype type) return NULL; } EXPORT_SYMBOL(cfg80211_get_iftype_ext_capa); + +static bool +ieee80211_radio_freq_range_valid(const struct wiphy_radio *radio, + u32 freq, u32 width) +{ + const struct wiphy_radio_freq_range *r; + int i; + + for (i = 0; i < radio->n_freq_range; i++) { + r = &radio->freq_range[i]; + if (freq - width / 2 >= r->start_freq && + freq + width / 2 <= r->end_freq) + return true; + } + + return false; +} + +bool cfg80211_radio_chandef_valid(const struct wiphy_radio *radio, + const struct cfg80211_chan_def *chandef) +{ + u32 freq, width; + + freq = ieee80211_chandef_to_khz(chandef); + width = nl80211_chan_width_to_mhz(chandef->width); + if (!ieee80211_radio_freq_range_valid(radio, freq, width)) + return false; + + freq = MHZ_TO_KHZ(chandef->center_freq2); + if (freq && !ieee80211_radio_freq_range_valid(radio, freq, width)) + return false; + + return true; +} +EXPORT_SYMBOL(cfg80211_radio_chandef_valid);