1 /******************************************************************************
3 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
31 #include "iwl-agn-calib.h"
33 static int iwlagn_disable_bss(struct iwl_priv
*priv
,
34 struct iwl_rxon_context
*ctx
,
35 struct iwl_rxon_cmd
*send
)
37 __le32 old_filter
= send
->filter_flags
;
40 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
41 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
, sizeof(*send
), send
);
43 send
->filter_flags
= old_filter
;
46 IWL_ERR(priv
, "Error clearing ASSOC_MSK on BSS (%d)\n", ret
);
51 static int iwlagn_disable_pan(struct iwl_priv
*priv
,
52 struct iwl_rxon_context
*ctx
,
53 struct iwl_rxon_cmd
*send
)
55 struct iwl_notification_wait disable_wait
;
56 __le32 old_filter
= send
->filter_flags
;
57 u8 old_dev_type
= send
->dev_type
;
60 iwlagn_init_notification_wait(priv
, &disable_wait
, NULL
,
61 REPLY_WIPAN_DEACTIVATION_COMPLETE
);
63 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
64 send
->dev_type
= RXON_DEV_TYPE_P2P
;
65 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
, sizeof(*send
), send
);
67 send
->filter_flags
= old_filter
;
68 send
->dev_type
= old_dev_type
;
71 IWL_ERR(priv
, "Error disabling PAN (%d)\n", ret
);
72 iwlagn_remove_notification(priv
, &disable_wait
);
76 wait_res
= iwlagn_wait_notification(priv
, &disable_wait
, HZ
);
78 IWL_ERR(priv
, "Timed out waiting for PAN disable\n");
86 static void iwlagn_update_qos(struct iwl_priv
*priv
,
87 struct iwl_rxon_context
*ctx
)
94 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
96 if (ctx
->qos_data
.qos_active
)
97 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
98 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
101 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
103 IWL_DEBUG_QOS(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
104 ctx
->qos_data
.qos_active
,
105 ctx
->qos_data
.def_qos_parm
.qos_flags
);
107 ret
= iwl_send_cmd_pdu(priv
, ctx
->qos_cmd
,
108 sizeof(struct iwl_qosparam_cmd
),
109 &ctx
->qos_data
.def_qos_parm
);
111 IWL_ERR(priv
, "Failed to update QoS\n");
114 static int iwlagn_update_beacon(struct iwl_priv
*priv
,
115 struct ieee80211_vif
*vif
)
117 lockdep_assert_held(&priv
->mutex
);
119 dev_kfree_skb(priv
->beacon_skb
);
120 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
121 if (!priv
->beacon_skb
)
123 return iwlagn_send_beacon_cmd(priv
);
127 * iwlagn_commit_rxon - commit staging_rxon to hardware
129 * The RXON command in staging_rxon is committed to the hardware and
130 * the active_rxon structure is updated with the new data. This
131 * function correctly transitions out of the RXON_ASSOC_MSK state if
132 * a HW tune is required based on the RXON structure changes.
134 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
136 /* cast away the const for active_rxon in this function */
137 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
138 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
139 bool old_assoc
= !!(ctx
->active
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
142 lockdep_assert_held(&priv
->mutex
);
144 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
147 if (!iwl_is_alive(priv
))
150 /* This function hardcodes a bunch of dual-mode assumptions */
151 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
156 /* always get timestamp with Rx frame */
157 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
159 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&& priv
->_agn
.hw_roc_channel
) {
160 struct ieee80211_channel
*chan
= priv
->_agn
.hw_roc_channel
;
162 iwl_set_rxon_channel(priv
, chan
, ctx
);
163 iwl_set_flags_for_band(priv
, ctx
, chan
->band
, NULL
);
164 ctx
->staging
.filter_flags
|=
165 RXON_FILTER_ASSOC_MSK
|
166 RXON_FILTER_PROMISC_MSK
|
167 RXON_FILTER_CTL2HOST_MSK
;
168 ctx
->staging
.dev_type
= RXON_DEV_TYPE_P2P
;
171 if (memcmp(&ctx
->staging
, &ctx
->active
,
172 sizeof(ctx
->staging
)) == 0)
177 * force CTS-to-self frames protection if RTS-CTS is not preferred
178 * one aggregation protection method
180 if (!(priv
->cfg
->ht_params
&&
181 priv
->cfg
->ht_params
->use_rts_for_aggregation
))
182 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
184 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
185 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
186 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
188 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
190 ret
= iwl_check_rxon_cmd(priv
, ctx
);
192 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
197 * receive commit_rxon request
198 * abort any previous channel switch if still in process
200 if (priv
->switch_rxon
.switch_in_progress
&&
201 (priv
->switch_rxon
.channel
!= ctx
->staging
.channel
)) {
202 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
203 le16_to_cpu(priv
->switch_rxon
.channel
));
204 iwl_chswitch_done(priv
, false);
208 * If we don't need to send a full RXON, we can use
209 * iwl_rxon_assoc_cmd which is used to reconfigure filter
210 * and other flags for the current radio configuration.
212 if (!iwl_full_rxon_required(priv
, ctx
)) {
213 ret
= iwl_send_rxon_assoc(priv
, ctx
);
215 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
219 memcpy(active
, &ctx
->staging
, sizeof(*active
));
220 iwl_print_rx_config_cmd(priv
, ctx
);
224 if (priv
->cfg
->ops
->hcmd
->set_pan_params
) {
225 ret
= priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);
230 iwl_set_rxon_hwcrypto(priv
, ctx
, !priv
->cfg
->mod_params
->sw_crypto
);
233 "Going to commit RXON\n"
234 " * with%s RXON_FILTER_ASSOC_MSK\n"
237 (new_assoc
? "" : "out"),
238 le16_to_cpu(ctx
->staging
.channel
),
239 ctx
->staging
.bssid_addr
);
242 * Always clear associated first, but with the correct config.
243 * This is required as for example station addition for the
244 * AP station must be done after the BSSID is set to correctly
245 * set up filters in the device.
247 if ((old_assoc
&& new_assoc
) || !new_assoc
) {
248 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
249 ret
= iwlagn_disable_bss(priv
, ctx
, &ctx
->staging
);
251 ret
= iwlagn_disable_pan(priv
, ctx
, &ctx
->staging
);
255 memcpy(active
, &ctx
->staging
, sizeof(*active
));
258 * Un-assoc RXON clears the station table and WEP
259 * keys, so we have to restore those afterwards.
261 iwl_clear_ucode_stations(priv
, ctx
);
262 iwl_restore_stations(priv
, ctx
);
263 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
265 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
270 /* RXON timing must be before associated RXON */
271 ret
= iwl_send_rxon_timing(priv
, ctx
);
273 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
278 /* QoS info may be cleared by previous un-assoc RXON */
279 iwlagn_update_qos(priv
, ctx
);
282 * We'll run into this code path when beaconing is
283 * enabled, but then we also need to send the beacon
286 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
287 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
290 "Error sending required beacon (%d)!\n",
296 priv
->start_calib
= 0;
298 * Apply the new configuration.
300 * Associated RXON doesn't clear the station table in uCode,
301 * so we don't need to restore stations etc. after this.
303 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
304 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
306 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
309 memcpy(active
, &ctx
->staging
, sizeof(*active
));
311 iwl_reprogram_ap_sta(priv
, ctx
);
313 /* IBSS beacon needs to be sent after setting assoc */
314 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
315 if (iwlagn_update_beacon(priv
, ctx
->vif
))
316 IWL_ERR(priv
, "Error sending IBSS beacon\n");
319 iwl_print_rx_config_cmd(priv
, ctx
);
321 iwl_init_sensitivity(priv
);
324 * If we issue a new RXON command which required a tune then we must
325 * send a new TXPOWER command or we won't be able to Tx any frames.
327 * It's expected we set power here if channel is changing.
329 ret
= iwl_set_tx_power(priv
, priv
->tx_power_next
, true);
331 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
338 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
340 struct iwl_priv
*priv
= hw
->priv
;
341 struct iwl_rxon_context
*ctx
;
342 struct ieee80211_conf
*conf
= &hw
->conf
;
343 struct ieee80211_channel
*channel
= conf
->channel
;
344 const struct iwl_channel_info
*ch_info
;
347 IWL_DEBUG_MAC80211(priv
, "changed %#x", changed
);
349 mutex_lock(&priv
->mutex
);
351 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
352 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
356 if (!iwl_is_ready(priv
)) {
357 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
361 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
362 IEEE80211_CONF_CHANGE_CHANNEL
)) {
363 /* mac80211 uses static for non-HT which is what we want */
364 priv
->current_ht_config
.smps
= conf
->smps_mode
;
367 * Recalculate chain counts.
369 * If monitor mode is enabled then mac80211 will
370 * set up the SM PS mode to OFF if an HT channel is
373 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
374 for_each_context(priv
, ctx
)
375 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
378 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
381 ch_info
= iwl_get_channel_info(priv
, channel
->band
,
383 if (!is_channel_valid(ch_info
)) {
384 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
389 spin_lock_irqsave(&priv
->lock
, flags
);
391 for_each_context(priv
, ctx
) {
392 /* Configure HT40 channels */
393 if (ctx
->ht
.enabled
!= conf_is_ht(conf
))
394 ctx
->ht
.enabled
= conf_is_ht(conf
);
396 if (ctx
->ht
.enabled
) {
397 if (conf_is_ht40_minus(conf
)) {
398 ctx
->ht
.extension_chan_offset
=
399 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
400 ctx
->ht
.is_40mhz
= true;
401 } else if (conf_is_ht40_plus(conf
)) {
402 ctx
->ht
.extension_chan_offset
=
403 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
404 ctx
->ht
.is_40mhz
= true;
406 ctx
->ht
.extension_chan_offset
=
407 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
408 ctx
->ht
.is_40mhz
= false;
411 ctx
->ht
.is_40mhz
= false;
414 * Default to no protection. Protection mode will
415 * later be set from BSS config in iwl_ht_conf
417 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
419 /* if we are switching from ht to 2.4 clear flags
420 * from any ht related info since 2.4 does not
422 if (le16_to_cpu(ctx
->staging
.channel
) !=
424 ctx
->staging
.flags
= 0;
426 iwl_set_rxon_channel(priv
, channel
, ctx
);
427 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
429 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
433 spin_unlock_irqrestore(&priv
->lock
, flags
);
435 iwl_update_bcast_stations(priv
);
438 * The list of supported rates and rate mask can be different
439 * for each band; since the band may have changed, reset
440 * the rate mask to what mac80211 lists.
445 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
446 IEEE80211_CONF_CHANGE_IDLE
)) {
447 ret
= iwl_power_update_mode(priv
, false);
449 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
452 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
453 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
454 priv
->tx_power_user_lmt
, conf
->power_level
);
456 iwl_set_tx_power(priv
, conf
->power_level
, false);
459 for_each_context(priv
, ctx
) {
460 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
462 iwlagn_commit_rxon(priv
, ctx
);
465 mutex_unlock(&priv
->mutex
);
469 static void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
470 struct iwl_rxon_context
*ctx
,
471 struct ieee80211_bss_conf
*bss_conf
)
473 struct ieee80211_vif
*vif
= ctx
->vif
;
474 struct iwl_rxon_context
*tmp
;
475 struct ieee80211_sta
*sta
;
476 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
477 struct ieee80211_sta_ht_cap
*ht_cap
;
480 lockdep_assert_held(&priv
->mutex
);
483 case NL80211_IFTYPE_STATION
:
485 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
488 * If at all, this can only happen through a race
489 * when the AP disconnects us while we're still
490 * setting up the connection, in that case mac80211
491 * will soon tell us about that.
493 need_multiple
= false;
498 ht_cap
= &sta
->ht_cap
;
500 need_multiple
= true;
503 * If the peer advertises no support for receiving 2 and 3
504 * stream MCS rates, it can't be transmitting them either.
506 if (ht_cap
->mcs
.rx_mask
[1] == 0 &&
507 ht_cap
->mcs
.rx_mask
[2] == 0) {
508 need_multiple
= false;
509 } else if (!(ht_cap
->mcs
.tx_params
&
510 IEEE80211_HT_MCS_TX_DEFINED
)) {
511 /* If it can't TX MCS at all ... */
512 need_multiple
= false;
513 } else if (ht_cap
->mcs
.tx_params
&
514 IEEE80211_HT_MCS_TX_RX_DIFF
) {
518 * But if it can receive them, it might still not
519 * be able to transmit them, which is what we need
520 * to check here -- so check the number of streams
521 * it advertises for TX (if different from RX).
524 maxstreams
= (ht_cap
->mcs
.tx_params
&
525 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
);
527 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
531 need_multiple
= false;
536 case NL80211_IFTYPE_ADHOC
:
538 need_multiple
= false;
542 need_multiple
= true;
546 ctx
->ht_need_multiple_chains
= need_multiple
;
548 if (!need_multiple
) {
549 /* check all contexts */
550 for_each_context(priv
, tmp
) {
553 if (tmp
->ht_need_multiple_chains
) {
554 need_multiple
= true;
560 ht_conf
->single_chain_sufficient
= !need_multiple
;
563 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
564 struct ieee80211_vif
*vif
,
565 struct ieee80211_bss_conf
*bss_conf
,
568 struct iwl_priv
*priv
= hw
->priv
;
569 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
573 mutex_lock(&priv
->mutex
);
575 if (unlikely(!iwl_is_ready(priv
))) {
576 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
577 mutex_unlock(&priv
->mutex
);
581 if (unlikely(!ctx
->vif
)) {
582 IWL_DEBUG_MAC80211(priv
, "leave - vif is NULL\n");
583 mutex_unlock(&priv
->mutex
);
587 if (changes
& BSS_CHANGED_BEACON_INT
)
590 if (changes
& BSS_CHANGED_QOS
) {
591 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
592 iwlagn_update_qos(priv
, ctx
);
595 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
596 if (vif
->bss_conf
.use_short_preamble
)
597 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
599 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
601 if (changes
& BSS_CHANGED_ASSOC
) {
602 if (bss_conf
->assoc
) {
603 priv
->timestamp
= bss_conf
->timestamp
;
604 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
606 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
610 if (ctx
->ht
.enabled
) {
611 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
612 IEEE80211_HT_OP_MODE_PROTECTION
;
613 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
614 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
615 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
616 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
619 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
620 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
622 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
623 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
625 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
627 if (bss_conf
->use_cts_prot
)
628 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
630 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
632 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
634 if (vif
->type
== NL80211_IFTYPE_AP
||
635 vif
->type
== NL80211_IFTYPE_ADHOC
) {
636 if (vif
->bss_conf
.enable_beacon
) {
637 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
638 priv
->beacon_ctx
= ctx
;
640 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
641 priv
->beacon_ctx
= NULL
;
645 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
646 iwlagn_commit_rxon(priv
, ctx
);
648 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
650 * The chain noise calibration will enable PM upon
651 * completion. If calibration has already been run
652 * then we need to enable power management here.
654 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
655 iwl_power_update_mode(priv
, false);
657 /* Enable RX differential gain and sensitivity calibrations */
658 iwl_chain_noise_reset(priv
);
659 priv
->start_calib
= 1;
662 if (changes
& BSS_CHANGED_IBSS
) {
663 ret
= iwlagn_manage_ibss_station(priv
, vif
,
664 bss_conf
->ibss_joined
);
666 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
667 bss_conf
->ibss_joined
? "add" : "remove",
671 if (changes
& BSS_CHANGED_BEACON
&& vif
->type
== NL80211_IFTYPE_ADHOC
&&
673 if (iwlagn_update_beacon(priv
, vif
))
674 IWL_ERR(priv
, "Error sending IBSS beacon\n");
677 mutex_unlock(&priv
->mutex
);
680 void iwlagn_post_scan(struct iwl_priv
*priv
)
682 struct iwl_rxon_context
*ctx
;
685 * Since setting the RXON may have been deferred while
686 * performing the scan, fire one off if needed
688 for_each_context(priv
, ctx
)
689 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
690 iwlagn_commit_rxon(priv
, ctx
);
692 if (priv
->cfg
->ops
->hcmd
->set_pan_params
)
693 priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);