blob: 6e80f1070c52c466c1b76ea1bf18d717e0a12472 [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 Bergbd50a8a2010-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
159 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
160 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
161 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
162 else
163 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
164
165 ret = iwl_check_rxon_cmd(priv, ctx);
166 if (ret) {
167 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
168 return -EINVAL;
169 }
170
171 /*
172 * receive commit_rxon request
173 * abort any previous channel switch if still in process
174 */
175 if (priv->switch_rxon.switch_in_progress &&
176 (priv->switch_rxon.channel != ctx->staging.channel)) {
177 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
178 le16_to_cpu(priv->switch_rxon.channel));
179 iwl_chswitch_done(priv, false);
180 }
181
182 /*
183 * If we don't need to send a full RXON, we can use
184 * iwl_rxon_assoc_cmd which is used to reconfigure filter
185 * and other flags for the current radio configuration.
186 */
187 if (!iwl_full_rxon_required(priv, ctx)) {
188 ret = iwl_send_rxon_assoc(priv, ctx);
189 if (ret) {
190 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
191 return ret;
192 }
193
194 memcpy(active, &ctx->staging, sizeof(*active));
195 iwl_print_rx_config_cmd(priv, ctx);
196 return 0;
197 }
198
199 if (priv->cfg->ops->hcmd->set_pan_params) {
200 ret = priv->cfg->ops->hcmd->set_pan_params(priv);
201 if (ret)
202 return ret;
203 }
204
205 iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
206
207 IWL_DEBUG_INFO(priv,
208 "Going to commit RXON\n"
209 " * with%s RXON_FILTER_ASSOC_MSK\n"
210 " * channel = %d\n"
211 " * bssid = %pM\n",
212 (new_assoc ? "" : "out"),
213 le16_to_cpu(ctx->staging.channel),
214 ctx->staging.bssid_addr);
215
216 /*
Johannes Berg52d980c2010-11-10 09:56:45 -0800217 * Always clear associated first, but with the correct config.
218 * This is required as for example station addition for the
219 * AP station must be done after the BSSID is set to correctly
220 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -0700221 */
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800222 if ((old_assoc && new_assoc) || !new_assoc) {
223 if (ctx->ctxid == IWL_RXON_CTX_BSS)
224 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
225 else
226 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
227 if (ret)
228 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -0700229
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800230 memcpy(active, &ctx->staging, sizeof(*active));
Johannes Berg2295c662010-10-23 09:15:41 -0700231
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800232 /*
233 * Un-assoc RXON clears the station table and WEP
234 * keys, so we have to restore those afterwards.
235 */
236 iwl_clear_ucode_stations(priv, ctx);
237 iwl_restore_stations(priv, ctx);
238 ret = iwl_restore_default_wep_keys(priv, ctx);
239 if (ret) {
240 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
241 return ret;
242 }
Johannes Berg2295c662010-10-23 09:15:41 -0700243 }
244
245 /* RXON timing must be before associated RXON */
246 ret = iwl_send_rxon_timing(priv, ctx);
247 if (ret) {
248 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
249 return ret;
250 }
251
252 if (new_assoc) {
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800253 /* QoS info may be cleared by previous un-assoc RXON */
254 iwlagn_update_qos(priv, ctx);
255
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700256 /*
257 * We'll run into this code path when beaconing is
258 * enabled, but then we also need to send the beacon
259 * to the device.
260 */
261 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
262 ret = iwlagn_update_beacon(priv, ctx->vif);
263 if (ret) {
264 IWL_ERR(priv,
265 "Error sending required beacon (%d)!\n",
266 ret);
267 return ret;
268 }
Johannes Berg2295c662010-10-23 09:15:41 -0700269 }
270
271 priv->start_calib = 0;
272 /*
273 * Apply the new configuration.
274 *
275 * Associated RXON doesn't clear the station table in uCode,
276 * so we don't need to restore stations etc. after this.
277 */
278 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
279 sizeof(struct iwl_rxon_cmd), &ctx->staging);
280 if (ret) {
281 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
282 return ret;
283 }
284 memcpy(active, &ctx->staging, sizeof(*active));
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700285
Johannes Berg2b5f7a62010-11-10 18:25:48 -0800286 iwl_reprogram_ap_sta(priv, ctx);
287
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700288 /* IBSS beacon needs to be sent after setting assoc */
289 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
290 if (iwlagn_update_beacon(priv, ctx->vif))
291 IWL_ERR(priv, "Error sending IBSS beacon\n");
Johannes Berg2295c662010-10-23 09:15:41 -0700292 }
293
294 iwl_print_rx_config_cmd(priv, ctx);
295
296 iwl_init_sensitivity(priv);
297
298 /*
299 * If we issue a new RXON command which required a tune then we must
300 * send a new TXPOWER command or we won't be able to Tx any frames.
301 *
302 * FIXME: which RXON requires a tune? Can we optimise this out in
303 * some cases?
304 */
305 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
306 if (ret) {
307 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
308 return ret;
309 }
310
311 return 0;
312}
313
314int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
315{
316 struct iwl_priv *priv = hw->priv;
317 struct iwl_rxon_context *ctx;
318 struct ieee80211_conf *conf = &hw->conf;
319 struct ieee80211_channel *channel = conf->channel;
320 const struct iwl_channel_info *ch_info;
321 int ret = 0;
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800322 bool ht_changed[NUM_IWL_RXON_CTX] = {};
Johannes Berg2295c662010-10-23 09:15:41 -0700323
324 IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
325
326 mutex_lock(&priv->mutex);
327
328 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
329 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
330 goto out;
331 }
332
333 if (!iwl_is_ready(priv)) {
334 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
335 goto out;
336 }
337
338 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
339 IEEE80211_CONF_CHANGE_CHANNEL)) {
340 /* mac80211 uses static for non-HT which is what we want */
341 priv->current_ht_config.smps = conf->smps_mode;
342
343 /*
344 * Recalculate chain counts.
345 *
346 * If monitor mode is enabled then mac80211 will
347 * set up the SM PS mode to OFF if an HT channel is
348 * configured.
349 */
350 if (priv->cfg->ops->hcmd->set_rxon_chain)
351 for_each_context(priv, ctx)
352 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
353 }
354
355 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
356 unsigned long flags;
357
358 ch_info = iwl_get_channel_info(priv, channel->band,
359 channel->hw_value);
360 if (!is_channel_valid(ch_info)) {
361 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
362 ret = -EINVAL;
363 goto out;
364 }
365
366 spin_lock_irqsave(&priv->lock, flags);
367
368 for_each_context(priv, ctx) {
369 /* Configure HT40 channels */
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800370 if (ctx->ht.enabled != conf_is_ht(conf)) {
371 ctx->ht.enabled = conf_is_ht(conf);
372 ht_changed[ctx->ctxid] = true;
373 }
374
Johannes Berg2295c662010-10-23 09:15:41 -0700375 if (ctx->ht.enabled) {
376 if (conf_is_ht40_minus(conf)) {
377 ctx->ht.extension_chan_offset =
378 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
379 ctx->ht.is_40mhz = true;
380 } else if (conf_is_ht40_plus(conf)) {
381 ctx->ht.extension_chan_offset =
382 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
383 ctx->ht.is_40mhz = true;
384 } else {
385 ctx->ht.extension_chan_offset =
386 IEEE80211_HT_PARAM_CHA_SEC_NONE;
387 ctx->ht.is_40mhz = false;
388 }
389 } else
390 ctx->ht.is_40mhz = false;
391
392 /*
393 * Default to no protection. Protection mode will
394 * later be set from BSS config in iwl_ht_conf
395 */
396 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
397
398 /* if we are switching from ht to 2.4 clear flags
399 * from any ht related info since 2.4 does not
400 * support ht */
401 if (le16_to_cpu(ctx->staging.channel) !=
402 channel->hw_value)
403 ctx->staging.flags = 0;
404
405 iwl_set_rxon_channel(priv, channel, ctx);
406 iwl_set_rxon_ht(priv, &priv->current_ht_config);
407
408 iwl_set_flags_for_band(priv, ctx, channel->band,
409 ctx->vif);
410 }
411
412 spin_unlock_irqrestore(&priv->lock, flags);
413
414 iwl_update_bcast_stations(priv);
415
416 /*
417 * The list of supported rates and rate mask can be different
418 * for each band; since the band may have changed, reset
419 * the rate mask to what mac80211 lists.
420 */
421 iwl_set_rate(priv);
422 }
423
424 if (changed & (IEEE80211_CONF_CHANGE_PS |
425 IEEE80211_CONF_CHANGE_IDLE)) {
426 ret = iwl_power_update_mode(priv, false);
427 if (ret)
428 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
429 }
430
431 if (changed & IEEE80211_CONF_CHANGE_POWER) {
432 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
433 priv->tx_power_user_lmt, conf->power_level);
434
435 iwl_set_tx_power(priv, conf->power_level, false);
436 }
437
438 for_each_context(priv, ctx) {
439 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
440 continue;
441 iwlagn_commit_rxon(priv, ctx);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800442 if (ht_changed[ctx->ctxid])
443 iwlagn_update_qos(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700444 }
445 out:
446 mutex_unlock(&priv->mutex);
447 return ret;
448}
449
Johannes Berg2295c662010-10-23 09:15:41 -0700450static void iwlagn_check_needed_chains(struct iwl_priv *priv,
451 struct iwl_rxon_context *ctx,
452 struct ieee80211_bss_conf *bss_conf)
453{
454 struct ieee80211_vif *vif = ctx->vif;
455 struct iwl_rxon_context *tmp;
456 struct ieee80211_sta *sta;
457 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
458 bool need_multiple;
459
460 lockdep_assert_held(&priv->mutex);
461
462 switch (vif->type) {
463 case NL80211_IFTYPE_STATION:
464 rcu_read_lock();
465 sta = ieee80211_find_sta(vif, bss_conf->bssid);
466 if (sta) {
467 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
468 int maxstreams;
469
470 maxstreams = (ht_cap->mcs.tx_params &
471 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
472 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
473 maxstreams += 1;
474
Johannes Berg2e1fea42010-11-10 09:56:44 -0800475 need_multiple = true;
476
Johannes Berg2295c662010-10-23 09:15:41 -0700477 if ((ht_cap->mcs.rx_mask[1] == 0) &&
478 (ht_cap->mcs.rx_mask[2] == 0))
479 need_multiple = false;
480 if (maxstreams <= 1)
Johannes Berg2e1fea42010-11-10 09:56:44 -0800481 need_multiple = false;
Johannes Berg2295c662010-10-23 09:15:41 -0700482 } else {
483 /*
484 * If at all, this can only happen through a race
485 * when the AP disconnects us while we're still
486 * setting up the connection, in that case mac80211
487 * will soon tell us about that.
488 */
489 need_multiple = false;
490 }
491 rcu_read_unlock();
492 break;
493 case NL80211_IFTYPE_ADHOC:
494 /* currently */
495 need_multiple = false;
496 break;
497 default:
498 /* only AP really */
499 need_multiple = true;
500 break;
501 }
502
503 ctx->ht_need_multiple_chains = need_multiple;
504
505 if (!need_multiple) {
506 /* check all contexts */
507 for_each_context(priv, tmp) {
508 if (!tmp->vif)
509 continue;
510 if (tmp->ht_need_multiple_chains) {
511 need_multiple = true;
512 break;
513 }
514 }
515 }
516
517 ht_conf->single_chain_sufficient = !need_multiple;
518}
519
520void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
521 struct ieee80211_vif *vif,
522 struct ieee80211_bss_conf *bss_conf,
523 u32 changes)
524{
525 struct iwl_priv *priv = hw->priv;
526 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
527 int ret;
528 bool force = false;
529
530 mutex_lock(&priv->mutex);
531
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800532 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -0800533 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
534 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800535 return;
536 }
537
538 if (unlikely(!ctx->vif)) {
539 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Berg893654d2010-11-10 18:25:47 -0800540 mutex_unlock(&priv->mutex);
541 return;
542 }
543
Johannes Berg2295c662010-10-23 09:15:41 -0700544 if (changes & BSS_CHANGED_BEACON_INT)
545 force = true;
546
547 if (changes & BSS_CHANGED_QOS) {
548 ctx->qos_data.qos_active = bss_conf->qos;
549 iwlagn_update_qos(priv, ctx);
550 }
551
552 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
553 if (vif->bss_conf.use_short_preamble)
554 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
555 else
556 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
557
558 if (changes & BSS_CHANGED_ASSOC) {
559 if (bss_conf->assoc) {
560 iwl_led_associate(priv);
561 priv->timestamp = bss_conf->timestamp;
562 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
563 } else {
564 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
565 iwl_led_disassociate(priv);
566 }
567 }
568
569 if (ctx->ht.enabled) {
570 ctx->ht.protection = bss_conf->ht_operation_mode &
571 IEEE80211_HT_OP_MODE_PROTECTION;
572 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
573 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
574 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -0800575 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -0700576 }
577
578 if (priv->cfg->ops->hcmd->set_rxon_chain)
579 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
580
581 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
582 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
583 else
584 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
585
586 if (bss_conf->use_cts_prot)
587 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
588 else
589 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
590
591 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
592
593 if (vif->type == NL80211_IFTYPE_AP ||
594 vif->type == NL80211_IFTYPE_ADHOC) {
595 if (vif->bss_conf.enable_beacon) {
596 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
597 priv->beacon_ctx = ctx;
598 } else {
599 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
600 priv->beacon_ctx = NULL;
601 }
602 }
603
604 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
605 iwlagn_commit_rxon(priv, ctx);
606
Johannes Berg8da8e622010-11-10 09:56:46 -0800607 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
608 /*
609 * The chain noise calibration will enable PM upon
610 * completion. If calibration has already been run
611 * then we need to enable power management here.
612 */
613 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
614 iwl_power_update_mode(priv, false);
615
616 /* Enable RX differential gain and sensitivity calibrations */
617 iwl_chain_noise_reset(priv);
618 priv->start_calib = 1;
619 }
620
Johannes Berg2295c662010-10-23 09:15:41 -0700621 if (changes & BSS_CHANGED_IBSS) {
622 ret = iwlagn_manage_ibss_station(priv, vif,
623 bss_conf->ibss_joined);
624 if (ret)
625 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
626 bss_conf->ibss_joined ? "add" : "remove",
627 bss_conf->bssid);
628 }
629
Johannes Bergbd50a8a2010-10-23 09:15:42 -0700630 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
631 priv->beacon_ctx) {
632 if (iwlagn_update_beacon(priv, vif))
633 IWL_ERR(priv, "Error sending IBSS beacon\n");
634 }
635
Johannes Berg2295c662010-10-23 09:15:41 -0700636 mutex_unlock(&priv->mutex);
637}
Johannes Bergae79d232010-11-10 09:56:38 -0800638
639void iwlagn_post_scan(struct iwl_priv *priv)
640{
641 struct iwl_rxon_context *ctx;
642
643 /*
644 * Since setting the RXON may have been deferred while
645 * performing the scan, fire one off if needed
646 */
647 for_each_context(priv, ctx)
648 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
649 iwlagn_commit_rxon(priv, ctx);
650
651 if (priv->cfg->ops->hcmd->set_pan_params)
652 priv->cfg->ops->hcmd->set_pan_params(priv);
653}