blob: 202ef64a14d5ca329e7b507a170d86ad6e516e5b [file] [log] [blame]
Johannes Berg2295c662010-10-23 09:15:41 -07001/******************************************************************************
2 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07003 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
Johannes Berg2295c662010-10-23 09:15:41 -07004 *
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.
8 *
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
12 * more details.
13 *
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
17 *
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
20 *
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
24 *
25 *****************************************************************************/
26
27#include "iwl-dev.h"
28#include "iwl-agn.h"
29#include "iwl-sta.h"
30#include "iwl-core.h"
31#include "iwl-agn-calib.h"
Garen Tamrazian68b99312011-03-30 02:29:32 -070032#include "iwl-helpers.h"
Johannes Berg2295c662010-10-23 09:15:41 -070033
34static int iwlagn_disable_bss(struct iwl_priv *priv,
35 struct iwl_rxon_context *ctx,
36 struct iwl_rxon_cmd *send)
37{
38 __le32 old_filter = send->filter_flags;
39 int ret;
40
41 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
42 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
43
44 send->filter_flags = old_filter;
45
46 if (ret)
47 IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
48
49 return ret;
50}
51
52static int iwlagn_disable_pan(struct iwl_priv *priv,
53 struct iwl_rxon_context *ctx,
54 struct iwl_rxon_cmd *send)
55{
Johannes Berg311dce72011-01-04 16:22:01 -080056 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -070057 __le32 old_filter = send->filter_flags;
58 u8 old_dev_type = send->dev_type;
59 int ret;
60
Johannes Berg09f18af2011-04-13 03:14:47 -070061 iwlagn_init_notification_wait(priv, &disable_wait,
62 REPLY_WIPAN_DEACTIVATION_COMPLETE,
63 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -080064
Johannes Berg2295c662010-10-23 09:15:41 -070065 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
66 send->dev_type = RXON_DEV_TYPE_P2P;
67 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
68
69 send->filter_flags = old_filter;
70 send->dev_type = old_dev_type;
71
Johannes Berg311dce72011-01-04 16:22:01 -080072 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -070073 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg311dce72011-01-04 16:22:01 -080074 iwlagn_remove_notification(priv, &disable_wait);
75 } else {
Johannes Berga8674a12011-04-13 03:14:48 -070076 ret = iwlagn_wait_notification(priv, &disable_wait, HZ);
77 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -080078 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
79 }
Johannes Berg2295c662010-10-23 09:15:41 -070080
81 return ret;
82}
83
Shanyu Zhaof4115d42010-11-10 18:25:58 -080084static void iwlagn_update_qos(struct iwl_priv *priv,
85 struct iwl_rxon_context *ctx)
86{
87 int ret;
88
89 if (!ctx->is_active)
90 return;
91
92 ctx->qos_data.def_qos_parm.qos_flags = 0;
93
94 if (ctx->qos_data.qos_active)
95 ctx->qos_data.def_qos_parm.qos_flags |=
96 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
97
98 if (ctx->ht.enabled)
99 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
100
101 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
102 ctx->qos_data.qos_active,
103 ctx->qos_data.def_qos_parm.qos_flags);
104
105 ret = iwl_send_cmd_pdu(priv, ctx->qos_cmd,
106 sizeof(struct iwl_qosparam_cmd),
107 &ctx->qos_data.def_qos_parm);
108 if (ret)
109 IWL_ERR(priv, "Failed to update QoS\n");
110}
111
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700112static int iwlagn_update_beacon(struct iwl_priv *priv,
113 struct ieee80211_vif *vif)
114{
115 lockdep_assert_held(&priv->mutex);
116
117 dev_kfree_skb(priv->beacon_skb);
118 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
119 if (!priv->beacon_skb)
120 return -ENOMEM;
121 return iwlagn_send_beacon_cmd(priv);
122}
123
Johannes Berg2295c662010-10-23 09:15:41 -0700124/**
125 * iwlagn_commit_rxon - commit staging_rxon to hardware
126 *
127 * The RXON command in staging_rxon is committed to the hardware and
128 * the active_rxon structure is updated with the new data. This
129 * function correctly transitions out of the RXON_ASSOC_MSK state if
130 * a HW tune is required based on the RXON structure changes.
131 */
132int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
133{
134 /* cast away the const for active_rxon in this function */
135 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -0700136 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800137 bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
Johannes Berg2295c662010-10-23 09:15:41 -0700138 int ret;
139
140 lockdep_assert_held(&priv->mutex);
141
Wey-Yi Guyadb90a02010-11-26 11:09:42 -0800142 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
143 return -EINVAL;
144
Johannes Berg2295c662010-10-23 09:15:41 -0700145 if (!iwl_is_alive(priv))
146 return -EBUSY;
147
148 /* This function hardcodes a bunch of dual-mode assumptions */
149 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
150
151 if (!ctx->is_active)
152 return 0;
153
154 /* always get timestamp with Rx frame */
155 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
156
Johannes Berg9b9190d2011-01-06 08:07:10 -0800157 if (ctx->ctxid == IWL_RXON_CTX_PAN && priv->_agn.hw_roc_channel) {
158 struct ieee80211_channel *chan = priv->_agn.hw_roc_channel;
159
160 iwl_set_rxon_channel(priv, chan, ctx);
161 iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
162 ctx->staging.filter_flags |=
163 RXON_FILTER_ASSOC_MSK |
164 RXON_FILTER_PROMISC_MSK |
165 RXON_FILTER_CTL2HOST_MSK;
166 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
167 new_assoc = true;
168
169 if (memcmp(&ctx->staging, &ctx->active,
170 sizeof(ctx->staging)) == 0)
171 return 0;
172 }
173
Johannes Berg2295c662010-10-23 09:15:41 -0700174 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
175 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
176 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
177 else
178 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
179
180 ret = iwl_check_rxon_cmd(priv, ctx);
181 if (ret) {
182 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
183 return -EINVAL;
184 }
185
186 /*
187 * receive commit_rxon request
188 * abort any previous channel switch if still in process
189 */
190 if (priv->switch_rxon.switch_in_progress &&
191 (priv->switch_rxon.channel != ctx->staging.channel)) {
192 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
193 le16_to_cpu(priv->switch_rxon.channel));
194 iwl_chswitch_done(priv, false);
195 }
196
197 /*
198 * If we don't need to send a full RXON, we can use
199 * iwl_rxon_assoc_cmd which is used to reconfigure filter
200 * and other flags for the current radio configuration.
201 */
202 if (!iwl_full_rxon_required(priv, ctx)) {
203 ret = iwl_send_rxon_assoc(priv, ctx);
204 if (ret) {
205 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
206 return ret;
207 }
208
209 memcpy(active, &ctx->staging, sizeof(*active));
210 iwl_print_rx_config_cmd(priv, ctx);
211 return 0;
212 }
213
214 if (priv->cfg->ops->hcmd->set_pan_params) {
215 ret = priv->cfg->ops->hcmd->set_pan_params(priv);
216 if (ret)
217 return ret;
218 }
219
220 iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
221
222 IWL_DEBUG_INFO(priv,
223 "Going to commit RXON\n"
224 " * with%s RXON_FILTER_ASSOC_MSK\n"
225 " * channel = %d\n"
226 " * bssid = %pM\n",
227 (new_assoc ? "" : "out"),
228 le16_to_cpu(ctx->staging.channel),
229 ctx->staging.bssid_addr);
230
231 /*
Johannes Berg52d980c2010-11-10 09:56:45 -0800232 * Always clear associated first, but with the correct config.
233 * This is required as for example station addition for the
234 * AP station must be done after the BSSID is set to correctly
235 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -0700236 */
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800237 if ((old_assoc && new_assoc) || !new_assoc) {
238 if (ctx->ctxid == IWL_RXON_CTX_BSS)
239 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
240 else
241 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
242 if (ret)
243 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -0700244
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800245 memcpy(active, &ctx->staging, sizeof(*active));
Johannes Berg2295c662010-10-23 09:15:41 -0700246
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800247 /*
248 * Un-assoc RXON clears the station table and WEP
249 * keys, so we have to restore those afterwards.
250 */
251 iwl_clear_ucode_stations(priv, ctx);
252 iwl_restore_stations(priv, ctx);
253 ret = iwl_restore_default_wep_keys(priv, ctx);
254 if (ret) {
255 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
256 return ret;
257 }
Johannes Berg2295c662010-10-23 09:15:41 -0700258 }
259
260 /* RXON timing must be before associated RXON */
261 ret = iwl_send_rxon_timing(priv, ctx);
262 if (ret) {
263 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
264 return ret;
265 }
266
267 if (new_assoc) {
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800268 /* QoS info may be cleared by previous un-assoc RXON */
269 iwlagn_update_qos(priv, ctx);
270
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700271 /*
272 * We'll run into this code path when beaconing is
273 * enabled, but then we also need to send the beacon
274 * to the device.
275 */
276 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
277 ret = iwlagn_update_beacon(priv, ctx->vif);
278 if (ret) {
279 IWL_ERR(priv,
280 "Error sending required beacon (%d)!\n",
281 ret);
282 return ret;
283 }
Johannes Berg2295c662010-10-23 09:15:41 -0700284 }
285
286 priv->start_calib = 0;
287 /*
288 * Apply the new configuration.
289 *
290 * Associated RXON doesn't clear the station table in uCode,
291 * so we don't need to restore stations etc. after this.
292 */
293 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
294 sizeof(struct iwl_rxon_cmd), &ctx->staging);
295 if (ret) {
296 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
297 return ret;
298 }
299 memcpy(active, &ctx->staging, sizeof(*active));
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700300
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800301 iwl_reprogram_ap_sta(priv, ctx);
302
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700303 /* IBSS beacon needs to be sent after setting assoc */
304 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
305 if (iwlagn_update_beacon(priv, ctx->vif))
306 IWL_ERR(priv, "Error sending IBSS beacon\n");
Johannes Berg2295c662010-10-23 09:15:41 -0700307 }
308
309 iwl_print_rx_config_cmd(priv, ctx);
310
311 iwl_init_sensitivity(priv);
312
313 /*
314 * If we issue a new RXON command which required a tune then we must
315 * send a new TXPOWER command or we won't be able to Tx any frames.
316 *
Stanislaw Gruszkaf844a702011-01-28 16:47:44 +0100317 * It's expected we set power here if channel is changing.
Johannes Berg2295c662010-10-23 09:15:41 -0700318 */
Stanislaw Gruszkaf844a702011-01-28 16:47:44 +0100319 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
Johannes Berg2295c662010-10-23 09:15:41 -0700320 if (ret) {
321 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
322 return ret;
323 }
324
325 return 0;
326}
327
328int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
329{
330 struct iwl_priv *priv = hw->priv;
331 struct iwl_rxon_context *ctx;
332 struct ieee80211_conf *conf = &hw->conf;
333 struct ieee80211_channel *channel = conf->channel;
334 const struct iwl_channel_info *ch_info;
335 int ret = 0;
336
337 IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
338
339 mutex_lock(&priv->mutex);
340
341 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
342 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
343 goto out;
344 }
345
346 if (!iwl_is_ready(priv)) {
347 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
348 goto out;
349 }
350
351 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
352 IEEE80211_CONF_CHANGE_CHANNEL)) {
353 /* mac80211 uses static for non-HT which is what we want */
354 priv->current_ht_config.smps = conf->smps_mode;
355
356 /*
357 * Recalculate chain counts.
358 *
359 * If monitor mode is enabled then mac80211 will
360 * set up the SM PS mode to OFF if an HT channel is
361 * configured.
362 */
363 if (priv->cfg->ops->hcmd->set_rxon_chain)
364 for_each_context(priv, ctx)
365 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
366 }
367
368 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
369 unsigned long flags;
370
371 ch_info = iwl_get_channel_info(priv, channel->band,
372 channel->hw_value);
373 if (!is_channel_valid(ch_info)) {
374 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
375 ret = -EINVAL;
376 goto out;
377 }
378
379 spin_lock_irqsave(&priv->lock, flags);
380
381 for_each_context(priv, ctx) {
382 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -0700383 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800384 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800385
Johannes Berg2295c662010-10-23 09:15:41 -0700386 if (ctx->ht.enabled) {
387 if (conf_is_ht40_minus(conf)) {
388 ctx->ht.extension_chan_offset =
389 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
390 ctx->ht.is_40mhz = true;
391 } else if (conf_is_ht40_plus(conf)) {
392 ctx->ht.extension_chan_offset =
393 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
394 ctx->ht.is_40mhz = true;
395 } else {
396 ctx->ht.extension_chan_offset =
397 IEEE80211_HT_PARAM_CHA_SEC_NONE;
398 ctx->ht.is_40mhz = false;
399 }
400 } else
401 ctx->ht.is_40mhz = false;
402
403 /*
404 * Default to no protection. Protection mode will
405 * later be set from BSS config in iwl_ht_conf
406 */
407 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
408
409 /* if we are switching from ht to 2.4 clear flags
410 * from any ht related info since 2.4 does not
411 * support ht */
412 if (le16_to_cpu(ctx->staging.channel) !=
413 channel->hw_value)
414 ctx->staging.flags = 0;
415
416 iwl_set_rxon_channel(priv, channel, ctx);
417 iwl_set_rxon_ht(priv, &priv->current_ht_config);
418
419 iwl_set_flags_for_band(priv, ctx, channel->band,
420 ctx->vif);
421 }
422
423 spin_unlock_irqrestore(&priv->lock, flags);
424
425 iwl_update_bcast_stations(priv);
426
427 /*
428 * The list of supported rates and rate mask can be different
429 * for each band; since the band may have changed, reset
430 * the rate mask to what mac80211 lists.
431 */
432 iwl_set_rate(priv);
433 }
434
435 if (changed & (IEEE80211_CONF_CHANGE_PS |
436 IEEE80211_CONF_CHANGE_IDLE)) {
437 ret = iwl_power_update_mode(priv, false);
438 if (ret)
439 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
440 }
441
442 if (changed & IEEE80211_CONF_CHANGE_POWER) {
443 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
444 priv->tx_power_user_lmt, conf->power_level);
445
446 iwl_set_tx_power(priv, conf->power_level, false);
447 }
448
449 for_each_context(priv, ctx) {
450 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
451 continue;
452 iwlagn_commit_rxon(priv, ctx);
453 }
454 out:
455 mutex_unlock(&priv->mutex);
456 return ret;
457}
458
Johannes Berg2295c662010-10-23 09:15:41 -0700459static void iwlagn_check_needed_chains(struct iwl_priv *priv,
460 struct iwl_rxon_context *ctx,
461 struct ieee80211_bss_conf *bss_conf)
462{
463 struct ieee80211_vif *vif = ctx->vif;
464 struct iwl_rxon_context *tmp;
465 struct ieee80211_sta *sta;
466 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +0100467 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -0700468 bool need_multiple;
469
470 lockdep_assert_held(&priv->mutex);
471
472 switch (vif->type) {
473 case NL80211_IFTYPE_STATION:
474 rcu_read_lock();
475 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +0100476 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -0700477 /*
478 * If at all, this can only happen through a race
479 * when the AP disconnects us while we're still
480 * setting up the connection, in that case mac80211
481 * will soon tell us about that.
482 */
483 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +0100484 rcu_read_unlock();
485 break;
Johannes Berg2295c662010-10-23 09:15:41 -0700486 }
Johannes Berg850bedc2011-02-25 12:24:11 +0100487
488 ht_cap = &sta->ht_cap;
489
490 need_multiple = true;
491
492 /*
493 * If the peer advertises no support for receiving 2 and 3
494 * stream MCS rates, it can't be transmitting them either.
495 */
496 if (ht_cap->mcs.rx_mask[1] == 0 &&
497 ht_cap->mcs.rx_mask[2] == 0) {
498 need_multiple = false;
499 } else if (!(ht_cap->mcs.tx_params &
500 IEEE80211_HT_MCS_TX_DEFINED)) {
501 /* If it can't TX MCS at all ... */
502 need_multiple = false;
503 } else if (ht_cap->mcs.tx_params &
504 IEEE80211_HT_MCS_TX_RX_DIFF) {
505 int maxstreams;
506
507 /*
508 * But if it can receive them, it might still not
509 * be able to transmit them, which is what we need
510 * to check here -- so check the number of streams
511 * it advertises for TX (if different from RX).
512 */
513
514 maxstreams = (ht_cap->mcs.tx_params &
515 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
516 maxstreams >>=
517 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
518 maxstreams += 1;
519
520 if (maxstreams <= 1)
521 need_multiple = false;
522 }
523
Johannes Berg2295c662010-10-23 09:15:41 -0700524 rcu_read_unlock();
525 break;
526 case NL80211_IFTYPE_ADHOC:
527 /* currently */
528 need_multiple = false;
529 break;
530 default:
531 /* only AP really */
532 need_multiple = true;
533 break;
534 }
535
536 ctx->ht_need_multiple_chains = need_multiple;
537
538 if (!need_multiple) {
539 /* check all contexts */
540 for_each_context(priv, tmp) {
541 if (!tmp->vif)
542 continue;
543 if (tmp->ht_need_multiple_chains) {
544 need_multiple = true;
545 break;
546 }
547 }
548 }
549
550 ht_conf->single_chain_sufficient = !need_multiple;
551}
552
553void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
554 struct ieee80211_vif *vif,
555 struct ieee80211_bss_conf *bss_conf,
556 u32 changes)
557{
558 struct iwl_priv *priv = hw->priv;
559 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
560 int ret;
561 bool force = false;
562
563 mutex_lock(&priv->mutex);
564
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800565 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -0800566 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
567 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800568 return;
569 }
570
571 if (unlikely(!ctx->vif)) {
572 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Berg893654d2010-11-10 18:25:47 -0800573 mutex_unlock(&priv->mutex);
574 return;
575 }
576
Johannes Berg2295c662010-10-23 09:15:41 -0700577 if (changes & BSS_CHANGED_BEACON_INT)
578 force = true;
579
580 if (changes & BSS_CHANGED_QOS) {
581 ctx->qos_data.qos_active = bss_conf->qos;
582 iwlagn_update_qos(priv, ctx);
583 }
584
585 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
586 if (vif->bss_conf.use_short_preamble)
587 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
588 else
589 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
590
591 if (changes & BSS_CHANGED_ASSOC) {
592 if (bss_conf->assoc) {
Johannes Berg2295c662010-10-23 09:15:41 -0700593 priv->timestamp = bss_conf->timestamp;
594 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
595 } else {
Garen Tamrazian68b99312011-03-30 02:29:32 -0700596 /*
597 * If we disassociate while there are pending
598 * frames, just wake up the queues and let the
599 * frames "escape" ... This shouldn't really
600 * be happening to start with, but we should
601 * not get stuck in this case either since it
602 * can happen if userspace gets confused.
603 */
604 if (ctx->last_tx_rejected) {
605 ctx->last_tx_rejected = false;
606 iwl_wake_any_queue(priv, ctx);
607 }
Johannes Berg2295c662010-10-23 09:15:41 -0700608 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berg2295c662010-10-23 09:15:41 -0700609 }
610 }
611
612 if (ctx->ht.enabled) {
613 ctx->ht.protection = bss_conf->ht_operation_mode &
614 IEEE80211_HT_OP_MODE_PROTECTION;
615 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
616 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
617 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -0800618 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -0700619 }
620
621 if (priv->cfg->ops->hcmd->set_rxon_chain)
622 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
623
624 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
625 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
626 else
627 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
628
629 if (bss_conf->use_cts_prot)
630 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
631 else
632 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
633
634 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
635
636 if (vif->type == NL80211_IFTYPE_AP ||
637 vif->type == NL80211_IFTYPE_ADHOC) {
638 if (vif->bss_conf.enable_beacon) {
639 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
640 priv->beacon_ctx = ctx;
641 } else {
642 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
643 priv->beacon_ctx = NULL;
644 }
645 }
646
647 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
648 iwlagn_commit_rxon(priv, ctx);
649
Johannes Berg8da8e622010-11-10 09:56:46 -0800650 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
651 /*
652 * The chain noise calibration will enable PM upon
653 * completion. If calibration has already been run
654 * then we need to enable power management here.
655 */
656 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
657 iwl_power_update_mode(priv, false);
658
659 /* Enable RX differential gain and sensitivity calibrations */
660 iwl_chain_noise_reset(priv);
661 priv->start_calib = 1;
662 }
663
Johannes Berg2295c662010-10-23 09:15:41 -0700664 if (changes & BSS_CHANGED_IBSS) {
665 ret = iwlagn_manage_ibss_station(priv, vif,
666 bss_conf->ibss_joined);
667 if (ret)
668 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
669 bss_conf->ibss_joined ? "add" : "remove",
670 bss_conf->bssid);
671 }
672
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700673 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
674 priv->beacon_ctx) {
675 if (iwlagn_update_beacon(priv, vif))
676 IWL_ERR(priv, "Error sending IBSS beacon\n");
677 }
678
Johannes Berg2295c662010-10-23 09:15:41 -0700679 mutex_unlock(&priv->mutex);
680}
Johannes Bergae79d232010-11-10 09:56:38 -0800681
682void iwlagn_post_scan(struct iwl_priv *priv)
683{
684 struct iwl_rxon_context *ctx;
685
686 /*
687 * Since setting the RXON may have been deferred while
688 * performing the scan, fire one off if needed
689 */
690 for_each_context(priv, ctx)
691 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
692 iwlagn_commit_rxon(priv, ctx);
693
694 if (priv->cfg->ops->hcmd->set_pan_params)
695 priv->cfg->ops->hcmd->set_pan_params(priv);
696}