Re: [PATCH] Fix a channel-to-frequency transformation in ieee80211_chan_to_freq()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>> - 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 <kkangshawn@xxxxxxxxx>
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 <kkangshawn@xxxxxxxxx>
---
 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

_______________________________________________
Hostap mailing list
Hostap@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/hostap

[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]

  Powered by Linux