blob: 057da2c3bf9521b7c7df92cd6181ffa0dc1c9788 [file] [log] [blame]
Wey-Yi Guybe663ab2011-02-21 11:27:26 -08001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2011 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-4965.h"
36
37static struct iwl_link_quality_cmd *
38iwl4965_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 |= iwl4965_first_antenna(priv->hw_params.valid_tx_ant) <<
61 RATE_MCS_ANT_POS;
62 rate_n_flags = iwl4965_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 iwl4965_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 ~iwl4965_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 (iwl4965_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 * iwl4965_add_bssid_station - Add the special IBSS BSSID station
90 *
91 * Function sleeps.
92 */
93int
94iwl4965_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
95 const u8 *addr, u8 *sta_id_r)
96{
97 int ret;
98 u8 sta_id;
99 struct iwl_link_quality_cmd *link_cmd;
100 unsigned long flags;
101
102 if (sta_id_r)
103 *sta_id_r = IWL_INVALID_STATION;
104
105 ret = iwl_legacy_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
106 if (ret) {
107 IWL_ERR(priv, "Unable to add station %pM\n", addr);
108 return ret;
109 }
110
111 if (sta_id_r)
112 *sta_id_r = sta_id;
113
114 spin_lock_irqsave(&priv->sta_lock, flags);
115 priv->stations[sta_id].used |= IWL_STA_LOCAL;
116 spin_unlock_irqrestore(&priv->sta_lock, flags);
117
118 /* Set up default rate scaling table in device's station table */
119 link_cmd = iwl4965_sta_alloc_lq(priv, sta_id);
120 if (!link_cmd) {
121 IWL_ERR(priv,
122 "Unable to initialize rate scaling for station %pM.\n",
123 addr);
124 return -ENOMEM;
125 }
126
127 ret = iwl_legacy_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
128 if (ret)
129 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
130
131 spin_lock_irqsave(&priv->sta_lock, flags);
132 priv->stations[sta_id].lq = link_cmd;
133 spin_unlock_irqrestore(&priv->sta_lock, flags);
134
135 return 0;
136}
137
138static int iwl4965_static_wepkey_cmd(struct iwl_priv *priv,
139 struct iwl_rxon_context *ctx,
140 bool send_if_empty)
141{
142 int i, not_empty = 0;
143 u8 buff[sizeof(struct iwl_wep_cmd) +
144 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
145 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
146 size_t cmd_size = sizeof(struct iwl_wep_cmd);
147 struct iwl_host_cmd cmd = {
148 .id = ctx->wep_key_cmd,
149 .data = wep_cmd,
150 .flags = CMD_SYNC,
151 };
152
153 might_sleep();
154
155 memset(wep_cmd, 0, cmd_size +
156 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
157
158 for (i = 0; i < WEP_KEYS_MAX ; i++) {
159 wep_cmd->key[i].key_index = i;
160 if (ctx->wep_keys[i].key_size) {
161 wep_cmd->key[i].key_offset = i;
162 not_empty = 1;
163 } else {
164 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
165 }
166
167 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
168 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
169 ctx->wep_keys[i].key_size);
170 }
171
172 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
173 wep_cmd->num_keys = WEP_KEYS_MAX;
174
175 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
176
177 cmd.len = cmd_size;
178
179 if (not_empty || send_if_empty)
180 return iwl_legacy_send_cmd(priv, &cmd);
181 else
182 return 0;
183}
184
185int iwl4965_restore_default_wep_keys(struct iwl_priv *priv,
186 struct iwl_rxon_context *ctx)
187{
188 lockdep_assert_held(&priv->mutex);
189
190 return iwl4965_static_wepkey_cmd(priv, ctx, false);
191}
192
193int iwl4965_remove_default_wep_key(struct iwl_priv *priv,
194 struct iwl_rxon_context *ctx,
195 struct ieee80211_key_conf *keyconf)
196{
197 int ret;
198
199 lockdep_assert_held(&priv->mutex);
200
201 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
202 keyconf->keyidx);
203
204 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
205 if (iwl_legacy_is_rfkill(priv)) {
206 IWL_DEBUG_WEP(priv,
207 "Not sending REPLY_WEPKEY command due to RFKILL.\n");
208 /* but keys in device are clear anyway so return success */
209 return 0;
210 }
211 ret = iwl4965_static_wepkey_cmd(priv, ctx, 1);
212 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
213 keyconf->keyidx, ret);
214
215 return ret;
216}
217
218int iwl4965_set_default_wep_key(struct iwl_priv *priv,
219 struct iwl_rxon_context *ctx,
220 struct ieee80211_key_conf *keyconf)
221{
222 int ret;
223
224 lockdep_assert_held(&priv->mutex);
225
226 if (keyconf->keylen != WEP_KEY_LEN_128 &&
227 keyconf->keylen != WEP_KEY_LEN_64) {
228 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
229 return -EINVAL;
230 }
231
232 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
233 keyconf->hw_key_idx = HW_KEY_DEFAULT;
234 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
235
236 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
237 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
238 keyconf->keylen);
239
240 ret = iwl4965_static_wepkey_cmd(priv, ctx, false);
241 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
242 keyconf->keylen, keyconf->keyidx, ret);
243
244 return ret;
245}
246
247static int iwl4965_set_wep_dynamic_key_info(struct iwl_priv *priv,
248 struct iwl_rxon_context *ctx,
249 struct ieee80211_key_conf *keyconf,
250 u8 sta_id)
251{
252 unsigned long flags;
253 __le16 key_flags = 0;
254 struct iwl_legacy_addsta_cmd sta_cmd;
255
256 lockdep_assert_held(&priv->mutex);
257
258 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
259
260 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
261 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
262 key_flags &= ~STA_KEY_FLG_INVALID;
263
264 if (keyconf->keylen == WEP_KEY_LEN_128)
265 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
266
267 if (sta_id == ctx->bcast_sta_id)
268 key_flags |= STA_KEY_MULTICAST_MSK;
269
270 spin_lock_irqsave(&priv->sta_lock, flags);
271
272 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
273 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
274 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
275
276 memcpy(priv->stations[sta_id].keyinfo.key,
277 keyconf->key, keyconf->keylen);
278
279 memcpy(&priv->stations[sta_id].sta.key.key[3],
280 keyconf->key, keyconf->keylen);
281
282 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
283 == STA_KEY_FLG_NO_ENC)
284 priv->stations[sta_id].sta.key.key_offset =
285 iwl_legacy_get_free_ucode_key_index(priv);
286 /* else, we are overriding an existing key => no need to allocated room
287 * in uCode. */
288
289 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
290 "no space for a new key");
291
292 priv->stations[sta_id].sta.key.key_flags = key_flags;
293 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
294 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
295
296 memcpy(&sta_cmd, &priv->stations[sta_id].sta,
297 sizeof(struct iwl_legacy_addsta_cmd));
298 spin_unlock_irqrestore(&priv->sta_lock, flags);
299
300 return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
301}
302
303static int iwl4965_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
304 struct iwl_rxon_context *ctx,
305 struct ieee80211_key_conf *keyconf,
306 u8 sta_id)
307{
308 unsigned long flags;
309 __le16 key_flags = 0;
310 struct iwl_legacy_addsta_cmd sta_cmd;
311
312 lockdep_assert_held(&priv->mutex);
313
314 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
315 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
316 key_flags &= ~STA_KEY_FLG_INVALID;
317
318 if (sta_id == ctx->bcast_sta_id)
319 key_flags |= STA_KEY_MULTICAST_MSK;
320
321 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
322
323 spin_lock_irqsave(&priv->sta_lock, flags);
324 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
325 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
326
327 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
328 keyconf->keylen);
329
330 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
331 keyconf->keylen);
332
333 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
334 == STA_KEY_FLG_NO_ENC)
335 priv->stations[sta_id].sta.key.key_offset =
336 iwl_legacy_get_free_ucode_key_index(priv);
337 /* else, we are overriding an existing key => no need to allocated room
338 * in uCode. */
339
340 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
341 "no space for a new key");
342
343 priv->stations[sta_id].sta.key.key_flags = key_flags;
344 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
345 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
346
347 memcpy(&sta_cmd, &priv->stations[sta_id].sta,
348 sizeof(struct iwl_legacy_addsta_cmd));
349 spin_unlock_irqrestore(&priv->sta_lock, flags);
350
351 return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
352}
353
354static int iwl4965_set_tkip_dynamic_key_info(struct iwl_priv *priv,
355 struct iwl_rxon_context *ctx,
356 struct ieee80211_key_conf *keyconf,
357 u8 sta_id)
358{
359 unsigned long flags;
360 int ret = 0;
361 __le16 key_flags = 0;
362
363 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
364 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
365 key_flags &= ~STA_KEY_FLG_INVALID;
366
367 if (sta_id == ctx->bcast_sta_id)
368 key_flags |= STA_KEY_MULTICAST_MSK;
369
370 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
371 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
372
373 spin_lock_irqsave(&priv->sta_lock, flags);
374
375 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
376 priv->stations[sta_id].keyinfo.keylen = 16;
377
378 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
379 == STA_KEY_FLG_NO_ENC)
380 priv->stations[sta_id].sta.key.key_offset =
381 iwl_legacy_get_free_ucode_key_index(priv);
382 /* else, we are overriding an existing key => no need to allocated room
383 * in uCode. */
384
385 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
386 "no space for a new key");
387
388 priv->stations[sta_id].sta.key.key_flags = key_flags;
389
390
391 /* This copy is acutally not needed: we get the key with each TX */
392 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
393
394 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
395
396 spin_unlock_irqrestore(&priv->sta_lock, flags);
397
398 return ret;
399}
400
401void iwl4965_update_tkip_key(struct iwl_priv *priv,
402 struct iwl_rxon_context *ctx,
403 struct ieee80211_key_conf *keyconf,
404 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
405{
406 u8 sta_id;
407 unsigned long flags;
408 int i;
409
410 if (iwl_legacy_scan_cancel(priv)) {
411 /* cancel scan failed, just live w/ bad key and rely
412 briefly on SW decryption */
413 return;
414 }
415
416 sta_id = iwl_legacy_sta_id_or_broadcast(priv, ctx, sta);
417 if (sta_id == IWL_INVALID_STATION)
418 return;
419
420 spin_lock_irqsave(&priv->sta_lock, flags);
421
422 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
423
424 for (i = 0; i < 5; i++)
425 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
426 cpu_to_le16(phase1key[i]);
427
428 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
429 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
430
431 iwl_legacy_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
432
433 spin_unlock_irqrestore(&priv->sta_lock, flags);
434
435}
436
437int iwl4965_remove_dynamic_key(struct iwl_priv *priv,
438 struct iwl_rxon_context *ctx,
439 struct ieee80211_key_conf *keyconf,
440 u8 sta_id)
441{
442 unsigned long flags;
443 u16 key_flags;
444 u8 keyidx;
445 struct iwl_legacy_addsta_cmd sta_cmd;
446
447 lockdep_assert_held(&priv->mutex);
448
449 ctx->key_mapping_keys--;
450
451 spin_lock_irqsave(&priv->sta_lock, flags);
452 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
453 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
454
455 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
456 keyconf->keyidx, sta_id);
457
458 if (keyconf->keyidx != keyidx) {
459 /* We need to remove a key with index different that the one
460 * in the uCode. This means that the key we need to remove has
461 * been replaced by another one with different index.
462 * Don't do anything and return ok
463 */
464 spin_unlock_irqrestore(&priv->sta_lock, flags);
465 return 0;
466 }
467
468 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
469 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
470 keyconf->keyidx, key_flags);
471 spin_unlock_irqrestore(&priv->sta_lock, flags);
472 return 0;
473 }
474
475 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
476 &priv->ucode_key_table))
477 IWL_ERR(priv, "index %d not used in uCode key table.\n",
478 priv->stations[sta_id].sta.key.key_offset);
479 memset(&priv->stations[sta_id].keyinfo, 0,
480 sizeof(struct iwl_hw_key));
481 memset(&priv->stations[sta_id].sta.key, 0,
482 sizeof(struct iwl4965_keyinfo));
483 priv->stations[sta_id].sta.key.key_flags =
484 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
485 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
486 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
487 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
488
489 if (iwl_legacy_is_rfkill(priv)) {
490 IWL_DEBUG_WEP(priv,
491 "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
492 spin_unlock_irqrestore(&priv->sta_lock, flags);
493 return 0;
494 }
495 memcpy(&sta_cmd, &priv->stations[sta_id].sta,
496 sizeof(struct iwl_legacy_addsta_cmd));
497 spin_unlock_irqrestore(&priv->sta_lock, flags);
498
499 return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
500}
501
502int iwl4965_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
503 struct ieee80211_key_conf *keyconf, u8 sta_id)
504{
505 int ret;
506
507 lockdep_assert_held(&priv->mutex);
508
509 ctx->key_mapping_keys++;
510 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
511
512 switch (keyconf->cipher) {
513 case WLAN_CIPHER_SUITE_CCMP:
514 ret = iwl4965_set_ccmp_dynamic_key_info(priv, ctx,
515 keyconf, sta_id);
516 break;
517 case WLAN_CIPHER_SUITE_TKIP:
518 ret = iwl4965_set_tkip_dynamic_key_info(priv, ctx,
519 keyconf, sta_id);
520 break;
521 case WLAN_CIPHER_SUITE_WEP40:
522 case WLAN_CIPHER_SUITE_WEP104:
523 ret = iwl4965_set_wep_dynamic_key_info(priv, ctx,
524 keyconf, sta_id);
525 break;
526 default:
527 IWL_ERR(priv,
528 "Unknown alg: %s cipher = %x\n", __func__,
529 keyconf->cipher);
530 ret = -EINVAL;
531 }
532
533 IWL_DEBUG_WEP(priv,
534 "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
535 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
536 sta_id, ret);
537
538 return ret;
539}
540
541/**
542 * iwl4965_alloc_bcast_station - add broadcast station into driver's station table.
543 *
544 * This adds the broadcast station into the driver's station table
545 * and marks it driver active, so that it will be restored to the
546 * device at the next best time.
547 */
548int iwl4965_alloc_bcast_station(struct iwl_priv *priv,
549 struct iwl_rxon_context *ctx)
550{
551 struct iwl_link_quality_cmd *link_cmd;
552 unsigned long flags;
553 u8 sta_id;
554
555 spin_lock_irqsave(&priv->sta_lock, flags);
556 sta_id = iwl_legacy_prep_station(priv, ctx, iwl_bcast_addr,
557 false, NULL);
558 if (sta_id == IWL_INVALID_STATION) {
559 IWL_ERR(priv, "Unable to prepare broadcast station\n");
560 spin_unlock_irqrestore(&priv->sta_lock, flags);
561
562 return -EINVAL;
563 }
564
565 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
566 priv->stations[sta_id].used |= IWL_STA_BCAST;
567 spin_unlock_irqrestore(&priv->sta_lock, flags);
568
569 link_cmd = iwl4965_sta_alloc_lq(priv, sta_id);
570 if (!link_cmd) {
571 IWL_ERR(priv,
572 "Unable to initialize rate scaling for bcast station.\n");
573 return -ENOMEM;
574 }
575
576 spin_lock_irqsave(&priv->sta_lock, flags);
577 priv->stations[sta_id].lq = link_cmd;
578 spin_unlock_irqrestore(&priv->sta_lock, flags);
579
580 return 0;
581}
582
583/**
584 * iwl4965_update_bcast_station - update broadcast station's LQ command
585 *
586 * Only used by iwl4965. Placed here to have all bcast station management
587 * code together.
588 */
589static int iwl4965_update_bcast_station(struct iwl_priv *priv,
590 struct iwl_rxon_context *ctx)
591{
592 unsigned long flags;
593 struct iwl_link_quality_cmd *link_cmd;
594 u8 sta_id = ctx->bcast_sta_id;
595
596 link_cmd = iwl4965_sta_alloc_lq(priv, sta_id);
597 if (!link_cmd) {
598 IWL_ERR(priv,
599 "Unable to initialize rate scaling for bcast station.\n");
600 return -ENOMEM;
601 }
602
603 spin_lock_irqsave(&priv->sta_lock, flags);
604 if (priv->stations[sta_id].lq)
605 kfree(priv->stations[sta_id].lq);
606 else
607 IWL_DEBUG_INFO(priv,
608 "Bcast station rate scaling has not been initialized yet.\n");
609 priv->stations[sta_id].lq = link_cmd;
610 spin_unlock_irqrestore(&priv->sta_lock, flags);
611
612 return 0;
613}
614
615int iwl4965_update_bcast_stations(struct iwl_priv *priv)
616{
617 struct iwl_rxon_context *ctx;
618 int ret = 0;
619
620 for_each_context(priv, ctx) {
621 ret = iwl4965_update_bcast_station(priv, ctx);
622 if (ret)
623 break;
624 }
625
626 return ret;
627}
628
629/**
630 * iwl4965_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
631 */
632int iwl4965_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
633{
634 unsigned long flags;
635 struct iwl_legacy_addsta_cmd sta_cmd;
636
637 lockdep_assert_held(&priv->mutex);
638
639 /* Remove "disable" flag, to enable Tx for this TID */
640 spin_lock_irqsave(&priv->sta_lock, flags);
641 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
642 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
643 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
644 memcpy(&sta_cmd, &priv->stations[sta_id].sta,
645 sizeof(struct iwl_legacy_addsta_cmd));
646 spin_unlock_irqrestore(&priv->sta_lock, flags);
647
648 return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
649}
650
651int iwl4965_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
652 int tid, u16 ssn)
653{
654 unsigned long flags;
655 int sta_id;
656 struct iwl_legacy_addsta_cmd sta_cmd;
657
658 lockdep_assert_held(&priv->mutex);
659
660 sta_id = iwl_legacy_sta_id(sta);
661 if (sta_id == IWL_INVALID_STATION)
662 return -ENXIO;
663
664 spin_lock_irqsave(&priv->sta_lock, flags);
665 priv->stations[sta_id].sta.station_flags_msk = 0;
666 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
667 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
668 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
669 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
670 memcpy(&sta_cmd, &priv->stations[sta_id].sta,
671 sizeof(struct iwl_legacy_addsta_cmd));
672 spin_unlock_irqrestore(&priv->sta_lock, flags);
673
674 return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
675}
676
677int iwl4965_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
678 int tid)
679{
680 unsigned long flags;
681 int sta_id;
682 struct iwl_legacy_addsta_cmd sta_cmd;
683
684 lockdep_assert_held(&priv->mutex);
685
686 sta_id = iwl_legacy_sta_id(sta);
687 if (sta_id == IWL_INVALID_STATION) {
688 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
689 return -ENXIO;
690 }
691
692 spin_lock_irqsave(&priv->sta_lock, flags);
693 priv->stations[sta_id].sta.station_flags_msk = 0;
694 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
695 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
696 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
697 memcpy(&sta_cmd, &priv->stations[sta_id].sta,
698 sizeof(struct iwl_legacy_addsta_cmd));
699 spin_unlock_irqrestore(&priv->sta_lock, flags);
700
701 return iwl_legacy_send_add_sta(priv, &sta_cmd, CMD_SYNC);
702}
703
704void
705iwl4965_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
706{
707 unsigned long flags;
708
709 spin_lock_irqsave(&priv->sta_lock, flags);
710 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
711 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
712 priv->stations[sta_id].sta.sta.modify_mask =
713 STA_MODIFY_SLEEP_TX_COUNT_MSK;
714 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
715 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
716 iwl_legacy_send_add_sta(priv,
717 &priv->stations[sta_id].sta, CMD_ASYNC);
718 spin_unlock_irqrestore(&priv->sta_lock, flags);
719
720}