Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2109981pxa; Mon, 3 Aug 2020 07:44:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmKQ4J5BaUflDr91Jp6T9DCARukVIBr77c3VSiINQd4HHM/Wn7/zJNmFQTosX7wD58Hh0H X-Received: by 2002:a17:906:7e0a:: with SMTP id e10mr16676078ejr.312.1596465873368; Mon, 03 Aug 2020 07:44:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596465873; cv=none; d=google.com; s=arc-20160816; b=D7OVGyy+F4FcTcLL7zrHWNUAXoPfonI05K1F1Dry09Nv5cc2kPFesbMKOG97t+twE/ HXAVg+9KtJZ2ZBwFQgTSMBMLh7JzjnsXYeK+6gAhOQouF5YZNyVGSVQzWt2GkuSUCR3d VDr3CYxCBhHgHJ1qpbjkpyj6RKUeNBl6S4VkNy5nW+GsxR8Cu8WK0UqzXs7rCp/UW67m C3aOYZe9KgNctnM+ysRUvzeB3hyuHD8MLb7AobrM8KWoeGnZav/jm1Whhpm0+CV6dFFp Itx1hvm1/7Fq1obZN9ZV9eS3msp7/FiYrTCwlK3MwAzmvqGX1bBMt1VT848pa4qW+NKI tTug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=zDbingyEKXIctO01z7aie3zq5AG3ogXeuIqQC6ZzMVU=; b=GDLV14tVVRr46kIJDsVZt17jk1r6AE5eahyZolP6Hd32AxIJkhG0fwnIkrXxAIJYeu zKqRF15rLThcznPErEW9tTm8wLwACkoULKfrIvrIfqprIqXTQwwHy5CWJG00whZ8rCDz svAyuFkbsH5pNq3sEv5aNnl4xTGEBIU6808ardHLvOYOgnoC6FHpf9ju2dPoXHweVzoN IrwFHCkG/d9B5y2BjdG1IfI2+Gype9a6EUqwjdYEiux2UuZ0JYHDRjSM0W4H3Z08/+/1 TzSAdR1gu+0y1JUmY6Aj/o2xSp7lNXuiSN8BnOZ2j86h0tMVUOJu6sJil8j+pufZsqtb /r4A== 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 r3si10070750ejr.664.2020.08.03.07.44.06; Mon, 03 Aug 2020 07:44:33 -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 S1727109AbgHCOn6 (ORCPT + 99 others); Mon, 3 Aug 2020 10:43:58 -0400 Received: from smail.rz.tu-ilmenau.de ([141.24.186.67]:51354 "EHLO smail.rz.tu-ilmenau.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbgHCOn6 (ORCPT ); Mon, 3 Aug 2020 10:43:58 -0400 Received: from legolas.prakinf.tu-ilmenau.de (unknown [141.24.207.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smail.rz.tu-ilmenau.de (Postfix) with ESMTPSA id 2D79A58005E; Mon, 3 Aug 2020 16:43:55 +0200 (CEST) From: Markus Theil To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Markus Theil Subject: [PATCH v3 1/2] cfg80211: add helper fn for single rule channels Date: Mon, 3 Aug 2020 16:43:52 +0200 Message-Id: <20200803144353.305538-1-markus.theil@tu-ilmenau.de> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org As a preparation to handle adjacent rule channels, factor out handling channels located in a single regulatory rule. Signed-off-by: Markus Theil --- v3: style fixes net/wireless/reg.c | 106 +++++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/net/wireless/reg.c b/net/wireless/reg.c index 35b8847a2f6d..3dff817a9559 100644 --- a/net/wireless/reg.c +++ b/net/wireless/reg.c @@ -1691,57 +1691,18 @@ static uint32_t reg_rule_to_chan_bw_flags(const struct ieee80211_regdomain *regd return bw_flags; } -/* - * Note that right now we assume the desired channel bandwidth - * is always 20 MHz for each individual channel (HT40 uses 20 MHz - * per channel, the primary and the extension channel). - */ -static void handle_channel(struct wiphy *wiphy, - enum nl80211_reg_initiator initiator, - struct ieee80211_channel *chan) +static void handle_channel_single_rule(struct wiphy *wiphy, + enum nl80211_reg_initiator initiator, + struct ieee80211_channel *chan, + u32 flags, + struct regulatory_request *lr, + struct wiphy *request_wiphy, + const struct ieee80211_reg_rule *reg_rule) { - u32 flags, bw_flags = 0; - const struct ieee80211_reg_rule *reg_rule = NULL; + u32 bw_flags = 0; const struct ieee80211_power_rule *power_rule = NULL; - struct wiphy *request_wiphy = NULL; - struct regulatory_request *lr = get_last_request(); const struct ieee80211_regdomain *regd; - request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); - - flags = chan->orig_flags; - - reg_rule = freq_reg_info(wiphy, ieee80211_channel_to_khz(chan)); - if (IS_ERR(reg_rule)) { - /* - * We will disable all channels that do not match our - * received regulatory rule unless the hint is coming - * from a Country IE and the Country IE had no information - * about a band. The IEEE 802.11 spec allows for an AP - * to send only a subset of the regulatory rules allowed, - * so an AP in the US that only supports 2.4 GHz may only send - * a country IE with information for the 2.4 GHz band - * while 5 GHz is still supported. - */ - if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && - PTR_ERR(reg_rule) == -ERANGE) - return; - - if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && - request_wiphy && request_wiphy == wiphy && - request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { - pr_debug("Disabling freq %d.%03d MHz for good\n", - chan->center_freq, chan->freq_offset); - chan->orig_flags |= IEEE80211_CHAN_DISABLED; - chan->flags = chan->orig_flags; - } else { - pr_debug("Disabling freq %d.%03d MHz\n", - chan->center_freq, chan->freq_offset); - chan->flags |= IEEE80211_CHAN_DISABLED; - } - return; - } - regd = reg_get_regdomain(wiphy); power_rule = ®_rule->power_rule; @@ -1803,6 +1764,57 @@ static void handle_channel(struct wiphy *wiphy, chan->max_power = chan->max_reg_power; } +/* Note that right now we assume the desired channel bandwidth + * is always 20 MHz for each individual channel (HT40 uses 20 MHz + * per channel, the primary and the extension channel). + */ +static void handle_channel(struct wiphy *wiphy, + enum nl80211_reg_initiator initiator, + struct ieee80211_channel *chan) +{ + u32 flags = 0; + const struct ieee80211_reg_rule *reg_rule = NULL; + struct wiphy *request_wiphy = NULL; + struct regulatory_request *lr = get_last_request(); + + request_wiphy = wiphy_idx_to_wiphy(lr->wiphy_idx); + + flags = chan->orig_flags; + + reg_rule = freq_reg_info(wiphy, ieee80211_channel_to_khz(chan)); + if (IS_ERR(reg_rule)) { + /* We will disable all channels that do not match our + * received regulatory rule unless the hint is coming + * from a Country IE and the Country IE had no information + * about a band. The IEEE 802.11 spec allows for an AP + * to send only a subset of the regulatory rules allowed, + * so an AP in the US that only supports 2.4 GHz may only send + * a country IE with information for the 2.4 GHz band + * while 5 GHz is still supported. + */ + if (initiator == NL80211_REGDOM_SET_BY_COUNTRY_IE && + PTR_ERR(reg_rule) == -ERANGE) + return; + + if (lr->initiator == NL80211_REGDOM_SET_BY_DRIVER && + request_wiphy && request_wiphy == wiphy && + request_wiphy->regulatory_flags & REGULATORY_STRICT_REG) { + pr_debug("Disabling freq %d.%03d MHz for good\n", + chan->center_freq, chan->freq_offset); + chan->orig_flags |= IEEE80211_CHAN_DISABLED; + chan->flags = chan->orig_flags; + } else { + pr_debug("Disabling freq %d.%03d MHz\n", + chan->center_freq, chan->freq_offset); + chan->flags |= IEEE80211_CHAN_DISABLED; + } + return; + } + + handle_channel_single_rule(wiphy, initiator, chan, flags, lr, + request_wiphy, reg_rule); +} + static void handle_band(struct wiphy *wiphy, enum nl80211_reg_initiator initiator, struct ieee80211_supported_band *sband) -- 2.28.0