blob: c365295cc59fef3144a58963c322eae0811f6cd0 [file] [log] [blame]
Johannes Berg2295c662010-10-23 09:15:41 -07001/******************************************************************************
2 *
Wey-Yi Guy901069c2011-04-05 09:42:00 -07003 * Copyright(c) 2003 - 2011 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
27#include "iwl-dev.h"
28#include "iwl-agn.h"
29#include "iwl-sta.h"
30#include "iwl-core.h"
31#include "iwl-agn-calib.h"
Garen Tamrazian68b99312011-03-30 02:29:32 -070032#include "iwl-helpers.h"
Johannes Berg2295c662010-10-23 09:15:41 -070033
34static 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;
Emmanuel Grumbache419d622011-07-08 08:46:14 -070042 ret = priv->trans.ops->send_cmd_pdu(priv, ctx->rxon_cmd,
43 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -070044
45 send->filter_flags = old_filter;
46
47 if (ret)
48 IWL_ERR(priv, "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
49
50 return ret;
51}
52
53static int iwlagn_disable_pan(struct iwl_priv *priv,
54 struct iwl_rxon_context *ctx,
55 struct iwl_rxon_cmd *send)
56{
Johannes Berg311dce72011-01-04 16:22:01 -080057 struct iwl_notification_wait disable_wait;
Johannes Berg2295c662010-10-23 09:15:41 -070058 __le32 old_filter = send->filter_flags;
59 u8 old_dev_type = send->dev_type;
60 int ret;
61
Johannes Berg09f18af2011-04-13 03:14:47 -070062 iwlagn_init_notification_wait(priv, &disable_wait,
63 REPLY_WIPAN_DEACTIVATION_COMPLETE,
64 NULL, NULL);
Johannes Berg311dce72011-01-04 16:22:01 -080065
Johannes Berg2295c662010-10-23 09:15:41 -070066 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
67 send->dev_type = RXON_DEV_TYPE_P2P;
Emmanuel Grumbache419d622011-07-08 08:46:14 -070068 ret = priv->trans.ops->send_cmd_pdu(priv, ctx->rxon_cmd,
69 CMD_SYNC, sizeof(*send), send);
Johannes Berg2295c662010-10-23 09:15:41 -070070
71 send->filter_flags = old_filter;
72 send->dev_type = old_dev_type;
73
Johannes Berg311dce72011-01-04 16:22:01 -080074 if (ret) {
Johannes Berg2295c662010-10-23 09:15:41 -070075 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
Johannes Berg311dce72011-01-04 16:22:01 -080076 iwlagn_remove_notification(priv, &disable_wait);
77 } else {
Johannes Berga8674a12011-04-13 03:14:48 -070078 ret = iwlagn_wait_notification(priv, &disable_wait, HZ);
79 if (ret)
Johannes Berg311dce72011-01-04 16:22:01 -080080 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
81 }
Johannes Berg2295c662010-10-23 09:15:41 -070082
83 return ret;
84}
85
Johannes Berg2b9253d2011-05-27 08:40:26 -070086static int iwlagn_disconn_pan(struct iwl_priv *priv,
87 struct iwl_rxon_context *ctx,
88 struct iwl_rxon_cmd *send)
89{
90 __le32 old_filter = send->filter_flags;
91 int ret;
92
93 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbache419d622011-07-08 08:46:14 -070094 ret = priv->trans.ops->send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
95 sizeof(*send), send);
Johannes Berg2b9253d2011-05-27 08:40:26 -070096
97 send->filter_flags = old_filter;
98
99 return ret;
100}
101
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800102static void iwlagn_update_qos(struct iwl_priv *priv,
103 struct iwl_rxon_context *ctx)
104{
105 int ret;
106
107 if (!ctx->is_active)
108 return;
109
110 ctx->qos_data.def_qos_parm.qos_flags = 0;
111
112 if (ctx->qos_data.qos_active)
113 ctx->qos_data.def_qos_parm.qos_flags |=
114 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
115
116 if (ctx->ht.enabled)
117 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
118
119 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
120 ctx->qos_data.qos_active,
121 ctx->qos_data.def_qos_parm.qos_flags);
122
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700123 ret = priv->trans.ops->send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
Shanyu Zhaof4115d42010-11-10 18:25:58 -0800124 sizeof(struct iwl_qosparam_cmd),
125 &ctx->qos_data.def_qos_parm);
126 if (ret)
127 IWL_ERR(priv, "Failed to update QoS\n");
128}
129
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700130static int iwlagn_update_beacon(struct iwl_priv *priv,
131 struct ieee80211_vif *vif)
132{
133 lockdep_assert_held(&priv->mutex);
134
135 dev_kfree_skb(priv->beacon_skb);
136 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
137 if (!priv->beacon_skb)
138 return -ENOMEM;
139 return iwlagn_send_beacon_cmd(priv);
140}
141
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700142static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
143 struct iwl_rxon_context *ctx)
144{
145 int ret = 0;
Wey-Yi Guy89e746b2011-04-19 16:52:58 -0700146 struct iwl_rxon_assoc_cmd rxon_assoc;
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700147 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
148 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
149
150 if ((rxon1->flags == rxon2->flags) &&
151 (rxon1->filter_flags == rxon2->filter_flags) &&
152 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
153 (rxon1->ofdm_ht_single_stream_basic_rates ==
154 rxon2->ofdm_ht_single_stream_basic_rates) &&
155 (rxon1->ofdm_ht_dual_stream_basic_rates ==
156 rxon2->ofdm_ht_dual_stream_basic_rates) &&
157 (rxon1->ofdm_ht_triple_stream_basic_rates ==
158 rxon2->ofdm_ht_triple_stream_basic_rates) &&
159 (rxon1->acquisition_data == rxon2->acquisition_data) &&
160 (rxon1->rx_chain == rxon2->rx_chain) &&
161 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
162 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
163 return 0;
164 }
165
166 rxon_assoc.flags = ctx->staging.flags;
167 rxon_assoc.filter_flags = ctx->staging.filter_flags;
168 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
169 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
170 rxon_assoc.reserved1 = 0;
171 rxon_assoc.reserved2 = 0;
172 rxon_assoc.reserved3 = 0;
173 rxon_assoc.ofdm_ht_single_stream_basic_rates =
174 ctx->staging.ofdm_ht_single_stream_basic_rates;
175 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
176 ctx->staging.ofdm_ht_dual_stream_basic_rates;
177 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
178 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
179 ctx->staging.ofdm_ht_triple_stream_basic_rates;
180 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
181
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700182 ret = priv->trans.ops->send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
183 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700184 return ret;
185}
186
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700187static int iwlagn_rxon_disconn(struct iwl_priv *priv,
188 struct iwl_rxon_context *ctx)
189{
190 int ret;
191 struct iwl_rxon_cmd *active = (void *)&ctx->active;
192
Johannes Berg2b9253d2011-05-27 08:40:26 -0700193 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700194 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700195 } else {
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700196 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
Johannes Berg2b9253d2011-05-27 08:40:26 -0700197 if (ret)
198 return ret;
199 if (ctx->vif) {
200 ret = iwl_send_rxon_timing(priv, ctx);
201 if (ret) {
202 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
203 return ret;
204 }
205 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
206 }
207 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700208 if (ret)
209 return ret;
210
211 /*
212 * Un-assoc RXON clears the station table and WEP
213 * keys, so we have to restore those afterwards.
214 */
215 iwl_clear_ucode_stations(priv, ctx);
Johannes Bergf775aa06d2011-06-22 06:34:09 -0700216 /* update -- might need P2P now */
217 iwl_update_bcast_station(priv, ctx);
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700218 iwl_restore_stations(priv, ctx);
219 ret = iwl_restore_default_wep_keys(priv, ctx);
220 if (ret) {
221 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
222 return ret;
223 }
224
225 memcpy(active, &ctx->staging, sizeof(*active));
226 return 0;
227}
228
229static int iwlagn_rxon_connect(struct iwl_priv *priv,
230 struct iwl_rxon_context *ctx)
231{
232 int ret;
233 struct iwl_rxon_cmd *active = (void *)&ctx->active;
234
235 /* RXON timing must be before associated RXON */
Johannes Berg2b9253d2011-05-27 08:40:26 -0700236 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
237 ret = iwl_send_rxon_timing(priv, ctx);
238 if (ret) {
239 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
240 return ret;
241 }
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700242 }
243 /* QoS info may be cleared by previous un-assoc RXON */
244 iwlagn_update_qos(priv, ctx);
245
246 /*
247 * We'll run into this code path when beaconing is
248 * enabled, but then we also need to send the beacon
249 * to the device.
250 */
251 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
252 ret = iwlagn_update_beacon(priv, ctx->vif);
253 if (ret) {
254 IWL_ERR(priv,
255 "Error sending required beacon (%d)!\n",
256 ret);
257 return ret;
258 }
259 }
260
261 priv->start_calib = 0;
262 /*
263 * Apply the new configuration.
264 *
265 * Associated RXON doesn't clear the station table in uCode,
266 * so we don't need to restore stations etc. after this.
267 */
Emmanuel Grumbache419d622011-07-08 08:46:14 -0700268 ret = priv->trans.ops->send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700269 sizeof(struct iwl_rxon_cmd), &ctx->staging);
270 if (ret) {
271 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
272 return ret;
273 }
274 memcpy(active, &ctx->staging, sizeof(*active));
275
276 iwl_reprogram_ap_sta(priv, ctx);
277
278 /* IBSS beacon needs to be sent after setting assoc */
279 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
280 if (iwlagn_update_beacon(priv, ctx->vif))
281 IWL_ERR(priv, "Error sending IBSS beacon\n");
282 iwl_init_sensitivity(priv);
283
284 /*
285 * If we issue a new RXON command which required a tune then
286 * we must send a new TXPOWER command or we won't be able to
287 * Tx any frames.
288 *
289 * It's expected we set power here if channel is changing.
290 */
291 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
292 if (ret) {
293 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
294 return ret;
295 }
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700296
297 if ((ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION) &&
298 priv->cfg->ht_params->smps_mode)
299 ieee80211_request_smps(ctx->vif,
300 priv->cfg->ht_params->smps_mode);
301
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700302 return 0;
303}
304
Johannes Berg2295c662010-10-23 09:15:41 -0700305/**
306 * iwlagn_commit_rxon - commit staging_rxon to hardware
307 *
308 * The RXON command in staging_rxon is committed to the hardware and
309 * the active_rxon structure is updated with the new data. This
310 * function correctly transitions out of the RXON_ASSOC_MSK state if
311 * a HW tune is required based on the RXON structure changes.
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700312 *
313 * The connect/disconnect flow should be as the following:
314 *
315 * 1. make sure send RXON command with association bit unset if not connect
316 * this should include the channel and the band for the candidate
317 * to be connected to
318 * 2. Add Station before RXON association with the AP
319 * 3. RXON_timing has to send before RXON for connection
320 * 4. full RXON command - associated bit set
321 * 5. use RXON_ASSOC command to update any flags changes
Johannes Berg2295c662010-10-23 09:15:41 -0700322 */
323int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
324{
325 /* cast away the const for active_rxon in this function */
326 struct iwl_rxon_cmd *active = (void *)&ctx->active;
Johannes Berg2295c662010-10-23 09:15:41 -0700327 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
328 int ret;
329
330 lockdep_assert_held(&priv->mutex);
331
Wey-Yi Guyadb90a02010-11-26 11:09:42 -0800332 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
333 return -EINVAL;
334
Johannes Berg2295c662010-10-23 09:15:41 -0700335 if (!iwl_is_alive(priv))
336 return -EBUSY;
337
338 /* This function hardcodes a bunch of dual-mode assumptions */
339 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
340
341 if (!ctx->is_active)
342 return 0;
343
344 /* always get timestamp with Rx frame */
345 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
346
Johannes Berg9b9190d2011-01-06 08:07:10 -0800347 if (ctx->ctxid == IWL_RXON_CTX_PAN && priv->_agn.hw_roc_channel) {
348 struct ieee80211_channel *chan = priv->_agn.hw_roc_channel;
349
350 iwl_set_rxon_channel(priv, chan, ctx);
351 iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
352 ctx->staging.filter_flags |=
353 RXON_FILTER_ASSOC_MSK |
354 RXON_FILTER_PROMISC_MSK |
355 RXON_FILTER_CTL2HOST_MSK;
356 ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
357 new_assoc = true;
358
359 if (memcmp(&ctx->staging, &ctx->active,
360 sizeof(ctx->staging)) == 0)
361 return 0;
362 }
363
Stanislaw Gruszka42b70a52011-05-26 17:14:22 +0200364 /*
365 * force CTS-to-self frames protection if RTS-CTS is not preferred
366 * one aggregation protection method
367 */
368 if (!(priv->cfg->ht_params &&
369 priv->cfg->ht_params->use_rts_for_aggregation))
370 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
371
Johannes Berg2295c662010-10-23 09:15:41 -0700372 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
373 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
374 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
375 else
376 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
377
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700378 iwl_print_rx_config_cmd(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700379 ret = iwl_check_rxon_cmd(priv, ctx);
380 if (ret) {
381 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
382 return -EINVAL;
383 }
384
385 /*
386 * receive commit_rxon request
387 * abort any previous channel switch if still in process
388 */
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200389 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
390 (priv->switch_channel != ctx->staging.channel)) {
Johannes Berg2295c662010-10-23 09:15:41 -0700391 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
Stanislaw Gruszka6f213ff2011-06-02 18:17:15 +0200392 le16_to_cpu(priv->switch_channel));
Johannes Berg2295c662010-10-23 09:15:41 -0700393 iwl_chswitch_done(priv, false);
394 }
395
396 /*
397 * If we don't need to send a full RXON, we can use
398 * iwl_rxon_assoc_cmd which is used to reconfigure filter
399 * and other flags for the current radio configuration.
400 */
401 if (!iwl_full_rxon_required(priv, ctx)) {
Wey-Yi Guyc3f6e9c2011-04-19 16:52:57 -0700402 ret = iwlagn_send_rxon_assoc(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700403 if (ret) {
404 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
405 return ret;
406 }
407
408 memcpy(active, &ctx->staging, sizeof(*active));
Wey-Yi Guy891db882011-05-27 08:40:24 -0700409 /*
410 * We do not commit tx power settings while channel changing,
411 * do it now if after settings changed.
412 */
413 iwl_set_tx_power(priv, priv->tx_power_next, false);
Wey-Yi Guy15b3f3b2011-06-03 07:54:13 -0700414
415 /* make sure we are in the right PS state */
416 iwl_power_update_mode(priv, true);
417
Johannes Berg2295c662010-10-23 09:15:41 -0700418 return 0;
419 }
420
Don Fry9d143e92011-04-20 15:23:57 -0700421 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
Johannes Berg2295c662010-10-23 09:15:41 -0700422
423 IWL_DEBUG_INFO(priv,
424 "Going to commit RXON\n"
425 " * with%s RXON_FILTER_ASSOC_MSK\n"
426 " * channel = %d\n"
427 " * bssid = %pM\n",
428 (new_assoc ? "" : "out"),
429 le16_to_cpu(ctx->staging.channel),
430 ctx->staging.bssid_addr);
431
432 /*
Johannes Berg52d980c2010-11-10 09:56:45 -0800433 * Always clear associated first, but with the correct config.
434 * This is required as for example station addition for the
435 * AP station must be done after the BSSID is set to correctly
436 * set up filters in the device.
Johannes Berg2295c662010-10-23 09:15:41 -0700437 */
Wey-Yi Guy3083d032011-05-06 17:06:44 -0700438 ret = iwlagn_rxon_disconn(priv, ctx);
439 if (ret)
440 return ret;
Johannes Berg2295c662010-10-23 09:15:41 -0700441
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700442 ret = iwlagn_set_pan_params(priv);
443 if (ret)
444 return ret;
Johannes Berg2b9253d2011-05-27 08:40:26 -0700445
Wey-Yi Guyc1821c92011-04-19 16:52:59 -0700446 if (new_assoc)
447 return iwlagn_rxon_connect(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700448
449 return 0;
450}
451
452int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
453{
454 struct iwl_priv *priv = hw->priv;
455 struct iwl_rxon_context *ctx;
456 struct ieee80211_conf *conf = &hw->conf;
457 struct ieee80211_channel *channel = conf->channel;
458 const struct iwl_channel_info *ch_info;
459 int ret = 0;
460
461 IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
462
463 mutex_lock(&priv->mutex);
464
465 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
466 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
467 goto out;
468 }
469
470 if (!iwl_is_ready(priv)) {
471 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
472 goto out;
473 }
474
475 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
476 IEEE80211_CONF_CHANGE_CHANNEL)) {
477 /* mac80211 uses static for non-HT which is what we want */
478 priv->current_ht_config.smps = conf->smps_mode;
479
480 /*
481 * Recalculate chain counts.
482 *
483 * If monitor mode is enabled then mac80211 will
484 * set up the SM PS mode to OFF if an HT channel is
485 * configured.
486 */
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700487 for_each_context(priv, ctx)
488 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700489 }
490
491 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
492 unsigned long flags;
493
494 ch_info = iwl_get_channel_info(priv, channel->band,
495 channel->hw_value);
496 if (!is_channel_valid(ch_info)) {
497 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
498 ret = -EINVAL;
499 goto out;
500 }
501
502 spin_lock_irqsave(&priv->lock, flags);
503
504 for_each_context(priv, ctx) {
505 /* Configure HT40 channels */
Daniel Halperin7caa2312011-04-06 12:47:25 -0700506 if (ctx->ht.enabled != conf_is_ht(conf))
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800507 ctx->ht.enabled = conf_is_ht(conf);
Wey-Yi Guy35a6eb32010-11-10 09:56:43 -0800508
Johannes Berg2295c662010-10-23 09:15:41 -0700509 if (ctx->ht.enabled) {
510 if (conf_is_ht40_minus(conf)) {
511 ctx->ht.extension_chan_offset =
512 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
513 ctx->ht.is_40mhz = true;
514 } else if (conf_is_ht40_plus(conf)) {
515 ctx->ht.extension_chan_offset =
516 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
517 ctx->ht.is_40mhz = true;
518 } else {
519 ctx->ht.extension_chan_offset =
520 IEEE80211_HT_PARAM_CHA_SEC_NONE;
521 ctx->ht.is_40mhz = false;
522 }
523 } else
524 ctx->ht.is_40mhz = false;
525
526 /*
527 * Default to no protection. Protection mode will
528 * later be set from BSS config in iwl_ht_conf
529 */
530 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
531
532 /* if we are switching from ht to 2.4 clear flags
533 * from any ht related info since 2.4 does not
534 * support ht */
535 if (le16_to_cpu(ctx->staging.channel) !=
536 channel->hw_value)
537 ctx->staging.flags = 0;
538
539 iwl_set_rxon_channel(priv, channel, ctx);
540 iwl_set_rxon_ht(priv, &priv->current_ht_config);
541
542 iwl_set_flags_for_band(priv, ctx, channel->band,
543 ctx->vif);
544 }
545
546 spin_unlock_irqrestore(&priv->lock, flags);
547
548 iwl_update_bcast_stations(priv);
549
550 /*
551 * The list of supported rates and rate mask can be different
552 * for each band; since the band may have changed, reset
553 * the rate mask to what mac80211 lists.
554 */
555 iwl_set_rate(priv);
556 }
557
558 if (changed & (IEEE80211_CONF_CHANGE_PS |
559 IEEE80211_CONF_CHANGE_IDLE)) {
560 ret = iwl_power_update_mode(priv, false);
561 if (ret)
562 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
563 }
564
565 if (changed & IEEE80211_CONF_CHANGE_POWER) {
566 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
567 priv->tx_power_user_lmt, conf->power_level);
568
569 iwl_set_tx_power(priv, conf->power_level, false);
570 }
571
572 for_each_context(priv, ctx) {
573 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
574 continue;
575 iwlagn_commit_rxon(priv, ctx);
576 }
577 out:
578 mutex_unlock(&priv->mutex);
579 return ret;
580}
581
Johannes Berg2295c662010-10-23 09:15:41 -0700582static void iwlagn_check_needed_chains(struct iwl_priv *priv,
583 struct iwl_rxon_context *ctx,
584 struct ieee80211_bss_conf *bss_conf)
585{
586 struct ieee80211_vif *vif = ctx->vif;
587 struct iwl_rxon_context *tmp;
588 struct ieee80211_sta *sta;
589 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
Johannes Berg850bedc2011-02-25 12:24:11 +0100590 struct ieee80211_sta_ht_cap *ht_cap;
Johannes Berg2295c662010-10-23 09:15:41 -0700591 bool need_multiple;
592
593 lockdep_assert_held(&priv->mutex);
594
595 switch (vif->type) {
596 case NL80211_IFTYPE_STATION:
597 rcu_read_lock();
598 sta = ieee80211_find_sta(vif, bss_conf->bssid);
Johannes Berg850bedc2011-02-25 12:24:11 +0100599 if (!sta) {
Johannes Berg2295c662010-10-23 09:15:41 -0700600 /*
601 * If at all, this can only happen through a race
602 * when the AP disconnects us while we're still
603 * setting up the connection, in that case mac80211
604 * will soon tell us about that.
605 */
606 need_multiple = false;
Johannes Berg850bedc2011-02-25 12:24:11 +0100607 rcu_read_unlock();
608 break;
Johannes Berg2295c662010-10-23 09:15:41 -0700609 }
Johannes Berg850bedc2011-02-25 12:24:11 +0100610
611 ht_cap = &sta->ht_cap;
612
613 need_multiple = true;
614
615 /*
616 * If the peer advertises no support for receiving 2 and 3
617 * stream MCS rates, it can't be transmitting them either.
618 */
619 if (ht_cap->mcs.rx_mask[1] == 0 &&
620 ht_cap->mcs.rx_mask[2] == 0) {
621 need_multiple = false;
622 } else if (!(ht_cap->mcs.tx_params &
623 IEEE80211_HT_MCS_TX_DEFINED)) {
624 /* If it can't TX MCS at all ... */
625 need_multiple = false;
626 } else if (ht_cap->mcs.tx_params &
627 IEEE80211_HT_MCS_TX_RX_DIFF) {
628 int maxstreams;
629
630 /*
631 * But if it can receive them, it might still not
632 * be able to transmit them, which is what we need
633 * to check here -- so check the number of streams
634 * it advertises for TX (if different from RX).
635 */
636
637 maxstreams = (ht_cap->mcs.tx_params &
638 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
639 maxstreams >>=
640 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
641 maxstreams += 1;
642
643 if (maxstreams <= 1)
644 need_multiple = false;
645 }
646
Johannes Berg2295c662010-10-23 09:15:41 -0700647 rcu_read_unlock();
648 break;
649 case NL80211_IFTYPE_ADHOC:
650 /* currently */
651 need_multiple = false;
652 break;
653 default:
654 /* only AP really */
655 need_multiple = true;
656 break;
657 }
658
659 ctx->ht_need_multiple_chains = need_multiple;
660
661 if (!need_multiple) {
662 /* check all contexts */
663 for_each_context(priv, tmp) {
664 if (!tmp->vif)
665 continue;
666 if (tmp->ht_need_multiple_chains) {
667 need_multiple = true;
668 break;
669 }
670 }
671 }
672
673 ht_conf->single_chain_sufficient = !need_multiple;
674}
675
676void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
677 struct ieee80211_vif *vif,
678 struct ieee80211_bss_conf *bss_conf,
679 u32 changes)
680{
681 struct iwl_priv *priv = hw->priv;
682 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
683 int ret;
684 bool force = false;
685
686 mutex_lock(&priv->mutex);
687
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800688 if (unlikely(!iwl_is_ready(priv))) {
Wey-Yi Guy14a085e2010-12-14 07:38:58 -0800689 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
690 mutex_unlock(&priv->mutex);
Shanyu Zhaoae0b6932010-12-02 11:02:28 -0800691 return;
692 }
693
694 if (unlikely(!ctx->vif)) {
695 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
Johannes Berg893654d2010-11-10 18:25:47 -0800696 mutex_unlock(&priv->mutex);
697 return;
698 }
699
Johannes Berg2295c662010-10-23 09:15:41 -0700700 if (changes & BSS_CHANGED_BEACON_INT)
701 force = true;
702
703 if (changes & BSS_CHANGED_QOS) {
704 ctx->qos_data.qos_active = bss_conf->qos;
705 iwlagn_update_qos(priv, ctx);
706 }
707
708 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
709 if (vif->bss_conf.use_short_preamble)
710 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
711 else
712 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
713
714 if (changes & BSS_CHANGED_ASSOC) {
715 if (bss_conf->assoc) {
Johannes Berg2295c662010-10-23 09:15:41 -0700716 priv->timestamp = bss_conf->timestamp;
717 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
718 } else {
Garen Tamrazian68b99312011-03-30 02:29:32 -0700719 /*
720 * If we disassociate while there are pending
721 * frames, just wake up the queues and let the
722 * frames "escape" ... This shouldn't really
723 * be happening to start with, but we should
724 * not get stuck in this case either since it
725 * can happen if userspace gets confused.
726 */
727 if (ctx->last_tx_rejected) {
728 ctx->last_tx_rejected = false;
729 iwl_wake_any_queue(priv, ctx);
730 }
Johannes Berg2295c662010-10-23 09:15:41 -0700731 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Johannes Berg2295c662010-10-23 09:15:41 -0700732 }
733 }
734
735 if (ctx->ht.enabled) {
736 ctx->ht.protection = bss_conf->ht_operation_mode &
737 IEEE80211_HT_OP_MODE_PROTECTION;
738 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
739 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
740 iwlagn_check_needed_chains(priv, ctx, bss_conf);
Johannes Bergb2769b82010-11-10 09:56:47 -0800741 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Johannes Berg2295c662010-10-23 09:15:41 -0700742 }
743
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700744 iwlagn_set_rxon_chain(priv, ctx);
Johannes Berg2295c662010-10-23 09:15:41 -0700745
746 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
747 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
748 else
749 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
750
751 if (bss_conf->use_cts_prot)
752 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
753 else
754 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
755
756 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
757
758 if (vif->type == NL80211_IFTYPE_AP ||
759 vif->type == NL80211_IFTYPE_ADHOC) {
760 if (vif->bss_conf.enable_beacon) {
761 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
762 priv->beacon_ctx = ctx;
763 } else {
764 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
765 priv->beacon_ctx = NULL;
766 }
767 }
768
769 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
770 iwlagn_commit_rxon(priv, ctx);
771
Johannes Berg8da8e622010-11-10 09:56:46 -0800772 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
773 /*
774 * The chain noise calibration will enable PM upon
775 * completion. If calibration has already been run
776 * then we need to enable power management here.
777 */
778 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
779 iwl_power_update_mode(priv, false);
780
781 /* Enable RX differential gain and sensitivity calibrations */
782 iwl_chain_noise_reset(priv);
783 priv->start_calib = 1;
784 }
785
Johannes Berg2295c662010-10-23 09:15:41 -0700786 if (changes & BSS_CHANGED_IBSS) {
787 ret = iwlagn_manage_ibss_station(priv, vif,
788 bss_conf->ibss_joined);
789 if (ret)
790 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
791 bss_conf->ibss_joined ? "add" : "remove",
792 bss_conf->bssid);
793 }
794
Johannes Bergbd50a8ab2010-10-23 09:15:42 -0700795 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
796 priv->beacon_ctx) {
797 if (iwlagn_update_beacon(priv, vif))
798 IWL_ERR(priv, "Error sending IBSS beacon\n");
799 }
800
Johannes Berg2295c662010-10-23 09:15:41 -0700801 mutex_unlock(&priv->mutex);
802}
Johannes Bergae79d232010-11-10 09:56:38 -0800803
804void iwlagn_post_scan(struct iwl_priv *priv)
805{
806 struct iwl_rxon_context *ctx;
807
808 /*
Wey-Yi Guyc2b821d2011-06-03 07:54:14 -0700809 * We do not commit power settings while scan is pending,
810 * do it now if the settings changed.
811 */
812 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
813 iwl_set_tx_power(priv, priv->tx_power_next, false);
814
815 /*
Johannes Bergae79d232010-11-10 09:56:38 -0800816 * Since setting the RXON may have been deferred while
817 * performing the scan, fire one off if needed
818 */
819 for_each_context(priv, ctx)
820 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
821 iwlagn_commit_rxon(priv, ctx);
822
Wey-Yi Guye3f10ce2011-07-01 07:59:26 -0700823 iwlagn_set_pan_params(priv);
Johannes Bergae79d232010-11-10 09:56:38 -0800824}