mac80211: Extend channel to frequency mapping for 802.11j
Subsystems (2)
RFC PATCH 1/1 mac80211: Extend channel to frequency mapping for 802.11j
Extend channel to frequency mapping for 802.11j Japan 4.9GHz band, according to IEEE802.11 section 17.3.8.3.2 and Annex J. Because there are now overlapping channel numbers in the 2GHz and 5GHz band we can't map from channel to frequency without knowing the band. This is no problem as in most contexts we know the band. In places where we don't know the band (and WEXT compatibility) we assume the 2GHz band for channels below 14.
--- include/net/cfg80211.h | 3 ++- net/mac80211/ibss.c | 2 +- net/mac80211/mesh.c | 2 +- net/mac80211/mlme.c | 8 +++++--- net/mac80211/scan.c | 3 ++- net/wireless/reg.c | 6 +++--- net/wireless/util.c | 36 ++++++++++++++++++++++-------------- net/wireless/wext-compat.c | 5 ++++- 8 files changed, 40 insertions(+), 25 deletions(-)
include/net/cfg80211.h +2 -1
@@ -1788,8 +1788,9 @@ static inline void *wdev_priv(struct wireless_dev *wdev)/** * ieee80211_channel_to_frequency - convert channel number to frequency * @chan: channel number +* @band: band, necessary due to channel number overlap */ -extern int ieee80211_channel_to_frequency (int chan); +extern int ieee80211_channel_to_frequency (int chan,enum ieee80211_band band);/** * ieee80211_frequency_to_channel - convert frequency to channel number
net/mac80211/ibss.c +1 -1
@@ -270,7 +270,7 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,enum ieee80211_band band = rx_status->band;if (elems->ds_params && elems->ds_params_len ==1 ) - freq =ieee80211_channel_to_frequency (elems->ds_params[0 ]); + freq =ieee80211_channel_to_frequency (elems->ds_params[0 ], band);else freq = rx_status->freq;
net/mac80211/mesh.c +1 -1
@@ -574,7 +574,7 @@ static void ieee80211_mesh_rx_bcn_presp(struct ieee80211_sub_if_data *sdata, &elems);if (elems.ds_params && elems.ds_params_len ==1 ) - freq =ieee80211_channel_to_frequency (elems.ds_params[0 ]); + freq =ieee80211_channel_to_frequency (elems.ds_params[0 ], band);else freq = rx_status->freq;
net/mac80211/mlme.c +5 -3
@@ -176,7 +176,7 @@ static u32 ieee80211_enable_ht(struct ieee80211_sub_if_data *sdata,/* check that channel matches the right operating channel */ if (local->hw.conf.channel->center_freq != -ieee80211_channel_to_frequency (hti->control_chan)) +ieee80211_channel_to_frequency (hti->control_chan, sband->band)) enable_ht = false;if (enable_ht) {
@@ -429,7 +429,8 @@ void ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata, container_of((void *)bss, struct cfg80211_bss, priv);struct ieee80211_channel *new_ch;struct ieee80211_if_managed *ifmgd = &sdata->u.mgd; -int new_freq =ieee80211_channel_to_frequency (sw_elem->new_ch_num); +int new_freq =ieee80211_channel_to_frequency (sw_elem->new_ch_num, + cbss->channel->band);ASSERT_MGD_MTX (ifmgd);
@@ -1519,7 +1520,8 @@ static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata, }if (elems->ds_params && elems->ds_params_len ==1 ) - freq =ieee80211_channel_to_frequency (elems->ds_params[0 ]); + freq =ieee80211_channel_to_frequency (elems->ds_params[0 ], + rx_status->band);else freq = rx_status->freq;
net/mac80211/scan.c +2 -1
@@ -196,7 +196,8 @@ ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)ieee802_11_parse_elems (elements, skb->len - baselen, &elems);if (elems.ds_params && elems.ds_params_len ==1 ) - freq =ieee80211_channel_to_frequency (elems.ds_params[0 ]); + freq =ieee80211_channel_to_frequency (elems.ds_params[0 ], + rx_status->band);else freq = rx_status->freq;
net/wireless/reg.c +3 -3
@@ -1801,9 +1801,9 @@ void regulatory_hint_disconnect(void)static bool freq_is_chan_12_13_14 (u16 freq) { -if (freq ==ieee80211_channel_to_frequency (12 ) || - freq ==ieee80211_channel_to_frequency (13 ) || - freq ==ieee80211_channel_to_frequency (14 )) +if (freq ==ieee80211_channel_to_frequency (12 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (13 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (14 ,IEEE80211_BAND_2GHZ ))return true;return false; }
net/wireless/util.c +22 -14
@@ -29,29 +29,37 @@ ieee80211_get_response_rate(struct ieee80211_supported_band *sband, }EXPORT_SYMBOL (ieee80211_get_response_rate); -int ieee80211_channel_to_frequency (int chan) +int ieee80211_channel_to_frequency (int chan,enum ieee80211_band band) { -if (chan <14 ) -return 2407 + chan *5 ; - -if (chan ==14 ) -return 2484 ; - -/* FIXME: 802.11j 17.3.8.3.2 */ -return (chan +1000 ) *5 ; +/* see 802.11 17.3.8.3.2 and Annex J +* there are overlapping channel numbers in 5GHz and 2GHz bands */ +if (band ==IEEE80211_BAND_5GHZ ) { +if (chan >=182 && chan <=196 ) +return 4000 + chan *5 ; +else +return 5000 + chan *5 ; + }else {/* IEEE80211_BAND_2GHZ */ +if (chan ==14 ) +return 2484 ; +else if (chan <14 ) +return 2407 + chan *5 ; +else +return 0 ;/* not supported */ + } }EXPORT_SYMBOL (ieee80211_channel_to_frequency);int ieee80211_frequency_to_channel (int freq) { +/* see 802.11 17.3.8.3.2 and Annex J */ if (freq ==2484 )return 14 ; - -if (freq <2484 ) +else if (freq <2484 )return (freq -2407 ) /5 ; - -/* FIXME: 802.11j 17.3.8.3.2 */ -return freq/5 -1000 ; +else if (freq >=4910 && freq <=4980 ) +return (freq -4000 ) /5 ; +else +return (freq -5000 ) /5 ; }EXPORT_SYMBOL (ieee80211_frequency_to_channel);
net/wireless/wext-compat.c +4 -1
@@ -267,9 +267,12 @@ int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq)* -EINVAL for impossible things. */ if (freq->e ==0 ) { +int band =IEEE80211_BAND_2GHZ ;if (freq->m <0 )return 0 ; -return ieee80211_channel_to_frequency (freq->m); +if (freq->m >14 ) + band =IEEE80211_BAND_5GHZ ; +return ieee80211_channel_to_frequency (freq->m, band); }else {int i, div =1000000 ;for (i =0 ; i < freq->e; i++)
Quoted 48 lines · Bruno Randolf
Extend channel to frequency mapping for 802.11j Japan 4.9GHz band, according to IEEE802.11 section 17.3.8.3.2 and Annex J. Because there are now overlapping channel numbers in the 2GHz and 5GHz band we can't map from channel to frequency without knowing the band. This is no problem as in most contexts we know the band. In places where we don't know the band (and WEXT compatibility) we assume the 2GHz band for channels below 14.
Signed-off-by Bruno Randolf <[email protected]>---
net/wireless/util.c +1
-1-int ieee80211_channel_to_frequency (int chan) +int ieee80211_channel_to_frequency (int chan,enum ieee80211_band band){
- if (chan < 14)
- return 2407 + chan * 5;net/wireless/util.c +15
-6- - if (chan == 14) - return 2484; - - /* FIXME: 802.11j 17.3.8.3.2 */ - return (chan + 1000) * 5; + /* see 802.11 17.3.8.3.2 and Annex J + * there are overlapping channel numbers in 5GHz and 2GHz bands */ + if (band == IEEE80211_BAND_5GHZ) { + if (chan >= 182 && chan <= 196) + return 4000 + chan * 5; + else + return 5000 + chan * 5; + } else { /* IEEE80211_BAND_2GHZ */ + if (chan == 14) + return 2484; + else if (chan < 14) + return 2407 + chan * 5; + else + return 0; /* not supported */ + }}
EXPORT_SYMBOL(ieee80211_channel_to_frequency);int
ieee80211_frequency_to_channel(int freq)
{
+ /* see 802.11 17.3.8.3.2 and Annex J */
if (freq == 2484)
return 14;
-
- if (freq < 2484)
+ else if (freq < 2484)
return (freq - 2407) / 5;
-
Quoted 8 lines
- /* FIXME: 802.11j 17.3.8.3.2 */
- return freq/5 - 1000;
+ else if (freq >= 4910 && freq <= 4980)
+ return (freq - 4000) / 5;
+ else
+ return (freq - 5000) / 5;
}
EXPORT_SYMBOL(ieee80211_frequency_to_channel);
You don't have to use them, but there are a few channel/frequency conversion routines in include/ieee80211.h which could be reused in these functions.
Regards,
Dave.
Johannes Berg
maintainernet/wireless/reg.c void regulatory_hint_disconnect(void) · line 1807
Quoted 9 lines · Bruno Randolf
static bool
freq_is_chan_12_13_14(u16 freq)
{net/wireless/reg.c +3
-3-if (freq ==ieee80211_channel_to_frequency (12 ) || - freq ==ieee80211_channel_to_frequency (13 ) || - freq ==ieee80211_channel_to_frequency (14 )) +if (freq ==ieee80211_channel_to_frequency (12 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (13 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (14 ,IEEE80211_BAND_2GHZ ))return true;
This seems strange ... why not just hardcode the values??
net/wireless/wext-compat.c int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq) · line 270
Quoted 2 lines
net/wireless/wext-compat.c +1
-0if (freq->e ==0 ) { +int band =IEEE80211_BAND_2GHZ ;
enum?
johannes
Quoted 11 lines · On Mon December 27 2010 19:57:39 Johannes Berg wrote:
Quoted 10 lines · Bruno Randolf
static bool
freq_is_chan_12_13_14(u16 freq)
{net/wireless/reg.c +3
-3-if (freq ==ieee80211_channel_to_frequency (12 ) || - freq ==ieee80211_channel_to_frequency (13 ) || - freq ==ieee80211_channel_to_frequency (14 )) +if (freq ==ieee80211_channel_to_frequency (12 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (13 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (14 ,IEEE80211_BAND_2GHZ ))
Quoted 3 lines
Quoted 1 line
return true;
This seems strange ... why not just hardcode the values??
True, but this is not my code, I just did the change for the new function parameter. It's in net/wireless/reg.c, so I'll CC: Luis.
Quoted 5 lines
net/wireless/wext-compat.c int cfg80211_wext_freq(struct wiphy *wiphy, struct iw_freq *freq) · line 270
Quoted 3 lines
net/wireless/wext-compat.c +1
-0if (freq->e ==0 ) { +int band =IEEE80211_BAND_2GHZ ;enum?
Ok, thanks.
Any other comments on the code or purpose of this patch?
bruno
Johannes Berg
maintainerQuoted 7 lines · Bruno Randolf
Quoted 7 lines
Quoted 7 lines
net/wireless/reg.c +3
-3-if (freq ==ieee80211_channel_to_frequency (12 ) || - freq ==ieee80211_channel_to_frequency (13 ) || - freq ==ieee80211_channel_to_frequency (14 )) +if (freq ==ieee80211_channel_to_frequency (12 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (13 ,IEEE80211_BAND_2GHZ ) || + freq ==ieee80211_channel_to_frequency (14 ,IEEE80211_BAND_2GHZ ))
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
return true;
This seems strange ... why not just hardcode the values??
True, but this is not my code, I just did the change for the new function parameter. It's in
net/wireless/reg.c, so I'll CC: Luis.
Right. It seems rather complicated though, especially with this change.
Quoted 1 line
Any other comments on the code or purpose of this patch?
Not really. I guess it seems fine. Do you know if there are ever any starting values used other than 4900 and 5000?
johannes
Quoted 2 lines · Johannes Berg
Not really. I guess it seems fine. Do you know if there are ever any starting values used other than 4900 and 5000?
Quite a few.. At least 4.85 GHz and 3.0 GHz for 20 MHz channels and more for 5 and 10 MHz channels (4.9375 GHz, 4.89 GHz, 3.0025 GHz, 4.0025 GHz, 5.0025 GHz) in channels defined by IEEE 802.11.
Signature · 1 line
Jouni Malinen PGP id EFC895FA
Johannes Berg
maintainerQuoted 7 lines · Jouni Malinen
Quoted 2 lines · Johannes Berg
Not really. I guess it seems fine. Do you know if there are ever any starting values used other than 4900 and 5000?
Quite a few.. At least 4.85 GHz and 3.0 GHz for 20 MHz channels and more for 5 and 10 MHz channels (4.9375 GHz, 4.89 GHz, 3.0025 GHz, 4.0025 GHz, 5.0025 GHz) in channels defined by IEEE 802.11.
That's what I kinda thought ... doesn't that mean this patch is insufficient?
johannes
Quoted 7 lines · Johannes Berg
Quoted 3 lines · Jouni Malinen
Quite a few.. At least 4.85 GHz and 3.0 GHz for 20 MHz channels and more for 5 and 10 MHz channels (4.9375 GHz, 4.89 GHz, 3.0025 GHz, 4.0025 GHz, 5.0025 GHz) in channels defined by IEEE 802.11.
That's what I kinda thought ... doesn't that mean this patch is insufficient?
Depends on what it is trying to achieve. Based on the Subject: line, it aims to add support for channels defined in 802.11j and it does indeed seem to do that (most of those odd channel starting frequencies come from 802.11y). If the goal were to cover all channels defined in the current IEEE 802.11 standard, then sure, it would be insufficient, but it is not like we support 3.6 GHz band or sub-20 MHz channels anyway, so only the 4.85 GHz starting frequency for some emergency channels from 802.11y would not be covered.
Signature · 1 line
Jouni Malinen PGP id EFC895FA
Quoted 9 lines · On Tue December 28 2010 18:25:10 Jouni Malinen wrote:
Quoted 7 lines · Johannes Berg
Quoted 3 lines · Jouni Malinen
Quite a few.. At least 4.85 GHz and 3.0 GHz for 20 MHz channels and more for 5 and 10 MHz channels (4.9375 GHz, 4.89 GHz, 3.0025 GHz, 4.0025 GHz, 5.0025 GHz) in channels defined by IEEE 802.11.
That's what I kinda thought ... doesn't that mean this patch is insufficient?
Quoted 8 lines
Depends on what it is trying to achieve. Based on the Subject: line, it aims to add support for channels defined in 802.11j and it does indeed seem to do that (most of those odd channel starting frequencies come from 802.11y). If the goal were to cover all channels defined in the current IEEE 802.11 standard, then sure, it would be insufficient, but it is not like we support 3.6 GHz band or sub-20 MHz channels anyway, so only the 4.85 GHz starting frequency for some emergency channels from 802.11y would not be covered.
Well, yeah, I'm was only concerned about the 802.11j part. And I left out all stuff for non 20MHz channels. If it's needed these functions can be extended more later... The Japanese need 802.11j now, not a theoretically complete channel to frequency mapping... ;)
bruno
Quoted 54 lines · On Sat December 25 2010 01:46:00 Dave Kilroy wrote:
Quoted 53 lines · Bruno Randolf
Extend channel to frequency mapping for 802.11j Japan 4.9GHz band, according to IEEE802.11 section 17.3.8.3.2 and Annex J. Because there are now overlapping channel numbers in the 2GHz and 5GHz band we can't map from channel to frequency without knowing the band. This is no problem as in most contexts we know the band. In places where we don't know the band (and WEXT compatibility) we assume the 2GHz band for channels below 14.
Signed-off-by Bruno Randolf <[email protected]>---
net/wireless/util.c +3
-9-int ieee80211_channel_to_frequency (int chan) +int ieee80211_channel_to_frequency (int chan,enum ieee80211_band band) { -if (chan <14 ) -return 2407 + chan *5 ; - -if (chan ==14 ) -return 2484 ; - -/* FIXME: 802.11j 17.3.8.3.2 */ -return (chan +1000 ) *5 ; +/* see 802.11 17.3.8.3.2 and Annex J +* there are overlapping channel numbers in 5GHz and 2GHz bands */ + if (band ==
IEEE80211_BAND_5GHZ) {net/wireless/util.c +16
-5+if (chan >=182 && chan <=196 ) +return 4000 + chan *5 ; +else +return 5000 + chan *5 ; + }else {/* IEEE80211_BAND_2GHZ */ +if (chan ==14 ) +return 2484 ; +else if (chan <14 ) +return 2407 + chan *5 ; +else +return 0 ;/* not supported */ + } }EXPORT_SYMBOL (ieee80211_channel_to_frequency);int ieee80211_frequency_to_channel (int freq) { +/* see 802.11 17.3.8.3.2 and Annex J */ if (freq ==2484 )return 14 ; - -if (freq <2484 ) +else if (freq <2484 )return (freq -2407 ) /5 ; - -/* FIXME: 802.11j 17.3.8.3.2 */ -return freq/5 -1000 ; +else if (freq >=4910 && freq <=4980 ) +return (freq -4000 ) /5 ;
Quoted 8 lines
net/wireless/util.c ieee80211_get_response_rate(struct ieee80211_supported_band *sband, · line 64
Quoted 4 lines
net/wireless/util.c +2
-0+else +return (freq -5000 ) /5 ; }EXPORT_SYMBOL (ieee80211_frequency_to_channel);You don't have to use them, but there are a few channel/frequency conversion routines in
include/ieee80211.hwhich could be reused in these functions.
Thanks for that info, I didn't know about those functions. I just checked them and it seems most of them are not used, AFAICT:
ieee80211_fhss_chan_to_freq - not usedieee80211_freq_to_fhss_chan - not usedieee80211_hr_chan_to_freq - not usedieee80211_freq_to_hr_chan - not usedieee80211_erp_chan_to_freq - not usedieee80211_freq_to_erp_chan - not usedieee80211_ofdm_chan_to_freq - not usedieee80211_freq_to_ofdm_chan - not used
The only two which are used are for 2GHz channels:
ieee80211_dsss_chan_to_freq - atmel, airo, wl3501_cs, orinoco, rndis_wlan ieee80211_freq_to_dsss_chan - atmel, airo, orinoco, zd1201
Anyhow i guess it would make sense to have a common channel to frequency mapping function for mac80211 and other wireless drivers? The problem is now we have to use enum ieee80211_band which is defined cfg80211.h...
Any opinions?
bruno
Johannes Berg
maintainerQuoted 7 lines · Bruno Randolf
Quoted 3 lines
You don't have to use them, but there are a few channel/frequency conversion routines in
include/ieee80211.hwhich could be reused in these functions.Thanks for that info, I didn't know about those functions. I just checked them and it seems most of them are not used, AFAICT:
Quoted 8 lines
ieee80211_fhss_chan_to_freq- not usedieee80211_freq_to_fhss_chan- not usedieee80211_hr_chan_to_freq- not usedieee80211_freq_to_hr_chan- not usedieee80211_erp_chan_to_freq- not usedieee80211_freq_to_erp_chan- not usedieee80211_ofdm_chan_to_freq- not usedieee80211_freq_to_ofdm_chan- not used
Cute -- we should probably just remove these.
Quoted 8 lines
The only two which are used are for 2GHz channels:
ieee80211_dsss_chan_to_freq- atmel, airo,wl3501_cs, orinoco,rndis_wlanieee80211_freq_to_dsss_chan- atmel, airo, orinoco, zd1201Anyhow i guess it would make sense to have a common channel to frequency mapping function for mac80211 and other wireless drivers? The problem is now we have to use enum
ieee80211_bandwhich is definedcfg80211.h...
Well, you're a bit wrong -- the function you're modifying is part of cfg80211. Therefore, including cfg80211.h makes perfect sense, it's also defined in there (therefore, your patch subject should begin with "cfg80211:" instead of "mac80211:").
However, of those drivers you list only orinoco and rndis_wlan already use cfg80211, so for the others using it would introduce an almost "fake" dependency. In any case, it seems like all that should be separate patches.
johannes
Johannes Berg
maintainerQuoted 6 lines · Johannes Berg
Quoted 6 lines
ieee80211_dsss_chan_to_freq- atmel, airo,wl3501_cs, orinoco,rndis_wlanieee80211_freq_to_dsss_chan- atmel, airo, orinoco, zd1201Anyhow i guess it would make sense to have a common channel to frequency mapping function for mac80211 and other wireless drivers? The problem is now we have to use enum
ieee80211_bandwhich is definedcfg80211.h...
Interestingly, I just noticed that the above ones also have different semantics -- they try to round to the nearest channel rather than returning an error if the center frequency isn't exact.
johannes
Quoted 5 lines · Johannes Berg
Quoted 3 lines · Johannes Berg
Quoted 3 lines
ieee80211_dsss_chan_to_freq- atmel, airo,wl3501_cs, orinoco,rndis_wlanieee80211_freq_to_dsss_chan- atmel, airo, orinoco, zd1201
Quoted 7 lines
Quoted 3 lines
Quoted 3 lines
Anyhow i guess it would make sense to have a common channel to frequency mapping function for mac80211 and other wireless drivers? The problem is now we have to use enum
ieee80211_bandwhich is definedcfg80211.h...Interestingly, I just noticed that the above ones also have different semantics -- they try to round to the nearest channel rather than returning an error if the center frequency isn't exact.
I suspect I introduced these functions while refactoring orinoco (well before the cfg80211 conversion). If I recall correctly, there was no specific reason for the round to nearest behaviour - it just seemed more appropriate than rounding down the frequencies. So if it helps, I don't see why we shouldn't modify the behaviour of the ieee80211 functions where necessary.
Dave.