Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp1150111lqt; Fri, 7 Jun 2024 09:18:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVjcQ8j2fIhpj0/SicMPcZizKM+rVq0L2XTfS2qupc+1IibGiOvMLEUa3w0ldbmaxdYRNXuVEsRK8Nf0pTVL777a+qPp8sGX6yUVM6wlg== X-Google-Smtp-Source: AGHT+IHBQ6TbFlhomiER83tD5HBcVu5WLnKyQVZwJkP+0RLL66HTpqzs9oL14v3M2ywOVJ2o74WT X-Received: by 2002:a17:906:b190:b0:a6e:f6b0:66cc with SMTP id a640c23a62f3a-a6ef6b06d15mr51741166b.18.1717777090930; Fri, 07 Jun 2024 09:18:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717777090; cv=pass; d=google.com; s=arc-20160816; b=lF/4UQFClb6BnvhguY6Zcuf6KmByLlPO2uoo0ZK9CV2OD78uDs1RonKa3ifbzge/r7 6MNKJ5qaQo+WYTi1YgGkiLTjLl9DII2KcbrZijPNSYJfY4ZkGx26DAoDYtMw31lA3MNy cJ9mnWiao7/R0Iw3QpKUHn+Ra+7X5XVp35lHoAKrhOcLMKreviBRROV6ko4C73kG4+Rr o/EU3sZweRCBYIHzhmuH/XbxpM0kqa93WQ3uWDAaep/ocUYLMTW+P5KiSQ5LzWHOp1K0 KRK75005NEQHEE4xnTkeNC7p41vzqU3N1+2irE48tpMaPv7ANFMXaCch/EXW9QoPIvDj sVPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Z8GPMQ3+e8e1LRdC4JDZxr/6CKNOR5J/wAjrc6pDDYw=; fh=fUr549cSqKocV7UcRuBHkVs5Q/EFHHdf/SC+m2DGkeo=; b=kjvku0K3jgCeKvZB8jYJXrZUW+jxKjCsSX4y0EM/0WPNoS3kLA6cx54tfeC2wpMVbP CltpU8uc/UCCpshMaN0iIdjurYXd0CF2cO4rmCAtZV3/lG71FC0Yz8Ua6QxluJnYSBNC SGjeovTEgULSt/XOj0Y8wxyQh+0wjrExvKIBpLuL3r6ys6qp05l0+qfwrZ/ArGnHXy1C 2l3giJA90e6dI9hVfot0CR0VMVOG0yx5XU5fPsmIm/4ELcLRCDJbrcEkGVHEvLVXJWIj 5BBgKsdc02vmHC2XciGzG5VC8psYFwh+fY3/hqqxVRwntyKvE3AoXuzvXKbMYMM8iK1r EtRA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=BLKaVbIN; arc=pass (i=1 dkim=pass dkdomain=nbd.name dmarc=pass fromdomain=nbd.name); spf=pass (google.com: domain of linux-wireless+bounces-8709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6c80597404si203329866b.137.2024.06.07.09.18.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Jun 2024 09:18:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless+bounces-8709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=BLKaVbIN; arc=pass (i=1 dkim=pass dkdomain=nbd.name dmarc=pass fromdomain=nbd.name); spf=pass (google.com: domain of linux-wireless+bounces-8709-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-wireless+bounces-8709-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nbd.name Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 9B6131F2822D for ; Fri, 7 Jun 2024 16:07:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7634719AA63; Fri, 7 Jun 2024 16:05:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=nbd.name header.i=@nbd.name header.b="BLKaVbIN" X-Original-To: linux-wireless@vger.kernel.org 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 2DAC4199E8D for ; Fri, 7 Jun 2024 16:05:55 +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=1717776358; cv=none; b=MTXMbawXbUzZpoHBXPXZ6tC0NCNLWfcAByJlsyCQh8224lPhPA8rAbjBPrETvHgDwXtBM6vl7rgNkc2XcvN78hTBk7AZ3N97v1EK3it/PkGESUeua+eyGY83Y0nExHF9/Gyt2Tz5Hy0qivEzR3/IXJmAjUcPIlFrUyhRWMjxyIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717776358; c=relaxed/simple; bh=aPs1l6oNVH7KsBAgFiXbDsImKn/+fCorSfl9c5lbpBE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t2ZXgeE4Wf3urnMqh4K7zgQJx3fqpQTeUQN8eBJOFjd21KIPfAhc8wUs7ZxQUx8JWJUcB/G9yI/xOpNB5Dsem5k2rsNhbqu9j9iQqcStpWOpYecfJKkC8mmwMmzE6dOYl5wMuGNpiSHe03yjG0gnu9qz0NpMWpMAWZBrPQxHIzw= 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=BLKaVbIN; 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 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=BLKaVbINDfgTuffRdx2V4DWgI/ PIFnNebtJQAC173OMtQljM7AMpvvbqavmJjiIfFu/JKWksUHYTcYsLCKjq1NJo2q9mmreW/mQDm1d mrXaq9UKuFJs2zIXdAq7T955lzl/L4IWmwlFsQOVsp0/HB+cFLtky8ROrUuTSvDbob80=; Received: from p4ff13226.dip0.t-ipconnect.de ([79.241.50.38] helo=localhost.localdomain) by ds12 with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (Exim 4.96) (envelope-from ) id 1sFc6A-008xPc-2g; Fri, 07 Jun 2024 18:05:50 +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: [RFC v4 4/9] wifi: cfg80211: add helper for checking if a chandef is valid on a radio Date: Fri, 7 Jun 2024 18:05:43 +0200 Message-ID: <2b6364366796642a1018272fc63ee69a56339c17.1717776325.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 Content-Transfer-Encoding: 8bit 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); -- git-series 0.9.1