[PATCH] Fix a channel-to-frequency transformation in ieee80211_chan_to_freq()
Siwon Kang
kkangshawn at gmail.com
Mon Feb 27 06:07:08 PST 2017
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 at gmail.com>
---
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.7.4
More information about the Hostap
mailing list