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