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