Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1360189pxj; Fri, 18 Jun 2021 05:36:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzPzKEKQm6+xGYHVkQj2QP8GCHyTqz6/YBcsf+rL8scl2aoBXlZEarlpZawtGxxlp3Dpr2g X-Received: by 2002:a17:906:b04d:: with SMTP id bj13mr10536493ejb.504.1624019818175; Fri, 18 Jun 2021 05:36:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624019818; cv=none; d=google.com; s=arc-20160816; b=MwxONQLRwqwB1fYh0VbYx9m5aDx7edJP8uaHV/MJH8zlJIS293mB5YGyZWR4SG53O1 H5u1r+ibqbYeP6JOC2yEHrB++GFAW1LwvUEXaEfoUHxY3khe6gcSxY8uCR6Btk+k/qsw E9tjv6eyPtEe1LwKqqQ9eFK9Aeia/Bs8qWbdNaRQO3pLe7e777//Zgu4jDwKEiBwadac O02plml/rZ5M4E3tupUORpMiKo8H6+vAULdsB/rHrAjiGMuZag8vNG2PjiQ7PEE4hily vrPNcOUhMa/hxcfPVt6SbqwT3oNIoRNtvIqiZ28ht9DmHwDXkovot03q3m8gz3saOrG2 z2fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:cc:to:from; bh=ULA9posp7siJJ4OUlgbmqSQcO7b/6vaBgMwm/qr8U0s=; b=DZEB7i6GETKNGlT6Tv1zUsIOTfiHc2OfPIzEfrP9pyB9ONEBpevWBeW2ZwIUP4/dJn Za1ZQEHkzjTzTIqMIzAj2mz2zcC2sBAoV/s4LalsrEiVQ6SnCOlP4RfsDIUi5wjuGznc LOiPD0e9fVP55Vv5GOHJ7FDIVklqWUYq+8kge88S7xMiogQuEERTB1hY5vmfOyOyy+3t BtvGHgnJpxKDyKzxI5DgpHM563srRg9YNCz88wC87CEWOpF74uVhc32Dct6jyyAdMCBK JMH75QhQaBZIasyNB/VVaHEAxWAHZOpq+Lf1NHmlG/5pzjJ78Q2BZWqwM4WjaKka51eH 2bOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 4si2067409ejc.663.2021.06.18.05.36.33; Fri, 18 Jun 2021 05:36:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233887AbhFRLCC (ORCPT + 99 others); Fri, 18 Jun 2021 07:02:02 -0400 Received: from paleale.coelho.fi ([176.9.41.70]:48256 "EHLO farmhouse.coelho.fi" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229550AbhFRLCC (ORCPT ); Fri, 18 Jun 2021 07:02:02 -0400 Received: from 91-156-6-193.elisa-laajakaista.fi ([91.156.6.193] helo=kveik.lan) by farmhouse.coelho.fi with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94) (envelope-from ) id 1luBwy-001YXx-7E; Fri, 18 Jun 2021 13:42:13 +0300 From: Luca Coelho To: johannes@sipsolutions.net Cc: luca@coelho.fi, linux-wireless@vger.kernel.org Date: Fri, 18 Jun 2021 13:41:39 +0300 Message-Id: X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210618104156.747775-1-luca@coelho.fi> References: <20210618104156.747775-1-luca@coelho.fi> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on farmhouse.coelho.fi X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=ALL_TRUSTED,BAYES_00, TVD_RCVD_IP autolearn=ham autolearn_force=no version=3.4.5-pre1 Subject: [PATCH 14/31] cfg80211: add cfg80211_any_usable_channels() Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Johannes Berg This helper function checks if there are any usable channels on any of the given bands with the given properties (as expressed by disallowed channel flags). Signed-off-by: Johannes Berg Signed-off-by: Luca Coelho --- include/net/cfg80211.h | 11 +++++++++++ net/wireless/chan.c | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 6a54caa6fa16..5a0c4fd2ec5a 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -905,6 +905,17 @@ ieee80211_chandef_max_power(struct cfg80211_chan_def *chandef) return chandef->chan->max_power; } +/** + * cfg80211_any_usable_channels - check for usable channels + * @wiphy: the wiphy to check for + * @band_mask: which bands to check on + * @prohibited_flags: which channels to not consider usable, + * %IEEE80211_CHAN_DISABLED is always taken into account + */ +bool cfg80211_any_usable_channels(struct wiphy *wiphy, + unsigned long band_mask, + u32 prohibited_flags); + /** * enum survey_info_flags - survey information flags * diff --git a/net/wireless/chan.c b/net/wireless/chan.c index 285b8076054b..0c349c7819dc 100644 --- a/net/wireless/chan.c +++ b/net/wireless/chan.c @@ -6,7 +6,7 @@ * * Copyright 2009 Johannes Berg * Copyright 2013-2014 Intel Mobile Communications GmbH - * Copyright 2018-2020 Intel Corporation + * Copyright 2018-2021 Intel Corporation */ #include @@ -1335,3 +1335,34 @@ cfg80211_get_chan_state(struct wireless_dev *wdev, WARN_ON(1); } } + +bool cfg80211_any_usable_channels(struct wiphy *wiphy, + unsigned long sband_mask, + u32 prohibited_flags) +{ + int idx; + + prohibited_flags |= IEEE80211_CHAN_DISABLED; + + for_each_set_bit(idx, &sband_mask, NUM_NL80211_BANDS) { + struct ieee80211_supported_band *sband = wiphy->bands[idx]; + int chanidx; + + if (!sband) + continue; + + for (chanidx = 0; chanidx < sband->n_channels; chanidx++) { + struct ieee80211_channel *chan; + + chan = &sband->channels[chanidx]; + + if (chan->flags & prohibited_flags) + continue; + + return true; + } + } + + return false; +} +EXPORT_SYMBOL(cfg80211_any_usable_channels); -- 2.32.0