1 /******************************************************************************
3 * Copyright(c) 2003 - 2008 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 * James P. Ketrenos <ipw2100-admin@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>
36 #include "iwl-helpers.h"
39 #define IWL_STA_DRIVER_ACTIVE 0x1 /* ucode entry is active */
40 #define IWL_STA_UCODE_ACTIVE 0x2 /* ucode entry is active */
42 u8
iwl_find_station(struct iwl_priv
*priv
, const u8
*addr
)
46 int ret
= IWL_INVALID_STATION
;
50 if ((priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
) ||
51 (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
))
54 if (is_broadcast_ether_addr(addr
))
55 return priv
->hw_params
.bcast_sta_id
;
57 spin_lock_irqsave(&priv
->sta_lock
, flags
);
58 for (i
= start
; i
< priv
->hw_params
.max_stations
; i
++)
59 if (priv
->stations
[i
].used
&&
60 (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
66 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
67 print_mac(mac
, addr
), priv
->num_stations
);
70 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
73 EXPORT_SYMBOL(iwl_find_station
);
75 int iwl_get_ra_sta_id(struct iwl_priv
*priv
, struct ieee80211_hdr
*hdr
)
77 if (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
) {
80 u8
*da
= ieee80211_get_DA(hdr
);
81 return iwl_find_station(priv
, da
);
84 EXPORT_SYMBOL(iwl_get_ra_sta_id
);
86 static int iwl_add_sta_callback(struct iwl_priv
*priv
,
87 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
89 struct iwl_rx_packet
*res
= NULL
;
92 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
96 res
= (struct iwl_rx_packet
*)skb
->data
;
97 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
98 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
103 switch (res
->u
.add_sta
.status
) {
104 case ADD_STA_SUCCESS_MSK
:
105 /* FIXME: implement iwl_sta_ucode_activate(priv, addr); */
108 IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n",
109 res
->u
.add_sta
.status
);
113 /* We didn't cache the SKB; let the caller free it */
117 int iwl_send_add_sta(struct iwl_priv
*priv
,
118 struct iwl_addsta_cmd
*sta
, u8 flags
)
120 struct iwl_rx_packet
*res
= NULL
;
122 u8 data
[sizeof(*sta
)];
123 struct iwl_host_cmd cmd
= {
129 if (flags
& CMD_ASYNC
)
130 cmd
.meta
.u
.callback
= iwl_add_sta_callback
;
132 cmd
.meta
.flags
|= CMD_WANT_SKB
;
134 cmd
.len
= priv
->cfg
->ops
->utils
->build_addsta_hcmd(sta
, data
);
135 ret
= iwl_send_cmd(priv
, &cmd
);
137 if (ret
|| (flags
& CMD_ASYNC
))
140 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
141 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
142 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
148 switch (res
->u
.add_sta
.status
) {
149 case ADD_STA_SUCCESS_MSK
:
150 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
154 IWL_WARNING("REPLY_ADD_STA failed\n");
159 priv
->alloc_rxb_skb
--;
160 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
164 EXPORT_SYMBOL(iwl_send_add_sta
);
166 static void iwl_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
167 struct ieee80211_ht_info
*sta_ht_inf
)
172 if (!sta_ht_inf
|| !sta_ht_inf
->ht_supported
)
175 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2;
177 sta_flags
= priv
->stations
[index
].sta
.station_flags
;
179 sta_flags
&= ~(STA_FLG_RTS_MIMO_PROT_MSK
| STA_FLG_MIMO_DIS_MSK
);
181 switch (mimo_ps_mode
) {
182 case WLAN_HT_CAP_MIMO_PS_STATIC
:
183 sta_flags
|= STA_FLG_MIMO_DIS_MSK
;
185 case WLAN_HT_CAP_MIMO_PS_DYNAMIC
:
186 sta_flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
188 case WLAN_HT_CAP_MIMO_PS_DISABLED
:
191 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode
);
195 sta_flags
|= cpu_to_le32(
196 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
198 sta_flags
|= cpu_to_le32(
199 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
201 if (iwl_is_fat_tx_allowed(priv
, sta_ht_inf
))
202 sta_flags
|= STA_FLG_FAT_EN_MSK
;
204 sta_flags
&= ~STA_FLG_FAT_EN_MSK
;
206 priv
->stations
[index
].sta
.station_flags
= sta_flags
;
212 * iwl_add_station_flags - Add station to tables in driver and device
214 u8
iwl_add_station_flags(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
,
215 u8 flags
, struct ieee80211_ht_info
*ht_info
)
218 int index
= IWL_INVALID_STATION
;
219 struct iwl_station_entry
*station
;
220 unsigned long flags_spin
;
221 DECLARE_MAC_BUF(mac
);
223 spin_lock_irqsave(&priv
->sta_lock
, flags_spin
);
226 else if (is_broadcast_ether_addr(addr
))
227 index
= priv
->hw_params
.bcast_sta_id
;
229 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++) {
230 if (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
236 if (!priv
->stations
[i
].used
&&
237 index
== IWL_INVALID_STATION
)
242 /* These two conditions have the same outcome, but keep them separate
243 since they have different meanings */
244 if (unlikely(index
== IWL_INVALID_STATION
)) {
245 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
249 if (priv
->stations
[index
].used
&&
250 !compare_ether_addr(priv
->stations
[index
].sta
.sta
.addr
, addr
)) {
251 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
256 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index
, print_mac(mac
, addr
));
257 station
= &priv
->stations
[index
];
259 priv
->num_stations
++;
261 /* Set up the REPLY_ADD_STA command to send to device */
262 memset(&station
->sta
, 0, sizeof(struct iwl_addsta_cmd
));
263 memcpy(station
->sta
.sta
.addr
, addr
, ETH_ALEN
);
264 station
->sta
.mode
= 0;
265 station
->sta
.sta
.sta_id
= index
;
266 station
->sta
.station_flags
= 0;
268 /* BCAST station and IBSS stations do not work in HT mode */
269 if (index
!= priv
->hw_params
.bcast_sta_id
&&
270 priv
->iw_mode
!= IEEE80211_IF_TYPE_IBSS
)
271 iwl_set_ht_add_station(priv
, index
, ht_info
);
273 spin_unlock_irqrestore(&priv
->sta_lock
, flags_spin
);
275 /* Add station to device's station table */
276 iwl_send_add_sta(priv
, &station
->sta
, flags
);
280 EXPORT_SYMBOL(iwl_add_station_flags
);
282 static int iwl_sta_ucode_deactivate(struct iwl_priv
*priv
, const char *addr
)
286 DECLARE_MAC_BUF(mac
);
288 sta_id
= iwl_find_station(priv
, addr
);
289 if (sta_id
!= IWL_INVALID_STATION
) {
290 IWL_DEBUG_ASSOC("Removed STA from Ucode: %s\n",
291 print_mac(mac
, addr
));
292 spin_lock_irqsave(&priv
->sta_lock
, flags
);
293 priv
->stations
[sta_id
].used
&= ~IWL_STA_UCODE_ACTIVE
;
294 memset(&priv
->stations
[sta_id
], 0,
295 sizeof(struct iwl_station_entry
));
296 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
302 static int iwl_remove_sta_callback(struct iwl_priv
*priv
,
303 struct iwl_cmd
*cmd
, struct sk_buff
*skb
)
305 struct iwl_rx_packet
*res
= NULL
;
306 const char *addr
= cmd
->cmd
.rm_sta
.addr
;
309 IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
313 res
= (struct iwl_rx_packet
*)skb
->data
;
314 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
315 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
320 switch (res
->u
.rem_sta
.status
) {
321 case REM_STA_SUCCESS_MSK
:
322 iwl_sta_ucode_deactivate(priv
, addr
);
328 /* We didn't cache the SKB; let the caller free it */
332 static int iwl_send_remove_station(struct iwl_priv
*priv
, const u8
*addr
,
335 struct iwl_rx_packet
*res
= NULL
;
338 struct iwl_rem_sta_cmd rm_sta_cmd
;
340 struct iwl_host_cmd cmd
= {
341 .id
= REPLY_REMOVE_STA
,
342 .len
= sizeof(struct iwl_rem_sta_cmd
),
347 memset(&rm_sta_cmd
, 0, sizeof(rm_sta_cmd
));
348 rm_sta_cmd
.num_sta
= 1;
349 memcpy(&rm_sta_cmd
.addr
, addr
, ETH_ALEN
);
351 if (flags
& CMD_ASYNC
)
352 cmd
.meta
.u
.callback
= iwl_remove_sta_callback
;
354 cmd
.meta
.flags
|= CMD_WANT_SKB
;
355 ret
= iwl_send_cmd(priv
, &cmd
);
357 if (ret
|| (flags
& CMD_ASYNC
))
360 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
361 if (res
->hdr
.flags
& IWL_CMD_FAILED_MSK
) {
362 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
368 switch (res
->u
.rem_sta
.status
) {
369 case REM_STA_SUCCESS_MSK
:
370 iwl_sta_ucode_deactivate(priv
, addr
);
371 IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
375 IWL_ERROR("REPLY_REMOVE_STA failed\n");
380 priv
->alloc_rxb_skb
--;
381 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
387 * iwl_remove_station - Remove driver's knowledge of station.
389 u8
iwl_remove_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
391 int index
= IWL_INVALID_STATION
;
395 spin_lock_irqsave(&priv
->sta_lock
, flags
);
399 else if (is_broadcast_ether_addr(addr
))
400 index
= priv
->hw_params
.bcast_sta_id
;
402 for (i
= IWL_STA_ID
; i
< priv
->hw_params
.max_stations
; i
++)
403 if (priv
->stations
[i
].used
&&
404 !compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
410 if (unlikely(index
== IWL_INVALID_STATION
))
413 if (priv
->stations
[index
].used
) {
414 priv
->stations
[index
].used
= 0;
415 priv
->num_stations
--;
418 BUG_ON(priv
->num_stations
< 0);
419 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
420 iwl_send_remove_station(priv
, addr
, CMD_ASYNC
);
423 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
426 EXPORT_SYMBOL(iwl_remove_station
);
427 static int iwl_get_free_ucode_key_index(struct iwl_priv
*priv
)
431 for (i
= 0; i
< STA_KEY_MAX_NUM
; i
++)
432 if (!test_and_set_bit(i
, &priv
->ucode_key_table
))
438 int iwl_send_static_wepkey_cmd(struct iwl_priv
*priv
, u8 send_if_empty
)
440 int i
, not_empty
= 0;
441 u8 buff
[sizeof(struct iwl_wep_cmd
) +
442 sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
];
443 struct iwl_wep_cmd
*wep_cmd
= (struct iwl_wep_cmd
*)buff
;
444 size_t cmd_size
= sizeof(struct iwl_wep_cmd
);
445 struct iwl_host_cmd cmd
= {
448 .meta
.flags
= CMD_ASYNC
,
451 memset(wep_cmd
, 0, cmd_size
+
452 (sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
));
454 for (i
= 0; i
< WEP_KEYS_MAX
; i
++) {
455 wep_cmd
->key
[i
].key_index
= i
;
456 if (priv
->wep_keys
[i
].key_size
) {
457 wep_cmd
->key
[i
].key_offset
= i
;
460 wep_cmd
->key
[i
].key_offset
= WEP_INVALID_OFFSET
;
463 wep_cmd
->key
[i
].key_size
= priv
->wep_keys
[i
].key_size
;
464 memcpy(&wep_cmd
->key
[i
].key
[3], priv
->wep_keys
[i
].key
,
465 priv
->wep_keys
[i
].key_size
);
468 wep_cmd
->global_key_type
= WEP_KEY_WEP_TYPE
;
469 wep_cmd
->num_keys
= WEP_KEYS_MAX
;
471 cmd_size
+= sizeof(struct iwl_wep_key
) * WEP_KEYS_MAX
;
475 if (not_empty
|| send_if_empty
)
476 return iwl_send_cmd(priv
, &cmd
);
480 EXPORT_SYMBOL(iwl_send_static_wepkey_cmd
);
482 int iwl_remove_default_wep_key(struct iwl_priv
*priv
,
483 struct ieee80211_key_conf
*keyconf
)
488 spin_lock_irqsave(&priv
->sta_lock
, flags
);
490 if (!test_and_clear_bit(keyconf
->keyidx
, &priv
->ucode_key_table
))
491 IWL_ERROR("index %d not used in uCode key table.\n",
494 priv
->default_wep_key
--;
495 memset(&priv
->wep_keys
[keyconf
->keyidx
], 0, sizeof(priv
->wep_keys
[0]));
496 ret
= iwl_send_static_wepkey_cmd(priv
, 1);
497 IWL_DEBUG_WEP("Remove default WEP key: idx=%d ret=%d\n",
498 keyconf
->keyidx
, ret
);
499 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
503 EXPORT_SYMBOL(iwl_remove_default_wep_key
);
505 int iwl_set_default_wep_key(struct iwl_priv
*priv
,
506 struct ieee80211_key_conf
*keyconf
)
511 if (keyconf
->keylen
!= WEP_KEY_LEN_128
&&
512 keyconf
->keylen
!= WEP_KEY_LEN_64
) {
513 IWL_DEBUG_WEP("Bad WEP key length %d\n", keyconf
->keylen
);
517 keyconf
->flags
&= ~IEEE80211_KEY_FLAG_GENERATE_IV
;
518 keyconf
->hw_key_idx
= HW_KEY_DEFAULT
;
519 priv
->stations
[IWL_AP_ID
].keyinfo
.alg
= ALG_WEP
;
521 spin_lock_irqsave(&priv
->sta_lock
, flags
);
522 priv
->default_wep_key
++;
524 if (test_and_set_bit(keyconf
->keyidx
, &priv
->ucode_key_table
))
525 IWL_ERROR("index %d already used in uCode key table.\n",
528 priv
->wep_keys
[keyconf
->keyidx
].key_size
= keyconf
->keylen
;
529 memcpy(&priv
->wep_keys
[keyconf
->keyidx
].key
, &keyconf
->key
,
532 ret
= iwl_send_static_wepkey_cmd(priv
, 0);
533 IWL_DEBUG_WEP("Set default WEP key: len=%d idx=%d ret=%d\n",
534 keyconf
->keylen
, keyconf
->keyidx
, ret
);
535 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
539 EXPORT_SYMBOL(iwl_set_default_wep_key
);
541 static int iwl_set_wep_dynamic_key_info(struct iwl_priv
*priv
,
542 struct ieee80211_key_conf
*keyconf
,
546 __le16 key_flags
= 0;
549 keyconf
->flags
&= ~IEEE80211_KEY_FLAG_GENERATE_IV
;
551 key_flags
|= (STA_KEY_FLG_WEP
| STA_KEY_FLG_MAP_KEY_MSK
);
552 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
553 key_flags
&= ~STA_KEY_FLG_INVALID
;
555 if (keyconf
->keylen
== WEP_KEY_LEN_128
)
556 key_flags
|= STA_KEY_FLG_KEY_SIZE_MSK
;
558 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
559 key_flags
|= STA_KEY_MULTICAST_MSK
;
561 spin_lock_irqsave(&priv
->sta_lock
, flags
);
563 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
564 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
565 priv
->stations
[sta_id
].keyinfo
.keyidx
= keyconf
->keyidx
;
567 memcpy(priv
->stations
[sta_id
].keyinfo
.key
,
568 keyconf
->key
, keyconf
->keylen
);
570 memcpy(&priv
->stations
[sta_id
].sta
.key
.key
[3],
571 keyconf
->key
, keyconf
->keylen
);
573 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
574 == STA_KEY_FLG_NO_ENC
)
575 priv
->stations
[sta_id
].sta
.key
.key_offset
=
576 iwl_get_free_ucode_key_index(priv
);
577 /* else, we are overriding an existing key => no need to allocated room
580 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
581 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
582 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
584 ret
= iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
586 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
591 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv
*priv
,
592 struct ieee80211_key_conf
*keyconf
,
596 __le16 key_flags
= 0;
598 key_flags
|= (STA_KEY_FLG_CCMP
| STA_KEY_FLG_MAP_KEY_MSK
);
599 key_flags
|= cpu_to_le16(keyconf
->keyidx
<< STA_KEY_FLG_KEYID_POS
);
600 key_flags
&= ~STA_KEY_FLG_INVALID
;
602 if (sta_id
== priv
->hw_params
.bcast_sta_id
)
603 key_flags
|= STA_KEY_MULTICAST_MSK
;
605 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
607 spin_lock_irqsave(&priv
->sta_lock
, flags
);
608 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
609 priv
->stations
[sta_id
].keyinfo
.keylen
= keyconf
->keylen
;
611 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
,
614 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
,
617 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
618 == STA_KEY_FLG_NO_ENC
)
619 priv
->stations
[sta_id
].sta
.key
.key_offset
=
620 iwl_get_free_ucode_key_index(priv
);
621 /* else, we are overriding an existing key => no need to allocated room
624 priv
->stations
[sta_id
].sta
.key
.key_flags
= key_flags
;
625 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
626 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
628 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
630 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
631 return iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
634 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv
*priv
,
635 struct ieee80211_key_conf
*keyconf
,
641 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
642 keyconf
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
644 spin_lock_irqsave(&priv
->sta_lock
, flags
);
646 priv
->stations
[sta_id
].keyinfo
.alg
= keyconf
->alg
;
647 priv
->stations
[sta_id
].keyinfo
.keylen
= 16;
649 if ((priv
->stations
[sta_id
].sta
.key
.key_flags
& STA_KEY_FLG_ENCRYPT_MSK
)
650 == STA_KEY_FLG_NO_ENC
)
651 priv
->stations
[sta_id
].sta
.key
.key_offset
=
652 iwl_get_free_ucode_key_index(priv
);
653 /* else, we are overriding an existing key => no need to allocated room
656 /* This copy is acutally not needed: we get the key with each TX */
657 memcpy(priv
->stations
[sta_id
].keyinfo
.key
, keyconf
->key
, 16);
659 memcpy(priv
->stations
[sta_id
].sta
.key
.key
, keyconf
->key
, 16);
661 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
666 int iwl_remove_dynamic_key(struct iwl_priv
*priv
,
667 struct ieee80211_key_conf
*keyconf
,
675 priv
->key_mapping_key
--;
677 spin_lock_irqsave(&priv
->sta_lock
, flags
);
678 key_flags
= le16_to_cpu(priv
->stations
[sta_id
].sta
.key
.key_flags
);
679 keyidx
= (key_flags
>> STA_KEY_FLG_KEYID_POS
) & 0x3;
681 IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n",
682 keyconf
->keyidx
, sta_id
);
684 if (keyconf
->keyidx
!= keyidx
) {
685 /* We need to remove a key with index different that the one
686 * in the uCode. This means that the key we need to remove has
687 * been replaced by another one with different index.
688 * Don't do anything and return ok
690 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
694 if (!test_and_clear_bit(priv
->stations
[sta_id
].sta
.key
.key_offset
,
695 &priv
->ucode_key_table
))
696 IWL_ERROR("index %d not used in uCode key table.\n",
697 priv
->stations
[sta_id
].sta
.key
.key_offset
);
698 memset(&priv
->stations
[sta_id
].keyinfo
, 0,
699 sizeof(struct iwl_hw_key
));
700 memset(&priv
->stations
[sta_id
].sta
.key
, 0,
701 sizeof(struct iwl4965_keyinfo
));
702 priv
->stations
[sta_id
].sta
.key
.key_flags
=
703 STA_KEY_FLG_NO_ENC
| STA_KEY_FLG_INVALID
;
704 priv
->stations
[sta_id
].sta
.key
.key_offset
= WEP_INVALID_OFFSET
;
705 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_KEY_MASK
;
706 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
708 ret
= iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
709 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
712 EXPORT_SYMBOL(iwl_remove_dynamic_key
);
714 int iwl_set_dynamic_key(struct iwl_priv
*priv
,
715 struct ieee80211_key_conf
*keyconf
, u8 sta_id
)
719 priv
->key_mapping_key
++;
720 keyconf
->hw_key_idx
= HW_KEY_DYNAMIC
;
722 switch (keyconf
->alg
) {
724 ret
= iwl_set_ccmp_dynamic_key_info(priv
, keyconf
, sta_id
);
727 ret
= iwl_set_tkip_dynamic_key_info(priv
, keyconf
, sta_id
);
730 ret
= iwl_set_wep_dynamic_key_info(priv
, keyconf
, sta_id
);
733 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__
, keyconf
->alg
);
737 IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
738 keyconf
->alg
, keyconf
->keylen
, keyconf
->keyidx
,
743 EXPORT_SYMBOL(iwl_set_dynamic_key
);
745 #ifdef CONFIG_IWLWIFI_DEBUG
746 static void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
747 struct iwl_link_quality_cmd
*lq
)
750 IWL_DEBUG_RATE("lq station id 0x%x\n", lq
->sta_id
);
751 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
752 lq
->general_params
.single_stream_ant_msk
,
753 lq
->general_params
.dual_stream_ant_msk
);
755 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++)
756 IWL_DEBUG_RATE("lq index %d 0x%X\n",
757 i
, lq
->rs_table
[i
].rate_n_flags
);
760 static inline void iwl_dump_lq_cmd(struct iwl_priv
*priv
,
761 struct iwl_link_quality_cmd
*lq
)
766 int iwl_send_lq_cmd(struct iwl_priv
*priv
,
767 struct iwl_link_quality_cmd
*lq
, u8 flags
)
769 struct iwl_host_cmd cmd
= {
770 .id
= REPLY_TX_LINK_QUALITY_CMD
,
771 .len
= sizeof(struct iwl_link_quality_cmd
),
776 if ((lq
->sta_id
== 0xFF) &&
777 (priv
->iw_mode
== IEEE80211_IF_TYPE_IBSS
))
780 if (lq
->sta_id
== 0xFF)
781 lq
->sta_id
= IWL_AP_ID
;
783 iwl_dump_lq_cmd(priv
,lq
);
785 if (iwl_is_associated(priv
) && priv
->assoc_station_added
&&
786 priv
->lq_mngr
.lq_ready
)
787 return iwl_send_cmd(priv
, &cmd
);
791 EXPORT_SYMBOL(iwl_send_lq_cmd
);
794 * iwl_sta_init_lq - Initialize a station's hardware rate table
796 * The uCode's station table contains a table of fallback rates
797 * for automatic fallback during transmission.
799 * NOTE: This sets up a default set of values. These will be replaced later
800 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
803 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
804 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
805 * which requires station table entry to exist).
807 static void iwl_sta_init_lq(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
810 struct iwl_link_quality_cmd link_cmd
= {
815 /* Set up the rate scaling to start at selected rate, fall back
816 * all the way down to 1M in IEEE order, and then spin on 1M */
818 r
= IWL_RATE_54M_INDEX
;
819 else if (priv
->band
== IEEE80211_BAND_5GHZ
)
820 r
= IWL_RATE_6M_INDEX
;
822 r
= IWL_RATE_1M_INDEX
;
824 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
826 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
827 rate_flags
|= RATE_MCS_CCK_MSK
;
829 /* Use Tx antenna B only */
830 rate_flags
|= RATE_MCS_ANT_B_MSK
; /*FIXME:RS*/
832 link_cmd
.rs_table
[i
].rate_n_flags
=
833 iwl_hw_set_rate_n_flags(iwl_rates
[r
].plcp
, rate_flags
);
834 r
= iwl4965_get_prev_ieee_rate(r
);
837 link_cmd
.general_params
.single_stream_ant_msk
= 2;
838 link_cmd
.general_params
.dual_stream_ant_msk
= 3;
839 link_cmd
.agg_params
.agg_dis_start_th
= 3;
840 link_cmd
.agg_params
.agg_time_limit
= cpu_to_le16(4000);
842 /* Update the rate scaling for control frame Tx to AP */
843 link_cmd
.sta_id
= is_ap
? IWL_AP_ID
: priv
->hw_params
.bcast_sta_id
;
845 iwl_send_cmd_pdu_async(priv
, REPLY_TX_LINK_QUALITY_CMD
,
846 sizeof(link_cmd
), &link_cmd
, NULL
);
849 * iwl_rxon_add_station - add station into station table.
851 * there is only one AP station with id= IWL_AP_ID
852 * NOTE: mutex must be held before calling this fnction
854 int iwl_rxon_add_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
858 /* Add station to device's station table */
859 struct ieee80211_conf
*conf
= &priv
->hw
->conf
;
860 struct ieee80211_ht_info
*cur_ht_config
= &conf
->ht_conf
;
863 (conf
->flags
& IEEE80211_CONF_SUPPORT_HT_MODE
) &&
864 (priv
->iw_mode
== IEEE80211_IF_TYPE_STA
))
865 sta_id
= iwl_add_station_flags(priv
, addr
, is_ap
,
868 sta_id
= iwl_add_station_flags(priv
, addr
, is_ap
,
871 /* Set up default rate scaling table in device's station table */
872 iwl_sta_init_lq(priv
, addr
, is_ap
);
876 EXPORT_SYMBOL(iwl_rxon_add_station
);
879 * iwl_get_sta_id - Find station's index within station table
881 * If new IBSS station, create new entry in station table
883 int iwl_get_sta_id(struct iwl_priv
*priv
, struct ieee80211_hdr
*hdr
)
886 u16 fc
= le16_to_cpu(hdr
->frame_control
);
887 DECLARE_MAC_BUF(mac
);
889 /* If this frame is broadcast or management, use broadcast station id */
890 if (((fc
& IEEE80211_FCTL_FTYPE
) != IEEE80211_FTYPE_DATA
) ||
891 is_multicast_ether_addr(hdr
->addr1
))
892 return priv
->hw_params
.bcast_sta_id
;
894 switch (priv
->iw_mode
) {
896 /* If we are a client station in a BSS network, use the special
897 * AP station entry (that's the only station we communicate with) */
898 case IEEE80211_IF_TYPE_STA
:
901 /* If we are an AP, then find the station, or use BCAST */
902 case IEEE80211_IF_TYPE_AP
:
903 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
904 if (sta_id
!= IWL_INVALID_STATION
)
906 return priv
->hw_params
.bcast_sta_id
;
908 /* If this frame is going out to an IBSS network, find the station,
909 * or create a new station table entry */
910 case IEEE80211_IF_TYPE_IBSS
:
911 sta_id
= iwl_find_station(priv
, hdr
->addr1
);
912 if (sta_id
!= IWL_INVALID_STATION
)
915 /* Create new station table entry */
916 sta_id
= iwl_add_station_flags(priv
, hdr
->addr1
,
919 if (sta_id
!= IWL_INVALID_STATION
)
922 IWL_DEBUG_DROP("Station %s not in station map. "
923 "Defaulting to broadcast...\n",
924 print_mac(mac
, hdr
->addr1
));
925 iwl_print_hex_dump(priv
, IWL_DL_DROP
, (u8
*) hdr
, sizeof(*hdr
));
926 return priv
->hw_params
.bcast_sta_id
;
929 IWL_WARNING("Unknown mode of operation: %d", priv
->iw_mode
);
930 return priv
->hw_params
.bcast_sta_id
;
933 EXPORT_SYMBOL(iwl_get_sta_id
);
936 * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
938 void iwl_sta_modify_enable_tid_tx(struct iwl_priv
*priv
, int sta_id
, int tid
)
942 /* Remove "disable" flag, to enable Tx for this TID */
943 spin_lock_irqsave(&priv
->sta_lock
, flags
);
944 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
945 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
946 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
947 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
949 iwl_send_add_sta(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
951 EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx
);