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 static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
160 struct ieee80211_ht_info *sta_ht_inf)
165 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
168 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
170 sta_flags = priv->stations[index].sta.station_flags;
172 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
174 switch (mimo_ps_mode) {
175 case WLAN_HT_CAP_MIMO_PS_STATIC:
176 sta_flags |= STA_FLG_MIMO_DIS_MSK;
178 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
179 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
181 case WLAN_HT_CAP_MIMO_PS_DISABLED:
184 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
188 sta_flags |= cpu_to_le32(
189 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
191 sta_flags |= cpu_to_le32(
192 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
194 if (iwl_is_fat_tx_allowed(priv, sta_ht_inf))
195 sta_flags |= STA_FLG_FAT_EN_MSK;
197 sta_flags &= ~STA_FLG_FAT_EN_MSK;
199 priv->stations[index].sta.station_flags = sta_flags;
205 * iwl_add_station_flags - Add station to tables in driver and device
207 u8 iwl_add_station_flags(struct iwl_priv *priv, const u8 *addr, int is_ap,
208 u8 flags, struct ieee80211_ht_info *ht_info)
211 int index = IWL_INVALID_STATION;
212 struct iwl_station_entry *station;
213 unsigned long flags_spin;
214 DECLARE_MAC_BUF(mac);
216 spin_lock_irqsave(&priv->sta_lock, flags_spin);
219 else if (is_broadcast_ether_addr(addr))
220 index = priv->hw_params.bcast_sta_id;
222 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
223 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
229 if (!priv->stations[i].used &&
230 index == IWL_INVALID_STATION)
235 /* These two conditions have the same outcome, but keep them separate
236 since they have different meanings */
237 if (unlikely(index == IWL_INVALID_STATION)) {
238 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
242 if (priv->stations[index].used &&
243 !compare_ether_addr(priv->stations[index].sta.sta.addr, addr)) {
244 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
249 IWL_DEBUG_ASSOC("Add STA ID %d: %s\n", index, print_mac(mac, addr));
250 station = &priv->stations[index];
252 priv->num_stations++;
254 /* Set up the REPLY_ADD_STA command to send to device */
255 memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd));
256 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
257 station->sta.mode = 0;
258 station->sta.sta.sta_id = index;
259 station->sta.station_flags = 0;
261 /* BCAST station and IBSS stations do not work in HT mode */
262 if (index != priv->hw_params.bcast_sta_id &&
263 priv->iw_mode != IEEE80211_IF_TYPE_IBSS)
264 iwl_set_ht_add_station(priv, index, ht_info);
266 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
268 /* Add station to device's station table */
269 iwl_send_add_sta(priv, &station->sta, flags);
273 EXPORT_SYMBOL(iwl_add_station_flags);
276 static int iwl_sta_ucode_deactivate(struct iwl_priv *priv, const char *addr)
280 DECLARE_MAC_BUF(mac);
282 sta_id = iwl_find_station(priv, addr);
283 if (sta_id != IWL_INVALID_STATION) {
284 IWL_DEBUG_ASSOC("Removed STA from Ucode: %s\n",
285 print_mac(mac, addr));
286 spin_lock_irqsave(&priv->sta_lock, flags);
287 priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE;
288 memset(&priv->stations[sta_id], 0,
289 sizeof(struct iwl_station_entry));
290 spin_unlock_irqrestore(&priv->sta_lock, flags);
296 static int iwl_remove_sta_callback(struct iwl_priv *priv,
297 struct iwl_cmd *cmd, struct sk_buff *skb)
299 struct iwl_rx_packet *res = NULL;
300 const char *addr = cmd->cmd.rm_sta.addr;
303 IWL_ERROR("Error: Response NULL in REPLY_REMOVE_STA.\n");
307 res = (struct iwl_rx_packet *)skb->data;
308 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
309 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
314 switch (res->u.rem_sta.status) {
315 case REM_STA_SUCCESS_MSK:
316 iwl_sta_ucode_deactivate(priv, addr);
322 /* We didn't cache the SKB; let the caller free it */
326 static int iwl_send_remove_station(struct iwl_priv *priv, const u8 *addr,
329 struct iwl_rx_packet *res = NULL;
332 struct iwl_rem_sta_cmd rm_sta_cmd;
334 struct iwl_host_cmd cmd = {
335 .id = REPLY_REMOVE_STA,
336 .len = sizeof(struct iwl_rem_sta_cmd),
341 memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd));
342 rm_sta_cmd.num_sta = 1;
343 memcpy(&rm_sta_cmd.addr, addr , ETH_ALEN);
345 if (flags & CMD_ASYNC)
346 cmd.meta.u.callback = iwl_remove_sta_callback;
348 cmd.meta.flags |= CMD_WANT_SKB;
349 ret = iwl_send_cmd(priv, &cmd);
351 if (ret || (flags & CMD_ASYNC))
354 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
355 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
356 IWL_ERROR("Bad return from REPLY_REMOVE_STA (0x%08X)\n",
362 switch (res->u.rem_sta.status) {
363 case REM_STA_SUCCESS_MSK:
364 iwl_sta_ucode_deactivate(priv, addr);
365 IWL_DEBUG_ASSOC("REPLY_REMOVE_STA PASSED\n");
369 IWL_ERROR("REPLY_REMOVE_STA failed\n");
374 priv->alloc_rxb_skb--;
375 dev_kfree_skb_any(cmd.meta.u.skb);
380 * iwl_remove_station - Remove driver's knowledge of station.
383 u8 iwl_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
385 int index = IWL_INVALID_STATION;
389 spin_lock_irqsave(&priv->sta_lock, flags);
393 else if (is_broadcast_ether_addr(addr))
394 index = priv->hw_params.bcast_sta_id;
396 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
397 if (priv->stations[i].used &&
398 !compare_ether_addr(priv->stations[i].sta.sta.addr,
404 if (unlikely(index == IWL_INVALID_STATION))
407 if (priv->stations[index].used) {
408 priv->stations[index].used = 0;
409 priv->num_stations--;
412 BUG_ON(priv->num_stations < 0);
413 spin_unlock_irqrestore(&priv->sta_lock, flags);
414 iwl_send_remove_station(priv, addr, CMD_ASYNC);
417 spin_unlock_irqrestore(&priv->sta_lock, flags);
420 EXPORT_SYMBOL(iwl_remove_station);
421 int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
425 for (i = 0; i < STA_KEY_MAX_NUM; i++)
426 if (!test_and_set_bit(i, &priv->ucode_key_table))
432 int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
434 int i, not_empty = 0;
435 u8 buff[sizeof(struct iwl_wep_cmd) +
436 sizeof(struct iwl_wep_key) * WEP_KEYS_MAX];
437 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
438 size_t cmd_size = sizeof(struct iwl_wep_cmd);
439 struct iwl_host_cmd cmd = {
442 .meta.flags = CMD_ASYNC,
445 memset(wep_cmd, 0, cmd_size +
446 (sizeof(struct iwl_wep_key) * WEP_KEYS_MAX));
448 for (i = 0; i < WEP_KEYS_MAX ; i++) {
449 wep_cmd->key[i].key_index = i;
450 if (priv->wep_keys[i].key_size) {
451 wep_cmd->key[i].key_offset = i;
454 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
457 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size;
458 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key,
459 priv->wep_keys[i].key_size);
462 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
463 wep_cmd->num_keys = WEP_KEYS_MAX;
465 cmd_size += sizeof(struct iwl_wep_key) * WEP_KEYS_MAX;
469 if (not_empty || send_if_empty)
470 return iwl_send_cmd(priv, &cmd);
474 EXPORT_SYMBOL(iwl_send_static_wepkey_cmd);
476 int iwl_remove_default_wep_key(struct iwl_priv *priv,
477 struct ieee80211_key_conf *keyconf)
482 spin_lock_irqsave(&priv->sta_lock, flags);
484 if (!test_and_clear_bit(keyconf->keyidx, &priv->ucode_key_table))
485 IWL_ERROR("index %d not used in uCode key table.\n",
488 priv->default_wep_key--;
489 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0]));
490 ret = iwl_send_static_wepkey_cmd(priv, 1);
491 IWL_DEBUG_WEP("Remove default WEP key: idx=%d ret=%d\n",
492 keyconf->keyidx, ret);
493 spin_unlock_irqrestore(&priv->sta_lock, flags);
497 EXPORT_SYMBOL(iwl_remove_default_wep_key);
499 int iwl_set_default_wep_key(struct iwl_priv *priv,
500 struct ieee80211_key_conf *keyconf)
505 if (keyconf->keylen != WEP_KEY_LEN_128 &&
506 keyconf->keylen != WEP_KEY_LEN_64) {
507 IWL_DEBUG_WEP("Bad WEP key length %d\n", keyconf->keylen);
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 IWL_DEBUG_WEP("Set default WEP key: len=%d idx=%d ret=%d\n",
528 keyconf->keylen, keyconf->keyidx, ret);
529 spin_unlock_irqrestore(&priv->sta_lock, flags);
533 EXPORT_SYMBOL(iwl_set_default_wep_key);
535 static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
536 struct ieee80211_key_conf *keyconf,
540 __le16 key_flags = 0;
543 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
545 key_flags |= (STA_KEY_FLG_WEP | STA_KEY_FLG_MAP_KEY_MSK);
546 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
547 key_flags &= ~STA_KEY_FLG_INVALID;
549 if (keyconf->keylen == WEP_KEY_LEN_128)
550 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
552 if (sta_id == priv->hw_params.bcast_sta_id)
553 key_flags |= STA_KEY_MULTICAST_MSK;
555 spin_lock_irqsave(&priv->sta_lock, flags);
557 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
558 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
559 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
561 memcpy(priv->stations[sta_id].keyinfo.key,
562 keyconf->key, keyconf->keylen);
564 memcpy(&priv->stations[sta_id].sta.key.key[3],
565 keyconf->key, keyconf->keylen);
567 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
568 == STA_KEY_FLG_NO_ENC)
569 priv->stations[sta_id].sta.key.key_offset =
570 iwl_get_free_ucode_key_index(priv);
571 /* else, we are overriding an existing key => no need to allocated room
574 priv->stations[sta_id].sta.key.key_flags = key_flags;
575 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
576 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
578 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
580 spin_unlock_irqrestore(&priv->sta_lock, flags);
585 static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
586 struct ieee80211_key_conf *keyconf,
590 __le16 key_flags = 0;
592 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
593 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
594 key_flags &= ~STA_KEY_FLG_INVALID;
596 if (sta_id == priv->hw_params.bcast_sta_id)
597 key_flags |= STA_KEY_MULTICAST_MSK;
599 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
601 spin_lock_irqsave(&priv->sta_lock, flags);
602 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
603 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
605 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
608 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key,
611 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
612 == STA_KEY_FLG_NO_ENC)
613 priv->stations[sta_id].sta.key.key_offset =
614 iwl_get_free_ucode_key_index(priv);
615 /* else, we are overriding an existing key => no need to allocated room
618 priv->stations[sta_id].sta.key.key_flags = key_flags;
619 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
620 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
622 spin_unlock_irqrestore(&priv->sta_lock, flags);
624 IWL_DEBUG_INFO("hwcrypto: modify ucode station key info\n");
625 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
628 static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
629 struct ieee80211_key_conf *keyconf,
635 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
636 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
638 spin_lock_irqsave(&priv->sta_lock, flags);
640 priv->stations[sta_id].keyinfo.alg = keyconf->alg;
641 priv->stations[sta_id].keyinfo.keylen = 16;
643 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
644 == STA_KEY_FLG_NO_ENC)
645 priv->stations[sta_id].sta.key.key_offset =
646 iwl_get_free_ucode_key_index(priv);
647 /* else, we are overriding an existing key => no need to allocated room
650 /* This copy is acutally not needed: we get the key with each TX */
651 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 16);
653 memcpy(priv->stations[sta_id].sta.key.key, keyconf->key, 16);
655 spin_unlock_irqrestore(&priv->sta_lock, flags);
660 int iwl_remove_dynamic_key(struct iwl_priv *priv,
661 struct ieee80211_key_conf *keyconf,
669 priv->key_mapping_key--;
671 spin_lock_irqsave(&priv->sta_lock, flags);
672 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
673 keyidx = (key_flags >> STA_KEY_FLG_KEYID_POS) & 0x3;
675 IWL_DEBUG_WEP("Remove dynamic key: idx=%d sta=%d\n",
676 keyconf->keyidx, sta_id);
678 if (keyconf->keyidx != keyidx) {
679 /* We need to remove a key with index different that the one
680 * in the uCode. This means that the key we need to remove has
681 * been replaced by another one with different index.
682 * Don't do anything and return ok
684 spin_unlock_irqrestore(&priv->sta_lock, flags);
688 if (!test_and_clear_bit(priv->stations[sta_id].sta.key.key_offset,
689 &priv->ucode_key_table))
690 IWL_ERROR("index %d not used in uCode key table.\n",
691 priv->stations[sta_id].sta.key.key_offset);
692 memset(&priv->stations[sta_id].keyinfo, 0,
693 sizeof(struct iwl_hw_key));
694 memset(&priv->stations[sta_id].sta.key, 0,
695 sizeof(struct iwl4965_keyinfo));
696 priv->stations[sta_id].sta.key.key_flags =
697 STA_KEY_FLG_NO_ENC | STA_KEY_FLG_INVALID;
698 priv->stations[sta_id].sta.key.key_offset = WEP_INVALID_OFFSET;
699 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
700 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
702 ret = iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
703 spin_unlock_irqrestore(&priv->sta_lock, flags);
706 EXPORT_SYMBOL(iwl_remove_dynamic_key);
708 int iwl_set_dynamic_key(struct iwl_priv *priv,
709 struct ieee80211_key_conf *keyconf, u8 sta_id)
713 priv->key_mapping_key++;
714 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
716 switch (keyconf->alg) {
718 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
721 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
724 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id);
727 IWL_ERROR("Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
731 IWL_DEBUG_WEP("Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
732 keyconf->alg, keyconf->keylen, keyconf->keyidx,
737 EXPORT_SYMBOL(iwl_set_dynamic_key);
739 #ifdef CONFIG_IWLWIFI_DEBUG
740 static void iwl_dump_lq_cmd(struct iwl_priv *priv,
741 struct iwl_link_quality_cmd *lq)
744 IWL_DEBUG_RATE("lq station id 0x%x\n", lq->sta_id);
745 IWL_DEBUG_RATE("lq dta 0x%X 0x%X\n",
746 lq->general_params.single_stream_ant_msk,
747 lq->general_params.dual_stream_ant_msk);
749 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
750 IWL_DEBUG_RATE("lq index %d 0x%X\n",
751 i, lq->rs_table[i].rate_n_flags);
754 static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
755 struct iwl_link_quality_cmd *lq)
760 int iwl_send_lq_cmd(struct iwl_priv *priv,
761 struct iwl_link_quality_cmd *lq, u8 flags)
763 struct iwl_host_cmd cmd = {
764 .id = REPLY_TX_LINK_QUALITY_CMD,
765 .len = sizeof(struct iwl_link_quality_cmd),
770 if ((lq->sta_id == 0xFF) &&
771 (priv->iw_mode == IEEE80211_IF_TYPE_IBSS))
774 if (lq->sta_id == 0xFF)
775 lq->sta_id = IWL_AP_ID;
777 iwl_dump_lq_cmd(priv,lq);
779 if (iwl_is_associated(priv) && priv->assoc_station_added &&
780 priv->lq_mngr.lq_ready)
781 return iwl_send_cmd(priv, &cmd);
785 EXPORT_SYMBOL(iwl_send_lq_cmd);
788 * iwl_sta_init_lq - Initialize a station's hardware rate table
790 * The uCode's station table contains a table of fallback rates
791 * for automatic fallback during transmission.
793 * NOTE: This sets up a default set of values. These will be replaced later
794 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
797 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
798 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
799 * which requires station table entry to exist).
801 static void iwl_sta_init_lq(struct iwl_priv *priv, const u8 *addr, int is_ap)
804 struct iwl_link_quality_cmd link_cmd = {
809 /* Set up the rate scaling to start at selected rate, fall back
810 * all the way down to 1M in IEEE order, and then spin on 1M */
812 r = IWL_RATE_54M_INDEX;
813 else if (priv->band == IEEE80211_BAND_5GHZ)
814 r = IWL_RATE_6M_INDEX;
816 r = IWL_RATE_1M_INDEX;
818 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
820 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
821 rate_flags |= RATE_MCS_CCK_MSK;
823 /* Use Tx antenna B only */
824 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
826 link_cmd.rs_table[i].rate_n_flags =
827 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
828 r = iwl4965_get_prev_ieee_rate(r);
831 link_cmd.general_params.single_stream_ant_msk = 2;
832 link_cmd.general_params.dual_stream_ant_msk = 3;
833 link_cmd.agg_params.agg_dis_start_th = 3;
834 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
836 /* Update the rate scaling for control frame Tx to AP */
837 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
839 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
840 sizeof(link_cmd), &link_cmd, NULL);
843 * iwl_rxon_add_station - add station into station table.
845 * there is only one AP station with id= IWL_AP_ID
846 * NOTE: mutex must be held before calling this fnction
848 int iwl_rxon_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
852 /* Add station to device's station table */
853 struct ieee80211_conf *conf = &priv->hw->conf;
854 struct ieee80211_ht_info *cur_ht_config = &conf->ht_conf;
857 (conf->flags & IEEE80211_CONF_SUPPORT_HT_MODE) &&
858 (priv->iw_mode == IEEE80211_IF_TYPE_STA))
859 sta_id = iwl_add_station_flags(priv, addr, is_ap,
862 sta_id = iwl_add_station_flags(priv, addr, is_ap,
865 /* Set up default rate scaling table in device's station table */
866 iwl_sta_init_lq(priv, addr, is_ap);
870 EXPORT_SYMBOL(iwl_rxon_add_station);
874 * iwl_get_sta_id - Find station's index within station table
876 * If new IBSS station, create new entry in station table
878 int iwl_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
881 u16 fc = le16_to_cpu(hdr->frame_control);
882 DECLARE_MAC_BUF(mac);
884 /* If this frame is broadcast or management, use broadcast station id */
885 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
886 is_multicast_ether_addr(hdr->addr1))
887 return priv->hw_params.bcast_sta_id;
889 switch (priv->iw_mode) {
891 /* If we are a client station in a BSS network, use the special
892 * AP station entry (that's the only station we communicate with) */
893 case IEEE80211_IF_TYPE_STA:
896 /* If we are an AP, then find the station, or use BCAST */
897 case IEEE80211_IF_TYPE_AP:
898 sta_id = iwl_find_station(priv, hdr->addr1);
899 if (sta_id != IWL_INVALID_STATION)
901 return priv->hw_params.bcast_sta_id;
903 /* If this frame is going out to an IBSS network, find the station,
904 * or create a new station table entry */
905 case IEEE80211_IF_TYPE_IBSS:
906 sta_id = iwl_find_station(priv, hdr->addr1);
907 if (sta_id != IWL_INVALID_STATION)
910 /* Create new station table entry */
911 sta_id = iwl_add_station_flags(priv, hdr->addr1,
914 if (sta_id != IWL_INVALID_STATION)
917 IWL_DEBUG_DROP("Station %s not in station map. "
918 "Defaulting to broadcast...\n",
919 print_mac(mac, hdr->addr1));
920 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
921 return priv->hw_params.bcast_sta_id;
924 IWL_WARNING("Unknown mode of operation: %d", priv->iw_mode);
925 return priv->hw_params.bcast_sta_id;
928 EXPORT_SYMBOL(iwl_get_sta_id);
932 * iwl_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
934 void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv, int sta_id, int tid)
938 /* Remove "disable" flag, to enable Tx for this TID */
939 spin_lock_irqsave(&priv->sta_lock, flags);
940 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
941 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
942 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
943 spin_unlock_irqrestore(&priv->sta_lock, flags);
945 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
947 EXPORT_SYMBOL(iwl_sta_modify_enable_tid_tx);