Linux wireless drivers development
 help / color / mirror / Atom feed
From: Simon Wunderlich <simon.wunderlich@s2003.tu-chemnitz.de>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org,
	Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>,
	Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Subject: [PATCHv6 07/18] cfg80211/mac80211: use reduced txpower for 5 and 10 MHz
Date: Mon,  8 Jul 2013 16:55:55 +0200	[thread overview]
Message-ID: <1373295366-12823-8-git-send-email-siwu@hrz.tu-chemnitz.de> (raw)
In-Reply-To: <1373295366-12823-1-git-send-email-siwu@hrz.tu-chemnitz.de>

Some regulations (like germany, but also FCC) express their transmission
power limit in dBm/MHz or mW/MHz. To cope with that and be on the safe
side, reduce the maximum power to half (10 MHz) or quarter (5 MHz)
when operating on these reduced bandwidth channels.

Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
Signed-off-by: Mathias Kretschmer <mathias.kretschmer@fokus.fraunhofer.de>

---
Changes to PATCHv3:
 * consider max_reg_power, max_power might contain the hardware limit
---
 include/net/cfg80211.h |   27 +++++++++++++++++++++++++++
 net/mac80211/iface.c   |    2 +-
 net/mac80211/main.c    |    2 +-
 net/mac80211/mlme.c    |    3 ++-
 4 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h
index 4ca16ab..75471ee 100644
--- a/include/net/cfg80211.h
+++ b/include/net/cfg80211.h
@@ -461,6 +461,33 @@ ieee80211_chandef_rate_flags(struct cfg80211_chan_def *chandef)
 }
 
 /**
+ * ieee80211_chandef_max_power - maximum transmission power for the chandef
+ *
+ * In some regulations, the transmit power may depend on the configured channel
+ * bandwidth which may be defined as dBm/MHz. This function returns the actual
+ * max_power for non-standard (20 MHz) channels.
+ *
+ * @chandef: channel definition for the channel
+ *
+ * Returns: maximum allowed transmission power in dBm for the chandef
+ */
+static inline int
+ieee80211_chandef_max_power(struct cfg80211_chan_def *chandef)
+{
+	switch (chandef->width) {
+	case NL80211_CHAN_WIDTH_5:
+		return min(chandef->chan->max_reg_power - 6,
+			   chandef->chan->max_power);
+	case NL80211_CHAN_WIDTH_10:
+		return min(chandef->chan->max_reg_power - 3,
+			   chandef->chan->max_power);
+	default:
+		break;
+	}
+	return chandef->chan->max_power;
+}
+
+/**
  * enum survey_info_flags - survey information flags
  *
  * @SURVEY_INFO_NOISE_DBM: noise (in dBm) was filled in
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index a2a8250..093c34a 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -54,7 +54,7 @@ bool __ieee80211_recalc_txpower(struct ieee80211_sub_if_data *sdata)
 		return false;
 	}
 
-	power = chanctx_conf->def.chan->max_power;
+	power = ieee80211_chandef_max_power(&chanctx_conf->def);
 	rcu_read_unlock();
 
 	if (sdata->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index 626c83c..a1d51af 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -151,7 +151,7 @@ static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
 		changed |= IEEE80211_CONF_CHANGE_SMPS;
 	}
 
-	power = chandef.chan->max_power;
+	power = ieee80211_chandef_max_power(&chandef);
 
 	rcu_read_lock();
 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index f7552c2..211246b 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -747,7 +747,8 @@ static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
 		*pos++ = WLAN_EID_PWR_CAPABILITY;
 		*pos++ = 2;
 		*pos++ = 0; /* min tx power */
-		*pos++ = chan->max_power; /* max tx power */
+		 /* max tx power */
+		*pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
 
 		/* 2. supported channels */
 		/* TODO: get this in reg domain format */
-- 
1.7.10.4


  parent reply	other threads:[~2013-07-08 14:56 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-08 14:55 [PATCHv6 00/18] Add support for 5 and 10 MHz channels Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 01/18] nl80211: add scan width to bss and scan request structs Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 02/18] mac80211/rc80211: add chandef to rate initialization Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 03/18] mac80211: fix timing for 5 MHz and 10 MHz channels Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 04/18] mac80211: add radiotap flag and handling for 5/10 MHz Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 05/18] mac80211: select and adjust bitrates according to channel mode Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 06/18] cfg80211/mac80211: get mandatory rates based on scan width Simon Wunderlich
2013-07-08 14:55 ` Simon Wunderlich [this message]
2013-07-08 14:55 ` [PATCHv6 08/18] mac80211: allow scanning for 5/10 MHz channels in IBSS Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 09/18] mac80211: return if IBSS chandef can not be used Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 10/18] nl80211: allow 5 and 10 MHz channels for IBSS Simon Wunderlich
2013-07-08 14:55 ` [PATCHv6 11/18] ath9k: always use SIFS times from OFDM for 5/10 MHz Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 12/18] ath9k: use chandef instead of channel_type Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 13/18] ath9k: report 5/10 MHz channels Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 14/18] ath9k: set 5/10 MHz supported channels and fix bitrate Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 15/18] ath9k: announce that ath9k supports 5/10 MHz Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 16/18] ath5k: report 5/10 MHz channels Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 17/18] ath5k: set 5/10 MHz supported channels and fix duration Simon Wunderlich
2013-07-08 14:56 ` [PATCHv6 18/18] ath5k: enable support for 5 MHz and 10 MHz channels Simon Wunderlich
2013-07-09 15:08 ` [PATCHv6 00/18] Add support for 5 " Johannes Berg
2013-07-09 15:29   ` Simon Wunderlich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373295366-12823-8-git-send-email-siwu@hrz.tu-chemnitz.de \
    --to=simon.wunderlich@s2003.tu-chemnitz.de \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mathias.kretschmer@fokus.fraunhofer.de \
    --cc=siwu@hrz.tu-chemnitz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox