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>
37 static struct iwl_link_quality_cmd
*
38 iwl_sta_alloc_lq(struct iwl_priv
*priv
, u8 sta_id
)
41 struct iwl_link_quality_cmd
*link_cmd
;
45 link_cmd
= kzalloc(sizeof(struct iwl_link_quality_cmd
), GFP_KERNEL
);
47 IWL_ERR(priv
, "Unable to allocate memory for LQ cmd.\n");
50 /* Set up the rate scaling to start at selected rate, fall back
51 * all the way down to 1M in IEEE order, and then spin on 1M */
52 if (priv
->band
== IEEE80211_BAND_5GHZ
)
53 r
= IWL_RATE_6M_INDEX
;
55 r
= IWL_RATE_1M_INDEX
;
57 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
58 rate_flags
|= RATE_MCS_CCK_MSK
;
60 rate_flags
|= first_antenna(priv
->hw_params
.valid_tx_ant
) <<
62 rate_n_flags
= iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
63 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
64 link_cmd
->rs_table
[i
].rate_n_flags
= rate_n_flags
;
66 link_cmd
->general_params
.single_stream_ant_msk
=
67 first_antenna(priv
->hw_params
.valid_tx_ant
);
69 link_cmd
->general_params
.dual_stream_ant_msk
=
70 priv
->hw_params
.valid_tx_ant
&
71 ~first_antenna(priv
->hw_params
.valid_tx_ant
);
72 if (!link_cmd
->general_params
.dual_stream_ant_msk
) {
73 link_cmd
->general_params
.dual_stream_ant_msk
= ANT_AB
;
74 } else if (num_of_ant(priv
->hw_params
.valid_tx_ant
) == 2) {
75 link_cmd
->general_params
.dual_stream_ant_msk
=
76 priv
->hw_params
.valid_tx_ant
;
79 link_cmd
->agg_params
.agg_dis_start_th
= LINK_QUAL_AGG_DISABLE_START_DEF
;
80 link_cmd
->agg_params
.agg_time_limit
=
81 cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF
);
83 link_cmd
->sta_id
= sta_id
;
89 * iwlagn_add_bssid_station - Add the special IBSS BSSID station
93 int iwlagn_add_bssid_station(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
94 const u8
*addr
, u8
*sta_id_r
)
98 struct iwl_link_quality_cmd
*link_cmd
;
102 *sta_id_r
= IWL_INVALID_STATION
;
104 ret
= iwl_add_station_common(priv
, ctx
, addr
, 0, NULL
, &sta_id
);
106 IWL_ERR(priv
, "Unable to add station %pM\n", addr
);
113 spin_lock_irqsave(&priv
->sta_lock
, flags
);
114 priv
->stations
[sta_id
].used
|= IWL_STA_LOCAL
;
115 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
117 /* Set up default rate scaling table in device's station table */
118 link_cmd
= iwl_sta_alloc_lq(priv
, sta_id
);
120 IWL_ERR(priv
, "Unable to initialize rate scaling for station %pM.\n",
125 ret
= iwl_send_lq_cmd(priv
, ctx
, link_cmd
, CMD_SYNC
, true);
127 IWL_ERR(priv
, "Link quality command failed (%d)\n", ret
);
129 spin_lock_irqsave(&priv
->sta_lock
, flags
);
130 priv
->stations
[sta_id
].lq
= link_cmd
;
131 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
136 static int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
,
137 struct iwl_rxon_context
*ctx
,
140 int i
, not_empty
= 0;
141 u8 buff
[sizeof(struct iwl_wep_cmd
) +
142 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
143 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
144 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
145 struct iwl_host_cmd cmd
= {
146 .id
= ctx
->wep_key_cmd
,
153 memset(wep_cmd
, 0, cmd_size
+
154 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
156 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
157 wep_cmd
->key
[i
].key_index
= i
;
158 if (ctx
->wep_keys
[i
].key_size
) {
159 wep_cmd
->key
[i
].key_offset
= i
;
162 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
165 wep_cmd
->key
[i
].key_size
= ctx
->wep_keys
[i
].key_size
;
166 memcpy(&wep_cmd
->key
[i
].key
[3], ctx
->wep_keys
[i
].key
,
167 ctx
->wep_keys
[i
].key_size
);
170 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
171 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
173 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
177 if (not_empty
|| send_if_empty
)
178 return iwl_send_cmd(priv
, &cmd
);
183 int iwl_restore_default_wep_keys(struct iwl_priv
*priv
,
184 struct iwl_rxon_context
*ctx
)
186 lockdep_assert_held(&priv
->mutex
);
188 return iwl_send_static_wepkey_cmd(priv
, ctx
, false);
191 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
192 struct iwl_rxon_context
*ctx
,
193 struct ieee80211_key_conf
*keyconf
)
197 lockdep_assert_held(&priv
->mutex
);
199 IWL_DEBUG_WEP(priv
, "Removing default WEP key: idx=%d\n",
202 memset(&ctx
->wep_keys
[keyconf
->keyidx
], 0, sizeof(ctx
->wep_keys
[0]));
203 if (iwl_is_rfkill(priv
)) {
204 IWL_DEBUG_WEP(priv
, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
205 /* but keys in device are clear anyway so return success */
208 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, 1);
209 IWL_DEBUG_WEP(priv
, "Remove default WEP key: idx=%d ret=%d\n",
210 keyconf
->keyidx
, ret
);
215 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
216 struct iwl_rxon_context
*ctx
,
217 struct ieee80211_key_conf
*keyconf
)
221 lockdep_assert_held(&priv
->mutex
);
223 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
224 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
225 IWL_DEBUG_WEP(priv
, "Bad WEP key length %d\n", keyconf
->keylen
);
229 keyconf
->flags
&= ~IEEE80211_KEY_FLAG_GENERATE_IV
;
230 keyconf
->hw_key_idx
= HW_KEY_DEFAULT
;
231 priv
->stations
[ctx
->ap_sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
233 ctx
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
234 memcpy(&ctx
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
237 ret
= iwl_send_static_wepkey_cmd(priv
, ctx
, false);
238 IWL_DEBUG_WEP(priv
, "Set default WEP key: len=%d idx=%d ret=%d\n",
239 keyconf
->keylen
, keyconf
->keyidx
, ret
);
244 static int iwl_set_wep_dynamic_key_info(struct iwl_priv
*priv
,
245 struct iwl_rxon_context
*ctx
,
246 struct ieee80211_key_conf
*keyconf
,
250 __le16 key_flags
= 0;
251 struct iwl_addsta_cmd sta_cmd
;
253 lockdep_assert_held(&priv
->mutex
);
255 keyconf
->flags
&= ~IEEE80211_KEY_FLAG_GENERATE_IV
;
257 key_flags
|= (STA_KEY_FLG_WEP
| STA_KEY_FLG_MAP_KEY_MSK
);
258 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
259 key_flags
&= ~STA_KEY_FLG_INVALID
;
261 if (keyconf
->keylen
== WEP_KEY_LEN_128
)
262 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
264 if (sta_id
== ctx
->bcast_sta_id
)
265 key_flags
|= STA_KEY_MULTICAST_MSK
;
267 spin_lock_irqsave(&priv
->sta_lock
, flags
);
269 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
270 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
271 priv
->stations
[sta_id
].keyinfo
.keyidx
= keyconf
->keyidx
;
273 memcpy(priv
->stations
[sta_id
].keyinfo
.key
,
274 keyconf
->key
, keyconf
->keylen
);
276 memcpy(&priv
->stations
[sta_id
].sta
.key
.key
[3],
277 keyconf
->key
, keyconf
->keylen
);
279 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
280 == STA_KEY_FLG_NO_ENC
)
281 priv
->stations
[sta_id
].sta
.key
.key_offset
=
282 iwl_get_free_ucode_key_index(priv
);
283 /* else, we are overriding an existing key => no need to allocated room
286 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
287 "no space for a new key");
289 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
290 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
291 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
293 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
294 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
296 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
299 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
300 struct iwl_rxon_context
*ctx
,
301 struct ieee80211_key_conf
*keyconf
,
305 __le16 key_flags
= 0;
306 struct iwl_addsta_cmd sta_cmd
;
308 lockdep_assert_held(&priv
->mutex
);
310 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
311 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
312 key_flags
&= ~STA_KEY_FLG_INVALID
;
314 if (sta_id
== ctx
->bcast_sta_id
)
315 key_flags
|= STA_KEY_MULTICAST_MSK
;
317 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
319 spin_lock_irqsave(&priv
->sta_lock
, flags
);
320 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
321 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
323 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
326 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
329 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
330 == STA_KEY_FLG_NO_ENC
)
331 priv
->stations
[sta_id
].sta
.key
.key_offset
=
332 iwl_get_free_ucode_key_index(priv
);
333 /* else, we are overriding an existing key => no need to allocated room
336 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
337 "no space for a new key");
339 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
340 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
341 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
343 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
344 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
346 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
349 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
350 struct iwl_rxon_context
*ctx
,
351 struct ieee80211_key_conf
*keyconf
,
356 __le16 key_flags
= 0;
358 key_flags
|= (STA_KEY_FLG_TKIP
| STA_KEY_FLG_MAP_KEY_MSK
);
359 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
360 key_flags
&= ~STA_KEY_FLG_INVALID
;
362 if (sta_id
== ctx
->bcast_sta_id
)
363 key_flags
|= STA_KEY_MULTICAST_MSK
;
365 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
366 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
368 spin_lock_irqsave(&priv
->sta_lock
, flags
);
370 priv
->stations
[sta_id
].keyinfo
.cipher
= keyconf
->cipher
;
371 priv
->stations
[sta_id
].keyinfo
.keylen
= 16;
373 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
374 == STA_KEY_FLG_NO_ENC
)
375 priv
->stations
[sta_id
].sta
.key
.key_offset
=
376 iwl_get_free_ucode_key_index(priv
);
377 /* else, we are overriding an existing key => no need to allocated room
380 WARN(priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
,
381 "no space for a new key");
383 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
386 /* This copy is acutally not needed: we get the key with each TX */
387 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
, 16);
389 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
, 16);
391 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
396 void iwl_update_tkip_key(struct iwl_priv
*priv
,
397 struct iwl_rxon_context
*ctx
,
398 struct ieee80211_key_conf
*keyconf
,
399 struct ieee80211_sta
*sta
, u32 iv32
, u16
*phase1key
)
405 if (iwl_scan_cancel(priv
)) {
406 /* cancel scan failed, just live w/ bad key and rely
407 briefly on SW decryption */
411 sta_id
= iwl_sta_id_or_broadcast(priv
, ctx
, sta
);
412 if (sta_id
== IWL_INVALID_STATION
)
415 spin_lock_irqsave(&priv
->sta_lock
, flags
);
417 priv
->stations
[sta_id
].sta
.key
.tkip_rx_tsc_byte2
= (u8
) iv32
;
419 for (i
= 0; i
< 5; i
++)
420 priv
->stations
[sta_id
].sta
.key
.tkip_rx_ttak
[i
] =
421 cpu_to_le16(phase1key
[i
]);
423 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
424 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
426 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
428 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
432 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
433 struct iwl_rxon_context
*ctx
,
434 struct ieee80211_key_conf
*keyconf
,
440 struct iwl_addsta_cmd sta_cmd
;
442 lockdep_assert_held(&priv
->mutex
);
444 ctx
->key_mapping_keys
--;
446 spin_lock_irqsave(&priv
->sta_lock
, flags
);
447 key_flags
= le16_to_cpu(priv
->stations
[sta_id
].sta
.key
.key_flags
);
448 keyidx
= (key_flags
>> STA_KEY_FLG_KEYID_POS
) & 0x3;
450 IWL_DEBUG_WEP(priv
, "Remove dynamic key: idx=%d sta=%d\n",
451 keyconf
->keyidx
, sta_id
);
453 if (keyconf
->keyidx
!= keyidx
) {
454 /* We need to remove a key with index different that the one
455 * in the uCode. This means that the key we need to remove has
456 * been replaced by another one with different index.
457 * Don't do anything and return ok
459 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
463 if (priv
->stations
[sta_id
].sta
.key
.key_offset
== WEP_INVALID_OFFSET
) {
464 IWL_WARN(priv
, "Removing wrong key %d 0x%x\n",
465 keyconf
->keyidx
, key_flags
);
466 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
470 if (!test_and_clear_bit(priv
->stations
[sta_id
].sta
.key
.key_offset
,
471 &priv
->ucode_key_table
))
472 IWL_ERR(priv
, "index %d not used in uCode key table.\n",
473 priv
->stations
[sta_id
].sta
.key
.key_offset
);
474 memset(&priv
->stations
[sta_id
].keyinfo
, 0,
475 sizeof(struct iwl_hw_key
));
476 memset(&priv
->stations
[sta_id
].sta
.key
, 0,
477 sizeof(struct iwl4965_keyinfo
));
478 priv
->stations
[sta_id
].sta
.key
.key_flags
=
479 STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_INVALID
;
480 priv
->stations
[sta_id
].sta
.key
.key_offset
= WEP_INVALID_OFFSET
;
481 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
482 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
484 if (iwl_is_rfkill(priv
)) {
485 IWL_DEBUG_WEP(priv
, "Not sending REPLY_ADD_STA command because RFKILL enabled.\n");
486 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
489 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
490 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
492 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
495 int iwl_set_dynamic_key(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
496 struct ieee80211_key_conf
*keyconf
, u8 sta_id
)
500 lockdep_assert_held(&priv
->mutex
);
502 ctx
->key_mapping_keys
++;
503 keyconf
->hw_key_idx
= HW_KEY_DYNAMIC
;
505 switch (keyconf
->cipher
) {
506 case WLAN_CIPHER_SUITE_CCMP
:
507 ret
= iwl_set_ccmp_dynamic_key_info(priv
, ctx
, keyconf
, sta_id
);
509 case WLAN_CIPHER_SUITE_TKIP
:
510 ret
= iwl_set_tkip_dynamic_key_info(priv
, ctx
, keyconf
, sta_id
);
512 case WLAN_CIPHER_SUITE_WEP40
:
513 case WLAN_CIPHER_SUITE_WEP104
:
514 ret
= iwl_set_wep_dynamic_key_info(priv
, ctx
, keyconf
, sta_id
);
518 "Unknown alg: %s cipher = %x\n", __func__
,
523 IWL_DEBUG_WEP(priv
, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
524 keyconf
->cipher
, keyconf
->keylen
, keyconf
->keyidx
,
531 * iwlagn_alloc_bcast_station - add broadcast station into driver's station table.
533 * This adds the broadcast station into the driver's station table
534 * and marks it driver active, so that it will be restored to the
535 * device at the next best time.
537 int iwlagn_alloc_bcast_station(struct iwl_priv
*priv
,
538 struct iwl_rxon_context
*ctx
)
540 struct iwl_link_quality_cmd
*link_cmd
;
544 spin_lock_irqsave(&priv
->sta_lock
, flags
);
545 sta_id
= iwl_prep_station(priv
, ctx
, iwl_bcast_addr
, false, NULL
);
546 if (sta_id
== IWL_INVALID_STATION
) {
547 IWL_ERR(priv
, "Unable to prepare broadcast station\n");
548 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
553 priv
->stations
[sta_id
].used
|= IWL_STA_DRIVER_ACTIVE
;
554 priv
->stations
[sta_id
].used
|= IWL_STA_BCAST
;
555 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
557 link_cmd
= iwl_sta_alloc_lq(priv
, sta_id
);
560 "Unable to initialize rate scaling for bcast station.\n");
564 spin_lock_irqsave(&priv
->sta_lock
, flags
);
565 priv
->stations
[sta_id
].lq
= link_cmd
;
566 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
572 * iwl_update_bcast_station - update broadcast station's LQ command
574 * Only used by iwlagn. Placed here to have all bcast station management
577 static int iwl_update_bcast_station(struct iwl_priv
*priv
,
578 struct iwl_rxon_context
*ctx
)
581 struct iwl_link_quality_cmd
*link_cmd
;
582 u8 sta_id
= ctx
->bcast_sta_id
;
584 link_cmd
= iwl_sta_alloc_lq(priv
, sta_id
);
586 IWL_ERR(priv
, "Unable to initialize rate scaling for bcast station.\n");
590 spin_lock_irqsave(&priv
->sta_lock
, flags
);
591 if (priv
->stations
[sta_id
].lq
)
592 kfree(priv
->stations
[sta_id
].lq
);
594 IWL_DEBUG_INFO(priv
, "Bcast station rate scaling has not been initialized yet.\n");
595 priv
->stations
[sta_id
].lq
= link_cmd
;
596 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
601 int iwl_update_bcast_stations(struct iwl_priv
*priv
)
603 struct iwl_rxon_context
*ctx
;
606 for_each_context(priv
, ctx
) {
607 ret
= iwl_update_bcast_station(priv
, ctx
);
616 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
618 int iwl_sta_tx_modify_enable_tid(struct iwl_priv
*priv
, int sta_id
, int tid
)
621 struct iwl_addsta_cmd sta_cmd
;
623 lockdep_assert_held(&priv
->mutex
);
625 /* Remove "disable" flag, to enable Tx for this TID */
626 spin_lock_irqsave(&priv
->sta_lock
, flags
);
627 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
628 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
629 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
630 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
631 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
633 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
636 int iwl_sta_rx_agg_start(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
641 struct iwl_addsta_cmd sta_cmd
;
643 lockdep_assert_held(&priv
->mutex
);
645 sta_id
= iwl_sta_id(sta
);
646 if (sta_id
== IWL_INVALID_STATION
)
649 spin_lock_irqsave(&priv
->sta_lock
, flags
);
650 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
651 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
652 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
653 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
654 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
655 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
656 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
658 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
661 int iwl_sta_rx_agg_stop(struct iwl_priv
*priv
, struct ieee80211_sta
*sta
,
666 struct iwl_addsta_cmd sta_cmd
;
668 lockdep_assert_held(&priv
->mutex
);
670 sta_id
= iwl_sta_id(sta
);
671 if (sta_id
== IWL_INVALID_STATION
) {
672 IWL_ERR(priv
, "Invalid station for AGG tid %d\n", tid
);
676 spin_lock_irqsave(&priv
->sta_lock
, flags
);
677 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
678 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
679 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
680 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
681 memcpy(&sta_cmd
, &priv
->stations
[sta_id
].sta
, sizeof(struct iwl_addsta_cmd
));
682 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
684 return iwl_send_add_sta(priv
, &sta_cmd
, CMD_SYNC
);
687 static void iwl_sta_modify_ps_wake(struct iwl_priv
*priv
, int sta_id
)
691 spin_lock_irqsave(&priv
->sta_lock
, flags
);
692 priv
->stations
[sta_id
].sta
.station_flags
&= ~STA_FLG_PWR_SAVE_MSK
;
693 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
694 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= 0;
695 priv
->stations
[sta_id
].sta
.sleep_tx_count
= 0;
696 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
697 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
698 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
702 void iwl_sta_modify_sleep_tx_count(struct iwl_priv
*priv
, int sta_id
, int cnt
)
706 spin_lock_irqsave(&priv
->sta_lock
, flags
);
707 priv
->stations
[sta_id
].sta
.station_flags
|= STA_FLG_PWR_SAVE_MSK
;
708 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
709 priv
->stations
[sta_id
].sta
.sta
.modify_mask
=
710 STA_MODIFY_SLEEP_TX_COUNT_MSK
;
711 priv
->stations
[sta_id
].sta
.sleep_tx_count
= cpu_to_le16(cnt
);
712 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
713 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
714 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
718 void iwlagn_mac_sta_notify(struct ieee80211_hw
*hw
,
719 struct ieee80211_vif
*vif
,
720 enum sta_notify_cmd cmd
,
721 struct ieee80211_sta
*sta
)
723 struct iwl_priv
*priv
= hw
->priv
;
724 struct iwl_station_priv
*sta_priv
= (void *)sta
->drv_priv
;
728 case STA_NOTIFY_SLEEP
:
729 WARN_ON(!sta_priv
->client
);
730 sta_priv
->asleep
= true;
731 if (atomic_read(&sta_priv
->pending_frames
) > 0)
732 ieee80211_sta_block_awake(hw
, sta
, true);
734 case STA_NOTIFY_AWAKE
:
735 WARN_ON(!sta_priv
->client
);
736 if (!sta_priv
->asleep
)
738 sta_priv
->asleep
= false;
739 sta_id
= iwl_sta_id(sta
);
740 if (sta_id
!= IWL_INVALID_STATION
)
741 iwl_sta_modify_ps_wake(priv
, sta_id
);