aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/iwlwifi/iwl-sta.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/iwlwifi/iwl-sta.c')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c224
1 files changed, 132 insertions, 92 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index 7e0829be5e78..6edd0341dfe2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -172,12 +172,14 @@ int iwl_send_add_sta(struct iwl_priv *priv,
172EXPORT_SYMBOL(iwl_send_add_sta); 172EXPORT_SYMBOL(iwl_send_add_sta);
173 173
174static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, 174static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
175 struct ieee80211_sta_ht_cap *sta_ht_inf) 175 struct ieee80211_sta *sta,
176 struct iwl_rxon_context *ctx)
176{ 177{
178 struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap;
177 __le32 sta_flags; 179 __le32 sta_flags;
178 u8 mimo_ps_mode; 180 u8 mimo_ps_mode;
179 181
180 if (!sta_ht_inf || !sta_ht_inf->ht_supported) 182 if (!sta || !sta_ht_inf->ht_supported)
181 goto done; 183 goto done;
182 184
183 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; 185 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
@@ -211,7 +213,7 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
211 sta_flags |= cpu_to_le32( 213 sta_flags |= cpu_to_le32(
212 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); 214 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
213 215
214 if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf)) 216 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
215 sta_flags |= STA_FLG_HT40_EN_MSK; 217 sta_flags |= STA_FLG_HT40_EN_MSK;
216 else 218 else
217 sta_flags &= ~STA_FLG_HT40_EN_MSK; 219 sta_flags &= ~STA_FLG_HT40_EN_MSK;
@@ -226,9 +228,9 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
226 * 228 *
227 * should be called with sta_lock held 229 * should be called with sta_lock held
228 */ 230 */
229static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, 231static u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
230 bool is_ap, 232 const u8 *addr, bool is_ap,
231 struct ieee80211_sta_ht_cap *ht_info) 233 struct ieee80211_sta *sta)
232{ 234{
233 struct iwl_station_entry *station; 235 struct iwl_station_entry *station;
234 int i; 236 int i;
@@ -236,9 +238,9 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
236 u16 rate; 238 u16 rate;
237 239
238 if (is_ap) 240 if (is_ap)
239 sta_id = IWL_AP_ID; 241 sta_id = ctx->ap_sta_id;
240 else if (is_broadcast_ether_addr(addr)) 242 else if (is_broadcast_ether_addr(addr))
241 sta_id = priv->hw_params.bcast_sta_id; 243 sta_id = ctx->bcast_sta_id;
242 else 244 else
243 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { 245 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
244 if (!compare_ether_addr(priv->stations[i].sta.sta.addr, 246 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
@@ -289,14 +291,22 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
289 memcpy(station->sta.sta.addr, addr, ETH_ALEN); 291 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
290 station->sta.mode = 0; 292 station->sta.mode = 0;
291 station->sta.sta.sta_id = sta_id; 293 station->sta.sta.sta_id = sta_id;
292 station->sta.station_flags = 0; 294 station->sta.station_flags = ctx->station_flags;
295 station->ctxid = ctx->ctxid;
296
297 if (sta) {
298 struct iwl_station_priv_common *sta_priv;
299
300 sta_priv = (void *)sta->drv_priv;
301 sta_priv->ctx = ctx;
302 }
293 303
294 /* 304 /*
295 * OK to call unconditionally, since local stations (IBSS BSSID 305 * OK to call unconditionally, since local stations (IBSS BSSID
296 * STA and broadcast STA) pass in a NULL ht_info, and mac80211 306 * STA and broadcast STA) pass in a NULL sta, and mac80211
297 * doesn't allow HT IBSS. 307 * doesn't allow HT IBSS.
298 */ 308 */
299 iwl_set_ht_add_station(priv, sta_id, ht_info); 309 iwl_set_ht_add_station(priv, sta_id, sta, ctx);
300 310
301 /* 3945 only */ 311 /* 3945 only */
302 rate = (priv->band == IEEE80211_BAND_5GHZ) ? 312 rate = (priv->band == IEEE80211_BAND_5GHZ) ?
@@ -313,10 +323,9 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
313/** 323/**
314 * iwl_add_station_common - 324 * iwl_add_station_common -
315 */ 325 */
316int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, 326int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
317 bool is_ap, 327 const u8 *addr, bool is_ap,
318 struct ieee80211_sta_ht_cap *ht_info, 328 struct ieee80211_sta *sta, u8 *sta_id_r)
319 u8 *sta_id_r)
320{ 329{
321 unsigned long flags_spin; 330 unsigned long flags_spin;
322 int ret = 0; 331 int ret = 0;
@@ -325,7 +334,7 @@ int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
325 334
326 *sta_id_r = 0; 335 *sta_id_r = 0;
327 spin_lock_irqsave(&priv->sta_lock, flags_spin); 336 spin_lock_irqsave(&priv->sta_lock, flags_spin);
328 sta_id = iwl_prep_station(priv, addr, is_ap, ht_info); 337 sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta);
329 if (sta_id == IWL_INVALID_STATION) { 338 if (sta_id == IWL_INVALID_STATION) {
330 IWL_ERR(priv, "Unable to prepare station %pM for addition\n", 339 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
331 addr); 340 addr);
@@ -377,7 +386,8 @@ static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
377{ 386{
378 int i, r; 387 int i, r;
379 struct iwl_link_quality_cmd *link_cmd; 388 struct iwl_link_quality_cmd *link_cmd;
380 u32 rate_flags; 389 u32 rate_flags = 0;
390 __le32 rate_n_flags;
381 391
382 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL); 392 link_cmd = kzalloc(sizeof(struct iwl_link_quality_cmd), GFP_KERNEL);
383 if (!link_cmd) { 393 if (!link_cmd) {
@@ -391,18 +401,14 @@ static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
391 else 401 else
392 r = IWL_RATE_1M_INDEX; 402 r = IWL_RATE_1M_INDEX;
393 403
394 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { 404 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
395 rate_flags = 0; 405 rate_flags |= RATE_MCS_CCK_MSK;
396 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
397 rate_flags |= RATE_MCS_CCK_MSK;
398 406
399 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) << 407 rate_flags |= first_antenna(priv->hw_params.valid_tx_ant) <<
400 RATE_MCS_ANT_POS; 408 RATE_MCS_ANT_POS;
401 409 rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
402 link_cmd->rs_table[i].rate_n_flags = 410 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++)
403 iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags); 411 link_cmd->rs_table[i].rate_n_flags = rate_n_flags;
404 r = iwl_get_prev_ieee_rate(r);
405 }
406 412
407 link_cmd->general_params.single_stream_ant_msk = 413 link_cmd->general_params.single_stream_ant_msk =
408 first_antenna(priv->hw_params.valid_tx_ant); 414 first_antenna(priv->hw_params.valid_tx_ant);
@@ -431,8 +437,8 @@ static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
431 * 437 *
432 * Function sleeps. 438 * Function sleeps.
433 */ 439 */
434int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs, 440int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
435 u8 *sta_id_r) 441 const u8 *addr, bool init_rs, u8 *sta_id_r)
436{ 442{
437 int ret; 443 int ret;
438 u8 sta_id; 444 u8 sta_id;
@@ -442,7 +448,7 @@ int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
442 if (sta_id_r) 448 if (sta_id_r)
443 *sta_id_r = IWL_INVALID_STATION; 449 *sta_id_r = IWL_INVALID_STATION;
444 450
445 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id); 451 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
446 if (ret) { 452 if (ret) {
447 IWL_ERR(priv, "Unable to add station %pM\n", addr); 453 IWL_ERR(priv, "Unable to add station %pM\n", addr);
448 return ret; 454 return ret;
@@ -464,7 +470,7 @@ int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
464 return -ENOMEM; 470 return -ENOMEM;
465 } 471 }
466 472
467 ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true); 473 ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
468 if (ret) 474 if (ret)
469 IWL_ERR(priv, "Link quality command failed (%d)\n", ret); 475 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
470 476
@@ -616,7 +622,8 @@ EXPORT_SYMBOL_GPL(iwl_remove_station);
616 * other than explicit station management would cause this in 622 * other than explicit station management would cause this in
617 * the ucode, e.g. unassociated RXON. 623 * the ucode, e.g. unassociated RXON.
618 */ 624 */
619void iwl_clear_ucode_stations(struct iwl_priv *priv) 625void iwl_clear_ucode_stations(struct iwl_priv *priv,
626 struct iwl_rxon_context *ctx)
620{ 627{
621 int i; 628 int i;
622 unsigned long flags_spin; 629 unsigned long flags_spin;
@@ -626,6 +633,9 @@ void iwl_clear_ucode_stations(struct iwl_priv *priv)
626 633
627 spin_lock_irqsave(&priv->sta_lock, flags_spin); 634 spin_lock_irqsave(&priv->sta_lock, flags_spin);
628 for (i = 0; i < priv->hw_params.max_stations; i++) { 635 for (i = 0; i < priv->hw_params.max_stations; i++) {
636 if (ctx && ctx->ctxid != priv->stations[i].ctxid)
637 continue;
638
629 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { 639 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
630 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); 640 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
631 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; 641 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
@@ -647,7 +657,7 @@ EXPORT_SYMBOL(iwl_clear_ucode_stations);
647 * 657 *
648 * Function sleeps. 658 * Function sleeps.
649 */ 659 */
650void iwl_restore_stations(struct iwl_priv *priv) 660void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
651{ 661{
652 struct iwl_addsta_cmd sta_cmd; 662 struct iwl_addsta_cmd sta_cmd;
653 struct iwl_link_quality_cmd lq; 663 struct iwl_link_quality_cmd lq;
@@ -665,6 +675,8 @@ void iwl_restore_stations(struct iwl_priv *priv)
665 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); 675 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
666 spin_lock_irqsave(&priv->sta_lock, flags_spin); 676 spin_lock_irqsave(&priv->sta_lock, flags_spin);
667 for (i = 0; i < priv->hw_params.max_stations; i++) { 677 for (i = 0; i < priv->hw_params.max_stations; i++) {
678 if (ctx->ctxid != priv->stations[i].ctxid)
679 continue;
668 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && 680 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
669 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { 681 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
670 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", 682 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
@@ -700,7 +712,7 @@ void iwl_restore_stations(struct iwl_priv *priv)
700 * current LQ command 712 * current LQ command
701 */ 713 */
702 if (send_lq) 714 if (send_lq)
703 iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true); 715 iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true);
704 spin_lock_irqsave(&priv->sta_lock, flags_spin); 716 spin_lock_irqsave(&priv->sta_lock, flags_spin);
705 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; 717 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
706 } 718 }
@@ -718,7 +730,7 @@ int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
718{ 730{
719 int i; 731 int i;
720 732
721 for (i = 0; i < STA_KEY_MAX_NUM; i++) 733 for (i = 0; i < priv->sta_key_max_num; i++)
722 if (!test_and_set_bit(i, &priv->ucode_key_table)) 734 if (!test_and_set_bit(i, &priv->ucode_key_table))
723 return i; 735 return i;
724 736
@@ -726,7 +738,9 @@ int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
726} 738}
727EXPORT_SYMBOL(iwl_get_free_ucode_key_index); 739EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
728 740
729static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) 741static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv,
742 struct iwl_rxon_context *ctx,
743 bool send_if_empty)
730{ 744{
731 int i, not_empty = 0; 745 int i, not_empty = 0;
732 u8 buff[sizeof(struct iwl_wep_cmd) + 746 u8 buff[sizeof(struct iwl_wep_cmd) +
@@ -734,7 +748,7 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
734 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; 748 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
735 size_t cmd_size = sizeof(struct iwl_wep_cmd); 749 size_t cmd_size = sizeof(struct iwl_wep_cmd);
736 struct iwl_host_cmd cmd = { 750 struct iwl_host_cmd cmd = {
737 .id = REPLY_WEPKEY, 751 .id = ctx->wep_key_cmd,
738 .data = wep_cmd, 752 .data = wep_cmd,
739 .flags = CMD_SYNC, 753 .flags = CMD_SYNC,
740 }; 754 };
@@ -746,16 +760,16 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
746 760
747 for (i = 0; i < WEP_KEYS_MAX ; i++) { 761 for (i = 0; i < WEP_KEYS_MAX ; i++) {
748 wep_cmd->key[i].key_index = i; 762 wep_cmd->key[i].key_index = i;
749 if (priv->wep_keys[i].key_size) { 763 if (ctx->wep_keys[i].key_size) {
750 wep_cmd->key[i].key_offset = i; 764 wep_cmd->key[i].key_offset = i;
751 not_empty = 1; 765 not_empty = 1;
752 } else { 766 } else {
753 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; 767 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
754 } 768 }
755 769
756 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; 770 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
757 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, 771 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
758 priv->wep_keys[i].key_size); 772 ctx->wep_keys[i].key_size);
759 } 773 }
760 774
761 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; 775 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
@@ -771,15 +785,17 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
771 return 0; 785 return 0;
772} 786}
773 787
774int iwl_restore_default_wep_keys(struct iwl_priv *priv) 788int iwl_restore_default_wep_keys(struct iwl_priv *priv,
789 struct iwl_rxon_context *ctx)
775{ 790{
776 lockdep_assert_held(&priv->mutex); 791 lockdep_assert_held(&priv->mutex);
777 792
778 return iwl_send_static_wepkey_cmd(priv, 0); 793 return iwl_send_static_wepkey_cmd(priv, ctx, false);
779} 794}
780EXPORT_SYMBOL(iwl_restore_default_wep_keys); 795EXPORT_SYMBOL(iwl_restore_default_wep_keys);
781 796
782int iwl_remove_default_wep_key(struct iwl_priv *priv, 797int iwl_remove_default_wep_key(struct iwl_priv *priv,
798 struct iwl_rxon_context *ctx,
783 struct ieee80211_key_conf *keyconf) 799 struct ieee80211_key_conf *keyconf)
784{ 800{
785 int ret; 801 int ret;
@@ -789,13 +805,13 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv,
789 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", 805 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
790 keyconf->keyidx); 806 keyconf->keyidx);
791 807
792 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); 808 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
793 if (iwl_is_rfkill(priv)) { 809 if (iwl_is_rfkill(priv)) {
794 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); 810 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
795 /* but keys in device are clear anyway so return success */ 811 /* but keys in device are clear anyway so return success */
796 return 0; 812 return 0;
797 } 813 }
798 ret = iwl_send_static_wepkey_cmd(priv, 1); 814 ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
799 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", 815 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
800 keyconf->keyidx, ret); 816 keyconf->keyidx, ret);
801 817
@@ -804,6 +820,7 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv,
804EXPORT_SYMBOL(iwl_remove_default_wep_key); 820EXPORT_SYMBOL(iwl_remove_default_wep_key);
805 821
806int iwl_set_default_wep_key(struct iwl_priv *priv, 822int iwl_set_default_wep_key(struct iwl_priv *priv,
823 struct iwl_rxon_context *ctx,
807 struct ieee80211_key_conf *keyconf) 824 struct ieee80211_key_conf *keyconf)
808{ 825{
809 int ret; 826 int ret;
@@ -818,13 +835,13 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
818 835
819 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 836 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
820 keyconf->hw_key_idx = HW_KEY_DEFAULT; 837 keyconf->hw_key_idx = HW_KEY_DEFAULT;
821 priv->stations[IWL_AP_ID].keyinfo.alg = ALG_WEP; 838 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
822 839
823 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; 840 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
824 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, 841 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
825 keyconf->keylen); 842 keyconf->keylen);
826 843
827 ret = iwl_send_static_wepkey_cmd(priv, 0); 844 ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
828 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", 845 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
829 keyconf->keylen, keyconf->keyidx, ret); 846 keyconf->keylen, keyconf->keyidx, ret);
830 847
@@ -833,8 +850,9 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
833EXPORT_SYMBOL(iwl_set_default_wep_key); 850EXPORT_SYMBOL(iwl_set_default_wep_key);
834 851
835static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, 852static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
836 struct ieee80211_key_conf *keyconf, 853 struct iwl_rxon_context *ctx,
837 u8 sta_id) 854 struct ieee80211_key_conf *keyconf,
855 u8 sta_id)
838{ 856{
839 unsigned long flags; 857 unsigned long flags;
840 __le16 key_flags = 0; 858 __le16 key_flags = 0;
@@ -851,12 +869,12 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
851 if (keyconf->keylen == WEP_KEY_LEN_128) 869 if (keyconf->keylen == WEP_KEY_LEN_128)
852 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; 870 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
853 871
854 if (sta_id == priv->hw_params.bcast_sta_id) 872 if (sta_id == ctx->bcast_sta_id)
855 key_flags |= STA_KEY_MULTICAST_MSK; 873 key_flags |= STA_KEY_MULTICAST_MSK;
856 874
857 spin_lock_irqsave(&priv->sta_lock, flags); 875 spin_lock_irqsave(&priv->sta_lock, flags);
858 876
859 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 877 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
860 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; 878 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
861 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx; 879 priv->stations[sta_id].keyinfo.keyidx = keyconf->keyidx;
862 880
@@ -887,8 +905,9 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
887} 905}
888 906
889static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, 907static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
890 struct ieee80211_key_conf *keyconf, 908 struct iwl_rxon_context *ctx,
891 u8 sta_id) 909 struct ieee80211_key_conf *keyconf,
910 u8 sta_id)
892{ 911{
893 unsigned long flags; 912 unsigned long flags;
894 __le16 key_flags = 0; 913 __le16 key_flags = 0;
@@ -900,13 +919,13 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
900 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 919 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
901 key_flags &= ~STA_KEY_FLG_INVALID; 920 key_flags &= ~STA_KEY_FLG_INVALID;
902 921
903 if (sta_id == priv->hw_params.bcast_sta_id) 922 if (sta_id == ctx->bcast_sta_id)
904 key_flags |= STA_KEY_MULTICAST_MSK; 923 key_flags |= STA_KEY_MULTICAST_MSK;
905 924
906 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 925 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
907 926
908 spin_lock_irqsave(&priv->sta_lock, flags); 927 spin_lock_irqsave(&priv->sta_lock, flags);
909 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 928 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
910 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen; 929 priv->stations[sta_id].keyinfo.keylen = keyconf->keylen;
911 930
912 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key, 931 memcpy(priv->stations[sta_id].keyinfo.key, keyconf->key,
@@ -936,8 +955,9 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
936} 955}
937 956
938static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, 957static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
939 struct ieee80211_key_conf *keyconf, 958 struct iwl_rxon_context *ctx,
940 u8 sta_id) 959 struct ieee80211_key_conf *keyconf,
960 u8 sta_id)
941{ 961{
942 unsigned long flags; 962 unsigned long flags;
943 int ret = 0; 963 int ret = 0;
@@ -947,7 +967,7 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
947 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 967 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
948 key_flags &= ~STA_KEY_FLG_INVALID; 968 key_flags &= ~STA_KEY_FLG_INVALID;
949 969
950 if (sta_id == priv->hw_params.bcast_sta_id) 970 if (sta_id == ctx->bcast_sta_id)
951 key_flags |= STA_KEY_MULTICAST_MSK; 971 key_flags |= STA_KEY_MULTICAST_MSK;
952 972
953 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 973 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
@@ -955,7 +975,7 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
955 975
956 spin_lock_irqsave(&priv->sta_lock, flags); 976 spin_lock_irqsave(&priv->sta_lock, flags);
957 977
958 priv->stations[sta_id].keyinfo.alg = keyconf->alg; 978 priv->stations[sta_id].keyinfo.cipher = keyconf->cipher;
959 priv->stations[sta_id].keyinfo.keylen = 16; 979 priv->stations[sta_id].keyinfo.keylen = 16;
960 980
961 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK) 981 if ((priv->stations[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
@@ -982,8 +1002,9 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
982} 1002}
983 1003
984void iwl_update_tkip_key(struct iwl_priv *priv, 1004void iwl_update_tkip_key(struct iwl_priv *priv,
985 struct ieee80211_key_conf *keyconf, 1005 struct iwl_rxon_context *ctx,
986 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) 1006 struct ieee80211_key_conf *keyconf,
1007 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
987{ 1008{
988 u8 sta_id; 1009 u8 sta_id;
989 unsigned long flags; 1010 unsigned long flags;
@@ -995,7 +1016,7 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
995 return; 1016 return;
996 } 1017 }
997 1018
998 sta_id = iwl_sta_id_or_broadcast(priv, sta); 1019 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
999 if (sta_id == IWL_INVALID_STATION) 1020 if (sta_id == IWL_INVALID_STATION)
1000 return; 1021 return;
1001 1022
@@ -1018,8 +1039,9 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
1018EXPORT_SYMBOL(iwl_update_tkip_key); 1039EXPORT_SYMBOL(iwl_update_tkip_key);
1019 1040
1020int iwl_remove_dynamic_key(struct iwl_priv *priv, 1041int iwl_remove_dynamic_key(struct iwl_priv *priv,
1021 struct ieee80211_key_conf *keyconf, 1042 struct iwl_rxon_context *ctx,
1022 u8 sta_id) 1043 struct ieee80211_key_conf *keyconf,
1044 u8 sta_id)
1023{ 1045{
1024 unsigned long flags; 1046 unsigned long flags;
1025 u16 key_flags; 1047 u16 key_flags;
@@ -1028,7 +1050,7 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
1028 1050
1029 lockdep_assert_held(&priv->mutex); 1051 lockdep_assert_held(&priv->mutex);
1030 1052
1031 priv->key_mapping_key--; 1053 ctx->key_mapping_keys--;
1032 1054
1033 spin_lock_irqsave(&priv->sta_lock, flags); 1055 spin_lock_irqsave(&priv->sta_lock, flags);
1034 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); 1056 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
@@ -1080,34 +1102,36 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
1080} 1102}
1081EXPORT_SYMBOL(iwl_remove_dynamic_key); 1103EXPORT_SYMBOL(iwl_remove_dynamic_key);
1082 1104
1083int iwl_set_dynamic_key(struct iwl_priv *priv, 1105int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1084 struct ieee80211_key_conf *keyconf, u8 sta_id) 1106 struct ieee80211_key_conf *keyconf, u8 sta_id)
1085{ 1107{
1086 int ret; 1108 int ret;
1087 1109
1088 lockdep_assert_held(&priv->mutex); 1110 lockdep_assert_held(&priv->mutex);
1089 1111
1090 priv->key_mapping_key++; 1112 ctx->key_mapping_keys++;
1091 keyconf->hw_key_idx = HW_KEY_DYNAMIC; 1113 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1092 1114
1093 switch (keyconf->alg) { 1115 switch (keyconf->cipher) {
1094 case ALG_CCMP: 1116 case WLAN_CIPHER_SUITE_CCMP:
1095 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); 1117 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
1096 break; 1118 break;
1097 case ALG_TKIP: 1119 case WLAN_CIPHER_SUITE_TKIP:
1098 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); 1120 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
1099 break; 1121 break;
1100 case ALG_WEP: 1122 case WLAN_CIPHER_SUITE_WEP40:
1101 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); 1123 case WLAN_CIPHER_SUITE_WEP104:
1124 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
1102 break; 1125 break;
1103 default: 1126 default:
1104 IWL_ERR(priv, 1127 IWL_ERR(priv,
1105 "Unknown alg: %s alg = %d\n", __func__, keyconf->alg); 1128 "Unknown alg: %s cipher = %x\n", __func__,
1129 keyconf->cipher);
1106 ret = -EINVAL; 1130 ret = -EINVAL;
1107 } 1131 }
1108 1132
1109 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n", 1133 IWL_DEBUG_WEP(priv, "Set dynamic key: cipher=%x len=%d idx=%d sta=%d ret=%d\n",
1110 keyconf->alg, keyconf->keylen, keyconf->keyidx, 1134 keyconf->cipher, keyconf->keylen, keyconf->keyidx,
1111 sta_id, ret); 1135 sta_id, ret);
1112 1136
1113 return ret; 1137 return ret;
@@ -1147,16 +1171,16 @@ static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
1147 * RXON flags are updated and when LQ command is updated. 1171 * RXON flags are updated and when LQ command is updated.
1148 */ 1172 */
1149static bool is_lq_table_valid(struct iwl_priv *priv, 1173static bool is_lq_table_valid(struct iwl_priv *priv,
1174 struct iwl_rxon_context *ctx,
1150 struct iwl_link_quality_cmd *lq) 1175 struct iwl_link_quality_cmd *lq)
1151{ 1176{
1152 int i; 1177 int i;
1153 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1154 1178
1155 if (ht_conf->is_ht) 1179 if (ctx->ht.enabled)
1156 return true; 1180 return true;
1157 1181
1158 IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", 1182 IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n",
1159 priv->active_rxon.channel); 1183 ctx->active.channel);
1160 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { 1184 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1161 if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { 1185 if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) {
1162 IWL_DEBUG_INFO(priv, 1186 IWL_DEBUG_INFO(priv,
@@ -1178,7 +1202,7 @@ static bool is_lq_table_valid(struct iwl_priv *priv,
1178 * this case to clear the state indicating that station creation is in 1202 * this case to clear the state indicating that station creation is in
1179 * progress. 1203 * progress.
1180 */ 1204 */
1181int iwl_send_lq_cmd(struct iwl_priv *priv, 1205int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1182 struct iwl_link_quality_cmd *lq, u8 flags, bool init) 1206 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
1183{ 1207{
1184 int ret = 0; 1208 int ret = 0;
@@ -1197,7 +1221,7 @@ int iwl_send_lq_cmd(struct iwl_priv *priv,
1197 iwl_dump_lq_cmd(priv, lq); 1221 iwl_dump_lq_cmd(priv, lq);
1198 BUG_ON(init && (cmd.flags & CMD_ASYNC)); 1222 BUG_ON(init && (cmd.flags & CMD_ASYNC));
1199 1223
1200 if (is_lq_table_valid(priv, lq)) 1224 if (is_lq_table_valid(priv, ctx, lq))
1201 ret = iwl_send_cmd(priv, &cmd); 1225 ret = iwl_send_cmd(priv, &cmd);
1202 else 1226 else
1203 ret = -EINVAL; 1227 ret = -EINVAL;
@@ -1223,14 +1247,15 @@ EXPORT_SYMBOL(iwl_send_lq_cmd);
1223 * and marks it driver active, so that it will be restored to the 1247 * and marks it driver active, so that it will be restored to the
1224 * device at the next best time. 1248 * device at the next best time.
1225 */ 1249 */
1226int iwl_alloc_bcast_station(struct iwl_priv *priv, bool init_lq) 1250int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1251 bool init_lq)
1227{ 1252{
1228 struct iwl_link_quality_cmd *link_cmd; 1253 struct iwl_link_quality_cmd *link_cmd;
1229 unsigned long flags; 1254 unsigned long flags;
1230 u8 sta_id; 1255 u8 sta_id;
1231 1256
1232 spin_lock_irqsave(&priv->sta_lock, flags); 1257 spin_lock_irqsave(&priv->sta_lock, flags);
1233 sta_id = iwl_prep_station(priv, iwl_bcast_addr, false, NULL); 1258 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
1234 if (sta_id == IWL_INVALID_STATION) { 1259 if (sta_id == IWL_INVALID_STATION) {
1235 IWL_ERR(priv, "Unable to prepare broadcast station\n"); 1260 IWL_ERR(priv, "Unable to prepare broadcast station\n");
1236 spin_unlock_irqrestore(&priv->sta_lock, flags); 1261 spin_unlock_irqrestore(&priv->sta_lock, flags);
@@ -1265,11 +1290,12 @@ EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station);
1265 * Only used by iwlagn. Placed here to have all bcast station management 1290 * Only used by iwlagn. Placed here to have all bcast station management
1266 * code together. 1291 * code together.
1267 */ 1292 */
1268int iwl_update_bcast_station(struct iwl_priv *priv) 1293static int iwl_update_bcast_station(struct iwl_priv *priv,
1294 struct iwl_rxon_context *ctx)
1269{ 1295{
1270 unsigned long flags; 1296 unsigned long flags;
1271 struct iwl_link_quality_cmd *link_cmd; 1297 struct iwl_link_quality_cmd *link_cmd;
1272 u8 sta_id = priv->hw_params.bcast_sta_id; 1298 u8 sta_id = ctx->bcast_sta_id;
1273 1299
1274 link_cmd = iwl_sta_alloc_lq(priv, sta_id); 1300 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1275 if (!link_cmd) { 1301 if (!link_cmd) {
@@ -1287,9 +1313,23 @@ int iwl_update_bcast_station(struct iwl_priv *priv)
1287 1313
1288 return 0; 1314 return 0;
1289} 1315}
1290EXPORT_SYMBOL_GPL(iwl_update_bcast_station);
1291 1316
1292void iwl_dealloc_bcast_station(struct iwl_priv *priv) 1317int iwl_update_bcast_stations(struct iwl_priv *priv)
1318{
1319 struct iwl_rxon_context *ctx;
1320 int ret = 0;
1321
1322 for_each_context(priv, ctx) {
1323 ret = iwl_update_bcast_station(priv, ctx);
1324 if (ret)
1325 break;
1326 }
1327
1328 return ret;
1329}
1330EXPORT_SYMBOL_GPL(iwl_update_bcast_stations);
1331
1332void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
1293{ 1333{
1294 unsigned long flags; 1334 unsigned long flags;
1295 int i; 1335 int i;
@@ -1307,7 +1347,7 @@ void iwl_dealloc_bcast_station(struct iwl_priv *priv)
1307 } 1347 }
1308 spin_unlock_irqrestore(&priv->sta_lock, flags); 1348 spin_unlock_irqrestore(&priv->sta_lock, flags);
1309} 1349}
1310EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_station); 1350EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations);
1311 1351
1312/** 1352/**
1313 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table 1353 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table