blob: 2a4ff832fbb8f2e1bee12c011f5fe3e7be219cda [file] [log] [blame]
Johannes Berg2295c662010-10-23 09:15:41 -07001/******************************************************************************
2 *
3 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
4 *
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"
32
33static int iwlagn_disable_bss(struct iwl_priv *priv,
34 struct iwl_rxon_context *ctx,
35 struct iwl_rxon_cmd *send)
36{
37 __le32 old_filter = send->filter_flags;
38 int ret;
39
40 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
41 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd, sizeof(*send), send);
42
43 send->filter_flags = old_filter;
44
45 if (ret)
46 IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
47
48 return ret;
49}
50
51static int iwlagn_disable_pan(struct iwl_priv *priv,
52 struct iwl_rxon_context *ctx,
53 struct iwl_rxon_cmd *send)
54{
Johannes Berg311dce72011-01-04 16:22:01 -080055 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -070056 __le32 old_filter = send->filter_flags;
57 u8 old_dev_type = send->dev_type;
58 int ret;
59
Johannes Berg311dce72011-01-04 16:22:01 -080060 iwlagn_init_notification_wait(priv, &disable_wait, NULL,
61 REPLY_WIPAN_DEACTIVATION_COMPLETE);
62
Johannes Berg2295c662010-10-23 09:15:41 -070063 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);
66
67 send->filter_flags = old_filter;
68 send->dev_type = old_dev_type;
69
Johannes Berg311dce72011-01-04 16:22:01 -080070 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -070071 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg311dce72011-01-04 16:22:01 -080072 iwlagn_remove_notification(priv, &disable_wait);
73 } else {
74 signed long wait_res;
Johannes Berg2295c662010-10-23 09:15:41 -070075
Johannes Berg311dce72011-01-04 16:22:01 -080076 wait_res = iwlagn_wait_notification(priv, &disable_wait, HZ);
Johannes Berg2a1a78d2011-01-04 16:22:02 -080077 if (wait_res == 0) {
Johannes Berg311dce72011-01-04 16:22:01 -080078 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
Johannes Berg2a1a78d2011-01-04 16:22:02 -080079 ret = -EIO;
80 }
Johannes Berg311dce72011-01-04 16:22:01 -080081 }
Johannes Berg2295c662010-10-23 09:15:41 -070082
83 return ret;
84}
85
Shanyu Zhaof4115d42010-11-10 18:25:58 -080086static void iwlagn_update_qos(struct iwl_priv *priv,
87 struct iwl_rxon_context *ctx)
88{
89 int ret;
90
91 if (!ctx->is_active)
92 return;
93
94 ctx->qos_data.def_qos_parm.qos_flags = 0;
95
96 if (ctx->qos_data.qos_active)
97 ctx->qos_data.def_qos_parm.qos_flags |=
98 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
99
100 if (ctx->ht.enabled)
101 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
102
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);
106
107 ret = iwl_send_cmd_pdu(priv, ctx->qos_cmd,
108 sizeof(struct iwl_qosparam_cmd),
109 &ctx->qos_data.def_qos_parm);
110 if (ret)
111 IWL_ERR(priv, "Failed to update QoS\n");
112}
113
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700114static int iwlagn_update_beacon(struct iwl_priv *priv,
115 struct ieee80211_vif *vif)
116{
117 lockdep_assert_held(&priv->mutex);
118
119 dev_kfree_skb(priv->beacon_skb);
120 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
121 if (!priv->beacon_skb)
122 return -ENOMEM;
123 return iwlagn_send_beacon_cmd(priv);
124}
125
Johannes Berg2295c662010-10-23 09:15:41 -0700126/**
127 * iwlagn_commit_rxon - commit staging_rxon to hardware
128 *
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.
133 */
134int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
135{
136 /* cast away the const for active_rxon in this function */
137 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -0700138 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800139 bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
Johannes Berg2295c662010-10-23 09:15:41 -0700140 int ret;
141
142 lockdep_assert_held(&priv->mutex);
143
Wey-Yi Guyadb90a02010-11-26 11:09:42 -0800144 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
145 return -EINVAL;
146
Johannes Berg2295c662010-10-23 09:15:41 -0700147 if (!iwl_is_alive(priv))
148 return -EBUSY;
149
150 /* This function hardcodes a bunch of dual-mode assumptions */
151 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
152
153 if (!ctx->is_active)
154 return 0;
155
156 /* always get timestamp with Rx frame */
157 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
158
Johannes Berg9b9190d2011-01-06 08:07:10 -0800159 if (ctx->ctxid == IWL_RXON_CTX_PAN && priv->_agn.hw_roc_channel) {
160 struct ieee80211_channel *chan = priv->_agn.hw_roc_channel;
161
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;
169 new_assoc = true;
170
171 if (memcmp(&ctx->staging, &ctx->active,
172 sizeof(ctx->staging)) == 0)
173 return 0;
174 }
175
Johannes Berg2295c662010-10-23 09:15:41 -0700176 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
177 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
178 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
179 else
180 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
181
182 ret = iwl_check_rxon_cmd(priv, ctx);
183 if (ret) {
184 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
185 return -EINVAL;
186 }
187
188 /*
189 * receive commit_rxon request
190 * abort any previous channel switch if still in process
191 */
192 if (priv->switch_rxon.switch_in_progress &&
193 (priv->switch_rxon.channel != ctx->staging.channel)) {
194 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
195 le16_to_cpu(priv->switch_rxon.channel));
196 iwl_chswitch_done(priv, false);
197 }
198
199 /*
200 * If we don't need to send a full RXON, we can use
201 * iwl_rxon_assoc_cmd which is used to reconfigure filter
202 * and other flags for the current radio configuration.
203 */
204 if (!iwl_full_rxon_required(priv, ctx)) {
205 ret = iwl_send_rxon_assoc(priv, ctx);
206 if (ret) {
207 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
208 return ret;
209 }
210
211 memcpy(active, &ctx->staging, sizeof(*active));
212 iwl_print_rx_config_cmd(priv, ctx);
213 return 0;
214 }
215
216 if (priv->cfg->ops->hcmd->set_pan_params) {
217 ret = priv->cfg->ops->hcmd->set_pan_params(priv);
218 if (ret)
219 return ret;
220 }
221
222 iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
223
224 IWL_DEBUG_INFO(priv,
225 "Going to commit RXON\n"
226 " * with%s RXON_FILTER_ASSOC_MSK\n"
227 " * channel = %d\n"
228 " * bssid = %pM\n",
229 (new_assoc ? "" : "out"),
230 le16_to_cpu(ctx->staging.channel),
231 ctx->staging.bssid_addr);
232
233 /*
Johannes Berg52d980c2010-11-10 09:56:45 -0800234 * Always clear associated first, but with the correct config.
235 * This is required as for example station addition for the
236 * AP station must be done after the BSSID is set to correctly
237 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -0700238 */
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800239 if ((old_assoc && new_assoc) || !new_assoc) {
240 if (ctx->ctxid == IWL_RXON_CTX_BSS)
241 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
242 else
243 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
244 if (ret)
245 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -0700246
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800247 memcpy(active, &ctx->staging, sizeof(*active));
Johannes Berg2295c662010-10-23 09:15:41 -0700248
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800249 /*
250 * Un-assoc RXON clears the station table and WEP
251 * keys, so we have to restore those afterwards.
252 */
253 iwl_clear_ucode_stations(priv, ctx);
254 iwl_restore_stations(priv, ctx);
255 ret = iwl_restore_default_wep_keys(priv, ctx);
256 if (ret) {
257 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
258 return ret;
259 }
Johannes Berg2295c662010-10-23 09:15:41 -0700260 }
261
262 /* RXON timing must be before associated RXON */
263 ret = iwl_send_rxon_timing(priv, ctx);
264 if (ret) {
265 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
266 return ret;
267 }
268
269 if (new_assoc) {
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800270 /* QoS info may be cleared by previous un-assoc RXON */
271 iwlagn_update_qos(priv, ctx);
272
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700273 /*
274 * We'll run into this code path when beaconing is
275 * enabled, but then we also need to send the beacon
276 * to the device.
277 */
278 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
279 ret = iwlagn_update_beacon(priv, ctx->vif);
280 if (ret) {
281 IWL_ERR(priv,
282 "Error sending required beacon (%d)!\n",
283 ret);
284 return ret;
285 }
Johannes Berg2295c662010-10-23 09:15:41 -0700286 }
287
288 priv->start_calib = 0;
289 /*
290 * Apply the new configuration.
291 *
292 * Associated RXON doesn't clear the station table in uCode,
293 * so we don't need to restore stations etc. after this.
294 */
295 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
296 sizeof(struct iwl_rxon_cmd), &ctx->staging);
297 if (ret) {
298 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
299 return ret;
300 }
301 memcpy(active, &ctx->staging, sizeof(*active));
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700302
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800303 iwl_reprogram_ap_sta(priv, ctx);
304
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700305 /* IBSS beacon needs to be sent after setting assoc */
306 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
307 if (iwlagn_update_beacon(priv, ctx->vif))
308 IWL_ERR(priv, "Error sending IBSS beacon\n");
Johannes Berg2295c662010-10-23 09:15:41 -0700309 }
310
311 iwl_print_rx_config_cmd(priv, ctx);
312
313 iwl_init_sensitivity(priv);
314
315 /*
316 * If we issue a new RXON command which required a tune then we must
317 * send a new TXPOWER command or we won't be able to Tx any frames.
318 *
319 * FIXME: which RXON requires a tune? Can we optimise this out in
320 * some cases?
321 */
322 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
323 if (ret) {
324 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
325 return ret;
326 }
327
328 return 0;
329}
330
331int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
332{
333 struct iwl_priv *priv = hw->priv;
334 struct iwl_rxon_context *ctx;
335 struct ieee80211_conf *conf = &hw->conf;
336 struct ieee80211_channel *channel = conf->channel;
337 const struct iwl_channel_info *ch_info;
338 int ret = 0;
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800339 bool ht_changed[NUM_IWL_RXON_CTX] = {};
Johannes Berg2295c662010-10-23 09:15:41 -0700340
341 IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
342
343 mutex_lock(&priv->mutex);
344
345 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
346 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
347 goto out;
348 }
349
350 if (!iwl_is_ready(priv)) {
351 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
352 goto out;
353 }
354
355 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
356 IEEE80211_CONF_CHANGE_CHANNEL)) {
357 /* mac80211 uses static for non-HT which is what we want */
358 priv->current_ht_config.smps = conf->smps_mode;
359
360 /*
361 * Recalculate chain counts.
362 *
363 * If monitor mode is enabled then mac80211 will
364 * set up the SM PS mode to OFF if an HT channel is
365 * configured.
366 */
367 if (priv->cfg->ops->hcmd->set_rxon_chain)
368 for_each_context(priv, ctx)
369 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
370 }
371
372 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
373 unsigned long flags;
374
375 ch_info = iwl_get_channel_info(priv, channel->band,
376 channel->hw_value);
377 if (!is_channel_valid(ch_info)) {
378 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
379 ret = -EINVAL;
380 goto out;
381 }
382
383 spin_lock_irqsave(&priv->lock, flags);
384
385 for_each_context(priv, ctx) {
386 /* Configure HT40 channels */
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800387 if (ctx->ht.enabled != conf_is_ht(conf)) {
388 ctx->ht.enabled = conf_is_ht(conf);
389 ht_changed[ctx->ctxid] = true;
390 }
391
Johannes Berg2295c662010-10-23 09:15:41 -0700392 if (ctx->ht.enabled) {
393 if (conf_is_ht40_minus(conf)) {
394 ctx->ht.extension_chan_offset =
395 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
396 ctx->ht.is_40mhz = true;
397 } else if (conf_is_ht40_plus(conf)) {
398 ctx->ht.extension_chan_offset =
399 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
400 ctx->ht.is_40mhz = true;
401 } else {
402 ctx->ht.extension_chan_offset =
403 IEEE80211_HT_PARAM_CHA_SEC_NONE;
404 ctx->ht.is_40mhz = false;
405 }
406 } else
407 ctx->ht.is_40mhz = false;
408
409 /*
410 * Default to no protection. Protection mode will
411 * later be set from BSS config in iwl_ht_conf
412 */
413 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
414
415 /* if we are switching from ht to 2.4 clear flags
416 * from any ht related info since 2.4 does not
417 * support ht */
418 if (le16_to_cpu(ctx->staging.channel) !=
419 channel->hw_value)
420 ctx->staging.flags = 0;
421
422 iwl_set_rxon_channel(priv, channel, ctx);
423 iwl_set_rxon_ht(priv, &priv->current_ht_config);
424
425 iwl_set_flags_for_band(priv, ctx, channel->band,
426 ctx->vif);
427 }
428
429 spin_unlock_irqrestore(&priv->lock, flags);
430
431 iwl_update_bcast_stations(priv);
432
433 /*
434 * The list of supported rates and rate mask can be different
435 * for each band; since the band may have changed, reset
436 * the rate mask to what mac80211 lists.
437 */
438 iwl_set_rate(priv);
439 }
440
441 if (changed & (IEEE80211_CONF_CHANGE_PS |
442 IEEE80211_CONF_CHANGE_IDLE)) {
443 ret = iwl_power_update_mode(priv, false);
444 if (ret)
445 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
446 }
447
448 if (changed & IEEE80211_CONF_CHANGE_POWER) {
449 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
450 priv->tx_power_user_lmt, conf->power_level);
451
452 iwl_set_tx_power(priv, conf->power_level, false);
453 }
454
455 for_each_context(priv, ctx) {
456 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
457 continue;
458 iwlagn_commit_rxon(priv, ctx);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800459 if (ht_changed[ctx->ctxid])
460 iwlagn_update_qos(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700461 }
462 out:
463 mutex_unlock(&priv->mutex);
464 return ret;
465}
466
Johannes Berg2295c662010-10-23 09:15:41 -0700467static void iwlagn_check_needed_chains(struct iwl_priv *priv,
468 struct iwl_rxon_context *ctx,
469 struct ieee80211_bss_conf *bss_conf)
470{
471 struct ieee80211_vif *vif = ctx->vif;
472 struct iwl_rxon_context *tmp;
473 struct ieee80211_sta *sta;
474 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
475 bool need_multiple;
476
477 lockdep_assert_held(&priv->mutex);
478
479 switch (vif->type) {
480 case NL80211_IFTYPE_STATION:
481 rcu_read_lock();
482 sta = ieee80211_find_sta(vif, bss_conf->bssid);
483 if (sta) {
484 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
485 int maxstreams;
486
487 maxstreams = (ht_cap->mcs.tx_params &
488 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
489 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
490 maxstreams += 1;
491
Johannes Berg2e1fea42010-11-10 09:56:44 -0800492 need_multiple = true;
493
Johannes Berg2295c662010-10-23 09:15:41 -0700494 if ((ht_cap->mcs.rx_mask[1] == 0) &&
495 (ht_cap->mcs.rx_mask[2] == 0))
496 need_multiple = false;
497 if (maxstreams <= 1)
Johannes Berg2e1fea42010-11-10 09:56:44 -0800498 need_multiple = false;
Johannes Berg2295c662010-10-23 09:15:41 -0700499 } else {
500 /*
501 * If at all, this can only happen through a race
502 * when the AP disconnects us while we're still
503 * setting up the connection, in that case mac80211
504 * will soon tell us about that.
505 */
506 need_multiple = false;
507 }
508 rcu_read_unlock();
509 break;
510 case NL80211_IFTYPE_ADHOC:
511 /* currently */
512 need_multiple = false;
513 break;
514 default:
515 /* only AP really */
516 need_multiple = true;
517 break;
518 }
519
520 ctx->ht_need_multiple_chains = need_multiple;
521
522 if (!need_multiple) {
523 /* check all contexts */
524 for_each_context(priv, tmp) {
525 if (!tmp->vif)
526 continue;
527 if (tmp->ht_need_multiple_chains) {
528 need_multiple = true;
529 break;
530 }
531 }
532 }
533
534 ht_conf->single_chain_sufficient = !need_multiple;
535}
536
537void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
538 struct ieee80211_vif *vif,
539 struct ieee80211_bss_conf *bss_conf,
540 u32 changes)
541{
542 struct iwl_priv *priv = hw->priv;
543 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
544 int ret;
545 bool force = false;
546
547 mutex_lock(&priv->mutex);
548
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800549 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -0800550 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
551 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800552 return;
553 }
554
555 if (unlikely(!ctx->vif)) {
556 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Berg893654d2010-11-10 18:25:47 -0800557 mutex_unlock(&priv->mutex);
558 return;
559 }
560
Johannes Berg2295c662010-10-23 09:15:41 -0700561 if (changes & BSS_CHANGED_BEACON_INT)
562 force = true;
563
564 if (changes & BSS_CHANGED_QOS) {
565 ctx->qos_data.qos_active = bss_conf->qos;
566 iwlagn_update_qos(priv, ctx);
567 }
568
569 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
570 if (vif->bss_conf.use_short_preamble)
571 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
572 else
573 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
574
575 if (changes & BSS_CHANGED_ASSOC) {
576 if (bss_conf->assoc) {
Johannes Berg2295c662010-10-23 09:15:41 -0700577 priv->timestamp = bss_conf->timestamp;
578 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
579 } else {
580 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berg2295c662010-10-23 09:15:41 -0700581 }
582 }
583
584 if (ctx->ht.enabled) {
585 ctx->ht.protection = bss_conf->ht_operation_mode &
586 IEEE80211_HT_OP_MODE_PROTECTION;
587 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
588 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
589 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -0800590 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -0700591 }
592
593 if (priv->cfg->ops->hcmd->set_rxon_chain)
594 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
595
596 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
597 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
598 else
599 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
600
601 if (bss_conf->use_cts_prot)
602 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
603 else
604 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
605
606 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
607
608 if (vif->type == NL80211_IFTYPE_AP ||
609 vif->type == NL80211_IFTYPE_ADHOC) {
610 if (vif->bss_conf.enable_beacon) {
611 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
612 priv->beacon_ctx = ctx;
613 } else {
614 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
615 priv->beacon_ctx = NULL;
616 }
617 }
618
619 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
620 iwlagn_commit_rxon(priv, ctx);
621
Johannes Berg8da8e622010-11-10 09:56:46 -0800622 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
623 /*
624 * The chain noise calibration will enable PM upon
625 * completion. If calibration has already been run
626 * then we need to enable power management here.
627 */
628 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
629 iwl_power_update_mode(priv, false);
630
631 /* Enable RX differential gain and sensitivity calibrations */
632 iwl_chain_noise_reset(priv);
633 priv->start_calib = 1;
634 }
635
Johannes Berg2295c662010-10-23 09:15:41 -0700636 if (changes & BSS_CHANGED_IBSS) {
637 ret = iwlagn_manage_ibss_station(priv, vif,
638 bss_conf->ibss_joined);
639 if (ret)
640 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
641 bss_conf->ibss_joined ? "add" : "remove",
642 bss_conf->bssid);
643 }
644
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700645 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
646 priv->beacon_ctx) {
647 if (iwlagn_update_beacon(priv, vif))
648 IWL_ERR(priv, "Error sending IBSS beacon\n");
649 }
650
Johannes Berg2295c662010-10-23 09:15:41 -0700651 mutex_unlock(&priv->mutex);
652}
Johannes Bergae79d232010-11-10 09:56:38 -0800653
654void iwlagn_post_scan(struct iwl_priv *priv)
655{
656 struct iwl_rxon_context *ctx;
657
658 /*
659 * Since setting the RXON may have been deferred while
660 * performing the scan, fire one off if needed
661 */
662 for_each_context(priv, ctx)
663 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
664 iwlagn_commit_rxon(priv, ctx);
665
666 if (priv->cfg->ops->hcmd->set_pan_params)
667 priv->cfg->ops->hcmd->set_pan_params(priv);
668}