From patchwork Sun Feb 19 15:35:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SiWon Kang X-Patchwork-Id: 729563 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vR9qF6wDKz9s9N for ; Mon, 20 Feb 2017 02:36:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lLm0wQZ4"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WK3NYo6N"; dkim-atps=neutral DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:To: Subject:Message-ID:Date:From:References:In-Reply-To:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uLaPPlIO51x8u6gC4bQdUlYnW7sy/S01rKvkx0R+Sms=; b=lLm0wQZ4h/pR5TgK8d78efPWC 9YrSKJpyJMViyGkT60pT7aXgBWEnTe96Xf3UCHmxPDltKFay8kgv6NVn5HhlSjgV03STaTKrnbeHS 7nqG4FYKS5BxBUJIiupuLYArcVKjHTkesT0T0uYtEFOc39/iiXiCo1eU4is2XJMtU6WU+lhv4KTAy bcuh0Lv579pJhBwBwRf1g3Y1tKuizkpwaXkDbmMZHJkfL5W7272JCqGFSc2cab5KJ+BKenZhBMOH7 Y/psytd3H5b+wNL9raePbtCAYRqKPB7zTQvSzwVqbCeMSGiGjcpL7TBYwZOfjIwFSxRzKIHDVrcJH eBjYBktLg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cfTWp-0004u2-UG; Sun, 19 Feb 2017 15:35:59 +0000 Received: from mail-wr0-x22e.google.com ([2a00:1450:400c:c0c::22e]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cfTWO-0004ZT-46 for hostap@lists.infradead.org; Sun, 19 Feb 2017 15:35:36 +0000 Received: by mail-wr0-x22e.google.com with SMTP id 35so11700859wrw.0 for ; Sun, 19 Feb 2017 07:35:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=ilEpWPdThstS7gHF7EsgOUhvaH7WF5yIIa8ep6qtuSU=; b=WK3NYo6NIuswuCUQyYsKI4B0dNCeNAjvW0eHiTaEfLtH9FRZikMialKya4A1kf9oZX I1t9GFWStbNOOup8QjbB9yWngrhI6MGCCDp7pVqSPY/8qB3rGg8OQZGlGZPMVUl4sT7y 5569aey8lV5wVdXXokXN/fZ8J+kRfvl/FvzAvSfIakycieZFdSLIF1p5R3LcTpwQKeQi j4epr7pb1dDai6T8sIJ1cjBWYNz9ZU2OYCJgquPBbeKlOneUC017XATmuXau2SfWka9O adr9pwnZ22Xst7dKqu1UUkfVFoRkB6kfue30gCm50v0WdoO5ZcpGC2zY9/YLVHgp8KUb 32kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=ilEpWPdThstS7gHF7EsgOUhvaH7WF5yIIa8ep6qtuSU=; b=sasHlL1KESr7pufgURzQlh39s0gm4w556AJMva3Pvcy8Ipq3E8S0+wURQfdXBgM2z8 hXaJW8beLPJn6ulyTVwzLMyODn1hHy6mUIl1h5ilHsPd5fny41G2KLbvlMxiA2KghGXq a0u+O/pGiS0m8gmpBg9NZrZB1vJGaJ+ic+iOFe8GDl7OOV6bxLPthkPLgdexCfZbJWHT 9Tj20pKSVNadU+TwhXWnBqN3IB9UpXWUpNxNMJmET47m89SeT2iPpjyZshkrhcUoMvqt dP0yN0U0jWfAoTgNZ1+3/fCRX8wT8Z+is9+B3UOMJn0gX1nBnnd/42lxj7TWxIczAC8x ob7Q== X-Gm-Message-State: AMke39l1EA+NRwK+/yTQC5nAHYKEP/ysfjM6gI+3bYVhZ10k4QbNOaPupgVAQQKzuTQOP1ksniS0PNpHRxX5tw== X-Received: by 10.223.145.227 with SMTP id 90mr13440655wri.156.1487518509497; Sun, 19 Feb 2017 07:35:09 -0800 (PST) MIME-Version: 1.0 Received: by 10.223.128.17 with HTTP; Sun, 19 Feb 2017 07:35:08 -0800 (PST) In-Reply-To: <20170219123810.GB24014@w1.fi> References: <20170219123810.GB24014@w1.fi> From: Siwon Kang Date: Mon, 20 Feb 2017 00:35:08 +0900 Message-ID: Subject: Re: [PATCH] Fix a channel-to-frequency transformation in ieee80211_chan_to_freq() To: Jouni Malinen X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170219_073532_459991_22759CBD X-CRM114-Status: GOOD ( 23.29 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c0c:0:0:0:22e listed in] [list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (kkangshawn[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: hostap@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: hostap@lists.infradead.org Sender: "Hostap" Errors-To: hostap-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org >> - int freq; >> + if (country_match(us_op_class_cc, country)) > > In addition, this is whitespace damaged (tabs converted to a single > space), so I cannot apply it. At first, I am very sorry about the whitespace. I should have rather attached the patch file than copy-and-paste the contents. I used to upload through git send-email but it is blocked by gmail now. Please kindly use attached file for the patch work. > Does this fix something externally observable? It looks like the current > design of the function uses the global table as a backup path on > purpose. As such, I would rather not modify this unless there is a > clearly identifiable misbehavior and/or no chances of breaking some > existing use cases. The externally observable malfunction is the set provided in the patch as an example. As you know well, the US regulatory does not allow ch 12 and 13 so this function shall return -1 if the country code is explicitly given as 'US' just like that -1 is returned for channel 14 when CC is in the set of 'us' or 'eu'. However, it currently returns 2467 or 2472 for the input 12 or 13 + US so that it looks those channels are allowed. The header comments says the return must be -1 if the specified channel is unknown. Since the channel 12, 13 are unknown in US, it shall return -1. As well as it shouldn't use global table as a backup path because, as stated in a doxygen format description, the function uses global op_class only if the country code is unknown. In above case it specifies the known country code - US so it should not use global op_class. /** * ieee80211_chan_to_freq - Convert channel info to frequency * @country: Country code, if known; otherwise, global operating class is used * @op_class: Operating class * @chan: Channel number * Returns: Frequency in MHz or -1 if the specified channel is unknown */ FYI, I am making an API utiliizing this function. If this function returns positive values for the channels not allowed in the region, I have to add check routine for channels' validity which is major advantage of using this function. I'd very appreciate if you could kindly take your precious time for a careful review. From 8b01ed12f162f2eb08f4734a9771e495822d1cbd Mon Sep 17 00:00:00 2001 From: Siwon Kang Date: Mon, 20 Feb 2017 00:28:49 +0900 Subject: [PATCH] Fix a channel-to-frequency transformation in ieee80211_chan_to_freq() The function ieee80211_chan_to_freq() is supposed to return -1 if the specified channel is unknown. However, current if-conditional statements do not catch a few wrong combination. For example, {"US", 81, 13} for country code, operating class, channel, respectively should return -1 because op_class 81 is not in the list and channel 13 is not allowed but currently returns 2472 as if it is global. This patch removes 'if (freq > 0)' to prevent from stepping over when an input op_class is out of the list of a country then finally going to ieee80211_chan_to_freq_global(). Instead, it returns result of sub-function directly which is correct. Signed-off-by: Siwon Kang --- src/common/ieee802_11_common.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/src/common/ieee802_11_common.c b/src/common/ieee802_11_common.c index a8d68e5..5ba5071 100644 --- a/src/common/ieee802_11_common.c +++ b/src/common/ieee802_11_common.c @@ -1133,31 +1133,17 @@ static int ieee80211_chan_to_freq_global(u8 op_class, u8 chan) */ int ieee80211_chan_to_freq(const char *country, u8 op_class, u8 chan) { - int freq; + if (country_match(us_op_class_cc, country)) + return ieee80211_chan_to_freq_us(op_class, chan); - if (country_match(us_op_class_cc, country)) { - freq = ieee80211_chan_to_freq_us(op_class, chan); - if (freq > 0) - return freq; - } - - if (country_match(eu_op_class_cc, country)) { - freq = ieee80211_chan_to_freq_eu(op_class, chan); - if (freq > 0) - return freq; - } + if (country_match(eu_op_class_cc, country)) + return ieee80211_chan_to_freq_eu(op_class, chan); - if (country_match(jp_op_class_cc, country)) { - freq = ieee80211_chan_to_freq_jp(op_class, chan); - if (freq > 0) - return freq; - } + if (country_match(jp_op_class_cc, country)) + return ieee80211_chan_to_freq_jp(op_class, chan); - if (country_match(cn_op_class_cc, country)) { - freq = ieee80211_chan_to_freq_cn(op_class, chan); - if (freq > 0) - return freq; - } + if (country_match(cn_op_class_cc, country)) + return ieee80211_chan_to_freq_cn(op_class, chan); return ieee80211_chan_to_freq_global(op_class, chan); } -- 2.5.5