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>
35 #include "iwl-trans.h"
37 /* priv->shrd->sta_lock must be held */
38 static void iwl_sta_ucode_activate(struct iwl_priv
*priv
, u8 sta_id
)
41 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
))
42 IWL_ERR(priv
, "ACTIVATE a non DRIVER active station id %u "
44 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
46 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) {
48 "STA id %u addr %pM already present in uCode "
49 "(according to driver)\n",
50 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
52 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_ACTIVE
;
53 IWL_DEBUG_ASSOC(priv
, "Added STA id %u addr %pM to uCode\n",
54 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
58 static int iwl_process_add_sta_resp(struct iwl_priv
*priv
,
59 struct iwl_addsta_cmd
*addsta
,
60 struct iwl_rx_packet
*pkt
)
62 u8 sta_id
= addsta
->sta
.sta_id
;
66 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
67 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
72 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
75 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
77 switch (pkt
->u
.add_sta
.status
) {
78 case ADD_STA_SUCCESS_MSK
:
79 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
80 iwl_sta_ucode_activate(priv
, sta_id
);
83 case ADD_STA_NO_ROOM_IN_TABLE
:
84 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
87 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
88 IWL_ERR(priv
, "Adding station %d failed, no block ack "
89 "resource.\n", sta_id
);
91 case ADD_STA_MODIFY_NON_EXIST_STA
:
92 IWL_ERR(priv
, "Attempting to modify non-existing station %d\n",
96 IWL_DEBUG_ASSOC(priv
, "Received REPLY_ADD_STA:(0x%08X)\n",
97 pkt
->u
.add_sta
.status
);
101 IWL_DEBUG_INFO(priv
, "%s station id %u addr %pM\n",
102 priv
->stations
[sta_id
].sta
.mode
==
103 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
104 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
107 * XXX: The MAC address in the command buffer is often changed from
108 * the original sent to the device. That is, the MAC address
109 * written to the command buffer often is not the same MAC address
110 * read from the command buffer when the command returns. This
111 * issue has not yet been resolved and this debugging is left to
112 * observe the problem.
114 IWL_DEBUG_INFO(priv
, "%s station according to cmd buffer %pM\n",
115 priv
->stations
[sta_id
].sta
.mode
==
116 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
118 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
123 int iwl_add_sta_callback(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
,
124 struct iwl_device_cmd
*cmd
)
126 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
127 struct iwl_addsta_cmd
*addsta
=
128 (struct iwl_addsta_cmd
*) cmd
->payload
;
130 return iwl_process_add_sta_resp(priv
, addsta
, pkt
);
133 int iwl_send_add_sta(struct iwl_priv
*priv
,
134 struct iwl_addsta_cmd
*sta
, u8 flags
)
137 struct iwl_host_cmd cmd
= {
141 .len
= { sizeof(*sta
), },
143 u8 sta_id __maybe_unused
= sta
->sta
.sta_id
;
145 IWL_DEBUG_INFO(priv
, "Adding sta %u (%pM) %ssynchronously\n",
146 sta_id
, sta
->sta
.addr
, flags
& CMD_ASYNC
? "a" : "");
148 if (!(flags
& CMD_ASYNC
)) {
149 cmd
.flags
|= CMD_WANT_SKB
;
153 ret
= iwl_trans_send_cmd(trans(priv
), &cmd
);
155 if (ret
|| (flags
& CMD_ASYNC
))
157 /*else the command was successfully sent in SYNC mode, need to free
160 iwl_free_pages(priv
->shrd
, cmd
.reply_page
);
162 if (cmd
.handler_status
)
163 IWL_ERR(priv
, "%s - error in the CMD response %d", __func__
,
166 return cmd
.handler_status
;
169 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
170 struct ieee80211_sta
*sta
,
171 struct iwl_rxon_context
*ctx
)
173 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
177 if (!sta
|| !sta_ht_inf
->ht_supported
)
180 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_SM_PS
) >> 2;
181 IWL_DEBUG_ASSOC(priv
, "spatial multiplexing power save mode: %s\n",
182 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_STATIC
) ?
184 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_DYNAMIC
) ?
185 "dynamic" : "disabled");
187 sta_flags
= priv
->stations
[index
].sta
.station_flags
;
189 sta_flags
&= ~(STA_FLG_RTS_MIMO_PROT_MSK
| STA_FLG_MIMO_DIS_MSK
);
191 switch (mimo_ps_mode
) {
192 case WLAN_HT_CAP_SM_PS_STATIC
:
193 sta_flags
|= STA_FLG_MIMO_DIS_MSK
;
195 case WLAN_HT_CAP_SM_PS_DYNAMIC
:
196 sta_flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
198 case WLAN_HT_CAP_SM_PS_DISABLED
:
201 IWL_WARN(priv
, "Invalid MIMO PS mode %d\n", mimo_ps_mode
);
205 sta_flags
|= cpu_to_le32(
206 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
208 sta_flags
|= cpu_to_le32(
209 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
211 if (iwl_is_ht40_tx_allowed(priv
, ctx
, &sta
->ht_cap
))
212 sta_flags
|= STA_FLG_HT40_EN_MSK
;
214 sta_flags
&= ~STA_FLG_HT40_EN_MSK
;
216 priv
->stations
[index
].sta
.station_flags
= sta_flags
;
222 * iwl_prep_station - Prepare station information for addition
224 * should be called with sta_lock held
226 u8
iwl_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
227 const u8
*addr
, bool is_ap
, struct ieee80211_sta
*sta
)
229 struct iwl_station_entry
*station
;
231 u8 sta_id
= IWL_INVALID_STATION
;
234 sta_id
= ctx
->ap_sta_id
;
235 else if (is_broadcast_ether_addr(addr
))
236 sta_id
= ctx
->bcast_sta_id
;
238 for (i
= IWL_STA_ID
; i
< IWLAGN_STATION_COUNT
; i
++) {
239 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
245 if (!priv
->stations
[i
].used
&&
246 sta_id
== IWL_INVALID_STATION
)
251 * These two conditions have the same outcome, but keep them
254 if (unlikely(sta_id
== IWL_INVALID_STATION
))
258 * uCode is not able to deal with multiple requests to add a
259 * station. Keep track if one is in progress so that we do not send
262 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
263 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
268 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
269 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
270 !compare_ether_addr(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
271 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
272 "adding again.\n", sta_id
, addr
);
276 station
= &priv
->stations
[sta_id
];
277 station
->used
= IWL_STA_DRIVER_ACTIVE
;
278 IWL_DEBUG_ASSOC(priv
, "Add STA to driver ID %d: %pM\n",
280 priv
->num_stations
++;
282 /* Set up the REPLY_ADD_STA command to send to device */
283 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
284 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
285 station
->sta
.mode
= 0;
286 station
->sta
.sta
.sta_id
= sta_id
;
287 station
->sta
.station_flags
= ctx
->station_flags
;
288 station
->ctxid
= ctx
->ctxid
;
291 struct iwl_station_priv
*sta_priv
;
293 sta_priv
= (void *)sta
->drv_priv
;
298 * OK to call unconditionally, since local stations (IBSS BSSID
299 * STA and broadcast STA) pass in a NULL sta, and mac80211
300 * doesn't allow HT IBSS.
302 iwl_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
308 #define STA_WAIT_TIMEOUT (HZ/2)
311 * iwl_add_station_common -
313 int iwl_add_station_common(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
314 const u8
*addr
, bool is_ap
,
315 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
317 unsigned long flags_spin
;
320 struct iwl_addsta_cmd sta_cmd
;
323 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
324 sta_id
= iwl_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
325 if (sta_id
== IWL_INVALID_STATION
) {
326 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
328 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
333 * uCode is not able to deal with multiple requests to add a
334 * station. Keep track if one is in progress so that we do not send
337 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
338 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
340 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
344 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
345 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
346 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
347 "adding again.\n", sta_id
, addr
);
348 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
352 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
353 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
,
354 sizeof(struct iwl_addsta_cmd
));
355 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
357 /* Add station to device's station table */
358 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
360 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
361 IWL_ERR(priv
, "Adding station %pM failed.\n",
362 priv
->stations
[sta_id
].sta
.sta
.addr
);
363 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
364 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
365 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
372 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
374 * priv->shrd->sta_lock must be held
376 static void iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
378 /* Ucode must be active and driver must be non active */
379 if ((priv
->stations
[sta_id
].used
&
380 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) !=
381 IWL_STA_UCODE_ACTIVE
)
382 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
384 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
386 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
387 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
390 static int iwl_send_remove_station(struct iwl_priv
*priv
,
391 const u8
*addr
, int sta_id
,
394 struct iwl_rx_packet
*pkt
;
397 unsigned long flags_spin
;
398 struct iwl_rem_sta_cmd rm_sta_cmd
;
400 struct iwl_host_cmd cmd
= {
401 .id
= REPLY_REMOVE_STA
,
402 .len
= { sizeof(struct iwl_rem_sta_cmd
), },
404 .data
= { &rm_sta_cmd
, },
407 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
408 rm_sta_cmd
.num_sta
= 1;
409 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
411 cmd
.flags
|= CMD_WANT_SKB
;
413 ret
= iwl_trans_send_cmd(trans(priv
), &cmd
);
418 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
419 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
420 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
426 switch (pkt
->u
.rem_sta
.status
) {
427 case REM_STA_SUCCESS_MSK
:
429 spin_lock_irqsave(&priv
->shrd
->sta_lock
,
431 iwl_sta_ucode_deactivate(priv
, sta_id
);
432 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
,
435 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
439 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
443 iwl_free_pages(priv
->shrd
, cmd
.reply_page
);
449 * iwl_remove_station - Remove driver's knowledge of station.
451 int iwl_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
457 if (!iwl_is_ready(priv
->shrd
)) {
459 "Unable to remove station %pM, device not ready.\n",
462 * It is typical for stations to be removed when we are
463 * going down. Return success since device will be down
469 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
472 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
475 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
477 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
478 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
483 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
484 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
489 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
490 kfree(priv
->stations
[sta_id
].lq
);
491 priv
->stations
[sta_id
].lq
= NULL
;
494 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++)
495 memset(&priv
->tid_data
[sta_id
][tid
], 0,
496 sizeof(priv
->tid_data
[sta_id
][tid
]));
498 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
500 priv
->num_stations
--;
502 if (WARN_ON(priv
->num_stations
< 0))
503 priv
->num_stations
= 0;
505 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
507 return iwl_send_remove_station(priv
, addr
, sta_id
, false);
509 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
514 * iwl_clear_ucode_stations - clear ucode station table bits
516 * This function clears all the bits in the driver indicating
517 * which stations are active in the ucode. Call when something
518 * other than explicit station management would cause this in
519 * the ucode, e.g. unassociated RXON.
521 void iwl_clear_ucode_stations(struct iwl_priv
*priv
,
522 struct iwl_rxon_context
*ctx
)
525 unsigned long flags_spin
;
526 bool cleared
= false;
528 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
530 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
531 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
532 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
535 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
537 "Clearing ucode active for station %d\n", i
);
538 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
542 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
546 "No active stations found to be cleared\n");
550 * iwl_restore_stations() - Restore driver known stations to device
552 * All stations considered active by driver, but not present in ucode, is
557 void iwl_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
559 struct iwl_addsta_cmd sta_cmd
;
560 struct iwl_link_quality_cmd lq
;
561 unsigned long flags_spin
;
567 if (!iwl_is_ready(priv
->shrd
)) {
569 "Not ready yet, not restoring any stations.\n");
573 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
574 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
575 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
576 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
578 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
579 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
580 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
581 priv
->stations
[i
].sta
.sta
.addr
);
582 priv
->stations
[i
].sta
.mode
= 0;
583 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
588 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
589 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
590 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
591 sizeof(struct iwl_addsta_cmd
));
593 if (priv
->stations
[i
].lq
) {
594 if (priv
->shrd
->wowlan
)
595 iwl_sta_fill_lq(priv
, ctx
, i
, &lq
);
597 memcpy(&lq
, priv
->stations
[i
].lq
,
598 sizeof(struct iwl_link_quality_cmd
));
601 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
,
603 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
605 spin_lock_irqsave(&priv
->shrd
->sta_lock
,
607 IWL_ERR(priv
, "Adding station %pM failed.\n",
608 priv
->stations
[i
].sta
.sta
.addr
);
609 priv
->stations
[i
].used
&=
610 ~IWL_STA_DRIVER_ACTIVE
;
611 priv
->stations
[i
].used
&=
612 ~IWL_STA_UCODE_INPROGRESS
;
613 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
,
617 * Rate scaling has already been initialized, send
621 iwl_send_lq_cmd(priv
, ctx
, &lq
,
623 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
624 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
628 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
630 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
631 "no stations to be restored.\n");
633 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
637 void iwl_reprogram_ap_sta(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
640 int sta_id
= ctx
->ap_sta_id
;
642 struct iwl_addsta_cmd sta_cmd
;
643 struct iwl_link_quality_cmd lq
;
644 bool active
, have_lq
= false;
646 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
647 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
648 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
652 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
654 if (priv
->stations
[sta_id
].lq
) {
655 memcpy(&lq
, priv
->stations
[sta_id
].lq
, sizeof(lq
));
659 active
= priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
;
660 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
661 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
664 ret
= iwl_send_remove_station(
665 priv
, priv
->stations
[sta_id
].sta
.sta
.addr
,
668 IWL_ERR(priv
, "failed to remove STA %pM (%d)\n",
669 priv
->stations
[sta_id
].sta
.sta
.addr
, ret
);
671 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
672 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
673 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
675 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
677 IWL_ERR(priv
, "failed to re-add STA %pM (%d)\n",
678 priv
->stations
[sta_id
].sta
.sta
.addr
, ret
);
680 iwl_send_lq_cmd(priv
, ctx
, &lq
, CMD_SYNC
, true);
683 int iwl_get_free_ucode_key_offset(struct iwl_priv
*priv
)
687 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
688 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
691 return WEP_INVALID_OFFSET
;
694 void iwl_dealloc_bcast_stations(struct iwl_priv
*priv
)
699 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
700 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
701 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
704 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
705 priv
->num_stations
--;
706 if (WARN_ON(priv
->num_stations
< 0))
707 priv
->num_stations
= 0;
708 kfree(priv
->stations
[i
].lq
);
709 priv
->stations
[i
].lq
= NULL
;
711 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
714 #ifdef CONFIG_IWLWIFI_DEBUG
715 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
716 struct iwl_link_quality_cmd
*lq
)
719 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
720 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
721 lq
->general_params
.single_stream_ant_msk
,
722 lq
->general_params
.dual_stream_ant_msk
);
724 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
725 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
726 i
, lq
->rs_table
[i
].rate_n_flags
);
729 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
730 struct iwl_link_quality_cmd
*lq
)
736 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
738 * It sometimes happens when a HT rate has been in use and we
739 * loose connectivity with AP then mac80211 will first tell us that the
740 * current channel is not HT anymore before removing the station. In such a
741 * scenario the RXON flags will be updated to indicate we are not
742 * communicating HT anymore, but the LQ command may still contain HT rates.
743 * Test for this to prevent driver from sending LQ command between the time
744 * RXON flags are updated and when LQ command is updated.
746 static bool is_lq_table_valid(struct iwl_priv
*priv
,
747 struct iwl_rxon_context
*ctx
,
748 struct iwl_link_quality_cmd
*lq
)
755 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
756 ctx
->active
.channel
);
757 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
758 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) &
761 "index %d of LQ expects HT channel\n",
770 * iwl_send_lq_cmd() - Send link quality command
771 * @init: This command is sent as part of station initialization right
772 * after station has been added.
774 * The link quality command is sent as the last step of station creation.
775 * This is the special case in which init is set and we call a callback in
776 * this case to clear the state indicating that station creation is in
779 int iwl_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
780 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
783 unsigned long flags_spin
;
785 struct iwl_host_cmd cmd
= {
786 .id
= REPLY_TX_LINK_QUALITY_CMD
,
787 .len
= { sizeof(struct iwl_link_quality_cmd
), },
792 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
796 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
797 if (!(priv
->stations
[lq
->sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
798 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
801 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
803 iwl_dump_lq_cmd(priv
, lq
);
804 if (WARN_ON(init
&& (cmd
.flags
& CMD_ASYNC
)))
807 if (is_lq_table_valid(priv
, ctx
, lq
))
808 ret
= iwl_trans_send_cmd(trans(priv
), &cmd
);
812 if (cmd
.flags
& CMD_ASYNC
)
816 IWL_DEBUG_INFO(priv
, "init LQ command complete, "
817 "clearing sta addition status for sta %d\n",
819 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags_spin
);
820 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
821 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags_spin
);
827 void iwl_sta_fill_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
828 u8 sta_id
, struct iwl_link_quality_cmd
*link_cmd
)
834 lockdep_assert_held(&priv
->shrd
->mutex
);
836 memset(link_cmd
, 0, sizeof(*link_cmd
));
838 /* Set up the rate scaling to start at selected rate, fall back
839 * all the way down to 1M in IEEE order, and then spin on 1M */
840 if (priv
->band
== IEEE80211_BAND_5GHZ
)
841 r
= IWL_RATE_6M_INDEX
;
842 else if (ctx
&& ctx
->vif
&& ctx
->vif
->p2p
)
843 r
= IWL_RATE_6M_INDEX
;
845 r
= IWL_RATE_1M_INDEX
;
847 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
848 rate_flags
|= RATE_MCS_CCK_MSK
;
850 rate_flags
|= first_antenna(hw_params(priv
).valid_tx_ant
) <<
852 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
853 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
854 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
856 link_cmd
->general_params
.single_stream_ant_msk
=
857 first_antenna(hw_params(priv
).valid_tx_ant
);
859 link_cmd
->general_params
.dual_stream_ant_msk
=
860 hw_params(priv
).valid_tx_ant
&
861 ~first_antenna(hw_params(priv
).valid_tx_ant
);
862 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
863 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
864 } else if (num_of_ant(hw_params(priv
).valid_tx_ant
) == 2) {
865 link_cmd
->general_params
.dual_stream_ant_msk
=
866 hw_params(priv
).valid_tx_ant
;
869 link_cmd
->agg_params
.agg_dis_start_th
=
870 LINK_QUAL_AGG_DISABLE_START_DEF
;
871 link_cmd
->agg_params
.agg_time_limit
=
872 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
874 link_cmd
->sta_id
= sta_id
;
877 static struct iwl_link_quality_cmd
*
878 iwl_sta_alloc_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
881 struct iwl_link_quality_cmd
*link_cmd
;
883 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
885 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
889 iwl_sta_fill_lq(priv
, ctx
, sta_id
, link_cmd
);
895 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
899 int iwlagn_add_bssid_station(struct iwl_priv
*priv
,
900 struct iwl_rxon_context
*ctx
,
901 const u8
*addr
, u8
*sta_id_r
)
905 struct iwl_link_quality_cmd
*link_cmd
;
909 *sta_id_r
= IWL_INVALID_STATION
;
911 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
913 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
920 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
921 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
922 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
924 /* Set up default rate scaling table in device's station table */
925 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
928 "Unable to initialize rate scaling for station %pM.\n",
933 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
935 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
937 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
938 priv
->stations
[sta_id
].lq
= link_cmd
;
939 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
947 * For each context, the device has a table of 4 static WEP keys
948 * (one for each key index) that is updated with the following
952 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
953 struct iwl_rxon_context
*ctx
,
956 int i
, not_empty
= 0;
957 u8 buff
[sizeof(struct iwl_wep_cmd
) +
958 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
959 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
960 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
961 struct iwl_host_cmd cmd
= {
962 .id
= ctx
->wep_key_cmd
,
963 .data
= { wep_cmd
, },
969 memset(wep_cmd
, 0, cmd_size
+
970 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
972 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
973 wep_cmd
->key
[i
].key_index
= i
;
974 if (ctx
->wep_keys
[i
].key_size
) {
975 wep_cmd
->key
[i
].key_offset
= i
;
978 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
981 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
982 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
983 ctx
->wep_keys
[i
].key_size
);
986 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
987 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
989 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
991 cmd
.len
[0] = cmd_size
;
993 if (not_empty
|| send_if_empty
)
994 return iwl_trans_send_cmd(trans(priv
), &cmd
);
999 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
1000 struct iwl_rxon_context
*ctx
)
1002 lockdep_assert_held(&priv
->shrd
->mutex
);
1004 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1007 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
1008 struct iwl_rxon_context
*ctx
,
1009 struct ieee80211_key_conf
*keyconf
)
1013 lockdep_assert_held(&priv
->shrd
->mutex
);
1015 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
1018 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
1019 if (iwl_is_rfkill(priv
->shrd
)) {
1021 "Not sending REPLY_WEPKEY command due to RFKILL.\n");
1022 /* but keys in device are clear anyway so return success */
1025 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
1026 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
1027 keyconf
->keyidx
, ret
);
1032 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
1033 struct iwl_rxon_context
*ctx
,
1034 struct ieee80211_key_conf
*keyconf
)
1038 lockdep_assert_held(&priv
->shrd
->mutex
);
1040 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
1041 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
1043 "Bad WEP key length %d\n", keyconf
->keylen
);
1047 keyconf
->hw_key_idx
= IWLAGN_HW_KEY_DEFAULT
;
1049 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
1050 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
1053 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1054 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
1055 keyconf
->keylen
, keyconf
->keyidx
, ret
);
1061 * dynamic (per-station) keys
1063 * The dynamic keys are a little more complicated. The device has
1064 * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
1065 * These are linked to stations by a table that contains an index
1066 * into the key table for each station/key index/{mcast,unicast},
1067 * i.e. it's basically an array of pointers like this:
1068 * key_offset_t key_mapping[NUM_STATIONS][4][2];
1069 * (it really works differently, but you can think of it as such)
1071 * The key uploading and linking happens in the same command, the
1072 * add station command with STA_MODIFY_KEY_MASK.
1075 static u8
iwlagn_key_sta_id(struct iwl_priv
*priv
,
1076 struct ieee80211_vif
*vif
,
1077 struct ieee80211_sta
*sta
)
1079 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1080 u8 sta_id
= IWL_INVALID_STATION
;
1083 sta_id
= iwl_sta_id(sta
);
1086 * The device expects GTKs for station interfaces to be
1087 * installed as GTKs for the AP station. If we have no
1088 * station ID, then use the ap_sta_id in that case.
1090 if (!sta
&& vif
&& vif_priv
->ctx
) {
1091 switch (vif
->type
) {
1092 case NL80211_IFTYPE_STATION
:
1093 sta_id
= vif_priv
->ctx
->ap_sta_id
;
1097 * In all other cases, the key will be
1098 * used either for TX only or is bound
1099 * to a station already.
1108 static int iwlagn_send_sta_key(struct iwl_priv
*priv
,
1109 struct ieee80211_key_conf
*keyconf
,
1110 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1113 unsigned long flags
;
1115 struct iwl_addsta_cmd sta_cmd
;
1118 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1119 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1120 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1122 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1123 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
;
1125 switch (keyconf
->cipher
) {
1126 case WLAN_CIPHER_SUITE_CCMP
:
1127 key_flags
|= STA_KEY_FLG_CCMP
;
1128 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1130 case WLAN_CIPHER_SUITE_TKIP
:
1131 key_flags
|= STA_KEY_FLG_TKIP
;
1132 sta_cmd
.key
.tkip_rx_tsc_byte2
= tkip_iv32
;
1133 for (i
= 0; i
< 5; i
++)
1134 sta_cmd
.key
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1135 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1137 case WLAN_CIPHER_SUITE_WEP104
:
1138 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
1140 case WLAN_CIPHER_SUITE_WEP40
:
1141 key_flags
|= STA_KEY_FLG_WEP
;
1142 memcpy(&sta_cmd
.key
.key
[3], keyconf
->key
, keyconf
->keylen
);
1149 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1150 key_flags
|= STA_KEY_MULTICAST_MSK
;
1152 /* key pointer (offset) */
1153 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
1155 sta_cmd
.key
.key_flags
= key_flags
;
1156 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1157 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1159 return iwl_send_add_sta(priv
, &sta_cmd
, cmd_flags
);
1162 void iwl_update_tkip_key(struct iwl_priv
*priv
,
1163 struct ieee80211_vif
*vif
,
1164 struct ieee80211_key_conf
*keyconf
,
1165 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
1167 u8 sta_id
= iwlagn_key_sta_id(priv
, vif
, sta
);
1169 if (sta_id
== IWL_INVALID_STATION
)
1172 if (iwl_scan_cancel(priv
)) {
1173 /* cancel scan failed, just live w/ bad key and rely
1174 briefly on SW decryption */
1178 iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1179 iv32
, phase1key
, CMD_ASYNC
);
1182 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
1183 struct iwl_rxon_context
*ctx
,
1184 struct ieee80211_key_conf
*keyconf
,
1185 struct ieee80211_sta
*sta
)
1187 unsigned long flags
;
1188 struct iwl_addsta_cmd sta_cmd
;
1189 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1192 /* if station isn't there, neither is the key */
1193 if (sta_id
== IWL_INVALID_STATION
)
1196 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1197 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1198 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
))
1199 sta_id
= IWL_INVALID_STATION
;
1200 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1202 if (sta_id
== IWL_INVALID_STATION
)
1205 lockdep_assert_held(&priv
->shrd
->mutex
);
1207 ctx
->key_mapping_keys
--;
1209 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
1210 keyconf
->keyidx
, sta_id
);
1212 if (!test_and_clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
))
1213 IWL_ERR(priv
, "offset %d not used in uCode key table.\n",
1214 keyconf
->hw_key_idx
);
1216 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1217 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
| STA_KEY_FLG_NO_ENC
|
1218 STA_KEY_FLG_INVALID
;
1220 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1221 key_flags
|= STA_KEY_MULTICAST_MSK
;
1223 sta_cmd
.key
.key_flags
= key_flags
;
1224 sta_cmd
.key
.key_offset
= WEP_INVALID_OFFSET
;
1225 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1226 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1228 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1231 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
1232 struct iwl_rxon_context
*ctx
,
1233 struct ieee80211_key_conf
*keyconf
,
1234 struct ieee80211_sta
*sta
)
1236 struct ieee80211_key_seq seq
;
1239 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1242 if (sta_id
== IWL_INVALID_STATION
)
1245 lockdep_assert_held(&priv
->shrd
->mutex
);
1247 keyconf
->hw_key_idx
= iwl_get_free_ucode_key_offset(priv
);
1248 if (keyconf
->hw_key_idx
== WEP_INVALID_OFFSET
)
1251 ctx
->key_mapping_keys
++;
1253 switch (keyconf
->cipher
) {
1254 case WLAN_CIPHER_SUITE_TKIP
:
1257 else /* station mode case only */
1258 addr
= ctx
->active
.bssid_addr
;
1260 /* pre-fill phase 1 key into device cache */
1261 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1262 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1263 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1264 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1266 case WLAN_CIPHER_SUITE_CCMP
:
1267 case WLAN_CIPHER_SUITE_WEP40
:
1268 case WLAN_CIPHER_SUITE_WEP104
:
1269 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1273 IWL_ERR(priv
, "Unknown cipher %x\n", keyconf
->cipher
);
1278 ctx
->key_mapping_keys
--;
1279 clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
);
1282 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1283 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1284 sta
? sta
->addr
: NULL
, ret
);
1290 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
1292 * This adds the broadcast station into the driver's station table
1293 * and marks it driver active, so that it will be restored to the
1294 * device at the next best time.
1296 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
1297 struct iwl_rxon_context
*ctx
)
1299 struct iwl_link_quality_cmd
*link_cmd
;
1300 unsigned long flags
;
1303 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1304 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
1305 if (sta_id
== IWL_INVALID_STATION
) {
1306 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
1307 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1312 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
1313 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
1314 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1316 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1319 "Unable to initialize rate scaling for bcast station.\n");
1323 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1324 priv
->stations
[sta_id
].lq
= link_cmd
;
1325 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1331 * iwl_update_bcast_station - update broadcast station's LQ command
1333 * Only used by iwlagn. Placed here to have all bcast station management
1336 int iwl_update_bcast_station(struct iwl_priv
*priv
,
1337 struct iwl_rxon_context
*ctx
)
1339 unsigned long flags
;
1340 struct iwl_link_quality_cmd
*link_cmd
;
1341 u8 sta_id
= ctx
->bcast_sta_id
;
1343 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1345 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
1349 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1350 if (priv
->stations
[sta_id
].lq
)
1351 kfree(priv
->stations
[sta_id
].lq
);
1353 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
1354 priv
->stations
[sta_id
].lq
= link_cmd
;
1355 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1360 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
1362 struct iwl_rxon_context
*ctx
;
1365 for_each_context(priv
, ctx
) {
1366 ret
= iwl_update_bcast_station(priv
, ctx
);
1375 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1377 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
1379 unsigned long flags
;
1380 struct iwl_addsta_cmd sta_cmd
;
1382 lockdep_assert_held(&priv
->shrd
->mutex
);
1384 /* Remove "disable" flag, to enable Tx for this TID */
1385 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1386 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
1387 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
1388 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1389 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1390 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1392 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1395 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1398 unsigned long flags
;
1400 struct iwl_addsta_cmd sta_cmd
;
1402 lockdep_assert_held(&priv
->shrd
->mutex
);
1404 sta_id
= iwl_sta_id(sta
);
1405 if (sta_id
== IWL_INVALID_STATION
)
1408 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1409 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1410 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
1411 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
1412 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1413 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1414 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1415 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1417 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1420 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1423 unsigned long flags
;
1425 struct iwl_addsta_cmd sta_cmd
;
1427 lockdep_assert_held(&priv
->shrd
->mutex
);
1429 sta_id
= iwl_sta_id(sta
);
1430 if (sta_id
== IWL_INVALID_STATION
) {
1431 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
1435 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1436 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1437 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
1438 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
1439 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1440 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1441 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);
1443 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1448 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
1450 unsigned long flags
;
1452 spin_lock_irqsave(&priv
->shrd
->sta_lock
, flags
);
1453 priv
->stations
[sta_id
].sta
.station_flags
|= STA_FLG_PWR_SAVE_MSK
;
1454 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
1455 priv
->stations
[sta_id
].sta
.sta
.modify_mask
=
1456 STA_MODIFY_SLEEP_TX_COUNT_MSK
;
1457 priv
->stations
[sta_id
].sta
.sleep_tx_count
= cpu_to_le16(cnt
);
1458 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1459 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1460 spin_unlock_irqrestore(&priv
->shrd
->sta_lock
, flags
);