blob: 88a7f3a1056c99997637f089f19547f1e716ebef [file] [log] [blame]
Johannes Berg2295c662010-10-23 09:15:41 -07001/******************************************************************************
2 *
Wey-Yi Guyfb4961d2012-01-06 13:16:33 -08003 * Copyright(c) 2003 - 2012 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
Meenakshi Venkataraman55620922012-03-15 13:27:02 -070027#include <linux/etherdevice.h>
Johannes Berg2295c662010-10-23 09:15:41 -070028#include "iwl-dev.h"
29#include "iwl-agn.h"
Johannes Berg2295c662010-10-23 09:15:41 -070030#include "iwl-core.h"
31#include "iwl-agn-calib.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070032#include "iwl-trans.h"
Emmanuel Grumbach48f20d32011-08-25 23:10:36 -070033#include "iwl-shared.h"
Johannes Berg2295c662010-10-23 09:15:41 -070034
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070035/*
36 * initialize rxon structure with default values from eeprom
37 */
38void iwl_connection_init_rx_config(struct iwl_priv *priv,
39 struct iwl_rxon_context *ctx)
40{
41 const struct iwl_channel_info *ch_info;
42
43 memset(&ctx->staging, 0, sizeof(ctx->staging));
44
45 if (!ctx->vif) {
46 ctx->staging.dev_type = ctx->unused_devtype;
47 } else
48 switch (ctx->vif->type) {
49 case NL80211_IFTYPE_AP:
50 ctx->staging.dev_type = ctx->ap_devtype;
51 break;
52
53 case NL80211_IFTYPE_STATION:
54 ctx->staging.dev_type = ctx->station_devtype;
55 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
56 break;
57
58 case NL80211_IFTYPE_ADHOC:
59 ctx->staging.dev_type = ctx->ibss_devtype;
60 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
61 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
62 RXON_FILTER_ACCEPT_GRP_MSK;
63 break;
64
65 default:
66 IWL_ERR(priv, "Unsupported interface type %d\n",
67 ctx->vif->type);
68 break;
69 }
70
71#if 0
72 /* TODO: Figure out when short_preamble would be set and cache from
73 * that */
74 if (!hw_to_local(priv->hw)->short_preamble)
75 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
76 else
77 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
78#endif
79
80 ch_info = iwl_get_channel_info(priv, priv->band,
81 le16_to_cpu(ctx->active.channel));
82
83 if (!ch_info)
84 ch_info = &priv->channel_info[0];
85
86 ctx->staging.channel = cpu_to_le16(ch_info->channel);
87 priv->band = ch_info->band;
88
89 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
90
91 ctx->staging.ofdm_basic_rates =
92 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
93 ctx->staging.cck_basic_rates =
94 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
95
96 /* clear both MIX and PURE40 mode flag */
97 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
98 RXON_FLG_CHANNEL_MODE_PURE_40);
99 if (ctx->vif)
100 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
101
102 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
103 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
104 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
105}
106
Johannes Berg2295c662010-10-23 09:15:41 -0700107static int iwlagn_disable_bss(struct iwl_priv *priv,
108 struct iwl_rxon_context *ctx,
109 struct iwl_rxon_cmd *send)
110{
111 __le32 old_filter = send->filter_flags;
112 int ret;
113
114 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800115 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700116 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700117
118 send->filter_flags = old_filter;
119
120 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800121 IWL_DEBUG_QUIET_RFKILL(priv,
122 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
Johannes Berg2295c662010-10-23 09:15:41 -0700123
124 return ret;
125}
126
127static int iwlagn_disable_pan(struct iwl_priv *priv,
128 struct iwl_rxon_context *ctx,
129 struct iwl_rxon_cmd *send)
130{
Johannes Berg311dce72011-01-04 16:22:01 -0800131 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -0700132 __le32 old_filter = send->filter_flags;
133 u8 old_dev_type = send->dev_type;
134 int ret;
Johannes Bergdb662d42012-03-15 13:26:44 -0700135 static const u8 deactivate_cmd[] = {
136 REPLY_WIPAN_DEACTIVATION_COMPLETE
137 };
Johannes Berg2295c662010-10-23 09:15:41 -0700138
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800139 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
Johannes Bergdb662d42012-03-15 13:26:44 -0700140 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800141 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -0800142
Johannes Berg2295c662010-10-23 09:15:41 -0700143 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
144 send->dev_type = RXON_DEV_TYPE_P2P;
Johannes Berge10a0532012-03-06 13:30:39 -0800145 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700146 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700147
148 send->filter_flags = old_filter;
149 send->dev_type = old_dev_type;
150
Johannes Berg311dce72011-01-04 16:22:01 -0800151 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -0700152 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800153 iwl_remove_notification(&priv->notif_wait, &disable_wait);
Johannes Berg311dce72011-01-04 16:22:01 -0800154 } else {
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800155 ret = iwl_wait_notification(&priv->notif_wait,
156 &disable_wait, HZ);
Johannes Berga8674a12011-04-13 03:14:48 -0700157 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -0800158 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
159 }
Johannes Berg2295c662010-10-23 09:15:41 -0700160
161 return ret;
162}
163
Johannes Berg2b9253d2011-05-27 08:40:26 -0700164static int iwlagn_disconn_pan(struct iwl_priv *priv,
165 struct iwl_rxon_context *ctx,
166 struct iwl_rxon_cmd *send)
167{
168 __le32 old_filter = send->filter_flags;
169 int ret;
170
171 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800172 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700173 sizeof(*send), send);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700174
175 send->filter_flags = old_filter;
176
177 return ret;
178}
179
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800180static void iwlagn_update_qos(struct iwl_priv *priv,
181 struct iwl_rxon_context *ctx)
182{
183 int ret;
184
185 if (!ctx->is_active)
186 return;
187
188 ctx->qos_data.def_qos_parm.qos_flags = 0;
189
190 if (ctx->qos_data.qos_active)
191 ctx->qos_data.def_qos_parm.qos_flags |=
192 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
193
194 if (ctx->ht.enabled)
195 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
196
Emmanuel Grumbach0dcf50c2011-11-10 06:55:23 -0800197 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800198 ctx->qos_data.qos_active,
199 ctx->qos_data.def_qos_parm.qos_flags);
200
Johannes Berge10a0532012-03-06 13:30:39 -0800201 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800202 sizeof(struct iwl_qosparam_cmd),
203 &ctx->qos_data.def_qos_parm);
204 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800205 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800206}
207
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700208static int iwlagn_update_beacon(struct iwl_priv *priv,
209 struct ieee80211_vif *vif)
210{
Johannes Bergb1eea292012-03-06 13:30:42 -0800211 lockdep_assert_held(&priv->mutex);
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700212
213 dev_kfree_skb(priv->beacon_skb);
214 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
215 if (!priv->beacon_skb)
216 return -ENOMEM;
217 return iwlagn_send_beacon_cmd(priv);
218}
219
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700220static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
221 struct iwl_rxon_context *ctx)
222{
223 int ret = 0;
Wey-Yi Guy89e746b2011-04-19 16:52:58 -0700224 struct iwl_rxon_assoc_cmd rxon_assoc;
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700225 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
226 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
227
228 if ((rxon1->flags == rxon2->flags) &&
229 (rxon1->filter_flags == rxon2->filter_flags) &&
230 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
231 (rxon1->ofdm_ht_single_stream_basic_rates ==
232 rxon2->ofdm_ht_single_stream_basic_rates) &&
233 (rxon1->ofdm_ht_dual_stream_basic_rates ==
234 rxon2->ofdm_ht_dual_stream_basic_rates) &&
235 (rxon1->ofdm_ht_triple_stream_basic_rates ==
236 rxon2->ofdm_ht_triple_stream_basic_rates) &&
237 (rxon1->acquisition_data == rxon2->acquisition_data) &&
238 (rxon1->rx_chain == rxon2->rx_chain) &&
239 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
240 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
241 return 0;
242 }
243
244 rxon_assoc.flags = ctx->staging.flags;
245 rxon_assoc.filter_flags = ctx->staging.filter_flags;
246 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
247 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
248 rxon_assoc.reserved1 = 0;
249 rxon_assoc.reserved2 = 0;
250 rxon_assoc.reserved3 = 0;
251 rxon_assoc.ofdm_ht_single_stream_basic_rates =
252 ctx->staging.ofdm_ht_single_stream_basic_rates;
253 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
254 ctx->staging.ofdm_ht_dual_stream_basic_rates;
255 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
256 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
257 ctx->staging.ofdm_ht_triple_stream_basic_rates;
258 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
259
Johannes Berge10a0532012-03-06 13:30:39 -0800260 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700261 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700262 return ret;
263}
264
Meenakshi Venkataramandff96c12012-03-15 13:26:59 -0700265static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
266{
267 u16 new_val;
268 u16 beacon_factor;
269
270 /*
271 * If mac80211 hasn't given us a beacon interval, program
272 * the default into the device (not checking this here
273 * would cause the adjustment below to return the maximum
274 * value, which may break PAN.)
275 */
276 if (!beacon_val)
277 return DEFAULT_BEACON_INTERVAL;
278
279 /*
280 * If the beacon interval we obtained from the peer
281 * is too large, we'll have to wake up more often
282 * (and in IBSS case, we'll beacon too much)
283 *
284 * For example, if max_beacon_val is 4096, and the
285 * requested beacon interval is 7000, we'll have to
286 * use 3500 to be able to wake up on the beacons.
287 *
288 * This could badly influence beacon detection stats.
289 */
290
291 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
292 new_val = beacon_val / beacon_factor;
293
294 if (!new_val)
295 new_val = max_beacon_val;
296
297 return new_val;
298}
299
300static int iwl_send_rxon_timing(struct iwl_priv *priv,
301 struct iwl_rxon_context *ctx)
302{
303 u64 tsf;
304 s32 interval_tm, rem;
305 struct ieee80211_conf *conf = NULL;
306 u16 beacon_int;
307 struct ieee80211_vif *vif = ctx->vif;
308
309 conf = &priv->hw->conf;
310
311 lockdep_assert_held(&priv->mutex);
312
313 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
314
315 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
316 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
317
318 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
319
320 /*
321 * TODO: For IBSS we need to get atim_window from mac80211,
322 * for now just always use 0
323 */
324 ctx->timing.atim_window = 0;
325
326 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
327 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
328 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
329 priv->contexts[IWL_RXON_CTX_BSS].vif &&
330 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
331 ctx->timing.beacon_interval =
332 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
333 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
334 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
335 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
336 priv->contexts[IWL_RXON_CTX_PAN].vif &&
337 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
338 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
339 !ctx->vif->bss_conf.beacon_int)) {
340 ctx->timing.beacon_interval =
341 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
342 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
343 } else {
344 beacon_int = iwl_adjust_beacon_interval(beacon_int,
345 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
346 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
347 }
348
349 ctx->beacon_int = beacon_int;
350
351 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
352 interval_tm = beacon_int * TIME_UNIT;
353 rem = do_div(tsf, interval_tm);
354 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
355
356 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
357
358 IWL_DEBUG_ASSOC(priv,
359 "beacon interval %d beacon timer %d beacon tim %d\n",
360 le16_to_cpu(ctx->timing.beacon_interval),
361 le32_to_cpu(ctx->timing.beacon_init_val),
362 le16_to_cpu(ctx->timing.atim_window));
363
364 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
365 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
366}
367
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700368static int iwlagn_rxon_disconn(struct iwl_priv *priv,
369 struct iwl_rxon_context *ctx)
370{
371 int ret;
372 struct iwl_rxon_cmd *active = (void *)&ctx->active;
373
Johannes Berg2b9253d2011-05-27 08:40:26 -0700374 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700375 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700376 } else {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700377 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700378 if (ret)
379 return ret;
380 if (ctx->vif) {
381 ret = iwl_send_rxon_timing(priv, ctx);
382 if (ret) {
383 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
384 return ret;
385 }
386 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
387 }
388 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700389 if (ret)
390 return ret;
391
392 /*
393 * Un-assoc RXON clears the station table and WEP
394 * keys, so we have to restore those afterwards.
395 */
396 iwl_clear_ucode_stations(priv, ctx);
Johannes Bergf775aa02011-06-22 06:34:09 -0700397 /* update -- might need P2P now */
398 iwl_update_bcast_station(priv, ctx);
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700399 iwl_restore_stations(priv, ctx);
400 ret = iwl_restore_default_wep_keys(priv, ctx);
401 if (ret) {
402 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
403 return ret;
404 }
405
406 memcpy(active, &ctx->staging, sizeof(*active));
407 return 0;
408}
409
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700410static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
411{
412 int ret;
413 s8 prev_tx_power;
414 bool defer;
415 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
416
Dor Shaishbfb45f52012-03-26 08:20:55 -0700417 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
418 return 0;
419
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700420 lockdep_assert_held(&priv->mutex);
421
422 if (priv->tx_power_user_lmt == tx_power && !force)
423 return 0;
424
425 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
426 IWL_WARN(priv,
427 "Requested user TXPOWER %d below lower limit %d.\n",
428 tx_power,
429 IWLAGN_TX_POWER_TARGET_POWER_MIN);
430 return -EINVAL;
431 }
432
433 if (tx_power > priv->tx_power_device_lmt) {
434 IWL_WARN(priv,
435 "Requested user TXPOWER %d above upper limit %d.\n",
436 tx_power, priv->tx_power_device_lmt);
437 return -EINVAL;
438 }
439
440 if (!iwl_is_ready_rf(priv))
441 return -EIO;
442
443 /* scan complete and commit_rxon use tx_power_next value,
444 * it always need to be updated for newest request */
445 priv->tx_power_next = tx_power;
446
447 /* do not set tx power when scanning or channel changing */
448 defer = test_bit(STATUS_SCANNING, &priv->status) ||
449 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
450 if (defer && !force) {
451 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
452 return 0;
453 }
454
455 prev_tx_power = priv->tx_power_user_lmt;
456 priv->tx_power_user_lmt = tx_power;
457
458 ret = iwlagn_send_tx_power(priv);
459
460 /* if fail to set tx_power, restore the orig. tx power */
461 if (ret) {
462 priv->tx_power_user_lmt = prev_tx_power;
463 priv->tx_power_next = prev_tx_power;
464 }
465 return ret;
466}
467
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700468static int iwlagn_rxon_connect(struct iwl_priv *priv,
469 struct iwl_rxon_context *ctx)
470{
471 int ret;
472 struct iwl_rxon_cmd *active = (void *)&ctx->active;
473
474 /* RXON timing must be before associated RXON */
Johannes Berg2b9253d2011-05-27 08:40:26 -0700475 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
476 ret = iwl_send_rxon_timing(priv, ctx);
477 if (ret) {
478 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
479 return ret;
480 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700481 }
482 /* QoS info may be cleared by previous un-assoc RXON */
483 iwlagn_update_qos(priv, ctx);
484
485 /*
486 * We'll run into this code path when beaconing is
487 * enabled, but then we also need to send the beacon
488 * to the device.
489 */
490 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
491 ret = iwlagn_update_beacon(priv, ctx->vif);
492 if (ret) {
493 IWL_ERR(priv,
494 "Error sending required beacon (%d)!\n",
495 ret);
496 return ret;
497 }
498 }
499
500 priv->start_calib = 0;
501 /*
502 * Apply the new configuration.
503 *
504 * Associated RXON doesn't clear the station table in uCode,
505 * so we don't need to restore stations etc. after this.
506 */
Johannes Berge10a0532012-03-06 13:30:39 -0800507 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700508 sizeof(struct iwl_rxon_cmd), &ctx->staging);
509 if (ret) {
510 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
511 return ret;
512 }
513 memcpy(active, &ctx->staging, sizeof(*active));
514
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700515 /* IBSS beacon needs to be sent after setting assoc */
516 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
517 if (iwlagn_update_beacon(priv, ctx->vif))
518 IWL_ERR(priv, "Error sending IBSS beacon\n");
519 iwl_init_sensitivity(priv);
520
521 /*
522 * If we issue a new RXON command which required a tune then
523 * we must send a new TXPOWER command or we won't be able to
524 * Tx any frames.
525 *
526 * It's expected we set power here if channel is changing.
527 */
528 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
529 if (ret) {
530 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
531 return ret;
532 }
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700533
Stanislaw Gruszka107ef972011-10-12 10:16:35 +0200534 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
Don Fry38622412011-12-16 07:07:36 -0800535 cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700536 ieee80211_request_smps(ctx->vif,
Don Fry38622412011-12-16 07:07:36 -0800537 cfg(priv)->ht_params->smps_mode);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700538
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700539 return 0;
540}
541
Wey-Yi Guye505c432011-07-07 08:27:41 -0700542int iwlagn_set_pan_params(struct iwl_priv *priv)
543{
544 struct iwl_wipan_params_cmd cmd;
545 struct iwl_rxon_context *ctx_bss, *ctx_pan;
546 int slot0 = 300, slot1 = 0;
547 int ret;
548
Johannes Berga18f61b2012-03-15 13:26:53 -0700549 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
Wey-Yi Guye505c432011-07-07 08:27:41 -0700550 return 0;
551
552 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
553
Johannes Bergb1eea292012-03-06 13:30:42 -0800554 lockdep_assert_held(&priv->mutex);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700555
556 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
557 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
558
559 /*
560 * If the PAN context is inactive, then we don't need
561 * to update the PAN parameters, the last thing we'll
562 * have done before it goes inactive is making the PAN
563 * parameters be WLAN-only.
564 */
565 if (!ctx_pan->is_active)
566 return 0;
567
568 memset(&cmd, 0, sizeof(cmd));
569
570 /* only 2 slots are currently allowed */
571 cmd.num_slots = 2;
572
573 cmd.slots[0].type = 0; /* BSS */
574 cmd.slots[1].type = 1; /* PAN */
575
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700576 if (priv->hw_roc_setup) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700577 /* both contexts must be used for this to happen */
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700578 slot1 = IWL_MIN_SLOT_TIME;
579 slot0 = 3000;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700580 } else if (ctx_bss->vif && ctx_pan->vif) {
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700581 int bcnint = ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700582 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
583
584 /* should be set, but seems unused?? */
585 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
586
587 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
588 bcnint &&
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700589 bcnint != ctx_bss->beacon_int) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700590 IWL_ERR(priv,
591 "beacon intervals don't match (%d, %d)\n",
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700592 ctx_bss->beacon_int, ctx_pan->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700593 } else
594 bcnint = max_t(int, bcnint,
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700595 ctx_bss->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700596 if (!bcnint)
597 bcnint = DEFAULT_BEACON_INTERVAL;
598 slot0 = bcnint / 2;
599 slot1 = bcnint - slot0;
600
Don Fry83626402012-03-07 09:52:37 -0800601 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
Wey-Yi Guye505c432011-07-07 08:27:41 -0700602 (!ctx_bss->vif->bss_conf.idle &&
603 !ctx_bss->vif->bss_conf.assoc)) {
604 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
605 slot1 = IWL_MIN_SLOT_TIME;
606 } else if (!ctx_pan->vif->bss_conf.idle &&
607 !ctx_pan->vif->bss_conf.assoc) {
Johannes Berg325a7dd2011-09-22 15:14:55 -0700608 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700609 slot0 = IWL_MIN_SLOT_TIME;
610 }
611 } else if (ctx_pan->vif) {
612 slot0 = 0;
613 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700614 ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700615 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
616
Don Fry83626402012-03-07 09:52:37 -0800617 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700618 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
619 slot1 = IWL_MIN_SLOT_TIME;
620 }
621 }
622
623 cmd.slots[0].width = cpu_to_le16(slot0);
624 cmd.slots[1].width = cpu_to_le16(slot1);
625
Johannes Berge10a0532012-03-06 13:30:39 -0800626 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
Wey-Yi Guye505c432011-07-07 08:27:41 -0700627 sizeof(cmd), &cmd);
628 if (ret)
629 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
630
631 return ret;
632}
633
Meenakshi Venkataramandd641732012-03-13 16:25:38 -0700634static void _iwl_set_rxon_ht(struct iwl_priv *priv,
635 struct iwl_ht_config *ht_conf,
636 struct iwl_rxon_context *ctx)
637{
638 struct iwl_rxon_cmd *rxon = &ctx->staging;
639
640 if (!ctx->ht.enabled) {
641 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
642 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
643 RXON_FLG_HT40_PROT_MSK |
644 RXON_FLG_HT_PROT_MSK);
645 return;
646 }
647
648 /* FIXME: if the definition of ht.protection changed, the "translation"
649 * will be needed for rxon->flags
650 */
651 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
652 RXON_FLG_HT_OPERATING_MODE_POS);
653
654 /* Set up channel bandwidth:
655 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
656 /* clear the HT channel mode before set the mode */
657 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
658 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
659 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
660 /* pure ht40 */
661 if (ctx->ht.protection ==
662 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
663 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
664 /*
665 * Note: control channel is opposite of extension
666 * channel
667 */
668 switch (ctx->ht.extension_chan_offset) {
669 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
670 rxon->flags &=
671 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
672 break;
673 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
674 rxon->flags |=
675 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
676 break;
677 }
678 } else {
679 /*
680 * Note: control channel is opposite of extension
681 * channel
682 */
683 switch (ctx->ht.extension_chan_offset) {
684 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
685 rxon->flags &=
686 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
687 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
688 break;
689 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
690 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
691 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
692 break;
693 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
694 default:
695 /*
696 * channel location only valid if in Mixed
697 * mode
698 */
699 IWL_ERR(priv,
700 "invalid extension channel offset\n");
701 break;
702 }
703 }
704 } else {
705 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
706 }
707
708 iwlagn_set_rxon_chain(priv, ctx);
709
710 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
711 "extension channel offset 0x%x\n",
712 le32_to_cpu(rxon->flags), ctx->ht.protection,
713 ctx->ht.extension_chan_offset);
714}
715
716void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
717{
718 struct iwl_rxon_context *ctx;
719
720 for_each_context(priv, ctx)
721 _iwl_set_rxon_ht(priv, ht_conf, ctx);
722}
723
Meenakshi Venkataramanfedfa872012-03-13 16:31:34 -0700724/**
725 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
726 * @ch: requested channel as a pointer to struct ieee80211_channel
727
728 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
729 * in the staging RXON flag structure based on the ch->band
730 */
731void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
732 struct iwl_rxon_context *ctx)
733{
734 enum ieee80211_band band = ch->band;
735 u16 channel = ch->hw_value;
736
737 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
738 (priv->band == band))
739 return;
740
741 ctx->staging.channel = cpu_to_le16(channel);
742 if (band == IEEE80211_BAND_5GHZ)
743 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
744 else
745 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
746
747 priv->band = band;
748
749 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
750
751}
752
Meenakshi Venkataraman50319f72012-03-13 16:45:00 -0700753void iwl_set_flags_for_band(struct iwl_priv *priv,
754 struct iwl_rxon_context *ctx,
755 enum ieee80211_band band,
756 struct ieee80211_vif *vif)
757{
758 if (band == IEEE80211_BAND_5GHZ) {
759 ctx->staging.flags &=
760 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
761 | RXON_FLG_CCK_MSK);
762 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
763 } else {
764 /* Copied from iwl_post_associate() */
765 if (vif && vif->bss_conf.use_short_slot)
766 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
767 else
768 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
769
770 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
771 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
772 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
773 }
774}
775
Meenakshi Venkataramanaecd44f2012-03-13 17:16:07 -0700776void iwl_set_rate(struct iwl_priv *priv)
777{
778 struct iwl_rxon_context *ctx;
779
780 for_each_context(priv, ctx) {
781 ctx->staging.cck_basic_rates =
782 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
783
784 ctx->staging.ofdm_basic_rates =
785 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
786 }
787}
788
Meenakshi Venkataraman354a4532012-03-15 13:27:00 -0700789static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
790 struct iwl_rxon_context *ctx, int hw_decrypt)
791{
792 struct iwl_rxon_cmd *rxon = &ctx->staging;
793
794 if (hw_decrypt)
795 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
796 else
797 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
798
799}
800
Meenakshi Venkataraman8931b572012-03-15 13:27:01 -0700801/* validate RXON structure is valid */
802static int iwl_check_rxon_cmd(struct iwl_priv *priv,
803 struct iwl_rxon_context *ctx)
804{
805 struct iwl_rxon_cmd *rxon = &ctx->staging;
806 u32 errors = 0;
807
808 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
809 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
810 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
811 errors |= BIT(0);
812 }
813 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
814 IWL_WARN(priv, "check 2.4G: wrong radar\n");
815 errors |= BIT(1);
816 }
817 } else {
818 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
819 IWL_WARN(priv, "check 5.2G: not short slot!\n");
820 errors |= BIT(2);
821 }
822 if (rxon->flags & RXON_FLG_CCK_MSK) {
823 IWL_WARN(priv, "check 5.2G: CCK!\n");
824 errors |= BIT(3);
825 }
826 }
827 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
828 IWL_WARN(priv, "mac/bssid mcast!\n");
829 errors |= BIT(4);
830 }
831
832 /* make sure basic rates 6Mbps and 1Mbps are supported */
833 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
834 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
835 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
836 errors |= BIT(5);
837 }
838
839 if (le16_to_cpu(rxon->assoc_id) > 2007) {
840 IWL_WARN(priv, "aid > 2007\n");
841 errors |= BIT(6);
842 }
843
844 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
845 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
846 IWL_WARN(priv, "CCK and short slot\n");
847 errors |= BIT(7);
848 }
849
850 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
851 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
852 IWL_WARN(priv, "CCK and auto detect");
853 errors |= BIT(8);
854 }
855
856 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
857 RXON_FLG_TGG_PROTECT_MSK)) ==
858 RXON_FLG_TGG_PROTECT_MSK) {
859 IWL_WARN(priv, "TGg but no auto-detect\n");
860 errors |= BIT(9);
861 }
862
863 if (rxon->channel == 0) {
864 IWL_WARN(priv, "zero channel is invalid\n");
865 errors |= BIT(10);
866 }
867
868 WARN(errors, "Invalid RXON (%#x), channel %d",
869 errors, le16_to_cpu(rxon->channel));
870
871 return errors ? -EINVAL : 0;
872}
873
Johannes Berg2295c662010-10-23 09:15:41 -0700874/**
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700875 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
876 * @priv: staging_rxon is compared to active_rxon
877 *
878 * If the RXON structure is changing enough to require a new tune,
879 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
880 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
881 */
882static int iwl_full_rxon_required(struct iwl_priv *priv,
883 struct iwl_rxon_context *ctx)
884{
885 const struct iwl_rxon_cmd *staging = &ctx->staging;
886 const struct iwl_rxon_cmd *active = &ctx->active;
887
888#define CHK(cond) \
889 if ((cond)) { \
890 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
891 return 1; \
892 }
893
894#define CHK_NEQ(c1, c2) \
895 if ((c1) != (c2)) { \
896 IWL_DEBUG_INFO(priv, "need full RXON - " \
897 #c1 " != " #c2 " - %d != %d\n", \
898 (c1), (c2)); \
899 return 1; \
900 }
901
902 /* These items are only settable from the full RXON command */
903 CHK(!iwl_is_associated_ctx(ctx));
904 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
905 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
906 CHK(compare_ether_addr(staging->wlap_bssid_addr,
907 active->wlap_bssid_addr));
908 CHK_NEQ(staging->dev_type, active->dev_type);
909 CHK_NEQ(staging->channel, active->channel);
910 CHK_NEQ(staging->air_propagation, active->air_propagation);
911 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
912 active->ofdm_ht_single_stream_basic_rates);
913 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
914 active->ofdm_ht_dual_stream_basic_rates);
915 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
916 active->ofdm_ht_triple_stream_basic_rates);
917 CHK_NEQ(staging->assoc_id, active->assoc_id);
918
919 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
920 * be updated with the RXON_ASSOC command -- however only some
921 * flag transitions are allowed using RXON_ASSOC */
922
923 /* Check if we are not switching bands */
924 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
925 active->flags & RXON_FLG_BAND_24G_MSK);
926
927 /* Check if we are switching association toggle */
928 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
929 active->filter_flags & RXON_FILTER_ASSOC_MSK);
930
931#undef CHK
932#undef CHK_NEQ
933
934 return 0;
935}
936
Meenakshi Venkataraman4d323ac2012-03-14 15:15:33 -0700937#ifdef CONFIG_IWLWIFI_DEBUG
938void iwl_print_rx_config_cmd(struct iwl_priv *priv,
939 enum iwl_rxon_context_id ctxid)
940{
941 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
942 struct iwl_rxon_cmd *rxon = &ctx->staging;
943
944 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
945 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
946 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
947 le16_to_cpu(rxon->channel));
948 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
949 le32_to_cpu(rxon->flags));
950 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
951 le32_to_cpu(rxon->filter_flags));
952 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
953 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
954 rxon->ofdm_basic_rates);
955 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
956 rxon->cck_basic_rates);
957 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
958 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
959 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
960 le16_to_cpu(rxon->assoc_id));
961}
962#endif
963
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700964/**
Johannes Berg2295c662010-10-23 09:15:41 -0700965 * iwlagn_commit_rxon - commit staging_rxon to hardware
966 *
967 * The RXON command in staging_rxon is committed to the hardware and
968 * the active_rxon structure is updated with the new data. This
969 * function correctly transitions out of the RXON_ASSOC_MSK state if
970 * a HW tune is required based on the RXON structure changes.
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700971 *
972 * The connect/disconnect flow should be as the following:
973 *
974 * 1. make sure send RXON command with association bit unset if not connect
975 * this should include the channel and the band for the candidate
976 * to be connected to
977 * 2. Add Station before RXON association with the AP
978 * 3. RXON_timing has to send before RXON for connection
979 * 4. full RXON command - associated bit set
980 * 5. use RXON_ASSOC command to update any flags changes
Johannes Berg2295c662010-10-23 09:15:41 -0700981 */
982int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
983{
984 /* cast away the const for active_rxon in this function */
985 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -0700986 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
987 int ret;
988
Johannes Bergb1eea292012-03-06 13:30:42 -0800989 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -0700990
Don Fry83626402012-03-07 09:52:37 -0800991 if (!iwl_is_alive(priv))
Johannes Berg2295c662010-10-23 09:15:41 -0700992 return -EBUSY;
993
994 /* This function hardcodes a bunch of dual-mode assumptions */
995 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
996
997 if (!ctx->is_active)
998 return 0;
999
1000 /* always get timestamp with Rx frame */
1001 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1002
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +02001003 /*
1004 * force CTS-to-self frames protection if RTS-CTS is not preferred
1005 * one aggregation protection method
1006 */
Johannes Berg9e295112012-04-09 17:46:55 -07001007 if (!priv->hw_params.use_rts_for_aggregation)
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +02001008 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1009
Johannes Berg2295c662010-10-23 09:15:41 -07001010 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1011 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1012 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1013 else
1014 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1015
Emmanuel Grumbach522376d2011-09-06 09:31:19 -07001016 iwl_print_rx_config_cmd(priv, ctx->ctxid);
Johannes Berg2295c662010-10-23 09:15:41 -07001017 ret = iwl_check_rxon_cmd(priv, ctx);
1018 if (ret) {
1019 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1020 return -EINVAL;
1021 }
1022
1023 /*
1024 * receive commit_rxon request
1025 * abort any previous channel switch if still in process
1026 */
Don Fry83626402012-03-07 09:52:37 -08001027 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001028 (priv->switch_channel != ctx->staging.channel)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001029 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001030 le16_to_cpu(priv->switch_channel));
Johannes Berg2295c662010-10-23 09:15:41 -07001031 iwl_chswitch_done(priv, false);
1032 }
1033
1034 /*
1035 * If we don't need to send a full RXON, we can use
1036 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1037 * and other flags for the current radio configuration.
1038 */
1039 if (!iwl_full_rxon_required(priv, ctx)) {
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -07001040 ret = iwlagn_send_rxon_assoc(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001041 if (ret) {
1042 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1043 return ret;
1044 }
1045
1046 memcpy(active, &ctx->staging, sizeof(*active));
Wey-Yi Guy891db882011-05-27 08:40:24 -07001047 /*
1048 * We do not commit tx power settings while channel changing,
1049 * do it now if after settings changed.
1050 */
1051 iwl_set_tx_power(priv, priv->tx_power_next, false);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -07001052
1053 /* make sure we are in the right PS state */
1054 iwl_power_update_mode(priv, true);
1055
Johannes Berg2295c662010-10-23 09:15:41 -07001056 return 0;
1057 }
1058
Don Fry9d143e92011-04-20 15:23:57 -07001059 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
Johannes Berg2295c662010-10-23 09:15:41 -07001060
1061 IWL_DEBUG_INFO(priv,
1062 "Going to commit RXON\n"
1063 " * with%s RXON_FILTER_ASSOC_MSK\n"
1064 " * channel = %d\n"
1065 " * bssid = %pM\n",
1066 (new_assoc ? "" : "out"),
1067 le16_to_cpu(ctx->staging.channel),
1068 ctx->staging.bssid_addr);
1069
1070 /*
Johannes Berg52d980c2010-11-10 09:56:45 -08001071 * Always clear associated first, but with the correct config.
1072 * This is required as for example station addition for the
1073 * AP station must be done after the BSSID is set to correctly
1074 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -07001075 */
Wey-Yi Guy3083d032011-05-06 17:06:44 -07001076 ret = iwlagn_rxon_disconn(priv, ctx);
1077 if (ret)
1078 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -07001079
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001080 ret = iwlagn_set_pan_params(priv);
1081 if (ret)
1082 return ret;
Johannes Berg2b9253d2011-05-27 08:40:26 -07001083
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001084 if (new_assoc)
1085 return iwlagn_rxon_connect(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001086
1087 return 0;
1088}
1089
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001090void iwlagn_config_ht40(struct ieee80211_conf *conf,
1091 struct iwl_rxon_context *ctx)
1092{
1093 if (conf_is_ht40_minus(conf)) {
1094 ctx->ht.extension_chan_offset =
1095 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1096 ctx->ht.is_40mhz = true;
1097 } else if (conf_is_ht40_plus(conf)) {
1098 ctx->ht.extension_chan_offset =
1099 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1100 ctx->ht.is_40mhz = true;
1101 } else {
1102 ctx->ht.extension_chan_offset =
1103 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1104 ctx->ht.is_40mhz = false;
1105 }
1106}
1107
Johannes Berg2295c662010-10-23 09:15:41 -07001108int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1109{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001110 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001111 struct iwl_rxon_context *ctx;
1112 struct ieee80211_conf *conf = &hw->conf;
1113 struct ieee80211_channel *channel = conf->channel;
1114 const struct iwl_channel_info *ch_info;
1115 int ret = 0;
1116
Johannes Berg0ca24da2012-03-15 13:26:46 -07001117 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
Johannes Berg2295c662010-10-23 09:15:41 -07001118
Johannes Bergb1eea292012-03-06 13:30:42 -08001119 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001120
Don Fry83626402012-03-07 09:52:37 -08001121 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Johannes Berg2295c662010-10-23 09:15:41 -07001122 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1123 goto out;
1124 }
1125
Don Fry83626402012-03-07 09:52:37 -08001126 if (!iwl_is_ready(priv)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001127 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1128 goto out;
1129 }
1130
1131 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1132 IEEE80211_CONF_CHANGE_CHANNEL)) {
1133 /* mac80211 uses static for non-HT which is what we want */
1134 priv->current_ht_config.smps = conf->smps_mode;
1135
1136 /*
1137 * Recalculate chain counts.
1138 *
1139 * If monitor mode is enabled then mac80211 will
1140 * set up the SM PS mode to OFF if an HT channel is
1141 * configured.
1142 */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001143 for_each_context(priv, ctx)
1144 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001145 }
1146
1147 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Johannes Berg2295c662010-10-23 09:15:41 -07001148 ch_info = iwl_get_channel_info(priv, channel->band,
1149 channel->hw_value);
1150 if (!is_channel_valid(ch_info)) {
1151 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1152 ret = -EINVAL;
1153 goto out;
1154 }
1155
Johannes Berg2295c662010-10-23 09:15:41 -07001156 for_each_context(priv, ctx) {
1157 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -07001158 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001159 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001160
Johannes Berg2295c662010-10-23 09:15:41 -07001161 if (ctx->ht.enabled) {
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001162 /* if HT40 is used, it should not change
1163 * after associated except channel switch */
Wey-Yi Guy78feb352011-12-14 08:22:36 -08001164 if (!ctx->ht.is_40mhz ||
1165 !iwl_is_associated_ctx(ctx))
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001166 iwlagn_config_ht40(conf, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001167 } else
1168 ctx->ht.is_40mhz = false;
1169
1170 /*
1171 * Default to no protection. Protection mode will
1172 * later be set from BSS config in iwl_ht_conf
1173 */
1174 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1175
1176 /* if we are switching from ht to 2.4 clear flags
1177 * from any ht related info since 2.4 does not
1178 * support ht */
1179 if (le16_to_cpu(ctx->staging.channel) !=
1180 channel->hw_value)
1181 ctx->staging.flags = 0;
1182
1183 iwl_set_rxon_channel(priv, channel, ctx);
1184 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1185
1186 iwl_set_flags_for_band(priv, ctx, channel->band,
1187 ctx->vif);
1188 }
1189
Johannes Berg2295c662010-10-23 09:15:41 -07001190 iwl_update_bcast_stations(priv);
1191
1192 /*
1193 * The list of supported rates and rate mask can be different
1194 * for each band; since the band may have changed, reset
1195 * the rate mask to what mac80211 lists.
1196 */
1197 iwl_set_rate(priv);
1198 }
1199
1200 if (changed & (IEEE80211_CONF_CHANGE_PS |
1201 IEEE80211_CONF_CHANGE_IDLE)) {
1202 ret = iwl_power_update_mode(priv, false);
1203 if (ret)
1204 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1205 }
1206
1207 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1208 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1209 priv->tx_power_user_lmt, conf->power_level);
1210
1211 iwl_set_tx_power(priv, conf->power_level, false);
1212 }
1213
1214 for_each_context(priv, ctx) {
1215 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1216 continue;
1217 iwlagn_commit_rxon(priv, ctx);
1218 }
1219 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001220 mutex_unlock(&priv->mutex);
Wey-Yi Guy770c72c2011-10-10 07:27:10 -07001221 IWL_DEBUG_MAC80211(priv, "leave\n");
1222
Johannes Berg2295c662010-10-23 09:15:41 -07001223 return ret;
1224}
1225
Johannes Berg2295c662010-10-23 09:15:41 -07001226static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1227 struct iwl_rxon_context *ctx,
1228 struct ieee80211_bss_conf *bss_conf)
1229{
1230 struct ieee80211_vif *vif = ctx->vif;
1231 struct iwl_rxon_context *tmp;
1232 struct ieee80211_sta *sta;
1233 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +01001234 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -07001235 bool need_multiple;
1236
Johannes Bergb1eea292012-03-06 13:30:42 -08001237 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001238
1239 switch (vif->type) {
1240 case NL80211_IFTYPE_STATION:
1241 rcu_read_lock();
1242 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +01001243 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -07001244 /*
1245 * If at all, this can only happen through a race
1246 * when the AP disconnects us while we're still
1247 * setting up the connection, in that case mac80211
1248 * will soon tell us about that.
1249 */
1250 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +01001251 rcu_read_unlock();
1252 break;
Johannes Berg2295c662010-10-23 09:15:41 -07001253 }
Johannes Berg850bedc2011-02-25 12:24:11 +01001254
1255 ht_cap = &sta->ht_cap;
1256
1257 need_multiple = true;
1258
1259 /*
1260 * If the peer advertises no support for receiving 2 and 3
1261 * stream MCS rates, it can't be transmitting them either.
1262 */
1263 if (ht_cap->mcs.rx_mask[1] == 0 &&
1264 ht_cap->mcs.rx_mask[2] == 0) {
1265 need_multiple = false;
1266 } else if (!(ht_cap->mcs.tx_params &
1267 IEEE80211_HT_MCS_TX_DEFINED)) {
1268 /* If it can't TX MCS at all ... */
1269 need_multiple = false;
1270 } else if (ht_cap->mcs.tx_params &
1271 IEEE80211_HT_MCS_TX_RX_DIFF) {
1272 int maxstreams;
1273
1274 /*
1275 * But if it can receive them, it might still not
1276 * be able to transmit them, which is what we need
1277 * to check here -- so check the number of streams
1278 * it advertises for TX (if different from RX).
1279 */
1280
1281 maxstreams = (ht_cap->mcs.tx_params &
1282 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1283 maxstreams >>=
1284 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1285 maxstreams += 1;
1286
1287 if (maxstreams <= 1)
1288 need_multiple = false;
1289 }
1290
Johannes Berg2295c662010-10-23 09:15:41 -07001291 rcu_read_unlock();
1292 break;
1293 case NL80211_IFTYPE_ADHOC:
1294 /* currently */
1295 need_multiple = false;
1296 break;
1297 default:
1298 /* only AP really */
1299 need_multiple = true;
1300 break;
1301 }
1302
1303 ctx->ht_need_multiple_chains = need_multiple;
1304
1305 if (!need_multiple) {
1306 /* check all contexts */
1307 for_each_context(priv, tmp) {
1308 if (!tmp->vif)
1309 continue;
1310 if (tmp->ht_need_multiple_chains) {
1311 need_multiple = true;
1312 break;
1313 }
1314 }
1315 }
1316
1317 ht_conf->single_chain_sufficient = !need_multiple;
1318}
1319
Don Fry5c3d29f2011-07-08 08:46:29 -07001320static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1321{
1322 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1323 int ret;
1324
Dor Shaishbfb45f52012-03-26 08:20:55 -07001325 if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED))
1326 return;
1327
Don Fry5c3d29f2011-07-08 08:46:29 -07001328 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1329 iwl_is_any_associated(priv)) {
1330 struct iwl_calib_chain_noise_reset_cmd cmd;
1331
1332 /* clear data for chain noise calibration algorithm */
1333 data->chain_noise_a = 0;
1334 data->chain_noise_b = 0;
1335 data->chain_noise_c = 0;
1336 data->chain_signal_a = 0;
1337 data->chain_signal_b = 0;
1338 data->chain_signal_c = 0;
1339 data->beacon_count = 0;
1340
1341 memset(&cmd, 0, sizeof(cmd));
1342 iwl_set_calib_hdr(&cmd.hdr,
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001343 priv->phy_calib_chain_noise_reset_cmd);
Johannes Berge10a0532012-03-06 13:30:39 -08001344 ret = iwl_dvm_send_cmd_pdu(priv,
Don Fry5c3d29f2011-07-08 08:46:29 -07001345 REPLY_PHY_CALIBRATION_CMD,
1346 CMD_SYNC, sizeof(cmd), &cmd);
1347 if (ret)
1348 IWL_ERR(priv,
1349 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1350 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1351 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1352 }
1353}
1354
Johannes Berg2295c662010-10-23 09:15:41 -07001355void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1356 struct ieee80211_vif *vif,
1357 struct ieee80211_bss_conf *bss_conf,
1358 u32 changes)
1359{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001360 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001361 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1362 int ret;
1363 bool force = false;
1364
Johannes Bergb1eea292012-03-06 13:30:42 -08001365 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001366
Don Fry83626402012-03-07 09:52:37 -08001367 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -08001368 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001369 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -08001370 return;
1371 }
1372
1373 if (unlikely(!ctx->vif)) {
1374 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001375 mutex_unlock(&priv->mutex);
Johannes Berg893654d2010-11-10 18:25:47 -08001376 return;
1377 }
1378
Johannes Berg2295c662010-10-23 09:15:41 -07001379 if (changes & BSS_CHANGED_BEACON_INT)
1380 force = true;
1381
1382 if (changes & BSS_CHANGED_QOS) {
1383 ctx->qos_data.qos_active = bss_conf->qos;
1384 iwlagn_update_qos(priv, ctx);
1385 }
1386
1387 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1388 if (vif->bss_conf.use_short_preamble)
1389 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1390 else
1391 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1392
1393 if (changes & BSS_CHANGED_ASSOC) {
1394 if (bss_conf->assoc) {
Johannes Berge9ac0742012-03-13 14:29:30 +01001395 priv->timestamp = bss_conf->last_tsf;
Johannes Berg2295c662010-10-23 09:15:41 -07001396 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1397 } else {
Garen Tamrazian68b99312011-03-30 02:29:32 -07001398 /*
1399 * If we disassociate while there are pending
1400 * frames, just wake up the queues and let the
1401 * frames "escape" ... This shouldn't really
1402 * be happening to start with, but we should
1403 * not get stuck in this case either since it
1404 * can happen if userspace gets confused.
1405 */
Johannes Berge755f882012-03-07 09:52:16 -08001406 iwlagn_lift_passive_no_rx(priv);
1407
Johannes Berg2295c662010-10-23 09:15:41 -07001408 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001409
1410 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1411 priv->have_rekey_data = false;
Johannes Berg2295c662010-10-23 09:15:41 -07001412 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001413
1414 iwlagn_bt_coex_rssi_monitor(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001415 }
1416
1417 if (ctx->ht.enabled) {
1418 ctx->ht.protection = bss_conf->ht_operation_mode &
1419 IEEE80211_HT_OP_MODE_PROTECTION;
1420 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1421 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1422 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -08001423 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -07001424 }
1425
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001426 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001427
1428 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1429 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1430 else
1431 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1432
1433 if (bss_conf->use_cts_prot)
1434 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1435 else
1436 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1437
1438 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1439
1440 if (vif->type == NL80211_IFTYPE_AP ||
1441 vif->type == NL80211_IFTYPE_ADHOC) {
1442 if (vif->bss_conf.enable_beacon) {
1443 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1444 priv->beacon_ctx = ctx;
1445 } else {
1446 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1447 priv->beacon_ctx = NULL;
1448 }
1449 }
1450
Meenakshi Venkataraman758f5552012-02-08 12:04:41 -08001451 /*
1452 * If the ucode decides to do beacon filtering before
1453 * association, it will lose beacons that are needed
1454 * before sending frames out on passive channels. This
1455 * causes association failures on those channels. Enable
1456 * receiving beacons in such cases.
1457 */
1458
1459 if (vif->type == NL80211_IFTYPE_STATION) {
1460 if (!bss_conf->assoc)
1461 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1462 else
1463 ctx->staging.filter_flags &=
1464 ~RXON_FILTER_BCON_AWARE_MSK;
1465 }
1466
Johannes Berg2295c662010-10-23 09:15:41 -07001467 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1468 iwlagn_commit_rxon(priv, ctx);
1469
Johannes Berg8da8e622010-11-10 09:56:46 -08001470 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1471 /*
1472 * The chain noise calibration will enable PM upon
1473 * completion. If calibration has already been run
1474 * then we need to enable power management here.
1475 */
1476 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1477 iwl_power_update_mode(priv, false);
1478
1479 /* Enable RX differential gain and sensitivity calibrations */
Dor Shaishbfb45f52012-03-26 08:20:55 -07001480 iwlagn_chain_noise_reset(priv);
Johannes Berg8da8e622010-11-10 09:56:46 -08001481 priv->start_calib = 1;
1482 }
1483
Johannes Berg2295c662010-10-23 09:15:41 -07001484 if (changes & BSS_CHANGED_IBSS) {
1485 ret = iwlagn_manage_ibss_station(priv, vif,
1486 bss_conf->ibss_joined);
1487 if (ret)
1488 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1489 bss_conf->ibss_joined ? "add" : "remove",
1490 bss_conf->bssid);
1491 }
1492
Johannes Bergbd50a8ab2010-10-23 09:15:42 -07001493 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1494 priv->beacon_ctx) {
1495 if (iwlagn_update_beacon(priv, vif))
1496 IWL_ERR(priv, "Error sending IBSS beacon\n");
1497 }
1498
Johannes Bergb1eea292012-03-06 13:30:42 -08001499 mutex_unlock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001500}
Johannes Bergae79d232010-11-10 09:56:38 -08001501
1502void iwlagn_post_scan(struct iwl_priv *priv)
1503{
1504 struct iwl_rxon_context *ctx;
1505
1506 /*
Wey-Yi Guyc2b821d2011-06-03 07:54:14 -07001507 * We do not commit power settings while scan is pending,
1508 * do it now if the settings changed.
1509 */
1510 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1511 iwl_set_tx_power(priv, priv->tx_power_next, false);
1512
1513 /*
Johannes Bergae79d232010-11-10 09:56:38 -08001514 * Since setting the RXON may have been deferred while
1515 * performing the scan, fire one off if needed
1516 */
1517 for_each_context(priv, ctx)
1518 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1519 iwlagn_commit_rxon(priv, ctx);
1520
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001521 iwlagn_set_pan_params(priv);
Johannes Bergae79d232010-11-10 09:56:38 -08001522}