linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
@ 2010-12-24  7:44 Bruno Randolf
  2010-12-24 16:46 ` Dave Kilroy
  2010-12-27 10:57 ` Johannes Berg
  0 siblings, 2 replies; 13+ messages in thread
From: Bruno Randolf @ 2010-12-24  7:44 UTC (permalink / raw)
  To: johannes, linville; +Cc: linux-wireless

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 <br1@einfach.org>
---
 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(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index bcc9f44..cfaac36 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -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
diff --git a/net/mac80211/ibss.c b/net/mac80211/ibss.c
index 53c7077..b9d8df1 100644
--- a/net/mac80211/ibss.c
+++ b/net/mac80211/ibss.c
@@ -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;
 
diff --git a/net/mac80211/mesh.c b/net/mac80211/mesh.c
index ca3af46..1430cdc 100644
--- a/net/mac80211/mesh.c
+++ b/net/mac80211/mesh.c
@@ -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;
 
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 45fbb9e..33bd6d4 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -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;
 
diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c
index fb274db..1ef73be 100644
--- a/net/mac80211/scan.c
+++ b/net/mac80211/scan.c
@@ -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;
 
diff --git a/net/wireless/reg.c b/net/wireless/reg.c
index 99d4183..add7c81 100644
--- a/net/wireless/reg.c
+++ b/net/wireless/reg.c
@@ -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;
 }
diff --git a/net/wireless/util.c b/net/wireless/util.c
index 7620ae2..4ed065d 100644
--- a/net/wireless/util.c
+++ b/net/wireless/util.c
@@ -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);
 
