1 /******************************************************************************
3 * Copyright(c) 2003 - 2012 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>
35 #include "iwl-trans.h"
37 static int iwl_sta_ucode_activate(struct iwl_priv
*priv
, u8 sta_id
)
39 lockdep_assert_held(&priv
->sta_lock
);
41 if (sta_id
>= IWLAGN_STATION_COUNT
) {
42 IWL_ERR(priv
, "invalid sta_id %u", sta_id
);
45 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
))
46 IWL_ERR(priv
, "ACTIVATE a non DRIVER active station id %u "
48 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
50 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) {
52 "STA id %u addr %pM already present in uCode "
53 "(according to driver)\n",
54 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
56 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_ACTIVE
;
57 IWL_DEBUG_ASSOC(priv
, "Added STA id %u addr %pM to uCode\n",
58 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
63 static int iwl_process_add_sta_resp(struct iwl_priv
*priv
,
64 struct iwl_addsta_cmd
*addsta
,
65 struct iwl_rx_packet
*pkt
)
67 u8 sta_id
= addsta
->sta
.sta_id
;
70 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
71 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
76 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
79 spin_lock(&priv
->sta_lock
);
81 switch (pkt
->u
.add_sta
.status
) {
82 case ADD_STA_SUCCESS_MSK
:
83 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
84 ret
= iwl_sta_ucode_activate(priv
, sta_id
);
86 case ADD_STA_NO_ROOM_IN_TABLE
:
87 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
90 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
91 IWL_ERR(priv
, "Adding station %d failed, no block ack "
92 "resource.\n", sta_id
);
94 case ADD_STA_MODIFY_NON_EXIST_STA
:
95 IWL_ERR(priv
, "Attempting to modify non-existing station %d\n",
99 IWL_DEBUG_ASSOC(priv
, "Received REPLY_ADD_STA:(0x%08X)\n",
100 pkt
->u
.add_sta
.status
);
104 IWL_DEBUG_INFO(priv
, "%s station id %u addr %pM\n",
105 priv
->stations
[sta_id
].sta
.mode
==
106 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
107 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
110 * XXX: The MAC address in the command buffer is often changed from
111 * the original sent to the device. That is, the MAC address
112 * written to the command buffer often is not the same MAC address
113 * read from the command buffer when the command returns. This
114 * issue has not yet been resolved and this debugging is left to
115 * observe the problem.
117 IWL_DEBUG_INFO(priv
, "%s station according to cmd buffer %pM\n",
118 priv
->stations
[sta_id
].sta
.mode
==
119 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
121 spin_unlock(&priv
->sta_lock
);
126 int iwl_add_sta_callback(struct iwl_priv
*priv
, struct iwl_rx_cmd_buffer
*rxb
,
127 struct iwl_device_cmd
*cmd
)
129 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
130 struct iwl_addsta_cmd
*addsta
=
131 (struct iwl_addsta_cmd
*) cmd
->payload
;
133 return iwl_process_add_sta_resp(priv
, addsta
, pkt
);
136 int iwl_send_add_sta(struct iwl_priv
*priv
,
137 struct iwl_addsta_cmd
*sta
, u8 flags
)
140 struct iwl_host_cmd cmd
= {
144 .len
= { sizeof(*sta
), },
146 u8 sta_id __maybe_unused
= sta
->sta
.sta_id
;
148 IWL_DEBUG_INFO(priv
, "Adding sta %u (%pM) %ssynchronously\n",
149 sta_id
, sta
->sta
.addr
, flags
& CMD_ASYNC
? "a" : "");
151 if (!(flags
& CMD_ASYNC
)) {
152 cmd
.flags
|= CMD_WANT_SKB
;
156 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
158 if (ret
|| (flags
& CMD_ASYNC
))
160 /*else the command was successfully sent in SYNC mode, need to free
165 if (cmd
.handler_status
)
166 IWL_ERR(priv
, "%s - error in the CMD response %d", __func__
,
169 return cmd
.handler_status
;
172 static void iwl_sta_calc_ht_flags(struct iwl_priv
*priv
,
173 struct ieee80211_sta
*sta
,
174 struct iwl_rxon_context
*ctx
,
175 __le32
*flags
, __le32
*mask
)
177 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
180 *mask
= STA_FLG_RTS_MIMO_PROT_MSK
|
181 STA_FLG_MIMO_DIS_MSK
|
182 STA_FLG_HT40_EN_MSK
|
183 STA_FLG_MAX_AGG_SIZE_MSK
|
184 STA_FLG_AGG_MPDU_DENSITY_MSK
;
187 if (!sta
|| !sta_ht_inf
->ht_supported
)
190 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_SM_PS
) >> 2;
192 IWL_DEBUG_INFO(priv
, "STA %pM SM PS mode: %s\n",
193 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_STATIC
) ?
195 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_DYNAMIC
) ?
196 "dynamic" : "disabled");
198 switch (mimo_ps_mode
) {
199 case WLAN_HT_CAP_SM_PS_STATIC
:
200 *flags
|= STA_FLG_MIMO_DIS_MSK
;
202 case WLAN_HT_CAP_SM_PS_DYNAMIC
:
203 *flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
205 case WLAN_HT_CAP_SM_PS_DISABLED
:
208 IWL_WARN(priv
, "Invalid MIMO PS mode %d\n", mimo_ps_mode
);
212 *flags
|= cpu_to_le32(
213 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
215 *flags
|= cpu_to_le32(
216 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
218 if (iwl_is_ht40_tx_allowed(priv
, ctx
, &sta
->ht_cap
))
219 *flags
|= STA_FLG_HT40_EN_MSK
;
222 int iwl_sta_update_ht(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
223 struct ieee80211_sta
*sta
)
225 u8 sta_id
= iwl_sta_id(sta
);
227 struct iwl_addsta_cmd cmd
;
229 if (WARN_ON_ONCE(sta_id
== IWL_INVALID_STATION
))
232 iwl_sta_calc_ht_flags(priv
, sta
, ctx
, &flags
, &mask
);
234 spin_lock_bh(&priv
->sta_lock
);
235 priv
->stations
[sta_id
].sta
.station_flags
&= ~mask
;
236 priv
->stations
[sta_id
].sta
.station_flags
|= flags
;
237 spin_unlock_bh(&priv
->sta_lock
);
239 memset(&cmd
, 0, sizeof(cmd
));
240 cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
241 cmd
.station_flags_msk
= mask
;
242 cmd
.station_flags
= flags
;
243 cmd
.sta
.sta_id
= sta_id
;
245 return iwl_send_add_sta(priv
, &cmd
, CMD_SYNC
);
248 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
249 struct ieee80211_sta
*sta
,
250 struct iwl_rxon_context
*ctx
)
254 iwl_sta_calc_ht_flags(priv
, sta
, ctx
, &flags
, &mask
);
256 lockdep_assert_held(&priv
->sta_lock
);
257 priv
->stations
[index
].sta
.station_flags
&= ~mask
;
258 priv
->stations
[index
].sta
.station_flags
|= flags
;
262 * iwl_prep_station - Prepare station information for addition
264 * should be called with sta_lock held
266 u8
iwl_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
267 const u8
*addr
, bool is_ap
, struct ieee80211_sta
*sta
)
269 struct iwl_station_entry
*station
;
271 u8 sta_id
= IWL_INVALID_STATION
;
274 sta_id
= ctx
->ap_sta_id
;
275 else if (is_broadcast_ether_addr(addr
))
276 sta_id
= ctx
->bcast_sta_id
;
278 for (i
= IWL_STA_ID
; i
< IWLAGN_STATION_COUNT
; i
++) {
279 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
285 if (!priv
->stations
[i
].used
&&
286 sta_id
== IWL_INVALID_STATION
)
291 * These two conditions have the same outcome, but keep them
294 if (unlikely(sta_id
== IWL_INVALID_STATION
))
298 * uCode is not able to deal with multiple requests to add a
299 * station. Keep track if one is in progress so that we do not send
302 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
303 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
308 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
309 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
310 !compare_ether_addr(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
311 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
312 "adding again.\n", sta_id
, addr
);
316 station
= &priv
->stations
[sta_id
];
317 station
->used
= IWL_STA_DRIVER_ACTIVE
;
318 IWL_DEBUG_ASSOC(priv
, "Add STA to driver ID %d: %pM\n",
320 priv
->num_stations
++;
322 /* Set up the REPLY_ADD_STA command to send to device */
323 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
324 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
325 station
->sta
.mode
= 0;
326 station
->sta
.sta
.sta_id
= sta_id
;
327 station
->sta
.station_flags
= ctx
->station_flags
;
328 station
->ctxid
= ctx
->ctxid
;
331 struct iwl_station_priv
*sta_priv
;
333 sta_priv
= (void *)sta
->drv_priv
;
338 * OK to call unconditionally, since local stations (IBSS BSSID
339 * STA and broadcast STA) pass in a NULL sta, and mac80211
340 * doesn't allow HT IBSS.
342 iwl_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
348 #define STA_WAIT_TIMEOUT (HZ/2)
351 * iwl_add_station_common -
353 int iwl_add_station_common(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
354 const u8
*addr
, bool is_ap
,
355 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
359 struct iwl_addsta_cmd sta_cmd
;
362 spin_lock_bh(&priv
->sta_lock
);
363 sta_id
= iwl_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
364 if (sta_id
== IWL_INVALID_STATION
) {
365 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
367 spin_unlock_bh(&priv
->sta_lock
);
372 * uCode is not able to deal with multiple requests to add a
373 * station. Keep track if one is in progress so that we do not send
376 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
377 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
379 spin_unlock_bh(&priv
->sta_lock
);
383 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
384 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
385 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
386 "adding again.\n", sta_id
, addr
);
387 spin_unlock_bh(&priv
->sta_lock
);
391 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
392 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
,
393 sizeof(struct iwl_addsta_cmd
));
394 spin_unlock_bh(&priv
->sta_lock
);
396 /* Add station to device's station table */
397 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
399 spin_lock_bh(&priv
->sta_lock
);
400 IWL_ERR(priv
, "Adding station %pM failed.\n",
401 priv
->stations
[sta_id
].sta
.sta
.addr
);
402 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
403 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
404 spin_unlock_bh(&priv
->sta_lock
);
411 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
413 static void iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
415 lockdep_assert_held(&priv
->sta_lock
);
417 /* Ucode must be active and driver must be non active */
418 if ((priv
->stations
[sta_id
].used
&
419 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) !=
420 IWL_STA_UCODE_ACTIVE
)
421 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
423 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
425 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
426 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
429 static int iwl_send_remove_station(struct iwl_priv
*priv
,
430 const u8
*addr
, int sta_id
,
433 struct iwl_rx_packet
*pkt
;
435 struct iwl_rem_sta_cmd rm_sta_cmd
;
437 struct iwl_host_cmd cmd
= {
438 .id
= REPLY_REMOVE_STA
,
439 .len
= { sizeof(struct iwl_rem_sta_cmd
), },
441 .data
= { &rm_sta_cmd
, },
444 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
445 rm_sta_cmd
.num_sta
= 1;
446 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
448 cmd
.flags
|= CMD_WANT_SKB
;
450 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
456 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
457 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
463 switch (pkt
->u
.rem_sta
.status
) {
464 case REM_STA_SUCCESS_MSK
:
466 spin_lock_bh(&priv
->sta_lock
);
467 iwl_sta_ucode_deactivate(priv
, sta_id
);
468 spin_unlock_bh(&priv
->sta_lock
);
470 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
474 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
484 * iwl_remove_station - Remove driver's knowledge of station.
486 int iwl_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
491 if (!iwl_is_ready(priv
->shrd
)) {
493 "Unable to remove station %pM, device not ready.\n",
496 * It is typical for stations to be removed when we are
497 * going down. Return success since device will be down
503 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
506 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
509 spin_lock_bh(&priv
->sta_lock
);
511 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
512 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
517 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
518 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
523 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
524 kfree(priv
->stations
[sta_id
].lq
);
525 priv
->stations
[sta_id
].lq
= NULL
;
528 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++)
529 memset(&priv
->tid_data
[sta_id
][tid
], 0,
530 sizeof(priv
->tid_data
[sta_id
][tid
]));
532 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
534 priv
->num_stations
--;
536 if (WARN_ON(priv
->num_stations
< 0))
537 priv
->num_stations
= 0;
539 spin_unlock_bh(&priv
->sta_lock
);
541 return iwl_send_remove_station(priv
, addr
, sta_id
, false);
543 spin_unlock_bh(&priv
->sta_lock
);
548 * iwl_clear_ucode_stations - clear ucode station table bits
550 * This function clears all the bits in the driver indicating
551 * which stations are active in the ucode. Call when something
552 * other than explicit station management would cause this in
553 * the ucode, e.g. unassociated RXON.
555 void iwl_clear_ucode_stations(struct iwl_priv
*priv
,
556 struct iwl_rxon_context
*ctx
)
559 bool cleared
= false;
561 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
563 spin_lock_bh(&priv
->sta_lock
);
564 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
565 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
568 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
570 "Clearing ucode active for station %d\n", i
);
571 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
575 spin_unlock_bh(&priv
->sta_lock
);
579 "No active stations found to be cleared\n");
583 * iwl_restore_stations() - Restore driver known stations to device
585 * All stations considered active by driver, but not present in ucode, is
590 void iwl_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
592 struct iwl_addsta_cmd sta_cmd
;
593 struct iwl_link_quality_cmd lq
;
599 if (!iwl_is_ready(priv
->shrd
)) {
601 "Not ready yet, not restoring any stations.\n");
605 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
606 spin_lock_bh(&priv
->sta_lock
);
607 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
608 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
610 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
611 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
612 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
613 priv
->stations
[i
].sta
.sta
.addr
);
614 priv
->stations
[i
].sta
.mode
= 0;
615 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
620 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
621 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
622 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
623 sizeof(struct iwl_addsta_cmd
));
625 if (priv
->stations
[i
].lq
) {
627 iwl_sta_fill_lq(priv
, ctx
, i
, &lq
);
629 memcpy(&lq
, priv
->stations
[i
].lq
,
630 sizeof(struct iwl_link_quality_cmd
));
633 spin_unlock_bh(&priv
->sta_lock
);
634 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
636 spin_lock_bh(&priv
->sta_lock
);
637 IWL_ERR(priv
, "Adding station %pM failed.\n",
638 priv
->stations
[i
].sta
.sta
.addr
);
639 priv
->stations
[i
].used
&=
640 ~IWL_STA_DRIVER_ACTIVE
;
641 priv
->stations
[i
].used
&=
642 ~IWL_STA_UCODE_INPROGRESS
;
643 spin_unlock_bh(&priv
->sta_lock
);
646 * Rate scaling has already been initialized, send
650 iwl_send_lq_cmd(priv
, ctx
, &lq
,
652 spin_lock_bh(&priv
->sta_lock
);
653 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
657 spin_unlock_bh(&priv
->sta_lock
);
659 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
660 "no stations to be restored.\n");
662 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
666 int iwl_get_free_ucode_key_offset(struct iwl_priv
*priv
)
670 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
671 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
674 return WEP_INVALID_OFFSET
;
677 void iwl_dealloc_bcast_stations(struct iwl_priv
*priv
)
681 spin_lock_bh(&priv
->sta_lock
);
682 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
683 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
686 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
687 priv
->num_stations
--;
688 if (WARN_ON(priv
->num_stations
< 0))
689 priv
->num_stations
= 0;
690 kfree(priv
->stations
[i
].lq
);
691 priv
->stations
[i
].lq
= NULL
;
693 spin_unlock_bh(&priv
->sta_lock
);
696 #ifdef CONFIG_IWLWIFI_DEBUG
697 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
698 struct iwl_link_quality_cmd
*lq
)
701 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
702 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
703 lq
->general_params
.single_stream_ant_msk
,
704 lq
->general_params
.dual_stream_ant_msk
);
706 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
707 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
708 i
, lq
->rs_table
[i
].rate_n_flags
);
711 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
712 struct iwl_link_quality_cmd
*lq
)
718 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
720 * It sometimes happens when a HT rate has been in use and we
721 * loose connectivity with AP then mac80211 will first tell us that the
722 * current channel is not HT anymore before removing the station. In such a
723 * scenario the RXON flags will be updated to indicate we are not
724 * communicating HT anymore, but the LQ command may still contain HT rates.
725 * Test for this to prevent driver from sending LQ command between the time
726 * RXON flags are updated and when LQ command is updated.
728 static bool is_lq_table_valid(struct iwl_priv
*priv
,
729 struct iwl_rxon_context
*ctx
,
730 struct iwl_link_quality_cmd
*lq
)
737 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
738 ctx
->active
.channel
);
739 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
740 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) &
743 "index %d of LQ expects HT channel\n",
752 * iwl_send_lq_cmd() - Send link quality command
753 * @init: This command is sent as part of station initialization right
754 * after station has been added.
756 * The link quality command is sent as the last step of station creation.
757 * This is the special case in which init is set and we call a callback in
758 * this case to clear the state indicating that station creation is in
761 int iwl_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
762 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
765 struct iwl_host_cmd cmd
= {
766 .id
= REPLY_TX_LINK_QUALITY_CMD
,
767 .len
= { sizeof(struct iwl_link_quality_cmd
), },
772 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
776 spin_lock_bh(&priv
->sta_lock
);
777 if (!(priv
->stations
[lq
->sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
778 spin_unlock_bh(&priv
->sta_lock
);
781 spin_unlock_bh(&priv
->sta_lock
);
783 iwl_dump_lq_cmd(priv
, lq
);
784 if (WARN_ON(init
&& (cmd
.flags
& CMD_ASYNC
)))
787 if (is_lq_table_valid(priv
, ctx
, lq
))
788 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
792 if (cmd
.flags
& CMD_ASYNC
)
796 IWL_DEBUG_INFO(priv
, "init LQ command complete, "
797 "clearing sta addition status for sta %d\n",
799 spin_lock_bh(&priv
->sta_lock
);
800 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
801 spin_unlock_bh(&priv
->sta_lock
);
807 void iwl_sta_fill_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
808 u8 sta_id
, struct iwl_link_quality_cmd
*link_cmd
)
814 lockdep_assert_held(&priv
->mutex
);
816 memset(link_cmd
, 0, sizeof(*link_cmd
));
818 /* Set up the rate scaling to start at selected rate, fall back
819 * all the way down to 1M in IEEE order, and then spin on 1M */
820 if (priv
->band
== IEEE80211_BAND_5GHZ
)
821 r
= IWL_RATE_6M_INDEX
;
822 else if (ctx
&& ctx
->vif
&& ctx
->vif
->p2p
)
823 r
= IWL_RATE_6M_INDEX
;
825 r
= IWL_RATE_1M_INDEX
;
827 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
828 rate_flags
|= RATE_MCS_CCK_MSK
;
830 rate_flags
|= first_antenna(hw_params(priv
).valid_tx_ant
) <<
832 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
833 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
834 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
836 link_cmd
->general_params
.single_stream_ant_msk
=
837 first_antenna(hw_params(priv
).valid_tx_ant
);
839 link_cmd
->general_params
.dual_stream_ant_msk
=
840 hw_params(priv
).valid_tx_ant
&
841 ~first_antenna(hw_params(priv
).valid_tx_ant
);
842 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
843 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
844 } else if (num_of_ant(hw_params(priv
).valid_tx_ant
) == 2) {
845 link_cmd
->general_params
.dual_stream_ant_msk
=
846 hw_params(priv
).valid_tx_ant
;
849 link_cmd
->agg_params
.agg_dis_start_th
=
850 LINK_QUAL_AGG_DISABLE_START_DEF
;
851 link_cmd
->agg_params
.agg_time_limit
=
852 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
854 link_cmd
->sta_id
= sta_id
;
857 static struct iwl_link_quality_cmd
*
858 iwl_sta_alloc_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
861 struct iwl_link_quality_cmd
*link_cmd
;
863 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
865 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
869 iwl_sta_fill_lq(priv
, ctx
, sta_id
, link_cmd
);
875 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
879 int iwlagn_add_bssid_station(struct iwl_priv
*priv
,
880 struct iwl_rxon_context
*ctx
,
881 const u8
*addr
, u8
*sta_id_r
)
885 struct iwl_link_quality_cmd
*link_cmd
;
888 *sta_id_r
= IWL_INVALID_STATION
;
890 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
892 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
899 spin_lock_bh(&priv
->sta_lock
);
900 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
901 spin_unlock_bh(&priv
->sta_lock
);
903 /* Set up default rate scaling table in device's station table */
904 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
907 "Unable to initialize rate scaling for station %pM.\n",
912 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
914 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
916 spin_lock_bh(&priv
->sta_lock
);
917 priv
->stations
[sta_id
].lq
= link_cmd
;
918 spin_unlock_bh(&priv
->sta_lock
);
926 * For each context, the device has a table of 4 static WEP keys
927 * (one for each key index) that is updated with the following
931 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
932 struct iwl_rxon_context
*ctx
,
935 int i
, not_empty
= 0;
936 u8 buff
[sizeof(struct iwl_wep_cmd
) +
937 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
938 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
939 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
940 struct iwl_host_cmd cmd
= {
941 .id
= ctx
->wep_key_cmd
,
942 .data
= { wep_cmd
, },
948 memset(wep_cmd
, 0, cmd_size
+
949 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
951 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
952 wep_cmd
->key
[i
].key_index
= i
;
953 if (ctx
->wep_keys
[i
].key_size
) {
954 wep_cmd
->key
[i
].key_offset
= i
;
957 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
960 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
961 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
962 ctx
->wep_keys
[i
].key_size
);
965 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
966 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
968 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
970 cmd
.len
[0] = cmd_size
;
972 if (not_empty
|| send_if_empty
)
973 return iwl_dvm_send_cmd(priv
, &cmd
);
978 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
979 struct iwl_rxon_context
*ctx
)
981 lockdep_assert_held(&priv
->mutex
);
983 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
986 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
987 struct iwl_rxon_context
*ctx
,
988 struct ieee80211_key_conf
*keyconf
)
992 lockdep_assert_held(&priv
->mutex
);
994 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
997 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
998 if (iwl_is_rfkill(priv
->shrd
)) {
1000 "Not sending REPLY_WEPKEY command due to RFKILL.\n");
1001 /* but keys in device are clear anyway so return success */
1004 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
1005 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
1006 keyconf
->keyidx
, ret
);
1011 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
1012 struct iwl_rxon_context
*ctx
,
1013 struct ieee80211_key_conf
*keyconf
)
1017 lockdep_assert_held(&priv
->mutex
);
1019 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
1020 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
1022 "Bad WEP key length %d\n", keyconf
->keylen
);
1026 keyconf
->hw_key_idx
= IWLAGN_HW_KEY_DEFAULT
;
1028 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
1029 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
1032 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1033 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
1034 keyconf
->keylen
, keyconf
->keyidx
, ret
);
1040 * dynamic (per-station) keys
1042 * The dynamic keys are a little more complicated. The device has
1043 * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
1044 * These are linked to stations by a table that contains an index
1045 * into the key table for each station/key index/{mcast,unicast},
1046 * i.e. it's basically an array of pointers like this:
1047 * key_offset_t key_mapping[NUM_STATIONS][4][2];
1048 * (it really works differently, but you can think of it as such)
1050 * The key uploading and linking happens in the same command, the
1051 * add station command with STA_MODIFY_KEY_MASK.
1054 static u8
iwlagn_key_sta_id(struct iwl_priv
*priv
,
1055 struct ieee80211_vif
*vif
,
1056 struct ieee80211_sta
*sta
)
1058 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1061 return iwl_sta_id(sta
);
1064 * The device expects GTKs for station interfaces to be
1065 * installed as GTKs for the AP station. If we have no
1066 * station ID, then use the ap_sta_id in that case.
1068 if (vif
->type
== NL80211_IFTYPE_STATION
&& vif_priv
->ctx
)
1069 return vif_priv
->ctx
->ap_sta_id
;
1071 return IWL_INVALID_STATION
;
1074 static int iwlagn_send_sta_key(struct iwl_priv
*priv
,
1075 struct ieee80211_key_conf
*keyconf
,
1076 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1080 struct iwl_addsta_cmd sta_cmd
;
1083 spin_lock_bh(&priv
->sta_lock
);
1084 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1085 spin_unlock_bh(&priv
->sta_lock
);
1087 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1088 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
;
1090 switch (keyconf
->cipher
) {
1091 case WLAN_CIPHER_SUITE_CCMP
:
1092 key_flags
|= STA_KEY_FLG_CCMP
;
1093 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1095 case WLAN_CIPHER_SUITE_TKIP
:
1096 key_flags
|= STA_KEY_FLG_TKIP
;
1097 sta_cmd
.key
.tkip_rx_tsc_byte2
= tkip_iv32
;
1098 for (i
= 0; i
< 5; i
++)
1099 sta_cmd
.key
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1100 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1102 case WLAN_CIPHER_SUITE_WEP104
:
1103 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
1105 case WLAN_CIPHER_SUITE_WEP40
:
1106 key_flags
|= STA_KEY_FLG_WEP
;
1107 memcpy(&sta_cmd
.key
.key
[3], keyconf
->key
, keyconf
->keylen
);
1114 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1115 key_flags
|= STA_KEY_MULTICAST_MSK
;
1117 /* key pointer (offset) */
1118 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
1120 sta_cmd
.key
.key_flags
= key_flags
;
1121 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1122 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1124 return iwl_send_add_sta(priv
, &sta_cmd
, cmd_flags
);
1127 void iwl_update_tkip_key(struct iwl_priv
*priv
,
1128 struct ieee80211_vif
*vif
,
1129 struct ieee80211_key_conf
*keyconf
,
1130 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
1132 u8 sta_id
= iwlagn_key_sta_id(priv
, vif
, sta
);
1134 if (sta_id
== IWL_INVALID_STATION
)
1137 if (iwl_scan_cancel(priv
)) {
1138 /* cancel scan failed, just live w/ bad key and rely
1139 briefly on SW decryption */
1143 iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1144 iv32
, phase1key
, CMD_ASYNC
);
1147 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
1148 struct iwl_rxon_context
*ctx
,
1149 struct ieee80211_key_conf
*keyconf
,
1150 struct ieee80211_sta
*sta
)
1152 struct iwl_addsta_cmd sta_cmd
;
1153 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1156 /* if station isn't there, neither is the key */
1157 if (sta_id
== IWL_INVALID_STATION
)
1160 spin_lock_bh(&priv
->sta_lock
);
1161 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1162 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
))
1163 sta_id
= IWL_INVALID_STATION
;
1164 spin_unlock_bh(&priv
->sta_lock
);
1166 if (sta_id
== IWL_INVALID_STATION
)
1169 lockdep_assert_held(&priv
->mutex
);
1171 ctx
->key_mapping_keys
--;
1173 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
1174 keyconf
->keyidx
, sta_id
);
1176 if (!test_and_clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
))
1177 IWL_ERR(priv
, "offset %d not used in uCode key table.\n",
1178 keyconf
->hw_key_idx
);
1180 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1181 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
| STA_KEY_FLG_NO_ENC
|
1182 STA_KEY_FLG_INVALID
;
1184 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1185 key_flags
|= STA_KEY_MULTICAST_MSK
;
1187 sta_cmd
.key
.key_flags
= key_flags
;
1188 sta_cmd
.key
.key_offset
= WEP_INVALID_OFFSET
;
1189 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1190 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1192 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1195 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
1196 struct iwl_rxon_context
*ctx
,
1197 struct ieee80211_key_conf
*keyconf
,
1198 struct ieee80211_sta
*sta
)
1200 struct ieee80211_key_seq seq
;
1203 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1206 if (sta_id
== IWL_INVALID_STATION
)
1209 lockdep_assert_held(&priv
->mutex
);
1211 keyconf
->hw_key_idx
= iwl_get_free_ucode_key_offset(priv
);
1212 if (keyconf
->hw_key_idx
== WEP_INVALID_OFFSET
)
1215 ctx
->key_mapping_keys
++;
1217 switch (keyconf
->cipher
) {
1218 case WLAN_CIPHER_SUITE_TKIP
:
1221 else /* station mode case only */
1222 addr
= ctx
->active
.bssid_addr
;
1224 /* pre-fill phase 1 key into device cache */
1225 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1226 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1227 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1228 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1230 case WLAN_CIPHER_SUITE_CCMP
:
1231 case WLAN_CIPHER_SUITE_WEP40
:
1232 case WLAN_CIPHER_SUITE_WEP104
:
1233 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1237 IWL_ERR(priv
, "Unknown cipher %x\n", keyconf
->cipher
);
1242 ctx
->key_mapping_keys
--;
1243 clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
);
1246 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1247 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1248 sta
? sta
->addr
: NULL
, ret
);
1254 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
1256 * This adds the broadcast station into the driver's station table
1257 * and marks it driver active, so that it will be restored to the
1258 * device at the next best time.
1260 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
1261 struct iwl_rxon_context
*ctx
)
1263 struct iwl_link_quality_cmd
*link_cmd
;
1266 spin_lock_bh(&priv
->sta_lock
);
1267 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
1268 if (sta_id
== IWL_INVALID_STATION
) {
1269 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
1270 spin_unlock_bh(&priv
->sta_lock
);
1275 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
1276 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
1277 spin_unlock_bh(&priv
->sta_lock
);
1279 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1282 "Unable to initialize rate scaling for bcast station.\n");
1286 spin_lock_bh(&priv
->sta_lock
);
1287 priv
->stations
[sta_id
].lq
= link_cmd
;
1288 spin_unlock_bh(&priv
->sta_lock
);
1294 * iwl_update_bcast_station - update broadcast station's LQ command
1296 * Only used by iwlagn. Placed here to have all bcast station management
1299 int iwl_update_bcast_station(struct iwl_priv
*priv
,
1300 struct iwl_rxon_context
*ctx
)
1302 struct iwl_link_quality_cmd
*link_cmd
;
1303 u8 sta_id
= ctx
->bcast_sta_id
;
1305 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1307 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
1311 spin_lock_bh(&priv
->sta_lock
);
1312 if (priv
->stations
[sta_id
].lq
)
1313 kfree(priv
->stations
[sta_id
].lq
);
1315 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
1316 priv
->stations
[sta_id
].lq
= link_cmd
;
1317 spin_unlock_bh(&priv
->sta_lock
);
1322 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
1324 struct iwl_rxon_context
*ctx
;
1327 for_each_context(priv
, ctx
) {
1328 ret
= iwl_update_bcast_station(priv
, ctx
);
1337 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1339 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
1341 struct iwl_addsta_cmd sta_cmd
;
1343 lockdep_assert_held(&priv
->mutex
);
1345 /* Remove "disable" flag, to enable Tx for this TID */
1346 spin_lock_bh(&priv
->sta_lock
);
1347 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
1348 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
1349 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1350 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1351 spin_unlock_bh(&priv
->sta_lock
);
1353 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1356 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1360 struct iwl_addsta_cmd sta_cmd
;
1362 lockdep_assert_held(&priv
->mutex
);
1364 sta_id
= iwl_sta_id(sta
);
1365 if (sta_id
== IWL_INVALID_STATION
)
1368 spin_lock_bh(&priv
->sta_lock
);
1369 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1370 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
1371 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
1372 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1373 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1374 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1375 spin_unlock_bh(&priv
->sta_lock
);
1377 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1380 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1384 struct iwl_addsta_cmd sta_cmd
;
1386 lockdep_assert_held(&priv
->mutex
);
1388 sta_id
= iwl_sta_id(sta
);
1389 if (sta_id
== IWL_INVALID_STATION
) {
1390 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
1394 spin_lock_bh(&priv
->sta_lock
);
1395 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1396 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
1397 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
1398 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1399 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1400 spin_unlock_bh(&priv
->sta_lock
);
1402 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1407 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
1409 struct iwl_addsta_cmd cmd
= {
1410 .mode
= STA_CONTROL_MODIFY_MSK
,
1411 .station_flags
= STA_FLG_PWR_SAVE_MSK
,
1412 .station_flags_msk
= STA_FLG_PWR_SAVE_MSK
,
1413 .sta
.sta_id
= sta_id
,
1414 .sta
.modify_mask
= STA_MODIFY_SLEEP_TX_COUNT_MSK
,
1415 .sleep_tx_count
= cpu_to_le16(cnt
),
1418 iwl_send_add_sta(priv
, &cmd
, CMD_ASYNC
);