1 /******************************************************************************
3 * Copyright(c) 2003 - 2013 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 *****************************************************************************/
29 #include <linux/etherdevice.h>
30 #include <net/mac80211.h>
31 #include "iwl-trans.h"
35 const u8 iwl_bcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
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 struct iwl_add_sta_resp
*add_sta_resp
= (void *)pkt
->data
;
68 u8 sta_id
= addsta
->sta
.sta_id
;
71 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
72 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
77 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
80 spin_lock_bh(&priv
->sta_lock
);
82 switch (add_sta_resp
->status
) {
83 case ADD_STA_SUCCESS_MSK
:
84 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
85 ret
= iwl_sta_ucode_activate(priv
, sta_id
);
87 case ADD_STA_NO_ROOM_IN_TABLE
:
88 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
91 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
92 IWL_ERR(priv
, "Adding station %d failed, no block ack "
93 "resource.\n", sta_id
);
95 case ADD_STA_MODIFY_NON_EXIST_STA
:
96 IWL_ERR(priv
, "Attempting to modify non-existing station %d\n",
100 IWL_DEBUG_ASSOC(priv
, "Received REPLY_ADD_STA:(0x%08X)\n",
101 add_sta_resp
->status
);
105 IWL_DEBUG_INFO(priv
, "%s station id %u addr %pM\n",
106 priv
->stations
[sta_id
].sta
.mode
==
107 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
108 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
111 * XXX: The MAC address in the command buffer is often changed from
112 * the original sent to the device. That is, the MAC address
113 * written to the command buffer often is not the same MAC address
114 * read from the command buffer when the command returns. This
115 * issue has not yet been resolved and this debugging is left to
116 * observe the problem.
118 IWL_DEBUG_INFO(priv
, "%s station according to cmd buffer %pM\n",
119 priv
->stations
[sta_id
].sta
.mode
==
120 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
122 spin_unlock_bh(&priv
->sta_lock
);
127 int iwl_add_sta_callback(struct iwl_priv
*priv
, struct iwl_rx_cmd_buffer
*rxb
,
128 struct iwl_device_cmd
*cmd
)
130 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
135 return iwl_process_add_sta_resp(priv
, (void *)cmd
->payload
, pkt
);
138 int iwl_send_add_sta(struct iwl_priv
*priv
,
139 struct iwl_addsta_cmd
*sta
, u8 flags
)
142 struct iwl_host_cmd cmd
= {
146 .len
= { sizeof(*sta
), },
148 u8 sta_id __maybe_unused
= sta
->sta
.sta_id
;
150 IWL_DEBUG_INFO(priv
, "Adding sta %u (%pM) %ssynchronously\n",
151 sta_id
, sta
->sta
.addr
, flags
& CMD_ASYNC
? "a" : "");
153 if (!(flags
& CMD_ASYNC
)) {
154 cmd
.flags
|= CMD_WANT_SKB
;
158 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
160 if (ret
|| (flags
& CMD_ASYNC
))
162 /*else the command was successfully sent in SYNC mode, need to free
167 if (cmd
.handler_status
)
168 IWL_ERR(priv
, "%s - error in the CMD response %d", __func__
,
171 return cmd
.handler_status
;
174 bool iwl_is_ht40_tx_allowed(struct iwl_priv
*priv
,
175 struct iwl_rxon_context
*ctx
,
176 struct ieee80211_sta
*sta
)
178 if (!ctx
->ht
.enabled
|| !ctx
->ht
.is_40mhz
)
181 #ifdef CONFIG_IWLWIFI_DEBUGFS
182 if (priv
->disable_ht40
)
186 /* special case for RXON */
190 return sta
->bandwidth
>= IEEE80211_STA_RX_BW_40
;
193 static void iwl_sta_calc_ht_flags(struct iwl_priv
*priv
,
194 struct ieee80211_sta
*sta
,
195 struct iwl_rxon_context
*ctx
,
196 __le32
*flags
, __le32
*mask
)
198 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
200 *mask
= STA_FLG_RTS_MIMO_PROT_MSK
|
201 STA_FLG_MIMO_DIS_MSK
|
202 STA_FLG_HT40_EN_MSK
|
203 STA_FLG_MAX_AGG_SIZE_MSK
|
204 STA_FLG_AGG_MPDU_DENSITY_MSK
;
207 if (!sta
|| !sta_ht_inf
->ht_supported
)
210 IWL_DEBUG_INFO(priv
, "STA %pM SM PS mode: %s\n",
212 (sta
->smps_mode
== IEEE80211_SMPS_STATIC
) ?
214 (sta
->smps_mode
== IEEE80211_SMPS_DYNAMIC
) ?
215 "dynamic" : "disabled");
217 switch (sta
->smps_mode
) {
218 case IEEE80211_SMPS_STATIC
:
219 *flags
|= STA_FLG_MIMO_DIS_MSK
;
221 case IEEE80211_SMPS_DYNAMIC
:
222 *flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
224 case IEEE80211_SMPS_OFF
:
227 IWL_WARN(priv
, "Invalid MIMO PS mode %d\n", sta
->smps_mode
);
231 *flags
|= cpu_to_le32(
232 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
234 *flags
|= cpu_to_le32(
235 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
237 if (iwl_is_ht40_tx_allowed(priv
, ctx
, sta
))
238 *flags
|= STA_FLG_HT40_EN_MSK
;
241 int iwl_sta_update_ht(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
242 struct ieee80211_sta
*sta
)
244 u8 sta_id
= iwl_sta_id(sta
);
246 struct iwl_addsta_cmd cmd
;
248 if (WARN_ON_ONCE(sta_id
== IWL_INVALID_STATION
))
251 iwl_sta_calc_ht_flags(priv
, sta
, ctx
, &flags
, &mask
);
253 spin_lock_bh(&priv
->sta_lock
);
254 priv
->stations
[sta_id
].sta
.station_flags
&= ~mask
;
255 priv
->stations
[sta_id
].sta
.station_flags
|= flags
;
256 spin_unlock_bh(&priv
->sta_lock
);
258 memset(&cmd
, 0, sizeof(cmd
));
259 cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
260 cmd
.station_flags_msk
= mask
;
261 cmd
.station_flags
= flags
;
262 cmd
.sta
.sta_id
= sta_id
;
264 return iwl_send_add_sta(priv
, &cmd
, CMD_SYNC
);
267 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
268 struct ieee80211_sta
*sta
,
269 struct iwl_rxon_context
*ctx
)
273 iwl_sta_calc_ht_flags(priv
, sta
, ctx
, &flags
, &mask
);
275 lockdep_assert_held(&priv
->sta_lock
);
276 priv
->stations
[index
].sta
.station_flags
&= ~mask
;
277 priv
->stations
[index
].sta
.station_flags
|= flags
;
281 * iwl_prep_station - Prepare station information for addition
283 * should be called with sta_lock held
285 u8
iwl_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
286 const u8
*addr
, bool is_ap
, struct ieee80211_sta
*sta
)
288 struct iwl_station_entry
*station
;
290 u8 sta_id
= IWL_INVALID_STATION
;
293 sta_id
= ctx
->ap_sta_id
;
294 else if (is_broadcast_ether_addr(addr
))
295 sta_id
= ctx
->bcast_sta_id
;
297 for (i
= IWL_STA_ID
; i
< IWLAGN_STATION_COUNT
; i
++) {
298 if (ether_addr_equal(priv
->stations
[i
].sta
.sta
.addr
,
304 if (!priv
->stations
[i
].used
&&
305 sta_id
== IWL_INVALID_STATION
)
310 * These two conditions have the same outcome, but keep them
313 if (unlikely(sta_id
== IWL_INVALID_STATION
))
317 * uCode is not able to deal with multiple requests to add a
318 * station. Keep track if one is in progress so that we do not send
321 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
322 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
327 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
328 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
329 ether_addr_equal(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
330 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
331 "adding again.\n", sta_id
, addr
);
335 station
= &priv
->stations
[sta_id
];
336 station
->used
= IWL_STA_DRIVER_ACTIVE
;
337 IWL_DEBUG_ASSOC(priv
, "Add STA to driver ID %d: %pM\n",
339 priv
->num_stations
++;
341 /* Set up the REPLY_ADD_STA command to send to device */
342 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
343 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
344 station
->sta
.mode
= 0;
345 station
->sta
.sta
.sta_id
= sta_id
;
346 station
->sta
.station_flags
= ctx
->station_flags
;
347 station
->ctxid
= ctx
->ctxid
;
350 struct iwl_station_priv
*sta_priv
;
352 sta_priv
= (void *)sta
->drv_priv
;
357 * OK to call unconditionally, since local stations (IBSS BSSID
358 * STA and broadcast STA) pass in a NULL sta, and mac80211
359 * doesn't allow HT IBSS.
361 iwl_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
367 #define STA_WAIT_TIMEOUT (HZ/2)
370 * iwl_add_station_common -
372 int iwl_add_station_common(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
373 const u8
*addr
, bool is_ap
,
374 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
378 struct iwl_addsta_cmd sta_cmd
;
381 spin_lock_bh(&priv
->sta_lock
);
382 sta_id
= iwl_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
383 if (sta_id
== IWL_INVALID_STATION
) {
384 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
386 spin_unlock_bh(&priv
->sta_lock
);
391 * uCode is not able to deal with multiple requests to add a
392 * station. Keep track if one is in progress so that we do not send
395 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
396 IWL_DEBUG_INFO(priv
, "STA %d already in process of being "
398 spin_unlock_bh(&priv
->sta_lock
);
402 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
403 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
404 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not "
405 "adding again.\n", sta_id
, addr
);
406 spin_unlock_bh(&priv
->sta_lock
);
410 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
411 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
,
412 sizeof(struct iwl_addsta_cmd
));
413 spin_unlock_bh(&priv
->sta_lock
);
415 /* Add station to device's station table */
416 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
418 spin_lock_bh(&priv
->sta_lock
);
419 IWL_ERR(priv
, "Adding station %pM failed.\n",
420 priv
->stations
[sta_id
].sta
.sta
.addr
);
421 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
422 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
423 spin_unlock_bh(&priv
->sta_lock
);
430 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
432 static void iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
434 lockdep_assert_held(&priv
->sta_lock
);
436 /* Ucode must be active and driver must be non active */
437 if ((priv
->stations
[sta_id
].used
&
438 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) !=
439 IWL_STA_UCODE_ACTIVE
)
440 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
442 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
444 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
445 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
448 static int iwl_send_remove_station(struct iwl_priv
*priv
,
449 const u8
*addr
, int sta_id
,
452 struct iwl_rx_packet
*pkt
;
454 struct iwl_rem_sta_cmd rm_sta_cmd
;
456 struct iwl_host_cmd cmd
= {
457 .id
= REPLY_REMOVE_STA
,
458 .len
= { sizeof(struct iwl_rem_sta_cmd
), },
460 .data
= { &rm_sta_cmd
, },
463 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
464 rm_sta_cmd
.num_sta
= 1;
465 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
467 cmd
.flags
|= CMD_WANT_SKB
;
469 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
475 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
476 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
482 struct iwl_rem_sta_resp
*rem_sta_resp
= (void *)pkt
->data
;
483 switch (rem_sta_resp
->status
) {
484 case REM_STA_SUCCESS_MSK
:
486 spin_lock_bh(&priv
->sta_lock
);
487 iwl_sta_ucode_deactivate(priv
, sta_id
);
488 spin_unlock_bh(&priv
->sta_lock
);
490 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
494 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
504 * iwl_remove_station - Remove driver's knowledge of station.
506 int iwl_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
511 if (!iwl_is_ready(priv
)) {
513 "Unable to remove station %pM, device not ready.\n",
516 * It is typical for stations to be removed when we are
517 * going down. Return success since device will be down
523 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
526 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
529 spin_lock_bh(&priv
->sta_lock
);
531 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
532 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
537 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
538 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
543 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
544 kfree(priv
->stations
[sta_id
].lq
);
545 priv
->stations
[sta_id
].lq
= NULL
;
548 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++)
549 memset(&priv
->tid_data
[sta_id
][tid
], 0,
550 sizeof(priv
->tid_data
[sta_id
][tid
]));
552 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
554 priv
->num_stations
--;
556 if (WARN_ON(priv
->num_stations
< 0))
557 priv
->num_stations
= 0;
559 spin_unlock_bh(&priv
->sta_lock
);
561 return iwl_send_remove_station(priv
, addr
, sta_id
, false);
563 spin_unlock_bh(&priv
->sta_lock
);
567 void iwl_deactivate_station(struct iwl_priv
*priv
, const u8 sta_id
,
572 if (!iwl_is_ready(priv
)) {
574 "Unable to remove station %pM, device not ready.\n",
579 IWL_DEBUG_ASSOC(priv
, "Deactivating STA: %pM (%d)\n", addr
, sta_id
);
581 if (WARN_ON_ONCE(sta_id
== IWL_INVALID_STATION
))
584 spin_lock_bh(&priv
->sta_lock
);
586 WARN_ON_ONCE(!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
));
588 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++)
589 memset(&priv
->tid_data
[sta_id
][tid
], 0,
590 sizeof(priv
->tid_data
[sta_id
][tid
]));
592 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
594 priv
->num_stations
--;
596 if (WARN_ON_ONCE(priv
->num_stations
< 0))
597 priv
->num_stations
= 0;
599 spin_unlock_bh(&priv
->sta_lock
);
602 static void iwl_sta_fill_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
603 u8 sta_id
, struct iwl_link_quality_cmd
*link_cmd
)
609 lockdep_assert_held(&priv
->mutex
);
611 memset(link_cmd
, 0, sizeof(*link_cmd
));
613 /* Set up the rate scaling to start at selected rate, fall back
614 * all the way down to 1M in IEEE order, and then spin on 1M */
615 if (priv
->band
== IEEE80211_BAND_5GHZ
)
616 r
= IWL_RATE_6M_INDEX
;
617 else if (ctx
&& ctx
->vif
&& ctx
->vif
->p2p
)
618 r
= IWL_RATE_6M_INDEX
;
620 r
= IWL_RATE_1M_INDEX
;
622 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
623 rate_flags
|= RATE_MCS_CCK_MSK
;
625 rate_flags
|= first_antenna(priv
->nvm_data
->valid_tx_ant
) <<
627 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
628 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
629 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
631 link_cmd
->general_params
.single_stream_ant_msk
=
632 first_antenna(priv
->nvm_data
->valid_tx_ant
);
634 link_cmd
->general_params
.dual_stream_ant_msk
=
635 priv
->nvm_data
->valid_tx_ant
&
636 ~first_antenna(priv
->nvm_data
->valid_tx_ant
);
637 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
638 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
639 } else if (num_of_ant(priv
->nvm_data
->valid_tx_ant
) == 2) {
640 link_cmd
->general_params
.dual_stream_ant_msk
=
641 priv
->nvm_data
->valid_tx_ant
;
644 link_cmd
->agg_params
.agg_dis_start_th
=
645 LINK_QUAL_AGG_DISABLE_START_DEF
;
646 link_cmd
->agg_params
.agg_time_limit
=
647 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
649 link_cmd
->sta_id
= sta_id
;
653 * iwl_clear_ucode_stations - clear ucode station table bits
655 * This function clears all the bits in the driver indicating
656 * which stations are active in the ucode. Call when something
657 * other than explicit station management would cause this in
658 * the ucode, e.g. unassociated RXON.
660 void iwl_clear_ucode_stations(struct iwl_priv
*priv
,
661 struct iwl_rxon_context
*ctx
)
664 bool cleared
= false;
666 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
668 spin_lock_bh(&priv
->sta_lock
);
669 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
670 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
673 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
675 "Clearing ucode active for station %d\n", i
);
676 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
680 spin_unlock_bh(&priv
->sta_lock
);
684 "No active stations found to be cleared\n");
688 * iwl_restore_stations() - Restore driver known stations to device
690 * All stations considered active by driver, but not present in ucode, is
695 void iwl_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
697 struct iwl_addsta_cmd sta_cmd
;
698 static const struct iwl_link_quality_cmd zero_lq
= {};
699 struct iwl_link_quality_cmd lq
;
705 if (!iwl_is_ready(priv
)) {
707 "Not ready yet, not restoring any stations.\n");
711 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
712 spin_lock_bh(&priv
->sta_lock
);
713 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
714 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
716 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
717 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
718 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
719 priv
->stations
[i
].sta
.sta
.addr
);
720 priv
->stations
[i
].sta
.mode
= 0;
721 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
726 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
727 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
728 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
729 sizeof(struct iwl_addsta_cmd
));
731 if (priv
->stations
[i
].lq
) {
733 iwl_sta_fill_lq(priv
, ctx
, i
, &lq
);
735 memcpy(&lq
, priv
->stations
[i
].lq
,
736 sizeof(struct iwl_link_quality_cmd
));
738 if (memcmp(&lq
, &zero_lq
, sizeof(lq
)))
741 spin_unlock_bh(&priv
->sta_lock
);
742 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
744 spin_lock_bh(&priv
->sta_lock
);
745 IWL_ERR(priv
, "Adding station %pM failed.\n",
746 priv
->stations
[i
].sta
.sta
.addr
);
747 priv
->stations
[i
].used
&=
748 ~IWL_STA_DRIVER_ACTIVE
;
749 priv
->stations
[i
].used
&=
750 ~IWL_STA_UCODE_INPROGRESS
;
754 * Rate scaling has already been initialized, send
758 iwl_send_lq_cmd(priv
, ctx
, &lq
,
760 spin_lock_bh(&priv
->sta_lock
);
761 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
765 spin_unlock_bh(&priv
->sta_lock
);
767 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
768 "no stations to be restored.\n");
770 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... "
774 int iwl_get_free_ucode_key_offset(struct iwl_priv
*priv
)
778 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
779 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
782 return WEP_INVALID_OFFSET
;
785 void iwl_dealloc_bcast_stations(struct iwl_priv
*priv
)
789 spin_lock_bh(&priv
->sta_lock
);
790 for (i
= 0; i
< IWLAGN_STATION_COUNT
; i
++) {
791 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
794 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
795 priv
->num_stations
--;
796 if (WARN_ON(priv
->num_stations
< 0))
797 priv
->num_stations
= 0;
798 kfree(priv
->stations
[i
].lq
);
799 priv
->stations
[i
].lq
= NULL
;
801 spin_unlock_bh(&priv
->sta_lock
);
804 #ifdef CONFIG_IWLWIFI_DEBUG
805 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
806 struct iwl_link_quality_cmd
*lq
)
809 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
810 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
811 lq
->general_params
.single_stream_ant_msk
,
812 lq
->general_params
.dual_stream_ant_msk
);
814 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
815 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
816 i
, lq
->rs_table
[i
].rate_n_flags
);
819 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
820 struct iwl_link_quality_cmd
*lq
)
826 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
828 * It sometimes happens when a HT rate has been in use and we
829 * loose connectivity with AP then mac80211 will first tell us that the
830 * current channel is not HT anymore before removing the station. In such a
831 * scenario the RXON flags will be updated to indicate we are not
832 * communicating HT anymore, but the LQ command may still contain HT rates.
833 * Test for this to prevent driver from sending LQ command between the time
834 * RXON flags are updated and when LQ command is updated.
836 static bool is_lq_table_valid(struct iwl_priv
*priv
,
837 struct iwl_rxon_context
*ctx
,
838 struct iwl_link_quality_cmd
*lq
)
845 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
846 ctx
->active
.channel
);
847 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
848 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) &
851 "index %d of LQ expects HT channel\n",
860 * iwl_send_lq_cmd() - Send link quality command
861 * @init: This command is sent as part of station initialization right
862 * after station has been added.
864 * The link quality command is sent as the last step of station creation.
865 * This is the special case in which init is set and we call a callback in
866 * this case to clear the state indicating that station creation is in
869 int iwl_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
870 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
873 struct iwl_host_cmd cmd
= {
874 .id
= REPLY_TX_LINK_QUALITY_CMD
,
875 .len
= { sizeof(struct iwl_link_quality_cmd
), },
880 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
884 spin_lock_bh(&priv
->sta_lock
);
885 if (!(priv
->stations
[lq
->sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
886 spin_unlock_bh(&priv
->sta_lock
);
889 spin_unlock_bh(&priv
->sta_lock
);
891 iwl_dump_lq_cmd(priv
, lq
);
892 if (WARN_ON(init
&& (cmd
.flags
& CMD_ASYNC
)))
895 if (is_lq_table_valid(priv
, ctx
, lq
))
896 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
900 if (cmd
.flags
& CMD_ASYNC
)
904 IWL_DEBUG_INFO(priv
, "init LQ command complete, "
905 "clearing sta addition status for sta %d\n",
907 spin_lock_bh(&priv
->sta_lock
);
908 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
909 spin_unlock_bh(&priv
->sta_lock
);
915 static struct iwl_link_quality_cmd
*
916 iwl_sta_alloc_lq(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
919 struct iwl_link_quality_cmd
*link_cmd
;
921 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
923 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
927 iwl_sta_fill_lq(priv
, ctx
, sta_id
, link_cmd
);
933 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
937 int iwlagn_add_bssid_station(struct iwl_priv
*priv
,
938 struct iwl_rxon_context
*ctx
,
939 const u8
*addr
, u8
*sta_id_r
)
943 struct iwl_link_quality_cmd
*link_cmd
;
946 *sta_id_r
= IWL_INVALID_STATION
;
948 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
950 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
957 spin_lock_bh(&priv
->sta_lock
);
958 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
959 spin_unlock_bh(&priv
->sta_lock
);
961 /* Set up default rate scaling table in device's station table */
962 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
965 "Unable to initialize rate scaling for station %pM.\n",
970 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
972 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
974 spin_lock_bh(&priv
->sta_lock
);
975 priv
->stations
[sta_id
].lq
= link_cmd
;
976 spin_unlock_bh(&priv
->sta_lock
);
984 * For each context, the device has a table of 4 static WEP keys
985 * (one for each key index) that is updated with the following
989 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
990 struct iwl_rxon_context
*ctx
,
993 int i
, not_empty
= 0;
994 u8 buff
[sizeof(struct iwl_wep_cmd
) +
995 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
996 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
997 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
998 struct iwl_host_cmd cmd
= {
999 .id
= ctx
->wep_key_cmd
,
1000 .data
= { wep_cmd
, },
1006 memset(wep_cmd
, 0, cmd_size
+
1007 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
1009 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
1010 wep_cmd
->key
[i
].key_index
= i
;
1011 if (ctx
->wep_keys
[i
].key_size
) {
1012 wep_cmd
->key
[i
].key_offset
= i
;
1015 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
1018 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
1019 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
1020 ctx
->wep_keys
[i
].key_size
);
1023 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
1024 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
1026 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
1028 cmd
.len
[0] = cmd_size
;
1030 if (not_empty
|| send_if_empty
)
1031 return iwl_dvm_send_cmd(priv
, &cmd
);
1036 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
1037 struct iwl_rxon_context
*ctx
)
1039 lockdep_assert_held(&priv
->mutex
);
1041 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1044 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
1045 struct iwl_rxon_context
*ctx
,
1046 struct ieee80211_key_conf
*keyconf
)
1050 lockdep_assert_held(&priv
->mutex
);
1052 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
1055 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
1056 if (iwl_is_rfkill(priv
)) {
1058 "Not sending REPLY_WEPKEY command due to RFKILL.\n");
1059 /* but keys in device are clear anyway so return success */
1062 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
1063 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
1064 keyconf
->keyidx
, ret
);
1069 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
1070 struct iwl_rxon_context
*ctx
,
1071 struct ieee80211_key_conf
*keyconf
)
1075 lockdep_assert_held(&priv
->mutex
);
1077 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
1078 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
1080 "Bad WEP key length %d\n", keyconf
->keylen
);
1084 keyconf
->hw_key_idx
= IWLAGN_HW_KEY_DEFAULT
;
1086 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
1087 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
1090 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
1091 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
1092 keyconf
->keylen
, keyconf
->keyidx
, ret
);
1098 * dynamic (per-station) keys
1100 * The dynamic keys are a little more complicated. The device has
1101 * a key cache of up to STA_KEY_MAX_NUM/STA_KEY_MAX_NUM_PAN keys.
1102 * These are linked to stations by a table that contains an index
1103 * into the key table for each station/key index/{mcast,unicast},
1104 * i.e. it's basically an array of pointers like this:
1105 * key_offset_t key_mapping[NUM_STATIONS][4][2];
1106 * (it really works differently, but you can think of it as such)
1108 * The key uploading and linking happens in the same command, the
1109 * add station command with STA_MODIFY_KEY_MASK.
1112 static u8
iwlagn_key_sta_id(struct iwl_priv
*priv
,
1113 struct ieee80211_vif
*vif
,
1114 struct ieee80211_sta
*sta
)
1116 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1119 return iwl_sta_id(sta
);
1122 * The device expects GTKs for station interfaces to be
1123 * installed as GTKs for the AP station. If we have no
1124 * station ID, then use the ap_sta_id in that case.
1126 if (vif
->type
== NL80211_IFTYPE_STATION
&& vif_priv
->ctx
)
1127 return vif_priv
->ctx
->ap_sta_id
;
1129 return IWL_INVALID_STATION
;
1132 static int iwlagn_send_sta_key(struct iwl_priv
*priv
,
1133 struct ieee80211_key_conf
*keyconf
,
1134 u8 sta_id
, u32 tkip_iv32
, u16
*tkip_p1k
,
1138 struct iwl_addsta_cmd sta_cmd
;
1141 spin_lock_bh(&priv
->sta_lock
);
1142 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1143 spin_unlock_bh(&priv
->sta_lock
);
1145 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1146 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
;
1148 switch (keyconf
->cipher
) {
1149 case WLAN_CIPHER_SUITE_CCMP
:
1150 key_flags
|= STA_KEY_FLG_CCMP
;
1151 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1153 case WLAN_CIPHER_SUITE_TKIP
:
1154 key_flags
|= STA_KEY_FLG_TKIP
;
1155 sta_cmd
.key
.tkip_rx_tsc_byte2
= tkip_iv32
;
1156 for (i
= 0; i
< 5; i
++)
1157 sta_cmd
.key
.tkip_rx_ttak
[i
] = cpu_to_le16(tkip_p1k
[i
]);
1158 memcpy(sta_cmd
.key
.key
, keyconf
->key
, keyconf
->keylen
);
1160 case WLAN_CIPHER_SUITE_WEP104
:
1161 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
1163 case WLAN_CIPHER_SUITE_WEP40
:
1164 key_flags
|= STA_KEY_FLG_WEP
;
1165 memcpy(&sta_cmd
.key
.key
[3], keyconf
->key
, keyconf
->keylen
);
1172 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1173 key_flags
|= STA_KEY_MULTICAST_MSK
;
1175 /* key pointer (offset) */
1176 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
1178 sta_cmd
.key
.key_flags
= key_flags
;
1179 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1180 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1182 return iwl_send_add_sta(priv
, &sta_cmd
, cmd_flags
);
1185 void iwl_update_tkip_key(struct iwl_priv
*priv
,
1186 struct ieee80211_vif
*vif
,
1187 struct ieee80211_key_conf
*keyconf
,
1188 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
1190 u8 sta_id
= iwlagn_key_sta_id(priv
, vif
, sta
);
1192 if (sta_id
== IWL_INVALID_STATION
)
1195 if (iwl_scan_cancel(priv
)) {
1196 /* cancel scan failed, just live w/ bad key and rely
1197 briefly on SW decryption */
1201 iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1202 iv32
, phase1key
, CMD_ASYNC
);
1205 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
1206 struct iwl_rxon_context
*ctx
,
1207 struct ieee80211_key_conf
*keyconf
,
1208 struct ieee80211_sta
*sta
)
1210 struct iwl_addsta_cmd sta_cmd
;
1211 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1214 /* if station isn't there, neither is the key */
1215 if (sta_id
== IWL_INVALID_STATION
)
1218 spin_lock_bh(&priv
->sta_lock
);
1219 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(sta_cmd
));
1220 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
))
1221 sta_id
= IWL_INVALID_STATION
;
1222 spin_unlock_bh(&priv
->sta_lock
);
1224 if (sta_id
== IWL_INVALID_STATION
)
1227 lockdep_assert_held(&priv
->mutex
);
1229 ctx
->key_mapping_keys
--;
1231 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
1232 keyconf
->keyidx
, sta_id
);
1234 if (!test_and_clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
))
1235 IWL_ERR(priv
, "offset %d not used in uCode key table.\n",
1236 keyconf
->hw_key_idx
);
1238 key_flags
= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
1239 key_flags
|= STA_KEY_FLG_MAP_KEY_MSK
| STA_KEY_FLG_NO_ENC
|
1240 STA_KEY_FLG_INVALID
;
1242 if (!(keyconf
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
))
1243 key_flags
|= STA_KEY_MULTICAST_MSK
;
1245 sta_cmd
.key
.key_flags
= key_flags
;
1246 sta_cmd
.key
.key_offset
= keyconf
->hw_key_idx
;
1247 sta_cmd
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1248 sta_cmd
.mode
= STA_CONTROL_MODIFY_MSK
;
1250 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1253 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
1254 struct iwl_rxon_context
*ctx
,
1255 struct ieee80211_key_conf
*keyconf
,
1256 struct ieee80211_sta
*sta
)
1258 struct ieee80211_key_seq seq
;
1261 u8 sta_id
= iwlagn_key_sta_id(priv
, ctx
->vif
, sta
);
1264 if (sta_id
== IWL_INVALID_STATION
)
1267 lockdep_assert_held(&priv
->mutex
);
1269 keyconf
->hw_key_idx
= iwl_get_free_ucode_key_offset(priv
);
1270 if (keyconf
->hw_key_idx
== WEP_INVALID_OFFSET
)
1273 ctx
->key_mapping_keys
++;
1275 switch (keyconf
->cipher
) {
1276 case WLAN_CIPHER_SUITE_TKIP
:
1279 else /* station mode case only */
1280 addr
= ctx
->active
.bssid_addr
;
1282 /* pre-fill phase 1 key into device cache */
1283 ieee80211_get_key_rx_seq(keyconf
, 0, &seq
);
1284 ieee80211_get_tkip_rx_p1k(keyconf
, addr
, seq
.tkip
.iv32
, p1k
);
1285 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1286 seq
.tkip
.iv32
, p1k
, CMD_SYNC
);
1288 case WLAN_CIPHER_SUITE_CCMP
:
1289 case WLAN_CIPHER_SUITE_WEP40
:
1290 case WLAN_CIPHER_SUITE_WEP104
:
1291 ret
= iwlagn_send_sta_key(priv
, keyconf
, sta_id
,
1295 IWL_ERR(priv
, "Unknown cipher %x\n", keyconf
->cipher
);
1300 ctx
->key_mapping_keys
--;
1301 clear_bit(keyconf
->hw_key_idx
, &priv
->ucode_key_table
);
1304 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n",
1305 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1306 sta
? sta
->addr
: NULL
, ret
);
1312 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
1314 * This adds the broadcast station into the driver's station table
1315 * and marks it driver active, so that it will be restored to the
1316 * device at the next best time.
1318 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
1319 struct iwl_rxon_context
*ctx
)
1321 struct iwl_link_quality_cmd
*link_cmd
;
1324 spin_lock_bh(&priv
->sta_lock
);
1325 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
1326 if (sta_id
== IWL_INVALID_STATION
) {
1327 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
1328 spin_unlock_bh(&priv
->sta_lock
);
1333 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
1334 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
1335 spin_unlock_bh(&priv
->sta_lock
);
1337 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1340 "Unable to initialize rate scaling for bcast station.\n");
1344 spin_lock_bh(&priv
->sta_lock
);
1345 priv
->stations
[sta_id
].lq
= link_cmd
;
1346 spin_unlock_bh(&priv
->sta_lock
);
1352 * iwl_update_bcast_station - update broadcast station's LQ command
1354 * Only used by iwlagn. Placed here to have all bcast station management
1357 int iwl_update_bcast_station(struct iwl_priv
*priv
,
1358 struct iwl_rxon_context
*ctx
)
1360 struct iwl_link_quality_cmd
*link_cmd
;
1361 u8 sta_id
= ctx
->bcast_sta_id
;
1363 link_cmd
= iwl_sta_alloc_lq(priv
, ctx
, sta_id
);
1365 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
1369 spin_lock_bh(&priv
->sta_lock
);
1370 if (priv
->stations
[sta_id
].lq
)
1371 kfree(priv
->stations
[sta_id
].lq
);
1373 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
1374 priv
->stations
[sta_id
].lq
= link_cmd
;
1375 spin_unlock_bh(&priv
->sta_lock
);
1380 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
1382 struct iwl_rxon_context
*ctx
;
1385 for_each_context(priv
, ctx
) {
1386 ret
= iwl_update_bcast_station(priv
, ctx
);
1395 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1397 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
1399 struct iwl_addsta_cmd sta_cmd
;
1401 lockdep_assert_held(&priv
->mutex
);
1403 /* Remove "disable" flag, to enable Tx for this TID */
1404 spin_lock_bh(&priv
->sta_lock
);
1405 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
1406 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
1407 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1408 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1409 spin_unlock_bh(&priv
->sta_lock
);
1411 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1414 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1418 struct iwl_addsta_cmd sta_cmd
;
1420 lockdep_assert_held(&priv
->mutex
);
1422 sta_id
= iwl_sta_id(sta
);
1423 if (sta_id
== IWL_INVALID_STATION
)
1426 spin_lock_bh(&priv
->sta_lock
);
1427 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1428 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
1429 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
1430 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1431 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1432 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1433 spin_unlock_bh(&priv
->sta_lock
);
1435 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1438 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1442 struct iwl_addsta_cmd sta_cmd
;
1444 lockdep_assert_held(&priv
->mutex
);
1446 sta_id
= iwl_sta_id(sta
);
1447 if (sta_id
== IWL_INVALID_STATION
) {
1448 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
1452 spin_lock_bh(&priv
->sta_lock
);
1453 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1454 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
1455 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
1456 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1457 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1458 spin_unlock_bh(&priv
->sta_lock
);
1460 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1465 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
1467 struct iwl_addsta_cmd cmd
= {
1468 .mode
= STA_CONTROL_MODIFY_MSK
,
1469 .station_flags
= STA_FLG_PWR_SAVE_MSK
,
1470 .station_flags_msk
= STA_FLG_PWR_SAVE_MSK
,
1471 .sta
.sta_id
= sta_id
,
1472 .sta
.modify_mask
= STA_MODIFY_SLEEP_TX_COUNT_MSK
,
1473 .sleep_tx_count
= cpu_to_le16(cnt
),
1476 iwl_send_add_sta(priv
, &cmd
, CMD_ASYNC
);