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 void iwl_sta_fill_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
39 u8 sta_id
, struct iwl_link_quality_cmd
*link_cmd
)
45 lockdep_assert_held(&priv
->shrd
->mutex
);
47 memset(link_cmd
, 0, sizeof(*link_cmd
));
49 /* Set up the rate scaling to start at selected rate, fall back
50 * all the way down to 1M in IEEE order, and then spin on 1M */
51 if (priv
->band
== IEEE80211_BAND_5GHZ
)
52 r
= IWL_RATE_6M_INDEX
;
53 else if (ctx
&& ctx
->vif
&& ctx
->vif
->p2p
)
54 r
= IWL_RATE_6M_INDEX
;
56 r
= IWL_RATE_1M_INDEX
;
58 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
59 rate_flags
|= RATE_MCS_CCK_MSK
;
61 rate_flags
|= first_antenna(hw_params(priv
).valid_tx_ant
) <<
63 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
64 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
65 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
67 link_cmd
->general_params
.single_stream_ant_msk
=
68 first_antenna(hw_params(priv
).valid_tx_ant
);
70 link_cmd
->general_params
.dual_stream_ant_msk
=
71 hw_params(priv
).valid_tx_ant
&
72 ~first_antenna(hw_params(priv
).valid_tx_ant
);
73 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
74 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
75 } else if (num_of_ant(hw_params(priv
).valid_tx_ant
) == 2) {
76 link_cmd
->general_params
.dual_stream_ant_msk
=
77 hw_params(priv
).valid_tx_ant
;
80 link_cmd
->agg_params
.agg_dis_start_th
= LINK_QUAL_AGG_DISABLE_START_DEF
;
81 link_cmd
->agg_params
.agg_time_limit
=
82 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
84 link_cmd
->sta_id
= sta_id
;
87 static struct iwl_link_quality_cmd
*
88 iwl_sta_alloc_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
, u8 sta_id
)
90 struct iwl_link_quality_cmd
*link_cmd
;
92 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
94 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
98 iwl_sta_fill_lq(priv
, ctx
, sta_id
, link_cmd
);
104 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
108 int iwlagn_add_bssid_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
109 const u8
*addr
, u8
*sta_id_r
)
113 struct iwl_link_quality_cmd
*link_cmd
;
117 *sta_id_r
= IWL_INVALID_STATION
;
119 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
121 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
128 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
129 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
130 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
132 /* Set up default rate scaling table in device's station table */
133 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
135 IWL_ERR(priv
, "Unable to initialize rate scaling for station %pM.\n",
140 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
142 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
144 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
145 priv
->stations
[sta_id
].lq
= link_cmd
;
146 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
154 * For each context, the device has a table of 4 static WEP keys
155 * (one for each key index) that is updated with the following
159 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
160 struct iwl_rxon_context
*ctx
,
163 int i
, not_empty
= 0;
164 u8 buff
[sizeof(struct iwl_wep_cmd
) +
165 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
166 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
167 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
168 struct iwl_host_cmd cmd
= {
169 .id
= ctx
->wep_key_cmd
,
170 .data
= { wep_cmd
, },
176 memset(wep_cmd
, 0, cmd_size
+
177 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
179 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
180 wep_cmd
->key
[i
].key_index
= i
;
181 if (ctx
->wep_keys
[i
].key_size
) {
182 wep_cmd
->key
[i
].key_offset
= i
;
185 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
188 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
189 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
190 ctx
->wep_keys
[i
].key_size
);
193 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
194 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
196 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
198 cmd
.len
[0] = cmd_size
;
200 if (not_empty
|| send_if_empty
)
201 return iwl_trans_send_cmd(trans(priv
), &cmd
);
206 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
207 struct iwl_rxon_context
*ctx
)
209 lockdep_assert_held(&priv
->shrd
->mutex
);
211 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
214 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
215 struct iwl_rxon_context
*ctx
,
216 struct ieee80211_key_conf
*keyconf
)
220 lockdep_assert_held(&priv
->shrd
->mutex
);
222 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
225 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
226 if (iwl_is_rfkill(priv
->shrd
)) {
227 IWL_DEBUG_WEP(priv
, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
228 /* but keys in device are clear anyway so return success */
231 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
232 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
233 keyconf
->keyidx
, ret
);
238 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
239 struct iwl_rxon_context
*ctx
,
240 struct ieee80211_key_conf
*keyconf
)
244 lockdep_assert_held(&priv
->shrd
->mutex
);
246 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
247 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
248 IWL_DEBUG_WEP(priv
, "Bad WEP key length %d\n", keyconf
->keylen
);
252 keyconf
->hw_key_idx
= IWLAGN_HW_KEY_DEFAULT
;
254 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
255 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
258 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
259 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
260 keyconf
->keylen
, keyconf
->keyidx
, ret
);
266 * dynamic (per-station) keys
268 * The dynamic keys are a little more complicated. The device has
269 * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
270 * These are linked to stations by a table that contains an index
271 * into the key table for each station/key index/{mcast,unicast},
272 * i.e. it's basically an array of pointers like this:
273 * key_offset_t key_mapping[NUM_STATIONS][4][2];
274 * (it really works differently, but you can think of it as such)
276 * The key uploading and linking happens in the same command, the
277 * add station command with STA_MODIFY_KEY_MASK.
280 static u8
iwlagn_key_sta_id(struct iwl_priv
*priv
,
281 struct ieee80211_vif
*vif
,
282 struct ieee80211_sta
*sta
)
284 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
285 u8 sta_id
= IWL_INVALID_STATION
;
288 sta_id
= iwl_sta_id(sta
);
291 * The device expects GTKs for station interfaces to be
292 * installed as GTKs for the AP station. If we have no
293 * station ID, then use the ap_sta_id in that case.
295 if (!sta
&& vif
&& vif_priv
->ctx
) {
297 case NL80211_IFTYPE_STATION
:
298 sta_id
= vif_priv
->ctx
->ap_sta_id
;
302 * In all other cases, the key will be
303 * used either for TX only or is bound
304 * to a station already.
313 static int iwlagn_send_sta_key(struct iwl_priv
*priv
,
314 struct ieee80211_key_conf
*keyconf
,
315 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
320 struct iwl_addsta_cmd sta_cmd
;
323 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
324 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
325 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
327 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
328 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
;
330 switch (keyconf
->cipher
) {
331 case WLAN_CIPHER_SUITE_CCMP
:
332 key_flags
|= STA_KEY_FLG_CCMP
;
333 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
335 case WLAN_CIPHER_SUITE_TKIP
:
336 key_flags
|= STA_KEY_FLG_TKIP
;
337 sta_cmd
.key
.tkip_rx_tsc_byte2
= tkip_iv32
;
338 for (i
= 0; i
< 5; i
++)
339 sta_cmd
.key
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
340 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
342 case WLAN_CIPHER_SUITE_WEP104
:
343 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
345 case WLAN_CIPHER_SUITE_WEP40
:
346 key_flags
|= STA_KEY_FLG_WEP
;
347 memcpy(&sta_cmd
.key
.key
[3], keyconf
->key
, keyconf
->keylen
);
354 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
355 key_flags
|= STA_KEY_MULTICAST_MSK
;
357 /* key pointer (offset) */
358 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
360 sta_cmd
.key
.key_flags
= key_flags
;
361 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
362 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
364 return iwl_send_add_sta(priv
, &sta_cmd
, cmd_flags
);
367 void iwl_update_tkip_key(struct iwl_priv
*priv
,
368 struct ieee80211_vif
*vif
,
369 struct ieee80211_key_conf
*keyconf
,
370 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
372 u8 sta_id
= iwlagn_key_sta_id(priv
, vif
, sta
);
374 if (sta_id
== IWL_INVALID_STATION
)
377 if (iwl_scan_cancel(priv
)) {
378 /* cancel scan failed, just live w/ bad key and rely
379 briefly on SW decryption */
383 iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
384 iv32
, phase1key
, CMD_ASYNC
);
387 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
388 struct iwl_rxon_context
*ctx
,
389 struct ieee80211_key_conf
*keyconf
,
390 struct ieee80211_sta
*sta
)
393 struct iwl_addsta_cmd sta_cmd
;
394 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
396 /* if station isn't there, neither is the key */
397 if (sta_id
== IWL_INVALID_STATION
)
400 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
401 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
402 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
))
403 sta_id
= IWL_INVALID_STATION
;
404 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
406 if (sta_id
== IWL_INVALID_STATION
)
409 lockdep_assert_held(&priv
->shrd
->mutex
);
411 ctx
->key_mapping_keys
--;
413 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
414 keyconf
->keyidx
, sta_id
);
416 if (!test_and_clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
))
417 IWL_ERR(priv
, "offset %d not used in uCode key table.\n",
418 keyconf
->hw_key_idx
);
420 sta_cmd
.key
.key_flags
= STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_INVALID
;
421 sta_cmd
.key
.key_offset
= WEP_INVALID_OFFSET
;
422 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
423 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
425 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
428 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
429 struct iwl_rxon_context
*ctx
,
430 struct ieee80211_key_conf
*keyconf
,
431 struct ieee80211_sta
*sta
)
433 struct ieee80211_key_seq seq
;
436 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
439 if (sta_id
== IWL_INVALID_STATION
)
442 lockdep_assert_held(&priv
->shrd
->mutex
);
444 keyconf
->hw_key_idx
= iwl_get_free_ucode_key_offset(priv
);
445 if (keyconf
->hw_key_idx
== WEP_INVALID_OFFSET
)
448 ctx
->key_mapping_keys
++;
450 switch (keyconf
->cipher
) {
451 case WLAN_CIPHER_SUITE_TKIP
:
452 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
453 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
457 else /* station mode case only */
458 addr
= ctx
->active
.bssid_addr
;
460 /* pre-fill phase 1 key into device cache */
461 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
462 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
463 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
464 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
466 case WLAN_CIPHER_SUITE_CCMP
:
467 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
469 case WLAN_CIPHER_SUITE_WEP40
:
470 case WLAN_CIPHER_SUITE_WEP104
:
471 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
475 IWL_ERR(priv
, "Unknown cipher %x\n", keyconf
->cipher
);
480 ctx
->key_mapping_keys
--;
481 clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
);
484 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
485 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
486 sta
? sta
->addr
: NULL
, ret
);
492 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
494 * This adds the broadcast station into the driver's station table
495 * and marks it driver active, so that it will be restored to the
496 * device at the next best time.
498 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
499 struct iwl_rxon_context
*ctx
)
501 struct iwl_link_quality_cmd
*link_cmd
;
505 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
506 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
507 if (sta_id
== IWL_INVALID_STATION
) {
508 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
509 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
514 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
515 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
516 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
518 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
521 "Unable to initialize rate scaling for bcast station.\n");
525 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
526 priv
->stations
[sta_id
].lq
= link_cmd
;
527 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
533 * iwl_update_bcast_station - update broadcast station's LQ command
535 * Only used by iwlagn. Placed here to have all bcast station management
538 int iwl_update_bcast_station(struct iwl_priv
*priv
,
539 struct iwl_rxon_context
*ctx
)
542 struct iwl_link_quality_cmd
*link_cmd
;
543 u8 sta_id
= ctx
->bcast_sta_id
;
545 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
547 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
551 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
552 if (priv
->stations
[sta_id
].lq
)
553 kfree(priv
->stations
[sta_id
].lq
);
555 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
556 priv
->stations
[sta_id
].lq
= link_cmd
;
557 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
562 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
564 struct iwl_rxon_context
*ctx
;
567 for_each_context(priv
, ctx
) {
568 ret
= iwl_update_bcast_station(priv
, ctx
);
577 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
579 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
582 struct iwl_addsta_cmd sta_cmd
;
584 lockdep_assert_held(&priv
->shrd
->mutex
);
586 /* Remove "disable" flag, to enable Tx for this TID */
587 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
588 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
589 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
590 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
591 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
592 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
594 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
597 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
602 struct iwl_addsta_cmd sta_cmd
;
604 lockdep_assert_held(&priv
->shrd
->mutex
);
606 sta_id
= iwl_sta_id(sta
);
607 if (sta_id
== IWL_INVALID_STATION
)
610 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
611 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
612 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
613 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
614 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
615 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
616 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
617 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
619 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
622 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
627 struct iwl_addsta_cmd sta_cmd
;
629 lockdep_assert_held(&priv
->shrd
->mutex
);
631 sta_id
= iwl_sta_id(sta
);
632 if (sta_id
== IWL_INVALID_STATION
) {
633 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
637 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
638 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
639 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
640 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
641 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
642 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
643 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
645 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
648 static void iwl_sta_modify_ps_wake(struct iwl_priv
*priv
, int sta_id
)
652 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
653 priv
->stations
[sta_id
].sta
.station_flags
&= ~STA_FLG_PWR_SAVE_MSK
;
654 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
655 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= 0;
656 priv
->stations
[sta_id
].sta
.sleep_tx_count
= 0;
657 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
658 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
659 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
663 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
667 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
668 priv
->stations
[sta_id
].sta
.station_flags
|= STA_FLG_PWR_SAVE_MSK
;
669 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
670 priv
->stations
[sta_id
].sta
.sta
.modify_mask
=
671 STA_MODIFY_SLEEP_TX_COUNT_MSK
;
672 priv
->stations
[sta_id
].sta
.sleep_tx_count
= cpu_to_le16(cnt
);
673 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
674 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
675 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
679 void iwlagn_mac_sta_notify(struct ieee80211_hw
*hw
,
680 struct ieee80211_vif
*vif
,
681 enum sta_notify_cmd cmd
,
682 struct ieee80211_sta
*sta
)
684 struct iwl_priv
*priv
= hw
->priv
;
685 struct iwl_station_priv
*sta_priv
= (void *)sta
->drv_priv
;
688 IWL_DEBUG_MAC80211(priv
, "enter\n");
691 case STA_NOTIFY_SLEEP
:
692 WARN_ON(!sta_priv
->client
);
693 sta_priv
->asleep
= true;
694 if (atomic_read(&sta_priv
->pending_frames
) > 0)
695 ieee80211_sta_block_awake(hw
, sta
, true);
697 case STA_NOTIFY_AWAKE
:
698 WARN_ON(!sta_priv
->client
);
699 if (!sta_priv
->asleep
)
701 sta_priv
->asleep
= false;
702 sta_id
= iwl_sta_id(sta
);
703 if (sta_id
!= IWL_INVALID_STATION
)
704 iwl_sta_modify_ps_wake(priv
, sta_id
);
709 IWL_DEBUG_MAC80211(priv
, "leave\n");