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>
37 static struct iwl_link_quality_cmd *
38 iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, u8 sta_id)
41 struct iwl_link_quality_cmd *link_cmd;
45 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
47 IWL_ERR(priv, "Unable to allocate memory for LQ cmd.\n");
51 lockdep_assert_held(&priv->mutex);
53 /* Set up the rate scaling to start at selected rate, fall back
54 * all the way down to 1M in IEEE order, and then spin on 1M */
55 if (priv->band == IEEE80211_BAND_5GHZ)
56 r = IWL_RATE_6M_INDEX;
57 else if (ctx && ctx->vif && ctx->vif->p2p)
58 r = IWL_RATE_6M_INDEX;
60 r = IWL_RATE_1M_INDEX;
62 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
63 rate_flags |= RATE_MCS_CCK_MSK;
65 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
67 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
68 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
69 link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
71 link_cmd->general_params.single_stream_ant_msk =
72 first_antenna(priv->hw_params.valid_tx_ant);
74 link_cmd->general_params.dual_stream_ant_msk =
75 priv->hw_params.valid_tx_ant &
76 ~first_antenna(priv->hw_params.valid_tx_ant);
77 if (!link_cmd->general_params.dual_stream_ant_msk) {
78 link_cmd->general_params.dual_stream_ant_msk = ANT_AB;
79 } else if (num_of_ant(priv->hw_params.valid_tx_ant) == 2) {
80 link_cmd->general_params.dual_stream_ant_msk =
81 priv->hw_params.valid_tx_ant;
84 link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF;
85 link_cmd->agg_params.agg_time_limit =
86 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF);
88 link_cmd->sta_id = sta_id;
94 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
98 int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
99 const u8 *addr, u8 *sta_id_r)
103 struct iwl_link_quality_cmd *link_cmd;
107 *sta_id_r = IWL_INVALID_STATION;
109 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
111 IWL_ERR(priv, "Unable to add station %pM\n", addr);
118 spin_lock_irqsave(&priv->sta_lock, flags);
119 priv->stations[sta_id].used |= IWL_STA_LOCAL;
120 spin_unlock_irqrestore(&priv->sta_lock, flags);
122 /* Set up default rate scaling table in device's station table */
123 link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
125 IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n",
130 ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
132 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
134 spin_lock_irqsave(&priv->sta_lock, flags);
135 priv->stations[sta_id].lq = link_cmd;
136 spin_unlock_irqrestore(&priv->sta_lock, flags);
141 static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv,
142 struct iwl_rxon_context *ctx,
145 int i, not_empty = 0;
146 u8 buff[sizeof(struct iwl_wep_cmd) +
147 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
148 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
149 size_t cmd_size = sizeof(struct iwl_wep_cmd);
150 struct iwl_host_cmd cmd = {
151 .id = ctx->wep_key_cmd,
152 .data = { wep_cmd, },
158 memset(wep_cmd, 0, cmd_size +
159 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
161 for (i = 0; i < WEP_KEYS_MAX ; i++) {
162 wep_cmd->key[i].key_index = i;
163 if (ctx->wep_keys[i].key_size) {
164 wep_cmd->key[i].key_offset = i;
167 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
170 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
171 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
172 ctx->wep_keys[i].key_size);
175 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
176 wep_cmd->num_keys = WEP_KEYS_MAX;
178 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
180 cmd.len[0] = cmd_size;
182 if (not_empty || send_if_empty)
183 return iwl_send_cmd(priv, &cmd);
188 int iwl_restore_default_wep_keys(struct iwl_priv *priv,
189 struct iwl_rxon_context *ctx)
191 lockdep_assert_held(&priv->mutex);
193 return iwl_send_static_wepkey_cmd(priv, ctx, false);
196 int iwl_remove_default_wep_key(struct iwl_priv *priv,
197 struct iwl_rxon_context *ctx,
198 struct ieee80211_key_conf *keyconf)
202 lockdep_assert_held(&priv->mutex);
204 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
207 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
208 if (iwl_is_rfkill(priv)) {
209 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
210 /* but keys in device are clear anyway so return success */
213 ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
214 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
215 keyconf->keyidx, ret);
220 int iwl_set_default_wep_key(struct iwl_priv *priv,
221 struct iwl_rxon_context *ctx,
222 struct ieee80211_key_conf *keyconf)
226 lockdep_assert_held(&priv->mutex);
228 if (keyconf->keylen != WEP_KEY_LEN_128 &&
229 keyconf->keylen != WEP_KEY_LEN_64) {
230 IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen);
234 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
235 keyconf->hw_key_idx = HW_KEY_DEFAULT;
236 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
238 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
239 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
242 ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
243 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
244 keyconf->keylen, keyconf->keyidx, ret);
249 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
250 struct iwl_rxon_context *ctx,
251 struct ieee80211_key_conf *keyconf,
255 __le16 key_flags = 0;
256 struct iwl_addsta_cmd sta_cmd;
258 lockdep_assert_held(&priv->mutex);
260 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
262 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
263 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
264 key_flags &= ~STA_KEY_FLG_INVALID;
266 if (keyconf->keylen == WEP_KEY_LEN_128)
267 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
269 if (sta_id == ctx->bcast_sta_id)
270 key_flags |= STA_KEY_MULTICAST_MSK;
272 spin_lock_irqsave(&priv->sta_lock, flags);
274 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
275 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
276 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
278 memcpy(priv->stations[sta_id].keyinfo.key,
279 keyconf->key, keyconf->keylen);
281 memcpy(&priv->stations[sta_id].sta.key.key[3],
282 keyconf->key, keyconf->keylen);
284 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
285 == STA_KEY_FLG_NO_ENC)
286 priv->stations[sta_id].sta.key.key_offset =
287 iwl_get_free_ucode_key_index(priv);
288 /* else, we are overriding an existing key => no need to allocated room
291 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
292 "no space for a new key");
294 priv->stations[sta_id].sta.key.key_flags = key_flags;
295 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
296 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
298 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
299 spin_unlock_irqrestore(&priv->sta_lock, flags);
301 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
304 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
305 struct iwl_rxon_context *ctx,
306 struct ieee80211_key_conf *keyconf,
310 __le16 key_flags = 0;
311 struct iwl_addsta_cmd sta_cmd;
313 lockdep_assert_held(&priv->mutex);
315 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
316 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
317 key_flags &= ~STA_KEY_FLG_INVALID;
319 if (sta_id == ctx->bcast_sta_id)
320 key_flags |= STA_KEY_MULTICAST_MSK;
322 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
324 spin_lock_irqsave(&priv->sta_lock, flags);
325 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
326 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
328 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
331 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
334 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
335 == STA_KEY_FLG_NO_ENC)
336 priv->stations[sta_id].sta.key.key_offset =
337 iwl_get_free_ucode_key_index(priv);
338 /* else, we are overriding an existing key => no need to allocated room
341 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
342 "no space for a new key");
344 priv->stations[sta_id].sta.key.key_flags = key_flags;
345 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
346 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
348 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
349 spin_unlock_irqrestore(&priv->sta_lock, flags);
351 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
354 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
355 struct iwl_rxon_context *ctx,
356 struct ieee80211_key_conf *keyconf,
361 __le16 key_flags = 0;
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;
367 if (sta_id == ctx->bcast_sta_id)
368 key_flags |= STA_KEY_MULTICAST_MSK;
370 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
371 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
373 spin_lock_irqsave(&priv->sta_lock, flags);
375 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
376 priv->stations[sta_id].keyinfo.keylen = 16;
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_get_free_ucode_key_index(priv);
382 /* else, we are overriding an existing key => no need to allocated room
385 WARN(priv->stations[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
386 "no space for a new key");
388 priv->stations[sta_id].sta.key.key_flags = key_flags;
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);
394 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
396 spin_unlock_irqrestore(&priv->sta_lock, flags);
401 void iwl_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)
410 if (iwl_scan_cancel(priv)) {
411 /* cancel scan failed, just live w/ bad key and rely
412 briefly on SW decryption */
416 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
417 if (sta_id == IWL_INVALID_STATION)
420 spin_lock_irqsave(&priv->sta_lock, flags);
422 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
424 for (i = 0; i < 5; i++)
425 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
426 cpu_to_le16(phase1key[i]);
428 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
429 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
431 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
433 spin_unlock_irqrestore(&priv->sta_lock, flags);
437 int iwl_remove_dynamic_key(struct iwl_priv *priv,
438 struct iwl_rxon_context *ctx,
439 struct ieee80211_key_conf *keyconf,
445 struct iwl_addsta_cmd sta_cmd;
447 lockdep_assert_held(&priv->mutex);
449 ctx->key_mapping_keys--;
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;
455 IWL_DEBUG_WEP(priv, "Remove dynamic key: idx=%d sta=%d\n",
456 keyconf->keyidx, sta_id);
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
464 spin_unlock_irqrestore(&priv->sta_lock, flags);
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);
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 iwl_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;
489 if (iwl_is_rfkill(priv)) {
490 IWL_DEBUG_WEP(priv, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
491 spin_unlock_irqrestore(&priv->sta_lock, flags);
494 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
495 spin_unlock_irqrestore(&priv->sta_lock, flags);
497 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
500 int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
501 struct ieee80211_key_conf *keyconf, u8 sta_id)
505 lockdep_assert_held(&priv->mutex);
507 ctx->key_mapping_keys++;
508 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
510 switch (keyconf->cipher) {
511 case WLAN_CIPHER_SUITE_CCMP:
512 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
514 case WLAN_CIPHER_SUITE_TKIP:
515 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
517 case WLAN_CIPHER_SUITE_WEP40:
518 case WLAN_CIPHER_SUITE_WEP104:
519 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
523 "Unknown alg: %s cipher = %x\n", __func__,
528 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
529 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
536 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
538 * This adds the broadcast station into the driver's station table
539 * and marks it driver active, so that it will be restored to the
540 * device at the next best time.
542 int iwlagn_alloc_bcast_station(struct iwl_priv *priv,
543 struct iwl_rxon_context *ctx)
545 struct iwl_link_quality_cmd *link_cmd;
549 spin_lock_irqsave(&priv->sta_lock, flags);
550 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
551 if (sta_id == IWL_INVALID_STATION) {
552 IWL_ERR(priv, "Unable to prepare broadcast station\n");
553 spin_unlock_irqrestore(&priv->sta_lock, flags);
558 priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE;
559 priv->stations[sta_id].used |= IWL_STA_BCAST;
560 spin_unlock_irqrestore(&priv->sta_lock, flags);
562 link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
565 "Unable to initialize rate scaling for bcast station.\n");
569 spin_lock_irqsave(&priv->sta_lock, flags);
570 priv->stations[sta_id].lq = link_cmd;
571 spin_unlock_irqrestore(&priv->sta_lock, flags);
577 * iwl_update_bcast_station - update broadcast station's LQ command
579 * Only used by iwlagn. Placed here to have all bcast station management
582 int iwl_update_bcast_station(struct iwl_priv *priv,
583 struct iwl_rxon_context *ctx)
586 struct iwl_link_quality_cmd *link_cmd;
587 u8 sta_id = ctx->bcast_sta_id;
589 link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id);
591 IWL_ERR(priv, "Unable to initialize rate scaling for bcast station.\n");
595 spin_lock_irqsave(&priv->sta_lock, flags);
596 if (priv->stations[sta_id].lq)
597 kfree(priv->stations[sta_id].lq);
599 IWL_DEBUG_INFO(priv, "Bcast station rate scaling has not been initialized yet.\n");
600 priv->stations[sta_id].lq = link_cmd;
601 spin_unlock_irqrestore(&priv->sta_lock, flags);
606 int iwl_update_bcast_stations(struct iwl_priv *priv)
608 struct iwl_rxon_context *ctx;
611 for_each_context(priv, ctx) {
612 ret = iwl_update_bcast_station(priv, ctx);
621 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
623 int iwl_sta_tx_modify_enable_tid(struct iwl_priv *priv, int sta_id, int tid)
626 struct iwl_addsta_cmd sta_cmd;
628 lockdep_assert_held(&priv->mutex);
630 /* Remove "disable" flag, to enable Tx for this TID */
631 spin_lock_irqsave(&priv->sta_lock, flags);
632 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
633 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
634 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
635 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
636 spin_unlock_irqrestore(&priv->sta_lock, flags);
638 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
641 int iwl_sta_rx_agg_start(struct iwl_priv *priv, struct ieee80211_sta *sta,
646 struct iwl_addsta_cmd sta_cmd;
648 lockdep_assert_held(&priv->mutex);
650 sta_id = iwl_sta_id(sta);
651 if (sta_id == IWL_INVALID_STATION)
654 spin_lock_irqsave(&priv->sta_lock, flags);
655 priv->stations[sta_id].sta.station_flags_msk = 0;
656 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
657 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
658 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
659 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
660 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
661 spin_unlock_irqrestore(&priv->sta_lock, flags);
663 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
666 int iwl_sta_rx_agg_stop(struct iwl_priv *priv, struct ieee80211_sta *sta,
671 struct iwl_addsta_cmd sta_cmd;
673 lockdep_assert_held(&priv->mutex);
675 sta_id = iwl_sta_id(sta);
676 if (sta_id == IWL_INVALID_STATION) {
677 IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid);
681 spin_lock_irqsave(&priv->sta_lock, flags);
682 priv->stations[sta_id].sta.station_flags_msk = 0;
683 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
684 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
685 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
686 memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd));
687 spin_unlock_irqrestore(&priv->sta_lock, flags);
689 return iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC);
692 static void iwl_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
696 spin_lock_irqsave(&priv->sta_lock, flags);
697 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
698 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
699 priv->stations[sta_id].sta.sta.modify_mask = 0;
700 priv->stations[sta_id].sta.sleep_tx_count = 0;
701 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
702 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
703 spin_unlock_irqrestore(&priv->sta_lock, flags);
707 void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt)
711 spin_lock_irqsave(&priv->sta_lock, flags);
712 priv->stations[sta_id].sta.station_flags |= STA_FLG_PWR_SAVE_MSK;
713 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
714 priv->stations[sta_id].sta.sta.modify_mask =
715 STA_MODIFY_SLEEP_TX_COUNT_MSK;
716 priv->stations[sta_id].sta.sleep_tx_count = cpu_to_le16(cnt);
717 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
718 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
719 spin_unlock_irqrestore(&priv->sta_lock, flags);
723 void iwlagn_mac_sta_notify(struct ieee80211_hw *hw,
724 struct ieee80211_vif *vif,
725 enum sta_notify_cmd cmd,
726 struct ieee80211_sta *sta)
728 struct iwl_priv *priv = hw->priv;
729 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
733 case STA_NOTIFY_SLEEP:
734 WARN_ON(!sta_priv->client);
735 sta_priv->asleep = true;
736 if (atomic_read(&sta_priv->pending_frames) > 0)
737 ieee80211_sta_block_awake(hw, sta, true);
739 case STA_NOTIFY_AWAKE:
740 WARN_ON(!sta_priv->client);
741 if (!sta_priv->asleep)
743 sta_priv->asleep = false;
744 sta_id = iwl_sta_id(sta);
745 if (sta_id != IWL_INVALID_STATION)
746 iwl_sta_modify_ps_wake(priv, sta_id);