Commit | Line | Data |
---|---|---|
2295c66b JB |
1 | /****************************************************************************** |
2 | * | |
fb4961db | 3 | * Copyright(c) 2003 - 2012 Intel Corporation. All rights reserved. |
2295c66b JB |
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 | ||
55620921 | 27 | #include <linux/etherdevice.h> |
2295c66b JB |
28 | #include "iwl-dev.h" |
29 | #include "iwl-agn.h" | |
2295c66b JB |
30 | #include "iwl-core.h" |
31 | #include "iwl-agn-calib.h" | |
bdfbf092 | 32 | #include "iwl-trans.h" |
48f20d35 | 33 | #include "iwl-shared.h" |
2295c66b | 34 | |
47042ac2 MV |
35 | /* |
36 | * initialize rxon structure with default values from eeprom | |
37 | */ | |
38 | void iwl_connection_init_rx_config(struct iwl_priv *priv, | |
39 | struct iwl_rxon_context *ctx) | |
40 | { | |
41 | const struct iwl_channel_info *ch_info; | |
42 | ||
43 | memset(&ctx->staging, 0, sizeof(ctx->staging)); | |
44 | ||
45 | if (!ctx->vif) { | |
46 | ctx->staging.dev_type = ctx->unused_devtype; | |
47 | } else | |
48 | switch (ctx->vif->type) { | |
49 | case NL80211_IFTYPE_AP: | |
50 | ctx->staging.dev_type = ctx->ap_devtype; | |
51 | break; | |
52 | ||
53 | case NL80211_IFTYPE_STATION: | |
54 | ctx->staging.dev_type = ctx->station_devtype; | |
55 | ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; | |
56 | break; | |
57 | ||
58 | case NL80211_IFTYPE_ADHOC: | |
59 | ctx->staging.dev_type = ctx->ibss_devtype; | |
60 | ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK; | |
61 | ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK | | |
62 | RXON_FILTER_ACCEPT_GRP_MSK; | |
63 | break; | |
64 | ||
65 | default: | |
66 | IWL_ERR(priv, "Unsupported interface type %d\n", | |
67 | ctx->vif->type); | |
68 | break; | |
69 | } | |
70 | ||
71 | #if 0 | |
72 | /* TODO: Figure out when short_preamble would be set and cache from | |
73 | * that */ | |
74 | if (!hw_to_local(priv->hw)->short_preamble) | |
75 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
76 | else | |
77 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | |
78 | #endif | |
79 | ||
80 | ch_info = iwl_get_channel_info(priv, priv->band, | |
81 | le16_to_cpu(ctx->active.channel)); | |
82 | ||
83 | if (!ch_info) | |
84 | ch_info = &priv->channel_info[0]; | |
85 | ||
86 | ctx->staging.channel = cpu_to_le16(ch_info->channel); | |
87 | priv->band = ch_info->band; | |
88 | ||
89 | iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif); | |
90 | ||
91 | ctx->staging.ofdm_basic_rates = | |
92 | (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; | |
93 | ctx->staging.cck_basic_rates = | |
94 | (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; | |
95 | ||
96 | /* clear both MIX and PURE40 mode flag */ | |
97 | ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | | |
98 | RXON_FLG_CHANNEL_MODE_PURE_40); | |
99 | if (ctx->vif) | |
100 | memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN); | |
101 | ||
102 | ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff; | |
103 | ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff; | |
104 | ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff; | |
105 | } | |
106 | ||
2295c66b JB |
107 | static int iwlagn_disable_bss(struct iwl_priv *priv, |
108 | struct iwl_rxon_context *ctx, | |
109 | struct iwl_rxon_cmd *send) | |
110 | { | |
111 | __le32 old_filter = send->filter_flags; | |
112 | int ret; | |
113 | ||
114 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
e10a0533 | 115 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, |
e419d62d | 116 | CMD_SYNC, sizeof(*send), send); |
2295c66b JB |
117 | |
118 | send->filter_flags = old_filter; | |
119 | ||
120 | if (ret) | |
b36b110c TP |
121 | IWL_DEBUG_QUIET_RFKILL(priv, |
122 | "Error clearing ASSOC_MSK on BSS (%d)\n", ret); | |
2295c66b JB |
123 | |
124 | return ret; | |
125 | } | |
126 | ||
127 | static int iwlagn_disable_pan(struct iwl_priv *priv, | |
128 | struct iwl_rxon_context *ctx, | |
129 | struct iwl_rxon_cmd *send) | |
130 | { | |
311dce71 | 131 | struct iwl_notification_wait disable_wait; |
2295c66b JB |
132 | __le32 old_filter = send->filter_flags; |
133 | u8 old_dev_type = send->dev_type; | |
134 | int ret; | |
db662d47 JB |
135 | static const u8 deactivate_cmd[] = { |
136 | REPLY_WIPAN_DEACTIVATION_COMPLETE | |
137 | }; | |
2295c66b | 138 | |
4bd14dd5 | 139 | iwl_init_notification_wait(&priv->notif_wait, &disable_wait, |
db662d47 | 140 | deactivate_cmd, ARRAY_SIZE(deactivate_cmd), |
4bd14dd5 | 141 | NULL, NULL); |
311dce71 | 142 | |
2295c66b JB |
143 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
144 | send->dev_type = RXON_DEV_TYPE_P2P; | |
e10a0533 | 145 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, |
e419d62d | 146 | CMD_SYNC, sizeof(*send), send); |
2295c66b JB |
147 | |
148 | send->filter_flags = old_filter; | |
149 | send->dev_type = old_dev_type; | |
150 | ||
311dce71 | 151 | if (ret) { |
2295c66b | 152 | IWL_ERR(priv, "Error disabling PAN (%d)\n", ret); |
4bd14dd5 | 153 | iwl_remove_notification(&priv->notif_wait, &disable_wait); |
311dce71 | 154 | } else { |
4bd14dd5 JB |
155 | ret = iwl_wait_notification(&priv->notif_wait, |
156 | &disable_wait, HZ); | |
a8674a1e | 157 | if (ret) |
311dce71 JB |
158 | IWL_ERR(priv, "Timed out waiting for PAN disable\n"); |
159 | } | |
2295c66b JB |
160 | |
161 | return ret; | |
162 | } | |
163 | ||
2b9253d2 JB |
164 | static int iwlagn_disconn_pan(struct iwl_priv *priv, |
165 | struct iwl_rxon_context *ctx, | |
166 | struct iwl_rxon_cmd *send) | |
167 | { | |
168 | __le32 old_filter = send->filter_flags; | |
169 | int ret; | |
170 | ||
171 | send->filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
e10a0533 | 172 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, |
e419d62d | 173 | sizeof(*send), send); |
2b9253d2 JB |
174 | |
175 | send->filter_flags = old_filter; | |
176 | ||
177 | return ret; | |
178 | } | |
179 | ||
f4115d46 SZ |
180 | static void iwlagn_update_qos(struct iwl_priv *priv, |
181 | struct iwl_rxon_context *ctx) | |
182 | { | |
183 | int ret; | |
184 | ||
185 | if (!ctx->is_active) | |
186 | return; | |
187 | ||
188 | ctx->qos_data.def_qos_parm.qos_flags = 0; | |
189 | ||
190 | if (ctx->qos_data.qos_active) | |
191 | ctx->qos_data.def_qos_parm.qos_flags |= | |
192 | QOS_PARAM_FLG_UPDATE_EDCA_MSK; | |
193 | ||
194 | if (ctx->ht.enabled) | |
195 | ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; | |
196 | ||
0dcf50ca | 197 | IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", |
f4115d46 SZ |
198 | ctx->qos_data.qos_active, |
199 | ctx->qos_data.def_qos_parm.qos_flags); | |
200 | ||
e10a0533 | 201 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC, |
f4115d46 SZ |
202 | sizeof(struct iwl_qosparam_cmd), |
203 | &ctx->qos_data.def_qos_parm); | |
204 | if (ret) | |
b36b110c | 205 | IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n"); |
f4115d46 SZ |
206 | } |
207 | ||
bd50a8ab JB |
208 | static int iwlagn_update_beacon(struct iwl_priv *priv, |
209 | struct ieee80211_vif *vif) | |
210 | { | |
b1eea297 | 211 | lockdep_assert_held(&priv->mutex); |
bd50a8ab JB |
212 | |
213 | dev_kfree_skb(priv->beacon_skb); | |
214 | priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif); | |
215 | if (!priv->beacon_skb) | |
216 | return -ENOMEM; | |
217 | return iwlagn_send_beacon_cmd(priv); | |
218 | } | |
219 | ||
c3f6e9cf WYG |
220 | static int iwlagn_send_rxon_assoc(struct iwl_priv *priv, |
221 | struct iwl_rxon_context *ctx) | |
222 | { | |
223 | int ret = 0; | |
89e746b2 | 224 | struct iwl_rxon_assoc_cmd rxon_assoc; |
c3f6e9cf WYG |
225 | const struct iwl_rxon_cmd *rxon1 = &ctx->staging; |
226 | const struct iwl_rxon_cmd *rxon2 = &ctx->active; | |
227 | ||
228 | if ((rxon1->flags == rxon2->flags) && | |
229 | (rxon1->filter_flags == rxon2->filter_flags) && | |
230 | (rxon1->cck_basic_rates == rxon2->cck_basic_rates) && | |
231 | (rxon1->ofdm_ht_single_stream_basic_rates == | |
232 | rxon2->ofdm_ht_single_stream_basic_rates) && | |
233 | (rxon1->ofdm_ht_dual_stream_basic_rates == | |
234 | rxon2->ofdm_ht_dual_stream_basic_rates) && | |
235 | (rxon1->ofdm_ht_triple_stream_basic_rates == | |
236 | rxon2->ofdm_ht_triple_stream_basic_rates) && | |
237 | (rxon1->acquisition_data == rxon2->acquisition_data) && | |
238 | (rxon1->rx_chain == rxon2->rx_chain) && | |
239 | (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) { | |
240 | IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n"); | |
241 | return 0; | |
242 | } | |
243 | ||
244 | rxon_assoc.flags = ctx->staging.flags; | |
245 | rxon_assoc.filter_flags = ctx->staging.filter_flags; | |
246 | rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates; | |
247 | rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates; | |
248 | rxon_assoc.reserved1 = 0; | |
249 | rxon_assoc.reserved2 = 0; | |
250 | rxon_assoc.reserved3 = 0; | |
251 | rxon_assoc.ofdm_ht_single_stream_basic_rates = | |
252 | ctx->staging.ofdm_ht_single_stream_basic_rates; | |
253 | rxon_assoc.ofdm_ht_dual_stream_basic_rates = | |
254 | ctx->staging.ofdm_ht_dual_stream_basic_rates; | |
255 | rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain; | |
256 | rxon_assoc.ofdm_ht_triple_stream_basic_rates = | |
257 | ctx->staging.ofdm_ht_triple_stream_basic_rates; | |
258 | rxon_assoc.acquisition_data = ctx->staging.acquisition_data; | |
259 | ||
e10a0533 | 260 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd, |
e419d62d | 261 | CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc); |
c3f6e9cf WYG |
262 | return ret; |
263 | } | |
264 | ||
dff96c1e MV |
265 | static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val) |
266 | { | |
267 | u16 new_val; | |
268 | u16 beacon_factor; | |
269 | ||
270 | /* | |
271 | * If mac80211 hasn't given us a beacon interval, program | |
272 | * the default into the device (not checking this here | |
273 | * would cause the adjustment below to return the maximum | |
274 | * value, which may break PAN.) | |
275 | */ | |
276 | if (!beacon_val) | |
277 | return DEFAULT_BEACON_INTERVAL; | |
278 | ||
279 | /* | |
280 | * If the beacon interval we obtained from the peer | |
281 | * is too large, we'll have to wake up more often | |
282 | * (and in IBSS case, we'll beacon too much) | |
283 | * | |
284 | * For example, if max_beacon_val is 4096, and the | |
285 | * requested beacon interval is 7000, we'll have to | |
286 | * use 3500 to be able to wake up on the beacons. | |
287 | * | |
288 | * This could badly influence beacon detection stats. | |
289 | */ | |
290 | ||
291 | beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val; | |
292 | new_val = beacon_val / beacon_factor; | |
293 | ||
294 | if (!new_val) | |
295 | new_val = max_beacon_val; | |
296 | ||
297 | return new_val; | |
298 | } | |
299 | ||
300 | static int iwl_send_rxon_timing(struct iwl_priv *priv, | |
301 | struct iwl_rxon_context *ctx) | |
302 | { | |
303 | u64 tsf; | |
304 | s32 interval_tm, rem; | |
305 | struct ieee80211_conf *conf = NULL; | |
306 | u16 beacon_int; | |
307 | struct ieee80211_vif *vif = ctx->vif; | |
308 | ||
309 | conf = &priv->hw->conf; | |
310 | ||
311 | lockdep_assert_held(&priv->mutex); | |
312 | ||
313 | memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd)); | |
314 | ||
315 | ctx->timing.timestamp = cpu_to_le64(priv->timestamp); | |
316 | ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval); | |
317 | ||
318 | beacon_int = vif ? vif->bss_conf.beacon_int : 0; | |
319 | ||
320 | /* | |
321 | * TODO: For IBSS we need to get atim_window from mac80211, | |
322 | * for now just always use 0 | |
323 | */ | |
324 | ctx->timing.atim_window = 0; | |
325 | ||
326 | if (ctx->ctxid == IWL_RXON_CTX_PAN && | |
327 | (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) && | |
328 | iwl_is_associated(priv, IWL_RXON_CTX_BSS) && | |
329 | priv->contexts[IWL_RXON_CTX_BSS].vif && | |
330 | priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) { | |
331 | ctx->timing.beacon_interval = | |
332 | priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval; | |
333 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); | |
334 | } else if (ctx->ctxid == IWL_RXON_CTX_BSS && | |
335 | iwl_is_associated(priv, IWL_RXON_CTX_PAN) && | |
336 | priv->contexts[IWL_RXON_CTX_PAN].vif && | |
337 | priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int && | |
338 | (!iwl_is_associated_ctx(ctx) || !ctx->vif || | |
339 | !ctx->vif->bss_conf.beacon_int)) { | |
340 | ctx->timing.beacon_interval = | |
341 | priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval; | |
342 | beacon_int = le16_to_cpu(ctx->timing.beacon_interval); | |
343 | } else { | |
344 | beacon_int = iwl_adjust_beacon_interval(beacon_int, | |
345 | IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT); | |
346 | ctx->timing.beacon_interval = cpu_to_le16(beacon_int); | |
347 | } | |
348 | ||
349 | ctx->beacon_int = beacon_int; | |
350 | ||
351 | tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ | |
352 | interval_tm = beacon_int * TIME_UNIT; | |
353 | rem = do_div(tsf, interval_tm); | |
354 | ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem); | |
355 | ||
356 | ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1; | |
357 | ||
358 | IWL_DEBUG_ASSOC(priv, | |
359 | "beacon interval %d beacon timer %d beacon tim %d\n", | |
360 | le16_to_cpu(ctx->timing.beacon_interval), | |
361 | le32_to_cpu(ctx->timing.beacon_init_val), | |
362 | le16_to_cpu(ctx->timing.atim_window)); | |
363 | ||
364 | return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd, | |
365 | CMD_SYNC, sizeof(ctx->timing), &ctx->timing); | |
366 | } | |
367 | ||
c1821c95 WYG |
368 | static int iwlagn_rxon_disconn(struct iwl_priv *priv, |
369 | struct iwl_rxon_context *ctx) | |
370 | { | |
371 | int ret; | |
372 | struct iwl_rxon_cmd *active = (void *)&ctx->active; | |
373 | ||
2b9253d2 | 374 | if (ctx->ctxid == IWL_RXON_CTX_BSS) { |
c1821c95 | 375 | ret = iwlagn_disable_bss(priv, ctx, &ctx->staging); |
2b9253d2 | 376 | } else { |
c1821c95 | 377 | ret = iwlagn_disable_pan(priv, ctx, &ctx->staging); |
2b9253d2 JB |
378 | if (ret) |
379 | return ret; | |
380 | if (ctx->vif) { | |
381 | ret = iwl_send_rxon_timing(priv, ctx); | |
382 | if (ret) { | |
383 | IWL_ERR(priv, "Failed to send timing (%d)!\n", ret); | |
384 | return ret; | |
385 | } | |
386 | ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging); | |
387 | } | |
388 | } | |
c1821c95 WYG |
389 | if (ret) |
390 | return ret; | |
391 | ||
392 | /* | |
393 | * Un-assoc RXON clears the station table and WEP | |
394 | * keys, so we have to restore those afterwards. | |
395 | */ | |
396 | iwl_clear_ucode_stations(priv, ctx); | |
f775aa06 JB |
397 | /* update -- might need P2P now */ |
398 | iwl_update_bcast_station(priv, ctx); | |
c1821c95 WYG |
399 | iwl_restore_stations(priv, ctx); |
400 | ret = iwl_restore_default_wep_keys(priv, ctx); | |
401 | if (ret) { | |
402 | IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); | |
403 | return ret; | |
404 | } | |
405 | ||
406 | memcpy(active, &ctx->staging, sizeof(*active)); | |
407 | return 0; | |
408 | } | |
409 | ||
e6a62a6e MV |
410 | static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force) |
411 | { | |
412 | int ret; | |
413 | s8 prev_tx_power; | |
414 | bool defer; | |
415 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
416 | ||
417 | 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 | ||
c1821c95 WYG |
465 | static 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 */ | |
2b9253d2 JB |
472 | 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 | } | |
c1821c95 WYG |
478 | } |
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 | */ | |
e10a0533 | 504 | ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC, |
c1821c95 WYG |
505 | 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 | ||
c1821c95 WYG |
512 | /* 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 | } | |
15b3f3b0 | 530 | |
107ef97a | 531 | if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION && |
38622419 | 532 | cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode) |
15b3f3b0 | 533 | ieee80211_request_smps(ctx->vif, |
38622419 | 534 | cfg(priv)->ht_params->smps_mode); |
15b3f3b0 | 535 | |
c1821c95 WYG |
536 | return 0; |
537 | } | |
538 | ||
e505c433 WYG |
539 | int 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 | ||
a18f61bc | 546 | if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS)) |
e505c433 WYG |
547 | return 0; |
548 | ||
549 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | |
550 | ||
b1eea297 | 551 | lockdep_assert_held(&priv->mutex); |
e505c433 WYG |
552 | |
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 | ||
c6baf7fb | 573 | if (priv->hw_roc_setup) { |
e505c433 | 574 | /* both contexts must be used for this to happen */ |
c6baf7fb JB |
575 | slot1 = IWL_MIN_SLOT_TIME; |
576 | slot0 = 3000; | |
e505c433 | 577 | } else if (ctx_bss->vif && ctx_pan->vif) { |
bbb05cb5 | 578 | int bcnint = ctx_pan->beacon_int; |
e505c433 WYG |
579 | 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 && | |
bbb05cb5 | 586 | bcnint != ctx_bss->beacon_int) { |
e505c433 WYG |
587 | IWL_ERR(priv, |
588 | "beacon intervals don't match (%d, %d)\n", | |
bbb05cb5 | 589 | ctx_bss->beacon_int, ctx_pan->beacon_int); |
e505c433 WYG |
590 | } else |
591 | bcnint = max_t(int, bcnint, | |
bbb05cb5 | 592 | ctx_bss->beacon_int); |
e505c433 WYG |
593 | if (!bcnint) |
594 | bcnint = DEFAULT_BEACON_INTERVAL; | |
595 | slot0 = bcnint / 2; | |
596 | slot1 = bcnint - slot0; | |
597 | ||
83626404 | 598 | if (test_bit(STATUS_SCAN_HW, &priv->status) || |
e505c433 WYG |
599 | (!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) { | |
325a7ddf | 605 | slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME; |
e505c433 WYG |
606 | 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) * | |
bbb05cb5 | 611 | ctx_pan->beacon_int; |
e505c433 WYG |
612 | slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1); |
613 | ||
83626404 | 614 | if (test_bit(STATUS_SCAN_HW, &priv->status)) { |
e505c433 WYG |
615 | 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 | ||
e10a0533 | 623 | ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC, |
e505c433 WYG |
624 | sizeof(cmd), &cmd); |
625 | if (ret) | |
626 | IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret); | |
627 | ||
628 | return ret; | |
629 | } | |
630 | ||
dd64173e MV |
631 | static 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 | ||
713 | void 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 | ||
fedfa87a MV |
721 | /** |
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 | */ | |
728 | void 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 | ||
50319f74 MV |
750 | void 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 | ||
aecd44f0 MV |
773 | void iwl_set_rate(struct iwl_priv *priv) |
774 | { | |
775 | struct iwl_rxon_context *ctx; | |
776 | ||
777 | for_each_context(priv, ctx) { | |
778 | ctx->staging.cck_basic_rates = | |
779 | (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; | |
780 | ||
781 | ctx->staging.ofdm_basic_rates = | |
782 | (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; | |
783 | } | |
784 | } | |
785 | ||
354a4530 MV |
786 | static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, |
787 | struct iwl_rxon_context *ctx, int hw_decrypt) | |
788 | { | |
789 | struct iwl_rxon_cmd *rxon = &ctx->staging; | |
790 | ||
791 | if (hw_decrypt) | |
792 | rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; | |
793 | else | |
794 | rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK; | |
795 | ||
796 | } | |
797 | ||
8931b576 MV |
798 | /* validate RXON structure is valid */ |
799 | static int iwl_check_rxon_cmd(struct iwl_priv *priv, | |
800 | struct iwl_rxon_context *ctx) | |
801 | { | |
802 | struct iwl_rxon_cmd *rxon = &ctx->staging; | |
803 | u32 errors = 0; | |
804 | ||
805 | if (rxon->flags & RXON_FLG_BAND_24G_MSK) { | |
806 | if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) { | |
807 | IWL_WARN(priv, "check 2.4G: wrong narrow\n"); | |
808 | errors |= BIT(0); | |
809 | } | |
810 | if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) { | |
811 | IWL_WARN(priv, "check 2.4G: wrong radar\n"); | |
812 | errors |= BIT(1); | |
813 | } | |
814 | } else { | |
815 | if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) { | |
816 | IWL_WARN(priv, "check 5.2G: not short slot!\n"); | |
817 | errors |= BIT(2); | |
818 | } | |
819 | if (rxon->flags & RXON_FLG_CCK_MSK) { | |
820 | IWL_WARN(priv, "check 5.2G: CCK!\n"); | |
821 | errors |= BIT(3); | |
822 | } | |
823 | } | |
824 | if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) { | |
825 | IWL_WARN(priv, "mac/bssid mcast!\n"); | |
826 | errors |= BIT(4); | |
827 | } | |
828 | ||
829 | /* make sure basic rates 6Mbps and 1Mbps are supported */ | |
830 | if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 && | |
831 | (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) { | |
832 | IWL_WARN(priv, "neither 1 nor 6 are basic\n"); | |
833 | errors |= BIT(5); | |
834 | } | |
835 | ||
836 | if (le16_to_cpu(rxon->assoc_id) > 2007) { | |
837 | IWL_WARN(priv, "aid > 2007\n"); | |
838 | errors |= BIT(6); | |
839 | } | |
840 | ||
841 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) | |
842 | == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) { | |
843 | IWL_WARN(priv, "CCK and short slot\n"); | |
844 | errors |= BIT(7); | |
845 | } | |
846 | ||
847 | if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) | |
848 | == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) { | |
849 | IWL_WARN(priv, "CCK and auto detect"); | |
850 | errors |= BIT(8); | |
851 | } | |
852 | ||
853 | if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK | | |
854 | RXON_FLG_TGG_PROTECT_MSK)) == | |
855 | RXON_FLG_TGG_PROTECT_MSK) { | |
856 | IWL_WARN(priv, "TGg but no auto-detect\n"); | |
857 | errors |= BIT(9); | |
858 | } | |
859 | ||
860 | if (rxon->channel == 0) { | |
861 | IWL_WARN(priv, "zero channel is invalid\n"); | |
862 | errors |= BIT(10); | |
863 | } | |
864 | ||
865 | WARN(errors, "Invalid RXON (%#x), channel %d", | |
866 | errors, le16_to_cpu(rxon->channel)); | |
867 | ||
868 | return errors ? -EINVAL : 0; | |
869 | } | |
870 | ||
55620921 MV |
871 | /** |
872 | * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed | |
873 | * @priv: staging_rxon is compared to active_rxon | |
874 | * | |
875 | * If the RXON structure is changing enough to require a new tune, | |
876 | * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that | |
877 | * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. | |
878 | */ | |
879 | static int iwl_full_rxon_required(struct iwl_priv *priv, | |
880 | struct iwl_rxon_context *ctx) | |
881 | { | |
882 | const struct iwl_rxon_cmd *staging = &ctx->staging; | |
883 | const struct iwl_rxon_cmd *active = &ctx->active; | |
884 | ||
885 | #define CHK(cond) \ | |
886 | if ((cond)) { \ | |
887 | IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \ | |
888 | return 1; \ | |
889 | } | |
890 | ||
891 | #define CHK_NEQ(c1, c2) \ | |
892 | if ((c1) != (c2)) { \ | |
893 | IWL_DEBUG_INFO(priv, "need full RXON - " \ | |
894 | #c1 " != " #c2 " - %d != %d\n", \ | |
895 | (c1), (c2)); \ | |
896 | return 1; \ | |
897 | } | |
898 | ||
899 | /* These items are only settable from the full RXON command */ | |
900 | CHK(!iwl_is_associated_ctx(ctx)); | |
901 | CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr)); | |
902 | CHK(compare_ether_addr(staging->node_addr, active->node_addr)); | |
903 | CHK(compare_ether_addr(staging->wlap_bssid_addr, | |
904 | active->wlap_bssid_addr)); | |
905 | CHK_NEQ(staging->dev_type, active->dev_type); | |
906 | CHK_NEQ(staging->channel, active->channel); | |
907 | CHK_NEQ(staging->air_propagation, active->air_propagation); | |
908 | CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates, | |
909 | active->ofdm_ht_single_stream_basic_rates); | |
910 | CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates, | |
911 | active->ofdm_ht_dual_stream_basic_rates); | |
912 | CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates, | |
913 | active->ofdm_ht_triple_stream_basic_rates); | |
914 | CHK_NEQ(staging->assoc_id, active->assoc_id); | |
915 | ||
916 | /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can | |
917 | * be updated with the RXON_ASSOC command -- however only some | |
918 | * flag transitions are allowed using RXON_ASSOC */ | |
919 | ||
920 | /* Check if we are not switching bands */ | |
921 | CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK, | |
922 | active->flags & RXON_FLG_BAND_24G_MSK); | |
923 | ||
924 | /* Check if we are switching association toggle */ | |
925 | CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK, | |
926 | active->filter_flags & RXON_FILTER_ASSOC_MSK); | |
927 | ||
928 | #undef CHK | |
929 | #undef CHK_NEQ | |
930 | ||
931 | return 0; | |
932 | } | |
933 | ||
2295c66b JB |
934 | /** |
935 | * iwlagn_commit_rxon - commit staging_rxon to hardware | |
936 | * | |
937 | * The RXON command in staging_rxon is committed to the hardware and | |
938 | * the active_rxon structure is updated with the new data. This | |
939 | * function correctly transitions out of the RXON_ASSOC_MSK state if | |
940 | * a HW tune is required based on the RXON structure changes. | |
c1821c95 WYG |
941 | * |
942 | * The connect/disconnect flow should be as the following: | |
943 | * | |
944 | * 1. make sure send RXON command with association bit unset if not connect | |
945 | * this should include the channel and the band for the candidate | |
946 | * to be connected to | |
947 | * 2. Add Station before RXON association with the AP | |
948 | * 3. RXON_timing has to send before RXON for connection | |
949 | * 4. full RXON command - associated bit set | |
950 | * 5. use RXON_ASSOC command to update any flags changes | |
2295c66b JB |
951 | */ |
952 | int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | |
953 | { | |
954 | /* cast away the const for active_rxon in this function */ | |
955 | struct iwl_rxon_cmd *active = (void *)&ctx->active; | |
2295c66b JB |
956 | bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK); |
957 | int ret; | |
958 | ||
b1eea297 | 959 | lockdep_assert_held(&priv->mutex); |
2295c66b | 960 | |
83626404 | 961 | if (!iwl_is_alive(priv)) |
2295c66b JB |
962 | return -EBUSY; |
963 | ||
964 | /* This function hardcodes a bunch of dual-mode assumptions */ | |
965 | BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2); | |
966 | ||
967 | if (!ctx->is_active) | |
968 | return 0; | |
969 | ||
970 | /* always get timestamp with Rx frame */ | |
971 | ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK; | |
972 | ||
42b70a5f SG |
973 | /* |
974 | * force CTS-to-self frames protection if RTS-CTS is not preferred | |
975 | * one aggregation protection method | |
976 | */ | |
9e295116 | 977 | if (!priv->hw_params.use_rts_for_aggregation) |
42b70a5f SG |
978 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; |
979 | ||
2295c66b JB |
980 | if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) || |
981 | !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK)) | |
982 | ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK; | |
983 | else | |
984 | ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK; | |
985 | ||
522376d2 | 986 | iwl_print_rx_config_cmd(priv, ctx->ctxid); |
2295c66b JB |
987 | ret = iwl_check_rxon_cmd(priv, ctx); |
988 | if (ret) { | |
989 | IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); | |
990 | return -EINVAL; | |
991 | } | |
992 | ||
993 | /* | |
994 | * receive commit_rxon request | |
995 | * abort any previous channel switch if still in process | |
996 | */ | |
83626404 | 997 | if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) && |
6f213ff1 | 998 | (priv->switch_channel != ctx->staging.channel)) { |
2295c66b | 999 | IWL_DEBUG_11H(priv, "abort channel switch on %d\n", |
6f213ff1 | 1000 | le16_to_cpu(priv->switch_channel)); |
2295c66b JB |
1001 | iwl_chswitch_done(priv, false); |
1002 | } | |
1003 | ||
1004 | /* | |
1005 | * If we don't need to send a full RXON, we can use | |
1006 | * iwl_rxon_assoc_cmd which is used to reconfigure filter | |
1007 | * and other flags for the current radio configuration. | |
1008 | */ | |
1009 | if (!iwl_full_rxon_required(priv, ctx)) { | |
c3f6e9cf | 1010 | ret = iwlagn_send_rxon_assoc(priv, ctx); |
2295c66b JB |
1011 | if (ret) { |
1012 | IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); | |
1013 | return ret; | |
1014 | } | |
1015 | ||
1016 | memcpy(active, &ctx->staging, sizeof(*active)); | |
891db881 WYG |
1017 | /* |
1018 | * We do not commit tx power settings while channel changing, | |
1019 | * do it now if after settings changed. | |
1020 | */ | |
1021 | iwl_set_tx_power(priv, priv->tx_power_next, false); | |
15b3f3b0 WYG |
1022 | |
1023 | /* make sure we are in the right PS state */ | |
1024 | iwl_power_update_mode(priv, true); | |
1025 | ||
2295c66b JB |
1026 | return 0; |
1027 | } | |
1028 | ||
9d143e9a | 1029 | iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto); |
2295c66b JB |
1030 | |
1031 | IWL_DEBUG_INFO(priv, | |
1032 | "Going to commit RXON\n" | |
1033 | " * with%s RXON_FILTER_ASSOC_MSK\n" | |
1034 | " * channel = %d\n" | |
1035 | " * bssid = %pM\n", | |
1036 | (new_assoc ? "" : "out"), | |
1037 | le16_to_cpu(ctx->staging.channel), | |
1038 | ctx->staging.bssid_addr); | |
1039 | ||
1040 | /* | |
52d980c0 JB |
1041 | * Always clear associated first, but with the correct config. |
1042 | * This is required as for example station addition for the | |
1043 | * AP station must be done after the BSSID is set to correctly | |
1044 | * set up filters in the device. | |
2295c66b | 1045 | */ |
3083d03c WYG |
1046 | ret = iwlagn_rxon_disconn(priv, ctx); |
1047 | if (ret) | |
1048 | return ret; | |
2295c66b | 1049 | |
e3f10cea WYG |
1050 | ret = iwlagn_set_pan_params(priv); |
1051 | if (ret) | |
1052 | return ret; | |
2b9253d2 | 1053 | |
c1821c95 WYG |
1054 | if (new_assoc) |
1055 | return iwlagn_rxon_connect(priv, ctx); | |
2295c66b JB |
1056 | |
1057 | return 0; | |
1058 | } | |
1059 | ||
34a5b4b6 WYG |
1060 | void iwlagn_config_ht40(struct ieee80211_conf *conf, |
1061 | struct iwl_rxon_context *ctx) | |
1062 | { | |
1063 | if (conf_is_ht40_minus(conf)) { | |
1064 | ctx->ht.extension_chan_offset = | |
1065 | IEEE80211_HT_PARAM_CHA_SEC_BELOW; | |
1066 | ctx->ht.is_40mhz = true; | |
1067 | } else if (conf_is_ht40_plus(conf)) { | |
1068 | ctx->ht.extension_chan_offset = | |
1069 | IEEE80211_HT_PARAM_CHA_SEC_ABOVE; | |
1070 | ctx->ht.is_40mhz = true; | |
1071 | } else { | |
1072 | ctx->ht.extension_chan_offset = | |
1073 | IEEE80211_HT_PARAM_CHA_SEC_NONE; | |
1074 | ctx->ht.is_40mhz = false; | |
1075 | } | |
1076 | } | |
1077 | ||
2295c66b JB |
1078 | int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed) |
1079 | { | |
d0f76d68 | 1080 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
2295c66b JB |
1081 | struct iwl_rxon_context *ctx; |
1082 | struct ieee80211_conf *conf = &hw->conf; | |
1083 | struct ieee80211_channel *channel = conf->channel; | |
1084 | const struct iwl_channel_info *ch_info; | |
1085 | int ret = 0; | |
1086 | ||
0ca24daf | 1087 | IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed); |
2295c66b | 1088 | |
b1eea297 | 1089 | mutex_lock(&priv->mutex); |
2295c66b | 1090 | |
83626404 | 1091 | if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) { |
2295c66b JB |
1092 | IWL_DEBUG_MAC80211(priv, "leave - scanning\n"); |
1093 | goto out; | |
1094 | } | |
1095 | ||
83626404 | 1096 | if (!iwl_is_ready(priv)) { |
2295c66b JB |
1097 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
1098 | goto out; | |
1099 | } | |
1100 | ||
1101 | if (changed & (IEEE80211_CONF_CHANGE_SMPS | | |
1102 | IEEE80211_CONF_CHANGE_CHANNEL)) { | |
1103 | /* mac80211 uses static for non-HT which is what we want */ | |
1104 | priv->current_ht_config.smps = conf->smps_mode; | |
1105 | ||
1106 | /* | |
1107 | * Recalculate chain counts. | |
1108 | * | |
1109 | * If monitor mode is enabled then mac80211 will | |
1110 | * set up the SM PS mode to OFF if an HT channel is | |
1111 | * configured. | |
1112 | */ | |
e3f10cea WYG |
1113 | for_each_context(priv, ctx) |
1114 | iwlagn_set_rxon_chain(priv, ctx); | |
2295c66b JB |
1115 | } |
1116 | ||
1117 | if (changed & IEEE80211_CONF_CHANGE_CHANNEL) { | |
2295c66b JB |
1118 | ch_info = iwl_get_channel_info(priv, channel->band, |
1119 | channel->hw_value); | |
1120 | if (!is_channel_valid(ch_info)) { | |
1121 | IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n"); | |
1122 | ret = -EINVAL; | |
1123 | goto out; | |
1124 | } | |
1125 | ||
2295c66b JB |
1126 | for_each_context(priv, ctx) { |
1127 | /* Configure HT40 channels */ | |
7caa2316 | 1128 | if (ctx->ht.enabled != conf_is_ht(conf)) |
35a6eb36 | 1129 | ctx->ht.enabled = conf_is_ht(conf); |
35a6eb36 | 1130 | |
2295c66b | 1131 | if (ctx->ht.enabled) { |
34a5b4b6 WYG |
1132 | /* if HT40 is used, it should not change |
1133 | * after associated except channel switch */ | |
78feb35b WYG |
1134 | if (!ctx->ht.is_40mhz || |
1135 | !iwl_is_associated_ctx(ctx)) | |
34a5b4b6 | 1136 | iwlagn_config_ht40(conf, ctx); |
2295c66b JB |
1137 | } else |
1138 | ctx->ht.is_40mhz = false; | |
1139 | ||
1140 | /* | |
1141 | * Default to no protection. Protection mode will | |
1142 | * later be set from BSS config in iwl_ht_conf | |
1143 | */ | |
1144 | ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; | |
1145 | ||
1146 | /* if we are switching from ht to 2.4 clear flags | |
1147 | * from any ht related info since 2.4 does not | |
1148 | * support ht */ | |
1149 | if (le16_to_cpu(ctx->staging.channel) != | |
1150 | channel->hw_value) | |
1151 | ctx->staging.flags = 0; | |
1152 | ||
1153 | iwl_set_rxon_channel(priv, channel, ctx); | |
1154 | iwl_set_rxon_ht(priv, &priv->current_ht_config); | |
1155 | ||
1156 | iwl_set_flags_for_band(priv, ctx, channel->band, | |
1157 | ctx->vif); | |
1158 | } | |
1159 | ||
2295c66b JB |
1160 | iwl_update_bcast_stations(priv); |
1161 | ||
1162 | /* | |
1163 | * The list of supported rates and rate mask can be different | |
1164 | * for each band; since the band may have changed, reset | |
1165 | * the rate mask to what mac80211 lists. | |
1166 | */ | |
1167 | iwl_set_rate(priv); | |
1168 | } | |
1169 | ||
1170 | if (changed & (IEEE80211_CONF_CHANGE_PS | | |
1171 | IEEE80211_CONF_CHANGE_IDLE)) { | |
1172 | ret = iwl_power_update_mode(priv, false); | |
1173 | if (ret) | |
1174 | IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n"); | |
1175 | } | |
1176 | ||
1177 | if (changed & IEEE80211_CONF_CHANGE_POWER) { | |
1178 | IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n", | |
1179 | priv->tx_power_user_lmt, conf->power_level); | |
1180 | ||
1181 | iwl_set_tx_power(priv, conf->power_level, false); | |
1182 | } | |
1183 | ||
1184 | for_each_context(priv, ctx) { | |
1185 | if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) | |
1186 | continue; | |
1187 | iwlagn_commit_rxon(priv, ctx); | |
1188 | } | |
1189 | out: | |
b1eea297 | 1190 | mutex_unlock(&priv->mutex); |
770c72c4 WYG |
1191 | IWL_DEBUG_MAC80211(priv, "leave\n"); |
1192 | ||
2295c66b JB |
1193 | return ret; |
1194 | } | |
1195 | ||
2295c66b JB |
1196 | static void iwlagn_check_needed_chains(struct iwl_priv *priv, |
1197 | struct iwl_rxon_context *ctx, | |
1198 | struct ieee80211_bss_conf *bss_conf) | |
1199 | { | |
1200 | struct ieee80211_vif *vif = ctx->vif; | |
1201 | struct iwl_rxon_context *tmp; | |
1202 | struct ieee80211_sta *sta; | |
1203 | struct iwl_ht_config *ht_conf = &priv->current_ht_config; | |
850bedcc | 1204 | struct ieee80211_sta_ht_cap *ht_cap; |
2295c66b JB |
1205 | bool need_multiple; |
1206 | ||
b1eea297 | 1207 | lockdep_assert_held(&priv->mutex); |
2295c66b JB |
1208 | |
1209 | switch (vif->type) { | |
1210 | case NL80211_IFTYPE_STATION: | |
1211 | rcu_read_lock(); | |
1212 | sta = ieee80211_find_sta(vif, bss_conf->bssid); | |
850bedcc | 1213 | if (!sta) { |
2295c66b JB |
1214 | /* |
1215 | * If at all, this can only happen through a race | |
1216 | * when the AP disconnects us while we're still | |
1217 | * setting up the connection, in that case mac80211 | |
1218 | * will soon tell us about that. | |
1219 | */ | |
1220 | need_multiple = false; | |
850bedcc JB |
1221 | rcu_read_unlock(); |
1222 | break; | |
1223 | } | |
1224 | ||
1225 | ht_cap = &sta->ht_cap; | |
1226 | ||
1227 | need_multiple = true; | |
1228 | ||
1229 | /* | |
1230 | * If the peer advertises no support for receiving 2 and 3 | |
1231 | * stream MCS rates, it can't be transmitting them either. | |
1232 | */ | |
1233 | if (ht_cap->mcs.rx_mask[1] == 0 && | |
1234 | ht_cap->mcs.rx_mask[2] == 0) { | |
1235 | need_multiple = false; | |
1236 | } else if (!(ht_cap->mcs.tx_params & | |
1237 | IEEE80211_HT_MCS_TX_DEFINED)) { | |
1238 | /* If it can't TX MCS at all ... */ | |
1239 | need_multiple = false; | |
1240 | } else if (ht_cap->mcs.tx_params & | |
1241 | IEEE80211_HT_MCS_TX_RX_DIFF) { | |
1242 | int maxstreams; | |
1243 | ||
1244 | /* | |
1245 | * But if it can receive them, it might still not | |
1246 | * be able to transmit them, which is what we need | |
1247 | * to check here -- so check the number of streams | |
1248 | * it advertises for TX (if different from RX). | |
1249 | */ | |
1250 | ||
1251 | maxstreams = (ht_cap->mcs.tx_params & | |
1252 | IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK); | |
1253 | maxstreams >>= | |
1254 | IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT; | |
1255 | maxstreams += 1; | |
1256 | ||
1257 | if (maxstreams <= 1) | |
1258 | need_multiple = false; | |
2295c66b | 1259 | } |
850bedcc | 1260 | |
2295c66b JB |
1261 | rcu_read_unlock(); |
1262 | break; | |
1263 | case NL80211_IFTYPE_ADHOC: | |
1264 | /* currently */ | |
1265 | need_multiple = false; | |
1266 | break; | |
1267 | default: | |
1268 | /* only AP really */ | |
1269 | need_multiple = true; | |
1270 | break; | |
1271 | } | |
1272 | ||
1273 | ctx->ht_need_multiple_chains = need_multiple; | |
1274 | ||
1275 | if (!need_multiple) { | |
1276 | /* check all contexts */ | |
1277 | for_each_context(priv, tmp) { | |
1278 | if (!tmp->vif) | |
1279 | continue; | |
1280 | if (tmp->ht_need_multiple_chains) { | |
1281 | need_multiple = true; | |
1282 | break; | |
1283 | } | |
1284 | } | |
1285 | } | |
1286 | ||
1287 | ht_conf->single_chain_sufficient = !need_multiple; | |
1288 | } | |
1289 | ||
5c3d29fc DF |
1290 | static void iwlagn_chain_noise_reset(struct iwl_priv *priv) |
1291 | { | |
1292 | struct iwl_chain_noise_data *data = &priv->chain_noise_data; | |
1293 | int ret; | |
1294 | ||
1295 | if ((data->state == IWL_CHAIN_NOISE_ALIVE) && | |
1296 | iwl_is_any_associated(priv)) { | |
1297 | struct iwl_calib_chain_noise_reset_cmd cmd; | |
1298 | ||
1299 | /* clear data for chain noise calibration algorithm */ | |
1300 | data->chain_noise_a = 0; | |
1301 | data->chain_noise_b = 0; | |
1302 | data->chain_noise_c = 0; | |
1303 | data->chain_signal_a = 0; | |
1304 | data->chain_signal_b = 0; | |
1305 | data->chain_signal_c = 0; | |
1306 | data->beacon_count = 0; | |
1307 | ||
1308 | memset(&cmd, 0, sizeof(cmd)); | |
1309 | iwl_set_calib_hdr(&cmd.hdr, | |
898ed67b | 1310 | priv->phy_calib_chain_noise_reset_cmd); |
e10a0533 | 1311 | ret = iwl_dvm_send_cmd_pdu(priv, |
5c3d29fc DF |
1312 | REPLY_PHY_CALIBRATION_CMD, |
1313 | CMD_SYNC, sizeof(cmd), &cmd); | |
1314 | if (ret) | |
1315 | IWL_ERR(priv, | |
1316 | "Could not send REPLY_PHY_CALIBRATION_CMD\n"); | |
1317 | data->state = IWL_CHAIN_NOISE_ACCUMULATE; | |
1318 | IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n"); | |
1319 | } | |
1320 | } | |
1321 | ||
2295c66b JB |
1322 | void iwlagn_bss_info_changed(struct ieee80211_hw *hw, |
1323 | struct ieee80211_vif *vif, | |
1324 | struct ieee80211_bss_conf *bss_conf, | |
1325 | u32 changes) | |
1326 | { | |
d0f76d68 | 1327 | struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw); |
2295c66b JB |
1328 | struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); |
1329 | int ret; | |
1330 | bool force = false; | |
1331 | ||
b1eea297 | 1332 | mutex_lock(&priv->mutex); |
2295c66b | 1333 | |
83626404 | 1334 | if (unlikely(!iwl_is_ready(priv))) { |
14a085e7 | 1335 | IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); |
b1eea297 | 1336 | mutex_unlock(&priv->mutex); |
ae0b693c SZ |
1337 | return; |
1338 | } | |
1339 | ||
1340 | if (unlikely(!ctx->vif)) { | |
1341 | IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n"); | |
b1eea297 | 1342 | mutex_unlock(&priv->mutex); |
893654de JB |
1343 | return; |
1344 | } | |
1345 | ||
2295c66b JB |
1346 | if (changes & BSS_CHANGED_BEACON_INT) |
1347 | force = true; | |
1348 | ||
1349 | if (changes & BSS_CHANGED_QOS) { | |
1350 | ctx->qos_data.qos_active = bss_conf->qos; | |
1351 | iwlagn_update_qos(priv, ctx); | |
1352 | } | |
1353 | ||
1354 | ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid); | |
1355 | if (vif->bss_conf.use_short_preamble) | |
1356 | ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; | |
1357 | else | |
1358 | ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; | |
1359 | ||
1360 | if (changes & BSS_CHANGED_ASSOC) { | |
1361 | if (bss_conf->assoc) { | |
e9ac0745 | 1362 | priv->timestamp = bss_conf->last_tsf; |
2295c66b JB |
1363 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; |
1364 | } else { | |
68b99311 GT |
1365 | /* |
1366 | * If we disassociate while there are pending | |
1367 | * frames, just wake up the queues and let the | |
1368 | * frames "escape" ... This shouldn't really | |
1369 | * be happening to start with, but we should | |
1370 | * not get stuck in this case either since it | |
1371 | * can happen if userspace gets confused. | |
1372 | */ | |
e755f882 JB |
1373 | iwlagn_lift_passive_no_rx(priv); |
1374 | ||
2295c66b | 1375 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; |
c8ac61cf JB |
1376 | |
1377 | if (ctx->ctxid == IWL_RXON_CTX_BSS) | |
1378 | priv->have_rekey_data = false; | |
2295c66b | 1379 | } |
207ecc5e MV |
1380 | |
1381 | iwlagn_bt_coex_rssi_monitor(priv); | |
2295c66b JB |
1382 | } |
1383 | ||
1384 | if (ctx->ht.enabled) { | |
1385 | ctx->ht.protection = bss_conf->ht_operation_mode & | |
1386 | IEEE80211_HT_OP_MODE_PROTECTION; | |
1387 | ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode & | |
1388 | IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); | |
1389 | iwlagn_check_needed_chains(priv, ctx, bss_conf); | |
b2769b84 | 1390 | iwl_set_rxon_ht(priv, &priv->current_ht_config); |
2295c66b JB |
1391 | } |
1392 | ||
e3f10cea | 1393 | iwlagn_set_rxon_chain(priv, ctx); |
2295c66b JB |
1394 | |
1395 | if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) | |
1396 | ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK; | |
1397 | else | |
1398 | ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK; | |
1399 | ||
1400 | if (bss_conf->use_cts_prot) | |
1401 | ctx->staging.flags |= RXON_FLG_SELF_CTS_EN; | |
1402 | else | |
1403 | ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN; | |
1404 | ||
1405 | memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN); | |
1406 | ||
1407 | if (vif->type == NL80211_IFTYPE_AP || | |
1408 | vif->type == NL80211_IFTYPE_ADHOC) { | |
1409 | if (vif->bss_conf.enable_beacon) { | |
1410 | ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK; | |
1411 | priv->beacon_ctx = ctx; | |
1412 | } else { | |
1413 | ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK; | |
1414 | priv->beacon_ctx = NULL; | |
1415 | } | |
1416 | } | |
1417 | ||
758f555f MV |
1418 | /* |
1419 | * If the ucode decides to do beacon filtering before | |
1420 | * association, it will lose beacons that are needed | |
1421 | * before sending frames out on passive channels. This | |
1422 | * causes association failures on those channels. Enable | |
1423 | * receiving beacons in such cases. | |
1424 | */ | |
1425 | ||
1426 | if (vif->type == NL80211_IFTYPE_STATION) { | |
1427 | if (!bss_conf->assoc) | |
1428 | ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK; | |
1429 | else | |
1430 | ctx->staging.filter_flags &= | |
1431 | ~RXON_FILTER_BCON_AWARE_MSK; | |
1432 | } | |
1433 | ||
2295c66b JB |
1434 | if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) |
1435 | iwlagn_commit_rxon(priv, ctx); | |
1436 | ||
8da8e628 JB |
1437 | if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) { |
1438 | /* | |
1439 | * The chain noise calibration will enable PM upon | |
1440 | * completion. If calibration has already been run | |
1441 | * then we need to enable power management here. | |
1442 | */ | |
1443 | if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE) | |
1444 | iwl_power_update_mode(priv, false); | |
1445 | ||
1446 | /* Enable RX differential gain and sensitivity calibrations */ | |
5c3d29fc DF |
1447 | if (!priv->disable_chain_noise_cal) |
1448 | iwlagn_chain_noise_reset(priv); | |
8da8e628 JB |
1449 | priv->start_calib = 1; |
1450 | } | |
1451 | ||
2295c66b JB |
1452 | if (changes & BSS_CHANGED_IBSS) { |
1453 | ret = iwlagn_manage_ibss_station(priv, vif, | |
1454 | bss_conf->ibss_joined); | |
1455 | if (ret) | |
1456 | IWL_ERR(priv, "failed to %s IBSS station %pM\n", | |
1457 | bss_conf->ibss_joined ? "add" : "remove", | |
1458 | bss_conf->bssid); | |
1459 | } | |
1460 | ||
bd50a8ab JB |
1461 | if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC && |
1462 | priv->beacon_ctx) { | |
1463 | if (iwlagn_update_beacon(priv, vif)) | |
1464 | IWL_ERR(priv, "Error sending IBSS beacon\n"); | |
1465 | } | |
1466 | ||
b1eea297 | 1467 | mutex_unlock(&priv->mutex); |
2295c66b | 1468 | } |
ae79d23d JB |
1469 | |
1470 | void iwlagn_post_scan(struct iwl_priv *priv) | |
1471 | { | |
1472 | struct iwl_rxon_context *ctx; | |
1473 | ||
c2b821d7 WYG |
1474 | /* |
1475 | * We do not commit power settings while scan is pending, | |
1476 | * do it now if the settings changed. | |
1477 | */ | |
1478 | iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false); | |
1479 | iwl_set_tx_power(priv, priv->tx_power_next, false); | |
1480 | ||
ae79d23d JB |
1481 | /* |
1482 | * Since setting the RXON may have been deferred while | |
1483 | * performing the scan, fire one off if needed | |
1484 | */ | |
1485 | for_each_context(priv, ctx) | |
1486 | if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging))) | |
1487 | iwlagn_commit_rxon(priv, ctx); | |
1488 | ||
e3f10cea | 1489 | iwlagn_set_pan_params(priv); |
ae79d23d | 1490 | } |