mac80211: update to wireless-testing 2013-02-22
[openwrt/staging/chunkeey.git] / package / mac80211 / patches / 523-mac80211_configure_antenna_gain.patch
1 --- a/include/net/mac80211.h
2 +++ b/include/net/mac80211.h
3 @@ -978,6 +978,7 @@ enum ieee80211_smps_mode {
4 *
5 * @power_level: requested transmit power (in dBm), backward compatibility
6 * value only that is set to the minimum of all interfaces
7 + * @max_antenna_gain: maximum antenna gain adjusted by user config (in dBi)
8 *
9 * @channel: the channel to tune to
10 * @channel_type: the channel (HT) type
11 @@ -1000,6 +1001,7 @@ struct ieee80211_conf {
12 u32 flags;
13 int power_level, dynamic_ps_timeout;
14 int max_sleep_period;
15 + int max_antenna_gain;
16
17 u16 listen_interval;
18 u8 ps_dtim_period;
19 --- a/net/mac80211/ieee80211_i.h
20 +++ b/net/mac80211/ieee80211_i.h
21 @@ -1116,6 +1116,7 @@ struct ieee80211_local {
22 int dynamic_ps_forced_timeout;
23
24 int user_power_level; /* in dBm, for all interfaces */
25 + int user_antenna_gain; /* in dBi */
26
27 enum ieee80211_smps_mode smps_mode;
28
29 --- a/include/uapi/linux/nl80211.h
30 +++ b/include/uapi/linux/nl80211.h
31 @@ -1654,6 +1654,8 @@ enum nl80211_attrs {
32 NL80211_ATTR_STA_CAPABILITY,
33 NL80211_ATTR_STA_EXT_CAPABILITY,
34
35 + NL80211_ATTR_WIPHY_ANTENNA_GAIN,
36 +
37 /* add attributes here, update the policy in nl80211.c */
38
39 __NL80211_ATTR_AFTER_LAST,
40 --- a/net/wireless/nl80211.c
41 +++ b/net/wireless/nl80211.c
42 @@ -370,6 +370,7 @@ static const struct nla_policy nl80211_p
43 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
44 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
45 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
46 + [NL80211_ATTR_WIPHY_ANTENNA_GAIN] = { .type = NLA_U32 },
47 };
48
49 /* policy for the key attributes */
50 @@ -1706,6 +1707,22 @@ static int nl80211_set_wiphy(struct sk_b
51 goto bad_res;
52 }
53
54 + if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_GAIN]) {
55 + int idx, dbi = 0;
56 +
57 + if (!rdev->ops->set_antenna_gain) {
58 + result = -EOPNOTSUPP;
59 + goto bad_res;
60 + }
61 +
62 + idx = NL80211_ATTR_WIPHY_ANTENNA_GAIN;
63 + dbi = nla_get_u32(info->attrs[idx]);
64 +
65 + result = rdev->ops->set_antenna_gain(&rdev->wiphy, dbi);
66 + if (result)
67 + goto bad_res;
68 + }
69 +
70 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
71 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
72 u32 tx_ant, rx_ant;
73 --- a/net/mac80211/cfg.c
74 +++ b/net/mac80211/cfg.c
75 @@ -2212,6 +2212,19 @@ static int ieee80211_get_tx_power(struct
76 return 0;
77 }
78
79 +static int ieee80211_set_antenna_gain(struct wiphy *wiphy, int dbi)
80 +{
81 + struct ieee80211_local *local = wiphy_priv(wiphy);
82 +
83 + if (dbi < 0)
84 + return -EINVAL;
85 +
86 + local->user_antenna_gain = dbi;
87 + ieee80211_hw_config(local, 0);
88 +
89 + return 0;
90 +}
91 +
92 static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
93 const u8 *addr)
94 {
95 @@ -3369,6 +3382,7 @@ struct cfg80211_ops mac80211_config_ops
96 .set_wiphy_params = ieee80211_set_wiphy_params,
97 .set_tx_power = ieee80211_set_tx_power,
98 .get_tx_power = ieee80211_get_tx_power,
99 + .set_antenna_gain = ieee80211_set_antenna_gain,
100 .set_wds_peer = ieee80211_set_wds_peer,
101 .rfkill_poll = ieee80211_rfkill_poll,
102 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
103 --- a/include/net/cfg80211.h
104 +++ b/include/net/cfg80211.h
105 @@ -1862,6 +1862,7 @@ struct cfg80211_gtk_rekey_data {
106 * (as advertised by the nl80211 feature flag.)
107 * @get_tx_power: store the current TX power into the dbm variable;
108 * return 0 if successful
109 + * @set_antenna_gain: set antenna gain to reduce maximum tx power if necessary
110 *
111 * @set_wds_peer: set the WDS peer for a WDS interface
112 *
113 @@ -2071,6 +2072,7 @@ struct cfg80211_ops {
114 enum nl80211_tx_power_setting type, int mbm);
115 int (*get_tx_power)(struct wiphy *wiphy, struct wireless_dev *wdev,
116 int *dbm);
117 + int (*set_antenna_gain)(struct wiphy *wiphy, int dbi);
118
119 int (*set_wds_peer)(struct wiphy *wiphy, struct net_device *dev,
120 const u8 *addr);
121 --- a/net/mac80211/main.c
122 +++ b/net/mac80211/main.c
123 @@ -101,7 +101,7 @@ static u32 ieee80211_hw_conf_chan(struct
124 struct ieee80211_sub_if_data *sdata;
125 struct ieee80211_channel *chan;
126 u32 changed = 0;
127 - int power;
128 + int power, ant_gain, max_power;
129 enum nl80211_channel_type channel_type;
130 u32 offchannel_flag;
131 bool scanning = false;
132 @@ -164,8 +164,21 @@ static u32 ieee80211_hw_conf_chan(struct
133 }
134 rcu_read_unlock();
135
136 - if (local->hw.conf.power_level != power) {
137 + max_power = chan->max_reg_power;
138 + ant_gain = chan->max_antenna_gain;
139 + if (local->user_antenna_gain > 0) {
140 + if (local->user_antenna_gain > ant_gain) {
141 + max_power -= local->user_antenna_gain - ant_gain;
142 + ant_gain = 0;
143 + } else
144 + ant_gain -= local->user_antenna_gain;
145 + power = min(power, max_power);
146 + }
147 +
148 + if (local->hw.conf.power_level != power ||
149 + local->hw.conf.max_antenna_gain != ant_gain) {
150 changed |= IEEE80211_CONF_CHANGE_POWER;
151 + local->hw.conf.max_antenna_gain = ant_gain;
152 local->hw.cur_power_level = power;
153 local->hw.conf.power_level = power;
154 }
155 @@ -612,6 +625,7 @@ struct ieee80211_hw *ieee80211_alloc_hw(
156 IEEE80211_RADIOTAP_MCS_HAVE_BW;
157 local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
158 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
159 + local->user_antenna_gain = 0;
160 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
161 wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
162