aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorJohannes Berg <johannes.berg@intel.com>2010-09-22 12:02:01 -0400
committerWey-Yi Guy <wey-yi.w.guy@intel.com>2010-10-07 18:50:33 -0400
commita30e3112a8bcb5bc1caa48547e597de3992e1b21 (patch)
tree3690cb36a987af1a3778011390221e48763c1b80 /drivers/net
parentd3f5ba958d6c425a87535c6fa2a69ca90eb6e930 (diff)
iwlwifi: move agn specific station code there
By duplicating a little bit of code between 3945 and agn, we can move a lot of code into an agn specific station management file and thus reduce the amount of code in core that is dead to 3945. before: text data bss dec hex filename 212886 3872 96 216854 34f16 iwlcore.ko 620542 10448 304 631294 9a1fe iwlagn.ko 314013 3264 196 317473 4d821 iwl3945.ko after: text data bss dec hex filename 202857 3872 92 206821 327e5 iwlcore.ko 629102 10448 308 639858 9c372 iwlagn.ko 314240 3264 196 317700 4d904 iwl3945.ko delta: -10029 iwlcore.ko 8560 iwlagn.ko 227 iwl3945.ko so it's a net win even if you have both loaded, likely because a lot of EXPORT_SYMBOLs go away. Signed-off-by: Johannes Berg <johannes.berg@intel.com> Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/iwlwifi/Makefile2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c32
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-sta.c716
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.h31
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c725
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h35
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c25
11 files changed, 823 insertions, 754 deletions
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile
index 493163925a45..b4b24b67892c 100644
--- a/drivers/net/wireless/iwlwifi/Makefile
+++ b/drivers/net/wireless/iwlwifi/Makefile
@@ -12,7 +12,7 @@ obj-$(CONFIG_IWLAGN) += iwlagn.o
12iwlagn-objs := iwl-agn.o iwl-agn-rs.o iwl-agn-led.o iwl-agn-ict.o 12iwlagn-objs := iwl-agn.o iwl-agn-rs.o iwl-agn-led.o iwl-agn-ict.o
13iwlagn-objs += iwl-agn-ucode.o iwl-agn-hcmd.o iwl-agn-tx.o 13iwlagn-objs += iwl-agn-ucode.o iwl-agn-hcmd.o iwl-agn-tx.o
14iwlagn-objs += iwl-agn-lib.o iwl-agn-rx.o iwl-agn-calib.o 14iwlagn-objs += iwl-agn-lib.o iwl-agn-rx.o iwl-agn-calib.o
15iwlagn-objs += iwl-agn-tt.o 15iwlagn-objs += iwl-agn-tt.o iwl-agn-sta.o
16iwlagn-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-agn-debugfs.o 16iwlagn-$(CONFIG_IWLWIFI_DEBUGFS) += iwl-agn-debugfs.o
17 17
18iwlagn-$(CONFIG_IWL4965) += iwl-4965.o 18iwlagn-$(CONFIG_IWL4965) += iwl-4965.o
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index a7dbb2806b1a..4b3eb785dcb2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -2299,6 +2299,32 @@ static u16 iwl3945_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
2299 return (u16)sizeof(struct iwl3945_addsta_cmd); 2299 return (u16)sizeof(struct iwl3945_addsta_cmd);
2300} 2300}
2301 2301
2302static int iwl3945_add_bssid_station(struct iwl_priv *priv,
2303 const u8 *addr, u8 *sta_id_r)
2304{
2305 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2306 int ret;
2307 u8 sta_id;
2308 unsigned long flags;
2309
2310 if (sta_id_r)
2311 *sta_id_r = IWL_INVALID_STATION;
2312
2313 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
2314 if (ret) {
2315 IWL_ERR(priv, "Unable to add station %pM\n", addr);
2316 return ret;
2317 }
2318
2319 if (sta_id_r)
2320 *sta_id_r = sta_id;
2321
2322 spin_lock_irqsave(&priv->sta_lock, flags);
2323 priv->stations[sta_id].used |= IWL_STA_LOCAL;
2324 spin_unlock_irqrestore(&priv->sta_lock, flags);
2325
2326 return 0;
2327}
2302static int iwl3945_manage_ibss_station(struct iwl_priv *priv, 2328static int iwl3945_manage_ibss_station(struct iwl_priv *priv,
2303 struct ieee80211_vif *vif, bool add) 2329 struct ieee80211_vif *vif, bool add)
2304{ 2330{
@@ -2306,10 +2332,8 @@ static int iwl3945_manage_ibss_station(struct iwl_priv *priv,
2306 int ret; 2332 int ret;
2307 2333
2308 if (add) { 2334 if (add) {
2309 ret = iwl_add_bssid_station( 2335 ret = iwl3945_add_bssid_station(priv, vif->bss_conf.bssid,
2310 priv, &priv->contexts[IWL_RXON_CTX_BSS], 2336 &vif_priv->ibss_bssid_sta_id);
2311 vif->bss_conf.bssid, false,
2312 &vif_priv->ibss_bssid_sta_id);
2313 if (ret) 2337 if (ret)
2314 return ret; 2338 return ret;
2315 2339
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index 0b45bced9c0c..3eeab0a99def 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -1587,9 +1587,9 @@ int iwlagn_manage_ibss_station(struct iwl_priv *priv,
1587 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; 1587 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1588 1588
1589 if (add) 1589 if (add)
1590 return iwl_add_bssid_station(priv, vif_priv->ctx, 1590 return iwlagn_add_bssid_station(priv, vif_priv->ctx,
1591 vif->bss_conf.bssid, true, 1591 vif->bss_conf.bssid,
1592 &vif_priv->ibss_bssid_sta_id); 1592 &vif_priv->ibss_bssid_sta_id);
1593 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id, 1593 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
1594 vif->bss_conf.bssid); 1594 vif->bss_conf.bssid);
1595} 1595}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index f865685fd5f5..7e5cf1a2b21e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -39,6 +39,7 @@
39#include "iwl-dev.h" 39#include "iwl-dev.h"
40#include "iwl-sta.h" 40#include "iwl-sta.h"
41#include "iwl-core.h" 41#include "iwl-core.h"
42#include "iwl-agn.h"
42 43
43#define RS_NAME "iwl-agn-rs" 44#define RS_NAME "iwl-agn-rs"
44 45
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c b/drivers/net/wireless/iwlwifi/iwl-agn-sta.c
new file mode 100644
index 000000000000..35a30d2e0734
--- /dev/null
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-sta.c
@@ -0,0 +1,716 @@
1/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
4 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
30#include <net/mac80211.h>
31
32#include "iwl-dev.h"
33#include "iwl-core.h"
34#include "iwl-sta.h"
35#include "iwl-agn.h"
36
37static struct iwl_link_quality_cmd *
38iwl_sta_alloc_lq(struct iwl_priv *priv, u8 sta_id)
39{
40 int i, r;
41 struct iwl_link_quality_cmd *link_cmd;
42 u32 rate_flags = 0;
43 __le32 rate_n_flags;
44
45 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
46 if (!link_cmd) {
47 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
48 return NULL;
49 }
50 /* Set up the rate scaling to start at selected rate, fall back
51 * all the way down to 1M in IEEE order, and then spin on 1M */
52 if (priv->band == IEEE80211_BAND_5GHZ)
53 r = IWL_RATE_6M_INDEX;
54 else
55 r = IWL_RATE_1M_INDEX;
56
57 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
58 rate_flags |= RATE_MCS_CCK_MSK;
59
60 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
61 RATE_MCS_ANT_POS;
62 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
63 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
64 link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
65
66 link_cmd->general_params.single_stream_ant_msk =
67 first_antenna(priv->hw_params.valid_tx_ant);
68
69 link_cmd->general_params.dual_stream_ant_msk =
70 priv->hw_params.valid_tx_ant &
71 ~first_antenna(priv->hw_params.valid_tx_ant);
72 if (!link_cmd->general_params.dual_stream_ant_msk) {
73 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
74 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
75 link_cmd->general_params.dual_stream_ant_msk =
76 priv->hw_params.valid_tx_ant;
77 }
78
79 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
80 link_cmd->agg_params.agg_time_limit =
81 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
82
83 link_cmd->sta_id = sta_id;
84
85 return link_cmd;
86}
87
88/*
89 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
90 *
91 * Function sleeps.
92 */
93int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
94 const u8 *addr, u8 *sta_id_r)
95{
96 int ret;
97 u8 sta_id;
98 struct iwl_link_quality_cmd *link_cmd;
99 unsigned long flags;
100
101 if (sta_id_r)
102 *sta_id_r = IWL_INVALID_STATION;
103
104 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
105 if (ret) {
106 IWL_ERR(priv, "Unable to add station %pM\n", addr);
107 return ret;
108 }
109
110 if (sta_id_r)
111 *sta_id_r = sta_id;
112
113 spin_lock_irqsave(&priv->sta_lock, flags);
114 priv->stations[sta_id].used |= IWL_STA_LOCAL;
115 spin_unlock_irqrestore(&priv->sta_lock, flags);
116
117 /* Set up default rate scaling table in device's station table */
118 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
119 if (!link_cmd) {
120 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
121 addr);
122 return -ENOMEM;
123 }
124
125 ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
126 if (ret)
127 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
128
129 spin_lock_irqsave(&priv->sta_lock, flags);
130 priv->stations[sta_id].lq = link_cmd;
131 spin_unlock_irqrestore(&priv->sta_lock, flags);
132
133 return 0;
134}
135
136static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv,
137 struct iwl_rxon_context *ctx,
138 bool send_if_empty)
139{
140 int i, not_empty = 0;
141 u8 buff[sizeof(struct iwl_wep_cmd) +
142 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
143 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
144 size_t cmd_size = sizeof(struct iwl_wep_cmd);
145 struct iwl_host_cmd cmd = {
146 .id = ctx->wep_key_cmd,
147 .data = wep_cmd,
148 .flags = CMD_SYNC,
149 };
150
151 might_sleep();
152
153 memset(wep_cmd, 0, cmd_size +
154 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
155
156 for (i = 0; i < WEP_KEYS_MAX ; i++) {
157 wep_cmd->key[i].key_index = i;
158 if (ctx->wep_keys[i].key_size) {
159 wep_cmd->key[i].key_offset = i;
160 not_empty = 1;
161 } else {
162 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
163 }
164
165 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
166 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
167 ctx->wep_keys[i].key_size);
168 }
169
170 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
171 wep_cmd->num_keys = WEP_KEYS_MAX;
172
173 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
174
175 cmd.len = cmd_size;
176
177 if (not_empty || send_if_empty)
178 return iwl_send_cmd(priv, &cmd);
179 else
180 return 0;
181}
182
183int iwl_restore_default_wep_keys(struct iwl_priv *priv,
184 struct iwl_rxon_context *ctx)
185{
186 lockdep_assert_held(&priv->mutex);
187
188 return iwl_send_static_wepkey_cmd(priv, ctx, false);
189}
190
191int iwl_remove_default_wep_key(struct iwl_priv *priv,
192 struct iwl_rxon_context *ctx,
193 struct ieee80211_key_conf *keyconf)
194{
195 int ret;
196
197 lockdep_assert_held(&priv->mutex);
198
199 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
200 keyconf->keyidx);
201
202 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
203 if (iwl_is_rfkill(priv)) {
204 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
205 /* but keys in device are clear anyway so return success */
206 return 0;
207 }
208 ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
209 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
210 keyconf->keyidx, ret);
211
212 return ret;
213}
214
215int iwl_set_default_wep_key(struct iwl_priv *priv,
216 struct iwl_rxon_context *ctx,
217 struct ieee80211_key_conf *keyconf)
218{
219 int ret;
220
221 lockdep_assert_held(&priv->mutex);
222
223 if (keyconf->keylen != WEP_KEY_LEN_128 &&
224 keyconf->keylen != WEP_KEY_LEN_64) {
225 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
226 return -EINVAL;
227 }
228
229 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
230 keyconf->hw_key_idx = HW_KEY_DEFAULT;
231 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
232
233 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
234 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
235 keyconf->keylen);
236
237 ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
238 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
239 keyconf->keylen, keyconf->keyidx, ret);
240
241 return ret;
242}
243
244static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
245 struct iwl_rxon_context *ctx,
246 struct ieee80211_key_conf *keyconf,
247 u8 sta_id)
248{
249 unsigned long flags;
250 __le16 key_flags = 0;
251 struct iwl_addsta_cmd sta_cmd;
252
253 lockdep_assert_held(&priv->mutex);
254
255 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
256
257 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
258 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
259 key_flags &= ~STA_KEY_FLG_INVALID;
260
261 if (keyconf->keylen == WEP_KEY_LEN_128)
262 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
263
264 if (sta_id == ctx->bcast_sta_id)
265 key_flags |= STA_KEY_MULTICAST_MSK;
266
267 spin_lock_irqsave(&priv->sta_lock, flags);
268
269 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
270 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
271 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
272
273 memcpy(priv->stations[sta_id].keyinfo.key,
274 keyconf->key, keyconf->keylen);
275
276 memcpy(&priv->stations[sta_id].sta.key.key[3],
277 keyconf->key, keyconf->keylen);
278
279 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
280 == STA_KEY_FLG_NO_ENC)
281 priv->stations[sta_id].sta.key.key_offset =
282 iwl_get_free_ucode_key_index(priv);
283 /* else, we are overriding an existing key => no need to allocated room
284 * in uCode. */
285
286 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
287 "no space for a new key");
288
289 priv->stations[sta_id].sta.key.key_flags = key_flags;
290 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
291 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
292
293 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
294 spin_unlock_irqrestore(&priv->sta_lock, flags);
295
296 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
297}
298
299static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
300 struct iwl_rxon_context *ctx,
301 struct ieee80211_key_conf *keyconf,
302 u8 sta_id)
303{
304 unsigned long flags;
305 __le16 key_flags = 0;
306 struct iwl_addsta_cmd sta_cmd;
307
308 lockdep_assert_held(&priv->mutex);
309
310 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
311 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
312 key_flags &= ~STA_KEY_FLG_INVALID;
313
314 if (sta_id == ctx->bcast_sta_id)
315 key_flags |= STA_KEY_MULTICAST_MSK;
316
317 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
318
319 spin_lock_irqsave(&priv->sta_lock, flags);
320 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
321 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
322
323 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
324 keyconf->keylen);
325
326 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
327 keyconf->keylen);
328
329 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
330 == STA_KEY_FLG_NO_ENC)
331 priv->stations[sta_id].sta.key.key_offset =
332 iwl_get_free_ucode_key_index(priv);
333 /* else, we are overriding an existing key => no need to allocated room
334 * in uCode. */
335
336 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
337 "no space for a new key");
338
339 priv->stations[sta_id].sta.key.key_flags = key_flags;
340 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
341 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
342
343 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
344 spin_unlock_irqrestore(&priv->sta_lock, flags);
345
346 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
347}
348
349static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
350 struct iwl_rxon_context *ctx,
351 struct ieee80211_key_conf *keyconf,
352 u8 sta_id)
353{
354 unsigned long flags;
355 int ret = 0;
356 __le16 key_flags = 0;
357
358 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
359 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
360 key_flags &= ~STA_KEY_FLG_INVALID;
361
362 if (sta_id == ctx->bcast_sta_id)
363 key_flags |= STA_KEY_MULTICAST_MSK;
364
365 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
366 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
367
368 spin_lock_irqsave(&priv->sta_lock, flags);
369
370 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
371 priv->stations[sta_id].keyinfo.keylen = 16;
372
373 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
374 == STA_KEY_FLG_NO_ENC)
375 priv->stations[sta_id].sta.key.key_offset =
376 iwl_get_free_ucode_key_index(priv);
377 /* else, we are overriding an existing key => no need to allocated room
378 * in uCode. */
379
380 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
381 "no space for a new key");
382
383 priv->stations[sta_id].sta.key.key_flags = key_flags;
384
385
386 /* This copy is acutally not needed: we get the key with each TX */
387 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
388
389 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
390
391 spin_unlock_irqrestore(&priv->sta_lock, flags);
392
393 return ret;
394}
395
396void iwl_update_tkip_key(struct iwl_priv *priv,
397 struct iwl_rxon_context *ctx,
398 struct ieee80211_key_conf *keyconf,
399 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
400{
401 u8 sta_id;
402 unsigned long flags;
403 int i;
404
405 if (iwl_scan_cancel(priv)) {
406 /* cancel scan failed, just live w/ bad key and rely
407 briefly on SW decryption */
408 return;
409 }
410
411 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
412 if (sta_id == IWL_INVALID_STATION)
413 return;
414
415 spin_lock_irqsave(&priv->sta_lock, flags);
416
417 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
418
419 for (i = 0; i < 5; i++)
420 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
421 cpu_to_le16(phase1key[i]);
422
423 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
424 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
425
426 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
427
428 spin_unlock_irqrestore(&priv->sta_lock, flags);
429
430}
431
432int iwl_remove_dynamic_key(struct iwl_priv *priv,
433 struct iwl_rxon_context *ctx,
434 struct ieee80211_key_conf *keyconf,
435 u8 sta_id)
436{
437 unsigned long flags;
438 u16 key_flags;
439 u8 keyidx;
440 struct iwl_addsta_cmd sta_cmd;
441
442 lockdep_assert_held(&priv->mutex);
443
444 ctx->key_mapping_keys--;
445
446 spin_lock_irqsave(&priv->sta_lock, flags);
447 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
448 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
449
450 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
451 keyconf->keyidx, sta_id);
452
453 if (keyconf->keyidx != keyidx) {
454 /* We need to remove a key with index different that the one
455 * in the uCode. This means that the key we need to remove has
456 * been replaced by another one with different index.
457 * Don't do anything and return ok
458 */
459 spin_unlock_irqrestore(&priv->sta_lock, flags);
460 return 0;
461 }
462
463 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
464 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
465 keyconf->keyidx, key_flags);
466 spin_unlock_irqrestore(&priv->sta_lock, flags);
467 return 0;
468 }
469
470 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
471 &priv->ucode_key_table))
472 IWL_ERR(priv, "index %d not used in uCode key table.\n",
473 priv->stations[sta_id].sta.key.key_offset);
474 memset(&priv->stations[sta_id].keyinfo, 0,
475 sizeof(struct iwl_hw_key));
476 memset(&priv->stations[sta_id].sta.key, 0,
477 sizeof(struct iwl4965_keyinfo));
478 priv->stations[sta_id].sta.key.key_flags =
479 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
480 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
481 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
482 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
483
484 if (iwl_is_rfkill(priv)) {
485 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
486 spin_unlock_irqrestore(&priv->sta_lock, flags);
487 return 0;
488 }
489 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
490 spin_unlock_irqrestore(&priv->sta_lock, flags);
491
492 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
493}
494
495int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
496 struct ieee80211_key_conf *keyconf, u8 sta_id)
497{
498 int ret;
499
500 lockdep_assert_held(&priv->mutex);
501
502 ctx->key_mapping_keys++;
503 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
504
505 switch (keyconf->cipher) {
506 case WLAN_CIPHER_SUITE_CCMP:
507 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
508 break;
509 case WLAN_CIPHER_SUITE_TKIP:
510 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
511 break;
512 case WLAN_CIPHER_SUITE_WEP40:
513 case WLAN_CIPHER_SUITE_WEP104:
514 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
515 break;
516 default:
517 IWL_ERR(priv,
518 "Unknown alg: %s cipher = %x\n", __func__,
519 keyconf->cipher);
520 ret = -EINVAL;
521 }
522
523 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
524 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
525 sta_id, ret);
526
527 return ret;
528}
529
530/**
531 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
532 *
533 * This adds the broadcast station into the driver's station table
534 * and marks it driver active, so that it will be restored to the
535 * device at the next best time.
536 */
537int iwlagn_alloc_bcast_station(struct iwl_priv *priv,
538 struct iwl_rxon_context *ctx)
539{
540 struct iwl_link_quality_cmd *link_cmd;
541 unsigned long flags;
542 u8 sta_id;
543
544 spin_lock_irqsave(&priv->sta_lock, flags);
545 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
546 if (sta_id == IWL_INVALID_STATION) {
547 IWL_ERR(priv, "Unable to prepare broadcast station\n");
548 spin_unlock_irqrestore(&priv->sta_lock, flags);
549
550 return -EINVAL;
551 }
552
553 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
554 priv->stations[sta_id].used |= IWL_STA_BCAST;
555 spin_unlock_irqrestore(&priv->sta_lock, flags);
556
557 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
558 if (!link_cmd) {
559 IWL_ERR(priv,
560 "Unable to initialize rate scaling for bcast station.\n");
561 return -ENOMEM;
562 }
563
564 spin_lock_irqsave(&priv->sta_lock, flags);
565 priv->stations[sta_id].lq = link_cmd;
566 spin_unlock_irqrestore(&priv->sta_lock, flags);
567
568 return 0;
569}
570
571/**
572 * iwl_update_bcast_station - update broadcast station's LQ command
573 *
574 * Only used by iwlagn. Placed here to have all bcast station management
575 * code together.
576 */
577static int iwl_update_bcast_station(struct iwl_priv *priv,
578 struct iwl_rxon_context *ctx)
579{
580 unsigned long flags;
581 struct iwl_link_quality_cmd *link_cmd;
582 u8 sta_id = ctx->bcast_sta_id;
583
584 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
585 if (!link_cmd) {
586 IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n");
587 return -ENOMEM;
588 }
589
590 spin_lock_irqsave(&priv->sta_lock, flags);
591 if (priv->stations[sta_id].lq)
592 kfree(priv->stations[sta_id].lq);
593 else
594 IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n");
595 priv->stations[sta_id].lq = link_cmd;
596 spin_unlock_irqrestore(&priv->sta_lock, flags);
597
598 return 0;
599}
600
601int iwl_update_bcast_stations(struct iwl_priv *priv)
602{
603 struct iwl_rxon_context *ctx;
604 int ret = 0;
605
606 for_each_context(priv, ctx) {
607 ret = iwl_update_bcast_station(priv, ctx);
608 if (ret)
609 break;
610 }
611
612 return ret;
613}
614
615/**
616 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
617 */
618int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
619{
620 unsigned long flags;
621 struct iwl_addsta_cmd sta_cmd;
622
623 lockdep_assert_held(&priv->mutex);
624
625 /* Remove "disable" flag, to enable Tx for this TID */
626 spin_lock_irqsave(&priv->sta_lock, flags);
627 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
628 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
629 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
630 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
631 spin_unlock_irqrestore(&priv->sta_lock, flags);
632
633 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
634}
635
636int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
637 int tid, u16 ssn)
638{
639 unsigned long flags;
640 int sta_id;
641 struct iwl_addsta_cmd sta_cmd;
642
643 lockdep_assert_held(&priv->mutex);
644
645 sta_id = iwl_sta_id(sta);
646 if (sta_id == IWL_INVALID_STATION)
647 return -ENXIO;
648
649 spin_lock_irqsave(&priv->sta_lock, flags);
650 priv->stations[sta_id].sta.station_flags_msk = 0;
651 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
652 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
653 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
654 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
655 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
656 spin_unlock_irqrestore(&priv->sta_lock, flags);
657
658 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
659}
660
661int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
662 int tid)
663{
664 unsigned long flags;
665 int sta_id;
666 struct iwl_addsta_cmd sta_cmd;
667
668 lockdep_assert_held(&priv->mutex);
669
670 sta_id = iwl_sta_id(sta);
671 if (sta_id == IWL_INVALID_STATION) {
672 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
673 return -ENXIO;
674 }
675
676 spin_lock_irqsave(&priv->sta_lock, flags);
677 priv->stations[sta_id].sta.station_flags_msk = 0;
678 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
679 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
680 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
681 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
682 spin_unlock_irqrestore(&priv->sta_lock, flags);
683
684 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
685}
686
687void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
688{
689 unsigned long flags;
690
691 spin_lock_irqsave(&priv->sta_lock, flags);
692 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
693 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
694 priv->stations[sta_id].sta.sta.modify_mask = 0;
695 priv->stations[sta_id].sta.sleep_tx_count = 0;
696 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
697 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
698 spin_unlock_irqrestore(&priv->sta_lock, flags);
699
700}
701
702void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
703{
704 unsigned long flags;
705
706 spin_lock_irqsave(&priv->sta_lock, flags);
707 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
708 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
709 priv->stations[sta_id].sta.sta.modify_mask =
710 STA_MODIFY_SLEEP_TX_COUNT_MSK;
711 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
712 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
713 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
714 spin_unlock_irqrestore(&priv->sta_lock, flags);
715
716}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index b59ce92730c7..8233c6410411 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -3089,7 +3089,7 @@ static int __iwl_up(struct iwl_priv *priv)
3089 } 3089 }
3090 3090
3091 for_each_context(priv, ctx) { 3091 for_each_context(priv, ctx) {
3092 ret = iwl_alloc_bcast_station(priv, ctx, true); 3092 ret = iwlagn_alloc_bcast_station(priv, ctx);
3093 if (ret) { 3093 if (ret) {
3094 iwl_dealloc_bcast_stations(priv); 3094 iwl_dealloc_bcast_stations(priv);
3095 return ret; 3095 return ret;
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/iwl-agn.h
index 5d5cacb54eb7..632ea4ba82bb 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.h
@@ -252,4 +252,35 @@ const char *iwl_get_agg_tx_fail_reason(u16 status);
252#else 252#else
253static inline const char *iwl_get_agg_tx_fail_reason(u16 status) { return ""; } 253static inline const char *iwl_get_agg_tx_fail_reason(u16 status) { return ""; }
254#endif 254#endif
255
256/* station management */
257int iwlagn_alloc_bcast_station(struct iwl_priv *priv,
258 struct iwl_rxon_context *ctx);
259int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
260 const u8 *addr, u8 *sta_id_r);
261int iwl_remove_default_wep_key(struct iwl_priv *priv,
262 struct iwl_rxon_context *ctx,
263 struct ieee80211_key_conf *key);
264int iwl_set_default_wep_key(struct iwl_priv *priv,
265 struct iwl_rxon_context *ctx,
266 struct ieee80211_key_conf *key);
267int iwl_restore_default_wep_keys(struct iwl_priv *priv,
268 struct iwl_rxon_context *ctx);
269int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
270 struct ieee80211_key_conf *key, u8 sta_id);
271int iwl_remove_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
272 struct ieee80211_key_conf *key, u8 sta_id);
273void iwl_update_tkip_key(struct iwl_priv *priv,
274 struct iwl_rxon_context *ctx,
275 struct ieee80211_key_conf *keyconf,
276 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key);
277int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid);
278int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
279 int tid, u16 ssn);
280int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
281 int tid);
282void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id);
283void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt);
284int iwl_update_bcast_stations(struct iwl_priv *priv);
285
255#endif /* __iwl_agn_h__ */ 286#endif /* __iwl_agn_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index 50a3c26e1412..31ec9db58b26 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -750,8 +750,6 @@ static inline int iwl_is_ready_rf(struct iwl_priv *priv)
750extern void iwl_send_bt_config(struct iwl_priv *priv); 750extern void iwl_send_bt_config(struct iwl_priv *priv);
751extern int iwl_send_statistics_request(struct iwl_priv *priv, 751extern int iwl_send_statistics_request(struct iwl_priv *priv,
752 u8 flags, bool clear); 752 u8 flags, bool clear);
753extern int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
754 struct iwl_link_quality_cmd *lq, u8 flags, bool init);
755void iwl_apm_stop(struct iwl_priv *priv); 753void iwl_apm_stop(struct iwl_priv *priv);
756int iwl_apm_init(struct iwl_priv *priv); 754int iwl_apm_init(struct iwl_priv *priv);
757 755
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 6edd0341dfe2..7c7f7dcb1b1e 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -228,9 +228,8 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
228 * 228 *
229 * should be called with sta_lock held 229 * should be called with sta_lock held
230 */ 230 */
231static u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, 231u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
232 const u8 *addr, bool is_ap, 232 const u8 *addr, bool is_ap, struct ieee80211_sta *sta)
233 struct ieee80211_sta *sta)
234{ 233{
235 struct iwl_station_entry *station; 234 struct iwl_station_entry *station;
236 int i; 235 int i;
@@ -317,6 +316,7 @@ static u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
317 return sta_id; 316 return sta_id;
318 317
319} 318}
319EXPORT_SYMBOL_GPL(iwl_prep_station);
320 320
321#define STA_WAIT_TIMEOUT (HZ/2) 321#define STA_WAIT_TIMEOUT (HZ/2)
322 322
@@ -381,108 +381,6 @@ int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
381} 381}
382EXPORT_SYMBOL(iwl_add_station_common); 382EXPORT_SYMBOL(iwl_add_station_common);
383 383
384static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
385 u8 sta_id)
386{
387 int i, r;
388 struct iwl_link_quality_cmd *link_cmd;
389 u32 rate_flags = 0;
390 __le32 rate_n_flags;
391
392 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
393 if (!link_cmd) {
394 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
395 return NULL;
396 }
397 /* Set up the rate scaling to start at selected rate, fall back
398 * all the way down to 1M in IEEE order, and then spin on 1M */
399 if (priv->band == IEEE80211_BAND_5GHZ)
400 r = IWL_RATE_6M_INDEX;
401 else
402 r = IWL_RATE_1M_INDEX;
403
404 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
405 rate_flags |= RATE_MCS_CCK_MSK;
406
407 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
408 RATE_MCS_ANT_POS;
409 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
410 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
411 link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
412
413 link_cmd->general_params.single_stream_ant_msk =
414 first_antenna(priv->hw_params.valid_tx_ant);
415
416 link_cmd->general_params.dual_stream_ant_msk =
417 priv->hw_params.valid_tx_ant &
418 ~first_antenna(priv->hw_params.valid_tx_ant);
419 if (!link_cmd->general_params.dual_stream_ant_msk) {
420 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
421 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
422 link_cmd->general_params.dual_stream_ant_msk =
423 priv->hw_params.valid_tx_ant;
424 }
425
426 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
427 link_cmd->agg_params.agg_time_limit =
428 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
429
430 link_cmd->sta_id = sta_id;
431
432 return link_cmd;
433}
434
435/*
436 * iwl_add_bssid_station - Add the special IBSS BSSID station
437 *
438 * Function sleeps.
439 */
440int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
441 const u8 *addr, bool init_rs, u8 *sta_id_r)
442{
443 int ret;
444 u8 sta_id;
445 struct iwl_link_quality_cmd *link_cmd;
446 unsigned long flags;
447
448 if (sta_id_r)
449 *sta_id_r = IWL_INVALID_STATION;
450
451 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
452 if (ret) {
453 IWL_ERR(priv, "Unable to add station %pM\n", addr);
454 return ret;
455 }
456
457 if (sta_id_r)
458 *sta_id_r = sta_id;
459
460 spin_lock_irqsave(&priv->sta_lock, flags);
461 priv->stations[sta_id].used |= IWL_STA_LOCAL;
462 spin_unlock_irqrestore(&priv->sta_lock, flags);
463
464 if (init_rs) {
465 /* Set up default rate scaling table in device's station table */
466 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
467 if (!link_cmd) {
468 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
469 addr);
470 return -ENOMEM;
471 }
472
473 ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
474 if (ret)
475 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
476
477 spin_lock_irqsave(&priv->sta_lock, flags);
478 priv->stations[sta_id].lq = link_cmd;
479 spin_unlock_irqrestore(&priv->sta_lock, flags);
480 }
481
482 return 0;
483}
484EXPORT_SYMBOL(iwl_add_bssid_station);
485
486/** 384/**
487 * iwl_sta_ucode_deactivate - deactivate ucode status for a station 385 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
488 * 386 *
@@ -738,405 +636,25 @@ int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
738} 636}
739EXPORT_SYMBOL(iwl_get_free_ucode_key_index); 637EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
740 638
741static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, 639void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
742 struct iwl_rxon_context *ctx,
743 bool send_if_empty)
744{
745 int i, not_empty = 0;
746 u8 buff[sizeof(struct iwl_wep_cmd) +
747 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
748 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
749 size_t cmd_size = sizeof(struct iwl_wep_cmd);
750 struct iwl_host_cmd cmd = {
751 .id = ctx->wep_key_cmd,
752 .data = wep_cmd,
753 .flags = CMD_SYNC,
754 };
755
756 might_sleep();
757
758 memset(wep_cmd, 0, cmd_size +
759 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
760
761 for (i = 0; i < WEP_KEYS_MAX ; i++) {
762 wep_cmd->key[i].key_index = i;
763 if (ctx->wep_keys[i].key_size) {
764 wep_cmd->key[i].key_offset = i;
765 not_empty = 1;
766 } else {
767 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
768 }
769
770 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
771 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
772 ctx->wep_keys[i].key_size);
773 }
774
775 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
776 wep_cmd->num_keys = WEP_KEYS_MAX;
777
778 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
779
780 cmd.len = cmd_size;
781
782 if (not_empty || send_if_empty)
783 return iwl_send_cmd(priv, &cmd);
784 else
785 return 0;
786}
787
788int iwl_restore_default_wep_keys(struct iwl_priv *priv,
789 struct iwl_rxon_context *ctx)
790{
791 lockdep_assert_held(&priv->mutex);
792
793 return iwl_send_static_wepkey_cmd(priv, ctx, false);
794}
795EXPORT_SYMBOL(iwl_restore_default_wep_keys);
796
797int iwl_remove_default_wep_key(struct iwl_priv *priv,
798 struct iwl_rxon_context *ctx,
799 struct ieee80211_key_conf *keyconf)
800{
801 int ret;
802
803 lockdep_assert_held(&priv->mutex);
804
805 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
806 keyconf->keyidx);
807
808 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
809 if (iwl_is_rfkill(priv)) {
810 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
811 /* but keys in device are clear anyway so return success */
812 return 0;
813 }
814 ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
815 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
816 keyconf->keyidx, ret);
817
818 return ret;
819}
820EXPORT_SYMBOL(iwl_remove_default_wep_key);
821
822int iwl_set_default_wep_key(struct iwl_priv *priv,
823 struct iwl_rxon_context *ctx,
824 struct ieee80211_key_conf *keyconf)
825{
826 int ret;
827
828 lockdep_assert_held(&priv->mutex);
829
830 if (keyconf->keylen != WEP_KEY_LEN_128 &&
831 keyconf->keylen != WEP_KEY_LEN_64) {
832 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
833 return -EINVAL;
834 }
835
836 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
837 keyconf->hw_key_idx = HW_KEY_DEFAULT;
838 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
839
840 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
841 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
842 keyconf->keylen);
843
844 ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
845 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
846 keyconf->keylen, keyconf->keyidx, ret);
847
848 return ret;
849}
850EXPORT_SYMBOL(iwl_set_default_wep_key);
851
852static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
853 struct iwl_rxon_context *ctx,
854 struct ieee80211_key_conf *keyconf,
855 u8 sta_id)
856{
857 unsigned long flags;
858 __le16 key_flags = 0;
859 struct iwl_addsta_cmd sta_cmd;
860
861 lockdep_assert_held(&priv->mutex);
862
863 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
864
865 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
866 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
867 key_flags &= ~STA_KEY_FLG_INVALID;
868
869 if (keyconf->keylen == WEP_KEY_LEN_128)
870 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
871
872 if (sta_id == ctx->bcast_sta_id)
873 key_flags |= STA_KEY_MULTICAST_MSK;
874
875 spin_lock_irqsave(&priv->sta_lock, flags);
876
877 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
878 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
879 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
880
881 memcpy(priv->stations[sta_id].keyinfo.key,
882 keyconf->key, keyconf->keylen);
883
884 memcpy(&priv->stations[sta_id].sta.key.key[3],
885 keyconf->key, keyconf->keylen);
886
887 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
888 == STA_KEY_FLG_NO_ENC)
889 priv->stations[sta_id].sta.key.key_offset =
890 iwl_get_free_ucode_key_index(priv);
891 /* else, we are overriding an existing key => no need to allocated room
892 * in uCode. */
893
894 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
895 "no space for a new key");
896
897 priv->stations[sta_id].sta.key.key_flags = key_flags;
898 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
899 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
900
901 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
902 spin_unlock_irqrestore(&priv->sta_lock, flags);
903
904 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
905}
906
907static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
908 struct iwl_rxon_context *ctx,
909 struct ieee80211_key_conf *keyconf,
910 u8 sta_id)
911{
912 unsigned long flags;
913 __le16 key_flags = 0;
914 struct iwl_addsta_cmd sta_cmd;
915
916 lockdep_assert_held(&priv->mutex);
917
918 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
919 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
920 key_flags &= ~STA_KEY_FLG_INVALID;
921
922 if (sta_id == ctx->bcast_sta_id)
923 key_flags |= STA_KEY_MULTICAST_MSK;
924
925 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
926
927 spin_lock_irqsave(&priv->sta_lock, flags);
928 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
929 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
930
931 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
932 keyconf->keylen);
933
934 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
935 keyconf->keylen);
936
937 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
938 == STA_KEY_FLG_NO_ENC)
939 priv->stations[sta_id].sta.key.key_offset =
940 iwl_get_free_ucode_key_index(priv);
941 /* else, we are overriding an existing key => no need to allocated room
942 * in uCode. */
943
944 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
945 "no space for a new key");
946
947 priv->stations[sta_id].sta.key.key_flags = key_flags;
948 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
949 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
950
951 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
952 spin_unlock_irqrestore(&priv->sta_lock, flags);
953
954 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
955}
956
957static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
958 struct iwl_rxon_context *ctx,
959 struct ieee80211_key_conf *keyconf,
960 u8 sta_id)
961{
962 unsigned long flags;
963 int ret = 0;
964 __le16 key_flags = 0;
965
966 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
967 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
968 key_flags &= ~STA_KEY_FLG_INVALID;
969
970 if (sta_id == ctx->bcast_sta_id)
971 key_flags |= STA_KEY_MULTICAST_MSK;
972
973 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
974 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
975
976 spin_lock_irqsave(&priv->sta_lock, flags);
977
978 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
979 priv->stations[sta_id].keyinfo.keylen = 16;
980
981 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
982 == STA_KEY_FLG_NO_ENC)
983 priv->stations[sta_id].sta.key.key_offset =
984 iwl_get_free_ucode_key_index(priv);
985 /* else, we are overriding an existing key => no need to allocated room
986 * in uCode. */
987
988 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
989 "no space for a new key");
990
991 priv->stations[sta_id].sta.key.key_flags = key_flags;
992
993
994 /* This copy is acutally not needed: we get the key with each TX */
995 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
996
997 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
998
999 spin_unlock_irqrestore(&priv->sta_lock, flags);
1000
1001 return ret;
1002}
1003
1004void iwl_update_tkip_key(struct iwl_priv *priv,
1005 struct iwl_rxon_context *ctx,
1006 struct ieee80211_key_conf *keyconf,
1007 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
1008{ 640{
1009 u8 sta_id;
1010 unsigned long flags; 641 unsigned long flags;
1011 int i; 642 int i;
1012 643
1013 if (iwl_scan_cancel(priv)) {
1014 /* cancel scan failed, just live w/ bad key and rely
1015 briefly on SW decryption */
1016 return;
1017 }
1018
1019 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
1020 if (sta_id == IWL_INVALID_STATION)
1021 return;
1022
1023 spin_lock_irqsave(&priv->sta_lock, flags);
1024
1025 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
1026
1027 for (i = 0; i < 5; i++)
1028 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
1029 cpu_to_le16(phase1key[i]);
1030
1031 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1032 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1033
1034 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1035
1036 spin_unlock_irqrestore(&priv->sta_lock, flags);
1037
1038}
1039EXPORT_SYMBOL(iwl_update_tkip_key);
1040
1041int iwl_remove_dynamic_key(struct iwl_priv *priv,
1042 struct iwl_rxon_context *ctx,
1043 struct ieee80211_key_conf *keyconf,
1044 u8 sta_id)
1045{
1046 unsigned long flags;
1047 u16 key_flags;
1048 u8 keyidx;
1049 struct iwl_addsta_cmd sta_cmd;
1050
1051 lockdep_assert_held(&priv->mutex);
1052
1053 ctx->key_mapping_keys--;
1054
1055 spin_lock_irqsave(&priv->sta_lock, flags); 644 spin_lock_irqsave(&priv->sta_lock, flags);
1056 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); 645 for (i = 0; i < priv->hw_params.max_stations; i++) {
1057 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3; 646 if (!(priv->stations[i].used & IWL_STA_BCAST))
1058 647 continue;
1059 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
1060 keyconf->keyidx, sta_id);
1061
1062 if (keyconf->keyidx != keyidx) {
1063 /* We need to remove a key with index different that the one
1064 * in the uCode. This means that the key we need to remove has
1065 * been replaced by another one with different index.
1066 * Don't do anything and return ok
1067 */
1068 spin_unlock_irqrestore(&priv->sta_lock, flags);
1069 return 0;
1070 }
1071
1072 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
1073 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
1074 keyconf->keyidx, key_flags);
1075 spin_unlock_irqrestore(&priv->sta_lock, flags);
1076 return 0;
1077 }
1078 648
1079 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset, 649 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
1080 &priv->ucode_key_table)) 650 priv->num_stations--;
1081 IWL_ERR(priv, "index %d not used in uCode key table.\n", 651 BUG_ON(priv->num_stations < 0);
1082 priv->stations[sta_id].sta.key.key_offset); 652 kfree(priv->stations[i].lq);
1083 memset(&priv->stations[sta_id].keyinfo, 0, 653 priv->stations[i].lq = NULL;
1084 sizeof(struct iwl_hw_key));
1085 memset(&priv->stations[sta_id].sta.key, 0,
1086 sizeof(struct iwl4965_keyinfo));
1087 priv->stations[sta_id].sta.key.key_flags =
1088 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
1089 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
1090 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
1091 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1092
1093 if (iwl_is_rfkill(priv)) {
1094 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
1095 spin_unlock_irqrestore(&priv->sta_lock, flags);
1096 return 0;
1097 } 654 }
1098 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1099 spin_unlock_irqrestore(&priv->sta_lock, flags); 655 spin_unlock_irqrestore(&priv->sta_lock, flags);
1100
1101 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1102}
1103EXPORT_SYMBOL(iwl_remove_dynamic_key);
1104
1105int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1106 struct ieee80211_key_conf *keyconf, u8 sta_id)
1107{
1108 int ret;
1109
1110 lockdep_assert_held(&priv->mutex);
1111
1112 ctx->key_mapping_keys++;
1113 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1114
1115 switch (keyconf->cipher) {
1116 case WLAN_CIPHER_SUITE_CCMP:
1117 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
1118 break;
1119 case WLAN_CIPHER_SUITE_TKIP:
1120 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
1121 break;
1122 case WLAN_CIPHER_SUITE_WEP40:
1123 case WLAN_CIPHER_SUITE_WEP104:
1124 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
1125 break;
1126 default:
1127 IWL_ERR(priv,
1128 "Unknown alg: %s cipher = %x\n", __func__,
1129 keyconf->cipher);
1130 ret = -EINVAL;
1131 }
1132
1133 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
1134 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
1135 sta_id, ret);
1136
1137 return ret;
1138} 656}
1139EXPORT_SYMBOL(iwl_set_dynamic_key); 657EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations);
1140 658
1141#ifdef CONFIG_IWLWIFI_DEBUG 659#ifdef CONFIG_IWLWIFI_DEBUG
1142static void iwl_dump_lq_cmd(struct iwl_priv *priv, 660static void iwl_dump_lq_cmd(struct iwl_priv *priv,
@@ -1240,223 +758,6 @@ int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1240} 758}
1241EXPORT_SYMBOL(iwl_send_lq_cmd); 759EXPORT_SYMBOL(iwl_send_lq_cmd);
1242 760
1243/**
1244 * iwl_alloc_bcast_station - add broadcast station into driver's station table.
1245 *
1246 * This adds the broadcast station into the driver's station table
1247 * and marks it driver active, so that it will be restored to the
1248 * device at the next best time.
1249 */
1250int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1251 bool init_lq)
1252{
1253 struct iwl_link_quality_cmd *link_cmd;
1254 unsigned long flags;
1255 u8 sta_id;
1256
1257 spin_lock_irqsave(&priv->sta_lock, flags);
1258 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
1259 if (sta_id == IWL_INVALID_STATION) {
1260 IWL_ERR(priv, "Unable to prepare broadcast station\n");
1261 spin_unlock_irqrestore(&priv->sta_lock, flags);
1262
1263 return -EINVAL;
1264 }
1265
1266 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
1267 priv->stations[sta_id].used |= IWL_STA_BCAST;
1268 spin_unlock_irqrestore(&priv->sta_lock, flags);
1269
1270 if (init_lq) {
1271 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1272 if (!link_cmd) {
1273 IWL_ERR(priv,
1274 "Unable to initialize rate scaling for bcast station.\n");
1275 return -ENOMEM;
1276 }
1277
1278 spin_lock_irqsave(&priv->sta_lock, flags);
1279 priv->stations[sta_id].lq = link_cmd;
1280 spin_unlock_irqrestore(&priv->sta_lock, flags);
1281 }
1282
1283 return 0;
1284}
1285EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station);
1286
1287/**
1288 * iwl_update_bcast_station - update broadcast station's LQ command
1289 *
1290 * Only used by iwlagn. Placed here to have all bcast station management
1291 * code together.
1292 */
1293static int iwl_update_bcast_station(struct iwl_priv *priv,
1294 struct iwl_rxon_context *ctx)
1295{
1296 unsigned long flags;
1297 struct iwl_link_quality_cmd *link_cmd;
1298 u8 sta_id = ctx->bcast_sta_id;
1299
1300 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1301 if (!link_cmd) {
1302 IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n");
1303 return -ENOMEM;
1304 }
1305
1306 spin_lock_irqsave(&priv->sta_lock, flags);
1307 if (priv->stations[sta_id].lq)
1308 kfree(priv->stations[sta_id].lq);
1309 else
1310 IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n");
1311 priv->stations[sta_id].lq = link_cmd;
1312 spin_unlock_irqrestore(&priv->sta_lock, flags);
1313
1314 return 0;
1315}
1316
1317int iwl_update_bcast_stations(struct iwl_priv *priv)
1318{
1319 struct iwl_rxon_context *ctx;
1320 int ret = 0;
1321
1322 for_each_context(priv, ctx) {
1323 ret = iwl_update_bcast_station(priv, ctx);
1324 if (ret)
1325 break;
1326 }
1327
1328 return ret;
1329}
1330EXPORT_SYMBOL_GPL(iwl_update_bcast_stations);
1331
1332void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
1333{
1334 unsigned long flags;
1335 int i;
1336
1337 spin_lock_irqsave(&priv->sta_lock, flags);
1338 for (i = 0; i < priv->hw_params.max_stations; i++) {
1339 if (!(priv->stations[i].used & IWL_STA_BCAST))
1340 continue;
1341
1342 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
1343 priv->num_stations--;
1344 BUG_ON(priv->num_stations < 0);
1345 kfree(priv->stations[i].lq);
1346 priv->stations[i].lq = NULL;
1347 }
1348 spin_unlock_irqrestore(&priv->sta_lock, flags);
1349}
1350EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations);
1351
1352/**
1353 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1354 */
1355int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
1356{
1357 unsigned long flags;
1358 struct iwl_addsta_cmd sta_cmd;
1359
1360 lockdep_assert_held(&priv->mutex);
1361
1362 /* Remove "disable" flag, to enable Tx for this TID */
1363 spin_lock_irqsave(&priv->sta_lock, flags);
1364 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
1365 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
1366 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1367 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1368 spin_unlock_irqrestore(&priv->sta_lock, flags);
1369
1370 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1371}
1372EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid);
1373
1374int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
1375 int tid, u16 ssn)
1376{
1377 unsigned long flags;
1378 int sta_id;
1379 struct iwl_addsta_cmd sta_cmd;
1380
1381 lockdep_assert_held(&priv->mutex);
1382
1383 sta_id = iwl_sta_id(sta);
1384 if (sta_id == IWL_INVALID_STATION)
1385 return -ENXIO;
1386
1387 spin_lock_irqsave(&priv->sta_lock, flags);
1388 priv->stations[sta_id].sta.station_flags_msk = 0;
1389 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
1390 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
1391 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
1392 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1393 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1394 spin_unlock_irqrestore(&priv->sta_lock, flags);
1395
1396 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1397}
1398EXPORT_SYMBOL(iwl_sta_rx_agg_start);
1399
1400int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
1401 int tid)
1402{
1403 unsigned long flags;
1404 int sta_id;
1405 struct iwl_addsta_cmd sta_cmd;
1406
1407 lockdep_assert_held(&priv->mutex);
1408
1409 sta_id = iwl_sta_id(sta);
1410 if (sta_id == IWL_INVALID_STATION) {
1411 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
1412 return -ENXIO;
1413 }
1414
1415 spin_lock_irqsave(&priv->sta_lock, flags);
1416 priv->stations[sta_id].sta.station_flags_msk = 0;
1417 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
1418 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
1419 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1420 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
1421 spin_unlock_irqrestore(&priv->sta_lock, flags);
1422
1423 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
1424}
1425EXPORT_SYMBOL(iwl_sta_rx_agg_stop);
1426
1427void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
1428{
1429 unsigned long flags;
1430
1431 spin_lock_irqsave(&priv->sta_lock, flags);
1432 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
1433 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1434 priv->stations[sta_id].sta.sta.modify_mask = 0;
1435 priv->stations[sta_id].sta.sleep_tx_count = 0;
1436 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1437 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1438 spin_unlock_irqrestore(&priv->sta_lock, flags);
1439
1440}
1441EXPORT_SYMBOL(iwl_sta_modify_ps_wake);
1442
1443void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
1444{
1445 unsigned long flags;
1446
1447 spin_lock_irqsave(&priv->sta_lock, flags);
1448 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
1449 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
1450 priv->stations[sta_id].sta.sta.modify_mask =
1451 STA_MODIFY_SLEEP_TX_COUNT_MSK;
1452 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
1453 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
1454 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
1455 spin_unlock_irqrestore(&priv->sta_lock, flags);
1456
1457}
1458EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count);
1459
1460int iwl_mac_sta_remove(struct ieee80211_hw *hw, 761int iwl_mac_sta_remove(struct ieee80211_hw *hw,
1461 struct ieee80211_vif *vif, 762 struct ieee80211_vif *vif,
1462 struct ieee80211_sta *sta) 763 struct ieee80211_sta *sta)
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index 56bad3f60d81..06475872eee4 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -43,35 +43,13 @@
43#define IWL_STA_BCAST BIT(4) /* this station is the special bcast station */ 43#define IWL_STA_BCAST BIT(4) /* this station is the special bcast station */
44 44
45 45
46int iwl_remove_default_wep_key(struct iwl_priv *priv,
47 struct iwl_rxon_context *ctx,
48 struct ieee80211_key_conf *key);
49int iwl_set_default_wep_key(struct iwl_priv *priv,
50 struct iwl_rxon_context *ctx,
51 struct ieee80211_key_conf *key);
52int iwl_restore_default_wep_keys(struct iwl_priv *priv,
53 struct iwl_rxon_context *ctx);
54int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
55 struct ieee80211_key_conf *key, u8 sta_id);
56int iwl_remove_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
57 struct ieee80211_key_conf *key, u8 sta_id);
58void iwl_update_tkip_key(struct iwl_priv *priv,
59 struct iwl_rxon_context *ctx,
60 struct ieee80211_key_conf *keyconf,
61 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key);
62
63void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx); 46void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
64void iwl_clear_ucode_stations(struct iwl_priv *priv, 47void iwl_clear_ucode_stations(struct iwl_priv *priv,
65 struct iwl_rxon_context *ctx); 48 struct iwl_rxon_context *ctx);
66int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
67 bool init_lq);
68void iwl_dealloc_bcast_stations(struct iwl_priv *priv); 49void iwl_dealloc_bcast_stations(struct iwl_priv *priv);
69int iwl_update_bcast_stations(struct iwl_priv *priv);
70int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 50int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
71int iwl_send_add_sta(struct iwl_priv *priv, 51int iwl_send_add_sta(struct iwl_priv *priv,
72 struct iwl_addsta_cmd *sta, u8 flags); 52 struct iwl_addsta_cmd *sta, u8 flags);
73int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
74 const u8 *addr, bool init_rs, u8 *sta_id_r);
75int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, 53int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
76 const u8 *addr, bool is_ap, 54 const u8 *addr, bool is_ap,
77 struct ieee80211_sta *sta, u8 *sta_id_r); 55 struct ieee80211_sta *sta, u8 *sta_id_r);
@@ -79,13 +57,12 @@ int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
79 const u8 *addr); 57 const u8 *addr);
80int iwl_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 58int iwl_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
81 struct ieee80211_sta *sta); 59 struct ieee80211_sta *sta);
82int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid); 60
83int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta, 61u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
84 int tid, u16 ssn); 62 const u8 *addr, bool is_ap, struct ieee80211_sta *sta);
85int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta, 63
86 int tid); 64int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
87void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id); 65 struct iwl_link_quality_cmd *lq, u8 flags, bool init);
88void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt);
89 66
90/** 67/**
91 * iwl_clear_driver_stations - clear knowledge of all stations from driver 68 * iwl_clear_driver_stations - clear knowledge of all stations from driver
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 64eb049140dc..c06b2189e09e 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -2661,12 +2661,33 @@ static void iwl3945_down(struct iwl_priv *priv)
2661 2661
2662#define MAX_HW_RESTARTS 5 2662#define MAX_HW_RESTARTS 5
2663 2663
2664static int iwl3945_alloc_bcast_station(struct iwl_priv *priv)
2665{
2666 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2667 unsigned long flags;
2668 u8 sta_id;
2669
2670 spin_lock_irqsave(&priv->sta_lock, flags);
2671 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
2672 if (sta_id == IWL_INVALID_STATION) {
2673 IWL_ERR(priv, "Unable to prepare broadcast station\n");
2674 spin_unlock_irqrestore(&priv->sta_lock, flags);
2675
2676 return -EINVAL;
2677 }
2678
2679 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
2680 priv->stations[sta_id].used |= IWL_STA_BCAST;
2681 spin_unlock_irqrestore(&priv->sta_lock, flags);
2682
2683 return 0;
2684}
2685
2664static int __iwl3945_up(struct iwl_priv *priv) 2686static int __iwl3945_up(struct iwl_priv *priv)
2665{ 2687{
2666 int rc, i; 2688 int rc, i;
2667 2689
2668 rc = iwl_alloc_bcast_station(priv, &priv->contexts[IWL_RXON_CTX_BSS], 2690 rc = iwl3945_alloc_bcast_station(priv);
2669 false);
2670 if (rc) 2691 if (rc)
2671 return rc; 2692 return rc;
2672 2693