blob: 89ccddcf023069c41cd47d9f4d7ba32cf474845c [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-agn-calib.h"
Emmanuel Grumbachbdfbf092011-07-08 08:46:16 -070031#include "iwl-trans.h"
Johannes Berg65de7e82012-04-17 07:36:30 -070032#include "iwl-modparams.h"
Johannes Berg2295c662010-10-23 09:15:41 -070033
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070034/*
35 * initialize rxon structure with default values from eeprom
36 */
37void iwl_connection_init_rx_config(struct iwl_priv *priv,
38 struct iwl_rxon_context *ctx)
39{
40 const struct iwl_channel_info *ch_info;
41
42 memset(&ctx->staging, 0, sizeof(ctx->staging));
43
44 if (!ctx->vif) {
45 ctx->staging.dev_type = ctx->unused_devtype;
46 } else
47 switch (ctx->vif->type) {
48 case NL80211_IFTYPE_AP:
49 ctx->staging.dev_type = ctx->ap_devtype;
50 break;
51
52 case NL80211_IFTYPE_STATION:
53 ctx->staging.dev_type = ctx->station_devtype;
54 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
55 break;
56
57 case NL80211_IFTYPE_ADHOC:
58 ctx->staging.dev_type = ctx->ibss_devtype;
59 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
60 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
61 RXON_FILTER_ACCEPT_GRP_MSK;
62 break;
63
Johannes Berg57897722012-05-11 10:53:18 +020064 case NL80211_IFTYPE_MONITOR:
65 ctx->staging.dev_type = RXON_DEV_TYPE_SNIFFER;
66 break;
67
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070068 default:
69 IWL_ERR(priv, "Unsupported interface type %d\n",
70 ctx->vif->type);
71 break;
72 }
73
74#if 0
75 /* TODO: Figure out when short_preamble would be set and cache from
76 * that */
77 if (!hw_to_local(priv->hw)->short_preamble)
78 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
79 else
80 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
81#endif
82
83 ch_info = iwl_get_channel_info(priv, priv->band,
84 le16_to_cpu(ctx->active.channel));
85
86 if (!ch_info)
87 ch_info = &priv->channel_info[0];
88
89 ctx->staging.channel = cpu_to_le16(ch_info->channel);
90 priv->band = ch_info->band;
91
92 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
93
Meenakshi Venkataraman47042ac2012-03-13 17:07:48 -070094 /* clear both MIX and PURE40 mode flag */
95 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
96 RXON_FLG_CHANNEL_MODE_PURE_40);
97 if (ctx->vif)
98 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
99
100 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
101 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
102 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
103}
104
Johannes Berg2295c662010-10-23 09:15:41 -0700105static int iwlagn_disable_bss(struct iwl_priv *priv,
106 struct iwl_rxon_context *ctx,
107 struct iwl_rxon_cmd *send)
108{
109 __le32 old_filter = send->filter_flags;
110 int ret;
111
112 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800113 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700114 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700115
116 send->filter_flags = old_filter;
117
118 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800119 IWL_DEBUG_QUIET_RFKILL(priv,
120 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
Johannes Berg2295c662010-10-23 09:15:41 -0700121
122 return ret;
123}
124
125static int iwlagn_disable_pan(struct iwl_priv *priv,
126 struct iwl_rxon_context *ctx,
127 struct iwl_rxon_cmd *send)
128{
Johannes Berg311dce72011-01-04 16:22:01 -0800129 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -0700130 __le32 old_filter = send->filter_flags;
131 u8 old_dev_type = send->dev_type;
132 int ret;
Johannes Bergdb662d42012-03-15 13:26:44 -0700133 static const u8 deactivate_cmd[] = {
134 REPLY_WIPAN_DEACTIVATION_COMPLETE
135 };
Johannes Berg2295c662010-10-23 09:15:41 -0700136
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800137 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
Johannes Bergdb662d42012-03-15 13:26:44 -0700138 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800139 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -0800140
Johannes Berg2295c662010-10-23 09:15:41 -0700141 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
142 send->dev_type = RXON_DEV_TYPE_P2P;
Johannes Berge10a0532012-03-06 13:30:39 -0800143 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700144 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -0700145
146 send->filter_flags = old_filter;
147 send->dev_type = old_dev_type;
148
Johannes Berg311dce72011-01-04 16:22:01 -0800149 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -0700150 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800151 iwl_remove_notification(&priv->notif_wait, &disable_wait);
Johannes Berg311dce72011-01-04 16:22:01 -0800152 } else {
Johannes Berg4bd14dd2012-03-06 13:30:58 -0800153 ret = iwl_wait_notification(&priv->notif_wait,
154 &disable_wait, HZ);
Johannes Berga8674a12011-04-13 03:14:48 -0700155 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -0800156 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
157 }
Johannes Berg2295c662010-10-23 09:15:41 -0700158
159 return ret;
160}
161
Johannes Berg2b9253d2011-05-27 08:40:26 -0700162static int iwlagn_disconn_pan(struct iwl_priv *priv,
163 struct iwl_rxon_context *ctx,
164 struct iwl_rxon_cmd *send)
165{
166 __le32 old_filter = send->filter_flags;
167 int ret;
168
169 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berge10a0532012-03-06 13:30:39 -0800170 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700171 sizeof(*send), send);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700172
173 send->filter_flags = old_filter;
174
175 return ret;
176}
177
David Spinadel50c1e9a2012-04-16 14:43:30 -0700178void iwlagn_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800179{
180 int ret;
181
182 if (!ctx->is_active)
183 return;
184
185 ctx->qos_data.def_qos_parm.qos_flags = 0;
186
187 if (ctx->qos_data.qos_active)
188 ctx->qos_data.def_qos_parm.qos_flags |=
189 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
190
191 if (ctx->ht.enabled)
192 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
193
Emmanuel Grumbach0dcf50c2011-11-10 06:55:23 -0800194 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800195 ctx->qos_data.qos_active,
196 ctx->qos_data.def_qos_parm.qos_flags);
197
Johannes Berge10a0532012-03-06 13:30:39 -0800198 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800199 sizeof(struct iwl_qosparam_cmd),
200 &ctx->qos_data.def_qos_parm);
201 if (ret)
Todd Previteb36b1102011-11-10 06:55:02 -0800202 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800203}
204
David Spinadel50c1e9a2012-04-16 14:43:30 -0700205int iwlagn_update_beacon(struct iwl_priv *priv,
206 struct ieee80211_vif *vif)
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700207{
Johannes Bergb1eea292012-03-06 13:30:42 -0800208 lockdep_assert_held(&priv->mutex);
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700209
210 dev_kfree_skb(priv->beacon_skb);
211 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
212 if (!priv->beacon_skb)
213 return -ENOMEM;
214 return iwlagn_send_beacon_cmd(priv);
215}
216
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700217static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
218 struct iwl_rxon_context *ctx)
219{
220 int ret = 0;
Wey-Yi Guy89e746b2011-04-19 16:52:58 -0700221 struct iwl_rxon_assoc_cmd rxon_assoc;
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700222 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
223 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
224
225 if ((rxon1->flags == rxon2->flags) &&
226 (rxon1->filter_flags == rxon2->filter_flags) &&
227 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
228 (rxon1->ofdm_ht_single_stream_basic_rates ==
229 rxon2->ofdm_ht_single_stream_basic_rates) &&
230 (rxon1->ofdm_ht_dual_stream_basic_rates ==
231 rxon2->ofdm_ht_dual_stream_basic_rates) &&
232 (rxon1->ofdm_ht_triple_stream_basic_rates ==
233 rxon2->ofdm_ht_triple_stream_basic_rates) &&
234 (rxon1->acquisition_data == rxon2->acquisition_data) &&
235 (rxon1->rx_chain == rxon2->rx_chain) &&
236 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
237 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
238 return 0;
239 }
240
241 rxon_assoc.flags = ctx->staging.flags;
242 rxon_assoc.filter_flags = ctx->staging.filter_flags;
243 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
244 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
245 rxon_assoc.reserved1 = 0;
246 rxon_assoc.reserved2 = 0;
247 rxon_assoc.reserved3 = 0;
248 rxon_assoc.ofdm_ht_single_stream_basic_rates =
249 ctx->staging.ofdm_ht_single_stream_basic_rates;
250 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
251 ctx->staging.ofdm_ht_dual_stream_basic_rates;
252 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
253 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
254 ctx->staging.ofdm_ht_triple_stream_basic_rates;
255 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
256
Johannes Berge10a0532012-03-06 13:30:39 -0800257 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700258 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700259 return ret;
260}
261
Meenakshi Venkataramandff96c12012-03-15 13:26:59 -0700262static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
263{
264 u16 new_val;
265 u16 beacon_factor;
266
267 /*
268 * If mac80211 hasn't given us a beacon interval, program
269 * the default into the device (not checking this here
270 * would cause the adjustment below to return the maximum
271 * value, which may break PAN.)
272 */
273 if (!beacon_val)
274 return DEFAULT_BEACON_INTERVAL;
275
276 /*
277 * If the beacon interval we obtained from the peer
278 * is too large, we'll have to wake up more often
279 * (and in IBSS case, we'll beacon too much)
280 *
281 * For example, if max_beacon_val is 4096, and the
282 * requested beacon interval is 7000, we'll have to
283 * use 3500 to be able to wake up on the beacons.
284 *
285 * This could badly influence beacon detection stats.
286 */
287
288 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
289 new_val = beacon_val / beacon_factor;
290
291 if (!new_val)
292 new_val = max_beacon_val;
293
294 return new_val;
295}
296
297static int iwl_send_rxon_timing(struct iwl_priv *priv,
298 struct iwl_rxon_context *ctx)
299{
300 u64 tsf;
301 s32 interval_tm, rem;
302 struct ieee80211_conf *conf = NULL;
303 u16 beacon_int;
304 struct ieee80211_vif *vif = ctx->vif;
305
306 conf = &priv->hw->conf;
307
308 lockdep_assert_held(&priv->mutex);
309
310 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
311
312 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
313 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
314
315 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
316
317 /*
318 * TODO: For IBSS we need to get atim_window from mac80211,
319 * for now just always use 0
320 */
321 ctx->timing.atim_window = 0;
322
323 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
324 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
325 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
326 priv->contexts[IWL_RXON_CTX_BSS].vif &&
327 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
328 ctx->timing.beacon_interval =
329 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
330 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
331 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
332 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
333 priv->contexts[IWL_RXON_CTX_PAN].vif &&
334 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
335 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
336 !ctx->vif->bss_conf.beacon_int)) {
337 ctx->timing.beacon_interval =
338 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
339 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
340 } else {
341 beacon_int = iwl_adjust_beacon_interval(beacon_int,
342 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
343 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
344 }
345
346 ctx->beacon_int = beacon_int;
347
348 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
349 interval_tm = beacon_int * TIME_UNIT;
350 rem = do_div(tsf, interval_tm);
351 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
352
353 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
354
355 IWL_DEBUG_ASSOC(priv,
356 "beacon interval %d beacon timer %d beacon tim %d\n",
357 le16_to_cpu(ctx->timing.beacon_interval),
358 le32_to_cpu(ctx->timing.beacon_init_val),
359 le16_to_cpu(ctx->timing.atim_window));
360
361 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
362 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
363}
364
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700365static int iwlagn_rxon_disconn(struct iwl_priv *priv,
366 struct iwl_rxon_context *ctx)
367{
368 int ret;
369 struct iwl_rxon_cmd *active = (void *)&ctx->active;
370
Johannes Berg2b9253d2011-05-27 08:40:26 -0700371 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700372 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700373 } else {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700374 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700375 if (ret)
376 return ret;
377 if (ctx->vif) {
378 ret = iwl_send_rxon_timing(priv, ctx);
379 if (ret) {
380 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
381 return ret;
382 }
383 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
384 }
385 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700386 if (ret)
387 return ret;
388
389 /*
390 * Un-assoc RXON clears the station table and WEP
391 * keys, so we have to restore those afterwards.
392 */
393 iwl_clear_ucode_stations(priv, ctx);
Johannes Bergf775aa06d2011-06-22 06:34:09 -0700394 /* update -- might need P2P now */
395 iwl_update_bcast_station(priv, ctx);
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700396 iwl_restore_stations(priv, ctx);
397 ret = iwl_restore_default_wep_keys(priv, ctx);
398 if (ret) {
399 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
400 return ret;
401 }
402
403 memcpy(active, &ctx->staging, sizeof(*active));
404 return 0;
405}
406
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700407static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
408{
409 int ret;
410 s8 prev_tx_power;
411 bool defer;
412 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
413
Dor Shaishbfb45f52012-03-26 08:20:55 -0700414 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
415 return 0;
416
Meenakshi Venkataramane6a62a62012-03-13 18:10:19 -0700417 lockdep_assert_held(&priv->mutex);
418
419 if (priv->tx_power_user_lmt == tx_power && !force)
420 return 0;
421
422 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
423 IWL_WARN(priv,
424 "Requested user TXPOWER %d below lower limit %d.\n",
425 tx_power,
426 IWLAGN_TX_POWER_TARGET_POWER_MIN);
427 return -EINVAL;
428 }
429
430 if (tx_power > priv->tx_power_device_lmt) {
431 IWL_WARN(priv,
432 "Requested user TXPOWER %d above upper limit %d.\n",
433 tx_power, priv->tx_power_device_lmt);
434 return -EINVAL;
435 }
436
437 if (!iwl_is_ready_rf(priv))
438 return -EIO;
439
440 /* scan complete and commit_rxon use tx_power_next value,
441 * it always need to be updated for newest request */
442 priv->tx_power_next = tx_power;
443
444 /* do not set tx power when scanning or channel changing */
445 defer = test_bit(STATUS_SCANNING, &priv->status) ||
446 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
447 if (defer && !force) {
448 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
449 return 0;
450 }
451
452 prev_tx_power = priv->tx_power_user_lmt;
453 priv->tx_power_user_lmt = tx_power;
454
455 ret = iwlagn_send_tx_power(priv);
456
457 /* if fail to set tx_power, restore the orig. tx power */
458 if (ret) {
459 priv->tx_power_user_lmt = prev_tx_power;
460 priv->tx_power_next = prev_tx_power;
461 }
462 return ret;
463}
464
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700465static int iwlagn_rxon_connect(struct iwl_priv *priv,
466 struct iwl_rxon_context *ctx)
467{
468 int ret;
469 struct iwl_rxon_cmd *active = (void *)&ctx->active;
470
471 /* RXON timing must be before associated RXON */
Johannes Berg2b9253d2011-05-27 08:40:26 -0700472 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
473 ret = iwl_send_rxon_timing(priv, ctx);
474 if (ret) {
475 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
476 return ret;
477 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700478 }
479 /* QoS info may be cleared by previous un-assoc RXON */
480 iwlagn_update_qos(priv, ctx);
481
482 /*
483 * We'll run into this code path when beaconing is
484 * enabled, but then we also need to send the beacon
485 * to the device.
486 */
487 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
488 ret = iwlagn_update_beacon(priv, ctx->vif);
489 if (ret) {
490 IWL_ERR(priv,
491 "Error sending required beacon (%d)!\n",
492 ret);
493 return ret;
494 }
495 }
496
497 priv->start_calib = 0;
498 /*
499 * Apply the new configuration.
500 *
501 * Associated RXON doesn't clear the station table in uCode,
502 * so we don't need to restore stations etc. after this.
503 */
Johannes Berge10a0532012-03-06 13:30:39 -0800504 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700505 sizeof(struct iwl_rxon_cmd), &ctx->staging);
506 if (ret) {
507 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
508 return ret;
509 }
510 memcpy(active, &ctx->staging, sizeof(*active));
511
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700512 /* IBSS beacon needs to be sent after setting assoc */
513 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
514 if (iwlagn_update_beacon(priv, ctx->vif))
515 IWL_ERR(priv, "Error sending IBSS beacon\n");
516 iwl_init_sensitivity(priv);
517
518 /*
519 * If we issue a new RXON command which required a tune then
520 * we must send a new TXPOWER command or we won't be able to
521 * Tx any frames.
522 *
523 * It's expected we set power here if channel is changing.
524 */
525 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
526 if (ret) {
527 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
528 return ret;
529 }
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700530
Stanislaw Gruszka107ef972011-10-12 10:16:35 +0200531 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200532 priv->cfg->ht_params && priv->cfg->ht_params->smps_mode)
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700533 ieee80211_request_smps(ctx->vif,
Emmanuel Grumbach21522682012-03-22 17:51:44 +0200534 priv->cfg->ht_params->smps_mode);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700535
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700536 return 0;
537}
538
Wey-Yi Guye505c432011-07-07 08:27:41 -0700539int iwlagn_set_pan_params(struct iwl_priv *priv)
540{
541 struct iwl_wipan_params_cmd cmd;
542 struct iwl_rxon_context *ctx_bss, *ctx_pan;
543 int slot0 = 300, slot1 = 0;
544 int ret;
545
Johannes Berga18f61b2012-03-15 13:26:53 -0700546 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
Wey-Yi Guye505c432011-07-07 08:27:41 -0700547 return 0;
548
549 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
550
Johannes Bergb1eea292012-03-06 13:30:42 -0800551 lockdep_assert_held(&priv->mutex);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700552
553 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
554 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
555
556 /*
557 * If the PAN context is inactive, then we don't need
558 * to update the PAN parameters, the last thing we'll
559 * have done before it goes inactive is making the PAN
560 * parameters be WLAN-only.
561 */
562 if (!ctx_pan->is_active)
563 return 0;
564
565 memset(&cmd, 0, sizeof(cmd));
566
567 /* only 2 slots are currently allowed */
568 cmd.num_slots = 2;
569
570 cmd.slots[0].type = 0; /* BSS */
571 cmd.slots[1].type = 1; /* PAN */
572
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700573 if (priv->hw_roc_setup) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700574 /* both contexts must be used for this to happen */
Johannes Bergc6baf7f2011-07-23 10:24:47 -0700575 slot1 = IWL_MIN_SLOT_TIME;
576 slot0 = 3000;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700577 } else if (ctx_bss->vif && ctx_pan->vif) {
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700578 int bcnint = ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700579 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
580
581 /* should be set, but seems unused?? */
582 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
583
584 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
585 bcnint &&
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700586 bcnint != ctx_bss->beacon_int) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700587 IWL_ERR(priv,
588 "beacon intervals don't match (%d, %d)\n",
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700589 ctx_bss->beacon_int, ctx_pan->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700590 } else
591 bcnint = max_t(int, bcnint,
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700592 ctx_bss->beacon_int);
Wey-Yi Guye505c432011-07-07 08:27:41 -0700593 if (!bcnint)
594 bcnint = DEFAULT_BEACON_INTERVAL;
595 slot0 = bcnint / 2;
596 slot1 = bcnint - slot0;
597
Don Fry83626402012-03-07 09:52:37 -0800598 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
Wey-Yi Guye505c432011-07-07 08:27:41 -0700599 (!ctx_bss->vif->bss_conf.idle &&
600 !ctx_bss->vif->bss_conf.assoc)) {
601 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
602 slot1 = IWL_MIN_SLOT_TIME;
603 } else if (!ctx_pan->vif->bss_conf.idle &&
604 !ctx_pan->vif->bss_conf.assoc) {
Johannes Berg325a7dd2011-09-22 15:14:55 -0700605 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700606 slot0 = IWL_MIN_SLOT_TIME;
607 }
608 } else if (ctx_pan->vif) {
609 slot0 = 0;
610 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
Johannes Bergbbb05cb2011-07-18 01:59:22 -0700611 ctx_pan->beacon_int;
Wey-Yi Guye505c432011-07-07 08:27:41 -0700612 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
613
Don Fry83626402012-03-07 09:52:37 -0800614 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Wey-Yi Guye505c432011-07-07 08:27:41 -0700615 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
616 slot1 = IWL_MIN_SLOT_TIME;
617 }
618 }
619
620 cmd.slots[0].width = cpu_to_le16(slot0);
621 cmd.slots[1].width = cpu_to_le16(slot1);
622
Johannes Berge10a0532012-03-06 13:30:39 -0800623 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
Wey-Yi Guye505c432011-07-07 08:27:41 -0700624 sizeof(cmd), &cmd);
625 if (ret)
626 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
627
628 return ret;
629}
630
Meenakshi Venkataramandd641732012-03-13 16:25:38 -0700631static void _iwl_set_rxon_ht(struct iwl_priv *priv,
632 struct iwl_ht_config *ht_conf,
633 struct iwl_rxon_context *ctx)
634{
635 struct iwl_rxon_cmd *rxon = &ctx->staging;
636
637 if (!ctx->ht.enabled) {
638 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
639 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
640 RXON_FLG_HT40_PROT_MSK |
641 RXON_FLG_HT_PROT_MSK);
642 return;
643 }
644
645 /* FIXME: if the definition of ht.protection changed, the "translation"
646 * will be needed for rxon->flags
647 */
648 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
649 RXON_FLG_HT_OPERATING_MODE_POS);
650
651 /* Set up channel bandwidth:
652 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
653 /* clear the HT channel mode before set the mode */
654 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
655 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
656 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
657 /* pure ht40 */
658 if (ctx->ht.protection ==
659 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
660 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
661 /*
662 * Note: control channel is opposite of extension
663 * channel
664 */
665 switch (ctx->ht.extension_chan_offset) {
666 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
667 rxon->flags &=
668 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
669 break;
670 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
671 rxon->flags |=
672 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
673 break;
674 }
675 } else {
676 /*
677 * Note: control channel is opposite of extension
678 * channel
679 */
680 switch (ctx->ht.extension_chan_offset) {
681 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
682 rxon->flags &=
683 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
684 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
685 break;
686 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
687 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
688 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
689 break;
690 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
691 default:
692 /*
693 * channel location only valid if in Mixed
694 * mode
695 */
696 IWL_ERR(priv,
697 "invalid extension channel offset\n");
698 break;
699 }
700 }
701 } else {
702 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
703 }
704
705 iwlagn_set_rxon_chain(priv, ctx);
706
707 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
708 "extension channel offset 0x%x\n",
709 le32_to_cpu(rxon->flags), ctx->ht.protection,
710 ctx->ht.extension_chan_offset);
711}
712
713void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
714{
715 struct iwl_rxon_context *ctx;
716
717 for_each_context(priv, ctx)
718 _iwl_set_rxon_ht(priv, ht_conf, ctx);
719}
720
Meenakshi Venkataramanfedfa872012-03-13 16:31:34 -0700721/**
722 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
723 * @ch: requested channel as a pointer to struct ieee80211_channel
724
725 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
726 * in the staging RXON flag structure based on the ch->band
727 */
728void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
729 struct iwl_rxon_context *ctx)
730{
731 enum ieee80211_band band = ch->band;
732 u16 channel = ch->hw_value;
733
734 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
735 (priv->band == band))
736 return;
737
738 ctx->staging.channel = cpu_to_le16(channel);
739 if (band == IEEE80211_BAND_5GHZ)
740 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
741 else
742 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
743
744 priv->band = band;
745
746 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
747
748}
749
Meenakshi Venkataraman50319f72012-03-13 16:45:00 -0700750void iwl_set_flags_for_band(struct iwl_priv *priv,
751 struct iwl_rxon_context *ctx,
752 enum ieee80211_band band,
753 struct ieee80211_vif *vif)
754{
755 if (band == IEEE80211_BAND_5GHZ) {
756 ctx->staging.flags &=
757 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
758 | RXON_FLG_CCK_MSK);
759 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
760 } else {
761 /* Copied from iwl_post_associate() */
762 if (vif && vif->bss_conf.use_short_slot)
763 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
764 else
765 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
766
767 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
768 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
769 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
770 }
771}
772
Meenakshi Venkataraman354a4532012-03-15 13:27:00 -0700773static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
774 struct iwl_rxon_context *ctx, int hw_decrypt)
775{
776 struct iwl_rxon_cmd *rxon = &ctx->staging;
777
778 if (hw_decrypt)
779 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
780 else
781 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
782
783}
784
Meenakshi Venkataraman8931b572012-03-15 13:27:01 -0700785/* validate RXON structure is valid */
786static int iwl_check_rxon_cmd(struct iwl_priv *priv,
787 struct iwl_rxon_context *ctx)
788{
789 struct iwl_rxon_cmd *rxon = &ctx->staging;
790 u32 errors = 0;
791
792 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
793 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
794 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
795 errors |= BIT(0);
796 }
797 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
798 IWL_WARN(priv, "check 2.4G: wrong radar\n");
799 errors |= BIT(1);
800 }
801 } else {
802 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
803 IWL_WARN(priv, "check 5.2G: not short slot!\n");
804 errors |= BIT(2);
805 }
806 if (rxon->flags & RXON_FLG_CCK_MSK) {
807 IWL_WARN(priv, "check 5.2G: CCK!\n");
808 errors |= BIT(3);
809 }
810 }
811 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
812 IWL_WARN(priv, "mac/bssid mcast!\n");
813 errors |= BIT(4);
814 }
815
816 /* make sure basic rates 6Mbps and 1Mbps are supported */
817 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
818 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
819 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
820 errors |= BIT(5);
821 }
822
823 if (le16_to_cpu(rxon->assoc_id) > 2007) {
824 IWL_WARN(priv, "aid > 2007\n");
825 errors |= BIT(6);
826 }
827
828 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
829 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
830 IWL_WARN(priv, "CCK and short slot\n");
831 errors |= BIT(7);
832 }
833
834 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
835 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
836 IWL_WARN(priv, "CCK and auto detect");
837 errors |= BIT(8);
838 }
839
840 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
841 RXON_FLG_TGG_PROTECT_MSK)) ==
842 RXON_FLG_TGG_PROTECT_MSK) {
843 IWL_WARN(priv, "TGg but no auto-detect\n");
844 errors |= BIT(9);
845 }
846
847 if (rxon->channel == 0) {
848 IWL_WARN(priv, "zero channel is invalid\n");
849 errors |= BIT(10);
850 }
851
852 WARN(errors, "Invalid RXON (%#x), channel %d",
853 errors, le16_to_cpu(rxon->channel));
854
855 return errors ? -EINVAL : 0;
856}
857
Johannes Berg2295c662010-10-23 09:15:41 -0700858/**
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700859 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
860 * @priv: staging_rxon is compared to active_rxon
861 *
862 * If the RXON structure is changing enough to require a new tune,
863 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
864 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
865 */
David Spinadel50c1e9a2012-04-16 14:43:30 -0700866int iwl_full_rxon_required(struct iwl_priv *priv,
867 struct iwl_rxon_context *ctx)
Meenakshi Venkataraman55620922012-03-15 13:27:02 -0700868{
869 const struct iwl_rxon_cmd *staging = &ctx->staging;
870 const struct iwl_rxon_cmd *active = &ctx->active;
871
872#define CHK(cond) \
873 if ((cond)) { \
874 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
875 return 1; \
876 }
877
878#define CHK_NEQ(c1, c2) \
879 if ((c1) != (c2)) { \
880 IWL_DEBUG_INFO(priv, "need full RXON - " \
881 #c1 " != " #c2 " - %d != %d\n", \
882 (c1), (c2)); \
883 return 1; \
884 }
885
886 /* These items are only settable from the full RXON command */
887 CHK(!iwl_is_associated_ctx(ctx));
888 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
889 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
890 CHK(compare_ether_addr(staging->wlap_bssid_addr,
891 active->wlap_bssid_addr));
892 CHK_NEQ(staging->dev_type, active->dev_type);
893 CHK_NEQ(staging->channel, active->channel);
894 CHK_NEQ(staging->air_propagation, active->air_propagation);
895 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
896 active->ofdm_ht_single_stream_basic_rates);
897 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
898 active->ofdm_ht_dual_stream_basic_rates);
899 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
900 active->ofdm_ht_triple_stream_basic_rates);
901 CHK_NEQ(staging->assoc_id, active->assoc_id);
902
903 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
904 * be updated with the RXON_ASSOC command -- however only some
905 * flag transitions are allowed using RXON_ASSOC */
906
907 /* Check if we are not switching bands */
908 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
909 active->flags & RXON_FLG_BAND_24G_MSK);
910
911 /* Check if we are switching association toggle */
912 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
913 active->filter_flags & RXON_FILTER_ASSOC_MSK);
914
915#undef CHK
916#undef CHK_NEQ
917
918 return 0;
919}
920
Meenakshi Venkataraman4d323ac2012-03-14 15:15:33 -0700921#ifdef CONFIG_IWLWIFI_DEBUG
922void iwl_print_rx_config_cmd(struct iwl_priv *priv,
923 enum iwl_rxon_context_id ctxid)
924{
925 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
926 struct iwl_rxon_cmd *rxon = &ctx->staging;
927
928 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
929 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
930 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
931 le16_to_cpu(rxon->channel));
932 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
933 le32_to_cpu(rxon->flags));
934 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
935 le32_to_cpu(rxon->filter_flags));
936 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
937 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
938 rxon->ofdm_basic_rates);
939 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
940 rxon->cck_basic_rates);
941 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
942 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
943 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
944 le16_to_cpu(rxon->assoc_id));
945}
946#endif
947
Johannes Berg9543c5f2012-03-08 09:37:53 +0100948static void iwl_calc_basic_rates(struct iwl_priv *priv,
949 struct iwl_rxon_context *ctx)
950{
951 int lowest_present_ofdm = 100;
952 int lowest_present_cck = 100;
953 u8 cck = 0;
954 u8 ofdm = 0;
955
956 if (ctx->vif) {
957 struct ieee80211_supported_band *sband;
958 unsigned long basic = ctx->vif->bss_conf.basic_rates;
959 int i;
960
961 sband = priv->hw->wiphy->bands[priv->hw->conf.channel->band];
962
963 for_each_set_bit(i, &basic, BITS_PER_LONG) {
964 int hw = sband->bitrates[i].hw_value;
965 if (hw >= IWL_FIRST_OFDM_RATE) {
966 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
967 if (lowest_present_ofdm > hw)
968 lowest_present_ofdm = hw;
969 } else {
970 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
971
972 cck |= BIT(hw);
973 if (lowest_present_cck > hw)
974 lowest_present_cck = hw;
975 }
976 }
977 }
978
979 /*
980 * Now we've got the basic rates as bitmaps in the ofdm and cck
981 * variables. This isn't sufficient though, as there might not
982 * be all the right rates in the bitmap. E.g. if the only basic
983 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
984 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
985 *
986 * [...] a STA responding to a received frame shall transmit
987 * its Control Response frame [...] at the highest rate in the
988 * BSSBasicRateSet parameter that is less than or equal to the
989 * rate of the immediately previous frame in the frame exchange
990 * sequence ([...]) and that is of the same modulation class
991 * ([...]) as the received frame. If no rate contained in the
992 * BSSBasicRateSet parameter meets these conditions, then the
993 * control frame sent in response to a received frame shall be
994 * transmitted at the highest mandatory rate of the PHY that is
995 * less than or equal to the rate of the received frame, and
996 * that is of the same modulation class as the received frame.
997 *
998 * As a consequence, we need to add all mandatory rates that are
999 * lower than all of the basic rates to these bitmaps.
1000 */
1001
1002 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
1003 ofdm |= IWL_RATE_24M_MASK >> IWL_FIRST_OFDM_RATE;
1004 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
1005 ofdm |= IWL_RATE_12M_MASK >> IWL_FIRST_OFDM_RATE;
1006 /* 6M already there or needed so always add */
1007 ofdm |= IWL_RATE_6M_MASK >> IWL_FIRST_OFDM_RATE;
1008
1009 /*
1010 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
1011 * Note, however:
1012 * - if no CCK rates are basic, it must be ERP since there must
1013 * be some basic rates at all, so they're OFDM => ERP PHY
1014 * (or we're in 5 GHz, and the cck bitmap will never be used)
1015 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
1016 * - if 5.5M is basic, 1M and 2M are mandatory
1017 * - if 2M is basic, 1M is mandatory
1018 * - if 1M is basic, that's the only valid ACK rate.
1019 * As a consequence, it's not as complicated as it sounds, just add
1020 * any lower rates to the ACK rate bitmap.
1021 */
1022 if (IWL_RATE_11M_INDEX < lowest_present_ofdm)
1023 ofdm |= IWL_RATE_11M_MASK >> IWL_FIRST_CCK_RATE;
1024 if (IWL_RATE_5M_INDEX < lowest_present_ofdm)
1025 ofdm |= IWL_RATE_5M_MASK >> IWL_FIRST_CCK_RATE;
1026 if (IWL_RATE_2M_INDEX < lowest_present_ofdm)
1027 ofdm |= IWL_RATE_2M_MASK >> IWL_FIRST_CCK_RATE;
1028 /* 1M already there or needed so always add */
1029 cck |= IWL_RATE_1M_MASK >> IWL_FIRST_CCK_RATE;
1030
1031 IWL_DEBUG_RATE(priv, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n",
1032 cck, ofdm);
1033
1034 /* "basic_rates" is a misnomer here -- should be called ACK rates */
1035 ctx->staging.cck_basic_rates = cck;
1036 ctx->staging.ofdm_basic_rates = ofdm;
1037}
1038
Meenakshi Venkataraman55620922012-03-15 13:27:02 -07001039/**
Johannes Berg2295c662010-10-23 09:15:41 -07001040 * iwlagn_commit_rxon - commit staging_rxon to hardware
1041 *
1042 * The RXON command in staging_rxon is committed to the hardware and
1043 * the active_rxon structure is updated with the new data. This
1044 * function correctly transitions out of the RXON_ASSOC_MSK state if
1045 * a HW tune is required based on the RXON structure changes.
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001046 *
1047 * The connect/disconnect flow should be as the following:
1048 *
1049 * 1. make sure send RXON command with association bit unset if not connect
1050 * this should include the channel and the band for the candidate
1051 * to be connected to
1052 * 2. Add Station before RXON association with the AP
1053 * 3. RXON_timing has to send before RXON for connection
1054 * 4. full RXON command - associated bit set
1055 * 5. use RXON_ASSOC command to update any flags changes
Johannes Berg2295c662010-10-23 09:15:41 -07001056 */
1057int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1058{
1059 /* cast away the const for active_rxon in this function */
1060 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -07001061 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
1062 int ret;
1063
Johannes Bergb1eea292012-03-06 13:30:42 -08001064 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001065
Don Fry83626402012-03-07 09:52:37 -08001066 if (!iwl_is_alive(priv))
Johannes Berg2295c662010-10-23 09:15:41 -07001067 return -EBUSY;
1068
1069 /* This function hardcodes a bunch of dual-mode assumptions */
1070 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1071
1072 if (!ctx->is_active)
1073 return 0;
1074
1075 /* always get timestamp with Rx frame */
1076 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1077
Johannes Berg9543c5f2012-03-08 09:37:53 +01001078 /* recalculate basic rates */
1079 iwl_calc_basic_rates(priv, ctx);
1080
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +02001081 /*
1082 * force CTS-to-self frames protection if RTS-CTS is not preferred
1083 * one aggregation protection method
1084 */
Johannes Berg9e295112012-04-09 17:46:55 -07001085 if (!priv->hw_params.use_rts_for_aggregation)
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +02001086 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1087
Johannes Berg2295c662010-10-23 09:15:41 -07001088 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1089 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1090 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1091 else
1092 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1093
Emmanuel Grumbach522376d2011-09-06 09:31:19 -07001094 iwl_print_rx_config_cmd(priv, ctx->ctxid);
Johannes Berg2295c662010-10-23 09:15:41 -07001095 ret = iwl_check_rxon_cmd(priv, ctx);
1096 if (ret) {
1097 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1098 return -EINVAL;
1099 }
1100
1101 /*
1102 * receive commit_rxon request
1103 * abort any previous channel switch if still in process
1104 */
Don Fry83626402012-03-07 09:52:37 -08001105 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001106 (priv->switch_channel != ctx->staging.channel)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001107 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +02001108 le16_to_cpu(priv->switch_channel));
Johannes Berg2295c662010-10-23 09:15:41 -07001109 iwl_chswitch_done(priv, false);
1110 }
1111
1112 /*
1113 * If we don't need to send a full RXON, we can use
1114 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1115 * and other flags for the current radio configuration.
1116 */
1117 if (!iwl_full_rxon_required(priv, ctx)) {
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -07001118 ret = iwlagn_send_rxon_assoc(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001119 if (ret) {
1120 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1121 return ret;
1122 }
1123
1124 memcpy(active, &ctx->staging, sizeof(*active));
Wey-Yi Guy891db882011-05-27 08:40:24 -07001125 /*
1126 * We do not commit tx power settings while channel changing,
1127 * do it now if after settings changed.
1128 */
1129 iwl_set_tx_power(priv, priv->tx_power_next, false);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -07001130
1131 /* make sure we are in the right PS state */
1132 iwl_power_update_mode(priv, true);
1133
Johannes Berg2295c662010-10-23 09:15:41 -07001134 return 0;
1135 }
1136
Johannes Berg65de7e82012-04-17 07:36:30 -07001137 iwl_set_rxon_hwcrypto(priv, ctx, !iwlwifi_mod_params.sw_crypto);
Johannes Berg2295c662010-10-23 09:15:41 -07001138
1139 IWL_DEBUG_INFO(priv,
1140 "Going to commit RXON\n"
1141 " * with%s RXON_FILTER_ASSOC_MSK\n"
1142 " * channel = %d\n"
1143 " * bssid = %pM\n",
1144 (new_assoc ? "" : "out"),
1145 le16_to_cpu(ctx->staging.channel),
1146 ctx->staging.bssid_addr);
1147
1148 /*
Johannes Berg52d980c2010-11-10 09:56:45 -08001149 * Always clear associated first, but with the correct config.
1150 * This is required as for example station addition for the
1151 * AP station must be done after the BSSID is set to correctly
1152 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -07001153 */
Wey-Yi Guy3083d032011-05-06 17:06:44 -07001154 ret = iwlagn_rxon_disconn(priv, ctx);
1155 if (ret)
1156 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -07001157
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001158 ret = iwlagn_set_pan_params(priv);
1159 if (ret)
1160 return ret;
Johannes Berg2b9253d2011-05-27 08:40:26 -07001161
Wey-Yi Guyc1821c92011-04-19 16:52:59 -07001162 if (new_assoc)
1163 return iwlagn_rxon_connect(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001164
1165 return 0;
1166}
1167
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001168void iwlagn_config_ht40(struct ieee80211_conf *conf,
1169 struct iwl_rxon_context *ctx)
1170{
1171 if (conf_is_ht40_minus(conf)) {
1172 ctx->ht.extension_chan_offset =
1173 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1174 ctx->ht.is_40mhz = true;
1175 } else if (conf_is_ht40_plus(conf)) {
1176 ctx->ht.extension_chan_offset =
1177 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1178 ctx->ht.is_40mhz = true;
1179 } else {
1180 ctx->ht.extension_chan_offset =
1181 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1182 ctx->ht.is_40mhz = false;
1183 }
1184}
1185
Johannes Berg2295c662010-10-23 09:15:41 -07001186int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1187{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001188 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001189 struct iwl_rxon_context *ctx;
1190 struct ieee80211_conf *conf = &hw->conf;
1191 struct ieee80211_channel *channel = conf->channel;
1192 const struct iwl_channel_info *ch_info;
1193 int ret = 0;
1194
Johannes Berg0ca24da2012-03-15 13:26:46 -07001195 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
Johannes Berg2295c662010-10-23 09:15:41 -07001196
Johannes Bergb1eea292012-03-06 13:30:42 -08001197 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001198
Don Fry83626402012-03-07 09:52:37 -08001199 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
Johannes Berg2295c662010-10-23 09:15:41 -07001200 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1201 goto out;
1202 }
1203
Don Fry83626402012-03-07 09:52:37 -08001204 if (!iwl_is_ready(priv)) {
Johannes Berg2295c662010-10-23 09:15:41 -07001205 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1206 goto out;
1207 }
1208
1209 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1210 IEEE80211_CONF_CHANGE_CHANNEL)) {
1211 /* mac80211 uses static for non-HT which is what we want */
1212 priv->current_ht_config.smps = conf->smps_mode;
1213
1214 /*
1215 * Recalculate chain counts.
1216 *
1217 * If monitor mode is enabled then mac80211 will
1218 * set up the SM PS mode to OFF if an HT channel is
1219 * configured.
1220 */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001221 for_each_context(priv, ctx)
1222 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001223 }
1224
1225 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
Johannes Berg2295c662010-10-23 09:15:41 -07001226 ch_info = iwl_get_channel_info(priv, channel->band,
1227 channel->hw_value);
1228 if (!is_channel_valid(ch_info)) {
1229 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1230 ret = -EINVAL;
1231 goto out;
1232 }
1233
Johannes Berg2295c662010-10-23 09:15:41 -07001234 for_each_context(priv, ctx) {
1235 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -07001236 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001237 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -08001238
Johannes Berg2295c662010-10-23 09:15:41 -07001239 if (ctx->ht.enabled) {
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001240 /* if HT40 is used, it should not change
1241 * after associated except channel switch */
Wey-Yi Guy78feb352011-12-14 08:22:36 -08001242 if (!ctx->ht.is_40mhz ||
1243 !iwl_is_associated_ctx(ctx))
Wey-Yi Guy34a5b4b2011-12-02 08:19:18 -08001244 iwlagn_config_ht40(conf, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001245 } else
1246 ctx->ht.is_40mhz = false;
1247
1248 /*
1249 * Default to no protection. Protection mode will
1250 * later be set from BSS config in iwl_ht_conf
1251 */
1252 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1253
1254 /* if we are switching from ht to 2.4 clear flags
1255 * from any ht related info since 2.4 does not
1256 * support ht */
1257 if (le16_to_cpu(ctx->staging.channel) !=
1258 channel->hw_value)
1259 ctx->staging.flags = 0;
1260
1261 iwl_set_rxon_channel(priv, channel, ctx);
1262 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1263
1264 iwl_set_flags_for_band(priv, ctx, channel->band,
1265 ctx->vif);
1266 }
1267
Johannes Berg2295c662010-10-23 09:15:41 -07001268 iwl_update_bcast_stations(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001269 }
1270
1271 if (changed & (IEEE80211_CONF_CHANGE_PS |
1272 IEEE80211_CONF_CHANGE_IDLE)) {
1273 ret = iwl_power_update_mode(priv, false);
1274 if (ret)
1275 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1276 }
1277
1278 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1279 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1280 priv->tx_power_user_lmt, conf->power_level);
1281
1282 iwl_set_tx_power(priv, conf->power_level, false);
1283 }
1284
1285 for_each_context(priv, ctx) {
1286 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1287 continue;
1288 iwlagn_commit_rxon(priv, ctx);
1289 }
1290 out:
Johannes Bergb1eea292012-03-06 13:30:42 -08001291 mutex_unlock(&priv->mutex);
Wey-Yi Guy770c72c2011-10-10 07:27:10 -07001292 IWL_DEBUG_MAC80211(priv, "leave\n");
1293
Johannes Berg2295c662010-10-23 09:15:41 -07001294 return ret;
1295}
1296
David Spinadel50c1e9a2012-04-16 14:43:30 -07001297void iwlagn_check_needed_chains(struct iwl_priv *priv,
1298 struct iwl_rxon_context *ctx,
1299 struct ieee80211_bss_conf *bss_conf)
Johannes Berg2295c662010-10-23 09:15:41 -07001300{
1301 struct ieee80211_vif *vif = ctx->vif;
1302 struct iwl_rxon_context *tmp;
1303 struct ieee80211_sta *sta;
1304 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +01001305 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -07001306 bool need_multiple;
1307
Johannes Bergb1eea292012-03-06 13:30:42 -08001308 lockdep_assert_held(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001309
1310 switch (vif->type) {
1311 case NL80211_IFTYPE_STATION:
1312 rcu_read_lock();
1313 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +01001314 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -07001315 /*
1316 * If at all, this can only happen through a race
1317 * when the AP disconnects us while we're still
1318 * setting up the connection, in that case mac80211
1319 * will soon tell us about that.
1320 */
1321 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +01001322 rcu_read_unlock();
1323 break;
Johannes Berg2295c662010-10-23 09:15:41 -07001324 }
Johannes Berg850bedc2011-02-25 12:24:11 +01001325
1326 ht_cap = &sta->ht_cap;
1327
1328 need_multiple = true;
1329
1330 /*
1331 * If the peer advertises no support for receiving 2 and 3
1332 * stream MCS rates, it can't be transmitting them either.
1333 */
1334 if (ht_cap->mcs.rx_mask[1] == 0 &&
1335 ht_cap->mcs.rx_mask[2] == 0) {
1336 need_multiple = false;
1337 } else if (!(ht_cap->mcs.tx_params &
1338 IEEE80211_HT_MCS_TX_DEFINED)) {
1339 /* If it can't TX MCS at all ... */
1340 need_multiple = false;
1341 } else if (ht_cap->mcs.tx_params &
1342 IEEE80211_HT_MCS_TX_RX_DIFF) {
1343 int maxstreams;
1344
1345 /*
1346 * But if it can receive them, it might still not
1347 * be able to transmit them, which is what we need
1348 * to check here -- so check the number of streams
1349 * it advertises for TX (if different from RX).
1350 */
1351
1352 maxstreams = (ht_cap->mcs.tx_params &
1353 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1354 maxstreams >>=
1355 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1356 maxstreams += 1;
1357
1358 if (maxstreams <= 1)
1359 need_multiple = false;
1360 }
1361
Johannes Berg2295c662010-10-23 09:15:41 -07001362 rcu_read_unlock();
1363 break;
1364 case NL80211_IFTYPE_ADHOC:
1365 /* currently */
1366 need_multiple = false;
1367 break;
1368 default:
1369 /* only AP really */
1370 need_multiple = true;
1371 break;
1372 }
1373
1374 ctx->ht_need_multiple_chains = need_multiple;
1375
1376 if (!need_multiple) {
1377 /* check all contexts */
1378 for_each_context(priv, tmp) {
1379 if (!tmp->vif)
1380 continue;
1381 if (tmp->ht_need_multiple_chains) {
1382 need_multiple = true;
1383 break;
1384 }
1385 }
1386 }
1387
1388 ht_conf->single_chain_sufficient = !need_multiple;
1389}
1390
David Spinadel50c1e9a2012-04-16 14:43:30 -07001391void iwlagn_chain_noise_reset(struct iwl_priv *priv)
Don Fry5c3d29f2011-07-08 08:46:29 -07001392{
1393 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1394 int ret;
1395
Dor Shaishbfb45f52012-03-26 08:20:55 -07001396 if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED))
1397 return;
1398
Don Fry5c3d29f2011-07-08 08:46:29 -07001399 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1400 iwl_is_any_associated(priv)) {
1401 struct iwl_calib_chain_noise_reset_cmd cmd;
1402
1403 /* clear data for chain noise calibration algorithm */
1404 data->chain_noise_a = 0;
1405 data->chain_noise_b = 0;
1406 data->chain_noise_c = 0;
1407 data->chain_signal_a = 0;
1408 data->chain_signal_b = 0;
1409 data->chain_signal_c = 0;
1410 data->beacon_count = 0;
1411
1412 memset(&cmd, 0, sizeof(cmd));
1413 iwl_set_calib_hdr(&cmd.hdr,
Wey-Yi Guy898ed672011-07-13 08:38:57 -07001414 priv->phy_calib_chain_noise_reset_cmd);
Johannes Berge10a0532012-03-06 13:30:39 -08001415 ret = iwl_dvm_send_cmd_pdu(priv,
Don Fry5c3d29f2011-07-08 08:46:29 -07001416 REPLY_PHY_CALIBRATION_CMD,
1417 CMD_SYNC, sizeof(cmd), &cmd);
1418 if (ret)
1419 IWL_ERR(priv,
1420 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1421 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1422 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1423 }
1424}
1425
Johannes Berg2295c662010-10-23 09:15:41 -07001426void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1427 struct ieee80211_vif *vif,
1428 struct ieee80211_bss_conf *bss_conf,
1429 u32 changes)
1430{
Emmanuel Grumbachd0f76d62012-02-09 16:08:15 +02001431 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
Johannes Berg2295c662010-10-23 09:15:41 -07001432 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1433 int ret;
1434 bool force = false;
1435
Johannes Bergb1eea292012-03-06 13:30:42 -08001436 mutex_lock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001437
Don Fry83626402012-03-07 09:52:37 -08001438 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -08001439 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001440 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -08001441 return;
1442 }
1443
1444 if (unlikely(!ctx->vif)) {
1445 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Bergb1eea292012-03-06 13:30:42 -08001446 mutex_unlock(&priv->mutex);
Johannes Berg893654d2010-11-10 18:25:47 -08001447 return;
1448 }
1449
Johannes Berg2295c662010-10-23 09:15:41 -07001450 if (changes & BSS_CHANGED_BEACON_INT)
1451 force = true;
1452
1453 if (changes & BSS_CHANGED_QOS) {
1454 ctx->qos_data.qos_active = bss_conf->qos;
1455 iwlagn_update_qos(priv, ctx);
1456 }
1457
1458 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1459 if (vif->bss_conf.use_short_preamble)
1460 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1461 else
1462 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1463
1464 if (changes & BSS_CHANGED_ASSOC) {
1465 if (bss_conf->assoc) {
Johannes Berge9ac0742012-03-13 14:29:30 +01001466 priv->timestamp = bss_conf->last_tsf;
Johannes Berg2295c662010-10-23 09:15:41 -07001467 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1468 } else {
Garen Tamrazian68b99312011-03-30 02:29:32 -07001469 /*
1470 * If we disassociate while there are pending
1471 * frames, just wake up the queues and let the
1472 * frames "escape" ... This shouldn't really
1473 * be happening to start with, but we should
1474 * not get stuck in this case either since it
1475 * can happen if userspace gets confused.
1476 */
Johannes Berge755f882012-03-07 09:52:16 -08001477 iwlagn_lift_passive_no_rx(priv);
1478
Johannes Berg2295c662010-10-23 09:15:41 -07001479 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Bergc8ac61c2011-07-15 13:23:45 -07001480
1481 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1482 priv->have_rekey_data = false;
Johannes Berg2295c662010-10-23 09:15:41 -07001483 }
Meenakshi Venkataraman207ecc52011-07-08 08:46:23 -07001484
1485 iwlagn_bt_coex_rssi_monitor(priv);
Johannes Berg2295c662010-10-23 09:15:41 -07001486 }
1487
1488 if (ctx->ht.enabled) {
1489 ctx->ht.protection = bss_conf->ht_operation_mode &
1490 IEEE80211_HT_OP_MODE_PROTECTION;
1491 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1492 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1493 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -08001494 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -07001495 }
1496
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001497 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -07001498
1499 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1500 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1501 else
1502 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1503
1504 if (bss_conf->use_cts_prot)
1505 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1506 else
1507 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1508
1509 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1510
1511 if (vif->type == NL80211_IFTYPE_AP ||
1512 vif->type == NL80211_IFTYPE_ADHOC) {
1513 if (vif->bss_conf.enable_beacon) {
1514 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1515 priv->beacon_ctx = ctx;
1516 } else {
1517 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1518 priv->beacon_ctx = NULL;
1519 }
1520 }
1521
Meenakshi Venkataraman758f5552012-02-08 12:04:41 -08001522 /*
1523 * If the ucode decides to do beacon filtering before
1524 * association, it will lose beacons that are needed
1525 * before sending frames out on passive channels. This
1526 * causes association failures on those channels. Enable
1527 * receiving beacons in such cases.
1528 */
1529
1530 if (vif->type == NL80211_IFTYPE_STATION) {
1531 if (!bss_conf->assoc)
1532 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1533 else
1534 ctx->staging.filter_flags &=
1535 ~RXON_FILTER_BCON_AWARE_MSK;
1536 }
1537
Johannes Berg2295c662010-10-23 09:15:41 -07001538 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1539 iwlagn_commit_rxon(priv, ctx);
1540
Johannes Berg8da8e622010-11-10 09:56:46 -08001541 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1542 /*
1543 * The chain noise calibration will enable PM upon
1544 * completion. If calibration has already been run
1545 * then we need to enable power management here.
1546 */
1547 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1548 iwl_power_update_mode(priv, false);
1549
1550 /* Enable RX differential gain and sensitivity calibrations */
Dor Shaishbfb45f52012-03-26 08:20:55 -07001551 iwlagn_chain_noise_reset(priv);
Johannes Berg8da8e622010-11-10 09:56:46 -08001552 priv->start_calib = 1;
1553 }
1554
Johannes Berg2295c662010-10-23 09:15:41 -07001555 if (changes & BSS_CHANGED_IBSS) {
1556 ret = iwlagn_manage_ibss_station(priv, vif,
1557 bss_conf->ibss_joined);
1558 if (ret)
1559 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1560 bss_conf->ibss_joined ? "add" : "remove",
1561 bss_conf->bssid);
1562 }
1563
Johannes Bergbd50a8ab2010-10-23 09:15:42 -07001564 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1565 priv->beacon_ctx) {
1566 if (iwlagn_update_beacon(priv, vif))
1567 IWL_ERR(priv, "Error sending IBSS beacon\n");
1568 }
1569
Johannes Bergb1eea292012-03-06 13:30:42 -08001570 mutex_unlock(&priv->mutex);
Johannes Berg2295c662010-10-23 09:15:41 -07001571}
Johannes Bergae79d232010-11-10 09:56:38 -08001572
1573void iwlagn_post_scan(struct iwl_priv *priv)
1574{
1575 struct iwl_rxon_context *ctx;
1576
1577 /*
Wey-Yi Guyc2b821d2011-06-03 07:54:14 -07001578 * We do not commit power settings while scan is pending,
1579 * do it now if the settings changed.
1580 */
1581 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1582 iwl_set_tx_power(priv, priv->tx_power_next, false);
1583
1584 /*
Johannes Bergae79d232010-11-10 09:56:38 -08001585 * Since setting the RXON may have been deferred while
1586 * performing the scan, fire one off if needed
1587 */
1588 for_each_context(priv, ctx)
1589 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1590 iwlagn_commit_rxon(priv, ctx);
1591
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -07001592 iwlagn_set_pan_params(priv);
Johannes Bergae79d232010-11-10 09:56:38 -08001593}