]>
Commit | Line | Data |
---|---|---|
95ea3627 | 1 | /* |
9c9a0d14 | 2 | Copyright (C) 2004 - 2009 Ivo van Doorn <IvDoorn@gmail.com> |
95ea3627 ID |
3 | <http://rt2x00.serialmonkey.com> |
4 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
19 | */ | |
20 | ||
21 | /* | |
22 | Module: rt2x00lib | |
23 | Abstract: rt2x00 generic configuration routines. | |
24 | */ | |
25 | ||
95ea3627 ID |
26 | #include <linux/kernel.h> |
27 | #include <linux/module.h> | |
28 | ||
29 | #include "rt2x00.h" | |
30 | #include "rt2x00lib.h" | |
31 | ||
6bb40dd1 ID |
32 | void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev, |
33 | struct rt2x00_intf *intf, | |
05c914fe | 34 | enum nl80211_iftype type, |
5f936f11 | 35 | const u8 *mac, const u8 *bssid) |
95ea3627 | 36 | { |
6bb40dd1 ID |
37 | struct rt2x00intf_conf conf; |
38 | unsigned int flags = 0; | |
95ea3627 | 39 | |
6bb40dd1 | 40 | conf.type = type; |
feb24691 ID |
41 | |
42 | switch (type) { | |
05c914fe | 43 | case NL80211_IFTYPE_ADHOC: |
ab8966dd HS |
44 | conf.sync = TSF_SYNC_ADHOC; |
45 | break; | |
05c914fe | 46 | case NL80211_IFTYPE_AP: |
a07dbea2 | 47 | case NL80211_IFTYPE_MESH_POINT: |
ce292a64 | 48 | case NL80211_IFTYPE_WDS: |
ab8966dd | 49 | conf.sync = TSF_SYNC_AP_NONE; |
feb24691 | 50 | break; |
05c914fe | 51 | case NL80211_IFTYPE_STATION: |
6bb40dd1 | 52 | conf.sync = TSF_SYNC_INFRA; |
feb24691 ID |
53 | break; |
54 | default: | |
6bb40dd1 | 55 | conf.sync = TSF_SYNC_NONE; |
feb24691 ID |
56 | break; |
57 | } | |
58 | ||
6bb40dd1 ID |
59 | /* |
60 | * Note that when NULL is passed as address we will send | |
61 | * 00:00:00:00:00 to the device to clear the address. | |
62 | * This will prevent the device being confused when it wants | |
25985edc | 63 | * to ACK frames or considers itself associated. |
6bb40dd1 | 64 | */ |
736e3aca | 65 | memset(conf.mac, 0, sizeof(conf.mac)); |
6bb40dd1 | 66 | if (mac) |
736e3aca | 67 | memcpy(conf.mac, mac, ETH_ALEN); |
6bb40dd1 | 68 | |
736e3aca | 69 | memset(conf.bssid, 0, sizeof(conf.bssid)); |
6bb40dd1 | 70 | if (bssid) |
736e3aca | 71 | memcpy(conf.bssid, bssid, ETH_ALEN); |
6bb40dd1 ID |
72 | |
73 | flags |= CONFIG_UPDATE_TYPE; | |
74 | if (mac || (!rt2x00dev->intf_ap_count && !rt2x00dev->intf_sta_count)) | |
75 | flags |= CONFIG_UPDATE_MAC; | |
76 | if (bssid || (!rt2x00dev->intf_ap_count && !rt2x00dev->intf_sta_count)) | |
77 | flags |= CONFIG_UPDATE_BSSID; | |
78 | ||
79 | rt2x00dev->ops->lib->config_intf(rt2x00dev, intf, &conf, flags); | |
80 | } | |
81 | ||
72810379 ID |
82 | void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev, |
83 | struct rt2x00_intf *intf, | |
02044643 HS |
84 | struct ieee80211_bss_conf *bss_conf, |
85 | u32 changed) | |
6bb40dd1 | 86 | { |
72810379 | 87 | struct rt2x00lib_erp erp; |
6bb40dd1 | 88 | |
72810379 ID |
89 | memset(&erp, 0, sizeof(erp)); |
90 | ||
91 | erp.short_preamble = bss_conf->use_short_preamble; | |
e360c4cb ID |
92 | erp.cts_protection = bss_conf->use_cts_prot; |
93 | ||
e4ea1c40 ID |
94 | erp.slot_time = bss_conf->use_short_slot ? SHORT_SLOT_TIME : SLOT_TIME; |
95 | erp.sifs = SIFS; | |
96 | erp.pifs = bss_conf->use_short_slot ? SHORT_PIFS : PIFS; | |
97 | erp.difs = bss_conf->use_short_slot ? SHORT_DIFS : DIFS; | |
98 | erp.eifs = bss_conf->use_short_slot ? SHORT_EIFS : EIFS; | |
6bb40dd1 | 99 | |
e4ea1c40 | 100 | erp.basic_rates = bss_conf->basic_rates; |
8a566afe | 101 | erp.beacon_int = bss_conf->beacon_int; |
e4ea1c40 | 102 | |
6b347bff ID |
103 | /* Update global beacon interval time, this is needed for PS support */ |
104 | rt2x00dev->beacon_int = bss_conf->beacon_int; | |
105 | ||
87c1915d HS |
106 | if (changed & BSS_CHANGED_HT) |
107 | erp.ht_opmode = bss_conf->ht_operation_mode; | |
108 | ||
02044643 | 109 | rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp, changed); |
95ea3627 ID |
110 | } |
111 | ||
0b927a07 ID |
112 | static inline |
113 | enum antenna rt2x00lib_config_antenna_check(enum antenna current_ant, | |
114 | enum antenna default_ant) | |
115 | { | |
116 | if (current_ant != ANTENNA_SW_DIVERSITY) | |
117 | return current_ant; | |
118 | return (default_ant != ANTENNA_SW_DIVERSITY) ? default_ant : ANTENNA_B; | |
119 | } | |
120 | ||
69f81a2c | 121 | void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev, |
bdfa500b | 122 | struct antenna_setup config) |
69f81a2c | 123 | { |
bdfa500b | 124 | struct link_ant *ant = &rt2x00dev->link.ant; |
0b927a07 ID |
125 | struct antenna_setup *def = &rt2x00dev->default_ant; |
126 | struct antenna_setup *active = &rt2x00dev->link.ant.active; | |
127 | ||
6d64360a ID |
128 | /* |
129 | * Failsafe: Make sure we are not sending the | |
130 | * ANTENNA_SW_DIVERSITY state to the driver. | |
49513481 | 131 | * If that happens, fallback to hardware defaults, |
6d64360a ID |
132 | * or our own default. |
133 | */ | |
bdfa500b ID |
134 | if (!(ant->flags & ANTENNA_RX_DIVERSITY)) |
135 | config.rx = rt2x00lib_config_antenna_check(config.rx, def->rx); | |
8a239033 | 136 | else if (config.rx == ANTENNA_SW_DIVERSITY) |
bdfa500b | 137 | config.rx = active->rx; |
69f81a2c | 138 | |
bdfa500b ID |
139 | if (!(ant->flags & ANTENNA_TX_DIVERSITY)) |
140 | config.tx = rt2x00lib_config_antenna_check(config.tx, def->tx); | |
85f4d648 | 141 | else if (config.tx == ANTENNA_SW_DIVERSITY) |
bdfa500b ID |
142 | config.tx = active->tx; |
143 | ||
e25c4bb9 ID |
144 | /* |
145 | * Antenna setup changes require the RX to be disabled, | |
146 | * else the changes will be ignored by the device. | |
147 | */ | |
0262ab0d | 148 | if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) |
0b7fde54 | 149 | rt2x00queue_stop_queue(rt2x00dev->rx); |
e25c4bb9 | 150 | |
69f81a2c ID |
151 | /* |
152 | * Write new antenna setup to device and reset the link tuner. | |
153 | * The latter is required since we need to recalibrate the | |
154 | * noise-sensitivity ratio for the new setup. | |
155 | */ | |
bdfa500b | 156 | rt2x00dev->ops->lib->config_ant(rt2x00dev, &config); |
e4ea1c40 | 157 | |
84e3196f | 158 | rt2x00link_reset_tuner(rt2x00dev, true); |
69f81a2c | 159 | |
bdfa500b | 160 | memcpy(active, &config, sizeof(config)); |
e25c4bb9 | 161 | |
0262ab0d | 162 | if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags)) |
0b7fde54 | 163 | rt2x00queue_start_queue(rt2x00dev->rx); |
69f81a2c ID |
164 | } |
165 | ||
066cb637 | 166 | void rt2x00lib_config(struct rt2x00_dev *rt2x00dev, |
e4ea1c40 ID |
167 | struct ieee80211_conf *conf, |
168 | unsigned int ieee80211_flags) | |
95ea3627 | 169 | { |
5c58ee51 | 170 | struct rt2x00lib_conf libconf; |
06443e46 | 171 | u16 hw_value; |
95ea3627 | 172 | |
5c58ee51 ID |
173 | memset(&libconf, 0, sizeof(libconf)); |
174 | ||
e4ea1c40 | 175 | libconf.conf = conf; |
5c58ee51 | 176 | |
e4ea1c40 | 177 | if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) { |
06443e46 | 178 | if (conf_is_ht40(conf)) { |
35f00cfc | 179 | __set_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags); |
06443e46 GW |
180 | hw_value = rt2x00ht_center_channel(rt2x00dev, conf); |
181 | } else { | |
35f00cfc | 182 | __clear_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags); |
06443e46 GW |
183 | hw_value = conf->channel->hw_value; |
184 | } | |
35f00cfc | 185 | |
5c58ee51 | 186 | memcpy(&libconf.rf, |
06443e46 | 187 | &rt2x00dev->spec.channels[hw_value], |
5c58ee51 | 188 | sizeof(libconf.rf)); |
8c5e7a5f ID |
189 | |
190 | memcpy(&libconf.channel, | |
06443e46 | 191 | &rt2x00dev->spec.channels_info[hw_value], |
8c5e7a5f | 192 | sizeof(libconf.channel)); |
5c58ee51 ID |
193 | } |
194 | ||
5c58ee51 ID |
195 | /* |
196 | * Start configuration. | |
197 | */ | |
e4ea1c40 | 198 | rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags); |
95ea3627 ID |
199 | |
200 | /* | |
201 | * Some configuration changes affect the link quality | |
202 | * which means we need to reset the link tuner. | |
203 | */ | |
e4ea1c40 | 204 | if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) |
84e3196f | 205 | rt2x00link_reset_tuner(rt2x00dev, false); |
95ea3627 | 206 | |
e4ea1c40 | 207 | rt2x00dev->curr_band = conf->channel->band; |
e5ef5bad | 208 | rt2x00dev->curr_freq = conf->channel->center_freq; |
95ea3627 | 209 | rt2x00dev->tx_power = conf->power_level; |
42c82857 ID |
210 | rt2x00dev->short_retry = conf->short_frame_max_tx_count; |
211 | rt2x00dev->long_retry = conf->long_frame_max_tx_count; | |
95ea3627 | 212 | } |