diff --git a/net/wireless/wext-compat.c b/net/wireless/wext-compat.c
index 3e5dbd4..b0e18f0 100644
--- a/net/wireless/wext-compat.c
+++ b/net/wireless/wext-compat.c
@@ -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++)


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-24  7:44 [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j Bruno Randolf
@ 2010-12-24 16:46 ` Dave Kilroy
  2010-12-28  9:43   ` Bruno Randolf
  2010-12-27 10:57 ` Johannes Berg
  1 sibling, 1 reply; 13+ messages in thread
From: Dave Kilroy @ 2010-12-24 16:46 UTC (permalink / raw)
  To: Bruno Randolf; +Cc: johannes, linville, linux-wireless

On Fri, Dec 24, 2010 at 7:44 AM, Bruno Randolf <br1@einfach.org> wrote:
> 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 <br1@einfach.org>
> ---
> -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);

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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-24  7:44 [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j Bruno Randolf
  2010-12-24 16:46 ` Dave Kilroy
@ 2010-12-27 10:57 ` Johannes Berg
  2010-12-28  5:31   ` Bruno Randolf
  1 sibling, 1 reply; 13+ messages in thread
From: Johannes Berg @ 2010-12-27 10:57 UTC (permalink / raw)
  To: Bruno Randolf; +Cc: linville, linux-wireless

On Fri, 2010-12-24 at 16:44 +0900, Bruno Randolf wrote:

>  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;

This seems strange ... why not just hardcode the values??

>  	if (freq->e == 0) {
> +		int band = IEEE80211_BAND_2GHZ;

enum?

johannes


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-27 10:57 ` Johannes Berg
@ 2010-12-28  5:31   ` Bruno Randolf
  2010-12-28  8:38     ` Johannes Berg
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Randolf @ 2010-12-28  5:31 UTC (permalink / raw)
  To: Johannes Berg; +Cc: linville, linux-wireless, mcgrof

On Mon December 27 2010 19:57:39 Johannes Berg wrote:
> On Fri, 2010-12-24 at 16:44 +0900, Bruno Randolf wrote:
> >  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;
> 
> 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.

> >  	if (freq->e == 0) {
> > 
> > +		int band = IEEE80211_BAND_2GHZ;
> 
> enum?

Ok, thanks.

Any other comments on the code or purpose of this patch?

bruno

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  5:31   ` Bruno Randolf
@ 2010-12-28  8:38     ` Johannes Berg
  2010-12-28  9:01       ` Jouni Malinen
  0 siblings, 1 reply; 13+ messages in thread
From: Johannes Berg @ 2010-12-28  8:38 UTC (permalink / raw)
  To: Bruno Randolf; +Cc: linville, linux-wireless, mcgrof

On Tue, 2010-12-28 at 14:31 +0900, Bruno Randolf wrote:

> > > -	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??
> 
> 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.


> 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  8:38     ` Johannes Berg
@ 2010-12-28  9:01       ` Jouni Malinen
  2010-12-28  9:08         ` Johannes Berg
  0 siblings, 1 reply; 13+ messages in thread
From: Jouni Malinen @ 2010-12-28  9:01 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Bruno Randolf, linville, linux-wireless, mcgrof

On Tue, Dec 28, 2010 at 09:38:33AM +0100, Johannes Berg wrote:
> 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.

-- 
Jouni Malinen                                            PGP id EFC895FA

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  9:01       ` Jouni Malinen
@ 2010-12-28  9:08         ` Johannes Berg
  2010-12-28  9:25           ` Jouni Malinen
  0 siblings, 1 reply; 13+ messages in thread
From: Johannes Berg @ 2010-12-28  9:08 UTC (permalink / raw)
  To: Jouni Malinen; +Cc: Bruno Randolf, linville, linux-wireless, mcgrof

On Tue, 2010-12-28 at 11:01 +0200, Jouni Malinen wrote:
> On Tue, Dec 28, 2010 at 09:38:33AM +0100, Johannes Berg wrote:
> > 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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  9:08         ` Johannes Berg
@ 2010-12-28  9:25           ` Jouni Malinen
  2010-12-28  9:39             ` Bruno Randolf
  0 siblings, 1 reply; 13+ messages in thread
From: Jouni Malinen @ 2010-12-28  9:25 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Bruno Randolf, linville, linux-wireless, mcgrof

On Tue, Dec 28, 2010 at 10:08:02AM +0100, Johannes Berg wrote:
> On Tue, 2010-12-28 at 11:01 +0200, Jouni Malinen wrote:
> > 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.

-- 
Jouni Malinen                                            PGP id EFC895FA

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  9:25           ` Jouni Malinen
@ 2010-12-28  9:39             ` Bruno Randolf
  0 siblings, 0 replies; 13+ messages in thread
From: Bruno Randolf @ 2010-12-28  9:39 UTC (permalink / raw)
  To: Jouni Malinen; +Cc: Johannes Berg, linville, linux-wireless, mcgrof

On Tue December 28 2010 18:25:10 Jouni Malinen wrote:
> On Tue, Dec 28, 2010 at 10:08:02AM +0100, Johannes Berg wrote:
> > On Tue, 2010-12-28 at 11:01 +0200, Jouni Malinen wrote:
> > > 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.

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-24 16:46 ` Dave Kilroy
@ 2010-12-28  9:43   ` Bruno Randolf
  2010-12-28  9:51     ` Johannes Berg
  0 siblings, 1 reply; 13+ messages in thread
From: Bruno Randolf @ 2010-12-28  9:43 UTC (permalink / raw)
  To: Dave Kilroy; +Cc: johannes, linville, linux-wireless

On Sat December 25 2010 01:46:00 Dave Kilroy wrote:
> On Fri, Dec 24, 2010 at 7:44 AM, Bruno Randolf <br1@einfach.org> wrote:
> > 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 <br1@einfach.org>
> > ---
> > -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);
> 
> 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.

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 used
ieee80211_freq_to_fhss_chan - not used
ieee80211_hr_chan_to_freq - not used
ieee80211_freq_to_hr_chan - not used
ieee80211_erp_chan_to_freq - not used
ieee80211_freq_to_erp_chan - not used
ieee80211_ofdm_chan_to_freq - not used
ieee80211_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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  9:43   ` Bruno Randolf
@ 2010-12-28  9:51     ` Johannes Berg
  2010-12-28  9:53       ` Johannes Berg
  0 siblings, 1 reply; 13+ messages in thread
From: Johannes Berg @ 2010-12-28  9:51 UTC (permalink / raw)
  To: Bruno Randolf; +Cc: Dave Kilroy, linville, linux-wireless

On Tue, 2010-12-28 at 18:43 +0900, Bruno Randolf wrote:

> > 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.
> 
> 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 used
> ieee80211_freq_to_fhss_chan - not used
> ieee80211_hr_chan_to_freq - not used
> ieee80211_freq_to_hr_chan - not used
> ieee80211_erp_chan_to_freq - not used
> ieee80211_freq_to_erp_chan - not used
> ieee80211_ofdm_chan_to_freq - not used
> ieee80211_freq_to_ofdm_chan - not used

Cute -- we should probably just remove these.

> 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...

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  9:51     ` Johannes Berg
@ 2010-12-28  9:53       ` Johannes Berg
  2010-12-29 13:55         ` Dave Kilroy
  0 siblings, 1 reply; 13+ messages in thread
From: Johannes Berg @ 2010-12-28  9:53 UTC (permalink / raw)
  To: Bruno Randolf; +Cc: Dave Kilroy, linville, linux-wireless

On Tue, 2010-12-28 at 10:51 +0100, Johannes Berg wrote:

> > 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...

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j
  2010-12-28  9:53       ` Johannes Berg
@ 2010-12-29 13:55         ` Dave Kilroy
  0 siblings, 0 replies; 13+ messages in thread
From: Dave Kilroy @ 2010-12-29 13:55 UTC (permalink / raw)
  To: Johannes Berg; +Cc: Bruno Randolf, linville, linux-wireless

On Tue, Dec 28, 2010 at 9:53 AM, Johannes Berg
<johannes@sipsolutions.net> wrote:
> On Tue, 2010-12-28 at 10:51 +0100, Johannes Berg wrote:
>
>> > 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...
>
> 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.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2010-12-29 13:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-24  7:44 [PATCH RFC] mac80211: Extend channel to frequency mapping for 802.11j Bruno Randolf
2010-12-24 16:46 ` Dave Kilroy
2010-12-28  9:43   ` Bruno Randolf
2010-12-28  9:51     ` Johannes Berg
2010-12-28  9:53       ` Johannes Berg
2010-12-29 13:55         ` Dave Kilroy
2010-12-27 10:57 ` Johannes Berg
2010-12-28  5:31   ` Bruno Randolf
2010-12-28  8:38     ` Johannes Berg
2010-12-28  9:01       ` Jouni Malinen
2010-12-28  9:08         ` Johannes Berg
2010-12-28  9:25           ` Jouni Malinen
2010-12-28  9:39             ` Bruno Randolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).