2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: rt2x00 generic configuration routines.
26 #include <linux/kernel.h>
27 #include <linux/module.h>
30 #include "rt2x00lib.h"
32 void rt2x00lib_config_intf(struct rt2x00_dev
*rt2x00dev
,
33 struct rt2x00_intf
*intf
,
34 enum nl80211_iftype type
,
37 struct rt2x00intf_conf conf
;
38 unsigned int flags
= 0;
43 case NL80211_IFTYPE_ADHOC
:
44 case NL80211_IFTYPE_AP
:
45 conf
.sync
= TSF_SYNC_BEACON
;
47 case NL80211_IFTYPE_STATION
:
48 conf
.sync
= TSF_SYNC_INFRA
;
51 conf
.sync
= TSF_SYNC_NONE
;
56 * Note that when NULL is passed as address we will send
57 * 00:00:00:00:00 to the device to clear the address.
58 * This will prevent the device being confused when it wants
59 * to ACK frames or consideres itself associated.
61 memset(&conf
.mac
, 0, sizeof(conf
.mac
));
63 memcpy(&conf
.mac
, mac
, ETH_ALEN
);
65 memset(&conf
.bssid
, 0, sizeof(conf
.bssid
));
67 memcpy(&conf
.bssid
, bssid
, ETH_ALEN
);
69 flags
|= CONFIG_UPDATE_TYPE
;
70 if (mac
|| (!rt2x00dev
->intf_ap_count
&& !rt2x00dev
->intf_sta_count
))
71 flags
|= CONFIG_UPDATE_MAC
;
72 if (bssid
|| (!rt2x00dev
->intf_ap_count
&& !rt2x00dev
->intf_sta_count
))
73 flags
|= CONFIG_UPDATE_BSSID
;
75 rt2x00dev
->ops
->lib
->config_intf(rt2x00dev
, intf
, &conf
, flags
);
78 void rt2x00lib_config_erp(struct rt2x00_dev
*rt2x00dev
,
79 struct rt2x00_intf
*intf
,
80 struct ieee80211_bss_conf
*bss_conf
)
82 struct rt2x00lib_erp erp
;
84 memset(&erp
, 0, sizeof(erp
));
86 erp
.short_preamble
= bss_conf
->use_short_preamble
;
87 erp
.cts_protection
= bss_conf
->use_cts_prot
;
89 erp
.ack_timeout
= PLCP
+ get_duration(ACK_SIZE
, 10);
90 erp
.ack_consume_time
= SIFS
+ PLCP
+ get_duration(ACK_SIZE
, 10);
92 if (rt2x00dev
->hw
->conf
.flags
& IEEE80211_CONF_SHORT_SLOT_TIME
)
93 erp
.ack_timeout
+= SHORT_DIFS
;
95 erp
.ack_timeout
+= DIFS
;
97 if (bss_conf
->use_short_preamble
) {
98 erp
.ack_timeout
+= SHORT_PREAMBLE
;
99 erp
.ack_consume_time
+= SHORT_PREAMBLE
;
101 erp
.ack_timeout
+= PREAMBLE
;
102 erp
.ack_consume_time
+= PREAMBLE
;
105 rt2x00dev
->ops
->lib
->config_erp(rt2x00dev
, &erp
);
108 void rt2x00lib_config_antenna(struct rt2x00_dev
*rt2x00dev
,
109 enum antenna rx
, enum antenna tx
)
111 struct rt2x00lib_conf libconf
;
116 if (rx
== rt2x00dev
->link
.ant
.active
.rx
&&
117 tx
== rt2x00dev
->link
.ant
.active
.tx
)
121 * Antenna setup changes require the RX to be disabled,
122 * else the changes will be ignored by the device.
124 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
125 rt2x00lib_toggle_rx(rt2x00dev
, STATE_RADIO_RX_OFF_LINK
);
128 * Write new antenna setup to device and reset the link tuner.
129 * The latter is required since we need to recalibrate the
130 * noise-sensitivity ratio for the new setup.
132 rt2x00dev
->ops
->lib
->config(rt2x00dev
, &libconf
, CONFIG_UPDATE_ANTENNA
);
133 rt2x00lib_reset_link_tuner(rt2x00dev
);
134 rt2x00_reset_link_ant_rssi(&rt2x00dev
->link
);
136 rt2x00dev
->link
.ant
.active
.rx
= libconf
.ant
.rx
;
137 rt2x00dev
->link
.ant
.active
.tx
= libconf
.ant
.tx
;
139 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
140 rt2x00lib_toggle_rx(rt2x00dev
, STATE_RADIO_RX_ON_LINK
);
143 static u32
rt2x00lib_get_basic_rates(struct ieee80211_supported_band
*band
)
145 const struct rt2x00_rate
*rate
;
149 for (i
= 0; i
< band
->n_bitrates
; i
++) {
150 rate
= rt2x00_get_rate(band
->bitrates
[i
].hw_value
);
151 if (rate
->flags
& DEV_RATE_BASIC
)
152 mask
|= rate
->ratemask
;
158 void rt2x00lib_config(struct rt2x00_dev
*rt2x00dev
,
159 struct ieee80211_conf
*conf
, const int force_config
)
161 struct rt2x00lib_conf libconf
;
162 struct ieee80211_supported_band
*band
;
163 struct antenna_setup
*default_ant
= &rt2x00dev
->default_ant
;
164 struct antenna_setup
*active_ant
= &rt2x00dev
->link
.ant
.active
;
169 * In some situations we want to force all configurations
170 * to be reloaded (When resuming for instance).
173 flags
= CONFIG_UPDATE_ALL
;
178 * Check which configuration options have been
179 * updated and should be send to the device.
181 if (rt2x00dev
->rx_status
.band
!= conf
->channel
->band
)
182 flags
|= CONFIG_UPDATE_PHYMODE
;
183 if (rt2x00dev
->rx_status
.freq
!= conf
->channel
->center_freq
)
184 flags
|= CONFIG_UPDATE_CHANNEL
;
185 if (rt2x00dev
->tx_power
!= conf
->power_level
)
186 flags
|= CONFIG_UPDATE_TXPOWER
;
189 * Determining changes in the antenna setups request several checks:
190 * antenna_sel_{r,t}x = 0
191 * -> Does active_{r,t}x match default_{r,t}x
192 * -> Is default_{r,t}x SW_DIVERSITY
193 * antenna_sel_{r,t}x = 1/2
194 * -> Does active_{r,t}x match antenna_sel_{r,t}x
195 * The reason for not updating the antenna while SW diversity
196 * should be used is simple: Software diversity means that
197 * we should switch between the antenna's based on the
198 * quality. This means that the current antenna is good enough
199 * to work with untill the link tuner decides that an antenna
200 * switch should be performed.
202 if (default_ant
->rx
!= ANTENNA_SW_DIVERSITY
&&
203 default_ant
->rx
!= active_ant
->rx
)
204 flags
|= CONFIG_UPDATE_ANTENNA
;
205 else if (active_ant
->rx
== ANTENNA_SW_DIVERSITY
)
206 flags
|= CONFIG_UPDATE_ANTENNA
;
208 if (default_ant
->tx
!= ANTENNA_SW_DIVERSITY
&&
209 default_ant
->tx
!= active_ant
->tx
)
210 flags
|= CONFIG_UPDATE_ANTENNA
;
211 else if (active_ant
->tx
== ANTENNA_SW_DIVERSITY
)
212 flags
|= CONFIG_UPDATE_ANTENNA
;
215 * The following configuration options are never
216 * stored anywhere and will always be updated.
218 flags
|= CONFIG_UPDATE_SLOT_TIME
;
219 flags
|= CONFIG_UPDATE_BEACON_INT
;
222 * We have determined what options should be updated,
223 * now precalculate device configuration values depending
224 * on what configuration options need to be updated.
227 memset(&libconf
, 0, sizeof(libconf
));
229 if (flags
& CONFIG_UPDATE_PHYMODE
) {
230 band
= &rt2x00dev
->bands
[conf
->channel
->band
];
232 libconf
.band
= conf
->channel
->band
;
233 libconf
.basic_rates
= rt2x00lib_get_basic_rates(band
);
236 if (flags
& CONFIG_UPDATE_CHANNEL
) {
238 &rt2x00dev
->spec
.channels
[conf
->channel
->hw_value
],
241 memcpy(&libconf
.channel
,
242 &rt2x00dev
->spec
.channels_info
[conf
->channel
->hw_value
],
243 sizeof(libconf
.channel
));
246 if (flags
& CONFIG_UPDATE_ANTENNA
) {
247 if (default_ant
->rx
!= ANTENNA_SW_DIVERSITY
)
248 libconf
.ant
.rx
= default_ant
->rx
;
249 else if (active_ant
->rx
== ANTENNA_SW_DIVERSITY
)
250 libconf
.ant
.rx
= ANTENNA_B
;
252 libconf
.ant
.rx
= active_ant
->rx
;
254 if (default_ant
->tx
!= ANTENNA_SW_DIVERSITY
)
255 libconf
.ant
.tx
= default_ant
->tx
;
256 else if (active_ant
->tx
== ANTENNA_SW_DIVERSITY
)
257 libconf
.ant
.tx
= ANTENNA_B
;
259 libconf
.ant
.tx
= active_ant
->tx
;
262 if (flags
& CONFIG_UPDATE_SLOT_TIME
) {
263 short_slot_time
= conf
->flags
& IEEE80211_CONF_SHORT_SLOT_TIME
;
266 short_slot_time
? SHORT_SLOT_TIME
: SLOT_TIME
;
268 libconf
.pifs
= short_slot_time
? SHORT_PIFS
: PIFS
;
269 libconf
.difs
= short_slot_time
? SHORT_DIFS
: DIFS
;
270 libconf
.eifs
= short_slot_time
? SHORT_EIFS
: EIFS
;
276 * Start configuration.
278 rt2x00dev
->ops
->lib
->config(rt2x00dev
, &libconf
, flags
);
281 * Some configuration changes affect the link quality
282 * which means we need to reset the link tuner.
284 if (flags
& (CONFIG_UPDATE_CHANNEL
| CONFIG_UPDATE_ANTENNA
))
285 rt2x00lib_reset_link_tuner(rt2x00dev
);
287 if (flags
& CONFIG_UPDATE_PHYMODE
) {
288 rt2x00dev
->curr_band
= conf
->channel
->band
;
289 rt2x00dev
->rx_status
.band
= conf
->channel
->band
;
292 rt2x00dev
->rx_status
.freq
= conf
->channel
->center_freq
;
293 rt2x00dev
->tx_power
= conf
->power_level
;
295 if (flags
& CONFIG_UPDATE_ANTENNA
) {
296 rt2x00dev
->link
.ant
.active
.rx
= libconf
.ant
.rx
;
297 rt2x00dev
->link
.ant
.active
.tx
= libconf
.ant
.tx
;