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
.slot_time
= bss_conf
->use_short_slot
? SHORT_SLOT_TIME
: SLOT_TIME
;
91 erp
.pifs
= bss_conf
->use_short_slot
? SHORT_PIFS
: PIFS
;
92 erp
.difs
= bss_conf
->use_short_slot
? SHORT_DIFS
: DIFS
;
93 erp
.eifs
= bss_conf
->use_short_slot
? SHORT_EIFS
: EIFS
;
95 erp
.ack_timeout
= PLCP
+ erp
.difs
+ GET_DURATION(ACK_SIZE
, 10);
96 erp
.ack_consume_time
= SIFS
+ PLCP
+ GET_DURATION(ACK_SIZE
, 10);
98 if (bss_conf
->use_short_preamble
) {
99 erp
.ack_timeout
+= SHORT_PREAMBLE
;
100 erp
.ack_consume_time
+= SHORT_PREAMBLE
;
102 erp
.ack_timeout
+= PREAMBLE
;
103 erp
.ack_consume_time
+= PREAMBLE
;
106 erp
.basic_rates
= bss_conf
->basic_rates
;
108 rt2x00dev
->ops
->lib
->config_erp(rt2x00dev
, &erp
);
111 void rt2x00lib_config_antenna(struct rt2x00_dev
*rt2x00dev
,
112 struct antenna_setup
*ant
)
115 * Failsafe: Make sure we are not sending the
116 * ANTENNA_SW_DIVERSITY state to the driver.
117 * If that happes fallback to hardware default,
118 * or our own default.
120 if (ant
->rx
== ANTENNA_SW_DIVERSITY
) {
121 if (rt2x00dev
->default_ant
.rx
== ANTENNA_SW_DIVERSITY
)
124 ant
->rx
= rt2x00dev
->default_ant
.rx
;
126 if (ant
->tx
== ANTENNA_SW_DIVERSITY
) {
127 if (rt2x00dev
->default_ant
.tx
== ANTENNA_SW_DIVERSITY
)
130 ant
->tx
= rt2x00dev
->default_ant
.tx
;
134 * Only reconfigure when something has changed.
136 if (ant
->rx
== rt2x00dev
->link
.ant
.active
.rx
&&
137 ant
->tx
== rt2x00dev
->link
.ant
.active
.tx
)
141 * Antenna setup changes require the RX to be disabled,
142 * else the changes will be ignored by the device.
144 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
145 rt2x00lib_toggle_rx(rt2x00dev
, STATE_RADIO_RX_OFF_LINK
);
148 * Write new antenna setup to device and reset the link tuner.
149 * The latter is required since we need to recalibrate the
150 * noise-sensitivity ratio for the new setup.
152 rt2x00dev
->ops
->lib
->config_ant(rt2x00dev
, ant
);
154 rt2x00lib_reset_link_tuner(rt2x00dev
);
155 rt2x00_reset_link_ant_rssi(&rt2x00dev
->link
);
157 memcpy(&rt2x00dev
->link
.ant
.active
, ant
, sizeof(*ant
));
159 if (test_bit(DEVICE_STATE_ENABLED_RADIO
, &rt2x00dev
->flags
))
160 rt2x00lib_toggle_rx(rt2x00dev
, STATE_RADIO_RX_ON_LINK
);
163 void rt2x00lib_config(struct rt2x00_dev
*rt2x00dev
,
164 struct ieee80211_conf
*conf
,
165 unsigned int ieee80211_flags
)
167 struct rt2x00lib_conf libconf
;
169 memset(&libconf
, 0, sizeof(libconf
));
173 if (ieee80211_flags
& IEEE80211_CONF_CHANGE_CHANNEL
) {
175 &rt2x00dev
->spec
.channels
[conf
->channel
->hw_value
],
178 memcpy(&libconf
.channel
,
179 &rt2x00dev
->spec
.channels_info
[conf
->channel
->hw_value
],
180 sizeof(libconf
.channel
));
184 * Start configuration.
186 rt2x00dev
->ops
->lib
->config(rt2x00dev
, &libconf
, ieee80211_flags
);
189 * Some configuration changes affect the link quality
190 * which means we need to reset the link tuner.
192 if (ieee80211_flags
& IEEE80211_CONF_CHANGE_CHANNEL
)
193 rt2x00lib_reset_link_tuner(rt2x00dev
);
195 rt2x00dev
->curr_band
= conf
->channel
->band
;
196 rt2x00dev
->tx_power
= conf
->power_level
;
197 rt2x00dev
->short_retry
= conf
->short_frame_max_tx_count
;
198 rt2x00dev
->long_retry
= conf
->long_frame_max_tx_count
;
200 rt2x00dev
->rx_status
.band
= conf
->channel
->band
;
201 rt2x00dev
->rx_status
.freq
= conf
->channel
->center_freq
;