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>
33 #include "iwl-eeprom.h"
38 #include "iwl-helpers.h"
41 #define IWL_STA_DRIVER_ACTIVE 0x1 /* ucode entry is active */
42 #define IWL_STA_UCODE_ACTIVE 0x2 /* ucode entry is active */
44 u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
48 int ret = IWL_INVALID_STATION;
52 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
53 (priv->iw_mode == IEEE80211_IF_TYPE_AP))
56 if (is_broadcast_ether_addr(addr))
57 return priv->hw_params.bcast_sta_id;
59 spin_lock_irqsave(&priv->sta_lock, flags);
60 for (i = start; i < priv->hw_params.max_stations; i++)
61 if (priv->stations[i].used &&
62 (!compare_ether_addr(priv->stations[i].sta.sta.addr,
68 IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
69 print_mac(mac, addr), priv->num_stations);
72 spin_unlock_irqrestore(&priv->sta_lock, flags);
75 EXPORT_SYMBOL(iwl_find_station);
77 static int iwl_add_sta_callback(struct iwl_priv *priv,
78 struct iwl_cmd *cmd, struct sk_buff *skb)
80 struct iwl_rx_packet *res = NULL;
83 IWL_ERROR("Error: Response NULL in REPLY_ADD_STA.\n");
87 res = (struct iwl_rx_packet *)skb->data;
88 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
89 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
94 switch (res->u.add_sta.status) {
95 case ADD_STA_SUCCESS_MSK:
96 /* FIXME: implement iwl_sta_ucode_activate(priv, addr); */
99 IWL_DEBUG_HC("Received REPLY_ADD_STA:(0x%08X)\n",
100 res->u.add_sta.status);
104 /* We didn't cache the SKB; let the caller free it */
110 int iwl_send_add_sta(struct iwl_priv *priv,
111 struct iwl_addsta_cmd *sta, u8 flags)
113 struct iwl_rx_packet *res = NULL;
115 u8 data[sizeof(*sta)];
116 struct iwl_host_cmd cmd = {
122 if (flags & CMD_ASYNC)
123 cmd.meta.u.callback = iwl_add_sta_callback;
125 cmd.meta.flags |= CMD_WANT_SKB;
127 cmd.len = priv->cfg->ops->utils->build_addsta_hcmd(sta, data);
128 ret = iwl_send_cmd(priv, &cmd);
130 if (ret || (flags & CMD_ASYNC))
133 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
134 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
135 IWL_ERROR("Bad return from REPLY_ADD_STA (0x%08X)\n",
141 switch (res->u.add_sta.status) {
142 case ADD_STA_SUCCESS_MSK:
143 IWL_DEBUG_INFO("REPLY_ADD_STA PASSED\n");
147 IWL_WARNING("REPLY_ADD_STA failed\n");
152 priv->alloc_rxb_skb--;
153 dev_kfree_skb_any(cmd.meta.u.skb);
157 EXPORT_SYMBOL(iwl_send_add_sta);
159 #ifdef CONFIG_IWL4965_HT
161 static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
162 struct ieee80211_ht_info *sta_ht_inf)
167 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
170 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
172 sta_flags = priv->stations[index].sta.station_flags;
174 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
176 switch (mimo_ps_mode) {
177 case WLAN_HT_CAP_MIMO_PS_STATIC:
178 sta_flags |= STA_FLG_MIMO_DIS_MSK;
180 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
181 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
183 case WLAN_HT_CAP_MIMO_PS_DISABLED:
186 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
190 sta_flags |= cpu_to_le32(
191 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
193 sta_flags |= cpu_to_le32(
194 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
196 if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
197 sta_flags |= STA_FLG_FAT_EN_MSK;
199 sta_flags &= ~STA_FLG_FAT_EN_MSK;
201 priv->stations[index].sta.station_flags = sta_flags;
206 static inline void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
207 struct ieee80211_ht_info *sta_ht_info)
213 * iwl_add_station_flags - Add station to tables in driver and device
215 u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
216 u8 flags, struct ieee80211_ht_info *ht_info)
219 int index = IWL_INVALID_STATION;
220 struct iwl_station_entry *station;
221 unsigned long flags_spin;
222 DECLARE_MAC_BUF(mac);
224 spin_lock_irqsave(&priv->sta_lock, flags_spin);
227 else if (is_broadcast_ether_addr(addr))
228 index = priv->hw_params.bcast_sta_id;
230 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
231 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
237 if (!priv->stations[i].used &&
238 index == IWL_INVALID_STATION)
243 /* These two conditions have the same outcome, but keep them separate
244 since they have different meanings */
245 if (unlikely(index == IWL_INVALID_STATION)) {
246 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
250 if (priv->stations[index].used &&
251 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
252 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
257 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
258 station = &priv->stations[index];
260 priv->num_stations++;
262 /* Set up the REPLY_ADD_STA command to send to device */
263 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
264 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
265 station->sta.mode = 0;
266 station->sta.sta.sta_id = index;
267 station->sta.station_flags = 0;
269 /* BCAST station and IBSS stations do not work in HT mode */
270 if (index != priv->hw_params.bcast_sta_id &&
271 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
272 iwl_set_ht_add_station(priv, index, ht_info);
274 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
276 /* Add station to device's station table */
277 iwl_send_add_sta(priv, &station->sta, flags);
281 EXPORT_SYMBOL(iwl_add_station_flags);
284 static int iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
288 DECLARE_MAC_BUF(mac);
290 sta_id = iwl_find_station(priv, addr);
291 if (sta_id != IWL_INVALID_STATION) {
292 IWL_DEBUG_ASSOC("Removed STA from Ucode: %s\n",
293 print_mac(mac, addr));
294 spin_lock_irqsave(&priv->sta_lock, flags);
295 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
296 memset(&priv->stations[sta_id], 0,
297 sizeof(struct iwl_station_entry));
298 spin_unlock_irqrestore(&priv->sta_lock, flags);
304 static int iwl_remove_sta_callback(struct iwl_priv *priv,
305 struct iwl_cmd *cmd, struct sk_buff *skb)
307 struct iwl_rx_packet *res = NULL;
308 const char *addr = cmd->cmd.rm_sta.addr;
311 IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
315 res = (struct iwl_rx_packet *)skb->data;
316 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
317 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
322 switch (res->u.rem_sta.status) {
323 case REM_STA_SUCCESS_MSK:
324 iwl_sta_ucode_deactivate(priv, addr);
330 /* We didn't cache the SKB; let the caller free it */
334 static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
337 struct iwl_rx_packet *res = NULL;
340 struct iwl_rem_sta_cmd rm_sta_cmd;
342 struct iwl_host_cmd cmd = {
343 .id = REPLY_REMOVE_STA,
344 .len = sizeof(struct iwl_rem_sta_cmd),
349 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
350 rm_sta_cmd.num_sta = 1;
351 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
353 if (flags & CMD_ASYNC)
354 cmd.meta.u.callback = iwl_remove_sta_callback;
356 cmd.meta.flags |= CMD_WANT_SKB;
357 ret = iwl_send_cmd(priv, &cmd);
359 if (ret || (flags & CMD_ASYNC))
362 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
363 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
364 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
370 switch (res->u.rem_sta.status) {
371 case REM_STA_SUCCESS_MSK:
372 iwl_sta_ucode_deactivate(priv, addr);
373 IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
377 IWL_ERROR("REPLY_REMOVE_STA failed\n");
382 priv->alloc_rxb_skb--;
383 dev_kfree_skb_any(cmd.meta.u.skb);
388 * iwl_remove_station - Remove driver's knowledge of station.
391 u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
393 int index = IWL_INVALID_STATION;
397 spin_lock_irqsave(&priv->sta_lock, flags);
401 else if (is_broadcast_ether_addr(addr))
402 index = priv->hw_params.bcast_sta_id;
404 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
405 if (priv->stations[i].used &&
406 !compare_ether_addr(priv->stations[i].sta.sta.addr,
412 if (unlikely(index == IWL_INVALID_STATION))
415 if (priv->stations[index].used) {
416 priv->stations[index].used = 0;
417 priv->num_stations--;
420 BUG_ON(priv->num_stations < 0);
421 spin_unlock_irqrestore(&priv->sta_lock, flags);
422 iwl_send_remove_station(priv, addr, CMD_ASYNC);
425 spin_unlock_irqrestore(&priv->sta_lock, flags);
428 EXPORT_SYMBOL(iwl_remove_station);
429 int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
433 for (i = 0; i < STA_KEY_MAX_NUM; i++)
434 if (!test_and_set_bit(i, &priv->ucode_key_table))
440 int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
442 int i, not_empty = 0;
443 u8 buff[sizeof(struct iwl_wep_cmd) +
444 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
445 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
446 size_t cmd_size = sizeof(struct iwl_wep_cmd);
447 struct iwl_host_cmd cmd = {
450 .meta.flags = CMD_ASYNC,
453 memset(wep_cmd, 0, cmd_size +
454 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
456 for (i = 0; i < WEP_KEYS_MAX ; i++) {
457 wep_cmd->key[i].key_index = i;
458 if (priv->wep_keys[i].key_size) {
459 wep_cmd->key[i].key_offset = i;
462 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
465 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
466 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
467 priv->wep_keys[i].key_size);
470 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
471 wep_cmd->num_keys = WEP_KEYS_MAX;
473 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
477 if (not_empty || send_if_empty)
478 return iwl_send_cmd(priv, &cmd);
482 EXPORT_SYMBOL(iwl_send_static_wepkey_cmd);
484 int iwl_remove_default_wep_key(struct iwl_priv *priv,
485 struct ieee80211_key_conf *keyconf)
490 spin_lock_irqsave(&priv->sta_lock, flags);
492 if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
493 IWL_ERROR("index %d not used in uCode key table.\n",
496 priv->default_wep_key--;
497 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
498 ret = iwl_send_static_wepkey_cmd(priv, 1);
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 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
512 keyconf->hw_key_idx = HW_KEY_DEFAULT;
513 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP;
515 spin_lock_irqsave(&priv->sta_lock, flags);
516 priv->default_wep_key++;
518 if (test_and_set_bit(keyconf->keyidx, &priv->ucode_key_table))
519 IWL_ERROR("index %d already used in uCode key table.\n",
522 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
523 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key,
526 ret = iwl_send_static_wepkey_cmd(priv, 0);
527 spin_unlock_irqrestore(&priv->sta_lock, flags);
531 EXPORT_SYMBOL(iwl_set_default_wep_key);
533 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
534 struct ieee80211_key_conf *keyconf,
538 __le16 key_flags = 0;
541 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
543 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
544 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
545 key_flags &= ~STA_KEY_FLG_INVALID;
547 if (keyconf->keylen == WEP_KEY_LEN_128)
548 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
550 if (sta_id == priv->hw_params.bcast_sta_id)
551 key_flags |= STA_KEY_MULTICAST_MSK;
553 spin_lock_irqsave(&priv->sta_lock, flags);
555 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
556 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
557 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
559 memcpy(priv->stations[sta_id].keyinfo.key,
560 keyconf->key, keyconf->keylen);
562 memcpy(&priv->stations[sta_id].sta.key.key[3],
563 keyconf->key, keyconf->keylen);
565 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
566 == STA_KEY_FLG_NO_ENC)
567 priv->stations[sta_id].sta.key.key_offset =
568 iwl_get_free_ucode_key_index(priv);
569 /* else, we are overriding an existing key => no need to allocated room
572 priv->stations[sta_id].sta.key.key_flags = key_flags;
573 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
574 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
576 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
578 spin_unlock_irqrestore(&priv->sta_lock, flags);
583 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
584 struct ieee80211_key_conf *keyconf,
588 __le16 key_flags = 0;
590 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
591 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
592 key_flags &= ~STA_KEY_FLG_INVALID;
594 if (sta_id == priv->hw_params.bcast_sta_id)
595 key_flags |= STA_KEY_MULTICAST_MSK;
597 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
599 spin_lock_irqsave(&priv->sta_lock, flags);
600 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
601 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
603 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
606 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
609 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
610 == STA_KEY_FLG_NO_ENC)
611 priv->stations[sta_id].sta.key.key_offset =
612 iwl_get_free_ucode_key_index(priv);
613 /* else, we are overriding an existing key => no need to allocated room
616 priv->stations[sta_id].sta.key.key_flags = key_flags;
617 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
618 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
620 spin_unlock_irqrestore(&priv->sta_lock, flags);
622 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
623 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
626 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
627 struct ieee80211_key_conf *keyconf,
633 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
634 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
636 spin_lock_irqsave(&priv->sta_lock, flags);
638 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
639 priv->stations[sta_id].keyinfo.keylen = 16;
641 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
642 == STA_KEY_FLG_NO_ENC)
643 priv->stations[sta_id].sta.key.key_offset =
644 iwl_get_free_ucode_key_index(priv);
645 /* else, we are overriding an existing key => no need to allocated room
648 /* This copy is acutally not needed: we get the key with each TX */
649 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
651 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
653 spin_unlock_irqrestore(&priv->sta_lock, flags);
658 int iwl_remove_dynamic_key(struct iwl_priv *priv,
659 struct ieee80211_key_conf *keyconf,
667 priv->key_mapping_key--;
669 spin_lock_irqsave(&priv->sta_lock, flags);
670 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
671 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
673 if (keyconf->keyidx != keyidx) {
674 /* We need to remove a key with index different that the one
675 * in the uCode. This means that the key we need to remove has
676 * been replaced by another one with different index.
677 * Don't do anything and return ok
679 spin_unlock_irqrestore(&priv->sta_lock, flags);
683 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
684 &priv->ucode_key_table))
685 IWL_ERROR("index %d not used in uCode key table.\n",
686 priv->stations[sta_id].sta.key.key_offset);
687 memset(&priv->stations[sta_id].keyinfo, 0,
688 sizeof(struct iwl_hw_key));
689 memset(&priv->stations[sta_id].sta.key, 0,
690 sizeof(struct iwl4965_keyinfo));
691 priv->stations[sta_id].sta.key.key_flags =
692 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
693 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
694 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
695 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
697 IWL_DEBUG_INFO("hwcrypto: clear ucode station key info\n");
698 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
699 spin_unlock_irqrestore(&priv->sta_lock, flags);
702 EXPORT_SYMBOL(iwl_remove_dynamic_key);
704 int iwl_set_dynamic_key(struct iwl_priv *priv,
705 struct ieee80211_key_conf *keyconf, u8 sta_id)
709 priv->key_mapping_key++;
710 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
712 switch (keyconf->alg) {
714 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
717 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
720 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
723 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
729 EXPORT_SYMBOL(iwl_set_dynamic_key);
731 #ifdef CONFIG_IWLWIFI_DEBUG
732 static void iwl_dump_lq_cmd(struct iwl_priv *priv,
733 struct iwl_link_quality_cmd *lq)
736 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
737 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
738 lq->general_params.single_stream_ant_msk,
739 lq->general_params.dual_stream_ant_msk);
741 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
742 IWL_DEBUG_RATE("lq index %d 0x%X\n",
743 i, lq->rs_table[i].rate_n_flags);
746 static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
747 struct iwl_link_quality_cmd *lq)
752 int iwl_send_lq_cmd(struct iwl_priv *priv,
753 struct iwl_link_quality_cmd *lq, u8 flags)
755 struct iwl_host_cmd cmd = {
756 .id = REPLY_TX_LINK_QUALITY_CMD,
757 .len = sizeof(struct iwl_link_quality_cmd),
762 if ((lq->sta_id == 0xFF) &&
763 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
766 if (lq->sta_id == 0xFF)
767 lq->sta_id = IWL_AP_ID;
769 iwl_dump_lq_cmd(priv,lq);
771 if (iwl_is_associated(priv) && priv->assoc_station_added &&
772 priv->lq_mngr.lq_ready)
773 return iwl_send_cmd(priv, &cmd);
777 EXPORT_SYMBOL(iwl_send_lq_cmd);
780 * iwl_sta_init_lq - Initialize a station's hardware rate table
782 * The uCode's station table contains a table of fallback rates
783 * for automatic fallback during transmission.
785 * NOTE: This sets up a default set of values. These will be replaced later
786 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
789 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
790 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
791 * which requires station table entry to exist).
793 static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
796 struct iwl_link_quality_cmd link_cmd = {
801 /* Set up the rate scaling to start at selected rate, fall back
802 * all the way down to 1M in IEEE order, and then spin on 1M */
804 r = IWL_RATE_54M_INDEX;
805 else if (priv->band == IEEE80211_BAND_5GHZ)
806 r = IWL_RATE_6M_INDEX;
808 r = IWL_RATE_1M_INDEX;
810 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
812 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
813 rate_flags |= RATE_MCS_CCK_MSK;
815 /* Use Tx antenna B only */
816 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
818 link_cmd.rs_table[i].rate_n_flags =
819 iwl4965_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
820 r = iwl4965_get_prev_ieee_rate(r);
823 link_cmd.general_params.single_stream_ant_msk = 2;
824 link_cmd.general_params.dual_stream_ant_msk = 3;
825 link_cmd.agg_params.agg_dis_start_th = 3;
826 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
828 /* Update the rate scaling for control frame Tx to AP */
829 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
831 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
832 sizeof(link_cmd), &link_cmd, NULL);
835 * iwl_rxon_add_station - add station into station table.
837 * there is only one AP station with id= IWL_AP_ID
838 * NOTE: mutex must be held before calling this fnction
840 int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
844 /* Add station to device's station table */
845 #ifdef CONFIG_IWL4965_HT
846 struct ieee80211_conf *conf = &priv->hw->conf;
847 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
850 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
851 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
852 sta_id = iwl_add_station_flags(priv, addr, is_ap,
855 #endif /* CONFIG_IWL4965_HT */
856 sta_id = iwl_add_station_flags(priv, addr, is_ap,
859 /* Set up default rate scaling table in device's station table */
860 iwl_sta_init_lq(priv, addr, is_ap);
864 EXPORT_SYMBOL(iwl_rxon_add_station);
868 * iwl_get_sta_id - Find station's index within station table
870 * If new IBSS station, create new entry in station table
872 int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
875 u16 fc = le16_to_cpu(hdr->frame_control);
876 DECLARE_MAC_BUF(mac);
878 /* If this frame is broadcast or management, use broadcast station id */
879 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
880 is_multicast_ether_addr(hdr->addr1))
881 return priv->hw_params.bcast_sta_id;
883 switch (priv->iw_mode) {
885 /* If we are a client station in a BSS network, use the special
886 * AP station entry (that's the only station we communicate with) */
887 case IEEE80211_IF_TYPE_STA:
890 /* If we are an AP, then find the station, or use BCAST */
891 case IEEE80211_IF_TYPE_AP:
892 sta_id = iwl_find_station(priv, hdr->addr1);
893 if (sta_id != IWL_INVALID_STATION)
895 return priv->hw_params.bcast_sta_id;
897 /* If this frame is going out to an IBSS network, find the station,
898 * or create a new station table entry */
899 case IEEE80211_IF_TYPE_IBSS:
900 sta_id = iwl_find_station(priv, hdr->addr1);
901 if (sta_id != IWL_INVALID_STATION)
904 /* Create new station table entry */
905 sta_id = iwl_add_station_flags(priv, hdr->addr1,
908 if (sta_id != IWL_INVALID_STATION)
911 IWL_DEBUG_DROP("Station %s not in station map. "
912 "Defaulting to broadcast...\n",
913 print_mac(mac, hdr->addr1));
914 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
915 return priv->hw_params.bcast_sta_id;
918 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
919 return priv->hw_params.bcast_sta_id;
922 EXPORT_SYMBOL(iwl_get_sta_id);
926 * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
928 void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid)
932 /* Remove "disable" flag, to enable Tx for this TID */
933 spin_lock_irqsave(&priv->sta_lock, flags);
934 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
935 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
936 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
937 spin_unlock_irqrestore(&priv->sta_lock, flags);
939 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
941 EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx);