rt2x00: Restrict interface between rt2x00link and drivers
[deliverable/linux.git] / drivers / net / wireless / rt2x00 / rt2x00config.c
CommitLineData
95ea3627 1/*
811aa9ca 2 Copyright (C) 2004 - 2008 rt2x00 SourceForge Project
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
32void rt2x00lib_config_intf(struct rt2x00_dev *rt2x00dev,
33 struct rt2x00_intf *intf,
05c914fe 34 enum nl80211_iftype type,
6bb40dd1 35 u8 *mac, 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
JB
43 case NL80211_IFTYPE_ADHOC:
44 case NL80211_IFTYPE_AP:
6bb40dd1 45 conf.sync = TSF_SYNC_BEACON;
feb24691 46 break;
05c914fe 47 case NL80211_IFTYPE_STATION:
6bb40dd1 48 conf.sync = TSF_SYNC_INFRA;
feb24691
ID
49 break;
50 default:
6bb40dd1 51 conf.sync = TSF_SYNC_NONE;
feb24691
ID
52 break;
53 }
54
6bb40dd1
ID
55 /*
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.
60 */
61 memset(&conf.mac, 0, sizeof(conf.mac));
62 if (mac)
63 memcpy(&conf.mac, mac, ETH_ALEN);
64
65 memset(&conf.bssid, 0, sizeof(conf.bssid));
66 if (bssid)
67 memcpy(&conf.bssid, bssid, ETH_ALEN);
68
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;
74
75 rt2x00dev->ops->lib->config_intf(rt2x00dev, intf, &conf, flags);
76}
77
72810379
ID
78void rt2x00lib_config_erp(struct rt2x00_dev *rt2x00dev,
79 struct rt2x00_intf *intf,
80 struct ieee80211_bss_conf *bss_conf)
6bb40dd1 81{
72810379 82 struct rt2x00lib_erp erp;
6bb40dd1 83
72810379
ID
84 memset(&erp, 0, sizeof(erp));
85
86 erp.short_preamble = bss_conf->use_short_preamble;
e360c4cb
ID
87 erp.cts_protection = bss_conf->use_cts_prot;
88
e4ea1c40
ID
89 erp.slot_time = bss_conf->use_short_slot ? SHORT_SLOT_TIME : SLOT_TIME;
90 erp.sifs = SIFS;
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;
6bb40dd1 94
bad13639
ID
95 erp.ack_timeout = PLCP + erp.difs + GET_DURATION(ACK_SIZE, 10);
96 erp.ack_consume_time = SIFS + PLCP + GET_DURATION(ACK_SIZE, 10);
6bb40dd1 97
72810379
ID
98 if (bss_conf->use_short_preamble) {
99 erp.ack_timeout += SHORT_PREAMBLE;
100 erp.ack_consume_time += SHORT_PREAMBLE;
6bb40dd1 101 } else {
72810379
ID
102 erp.ack_timeout += PREAMBLE;
103 erp.ack_consume_time += PREAMBLE;
6bb40dd1
ID
104 }
105
e4ea1c40
ID
106 erp.basic_rates = bss_conf->basic_rates;
107
3a643d24 108 rt2x00dev->ops->lib->config_erp(rt2x00dev, &erp);
95ea3627
ID
109}
110
0b927a07
ID
111static inline
112enum antenna rt2x00lib_config_antenna_check(enum antenna current_ant,
113 enum antenna default_ant)
114{
115 if (current_ant != ANTENNA_SW_DIVERSITY)
116 return current_ant;
117 return (default_ant != ANTENNA_SW_DIVERSITY) ? default_ant : ANTENNA_B;
118}
119
69f81a2c 120void rt2x00lib_config_antenna(struct rt2x00_dev *rt2x00dev,
6d64360a 121 struct antenna_setup *ant)
69f81a2c 122{
0b927a07
ID
123 struct antenna_setup *def = &rt2x00dev->default_ant;
124 struct antenna_setup *active = &rt2x00dev->link.ant.active;
125
6d64360a
ID
126 /*
127 * Failsafe: Make sure we are not sending the
128 * ANTENNA_SW_DIVERSITY state to the driver.
129 * If that happes fallback to hardware default,
130 * or our own default.
0b927a07
ID
131 * The calls to rt2x00lib_config_antenna_check()
132 * might have caused that we restore back to the already
133 * active setting. If that has happened we can quit.
6d64360a 134 */
0b927a07
ID
135 ant->rx = rt2x00lib_config_antenna_check(ant->rx, def->rx);
136 ant->tx = rt2x00lib_config_antenna_check(ant->tx, def->tx);
69f81a2c 137
0b927a07 138 if (ant->rx == active->rx && ant->tx == active->tx)
05253c93
ID
139 return;
140
e25c4bb9
ID
141 /*
142 * Antenna setup changes require the RX to be disabled,
143 * else the changes will be ignored by the device.
144 */
0262ab0d 145 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
61667d8d 146 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_OFF_LINK);
e25c4bb9 147
69f81a2c
ID
148 /*
149 * Write new antenna setup to device and reset the link tuner.
150 * The latter is required since we need to recalibrate the
151 * noise-sensitivity ratio for the new setup.
152 */
6d64360a 153 rt2x00dev->ops->lib->config_ant(rt2x00dev, ant);
e4ea1c40 154
84e3196f 155 rt2x00link_reset_tuner(rt2x00dev, true);
69f81a2c 156
0b927a07 157 memcpy(active, ant, sizeof(*ant));
e25c4bb9 158
0262ab0d 159 if (test_bit(DEVICE_STATE_ENABLED_RADIO, &rt2x00dev->flags))
61667d8d 160 rt2x00lib_toggle_rx(rt2x00dev, STATE_RADIO_RX_ON_LINK);
69f81a2c
ID
161}
162
066cb637 163void rt2x00lib_config(struct rt2x00_dev *rt2x00dev,
e4ea1c40
ID
164 struct ieee80211_conf *conf,
165 unsigned int ieee80211_flags)
95ea3627 166{
5c58ee51 167 struct rt2x00lib_conf libconf;
95ea3627 168
5c58ee51
ID
169 memset(&libconf, 0, sizeof(libconf));
170
e4ea1c40 171 libconf.conf = conf;
5c58ee51 172
e4ea1c40 173 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL) {
5c58ee51 174 memcpy(&libconf.rf,
8318d78a 175 &rt2x00dev->spec.channels[conf->channel->hw_value],
5c58ee51 176 sizeof(libconf.rf));
8c5e7a5f
ID
177
178 memcpy(&libconf.channel,
179 &rt2x00dev->spec.channels_info[conf->channel->hw_value],
180 sizeof(libconf.channel));
5c58ee51
ID
181 }
182
5c58ee51
ID
183 /*
184 * Start configuration.
185 */
e4ea1c40 186 rt2x00dev->ops->lib->config(rt2x00dev, &libconf, ieee80211_flags);
95ea3627
ID
187
188 /*
189 * Some configuration changes affect the link quality
190 * which means we need to reset the link tuner.
191 */
e4ea1c40 192 if (ieee80211_flags & IEEE80211_CONF_CHANGE_CHANNEL)
84e3196f 193 rt2x00link_reset_tuner(rt2x00dev, false);
95ea3627 194
e4ea1c40 195 rt2x00dev->curr_band = conf->channel->band;
95ea3627 196 rt2x00dev->tx_power = conf->power_level;
42c82857
ID
197 rt2x00dev->short_retry = conf->short_frame_max_tx_count;
198 rt2x00dev->long_retry = conf->long_frame_max_tx_count;
16b1951f 199
e4ea1c40
ID
200 rt2x00dev->rx_status.band = conf->channel->band;
201 rt2x00dev->rx_status.freq = conf->channel->center_freq;
95ea3627 202}
This page took 0.261459 seconds and 5 git commands to generate.