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