1 /******************************************************************************
3 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
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.
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
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
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
28 *****************************************************************************/
30 #include <net/mac80211.h>
36 #include "iwl-trans.h"
38 static struct iwl_link_quality_cmd *
39 iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, u8 sta_id)
42 struct iwl_link_quality_cmd *link_cmd;
46 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
48 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
52 lockdep_assert_held(&priv->mutex);
54 /* Set up the rate scaling to start at selected rate, fall back
55 * all the way down to 1M in IEEE order, and then spin on 1M */
56 if (priv->band == IEEE80211_BAND_5GHZ)
57 r = IWL_RATE_6M_INDEX;
58 else if (ctx && ctx->vif && ctx->vif->p2p)
59 r = IWL_RATE_6M_INDEX;
61 r = IWL_RATE_1M_INDEX;
63 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
64 rate_flags |= RATE_MCS_CCK_MSK;
66 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
68 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
69 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
70 link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
72 link_cmd->general_params.single_stream_ant_msk =
73 first_antenna(priv->hw_params.valid_tx_ant);
75 link_cmd->general_params.dual_stream_ant_msk =
76 priv->hw_params.valid_tx_ant &
77 ~first_antenna(priv->hw_params.valid_tx_ant);
78 if (!link_cmd->general_params.dual_stream_ant_msk) {
79 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
80 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
81 link_cmd->general_params.dual_stream_ant_msk =
82 priv->hw_params.valid_tx_ant;
85 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
86 link_cmd->agg_params.agg_time_limit =
87 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
89 link_cmd->sta_id = sta_id;
95 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
99 int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
100 const u8 *addr, u8 *sta_id_r)
104 struct iwl_link_quality_cmd *link_cmd;
108 *sta_id_r = IWL_INVALID_STATION;
110 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
112 IWL_ERR(priv, "Unable to add station %pM\n", addr);
119 spin_lock_irqsave(&priv->sta_lock, flags);
120 priv->stations[sta_id].used |= IWL_STA_LOCAL;
121 spin_unlock_irqrestore(&priv->sta_lock, flags);
123 /* Set up default rate scaling table in device's station table */
124 link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
126 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
131 ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
133 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
135 spin_lock_irqsave(&priv->sta_lock, flags);
136 priv->stations[sta_id].lq = link_cmd;
137 spin_unlock_irqrestore(&priv->sta_lock, flags);
142 static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv,
143 struct iwl_rxon_context *ctx,
146 int i, not_empty = 0;
147 u8 buff[sizeof(struct iwl_wep_cmd) +
148 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
149 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
150 size_t cmd_size = sizeof(struct iwl_wep_cmd);
151 struct iwl_host_cmd cmd = {
152 .id = ctx->wep_key_cmd,
153 .data = { wep_cmd, },
159 memset(wep_cmd, 0, cmd_size +
160 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
162 for (i = 0; i < WEP_KEYS_MAX ; i++) {
163 wep_cmd->key[i].key_index = i;
164 if (ctx->wep_keys[i].key_size) {
165 wep_cmd->key[i].key_offset = i;
168 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
171 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
172 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
173 ctx->wep_keys[i].key_size);
176 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
177 wep_cmd->num_keys = WEP_KEYS_MAX;
179 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
181 cmd.len[0] = cmd_size;
183 if (not_empty || send_if_empty)
184 return trans_send_cmd(priv, &cmd);
189 int iwl_restore_default_wep_keys(struct iwl_priv *priv,
190 struct iwl_rxon_context *ctx)
192 lockdep_assert_held(&priv->mutex);
194 return iwl_send_static_wepkey_cmd(priv, ctx, false);
197 int iwl_remove_default_wep_key(struct iwl_priv *priv,
198 struct iwl_rxon_context *ctx,
199 struct ieee80211_key_conf *keyconf)
203 lockdep_assert_held(&priv->mutex);
205 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
208 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
209 if (iwl_is_rfkill(priv)) {
210 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
211 /* but keys in device are clear anyway so return success */
214 ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
215 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
216 keyconf->keyidx, ret);
221 int iwl_set_default_wep_key(struct iwl_priv *priv,
222 struct iwl_rxon_context *ctx,
223 struct ieee80211_key_conf *keyconf)
227 lockdep_assert_held(&priv->mutex);
229 if (keyconf->keylen != WEP_KEY_LEN_128 &&
230 keyconf->keylen != WEP_KEY_LEN_64) {
231 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
235 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
236 keyconf->hw_key_idx = HW_KEY_DEFAULT;
237 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
239 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
240 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
243 ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
244 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
245 keyconf->keylen, keyconf->keyidx, ret);
250 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
251 struct iwl_rxon_context *ctx,
252 struct ieee80211_key_conf *keyconf,
256 __le16 key_flags = 0;
257 struct iwl_addsta_cmd sta_cmd;
259 lockdep_assert_held(&priv->mutex);
261 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
263 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
264 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
265 key_flags &= ~STA_KEY_FLG_INVALID;
267 if (keyconf->keylen == WEP_KEY_LEN_128)
268 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
270 if (sta_id == ctx->bcast_sta_id)
271 key_flags |= STA_KEY_MULTICAST_MSK;
273 spin_lock_irqsave(&priv->sta_lock, flags);
275 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
276 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
277 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
279 memcpy(priv->stations[sta_id].keyinfo.key,
280 keyconf->key, keyconf->keylen);
282 memcpy(&priv->stations[sta_id].sta.key.key[3],
283 keyconf->key, keyconf->keylen);
285 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
286 == STA_KEY_FLG_NO_ENC)
287 priv->stations[sta_id].sta.key.key_offset =
288 iwl_get_free_ucode_key_index(priv);
289 /* else, we are overriding an existing key => no need to allocated room
292 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
293 "no space for a new key");
295 priv->stations[sta_id].sta.key.key_flags = key_flags;
296 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
297 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
299 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
300 spin_unlock_irqrestore(&priv->sta_lock, flags);
302 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
305 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
306 struct iwl_rxon_context *ctx,
307 struct ieee80211_key_conf *keyconf,
311 __le16 key_flags = 0;
312 struct iwl_addsta_cmd sta_cmd;
314 lockdep_assert_held(&priv->mutex);
316 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
317 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
318 key_flags &= ~STA_KEY_FLG_INVALID;
320 if (sta_id == ctx->bcast_sta_id)
321 key_flags |= STA_KEY_MULTICAST_MSK;
323 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
325 spin_lock_irqsave(&priv->sta_lock, flags);
326 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
327 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
329 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
332 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
335 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
336 == STA_KEY_FLG_NO_ENC)
337 priv->stations[sta_id].sta.key.key_offset =
338 iwl_get_free_ucode_key_index(priv);
339 /* else, we are overriding an existing key => no need to allocated room
342 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
343 "no space for a new key");
345 priv->stations[sta_id].sta.key.key_flags = key_flags;
346 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
347 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
349 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
350 spin_unlock_irqrestore(&priv->sta_lock, flags);
352 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
355 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
356 struct iwl_rxon_context *ctx,
357 struct ieee80211_key_conf *keyconf,
362 __le16 key_flags = 0;
364 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
365 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
366 key_flags &= ~STA_KEY_FLG_INVALID;
368 if (sta_id == ctx->bcast_sta_id)
369 key_flags |= STA_KEY_MULTICAST_MSK;
371 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
372 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
374 spin_lock_irqsave(&priv->sta_lock, flags);
376 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
377 priv->stations[sta_id].keyinfo.keylen = 16;
379 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
380 == STA_KEY_FLG_NO_ENC)
381 priv->stations[sta_id].sta.key.key_offset =
382 iwl_get_free_ucode_key_index(priv);
383 /* else, we are overriding an existing key => no need to allocated room
386 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
387 "no space for a new key");
389 priv->stations[sta_id].sta.key.key_flags = key_flags;
392 /* This copy is acutally not needed: we get the key with each TX */
393 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
395 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
397 spin_unlock_irqrestore(&priv->sta_lock, flags);
402 void iwl_update_tkip_key(struct iwl_priv *priv,
403 struct iwl_rxon_context *ctx,
404 struct ieee80211_key_conf *keyconf,
405 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
411 if (iwl_scan_cancel(priv)) {
412 /* cancel scan failed, just live w/ bad key and rely
413 briefly on SW decryption */
417 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
418 if (sta_id == IWL_INVALID_STATION)
421 spin_lock_irqsave(&priv->sta_lock, flags);
423 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
425 for (i = 0; i < 5; i++)
426 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
427 cpu_to_le16(phase1key[i]);
429 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
430 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
432 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
434 spin_unlock_irqrestore(&priv->sta_lock, flags);
438 int iwl_remove_dynamic_key(struct iwl_priv *priv,
439 struct iwl_rxon_context *ctx,
440 struct ieee80211_key_conf *keyconf,
446 struct iwl_addsta_cmd sta_cmd;
448 lockdep_assert_held(&priv->mutex);
450 ctx->key_mapping_keys--;
452 spin_lock_irqsave(&priv->sta_lock, flags);
453 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
454 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
456 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
457 keyconf->keyidx, sta_id);
459 if (keyconf->keyidx != keyidx) {
460 /* We need to remove a key with index different that the one
461 * in the uCode. This means that the key we need to remove has
462 * been replaced by another one with different index.
463 * Don't do anything and return ok
465 spin_unlock_irqrestore(&priv->sta_lock, flags);
469 if (priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET) {
470 IWL_WARN(priv, "Removing wrong key %d 0x%x\n",
471 keyconf->keyidx, key_flags);
472 spin_unlock_irqrestore(&priv->sta_lock, flags);
476 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
477 &priv->ucode_key_table))
478 IWL_ERR(priv, "index %d not used in uCode key table.\n",
479 priv->stations[sta_id].sta.key.key_offset);
480 memset(&priv->stations[sta_id].keyinfo, 0,
481 sizeof(struct iwl_hw_key));
482 memset(&priv->stations[sta_id].sta.key, 0,
483 sizeof(struct iwl_keyinfo));
484 priv->stations[sta_id].sta.key.key_flags =
485 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
486 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
487 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
488 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
490 if (iwl_is_rfkill(priv)) {
491 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
492 spin_unlock_irqrestore(&priv->sta_lock, flags);
495 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
496 spin_unlock_irqrestore(&priv->sta_lock, flags);
498 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
501 int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
502 struct ieee80211_key_conf *keyconf, u8 sta_id)
506 lockdep_assert_held(&priv->mutex);
508 ctx->key_mapping_keys++;
509 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
511 switch (keyconf->cipher) {
512 case WLAN_CIPHER_SUITE_CCMP:
513 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
515 case WLAN_CIPHER_SUITE_TKIP:
516 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
518 case WLAN_CIPHER_SUITE_WEP40:
519 case WLAN_CIPHER_SUITE_WEP104:
520 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
524 "Unknown alg: %s cipher = %x\n", __func__,
529 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
530 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
537 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
539 * This adds the broadcast station into the driver's station table
540 * and marks it driver active, so that it will be restored to the
541 * device at the next best time.
543 int iwlagn_alloc_bcast_station(struct iwl_priv *priv,
544 struct iwl_rxon_context *ctx)
546 struct iwl_link_quality_cmd *link_cmd;
550 spin_lock_irqsave(&priv->sta_lock, flags);
551 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
552 if (sta_id == IWL_INVALID_STATION) {
553 IWL_ERR(priv, "Unable to prepare broadcast station\n");
554 spin_unlock_irqrestore(&priv->sta_lock, flags);
559 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
560 priv->stations[sta_id].used |= IWL_STA_BCAST;
561 spin_unlock_irqrestore(&priv->sta_lock, flags);
563 link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
566 "Unable to initialize rate scaling for bcast station.\n");
570 spin_lock_irqsave(&priv->sta_lock, flags);
571 priv->stations[sta_id].lq = link_cmd;
572 spin_unlock_irqrestore(&priv->sta_lock, flags);
578 * iwl_update_bcast_station - update broadcast station's LQ command
580 * Only used by iwlagn. Placed here to have all bcast station management
583 int iwl_update_bcast_station(struct iwl_priv *priv,
584 struct iwl_rxon_context *ctx)
587 struct iwl_link_quality_cmd *link_cmd;
588 u8 sta_id = ctx->bcast_sta_id;
590 link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
592 IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n");
596 spin_lock_irqsave(&priv->sta_lock, flags);
597 if (priv->stations[sta_id].lq)
598 kfree(priv->stations[sta_id].lq);
600 IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n");
601 priv->stations[sta_id].lq = link_cmd;
602 spin_unlock_irqrestore(&priv->sta_lock, flags);
607 int iwl_update_bcast_stations(struct iwl_priv *priv)
609 struct iwl_rxon_context *ctx;
612 for_each_context(priv, ctx) {
613 ret = iwl_update_bcast_station(priv, ctx);
622 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
624 int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
627 struct iwl_addsta_cmd sta_cmd;
629 lockdep_assert_held(&priv->mutex);
631 /* Remove "disable" flag, to enable Tx for this TID */
632 spin_lock_irqsave(&priv->sta_lock, flags);
633 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
634 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
635 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
636 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
637 spin_unlock_irqrestore(&priv->sta_lock, flags);
639 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
642 int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
647 struct iwl_addsta_cmd sta_cmd;
649 lockdep_assert_held(&priv->mutex);
651 sta_id = iwl_sta_id(sta);
652 if (sta_id == IWL_INVALID_STATION)
655 spin_lock_irqsave(&priv->sta_lock, flags);
656 priv->stations[sta_id].sta.station_flags_msk = 0;
657 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
658 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
659 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
660 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
661 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
662 spin_unlock_irqrestore(&priv->sta_lock, flags);
664 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
667 int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
672 struct iwl_addsta_cmd sta_cmd;
674 lockdep_assert_held(&priv->mutex);
676 sta_id = iwl_sta_id(sta);
677 if (sta_id == IWL_INVALID_STATION) {
678 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
682 spin_lock_irqsave(&priv->sta_lock, flags);
683 priv->stations[sta_id].sta.station_flags_msk = 0;
684 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
685 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
686 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
687 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
688 spin_unlock_irqrestore(&priv->sta_lock, flags);
690 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
693 static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
697 spin_lock_irqsave(&priv->sta_lock, flags);
698 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
699 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
700 priv->stations[sta_id].sta.sta.modify_mask = 0;
701 priv->stations[sta_id].sta.sleep_tx_count = 0;
702 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
703 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
704 spin_unlock_irqrestore(&priv->sta_lock, flags);
708 void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
712 spin_lock_irqsave(&priv->sta_lock, flags);
713 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
714 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
715 priv->stations[sta_id].sta.sta.modify_mask =
716 STA_MODIFY_SLEEP_TX_COUNT_MSK;
717 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
718 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
719 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
720 spin_unlock_irqrestore(&priv->sta_lock, flags);
724 void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
725 struct ieee80211_vif *vif,
726 enum sta_notify_cmd cmd,
727 struct ieee80211_sta *sta)
729 struct iwl_priv *priv = hw->priv;
730 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
734 case STA_NOTIFY_SLEEP:
735 WARN_ON(!sta_priv->client);
736 sta_priv->asleep = true;
737 if (atomic_read(&sta_priv->pending_frames) > 0)
738 ieee80211_sta_block_awake(hw, sta, true);
740 case STA_NOTIFY_AWAKE:
741 WARN_ON(!sta_priv->client);
742 if (!sta_priv->asleep)
744 sta_priv->asleep = false;
745 sta_id = iwl_sta_id(sta);
746 if (sta_id != IWL_INVALID_STATION)
747 iwl_sta_modify_ps_wake(priv, sta_id);