3e7e315d11b4569d6af684b8e84b74a94dc0f701
[openwrt/svn-archive/archive.git] / package / madwifi / patches / 414-txpower.patch
1 --- a/net80211/ieee80211.c
2 +++ b/net80211/ieee80211.c
3 @@ -270,6 +270,7 @@ ieee80211_ifattach(struct ieee80211com *
4 ("invalid number of channels specified: %u", ic->ic_nchans));
5 memset(ic->ic_chan_avail, 0, sizeof(ic->ic_chan_avail));
6 ic->ic_modecaps |= 1 << IEEE80211_MODE_AUTO;
7 + ic->ic_max_txpower = IEEE80211_TXPOWER_MIN;
8
9 for (i = 0; i < ic->ic_nchans; i++) {
10 c = &ic->ic_channels[i];
11 @@ -277,6 +278,7 @@ ieee80211_ifattach(struct ieee80211com *
12 KASSERT(c->ic_ieee < IEEE80211_CHAN_MAX,
13 ("channel with bogus ieee number %u", c->ic_ieee));
14 setbit(ic->ic_chan_avail, c->ic_ieee);
15 + ic->ic_max_txpower = max(ic->ic_max_txpower, (u16) c->ic_maxpower * 2);
16
17 if (c->ic_scanflags & IEEE80211_NOSCAN_DEFAULT)
18 c->ic_scanflags |= IEEE80211_NOSCAN_SET;
19 @@ -346,8 +348,6 @@ ieee80211_ifattach(struct ieee80211com *
20 TAILQ_INIT(&ic->ic_vaps);
21
22 ic->ic_txpowlimit = IEEE80211_TXPOWER_MAX;
23 - ic->ic_txpowlimit = IEEE80211_TXPOWER_MIN;
24 - ic->ic_newtxpowlimit = IEEE80211_TXPOWER_MAX;
25
26 init_timer(&ic->ic_dfs_excl_timer);
27 ic->ic_dfs_excl_timer.function =
28 --- a/net80211/ieee80211_node.c
29 +++ b/net80211/ieee80211_node.c
30 @@ -1125,7 +1125,7 @@ ieee80211_alloc_node(struct ieee80211vap
31
32 ni->ni_chan = IEEE80211_CHAN_ANYC;
33 ni->ni_authmode = IEEE80211_AUTH_OPEN;
34 - ni->ni_txpower = ic->ic_txpowlimit;
35 + ni->ni_txpower = IEEE80211_TXPOWER_MAX;
36
37 ieee80211_crypto_resetkey(vap, &ni->ni_ucastkey,
38 IEEE80211_KEYIX_NONE);
39 --- a/net80211/ieee80211_var.h
40 +++ b/net80211/ieee80211_var.h
41 @@ -343,8 +343,9 @@ struct ieee80211com {
42 u_int16_t ic_holdover; /* PM hold over duration */
43 u_int16_t ic_bmissthreshold; /* beacon miss threshold (# beacons) */
44 unsigned long ic_bmiss_guard; /* when to cease ignoring bmiss (jiffies) */
45 - u_int16_t ic_txpowlimit; /* global tx power limit (in 0.5 dBm) */
46 - u_int16_t ic_newtxpowlimit; /* tx power limit to change to (in 0.5 dBm) */
47 + u_int16_t ic_txpowlimit; /* configured global tx power limit (in 0.5 dBm) */
48 + u_int16_t ic_max_txpower; /* global hardware tx power limit */
49 + u_int16_t ic_cur_txpower; /* current tx power */
50 u_int16_t ic_uapsdmaxtriggers; /* max triggers that could arrive */
51 u_int8_t ic_coverageclass; /* coverage class */
52 u_int8_t ic_protmode_rssi; /* rssi threshold for protection mode */
53 --- a/net80211/ieee80211_wireless.c
54 +++ b/net80211/ieee80211_wireless.c
55 @@ -920,17 +920,23 @@ ieee80211_ioctl_giwrange(struct net_devi
56 u_int8_t reported[IEEE80211_CHAN_BYTES]; /* XXX stack usage? */
57 int i, r;
58 int step = 0;
59 + u_int16_t power;
60
61 data->length = sizeof(struct iw_range);
62 memset(range, 0, sizeof(struct iw_range));
63
64 + power = ic->ic_max_txpower;
65 + if (ic->ic_bsschan && (ic->ic_bsschan != IEEE80211_CHAN_ANYC))
66 + power = min(power, ic->ic_bsschan->ic_maxpower);
67 +
68 /* txpower (128 values, but will print out only IW_MAX_TXPOWER) */
69 - range->num_txpower = (ic->ic_txpowlimit >= 8) ? IW_MAX_TXPOWER : ic->ic_txpowlimit;
70 - step = ic->ic_txpowlimit / (2 * (IW_MAX_TXPOWER - 1));
71 + power /= 2; /* Unit: 0.5 dBm */
72 + range->num_txpower = (power >= 8) ? IW_MAX_TXPOWER : power;
73 + step = power / (IW_MAX_TXPOWER - 1);
74
75 range->txpower[0] = 0;
76 for (i = 1; i < IW_MAX_TXPOWER; i++)
77 - range->txpower[i] = (ic->ic_txpowlimit/2)
78 + range->txpower[i] = power
79 - (IW_MAX_TXPOWER - i - 1) * step;
80
81 range->txpower_capa = IW_TXPOW_DBM;
82 @@ -1382,10 +1388,8 @@ ieee80211_ioctl_siwtxpow(struct net_devi
83 disabled = (fixed && vap->iv_bss->ni_txpower == 0);
84 if (rrq->disabled) {
85 if (!disabled) {
86 - if ((ic->ic_caps & IEEE80211_C_TXPMGT) == 0)
87 - return -EOPNOTSUPP;
88 ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
89 - vap->iv_bss->ni_txpower = 0;
90 + ic->ic_txpowlimit = 0;
91 goto done;
92 }
93 return 0;
94 @@ -1396,30 +1400,12 @@ ieee80211_ioctl_siwtxpow(struct net_devi
95 return -EOPNOTSUPP;
96 if (rrq->flags != IW_TXPOW_DBM)
97 return -EINVAL;
98 - if (ic->ic_bsschan != IEEE80211_CHAN_ANYC) {
99 - if ((ic->ic_bsschan->ic_maxregpower >= rrq->value) &&
100 - (ic->ic_txpowlimit/2 >= rrq->value)) {
101 - vap->iv_bss->ni_txpower = 2 * rrq->value;
102 - ic->ic_newtxpowlimit = 2 * rrq->value;
103 - ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
104 - } else
105 - return -EINVAL;
106 - } else {
107 - /*
108 - * No channel set yet
109 - */
110 - if (ic->ic_txpowlimit/2 >= rrq->value) {
111 - vap->iv_bss->ni_txpower = 2 * rrq->value;
112 - ic->ic_newtxpowlimit = 2 * rrq->value;
113 - ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
114 - }
115 - else
116 - return -EINVAL;
117 - }
118 + ic->ic_txpowlimit = 2 * rrq->value;
119 + ic->ic_flags |= IEEE80211_F_TXPOW_FIXED;
120 } else {
121 if (!fixed) /* no change */
122 return 0;
123 - ic->ic_newtxpowlimit = IEEE80211_TXPOWER_MAX;
124 + ic->ic_txpowlimit = IEEE80211_TXPOWER_MAX;
125 ic->ic_flags &= ~IEEE80211_F_TXPOW_FIXED;
126 }
127 done:
128 @@ -1588,9 +1574,22 @@ ieee80211_ioctl_giwtxpow(struct net_devi
129 {
130 struct ieee80211vap *vap = dev->priv;
131 struct ieee80211com *ic = vap->iv_ic;
132 -
133 - rrq->value = vap->iv_bss->ni_txpower / 2;
134 - rrq->fixed = (ic->ic_flags & IEEE80211_F_TXPOW_FIXED) != 0;
135 + unsigned int power = ic->ic_txpowlimit;
136 + struct ieee80211_channel *c;
137 + u_int16_t txp = ic->ic_max_txpower;
138 +
139 + if (ic->ic_bsschan && (ic->ic_bsschan != IEEE80211_CHAN_ANYC))
140 + txp = min(txp, ic->ic_bsschan->ic_maxpower);
141 + } else if (ic->ic_cur_txpower > 0) {
142 + txp = min(txp, ic->ic_cur_txpower);
143 + }
144 + if (ic->ic_flags & IEEE80211_F_TXPOW_FIXED) {
145 + txp = min(txp, ic->ic_txpowlimit);
146 + rrq->fixed = 1;
147 + } else {
148 + rrq->fixed = 0;
149 + }
150 + rrq->value = txp / 2;
151 rrq->disabled = (rrq->fixed && rrq->value == 0);
152 rrq->flags = IW_TXPOW_DBM;
153 return 0;
154 --- a/ath/if_ath.c
155 +++ b/ath/if_ath.c
156 @@ -380,7 +380,6 @@ static unsigned int ath_dump_hal_map(str
157 static u_int32_t ath_get_clamped_maxtxpower(struct ath_softc *sc);
158 static u_int32_t ath_set_clamped_maxtxpower(struct ath_softc *sc,
159 u_int32_t new_clamped_maxtxpower);
160 -static u_int32_t ath_get_real_maxtxpower(struct ath_softc *sc);
161
162 static void ath_poll_disable(struct net_device *dev);
163 static void ath_poll_enable(struct net_device *dev);
164 @@ -3159,7 +3158,7 @@ ath_tx_startraw(struct net_device *dev,
165 try0 = ph->try0;
166 rt = sc->sc_currates;
167 txrate = dot11_to_ratecode(sc, rt, ph->rate0);
168 - power = ph->power > 60 ? 60 : ph->power;
169 + power = ph->power > 63 ? 63 : ph->power;
170 hdrlen = ieee80211_anyhdrsize(wh);
171 pktlen = skb->len + IEEE80211_CRC_LEN;
172
173 @@ -8381,7 +8380,7 @@ ath_tx_start(struct net_device *dev, str
174 pktlen, /* packet length */
175 hdrlen, /* header length */
176 atype, /* Atheros packet type */
177 - MIN(ni->ni_txpower, 60), /* txpower */
178 + MIN(ni->ni_txpower, 63), /* txpower */
179 txrate, try0, /* series 0 rate/tries */
180 keyix, /* key cache index */
181 antenna, /* antenna mode */
182 @@ -10364,59 +10363,16 @@ ath_get_clamped_maxtxpower(struct ath_so
183
184 /* XXX: this function needs some locking to avoid being called
185 * twice/interrupted */
186 -/* 1. Save the currently specified maximum txpower (as clamped by madwifi)
187 - * 2. Determine the real maximum txpower the card can support by
188 - * setting a value that exceeds the maximum range (by one) and
189 - * finding out what it limits us to.
190 - * 3. Restore the saved maxtxpower value we had previously specified */
191 -static u_int32_t
192 -ath_get_real_maxtxpower(struct ath_softc *sc)
193 -{
194 - u_int32_t saved_clamped_maxtxpower;
195 - u_int32_t real_maxtxpower;
196 -
197 - saved_clamped_maxtxpower = ath_get_clamped_maxtxpower(sc);
198 - real_maxtxpower =
199 - ath_set_clamped_maxtxpower(sc, IEEE80211_TXPOWER_MAX + 1);
200 - ath_set_clamped_maxtxpower(sc, saved_clamped_maxtxpower);
201 - return real_maxtxpower;
202 -}
203 -
204 -
205 -/* XXX: this function needs some locking to avoid being called
206 - * twice/interrupted */
207 static void
208 ath_update_txpow(struct ath_softc *sc)
209 {
210 struct ieee80211com *ic = &sc->sc_ic;
211 struct ieee80211vap *vap = NULL;
212 struct ath_hal *ah = sc->sc_ah;
213 - u_int32_t prev_clamped_maxtxpower = 0;
214 - u_int32_t new_clamped_maxtxpower = 0;
215
216 /* Determine the previous value of maxtxpower */
217 - prev_clamped_maxtxpower = ath_get_clamped_maxtxpower(sc);
218 - /* Determine the real maximum txpower the card can support */
219 - ic->ic_txpowlimit = ath_get_real_maxtxpower(sc);
220 - /* Grab the new maxtxpower setting (which may have changed) */
221 - new_clamped_maxtxpower = ic->ic_newtxpowlimit;
222 - /* Make sure the change is within limits, clamp it otherwise */
223 - if (ic->ic_newtxpowlimit > ic->ic_txpowlimit)
224 - new_clamped_maxtxpower = ic->ic_txpowlimit;
225 - /* Search for the VAP that needs a txpow change, if any */
226 - TAILQ_FOREACH(vap, &ic->ic_vaps, iv_next) {
227 - if (!tpc || ic->ic_newtxpowlimit != vap->iv_bss->ni_txpower) {
228 - vap->iv_bss->ni_txpower = new_clamped_maxtxpower;
229 - ieee80211_iterate_nodes(&vap->iv_ic->ic_sta,
230 - set_node_txpower,
231 - &new_clamped_maxtxpower);
232 - }
233 - }
234 -
235 - /* Store the assigned (clamped) maximum txpower and update the HAL */
236 - sc->sc_curtxpow = new_clamped_maxtxpower;
237 - if (new_clamped_maxtxpower != prev_clamped_maxtxpower)
238 - ath_hal_settxpowlimit(ah, new_clamped_maxtxpower);
239 + ath_set_clamped_maxtxpower(sc, ic->ic_txpowlimit);
240 + ic->ic_cur_txpower = ath_get_clamped_maxtxpower(sc);
241 }
242
243 #ifdef ATH_SUPERG_XR