iwlwifi: move iwl_set_flags_for_band to iwl-agn-rxon.c
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-agn-rxon.c
1 /******************************************************************************
2 *
3 * Copyright(c) 2003 - 2012 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 <linux/etherdevice.h>
28 #include "iwl-dev.h"
29 #include "iwl-agn.h"
30 #include "iwl-core.h"
31 #include "iwl-agn-calib.h"
32 #include "iwl-trans.h"
33 #include "iwl-shared.h"
34
35 static int iwlagn_disable_bss(struct iwl_priv *priv,
36 struct iwl_rxon_context *ctx,
37 struct iwl_rxon_cmd *send)
38 {
39 __le32 old_filter = send->filter_flags;
40 int ret;
41
42 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
43 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
44 CMD_SYNC, sizeof(*send), send);
45
46 send->filter_flags = old_filter;
47
48 if (ret)
49 IWL_DEBUG_QUIET_RFKILL(priv,
50 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
51
52 return ret;
53 }
54
55 static int iwlagn_disable_pan(struct iwl_priv *priv,
56 struct iwl_rxon_context *ctx,
57 struct iwl_rxon_cmd *send)
58 {
59 struct iwl_notification_wait disable_wait;
60 __le32 old_filter = send->filter_flags;
61 u8 old_dev_type = send->dev_type;
62 int ret;
63 static const u8 deactivate_cmd[] = {
64 REPLY_WIPAN_DEACTIVATION_COMPLETE
65 };
66
67 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
68 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
69 NULL, NULL);
70
71 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
72 send->dev_type = RXON_DEV_TYPE_P2P;
73 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
74 CMD_SYNC, sizeof(*send), send);
75
76 send->filter_flags = old_filter;
77 send->dev_type = old_dev_type;
78
79 if (ret) {
80 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
81 iwl_remove_notification(&priv->notif_wait, &disable_wait);
82 } else {
83 ret = iwl_wait_notification(&priv->notif_wait,
84 &disable_wait, HZ);
85 if (ret)
86 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
87 }
88
89 return ret;
90 }
91
92 static int iwlagn_disconn_pan(struct iwl_priv *priv,
93 struct iwl_rxon_context *ctx,
94 struct iwl_rxon_cmd *send)
95 {
96 __le32 old_filter = send->filter_flags;
97 int ret;
98
99 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
100 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
101 sizeof(*send), send);
102
103 send->filter_flags = old_filter;
104
105 return ret;
106 }
107
108 static void iwlagn_update_qos(struct iwl_priv *priv,
109 struct iwl_rxon_context *ctx)
110 {
111 int ret;
112
113 if (!ctx->is_active)
114 return;
115
116 ctx->qos_data.def_qos_parm.qos_flags = 0;
117
118 if (ctx->qos_data.qos_active)
119 ctx->qos_data.def_qos_parm.qos_flags |=
120 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
121
122 if (ctx->ht.enabled)
123 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
124
125 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
126 ctx->qos_data.qos_active,
127 ctx->qos_data.def_qos_parm.qos_flags);
128
129 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
130 sizeof(struct iwl_qosparam_cmd),
131 &ctx->qos_data.def_qos_parm);
132 if (ret)
133 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
134 }
135
136 static int iwlagn_update_beacon(struct iwl_priv *priv,
137 struct ieee80211_vif *vif)
138 {
139 lockdep_assert_held(&priv->mutex);
140
141 dev_kfree_skb(priv->beacon_skb);
142 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
143 if (!priv->beacon_skb)
144 return -ENOMEM;
145 return iwlagn_send_beacon_cmd(priv);
146 }
147
148 static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
149 struct iwl_rxon_context *ctx)
150 {
151 int ret = 0;
152 struct iwl_rxon_assoc_cmd rxon_assoc;
153 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
154 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
155
156 if ((rxon1->flags == rxon2->flags) &&
157 (rxon1->filter_flags == rxon2->filter_flags) &&
158 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
159 (rxon1->ofdm_ht_single_stream_basic_rates ==
160 rxon2->ofdm_ht_single_stream_basic_rates) &&
161 (rxon1->ofdm_ht_dual_stream_basic_rates ==
162 rxon2->ofdm_ht_dual_stream_basic_rates) &&
163 (rxon1->ofdm_ht_triple_stream_basic_rates ==
164 rxon2->ofdm_ht_triple_stream_basic_rates) &&
165 (rxon1->acquisition_data == rxon2->acquisition_data) &&
166 (rxon1->rx_chain == rxon2->rx_chain) &&
167 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
168 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
169 return 0;
170 }
171
172 rxon_assoc.flags = ctx->staging.flags;
173 rxon_assoc.filter_flags = ctx->staging.filter_flags;
174 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
175 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
176 rxon_assoc.reserved1 = 0;
177 rxon_assoc.reserved2 = 0;
178 rxon_assoc.reserved3 = 0;
179 rxon_assoc.ofdm_ht_single_stream_basic_rates =
180 ctx->staging.ofdm_ht_single_stream_basic_rates;
181 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
182 ctx->staging.ofdm_ht_dual_stream_basic_rates;
183 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
184 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
185 ctx->staging.ofdm_ht_triple_stream_basic_rates;
186 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
187
188 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
189 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
190 return ret;
191 }
192
193 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
194 {
195 u16 new_val;
196 u16 beacon_factor;
197
198 /*
199 * If mac80211 hasn't given us a beacon interval, program
200 * the default into the device (not checking this here
201 * would cause the adjustment below to return the maximum
202 * value, which may break PAN.)
203 */
204 if (!beacon_val)
205 return DEFAULT_BEACON_INTERVAL;
206
207 /*
208 * If the beacon interval we obtained from the peer
209 * is too large, we'll have to wake up more often
210 * (and in IBSS case, we'll beacon too much)
211 *
212 * For example, if max_beacon_val is 4096, and the
213 * requested beacon interval is 7000, we'll have to
214 * use 3500 to be able to wake up on the beacons.
215 *
216 * This could badly influence beacon detection stats.
217 */
218
219 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
220 new_val = beacon_val / beacon_factor;
221
222 if (!new_val)
223 new_val = max_beacon_val;
224
225 return new_val;
226 }
227
228 static int iwl_send_rxon_timing(struct iwl_priv *priv,
229 struct iwl_rxon_context *ctx)
230 {
231 u64 tsf;
232 s32 interval_tm, rem;
233 struct ieee80211_conf *conf = NULL;
234 u16 beacon_int;
235 struct ieee80211_vif *vif = ctx->vif;
236
237 conf = &priv->hw->conf;
238
239 lockdep_assert_held(&priv->mutex);
240
241 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
242
243 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
244 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
245
246 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
247
248 /*
249 * TODO: For IBSS we need to get atim_window from mac80211,
250 * for now just always use 0
251 */
252 ctx->timing.atim_window = 0;
253
254 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
255 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
256 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
257 priv->contexts[IWL_RXON_CTX_BSS].vif &&
258 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
259 ctx->timing.beacon_interval =
260 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
261 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
262 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
263 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
264 priv->contexts[IWL_RXON_CTX_PAN].vif &&
265 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
266 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
267 !ctx->vif->bss_conf.beacon_int)) {
268 ctx->timing.beacon_interval =
269 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
270 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
271 } else {
272 beacon_int = iwl_adjust_beacon_interval(beacon_int,
273 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
274 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
275 }
276
277 ctx->beacon_int = beacon_int;
278
279 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
280 interval_tm = beacon_int * TIME_UNIT;
281 rem = do_div(tsf, interval_tm);
282 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
283
284 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
285
286 IWL_DEBUG_ASSOC(priv,
287 "beacon interval %d beacon timer %d beacon tim %d\n",
288 le16_to_cpu(ctx->timing.beacon_interval),
289 le32_to_cpu(ctx->timing.beacon_init_val),
290 le16_to_cpu(ctx->timing.atim_window));
291
292 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
293 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
294 }
295
296 static int iwlagn_rxon_disconn(struct iwl_priv *priv,
297 struct iwl_rxon_context *ctx)
298 {
299 int ret;
300 struct iwl_rxon_cmd *active = (void *)&ctx->active;
301
302 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
303 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
304 } else {
305 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
306 if (ret)
307 return ret;
308 if (ctx->vif) {
309 ret = iwl_send_rxon_timing(priv, ctx);
310 if (ret) {
311 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
312 return ret;
313 }
314 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
315 }
316 }
317 if (ret)
318 return ret;
319
320 /*
321 * Un-assoc RXON clears the station table and WEP
322 * keys, so we have to restore those afterwards.
323 */
324 iwl_clear_ucode_stations(priv, ctx);
325 /* update -- might need P2P now */
326 iwl_update_bcast_station(priv, ctx);
327 iwl_restore_stations(priv, ctx);
328 ret = iwl_restore_default_wep_keys(priv, ctx);
329 if (ret) {
330 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
331 return ret;
332 }
333
334 memcpy(active, &ctx->staging, sizeof(*active));
335 return 0;
336 }
337
338 static int iwlagn_rxon_connect(struct iwl_priv *priv,
339 struct iwl_rxon_context *ctx)
340 {
341 int ret;
342 struct iwl_rxon_cmd *active = (void *)&ctx->active;
343
344 /* RXON timing must be before associated RXON */
345 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
346 ret = iwl_send_rxon_timing(priv, ctx);
347 if (ret) {
348 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
349 return ret;
350 }
351 }
352 /* QoS info may be cleared by previous un-assoc RXON */
353 iwlagn_update_qos(priv, ctx);
354
355 /*
356 * We'll run into this code path when beaconing is
357 * enabled, but then we also need to send the beacon
358 * to the device.
359 */
360 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
361 ret = iwlagn_update_beacon(priv, ctx->vif);
362 if (ret) {
363 IWL_ERR(priv,
364 "Error sending required beacon (%d)!\n",
365 ret);
366 return ret;
367 }
368 }
369
370 priv->start_calib = 0;
371 /*
372 * Apply the new configuration.
373 *
374 * Associated RXON doesn't clear the station table in uCode,
375 * so we don't need to restore stations etc. after this.
376 */
377 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
378 sizeof(struct iwl_rxon_cmd), &ctx->staging);
379 if (ret) {
380 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
381 return ret;
382 }
383 memcpy(active, &ctx->staging, sizeof(*active));
384
385 /* IBSS beacon needs to be sent after setting assoc */
386 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
387 if (iwlagn_update_beacon(priv, ctx->vif))
388 IWL_ERR(priv, "Error sending IBSS beacon\n");
389 iwl_init_sensitivity(priv);
390
391 /*
392 * If we issue a new RXON command which required a tune then
393 * we must send a new TXPOWER command or we won't be able to
394 * Tx any frames.
395 *
396 * It's expected we set power here if channel is changing.
397 */
398 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
399 if (ret) {
400 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
401 return ret;
402 }
403
404 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
405 cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
406 ieee80211_request_smps(ctx->vif,
407 cfg(priv)->ht_params->smps_mode);
408
409 return 0;
410 }
411
412 int iwlagn_set_pan_params(struct iwl_priv *priv)
413 {
414 struct iwl_wipan_params_cmd cmd;
415 struct iwl_rxon_context *ctx_bss, *ctx_pan;
416 int slot0 = 300, slot1 = 0;
417 int ret;
418
419 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
420 return 0;
421
422 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
423
424 lockdep_assert_held(&priv->mutex);
425
426 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
427 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
428
429 /*
430 * If the PAN context is inactive, then we don't need
431 * to update the PAN parameters, the last thing we'll
432 * have done before it goes inactive is making the PAN
433 * parameters be WLAN-only.
434 */
435 if (!ctx_pan->is_active)
436 return 0;
437
438 memset(&cmd, 0, sizeof(cmd));
439
440 /* only 2 slots are currently allowed */
441 cmd.num_slots = 2;
442
443 cmd.slots[0].type = 0; /* BSS */
444 cmd.slots[1].type = 1; /* PAN */
445
446 if (priv->hw_roc_setup) {
447 /* both contexts must be used for this to happen */
448 slot1 = IWL_MIN_SLOT_TIME;
449 slot0 = 3000;
450 } else if (ctx_bss->vif && ctx_pan->vif) {
451 int bcnint = ctx_pan->beacon_int;
452 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
453
454 /* should be set, but seems unused?? */
455 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
456
457 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
458 bcnint &&
459 bcnint != ctx_bss->beacon_int) {
460 IWL_ERR(priv,
461 "beacon intervals don't match (%d, %d)\n",
462 ctx_bss->beacon_int, ctx_pan->beacon_int);
463 } else
464 bcnint = max_t(int, bcnint,
465 ctx_bss->beacon_int);
466 if (!bcnint)
467 bcnint = DEFAULT_BEACON_INTERVAL;
468 slot0 = bcnint / 2;
469 slot1 = bcnint - slot0;
470
471 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
472 (!ctx_bss->vif->bss_conf.idle &&
473 !ctx_bss->vif->bss_conf.assoc)) {
474 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
475 slot1 = IWL_MIN_SLOT_TIME;
476 } else if (!ctx_pan->vif->bss_conf.idle &&
477 !ctx_pan->vif->bss_conf.assoc) {
478 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
479 slot0 = IWL_MIN_SLOT_TIME;
480 }
481 } else if (ctx_pan->vif) {
482 slot0 = 0;
483 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
484 ctx_pan->beacon_int;
485 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
486
487 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
488 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
489 slot1 = IWL_MIN_SLOT_TIME;
490 }
491 }
492
493 cmd.slots[0].width = cpu_to_le16(slot0);
494 cmd.slots[1].width = cpu_to_le16(slot1);
495
496 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
497 sizeof(cmd), &cmd);
498 if (ret)
499 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
500
501 return ret;
502 }
503
504 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
505 struct iwl_ht_config *ht_conf,
506 struct iwl_rxon_context *ctx)
507 {
508 struct iwl_rxon_cmd *rxon = &ctx->staging;
509
510 if (!ctx->ht.enabled) {
511 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
512 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
513 RXON_FLG_HT40_PROT_MSK |
514 RXON_FLG_HT_PROT_MSK);
515 return;
516 }
517
518 /* FIXME: if the definition of ht.protection changed, the "translation"
519 * will be needed for rxon->flags
520 */
521 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
522 RXON_FLG_HT_OPERATING_MODE_POS);
523
524 /* Set up channel bandwidth:
525 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
526 /* clear the HT channel mode before set the mode */
527 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
528 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
529 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
530 /* pure ht40 */
531 if (ctx->ht.protection ==
532 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
533 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
534 /*
535 * Note: control channel is opposite of extension
536 * channel
537 */
538 switch (ctx->ht.extension_chan_offset) {
539 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
540 rxon->flags &=
541 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
542 break;
543 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
544 rxon->flags |=
545 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
546 break;
547 }
548 } else {
549 /*
550 * Note: control channel is opposite of extension
551 * channel
552 */
553 switch (ctx->ht.extension_chan_offset) {
554 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
555 rxon->flags &=
556 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
557 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
558 break;
559 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
560 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
561 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
562 break;
563 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
564 default:
565 /*
566 * channel location only valid if in Mixed
567 * mode
568 */
569 IWL_ERR(priv,
570 "invalid extension channel offset\n");
571 break;
572 }
573 }
574 } else {
575 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
576 }
577
578 iwlagn_set_rxon_chain(priv, ctx);
579
580 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
581 "extension channel offset 0x%x\n",
582 le32_to_cpu(rxon->flags), ctx->ht.protection,
583 ctx->ht.extension_chan_offset);
584 }
585
586 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
587 {
588 struct iwl_rxon_context *ctx;
589
590 for_each_context(priv, ctx)
591 _iwl_set_rxon_ht(priv, ht_conf, ctx);
592 }
593
594 /**
595 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
596 * @ch: requested channel as a pointer to struct ieee80211_channel
597
598 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
599 * in the staging RXON flag structure based on the ch->band
600 */
601 void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
602 struct iwl_rxon_context *ctx)
603 {
604 enum ieee80211_band band = ch->band;
605 u16 channel = ch->hw_value;
606
607 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
608 (priv->band == band))
609 return;
610
611 ctx->staging.channel = cpu_to_le16(channel);
612 if (band == IEEE80211_BAND_5GHZ)
613 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
614 else
615 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
616
617 priv->band = band;
618
619 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
620
621 }
622
623 void iwl_set_flags_for_band(struct iwl_priv *priv,
624 struct iwl_rxon_context *ctx,
625 enum ieee80211_band band,
626 struct ieee80211_vif *vif)
627 {
628 if (band == IEEE80211_BAND_5GHZ) {
629 ctx->staging.flags &=
630 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
631 | RXON_FLG_CCK_MSK);
632 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
633 } else {
634 /* Copied from iwl_post_associate() */
635 if (vif && vif->bss_conf.use_short_slot)
636 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
637 else
638 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
639
640 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
641 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
642 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
643 }
644 }
645
646 static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
647 struct iwl_rxon_context *ctx, int hw_decrypt)
648 {
649 struct iwl_rxon_cmd *rxon = &ctx->staging;
650
651 if (hw_decrypt)
652 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
653 else
654 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
655
656 }
657
658 /* validate RXON structure is valid */
659 static int iwl_check_rxon_cmd(struct iwl_priv *priv,
660 struct iwl_rxon_context *ctx)
661 {
662 struct iwl_rxon_cmd *rxon = &ctx->staging;
663 u32 errors = 0;
664
665 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
666 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
667 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
668 errors |= BIT(0);
669 }
670 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
671 IWL_WARN(priv, "check 2.4G: wrong radar\n");
672 errors |= BIT(1);
673 }
674 } else {
675 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
676 IWL_WARN(priv, "check 5.2G: not short slot!\n");
677 errors |= BIT(2);
678 }
679 if (rxon->flags & RXON_FLG_CCK_MSK) {
680 IWL_WARN(priv, "check 5.2G: CCK!\n");
681 errors |= BIT(3);
682 }
683 }
684 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
685 IWL_WARN(priv, "mac/bssid mcast!\n");
686 errors |= BIT(4);
687 }
688
689 /* make sure basic rates 6Mbps and 1Mbps are supported */
690 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
691 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
692 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
693 errors |= BIT(5);
694 }
695
696 if (le16_to_cpu(rxon->assoc_id) > 2007) {
697 IWL_WARN(priv, "aid > 2007\n");
698 errors |= BIT(6);
699 }
700
701 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
702 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
703 IWL_WARN(priv, "CCK and short slot\n");
704 errors |= BIT(7);
705 }
706
707 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
708 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
709 IWL_WARN(priv, "CCK and auto detect");
710 errors |= BIT(8);
711 }
712
713 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
714 RXON_FLG_TGG_PROTECT_MSK)) ==
715 RXON_FLG_TGG_PROTECT_MSK) {
716 IWL_WARN(priv, "TGg but no auto-detect\n");
717 errors |= BIT(9);
718 }
719
720 if (rxon->channel == 0) {
721 IWL_WARN(priv, "zero channel is invalid\n");
722 errors |= BIT(10);
723 }
724
725 WARN(errors, "Invalid RXON (%#x), channel %d",
726 errors, le16_to_cpu(rxon->channel));
727
728 return errors ? -EINVAL : 0;
729 }
730
731 /**
732 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
733 * @priv: staging_rxon is compared to active_rxon
734 *
735 * If the RXON structure is changing enough to require a new tune,
736 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
737 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
738 */
739 static int iwl_full_rxon_required(struct iwl_priv *priv,
740 struct iwl_rxon_context *ctx)
741 {
742 const struct iwl_rxon_cmd *staging = &ctx->staging;
743 const struct iwl_rxon_cmd *active = &ctx->active;
744
745 #define CHK(cond) \
746 if ((cond)) { \
747 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
748 return 1; \
749 }
750
751 #define CHK_NEQ(c1, c2) \
752 if ((c1) != (c2)) { \
753 IWL_DEBUG_INFO(priv, "need full RXON - " \
754 #c1 " != " #c2 " - %d != %d\n", \
755 (c1), (c2)); \
756 return 1; \
757 }
758
759 /* These items are only settable from the full RXON command */
760 CHK(!iwl_is_associated_ctx(ctx));
761 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
762 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
763 CHK(compare_ether_addr(staging->wlap_bssid_addr,
764 active->wlap_bssid_addr));
765 CHK_NEQ(staging->dev_type, active->dev_type);
766 CHK_NEQ(staging->channel, active->channel);
767 CHK_NEQ(staging->air_propagation, active->air_propagation);
768 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
769 active->ofdm_ht_single_stream_basic_rates);
770 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
771 active->ofdm_ht_dual_stream_basic_rates);
772 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
773 active->ofdm_ht_triple_stream_basic_rates);
774 CHK_NEQ(staging->assoc_id, active->assoc_id);
775
776 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
777 * be updated with the RXON_ASSOC command -- however only some
778 * flag transitions are allowed using RXON_ASSOC */
779
780 /* Check if we are not switching bands */
781 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
782 active->flags & RXON_FLG_BAND_24G_MSK);
783
784 /* Check if we are switching association toggle */
785 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
786 active->filter_flags & RXON_FILTER_ASSOC_MSK);
787
788 #undef CHK
789 #undef CHK_NEQ
790
791 return 0;
792 }
793
794 /**
795 * iwlagn_commit_rxon - commit staging_rxon to hardware
796 *
797 * The RXON command in staging_rxon is committed to the hardware and
798 * the active_rxon structure is updated with the new data. This
799 * function correctly transitions out of the RXON_ASSOC_MSK state if
800 * a HW tune is required based on the RXON structure changes.
801 *
802 * The connect/disconnect flow should be as the following:
803 *
804 * 1. make sure send RXON command with association bit unset if not connect
805 * this should include the channel and the band for the candidate
806 * to be connected to
807 * 2. Add Station before RXON association with the AP
808 * 3. RXON_timing has to send before RXON for connection
809 * 4. full RXON command - associated bit set
810 * 5. use RXON_ASSOC command to update any flags changes
811 */
812 int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
813 {
814 /* cast away the const for active_rxon in this function */
815 struct iwl_rxon_cmd *active = (void *)&ctx->active;
816 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
817 int ret;
818
819 lockdep_assert_held(&priv->mutex);
820
821 if (!iwl_is_alive(priv))
822 return -EBUSY;
823
824 /* This function hardcodes a bunch of dual-mode assumptions */
825 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
826
827 if (!ctx->is_active)
828 return 0;
829
830 /* always get timestamp with Rx frame */
831 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
832
833 /*
834 * force CTS-to-self frames protection if RTS-CTS is not preferred
835 * one aggregation protection method
836 */
837 if (!priv->hw_params.use_rts_for_aggregation)
838 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
839
840 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
841 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
842 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
843 else
844 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
845
846 iwl_print_rx_config_cmd(priv, ctx->ctxid);
847 ret = iwl_check_rxon_cmd(priv, ctx);
848 if (ret) {
849 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
850 return -EINVAL;
851 }
852
853 /*
854 * receive commit_rxon request
855 * abort any previous channel switch if still in process
856 */
857 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
858 (priv->switch_channel != ctx->staging.channel)) {
859 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
860 le16_to_cpu(priv->switch_channel));
861 iwl_chswitch_done(priv, false);
862 }
863
864 /*
865 * If we don't need to send a full RXON, we can use
866 * iwl_rxon_assoc_cmd which is used to reconfigure filter
867 * and other flags for the current radio configuration.
868 */
869 if (!iwl_full_rxon_required(priv, ctx)) {
870 ret = iwlagn_send_rxon_assoc(priv, ctx);
871 if (ret) {
872 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
873 return ret;
874 }
875
876 memcpy(active, &ctx->staging, sizeof(*active));
877 /*
878 * We do not commit tx power settings while channel changing,
879 * do it now if after settings changed.
880 */
881 iwl_set_tx_power(priv, priv->tx_power_next, false);
882
883 /* make sure we are in the right PS state */
884 iwl_power_update_mode(priv, true);
885
886 return 0;
887 }
888
889 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
890
891 IWL_DEBUG_INFO(priv,
892 "Going to commit RXON\n"
893 " * with%s RXON_FILTER_ASSOC_MSK\n"
894 " * channel = %d\n"
895 " * bssid = %pM\n",
896 (new_assoc ? "" : "out"),
897 le16_to_cpu(ctx->staging.channel),
898 ctx->staging.bssid_addr);
899
900 /*
901 * Always clear associated first, but with the correct config.
902 * This is required as for example station addition for the
903 * AP station must be done after the BSSID is set to correctly
904 * set up filters in the device.
905 */
906 ret = iwlagn_rxon_disconn(priv, ctx);
907 if (ret)
908 return ret;
909
910 ret = iwlagn_set_pan_params(priv);
911 if (ret)
912 return ret;
913
914 if (new_assoc)
915 return iwlagn_rxon_connect(priv, ctx);
916
917 return 0;
918 }
919
920 void iwlagn_config_ht40(struct ieee80211_conf *conf,
921 struct iwl_rxon_context *ctx)
922 {
923 if (conf_is_ht40_minus(conf)) {
924 ctx->ht.extension_chan_offset =
925 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
926 ctx->ht.is_40mhz = true;
927 } else if (conf_is_ht40_plus(conf)) {
928 ctx->ht.extension_chan_offset =
929 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
930 ctx->ht.is_40mhz = true;
931 } else {
932 ctx->ht.extension_chan_offset =
933 IEEE80211_HT_PARAM_CHA_SEC_NONE;
934 ctx->ht.is_40mhz = false;
935 }
936 }
937
938 int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
939 {
940 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
941 struct iwl_rxon_context *ctx;
942 struct ieee80211_conf *conf = &hw->conf;
943 struct ieee80211_channel *channel = conf->channel;
944 const struct iwl_channel_info *ch_info;
945 int ret = 0;
946
947 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
948
949 mutex_lock(&priv->mutex);
950
951 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
952 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
953 goto out;
954 }
955
956 if (!iwl_is_ready(priv)) {
957 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
958 goto out;
959 }
960
961 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
962 IEEE80211_CONF_CHANGE_CHANNEL)) {
963 /* mac80211 uses static for non-HT which is what we want */
964 priv->current_ht_config.smps = conf->smps_mode;
965
966 /*
967 * Recalculate chain counts.
968 *
969 * If monitor mode is enabled then mac80211 will
970 * set up the SM PS mode to OFF if an HT channel is
971 * configured.
972 */
973 for_each_context(priv, ctx)
974 iwlagn_set_rxon_chain(priv, ctx);
975 }
976
977 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
978 ch_info = iwl_get_channel_info(priv, channel->band,
979 channel->hw_value);
980 if (!is_channel_valid(ch_info)) {
981 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
982 ret = -EINVAL;
983 goto out;
984 }
985
986 for_each_context(priv, ctx) {
987 /* Configure HT40 channels */
988 if (ctx->ht.enabled != conf_is_ht(conf))
989 ctx->ht.enabled = conf_is_ht(conf);
990
991 if (ctx->ht.enabled) {
992 /* if HT40 is used, it should not change
993 * after associated except channel switch */
994 if (!ctx->ht.is_40mhz ||
995 !iwl_is_associated_ctx(ctx))
996 iwlagn_config_ht40(conf, ctx);
997 } else
998 ctx->ht.is_40mhz = false;
999
1000 /*
1001 * Default to no protection. Protection mode will
1002 * later be set from BSS config in iwl_ht_conf
1003 */
1004 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1005
1006 /* if we are switching from ht to 2.4 clear flags
1007 * from any ht related info since 2.4 does not
1008 * support ht */
1009 if (le16_to_cpu(ctx->staging.channel) !=
1010 channel->hw_value)
1011 ctx->staging.flags = 0;
1012
1013 iwl_set_rxon_channel(priv, channel, ctx);
1014 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1015
1016 iwl_set_flags_for_band(priv, ctx, channel->band,
1017 ctx->vif);
1018 }
1019
1020 iwl_update_bcast_stations(priv);
1021
1022 /*
1023 * The list of supported rates and rate mask can be different
1024 * for each band; since the band may have changed, reset
1025 * the rate mask to what mac80211 lists.
1026 */
1027 iwl_set_rate(priv);
1028 }
1029
1030 if (changed & (IEEE80211_CONF_CHANGE_PS |
1031 IEEE80211_CONF_CHANGE_IDLE)) {
1032 ret = iwl_power_update_mode(priv, false);
1033 if (ret)
1034 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1035 }
1036
1037 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1038 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1039 priv->tx_power_user_lmt, conf->power_level);
1040
1041 iwl_set_tx_power(priv, conf->power_level, false);
1042 }
1043
1044 for_each_context(priv, ctx) {
1045 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1046 continue;
1047 iwlagn_commit_rxon(priv, ctx);
1048 }
1049 out:
1050 mutex_unlock(&priv->mutex);
1051 IWL_DEBUG_MAC80211(priv, "leave\n");
1052
1053 return ret;
1054 }
1055
1056 static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1057 struct iwl_rxon_context *ctx,
1058 struct ieee80211_bss_conf *bss_conf)
1059 {
1060 struct ieee80211_vif *vif = ctx->vif;
1061 struct iwl_rxon_context *tmp;
1062 struct ieee80211_sta *sta;
1063 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1064 struct ieee80211_sta_ht_cap *ht_cap;
1065 bool need_multiple;
1066
1067 lockdep_assert_held(&priv->mutex);
1068
1069 switch (vif->type) {
1070 case NL80211_IFTYPE_STATION:
1071 rcu_read_lock();
1072 sta = ieee80211_find_sta(vif, bss_conf->bssid);
1073 if (!sta) {
1074 /*
1075 * If at all, this can only happen through a race
1076 * when the AP disconnects us while we're still
1077 * setting up the connection, in that case mac80211
1078 * will soon tell us about that.
1079 */
1080 need_multiple = false;
1081 rcu_read_unlock();
1082 break;
1083 }
1084
1085 ht_cap = &sta->ht_cap;
1086
1087 need_multiple = true;
1088
1089 /*
1090 * If the peer advertises no support for receiving 2 and 3
1091 * stream MCS rates, it can't be transmitting them either.
1092 */
1093 if (ht_cap->mcs.rx_mask[1] == 0 &&
1094 ht_cap->mcs.rx_mask[2] == 0) {
1095 need_multiple = false;
1096 } else if (!(ht_cap->mcs.tx_params &
1097 IEEE80211_HT_MCS_TX_DEFINED)) {
1098 /* If it can't TX MCS at all ... */
1099 need_multiple = false;
1100 } else if (ht_cap->mcs.tx_params &
1101 IEEE80211_HT_MCS_TX_RX_DIFF) {
1102 int maxstreams;
1103
1104 /*
1105 * But if it can receive them, it might still not
1106 * be able to transmit them, which is what we need
1107 * to check here -- so check the number of streams
1108 * it advertises for TX (if different from RX).
1109 */
1110
1111 maxstreams = (ht_cap->mcs.tx_params &
1112 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1113 maxstreams >>=
1114 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1115 maxstreams += 1;
1116
1117 if (maxstreams <= 1)
1118 need_multiple = false;
1119 }
1120
1121 rcu_read_unlock();
1122 break;
1123 case NL80211_IFTYPE_ADHOC:
1124 /* currently */
1125 need_multiple = false;
1126 break;
1127 default:
1128 /* only AP really */
1129 need_multiple = true;
1130 break;
1131 }
1132
1133 ctx->ht_need_multiple_chains = need_multiple;
1134
1135 if (!need_multiple) {
1136 /* check all contexts */
1137 for_each_context(priv, tmp) {
1138 if (!tmp->vif)
1139 continue;
1140 if (tmp->ht_need_multiple_chains) {
1141 need_multiple = true;
1142 break;
1143 }
1144 }
1145 }
1146
1147 ht_conf->single_chain_sufficient = !need_multiple;
1148 }
1149
1150 static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1151 {
1152 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1153 int ret;
1154
1155 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1156 iwl_is_any_associated(priv)) {
1157 struct iwl_calib_chain_noise_reset_cmd cmd;
1158
1159 /* clear data for chain noise calibration algorithm */
1160 data->chain_noise_a = 0;
1161 data->chain_noise_b = 0;
1162 data->chain_noise_c = 0;
1163 data->chain_signal_a = 0;
1164 data->chain_signal_b = 0;
1165 data->chain_signal_c = 0;
1166 data->beacon_count = 0;
1167
1168 memset(&cmd, 0, sizeof(cmd));
1169 iwl_set_calib_hdr(&cmd.hdr,
1170 priv->phy_calib_chain_noise_reset_cmd);
1171 ret = iwl_dvm_send_cmd_pdu(priv,
1172 REPLY_PHY_CALIBRATION_CMD,
1173 CMD_SYNC, sizeof(cmd), &cmd);
1174 if (ret)
1175 IWL_ERR(priv,
1176 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1177 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1178 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1179 }
1180 }
1181
1182 void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1183 struct ieee80211_vif *vif,
1184 struct ieee80211_bss_conf *bss_conf,
1185 u32 changes)
1186 {
1187 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1188 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1189 int ret;
1190 bool force = false;
1191
1192 mutex_lock(&priv->mutex);
1193
1194 if (unlikely(!iwl_is_ready(priv))) {
1195 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1196 mutex_unlock(&priv->mutex);
1197 return;
1198 }
1199
1200 if (unlikely(!ctx->vif)) {
1201 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
1202 mutex_unlock(&priv->mutex);
1203 return;
1204 }
1205
1206 if (changes & BSS_CHANGED_BEACON_INT)
1207 force = true;
1208
1209 if (changes & BSS_CHANGED_QOS) {
1210 ctx->qos_data.qos_active = bss_conf->qos;
1211 iwlagn_update_qos(priv, ctx);
1212 }
1213
1214 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1215 if (vif->bss_conf.use_short_preamble)
1216 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1217 else
1218 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1219
1220 if (changes & BSS_CHANGED_ASSOC) {
1221 if (bss_conf->assoc) {
1222 priv->timestamp = bss_conf->last_tsf;
1223 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1224 } else {
1225 /*
1226 * If we disassociate while there are pending
1227 * frames, just wake up the queues and let the
1228 * frames "escape" ... This shouldn't really
1229 * be happening to start with, but we should
1230 * not get stuck in this case either since it
1231 * can happen if userspace gets confused.
1232 */
1233 iwlagn_lift_passive_no_rx(priv);
1234
1235 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1236
1237 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1238 priv->have_rekey_data = false;
1239 }
1240
1241 iwlagn_bt_coex_rssi_monitor(priv);
1242 }
1243
1244 if (ctx->ht.enabled) {
1245 ctx->ht.protection = bss_conf->ht_operation_mode &
1246 IEEE80211_HT_OP_MODE_PROTECTION;
1247 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1248 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1249 iwlagn_check_needed_chains(priv, ctx, bss_conf);
1250 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1251 }
1252
1253 iwlagn_set_rxon_chain(priv, ctx);
1254
1255 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1256 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1257 else
1258 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1259
1260 if (bss_conf->use_cts_prot)
1261 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1262 else
1263 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1264
1265 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1266
1267 if (vif->type == NL80211_IFTYPE_AP ||
1268 vif->type == NL80211_IFTYPE_ADHOC) {
1269 if (vif->bss_conf.enable_beacon) {
1270 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1271 priv->beacon_ctx = ctx;
1272 } else {
1273 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1274 priv->beacon_ctx = NULL;
1275 }
1276 }
1277
1278 /*
1279 * If the ucode decides to do beacon filtering before
1280 * association, it will lose beacons that are needed
1281 * before sending frames out on passive channels. This
1282 * causes association failures on those channels. Enable
1283 * receiving beacons in such cases.
1284 */
1285
1286 if (vif->type == NL80211_IFTYPE_STATION) {
1287 if (!bss_conf->assoc)
1288 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1289 else
1290 ctx->staging.filter_flags &=
1291 ~RXON_FILTER_BCON_AWARE_MSK;
1292 }
1293
1294 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1295 iwlagn_commit_rxon(priv, ctx);
1296
1297 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1298 /*
1299 * The chain noise calibration will enable PM upon
1300 * completion. If calibration has already been run
1301 * then we need to enable power management here.
1302 */
1303 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1304 iwl_power_update_mode(priv, false);
1305
1306 /* Enable RX differential gain and sensitivity calibrations */
1307 if (!priv->disable_chain_noise_cal)
1308 iwlagn_chain_noise_reset(priv);
1309 priv->start_calib = 1;
1310 }
1311
1312 if (changes & BSS_CHANGED_IBSS) {
1313 ret = iwlagn_manage_ibss_station(priv, vif,
1314 bss_conf->ibss_joined);
1315 if (ret)
1316 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1317 bss_conf->ibss_joined ? "add" : "remove",
1318 bss_conf->bssid);
1319 }
1320
1321 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1322 priv->beacon_ctx) {
1323 if (iwlagn_update_beacon(priv, vif))
1324 IWL_ERR(priv, "Error sending IBSS beacon\n");
1325 }
1326
1327 mutex_unlock(&priv->mutex);
1328 }
1329
1330 void iwlagn_post_scan(struct iwl_priv *priv)
1331 {
1332 struct iwl_rxon_context *ctx;
1333
1334 /*
1335 * We do not commit power settings while scan is pending,
1336 * do it now if the settings changed.
1337 */
1338 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1339 iwl_set_tx_power(priv, priv->tx_power_next, false);
1340
1341 /*
1342 * Since setting the RXON may have been deferred while
1343 * performing the scan, fire one off if needed
1344 */
1345 for_each_context(priv, ctx)
1346 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1347 iwlagn_commit_rxon(priv, ctx);
1348
1349 iwlagn_set_pan_params(priv);
1350 }
This page took 0.056825 seconds and 6 git commands to generate.