1 /******************************************************************************
3 * Copyright(c) 2003 - 2010 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>
31 #include <linux/etherdevice.h>
32 #include <linux/sched.h>
33 #include <linux/lockdep.h>
39 /* priv->sta_lock must be held */
40 static void iwl_sta_ucode_activate(struct iwl_priv
*priv
, u8 sta_id
)
43 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
))
44 IWL_ERR(priv
, "ACTIVATE a non DRIVER active station id %u addr %pM\n",
45 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
47 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) {
49 "STA id %u addr %pM already present in uCode (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
,
63 u8 sta_id
= addsta
->sta
.sta_id
;
67 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
68 IWL_ERR(priv
, "Bad return from REPLY_ADD_STA (0x%08X)\n",
73 IWL_DEBUG_INFO(priv
, "Processing response for adding station %u\n",
76 spin_lock_irqsave(&priv
->sta_lock
, flags
);
78 switch (pkt
->u
.add_sta
.status
) {
79 case ADD_STA_SUCCESS_MSK
:
80 IWL_DEBUG_INFO(priv
, "REPLY_ADD_STA PASSED\n");
81 iwl_sta_ucode_activate(priv
, sta_id
);
84 case ADD_STA_NO_ROOM_IN_TABLE
:
85 IWL_ERR(priv
, "Adding station %d failed, no room in table.\n",
88 case ADD_STA_NO_BLOCK_ACK_RESOURCE
:
89 IWL_ERR(priv
, "Adding station %d failed, no block ack resource.\n",
92 case ADD_STA_MODIFY_NON_EXIST_STA
:
93 IWL_ERR(priv
, "Attempting to modify non-existing station %d\n",
97 IWL_DEBUG_ASSOC(priv
, "Received REPLY_ADD_STA:(0x%08X)\n",
98 pkt
->u
.add_sta
.status
);
102 IWL_DEBUG_INFO(priv
, "%s station id %u addr %pM\n",
103 priv
->stations
[sta_id
].sta
.mode
==
104 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
105 sta_id
, priv
->stations
[sta_id
].sta
.sta
.addr
);
108 * XXX: The MAC address in the command buffer is often changed from
109 * the original sent to the device. That is, the MAC address
110 * written to the command buffer often is not the same MAC adress
111 * read from the command buffer when the command returns. This
112 * issue has not yet been resolved and this debugging is left to
113 * observe the problem.
115 IWL_DEBUG_INFO(priv
, "%s station according to cmd buffer %pM\n",
116 priv
->stations
[sta_id
].sta
.mode
==
117 STA_CONTROL_MODIFY_MSK
? "Modified" : "Added",
119 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
124 static void iwl_add_sta_callback(struct iwl_priv
*priv
,
125 struct iwl_device_cmd
*cmd
,
126 struct iwl_rx_packet
*pkt
)
128 struct iwl_addsta_cmd
*addsta
=
129 (struct iwl_addsta_cmd
*)cmd
->cmd
.payload
;
131 iwl_process_add_sta_resp(priv
, addsta
, pkt
, false);
135 int iwl_send_add_sta(struct iwl_priv
*priv
,
136 struct iwl_addsta_cmd
*sta
, u8 flags
)
138 struct iwl_rx_packet
*pkt
= NULL
;
140 u8 data
[sizeof(*sta
)];
141 struct iwl_host_cmd cmd
= {
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
.callback
= iwl_add_sta_callback
;
154 cmd
.flags
|= CMD_WANT_SKB
;
158 cmd
.len
= priv
->cfg
->ops
->utils
->build_addsta_hcmd(sta
, data
);
159 ret
= iwl_send_cmd(priv
, &cmd
);
161 if (ret
|| (flags
& CMD_ASYNC
))
165 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
166 ret
= iwl_process_add_sta_resp(priv
, sta
, pkt
, true);
168 iwl_free_pages(priv
, cmd
.reply_page
);
172 EXPORT_SYMBOL(iwl_send_add_sta
);
174 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
175 struct ieee80211_sta
*sta
,
176 struct iwl_rxon_context
*ctx
)
178 struct ieee80211_sta_ht_cap
*sta_ht_inf
= &sta
->ht_cap
;
182 if (!sta
|| !sta_ht_inf
->ht_supported
)
185 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_SM_PS
) >> 2;
186 IWL_DEBUG_ASSOC(priv
, "spatial multiplexing power save mode: %s\n",
187 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_STATIC
) ?
189 (mimo_ps_mode
== WLAN_HT_CAP_SM_PS_DYNAMIC
) ?
190 "dynamic" : "disabled");
192 sta_flags
= priv
->stations
[index
].sta
.station_flags
;
194 sta_flags
&= ~(STA_FLG_RTS_MIMO_PROT_MSK
| STA_FLG_MIMO_DIS_MSK
);
196 switch (mimo_ps_mode
) {
197 case WLAN_HT_CAP_SM_PS_STATIC
:
198 sta_flags
|= STA_FLG_MIMO_DIS_MSK
;
200 case WLAN_HT_CAP_SM_PS_DYNAMIC
:
201 sta_flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
203 case WLAN_HT_CAP_SM_PS_DISABLED
:
206 IWL_WARN(priv
, "Invalid MIMO PS mode %d\n", mimo_ps_mode
);
210 sta_flags
|= cpu_to_le32(
211 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
213 sta_flags
|= cpu_to_le32(
214 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
216 if (iwl_is_ht40_tx_allowed(priv
, ctx
, &sta
->ht_cap
))
217 sta_flags
|= STA_FLG_HT40_EN_MSK
;
219 sta_flags
&= ~STA_FLG_HT40_EN_MSK
;
221 priv
->stations
[index
].sta
.station_flags
= sta_flags
;
227 * iwl_prep_station - Prepare station information for addition
229 * should be called with sta_lock held
231 static u8
iwl_prep_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
232 const u8
*addr
, bool is_ap
,
233 struct ieee80211_sta
*sta
)
235 struct iwl_station_entry
*station
;
237 u8 sta_id
= IWL_INVALID_STATION
;
241 sta_id
= ctx
->ap_sta_id
;
242 else if (is_broadcast_ether_addr(addr
))
243 sta_id
= ctx
->bcast_sta_id
;
245 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
246 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
252 if (!priv
->stations
[i
].used
&&
253 sta_id
== IWL_INVALID_STATION
)
258 * These two conditions have the same outcome, but keep them
261 if (unlikely(sta_id
== IWL_INVALID_STATION
))
265 * uCode is not able to deal with multiple requests to add a
266 * station. Keep track if one is in progress so that we do not send
269 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
270 IWL_DEBUG_INFO(priv
, "STA %d already in process of being added.\n",
275 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
276 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
) &&
277 !compare_ether_addr(priv
->stations
[sta_id
].sta
.sta
.addr
, addr
)) {
278 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not adding again.\n",
283 station
= &priv
->stations
[sta_id
];
284 station
->used
= IWL_STA_DRIVER_ACTIVE
;
285 IWL_DEBUG_ASSOC(priv
, "Add STA to driver ID %d: %pM\n",
287 priv
->num_stations
++;
289 /* Set up the REPLY_ADD_STA command to send to device */
290 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
291 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
292 station
->sta
.mode
= 0;
293 station
->sta
.sta
.sta_id
= sta_id
;
294 station
->sta
.station_flags
= ctx
->station_flags
;
295 station
->ctxid
= ctx
->ctxid
;
298 struct iwl_station_priv_common
*sta_priv
;
300 sta_priv
= (void *)sta
->drv_priv
;
305 * OK to call unconditionally, since local stations (IBSS BSSID
306 * STA and broadcast STA) pass in a NULL sta, and mac80211
307 * doesn't allow HT IBSS.
309 iwl_set_ht_add_station(priv
, sta_id
, sta
, ctx
);
312 rate
= (priv
->band
== IEEE80211_BAND_5GHZ
) ?
313 IWL_RATE_6M_PLCP
: IWL_RATE_1M_PLCP
;
314 /* Turn on both antennas for the station... */
315 station
->sta
.rate_n_flags
= cpu_to_le16(rate
| RATE_MCS_ANT_AB_MSK
);
321 #define STA_WAIT_TIMEOUT (HZ/2)
324 * iwl_add_station_common -
326 int iwl_add_station_common(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
327 const u8
*addr
, bool is_ap
,
328 struct ieee80211_sta
*sta
, u8
*sta_id_r
)
330 unsigned long flags_spin
;
333 struct iwl_addsta_cmd sta_cmd
;
336 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
337 sta_id
= iwl_prep_station(priv
, ctx
, addr
, is_ap
, sta
);
338 if (sta_id
== IWL_INVALID_STATION
) {
339 IWL_ERR(priv
, "Unable to prepare station %pM for addition\n",
341 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
346 * uCode is not able to deal with multiple requests to add a
347 * station. Keep track if one is in progress so that we do not send
350 if (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_INPROGRESS
) {
351 IWL_DEBUG_INFO(priv
, "STA %d already in process of being added.\n",
353 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
357 if ((priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
) &&
358 (priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
359 IWL_DEBUG_ASSOC(priv
, "STA %d (%pM) already added, not adding again.\n",
361 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
365 priv
->stations
[sta_id
].used
|= IWL_STA_UCODE_INPROGRESS
;
366 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
367 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
369 /* Add station to device's station table */
370 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
372 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
373 IWL_ERR(priv
, "Adding station %pM failed.\n",
374 priv
->stations
[sta_id
].sta
.sta
.addr
);
375 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
376 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
377 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
382 EXPORT_SYMBOL(iwl_add_station_common
);
384 static struct iwl_link_quality_cmd
*iwl_sta_alloc_lq(struct iwl_priv
*priv
,
388 struct iwl_link_quality_cmd
*link_cmd
;
392 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
394 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
397 /* Set up the rate scaling to start at selected rate, fall back
398 * all the way down to 1M in IEEE order, and then spin on 1M */
399 if (priv
->band
== IEEE80211_BAND_5GHZ
)
400 r
= IWL_RATE_6M_INDEX
;
402 r
= IWL_RATE_1M_INDEX
;
404 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
405 rate_flags
|= RATE_MCS_CCK_MSK
;
407 rate_flags
|= first_antenna(priv
->hw_params
.valid_tx_ant
) <<
409 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
410 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
411 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
413 link_cmd
->general_params
.single_stream_ant_msk
=
414 first_antenna(priv
->hw_params
.valid_tx_ant
);
416 link_cmd
->general_params
.dual_stream_ant_msk
=
417 priv
->hw_params
.valid_tx_ant
&
418 ~first_antenna(priv
->hw_params
.valid_tx_ant
);
419 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
420 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
421 } else if (num_of_ant(priv
->hw_params
.valid_tx_ant
) == 2) {
422 link_cmd
->general_params
.dual_stream_ant_msk
=
423 priv
->hw_params
.valid_tx_ant
;
426 link_cmd
->agg_params
.agg_dis_start_th
= LINK_QUAL_AGG_DISABLE_START_DEF
;
427 link_cmd
->agg_params
.agg_time_limit
=
428 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
430 link_cmd
->sta_id
= sta_id
;
436 * iwl_add_bssid_station - Add the special IBSS BSSID station
440 int iwl_add_bssid_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
441 const u8
*addr
, bool init_rs
, u8
*sta_id_r
)
445 struct iwl_link_quality_cmd
*link_cmd
;
449 *sta_id_r
= IWL_INVALID_STATION
;
451 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
453 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
460 spin_lock_irqsave(&priv
->sta_lock
, flags
);
461 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
462 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
465 /* Set up default rate scaling table in device's station table */
466 link_cmd
= iwl_sta_alloc_lq(priv
, sta_id
);
468 IWL_ERR(priv
, "Unable to initialize rate scaling for station %pM.\n",
473 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
475 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
477 spin_lock_irqsave(&priv
->sta_lock
, flags
);
478 priv
->stations
[sta_id
].lq
= link_cmd
;
479 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
484 EXPORT_SYMBOL(iwl_add_bssid_station
);
487 * iwl_sta_ucode_deactivate - deactivate ucode status for a station
489 * priv->sta_lock must be held
491 static void iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, u8 sta_id
)
493 /* Ucode must be active and driver must be non active */
494 if ((priv
->stations
[sta_id
].used
&
495 (IWL_STA_UCODE_ACTIVE
| IWL_STA_DRIVER_ACTIVE
)) != IWL_STA_UCODE_ACTIVE
)
496 IWL_ERR(priv
, "removed non active STA %u\n", sta_id
);
498 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
500 memset(&priv
->stations
[sta_id
], 0, sizeof(struct iwl_station_entry
));
501 IWL_DEBUG_ASSOC(priv
, "Removed STA %u\n", sta_id
);
504 static int iwl_send_remove_station(struct iwl_priv
*priv
,
505 const u8
*addr
, int sta_id
)
507 struct iwl_rx_packet
*pkt
;
510 unsigned long flags_spin
;
511 struct iwl_rem_sta_cmd rm_sta_cmd
;
513 struct iwl_host_cmd cmd
= {
514 .id
= REPLY_REMOVE_STA
,
515 .len
= sizeof(struct iwl_rem_sta_cmd
),
520 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
521 rm_sta_cmd
.num_sta
= 1;
522 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
524 cmd
.flags
|= CMD_WANT_SKB
;
526 ret
= iwl_send_cmd(priv
, &cmd
);
531 pkt
= (struct iwl_rx_packet
*)cmd
.reply_page
;
532 if (pkt
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
533 IWL_ERR(priv
, "Bad return from REPLY_REMOVE_STA (0x%08X)\n",
539 switch (pkt
->u
.rem_sta
.status
) {
540 case REM_STA_SUCCESS_MSK
:
541 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
542 iwl_sta_ucode_deactivate(priv
, sta_id
);
543 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
544 IWL_DEBUG_ASSOC(priv
, "REPLY_REMOVE_STA PASSED\n");
548 IWL_ERR(priv
, "REPLY_REMOVE_STA failed\n");
552 iwl_free_pages(priv
, cmd
.reply_page
);
558 * iwl_remove_station - Remove driver's knowledge of station.
560 int iwl_remove_station(struct iwl_priv
*priv
, const u8 sta_id
,
565 if (!iwl_is_ready(priv
)) {
567 "Unable to remove station %pM, device not ready.\n",
570 * It is typical for stations to be removed when we are
571 * going down. Return success since device will be down
577 IWL_DEBUG_ASSOC(priv
, "Removing STA from driver:%d %pM\n",
580 if (WARN_ON(sta_id
== IWL_INVALID_STATION
))
583 spin_lock_irqsave(&priv
->sta_lock
, flags
);
585 if (!(priv
->stations
[sta_id
].used
& IWL_STA_DRIVER_ACTIVE
)) {
586 IWL_DEBUG_INFO(priv
, "Removing %pM but non DRIVER active\n",
591 if (!(priv
->stations
[sta_id
].used
& IWL_STA_UCODE_ACTIVE
)) {
592 IWL_DEBUG_INFO(priv
, "Removing %pM but non UCODE active\n",
597 if (priv
->stations
[sta_id
].used
& IWL_STA_LOCAL
) {
598 kfree(priv
->stations
[sta_id
].lq
);
599 priv
->stations
[sta_id
].lq
= NULL
;
602 priv
->stations
[sta_id
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
604 priv
->num_stations
--;
606 BUG_ON(priv
->num_stations
< 0);
608 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
610 return iwl_send_remove_station(priv
, addr
, sta_id
);
612 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
615 EXPORT_SYMBOL_GPL(iwl_remove_station
);
618 * iwl_clear_ucode_stations - clear ucode station table bits
620 * This function clears all the bits in the driver indicating
621 * which stations are active in the ucode. Call when something
622 * other than explicit station management would cause this in
623 * the ucode, e.g. unassociated RXON.
625 void iwl_clear_ucode_stations(struct iwl_priv
*priv
,
626 struct iwl_rxon_context
*ctx
)
629 unsigned long flags_spin
;
630 bool cleared
= false;
632 IWL_DEBUG_INFO(priv
, "Clearing ucode stations in driver\n");
634 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
635 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
636 if (ctx
&& ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
639 if (priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
) {
640 IWL_DEBUG_INFO(priv
, "Clearing ucode active for station %d\n", i
);
641 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
645 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
648 IWL_DEBUG_INFO(priv
, "No active stations found to be cleared\n");
650 EXPORT_SYMBOL(iwl_clear_ucode_stations
);
653 * iwl_restore_stations() - Restore driver known stations to device
655 * All stations considered active by driver, but not present in ucode, is
660 void iwl_restore_stations(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
662 struct iwl_addsta_cmd sta_cmd
;
663 struct iwl_link_quality_cmd lq
;
664 unsigned long flags_spin
;
670 if (!iwl_is_ready(priv
)) {
671 IWL_DEBUG_INFO(priv
, "Not ready yet, not restoring any stations.\n");
675 IWL_DEBUG_ASSOC(priv
, "Restoring all known stations ... start.\n");
676 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
677 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
678 if (ctx
->ctxid
!= priv
->stations
[i
].ctxid
)
680 if ((priv
->stations
[i
].used
& IWL_STA_DRIVER_ACTIVE
) &&
681 !(priv
->stations
[i
].used
& IWL_STA_UCODE_ACTIVE
)) {
682 IWL_DEBUG_ASSOC(priv
, "Restoring sta %pM\n",
683 priv
->stations
[i
].sta
.sta
.addr
);
684 priv
->stations
[i
].sta
.mode
= 0;
685 priv
->stations
[i
].used
|= IWL_STA_UCODE_INPROGRESS
;
690 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
691 if ((priv
->stations
[i
].used
& IWL_STA_UCODE_INPROGRESS
)) {
692 memcpy(&sta_cmd
, &priv
->stations
[i
].sta
,
693 sizeof(struct iwl_addsta_cmd
));
695 if (priv
->stations
[i
].lq
) {
696 memcpy(&lq
, priv
->stations
[i
].lq
,
697 sizeof(struct iwl_link_quality_cmd
));
700 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
701 ret
= iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
703 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
704 IWL_ERR(priv
, "Adding station %pM failed.\n",
705 priv
->stations
[i
].sta
.sta
.addr
);
706 priv
->stations
[i
].used
&= ~IWL_STA_DRIVER_ACTIVE
;
707 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
708 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
711 * Rate scaling has already been initialized, send
715 iwl_send_lq_cmd(priv
, ctx
, &lq
, CMD_SYNC
, true);
716 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
717 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
721 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
723 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... no stations to be restored.\n");
725 IWL_DEBUG_INFO(priv
, "Restoring all known stations .... complete.\n");
727 EXPORT_SYMBOL(iwl_restore_stations
);
729 int iwl_get_free_ucode_key_index(struct iwl_priv
*priv
)
733 for (i
= 0; i
< priv
->sta_key_max_num
; i
++)
734 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
737 return WEP_INVALID_OFFSET
;
739 EXPORT_SYMBOL(iwl_get_free_ucode_key_index
);
741 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
742 struct iwl_rxon_context
*ctx
,
745 int i
, not_empty
= 0;
746 u8 buff
[sizeof(struct iwl_wep_cmd
) +
747 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
748 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
749 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
750 struct iwl_host_cmd cmd
= {
751 .id
= ctx
->wep_key_cmd
,
758 memset(wep_cmd
, 0, cmd_size
+
759 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
761 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
762 wep_cmd
->key
[i
].key_index
= i
;
763 if (ctx
->wep_keys
[i
].key_size
) {
764 wep_cmd
->key
[i
].key_offset
= i
;
767 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
770 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
771 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
772 ctx
->wep_keys
[i
].key_size
);
775 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
776 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
778 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
782 if (not_empty
|| send_if_empty
)
783 return iwl_send_cmd(priv
, &cmd
);
788 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
789 struct iwl_rxon_context
*ctx
)
791 lockdep_assert_held(&priv
->mutex
);
793 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
795 EXPORT_SYMBOL(iwl_restore_default_wep_keys
);
797 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
798 struct iwl_rxon_context
*ctx
,
799 struct ieee80211_key_conf
*keyconf
)
803 lockdep_assert_held(&priv
->mutex
);
805 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
808 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
809 if (iwl_is_rfkill(priv
)) {
810 IWL_DEBUG_WEP(priv
, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
811 /* but keys in device are clear anyway so return success */
814 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
815 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
816 keyconf
->keyidx
, ret
);
820 EXPORT_SYMBOL(iwl_remove_default_wep_key
);
822 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
823 struct iwl_rxon_context
*ctx
,
824 struct ieee80211_key_conf
*keyconf
)
828 lockdep_assert_held(&priv
->mutex
);
830 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
831 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
832 IWL_DEBUG_WEP(priv
, "Bad WEP key length %d\n", keyconf
->keylen
);
836 keyconf
->flags
&= ~IEEE80211_KEY_FLAG_GENERATE_IV
;
837 keyconf
->hw_key_idx
= HW_KEY_DEFAULT
;
838 priv
->stations
[ctx
->ap_sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
840 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
841 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
844 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
845 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
846 keyconf
->keylen
, keyconf
->keyidx
, ret
);
850 EXPORT_SYMBOL(iwl_set_default_wep_key
);
852 static int iwl_set_wep_dynamic_key_info(struct iwl_priv
*priv
,
853 struct iwl_rxon_context
*ctx
,
854 struct ieee80211_key_conf
*keyconf
,
858 __le16 key_flags
= 0;
859 struct iwl_addsta_cmd sta_cmd
;
861 lockdep_assert_held(&priv
->mutex
);
863 keyconf
->flags
&= ~IEEE80211_KEY_FLAG_GENERATE_IV
;
865 key_flags
|= (STA_KEY_FLG_WEP
| STA_KEY_FLG_MAP_KEY_MSK
);
866 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
867 key_flags
&= ~STA_KEY_FLG_INVALID
;
869 if (keyconf
->keylen
== WEP_KEY_LEN_128
)
870 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
872 if (sta_id
== ctx
->bcast_sta_id
)
873 key_flags
|= STA_KEY_MULTICAST_MSK
;
875 spin_lock_irqsave(&priv
->sta_lock
, flags
);
877 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
878 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
879 priv
->stations
[sta_id
].keyinfo
.keyidx
= keyconf
->keyidx
;
881 memcpy(priv
->stations
[sta_id
].keyinfo
.key
,
882 keyconf
->key
, keyconf
->keylen
);
884 memcpy(&priv
->stations
[sta_id
].sta
.key
.key
[3],
885 keyconf
->key
, keyconf
->keylen
);
887 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
888 == STA_KEY_FLG_NO_ENC
)
889 priv
->stations
[sta_id
].sta
.key
.key_offset
=
890 iwl_get_free_ucode_key_index(priv
);
891 /* else, we are overriding an existing key => no need to allocated room
894 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
895 "no space for a new key");
897 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
898 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
899 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
901 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
902 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
904 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
907 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
908 struct iwl_rxon_context
*ctx
,
909 struct ieee80211_key_conf
*keyconf
,
913 __le16 key_flags
= 0;
914 struct iwl_addsta_cmd sta_cmd
;
916 lockdep_assert_held(&priv
->mutex
);
918 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
919 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
920 key_flags
&= ~STA_KEY_FLG_INVALID
;
922 if (sta_id
== ctx
->bcast_sta_id
)
923 key_flags
|= STA_KEY_MULTICAST_MSK
;
925 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
927 spin_lock_irqsave(&priv
->sta_lock
, flags
);
928 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
929 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
931 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
934 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
937 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
938 == STA_KEY_FLG_NO_ENC
)
939 priv
->stations
[sta_id
].sta
.key
.key_offset
=
940 iwl_get_free_ucode_key_index(priv
);
941 /* else, we are overriding an existing key => no need to allocated room
944 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
945 "no space for a new key");
947 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
948 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
949 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
951 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
952 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
954 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
957 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
958 struct iwl_rxon_context
*ctx
,
959 struct ieee80211_key_conf
*keyconf
,
964 __le16 key_flags
= 0;
966 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
967 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
968 key_flags
&= ~STA_KEY_FLG_INVALID
;
970 if (sta_id
== ctx
->bcast_sta_id
)
971 key_flags
|= STA_KEY_MULTICAST_MSK
;
973 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
974 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
976 spin_lock_irqsave(&priv
->sta_lock
, flags
);
978 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
979 priv
->stations
[sta_id
].keyinfo
.keylen
= 16;
981 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
982 == STA_KEY_FLG_NO_ENC
)
983 priv
->stations
[sta_id
].sta
.key
.key_offset
=
984 iwl_get_free_ucode_key_index(priv
);
985 /* else, we are overriding an existing key => no need to allocated room
988 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
989 "no space for a new key");
991 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
994 /* This copy is acutally not needed: we get the key with each TX */
995 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
, 16);
997 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
, 16);
999 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1004 void iwl_update_tkip_key(struct iwl_priv
*priv
,
1005 struct iwl_rxon_context
*ctx
,
1006 struct ieee80211_key_conf
*keyconf
,
1007 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
1010 unsigned long flags
;
1013 if (iwl_scan_cancel(priv
)) {
1014 /* cancel scan failed, just live w/ bad key and rely
1015 briefly on SW decryption */
1019 sta_id
= iwl_sta_id_or_broadcast(priv
, ctx
, sta
);
1020 if (sta_id
== IWL_INVALID_STATION
)
1023 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1025 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
1027 for (i
= 0; i
< 5; i
++)
1028 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
1029 cpu_to_le16(phase1key
[i
]);
1031 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1032 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1034 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1036 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1039 EXPORT_SYMBOL(iwl_update_tkip_key
);
1041 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
1042 struct iwl_rxon_context
*ctx
,
1043 struct ieee80211_key_conf
*keyconf
,
1046 unsigned long flags
;
1049 struct iwl_addsta_cmd sta_cmd
;
1051 lockdep_assert_held(&priv
->mutex
);
1053 ctx
->key_mapping_keys
--;
1055 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1056 key_flags
= le16_to_cpu(priv
->stations
[sta_id
].sta
.key
.key_flags
);
1057 keyidx
= (key_flags
>> STA_KEY_FLG_KEYID_POS
) & 0x3;
1059 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
1060 keyconf
->keyidx
, sta_id
);
1062 if (keyconf
->keyidx
!= keyidx
) {
1063 /* We need to remove a key with index different that the one
1064 * in the uCode. This means that the key we need to remove has
1065 * been replaced by another one with different index.
1066 * Don't do anything and return ok
1068 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1072 if (priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
) {
1073 IWL_WARN(priv
, "Removing wrong key %d 0x%x\n",
1074 keyconf
->keyidx
, key_flags
);
1075 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1079 if (!test_and_clear_bit(priv
->stations
[sta_id
].sta
.key
.key_offset
,
1080 &priv
->ucode_key_table
))
1081 IWL_ERR(priv
, "index %d not used in uCode key table.\n",
1082 priv
->stations
[sta_id
].sta
.key
.key_offset
);
1083 memset(&priv
->stations
[sta_id
].keyinfo
, 0,
1084 sizeof(struct iwl_hw_key
));
1085 memset(&priv
->stations
[sta_id
].sta
.key
, 0,
1086 sizeof(struct iwl4965_keyinfo
));
1087 priv
->stations
[sta_id
].sta
.key
.key_flags
=
1088 STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_INVALID
;
1089 priv
->stations
[sta_id
].sta
.key
.key_offset
= WEP_INVALID_OFFSET
;
1090 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
1091 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1093 if (iwl_is_rfkill(priv
)) {
1094 IWL_DEBUG_WEP(priv
, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
1095 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1098 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1099 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1101 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1103 EXPORT_SYMBOL(iwl_remove_dynamic_key
);
1105 int iwl_set_dynamic_key(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
1106 struct ieee80211_key_conf
*keyconf
, u8 sta_id
)
1110 lockdep_assert_held(&priv
->mutex
);
1112 ctx
->key_mapping_keys
++;
1113 keyconf
->hw_key_idx
= HW_KEY_DYNAMIC
;
1115 switch (keyconf
->cipher
) {
1116 case WLAN_CIPHER_SUITE_CCMP
:
1117 ret
= iwl_set_ccmp_dynamic_key_info(priv
, ctx
, keyconf
, sta_id
);
1119 case WLAN_CIPHER_SUITE_TKIP
:
1120 ret
= iwl_set_tkip_dynamic_key_info(priv
, ctx
, keyconf
, sta_id
);
1122 case WLAN_CIPHER_SUITE_WEP40
:
1123 case WLAN_CIPHER_SUITE_WEP104
:
1124 ret
= iwl_set_wep_dynamic_key_info(priv
, ctx
, keyconf
, sta_id
);
1128 "Unknown alg: %s cipher = %x\n", __func__
,
1133 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
1134 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
1139 EXPORT_SYMBOL(iwl_set_dynamic_key
);
1141 #ifdef CONFIG_IWLWIFI_DEBUG
1142 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
1143 struct iwl_link_quality_cmd
*lq
)
1146 IWL_DEBUG_RATE(priv
, "lq station id 0x%x\n", lq
->sta_id
);
1147 IWL_DEBUG_RATE(priv
, "lq ant 0x%X 0x%X\n",
1148 lq
->general_params
.single_stream_ant_msk
,
1149 lq
->general_params
.dual_stream_ant_msk
);
1151 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
1152 IWL_DEBUG_RATE(priv
, "lq index %d 0x%X\n",
1153 i
, lq
->rs_table
[i
].rate_n_flags
);
1156 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
1157 struct iwl_link_quality_cmd
*lq
)
1163 * is_lq_table_valid() - Test one aspect of LQ cmd for validity
1165 * It sometimes happens when a HT rate has been in use and we
1166 * loose connectivity with AP then mac80211 will first tell us that the
1167 * current channel is not HT anymore before removing the station. In such a
1168 * scenario the RXON flags will be updated to indicate we are not
1169 * communicating HT anymore, but the LQ command may still contain HT rates.
1170 * Test for this to prevent driver from sending LQ command between the time
1171 * RXON flags are updated and when LQ command is updated.
1173 static bool is_lq_table_valid(struct iwl_priv
*priv
,
1174 struct iwl_rxon_context
*ctx
,
1175 struct iwl_link_quality_cmd
*lq
)
1179 if (ctx
->ht
.enabled
)
1182 IWL_DEBUG_INFO(priv
, "Channel %u is not an HT channel\n",
1183 ctx
->active
.channel
);
1184 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
1185 if (le32_to_cpu(lq
->rs_table
[i
].rate_n_flags
) & RATE_MCS_HT_MSK
) {
1186 IWL_DEBUG_INFO(priv
,
1187 "index %d of LQ expects HT channel\n",
1196 * iwl_send_lq_cmd() - Send link quality command
1197 * @init: This command is sent as part of station initialization right
1198 * after station has been added.
1200 * The link quality command is sent as the last step of station creation.
1201 * This is the special case in which init is set and we call a callback in
1202 * this case to clear the state indicating that station creation is in
1205 int iwl_send_lq_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
1206 struct iwl_link_quality_cmd
*lq
, u8 flags
, bool init
)
1209 unsigned long flags_spin
;
1211 struct iwl_host_cmd cmd
= {
1212 .id
= REPLY_TX_LINK_QUALITY_CMD
,
1213 .len
= sizeof(struct iwl_link_quality_cmd
),
1218 if (WARN_ON(lq
->sta_id
== IWL_INVALID_STATION
))
1221 iwl_dump_lq_cmd(priv
, lq
);
1222 BUG_ON(init
&& (cmd
.flags
& CMD_ASYNC
));
1224 if (is_lq_table_valid(priv
, ctx
, lq
))
1225 ret
= iwl_send_cmd(priv
, &cmd
);
1229 if (cmd
.flags
& CMD_ASYNC
)
1233 IWL_DEBUG_INFO(priv
, "init LQ command complete, clearing sta addition status for sta %d\n",
1235 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
1236 priv
->stations
[lq
->sta_id
].used
&= ~IWL_STA_UCODE_INPROGRESS
;
1237 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
1241 EXPORT_SYMBOL(iwl_send_lq_cmd
);
1244 * iwl_alloc_bcast_station - add broadcast station into driver's station table.
1246 * This adds the broadcast station into the driver's station table
1247 * and marks it driver active, so that it will be restored to the
1248 * device at the next best time.
1250 int iwl_alloc_bcast_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
1253 struct iwl_link_quality_cmd
*link_cmd
;
1254 unsigned long flags
;
1257 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1258 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
1259 if (sta_id
== IWL_INVALID_STATION
) {
1260 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
1261 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1266 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
1267 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
1268 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1271 link_cmd
= iwl_sta_alloc_lq(priv
, sta_id
);
1274 "Unable to initialize rate scaling for bcast station.\n");
1278 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1279 priv
->stations
[sta_id
].lq
= link_cmd
;
1280 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1285 EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station
);
1288 * iwl_update_bcast_station - update broadcast station's LQ command
1290 * Only used by iwlagn. Placed here to have all bcast station management
1293 static int iwl_update_bcast_station(struct iwl_priv
*priv
,
1294 struct iwl_rxon_context
*ctx
)
1296 unsigned long flags
;
1297 struct iwl_link_quality_cmd
*link_cmd
;
1298 u8 sta_id
= ctx
->bcast_sta_id
;
1300 link_cmd
= iwl_sta_alloc_lq(priv
, sta_id
);
1302 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
1306 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1307 if (priv
->stations
[sta_id
].lq
)
1308 kfree(priv
->stations
[sta_id
].lq
);
1310 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
1311 priv
->stations
[sta_id
].lq
= link_cmd
;
1312 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1317 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
1319 struct iwl_rxon_context
*ctx
;
1322 for_each_context(priv
, ctx
) {
1323 ret
= iwl_update_bcast_station(priv
, ctx
);
1330 EXPORT_SYMBOL_GPL(iwl_update_bcast_stations
);
1332 void iwl_dealloc_bcast_stations(struct iwl_priv
*priv
)
1334 unsigned long flags
;
1337 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1338 for (i
= 0; i
< priv
->hw_params
.max_stations
; i
++) {
1339 if (!(priv
->stations
[i
].used
& IWL_STA_BCAST
))
1342 priv
->stations
[i
].used
&= ~IWL_STA_UCODE_ACTIVE
;
1343 priv
->num_stations
--;
1344 BUG_ON(priv
->num_stations
< 0);
1345 kfree(priv
->stations
[i
].lq
);
1346 priv
->stations
[i
].lq
= NULL
;
1348 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1350 EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations
);
1353 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
1355 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
1357 unsigned long flags
;
1358 struct iwl_addsta_cmd sta_cmd
;
1360 lockdep_assert_held(&priv
->mutex
);
1362 /* Remove "disable" flag, to enable Tx for this TID */
1363 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1364 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
1365 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
1366 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1367 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1368 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1370 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1372 EXPORT_SYMBOL(iwl_sta_tx_modify_enable_tid
);
1374 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1377 unsigned long flags
;
1379 struct iwl_addsta_cmd sta_cmd
;
1381 lockdep_assert_held(&priv
->mutex
);
1383 sta_id
= iwl_sta_id(sta
);
1384 if (sta_id
== IWL_INVALID_STATION
)
1387 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1388 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1389 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
1390 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
1391 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
1392 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1393 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1394 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1396 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1398 EXPORT_SYMBOL(iwl_sta_rx_agg_start
);
1400 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
1403 unsigned long flags
;
1405 struct iwl_addsta_cmd sta_cmd
;
1407 lockdep_assert_held(&priv
->mutex
);
1409 sta_id
= iwl_sta_id(sta
);
1410 if (sta_id
== IWL_INVALID_STATION
) {
1411 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
1415 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1416 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
1417 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
1418 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
1419 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1420 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
1421 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1423 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
1425 EXPORT_SYMBOL(iwl_sta_rx_agg_stop
);
1427 void iwl_sta_modify_ps_wake(struct iwl_priv
*priv
, int sta_id
)
1429 unsigned long flags
;
1431 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1432 priv
->stations
[sta_id
].sta
.station_flags
&= ~STA_FLG_PWR_SAVE_MSK
;
1433 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
1434 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= 0;
1435 priv
->stations
[sta_id
].sta
.sleep_tx_count
= 0;
1436 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1437 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1438 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1441 EXPORT_SYMBOL(iwl_sta_modify_ps_wake
);
1443 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
1445 unsigned long flags
;
1447 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1448 priv
->stations
[sta_id
].sta
.station_flags
|= STA_FLG_PWR_SAVE_MSK
;
1449 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
1450 priv
->stations
[sta_id
].sta
.sta
.modify_mask
=
1451 STA_MODIFY_SLEEP_TX_COUNT_MSK
;
1452 priv
->stations
[sta_id
].sta
.sleep_tx_count
= cpu_to_le16(cnt
);
1453 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
1454 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
1455 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1458 EXPORT_SYMBOL(iwl_sta_modify_sleep_tx_count
);
1460 int iwl_mac_sta_remove(struct ieee80211_hw
*hw
,
1461 struct ieee80211_vif
*vif
,
1462 struct ieee80211_sta
*sta
)
1464 struct iwl_priv
*priv
= hw
->priv
;
1465 struct iwl_station_priv_common
*sta_common
= (void *)sta
->drv_priv
;
1468 IWL_DEBUG_INFO(priv
, "received request to remove station %pM\n",
1470 mutex_lock(&priv
->mutex
);
1471 IWL_DEBUG_INFO(priv
, "proceeding to remove station %pM\n",
1473 ret
= iwl_remove_station(priv
, sta_common
->sta_id
, sta
->addr
);
1475 IWL_ERR(priv
, "Error removing station %pM\n",
1477 mutex_unlock(&priv
->mutex
);
1480 EXPORT_SYMBOL(iwl_mac_sta_remove
);