Commit | Line | Data |
---|---|---|
2a421b91 TW |
1 | /****************************************************************************** |
2 | * | |
3 | * GPL LICENSE SUMMARY | |
4 | * | |
fb4961db | 5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. |
2a421b91 TW |
6 | * |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of version 2 of the GNU General Public License as | |
9 | * published by the Free Software Foundation. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, but | |
12 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | * General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
19 | * USA | |
20 | * | |
21 | * The full GNU General Public License is included in this distribution | |
22 | * in the file called LICENSE.GPL. | |
23 | * | |
24 | * Contact Information: | |
759ef89f | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
2a421b91 TW |
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
27 | *****************************************************************************/ | |
5a0e3ad6 | 28 | #include <linux/slab.h> |
7e272fcf | 29 | #include <linux/types.h> |
2a421b91 | 30 | #include <linux/etherdevice.h> |
7e272fcf | 31 | #include <net/mac80211.h> |
2a421b91 TW |
32 | |
33 | #include "iwl-eeprom.h" | |
34 | #include "iwl-dev.h" | |
35 | #include "iwl-core.h" | |
2a421b91 | 36 | #include "iwl-io.h" |
e80d70e9 | 37 | #include "iwl-agn.h" |
bdfbf092 | 38 | #include "iwl-trans.h" |
2a421b91 TW |
39 | |
40 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after | |
41 | * sending probe req. This should be set long enough to hear probe responses | |
42 | * from more than one AP. */ | |
fe905f1d TW |
43 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
44 | #define IWL_ACTIVE_DWELL_TIME_52 (20) | |
45 | ||
46 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) | |
47 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) | |
2a421b91 | 48 | |
2a421b91 TW |
49 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
50 | * Must be set longer than active dwell time. | |
51 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ | |
52 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ | |
53 | #define IWL_PASSIVE_DWELL_TIME_52 (10) | |
54 | #define IWL_PASSIVE_DWELL_BASE (100) | |
55 | #define IWL_CHANNEL_TUNE_TIME 5 | |
56 | ||
cd44600f SG |
57 | static int iwl_send_scan_abort(struct iwl_priv *priv) |
58 | { | |
59 | int ret; | |
60 | struct iwl_rx_packet *pkt; | |
61 | struct iwl_host_cmd cmd = { | |
62 | .id = REPLY_SCAN_ABORT_CMD, | |
e419d62d | 63 | .flags = CMD_SYNC | CMD_WANT_SKB, |
cd44600f | 64 | }; |
fe905f1d | 65 | |
cd44600f SG |
66 | /* Exit instantly with error when device is not ready |
67 | * to receive scan abort command or it does not perform | |
68 | * hardware scan currently */ | |
63013ae3 EG |
69 | if (!test_bit(STATUS_READY, &priv->shrd->status) || |
70 | !test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) || | |
71 | !test_bit(STATUS_SCAN_HW, &priv->shrd->status) || | |
5c40d860 | 72 | test_bit(STATUS_FW_ERROR, &priv->shrd->status)) |
cd44600f | 73 | return -EIO; |
fe905f1d | 74 | |
e6bb4c9c | 75 | ret = iwl_trans_send_cmd(trans(priv), &cmd); |
cd44600f SG |
76 | if (ret) |
77 | return ret; | |
78 | ||
65b94a4a | 79 | pkt = cmd.resp_pkt; |
cd44600f SG |
80 | if (pkt->u.status != CAN_ABORT_STATUS) { |
81 | /* The scan abort will return 1 for success or | |
82 | * 2 for "failure". A failure condition can be | |
83 | * due to simply not being in an active scan which | |
84 | * can occur if we send the scan abort before we | |
85 | * the microcode has notified us that a scan is | |
86 | * completed. */ | |
7cf24421 | 87 | IWL_DEBUG_SCAN(priv, "SCAN_ABORT ret %d.\n", pkt->u.status); |
cd44600f | 88 | ret = -EIO; |
2a421b91 TW |
89 | } |
90 | ||
65b94a4a | 91 | iwl_free_resp(&cmd); |
cd44600f SG |
92 | return ret; |
93 | } | |
2a421b91 | 94 | |
02d8c14b SG |
95 | static void iwl_complete_scan(struct iwl_priv *priv, bool aborted) |
96 | { | |
97 | /* check if scan was requested from mac80211 */ | |
98 | if (priv->scan_request) { | |
99 | IWL_DEBUG_SCAN(priv, "Complete scan in mac80211\n"); | |
100 | ieee80211_scan_completed(priv->hw, aborted); | |
101 | } | |
102 | ||
c6baf7fb JB |
103 | if (priv->scan_type == IWL_SCAN_ROC) { |
104 | ieee80211_remain_on_channel_expired(priv->hw); | |
105 | priv->hw_roc_channel = NULL; | |
106 | schedule_delayed_work(&priv->hw_roc_disable_work, 10 * HZ); | |
107 | } | |
108 | ||
266af4c7 | 109 | priv->scan_type = IWL_SCAN_NORMAL; |
02d8c14b SG |
110 | priv->scan_vif = NULL; |
111 | priv->scan_request = NULL; | |
112 | } | |
113 | ||
a2fa2462 JB |
114 | static void iwl_process_scan_complete(struct iwl_priv *priv) |
115 | { | |
116 | bool aborted; | |
117 | ||
84b1bec6 JB |
118 | lockdep_assert_held(&priv->shrd->mutex); |
119 | ||
120 | if (!test_and_clear_bit(STATUS_SCAN_COMPLETE, &priv->shrd->status)) | |
121 | return; | |
122 | ||
a2fa2462 JB |
123 | IWL_DEBUG_SCAN(priv, "Completed scan.\n"); |
124 | ||
125 | cancel_delayed_work(&priv->scan_check); | |
126 | ||
127 | aborted = test_and_clear_bit(STATUS_SCAN_ABORTING, &priv->shrd->status); | |
128 | if (aborted) | |
129 | IWL_DEBUG_SCAN(priv, "Aborted scan completed.\n"); | |
130 | ||
131 | if (!test_and_clear_bit(STATUS_SCANNING, &priv->shrd->status)) { | |
132 | IWL_DEBUG_SCAN(priv, "Scan already completed.\n"); | |
133 | goto out_settings; | |
134 | } | |
135 | ||
136 | if (priv->scan_type == IWL_SCAN_ROC) { | |
137 | ieee80211_remain_on_channel_expired(priv->hw); | |
138 | priv->hw_roc_channel = NULL; | |
139 | schedule_delayed_work(&priv->hw_roc_disable_work, 10 * HZ); | |
140 | } | |
141 | ||
142 | if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) { | |
143 | int err; | |
144 | ||
145 | /* Check if mac80211 requested scan during our internal scan */ | |
146 | if (priv->scan_request == NULL) | |
147 | goto out_complete; | |
148 | ||
149 | /* If so request a new scan */ | |
150 | err = iwl_scan_initiate(priv, priv->scan_vif, IWL_SCAN_NORMAL, | |
151 | priv->scan_request->channels[0]->band); | |
152 | if (err) { | |
153 | IWL_DEBUG_SCAN(priv, | |
154 | "failed to initiate pending scan: %d\n", err); | |
155 | aborted = true; | |
156 | goto out_complete; | |
157 | } | |
158 | ||
159 | return; | |
160 | } | |
161 | ||
162 | out_complete: | |
163 | iwl_complete_scan(priv, aborted); | |
164 | ||
165 | out_settings: | |
166 | /* Can we still talk to firmware ? */ | |
167 | if (!iwl_is_ready_rf(priv->shrd)) | |
168 | return; | |
169 | ||
170 | iwlagn_post_scan(priv); | |
171 | } | |
172 | ||
e7e16b90 | 173 | void iwl_force_scan_end(struct iwl_priv *priv) |
f5354c17 | 174 | { |
6ac2f839 | 175 | lockdep_assert_held(&priv->shrd->mutex); |
e7e16b90 | 176 | |
63013ae3 | 177 | if (!test_bit(STATUS_SCANNING, &priv->shrd->status)) { |
e7e16b90 SG |
178 | IWL_DEBUG_SCAN(priv, "Forcing scan end while not scanning\n"); |
179 | return; | |
180 | } | |
181 | ||
f5354c17 | 182 | IWL_DEBUG_SCAN(priv, "Forcing scan end\n"); |
63013ae3 EG |
183 | clear_bit(STATUS_SCANNING, &priv->shrd->status); |
184 | clear_bit(STATUS_SCAN_HW, &priv->shrd->status); | |
185 | clear_bit(STATUS_SCAN_ABORTING, &priv->shrd->status); | |
84b1bec6 | 186 | clear_bit(STATUS_SCAN_COMPLETE, &priv->shrd->status); |
f5354c17 SG |
187 | iwl_complete_scan(priv, true); |
188 | } | |
189 | ||
cd44600f SG |
190 | static void iwl_do_scan_abort(struct iwl_priv *priv) |
191 | { | |
192 | int ret; | |
2a421b91 | 193 | |
6ac2f839 | 194 | lockdep_assert_held(&priv->shrd->mutex); |
cd44600f | 195 | |
63013ae3 | 196 | if (!test_bit(STATUS_SCANNING, &priv->shrd->status)) { |
cd44600f SG |
197 | IWL_DEBUG_SCAN(priv, "Not performing scan to abort\n"); |
198 | return; | |
2a421b91 TW |
199 | } |
200 | ||
63013ae3 | 201 | if (test_and_set_bit(STATUS_SCAN_ABORTING, &priv->shrd->status)) { |
cd44600f SG |
202 | IWL_DEBUG_SCAN(priv, "Scan abort in progress\n"); |
203 | return; | |
204 | } | |
205 | ||
206 | ret = iwl_send_scan_abort(priv); | |
207 | if (ret) { | |
208 | IWL_DEBUG_SCAN(priv, "Send scan abort failed %d\n", ret); | |
f5354c17 | 209 | iwl_force_scan_end(priv); |
cd44600f | 210 | } else |
25985edc | 211 | IWL_DEBUG_SCAN(priv, "Successfully send scan abort\n"); |
cd44600f SG |
212 | } |
213 | ||
214 | /** | |
215 | * iwl_scan_cancel - Cancel any currently executing HW scan | |
216 | */ | |
217 | int iwl_scan_cancel(struct iwl_priv *priv) | |
218 | { | |
219 | IWL_DEBUG_SCAN(priv, "Queuing abort scan\n"); | |
1ee158d8 | 220 | queue_work(priv->workqueue, &priv->abort_scan); |
2a421b91 TW |
221 | return 0; |
222 | } | |
cd44600f | 223 | |
2a421b91 TW |
224 | /** |
225 | * iwl_scan_cancel_timeout - Cancel any currently executing HW scan | |
226 | * @ms: amount of time to wait (in milliseconds) for scan to abort | |
227 | * | |
2a421b91 | 228 | */ |
98efb4a5 | 229 | void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
2a421b91 | 230 | { |
e693a802 SG |
231 | unsigned long timeout = jiffies + msecs_to_jiffies(ms); |
232 | ||
6ac2f839 | 233 | lockdep_assert_held(&priv->shrd->mutex); |
2a421b91 | 234 | |
e693a802 | 235 | IWL_DEBUG_SCAN(priv, "Scan cancel timeout\n"); |
2a421b91 | 236 | |
e693a802 SG |
237 | iwl_do_scan_abort(priv); |
238 | ||
239 | while (time_before_eq(jiffies, timeout)) { | |
63013ae3 | 240 | if (!test_bit(STATUS_SCAN_HW, &priv->shrd->status)) |
84b1bec6 | 241 | goto finished; |
e693a802 | 242 | msleep(20); |
2a421b91 | 243 | } |
84b1bec6 JB |
244 | |
245 | return; | |
246 | ||
247 | finished: | |
248 | /* | |
249 | * Now STATUS_SCAN_HW is clear. This means that the | |
250 | * device finished, but the background work is going | |
251 | * to execute at best as soon as we release the mutex. | |
252 | * Since we need to be able to issue a new scan right | |
253 | * after this function returns, run the complete here. | |
254 | * The STATUS_SCAN_COMPLETE bit will then be cleared | |
255 | * and prevent the background work from "completing" | |
256 | * a possible new scan. | |
257 | */ | |
258 | iwl_process_scan_complete(priv); | |
2a421b91 | 259 | } |
2a421b91 | 260 | |
2a421b91 | 261 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
247c61d6 | 262 | static int iwl_rx_reply_scan(struct iwl_priv *priv, |
48a2d66f | 263 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 264 | struct iwl_device_cmd *cmd) |
2a421b91 TW |
265 | { |
266 | #ifdef CONFIG_IWLWIFI_DEBUG | |
2f301227 | 267 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
2a421b91 TW |
268 | struct iwl_scanreq_notification *notif = |
269 | (struct iwl_scanreq_notification *)pkt->u.raw; | |
270 | ||
7cf24421 | 271 | IWL_DEBUG_SCAN(priv, "Scan request status = 0x%x\n", notif->status); |
2a421b91 | 272 | #endif |
247c61d6 | 273 | return 0; |
2a421b91 TW |
274 | } |
275 | ||
276 | /* Service SCAN_START_NOTIFICATION (0x82) */ | |
247c61d6 | 277 | static int iwl_rx_scan_start_notif(struct iwl_priv *priv, |
48a2d66f | 278 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 279 | struct iwl_device_cmd *cmd) |
2a421b91 | 280 | { |
2f301227 | 281 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
2a421b91 TW |
282 | struct iwl_scanstart_notification *notif = |
283 | (struct iwl_scanstart_notification *)pkt->u.raw; | |
284 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); | |
e1623446 | 285 | IWL_DEBUG_SCAN(priv, "Scan start: " |
2a421b91 TW |
286 | "%d [802.11%s] " |
287 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", | |
288 | notif->channel, | |
289 | notif->band ? "bg" : "a", | |
fe905f1d TW |
290 | le32_to_cpu(notif->tsf_high), |
291 | le32_to_cpu(notif->tsf_low), | |
292 | notif->status, notif->beacon_timer); | |
c6baf7fb | 293 | |
390808db JB |
294 | if (priv->scan_type == IWL_SCAN_ROC && |
295 | !priv->hw_roc_start_notified) { | |
c6baf7fb | 296 | ieee80211_ready_on_channel(priv->hw); |
390808db JB |
297 | priv->hw_roc_start_notified = true; |
298 | } | |
247c61d6 EG |
299 | |
300 | return 0; | |
2a421b91 TW |
301 | } |
302 | ||
303 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ | |
247c61d6 | 304 | static int iwl_rx_scan_results_notif(struct iwl_priv *priv, |
48a2d66f | 305 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 306 | struct iwl_device_cmd *cmd) |
2a421b91 TW |
307 | { |
308 | #ifdef CONFIG_IWLWIFI_DEBUG | |
2f301227 | 309 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
2a421b91 TW |
310 | struct iwl_scanresults_notification *notif = |
311 | (struct iwl_scanresults_notification *)pkt->u.raw; | |
312 | ||
e1623446 | 313 | IWL_DEBUG_SCAN(priv, "Scan ch.res: " |
2a421b91 | 314 | "%d [802.11%s] " |
1895b36b | 315 | "probe status: %u:%u " |
2a421b91 | 316 | "(TSF: 0x%08X:%08X) - %d " |
220575f7 | 317 | "elapsed=%lu usec\n", |
2a421b91 TW |
318 | notif->channel, |
319 | notif->band ? "bg" : "a", | |
1895b36b | 320 | notif->probe_status, notif->num_probe_not_sent, |
2a421b91 TW |
321 | le32_to_cpu(notif->tsf_high), |
322 | le32_to_cpu(notif->tsf_low), | |
323 | le32_to_cpu(notif->statistics[0]), | |
220575f7 | 324 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf); |
2a421b91 | 325 | #endif |
247c61d6 | 326 | return 0; |
2a421b91 TW |
327 | } |
328 | ||
329 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ | |
247c61d6 | 330 | static int iwl_rx_scan_complete_notif(struct iwl_priv *priv, |
48a2d66f | 331 | struct iwl_rx_cmd_buffer *rxb, |
247c61d6 | 332 | struct iwl_device_cmd *cmd) |
2a421b91 | 333 | { |
2f301227 | 334 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
2a421b91 TW |
335 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
336 | ||
e1623446 | 337 | IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
2a421b91 TW |
338 | scan_notif->scanned_channels, |
339 | scan_notif->tsf_low, | |
340 | scan_notif->tsf_high, scan_notif->status); | |
341 | ||
7cf24421 | 342 | IWL_DEBUG_SCAN(priv, "Scan on %sGHz took %dms\n", |
00700ee0 | 343 | (priv->scan_band == IEEE80211_BAND_2GHZ) ? "2.4" : "5.2", |
ef1b21f7 | 344 | jiffies_to_msecs(jiffies - priv->scan_start)); |
2a421b91 | 345 | |
84b1bec6 JB |
346 | /* |
347 | * When aborting, we run the scan completed background work inline | |
348 | * and the background work must then do nothing. The SCAN_COMPLETE | |
349 | * bit helps implement that logic and thus needs to be set before | |
350 | * queueing the work. Also, since the scan abort waits for SCAN_HW | |
351 | * to clear, we need to set SCAN_COMPLETE before clearing SCAN_HW | |
352 | * to avoid a race there. | |
353 | */ | |
354 | set_bit(STATUS_SCAN_COMPLETE, &priv->shrd->status); | |
355 | clear_bit(STATUS_SCAN_HW, &priv->shrd->status); | |
1ee158d8 | 356 | queue_work(priv->workqueue, &priv->scan_completed); |
2a421b91 | 357 | |
f78e5454 | 358 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC && |
88e58fc5 | 359 | iwl_advanced_bt_coexist(priv) && |
d5926d9d | 360 | priv->bt_status != scan_notif->bt_status) { |
f78e5454 WYG |
361 | if (scan_notif->bt_status) { |
362 | /* BT on */ | |
363 | if (!priv->bt_ch_announce) | |
364 | priv->bt_traffic_load = | |
365 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH; | |
366 | /* | |
367 | * otherwise, no traffic load information provided | |
368 | * no changes made | |
369 | */ | |
370 | } else { | |
371 | /* BT off */ | |
372 | priv->bt_traffic_load = | |
373 | IWL_BT_COEX_TRAFFIC_LOAD_NONE; | |
374 | } | |
375 | priv->bt_status = scan_notif->bt_status; | |
1ee158d8 | 376 | queue_work(priv->workqueue, |
74e28e44 | 377 | &priv->bt_traffic_change_work); |
f78e5454 | 378 | } |
247c61d6 | 379 | return 0; |
2a421b91 TW |
380 | } |
381 | ||
382 | void iwl_setup_rx_scan_handlers(struct iwl_priv *priv) | |
383 | { | |
384 | /* scan handlers */ | |
385 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan; | |
386 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif; | |
387 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = | |
388 | iwl_rx_scan_results_notif; | |
389 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = | |
390 | iwl_rx_scan_complete_notif; | |
391 | } | |
2a421b91 | 392 | |
6e809a16 JB |
393 | static u16 iwl_get_active_dwell_time(struct iwl_priv *priv, |
394 | enum ieee80211_band band, u8 n_probes) | |
2a421b91 TW |
395 | { |
396 | if (band == IEEE80211_BAND_5GHZ) | |
fe905f1d TW |
397 | return IWL_ACTIVE_DWELL_TIME_52 + |
398 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); | |
2a421b91 | 399 | else |
fe905f1d TW |
400 | return IWL_ACTIVE_DWELL_TIME_24 + |
401 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); | |
2a421b91 TW |
402 | } |
403 | ||
390808db JB |
404 | static u16 iwl_limit_dwell(struct iwl_priv *priv, u16 dwell_time) |
405 | { | |
406 | struct iwl_rxon_context *ctx; | |
407 | ||
408 | /* | |
409 | * If we're associated, we clamp the dwell time 98% | |
410 | * of the smallest beacon interval (minus 2 * channel | |
411 | * tune time) | |
412 | */ | |
413 | for_each_context(priv, ctx) { | |
414 | u16 value; | |
415 | ||
2ed81710 JB |
416 | switch (ctx->staging.dev_type) { |
417 | case RXON_DEV_TYPE_P2P: | |
418 | /* no timing constraints */ | |
eb32043f | 419 | continue; |
2ed81710 JB |
420 | case RXON_DEV_TYPE_ESS: |
421 | default: | |
422 | /* timing constraints if associated */ | |
423 | if (!iwl_is_associated_ctx(ctx)) | |
424 | continue; | |
425 | break; | |
426 | case RXON_DEV_TYPE_CP: | |
427 | case RXON_DEV_TYPE_2STA: | |
428 | /* | |
429 | * These seem to always have timers for TBTT | |
430 | * active in uCode even when not associated yet. | |
431 | */ | |
432 | break; | |
433 | } | |
434 | ||
390808db JB |
435 | value = ctx->beacon_int; |
436 | if (!value) | |
437 | value = IWL_PASSIVE_DWELL_BASE; | |
438 | value = (value * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; | |
439 | dwell_time = min(value, dwell_time); | |
440 | } | |
441 | ||
442 | return dwell_time; | |
443 | } | |
444 | ||
6e809a16 JB |
445 | static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, |
446 | enum ieee80211_band band) | |
2a421b91 | 447 | { |
fe905f1d | 448 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
2a421b91 TW |
449 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
450 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; | |
451 | ||
390808db | 452 | return iwl_limit_dwell(priv, passive); |
2a421b91 TW |
453 | } |
454 | ||
6e809a16 JB |
455 | static int iwl_get_single_channel_for_scan(struct iwl_priv *priv, |
456 | struct ieee80211_vif *vif, | |
457 | enum ieee80211_band band, | |
458 | struct iwl_scan_channel *scan_ch) | |
459 | { | |
460 | const struct ieee80211_supported_band *sband; | |
461 | u16 passive_dwell = 0; | |
462 | u16 active_dwell = 0; | |
463 | int added = 0; | |
464 | u16 channel = 0; | |
465 | ||
466 | sband = iwl_get_hw_mode(priv, band); | |
467 | if (!sband) { | |
468 | IWL_ERR(priv, "invalid band\n"); | |
469 | return added; | |
470 | } | |
471 | ||
472 | active_dwell = iwl_get_active_dwell_time(priv, band, 0); | |
473 | passive_dwell = iwl_get_passive_dwell_time(priv, band); | |
474 | ||
475 | if (passive_dwell <= active_dwell) | |
476 | passive_dwell = active_dwell + 1; | |
477 | ||
478 | channel = iwl_get_single_channel_number(priv, band); | |
479 | if (channel) { | |
480 | scan_ch->channel = cpu_to_le16(channel); | |
481 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; | |
482 | scan_ch->active_dwell = cpu_to_le16(active_dwell); | |
483 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); | |
484 | /* Set txpower levels to defaults */ | |
485 | scan_ch->dsp_atten = 110; | |
486 | if (band == IEEE80211_BAND_5GHZ) | |
487 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; | |
488 | else | |
489 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); | |
490 | added++; | |
491 | } else | |
492 | IWL_ERR(priv, "no valid channel found\n"); | |
493 | return added; | |
494 | } | |
495 | ||
496 | static int iwl_get_channels_for_scan(struct iwl_priv *priv, | |
497 | struct ieee80211_vif *vif, | |
498 | enum ieee80211_band band, | |
499 | u8 is_active, u8 n_probes, | |
500 | struct iwl_scan_channel *scan_ch) | |
501 | { | |
502 | struct ieee80211_channel *chan; | |
503 | const struct ieee80211_supported_band *sband; | |
504 | const struct iwl_channel_info *ch_info; | |
505 | u16 passive_dwell = 0; | |
506 | u16 active_dwell = 0; | |
507 | int added, i; | |
508 | u16 channel; | |
509 | ||
510 | sband = iwl_get_hw_mode(priv, band); | |
511 | if (!sband) | |
512 | return 0; | |
513 | ||
514 | active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); | |
515 | passive_dwell = iwl_get_passive_dwell_time(priv, band); | |
516 | ||
517 | if (passive_dwell <= active_dwell) | |
518 | passive_dwell = active_dwell + 1; | |
519 | ||
520 | for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) { | |
521 | chan = priv->scan_request->channels[i]; | |
522 | ||
523 | if (chan->band != band) | |
524 | continue; | |
525 | ||
526 | channel = chan->hw_value; | |
527 | scan_ch->channel = cpu_to_le16(channel); | |
528 | ||
529 | ch_info = iwl_get_channel_info(priv, band, channel); | |
530 | if (!is_channel_valid(ch_info)) { | |
531 | IWL_DEBUG_SCAN(priv, | |
532 | "Channel %d is INVALID for this band.\n", | |
533 | channel); | |
534 | continue; | |
535 | } | |
536 | ||
537 | if (!is_active || is_channel_passive(ch_info) || | |
538 | (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) | |
539 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; | |
540 | else | |
541 | scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE; | |
542 | ||
543 | if (n_probes) | |
544 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); | |
545 | ||
546 | scan_ch->active_dwell = cpu_to_le16(active_dwell); | |
547 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); | |
548 | ||
549 | /* Set txpower levels to defaults */ | |
550 | scan_ch->dsp_atten = 110; | |
551 | ||
552 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use | |
553 | * power level: | |
554 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; | |
555 | */ | |
556 | if (band == IEEE80211_BAND_5GHZ) | |
557 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; | |
558 | else | |
559 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); | |
560 | ||
561 | IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n", | |
562 | channel, le32_to_cpu(scan_ch->type), | |
563 | (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ? | |
564 | "ACTIVE" : "PASSIVE", | |
565 | (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ? | |
566 | active_dwell : passive_dwell); | |
567 | ||
568 | scan_ch++; | |
569 | added++; | |
570 | } | |
571 | ||
572 | IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added); | |
573 | return added; | |
574 | } | |
575 | ||
576 | static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif) | |
577 | { | |
578 | struct iwl_host_cmd cmd = { | |
579 | .id = REPLY_SCAN_CMD, | |
580 | .len = { sizeof(struct iwl_scan_cmd), }, | |
581 | .flags = CMD_SYNC, | |
582 | }; | |
583 | struct iwl_scan_cmd *scan; | |
584 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; | |
585 | u32 rate_flags = 0; | |
331d9301 | 586 | u16 cmd_len = 0; |
6e809a16 JB |
587 | u16 rx_chain = 0; |
588 | enum ieee80211_band band; | |
589 | u8 n_probes = 0; | |
590 | u8 rx_ant = hw_params(priv).valid_rx_ant; | |
591 | u8 rate; | |
592 | bool is_active = false; | |
593 | int chan_mod; | |
594 | u8 active_chains; | |
595 | u8 scan_tx_antennas = hw_params(priv).valid_tx_ant; | |
596 | int ret; | |
597 | ||
598 | lockdep_assert_held(&priv->shrd->mutex); | |
599 | ||
600 | if (vif) | |
601 | ctx = iwl_rxon_ctx_from_vif(vif); | |
602 | ||
603 | if (!priv->scan_cmd) { | |
604 | priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) + | |
605 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); | |
606 | if (!priv->scan_cmd) { | |
607 | IWL_DEBUG_SCAN(priv, | |
608 | "fail to allocate memory for scan\n"); | |
609 | return -ENOMEM; | |
610 | } | |
611 | } | |
612 | scan = priv->scan_cmd; | |
613 | memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE); | |
614 | ||
615 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; | |
616 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; | |
617 | ||
618 | if (priv->scan_type != IWL_SCAN_ROC && | |
619 | iwl_is_any_associated(priv)) { | |
620 | u16 interval = 0; | |
621 | u32 extra; | |
622 | u32 suspend_time = 100; | |
623 | u32 scan_suspend_time = 100; | |
624 | ||
625 | IWL_DEBUG_INFO(priv, "Scanning while associated...\n"); | |
626 | switch (priv->scan_type) { | |
627 | case IWL_SCAN_ROC: | |
628 | WARN_ON(1); | |
629 | break; | |
630 | case IWL_SCAN_RADIO_RESET: | |
631 | interval = 0; | |
632 | break; | |
633 | case IWL_SCAN_NORMAL: | |
634 | interval = vif->bss_conf.beacon_int; | |
635 | break; | |
636 | } | |
637 | ||
638 | scan->suspend_time = 0; | |
639 | scan->max_out_time = cpu_to_le32(200 * 1024); | |
640 | if (!interval) | |
641 | interval = suspend_time; | |
642 | ||
643 | extra = (suspend_time / interval) << 22; | |
644 | scan_suspend_time = (extra | | |
645 | ((suspend_time % interval) * 1024)); | |
646 | scan->suspend_time = cpu_to_le32(scan_suspend_time); | |
647 | IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n", | |
648 | scan_suspend_time, interval); | |
649 | } else if (priv->scan_type == IWL_SCAN_ROC) { | |
650 | scan->suspend_time = 0; | |
651 | scan->max_out_time = 0; | |
652 | scan->quiet_time = 0; | |
653 | scan->quiet_plcp_th = 0; | |
654 | } | |
655 | ||
656 | switch (priv->scan_type) { | |
657 | case IWL_SCAN_RADIO_RESET: | |
658 | IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n"); | |
659 | break; | |
660 | case IWL_SCAN_NORMAL: | |
661 | if (priv->scan_request->n_ssids) { | |
662 | int i, p = 0; | |
663 | IWL_DEBUG_SCAN(priv, "Kicking off active scan\n"); | |
664 | for (i = 0; i < priv->scan_request->n_ssids; i++) { | |
665 | /* always does wildcard anyway */ | |
666 | if (!priv->scan_request->ssids[i].ssid_len) | |
667 | continue; | |
668 | scan->direct_scan[p].id = WLAN_EID_SSID; | |
669 | scan->direct_scan[p].len = | |
670 | priv->scan_request->ssids[i].ssid_len; | |
671 | memcpy(scan->direct_scan[p].ssid, | |
672 | priv->scan_request->ssids[i].ssid, | |
673 | priv->scan_request->ssids[i].ssid_len); | |
674 | n_probes++; | |
675 | p++; | |
676 | } | |
677 | is_active = true; | |
678 | } else | |
679 | IWL_DEBUG_SCAN(priv, "Start passive scan.\n"); | |
680 | break; | |
681 | case IWL_SCAN_ROC: | |
682 | IWL_DEBUG_SCAN(priv, "Start ROC scan.\n"); | |
683 | break; | |
684 | } | |
685 | ||
686 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; | |
687 | scan->tx_cmd.sta_id = ctx->bcast_sta_id; | |
688 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; | |
689 | ||
690 | switch (priv->scan_band) { | |
691 | case IEEE80211_BAND_2GHZ: | |
692 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; | |
693 | chan_mod = le32_to_cpu( | |
694 | priv->contexts[IWL_RXON_CTX_BSS].active.flags & | |
695 | RXON_FLG_CHANNEL_MODE_MSK) | |
696 | >> RXON_FLG_CHANNEL_MODE_POS; | |
3a8aea09 JB |
697 | if ((priv->scan_request && priv->scan_request->no_cck) || |
698 | chan_mod == CHANNEL_MODE_PURE_40) { | |
6e809a16 JB |
699 | rate = IWL_RATE_6M_PLCP; |
700 | } else { | |
701 | rate = IWL_RATE_1M_PLCP; | |
702 | rate_flags = RATE_MCS_CCK_MSK; | |
703 | } | |
704 | /* | |
705 | * Internal scans are passive, so we can indiscriminately set | |
706 | * the BT ignore flag on 2.4 GHz since it applies to TX only. | |
707 | */ | |
38622419 DF |
708 | if (cfg(priv)->bt_params && |
709 | cfg(priv)->bt_params->advanced_bt_coexist) | |
6e809a16 JB |
710 | scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT; |
711 | break; | |
712 | case IEEE80211_BAND_5GHZ: | |
713 | rate = IWL_RATE_6M_PLCP; | |
714 | break; | |
715 | default: | |
716 | IWL_WARN(priv, "Invalid scan band\n"); | |
717 | return -EIO; | |
718 | } | |
719 | ||
720 | /* | |
721 | * If active scanning is requested but a certain channel is | |
722 | * marked passive, we can do active scanning if we detect | |
723 | * transmissions. | |
724 | * | |
725 | * There is an issue with some firmware versions that triggers | |
726 | * a sysassert on a "good CRC threshold" of zero (== disabled), | |
727 | * on a radar channel even though this means that we should NOT | |
728 | * send probes. | |
729 | * | |
730 | * The "good CRC threshold" is the number of frames that we | |
731 | * need to receive during our dwell time on a channel before | |
732 | * sending out probes -- setting this to a huge value will | |
733 | * mean we never reach it, but at the same time work around | |
734 | * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER | |
735 | * here instead of IWL_GOOD_CRC_TH_DISABLED. | |
736 | * | |
737 | * This was fixed in later versions along with some other | |
738 | * scan changes, and the threshold behaves as a flag in those | |
739 | * versions. | |
740 | */ | |
741 | if (priv->new_scan_threshold_behaviour) | |
742 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : | |
743 | IWL_GOOD_CRC_TH_DISABLED; | |
744 | else | |
745 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : | |
746 | IWL_GOOD_CRC_TH_NEVER; | |
747 | ||
748 | band = priv->scan_band; | |
749 | ||
38622419 DF |
750 | if (cfg(priv)->scan_rx_antennas[band]) |
751 | rx_ant = cfg(priv)->scan_rx_antennas[band]; | |
6e809a16 JB |
752 | |
753 | if (band == IEEE80211_BAND_2GHZ && | |
38622419 DF |
754 | cfg(priv)->bt_params && |
755 | cfg(priv)->bt_params->advanced_bt_coexist) { | |
6e809a16 JB |
756 | /* transmit 2.4 GHz probes only on first antenna */ |
757 | scan_tx_antennas = first_antenna(scan_tx_antennas); | |
758 | } | |
759 | ||
760 | priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, | |
761 | priv->scan_tx_ant[band], | |
762 | scan_tx_antennas); | |
763 | rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]); | |
764 | scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags); | |
765 | ||
766 | /* In power save mode use one chain, otherwise use all chains */ | |
767 | if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) { | |
768 | /* rx_ant has been set to all valid chains previously */ | |
769 | active_chains = rx_ant & | |
770 | ((u8)(priv->chain_noise_data.active_chains)); | |
771 | if (!active_chains) | |
772 | active_chains = rx_ant; | |
773 | ||
774 | IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n", | |
775 | priv->chain_noise_data.active_chains); | |
776 | ||
777 | rx_ant = first_antenna(active_chains); | |
778 | } | |
38622419 DF |
779 | if (cfg(priv)->bt_params && |
780 | cfg(priv)->bt_params->advanced_bt_coexist && | |
6e809a16 JB |
781 | priv->bt_full_concurrent) { |
782 | /* operated as 1x1 in full concurrency mode */ | |
783 | rx_ant = first_antenna(rx_ant); | |
784 | } | |
785 | ||
786 | /* MIMO is not used here, but value is required */ | |
787 | rx_chain |= | |
788 | hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS; | |
789 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; | |
790 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; | |
791 | rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; | |
792 | scan->rx_chain = cpu_to_le16(rx_chain); | |
793 | switch (priv->scan_type) { | |
794 | case IWL_SCAN_NORMAL: | |
795 | cmd_len = iwl_fill_probe_req(priv, | |
796 | (struct ieee80211_mgmt *)scan->data, | |
797 | vif->addr, | |
798 | priv->scan_request->ie, | |
799 | priv->scan_request->ie_len, | |
800 | IWL_MAX_SCAN_SIZE - sizeof(*scan)); | |
801 | break; | |
802 | case IWL_SCAN_RADIO_RESET: | |
803 | case IWL_SCAN_ROC: | |
804 | /* use bcast addr, will not be transmitted but must be valid */ | |
805 | cmd_len = iwl_fill_probe_req(priv, | |
806 | (struct ieee80211_mgmt *)scan->data, | |
807 | iwl_bcast_addr, NULL, 0, | |
808 | IWL_MAX_SCAN_SIZE - sizeof(*scan)); | |
809 | break; | |
810 | default: | |
811 | BUG(); | |
812 | } | |
813 | scan->tx_cmd.len = cpu_to_le16(cmd_len); | |
814 | ||
815 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | | |
816 | RXON_FILTER_BCON_AWARE_MSK); | |
817 | ||
818 | switch (priv->scan_type) { | |
819 | case IWL_SCAN_RADIO_RESET: | |
820 | scan->channel_count = | |
821 | iwl_get_single_channel_for_scan(priv, vif, band, | |
822 | (void *)&scan->data[cmd_len]); | |
823 | break; | |
824 | case IWL_SCAN_NORMAL: | |
825 | scan->channel_count = | |
826 | iwl_get_channels_for_scan(priv, vif, band, | |
827 | is_active, n_probes, | |
828 | (void *)&scan->data[cmd_len]); | |
829 | break; | |
830 | case IWL_SCAN_ROC: { | |
831 | struct iwl_scan_channel *scan_ch; | |
390808db JB |
832 | int n_chan, i; |
833 | u16 dwell; | |
834 | ||
835 | dwell = iwl_limit_dwell(priv, priv->hw_roc_duration); | |
836 | n_chan = DIV_ROUND_UP(priv->hw_roc_duration, dwell); | |
6e809a16 | 837 | |
390808db | 838 | scan->channel_count = n_chan; |
6e809a16 JB |
839 | |
840 | scan_ch = (void *)&scan->data[cmd_len]; | |
6e809a16 | 841 | |
390808db JB |
842 | for (i = 0; i < n_chan; i++) { |
843 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; | |
844 | scan_ch->channel = | |
845 | cpu_to_le16(priv->hw_roc_channel->hw_value); | |
6e809a16 | 846 | |
390808db JB |
847 | if (i == n_chan - 1) |
848 | dwell = priv->hw_roc_duration - i * dwell; | |
849 | ||
850 | scan_ch->active_dwell = | |
851 | scan_ch->passive_dwell = cpu_to_le16(dwell); | |
852 | ||
853 | /* Set txpower levels to defaults */ | |
854 | scan_ch->dsp_atten = 110; | |
855 | ||
856 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use | |
857 | * power level: | |
858 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; | |
859 | */ | |
860 | if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ) | |
861 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; | |
862 | else | |
863 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); | |
864 | ||
865 | scan_ch++; | |
6e809a16 | 866 | } |
390808db JB |
867 | } |
868 | ||
6e809a16 JB |
869 | break; |
870 | } | |
871 | ||
872 | if (scan->channel_count == 0) { | |
873 | IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count); | |
874 | return -EIO; | |
875 | } | |
876 | ||
877 | cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) + | |
878 | scan->channel_count * sizeof(struct iwl_scan_channel); | |
879 | cmd.data[0] = scan; | |
880 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; | |
881 | scan->len = cpu_to_le16(cmd.len[0]); | |
882 | ||
883 | /* set scan bit here for PAN params */ | |
884 | set_bit(STATUS_SCAN_HW, &priv->shrd->status); | |
885 | ||
886 | ret = iwlagn_set_pan_params(priv); | |
887 | if (ret) | |
888 | return ret; | |
889 | ||
890 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | |
891 | if (ret) { | |
892 | clear_bit(STATUS_SCAN_HW, &priv->shrd->status); | |
893 | iwlagn_set_pan_params(priv); | |
894 | } | |
895 | ||
896 | return ret; | |
897 | } | |
898 | ||
f53696de TW |
899 | void iwl_init_scan_params(struct iwl_priv *priv) |
900 | { | |
d6189124 | 901 | u8 ant_idx = fls(hw_params(priv).valid_tx_ant) - 1; |
f53696de | 902 | if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ]) |
76eff18b | 903 | priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx; |
f53696de | 904 | if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ]) |
76eff18b | 905 | priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx; |
f53696de TW |
906 | } |
907 | ||
266af4c7 JB |
908 | int __must_check iwl_scan_initiate(struct iwl_priv *priv, |
909 | struct ieee80211_vif *vif, | |
910 | enum iwl_scan_type scan_type, | |
911 | enum ieee80211_band band) | |
2a421b91 | 912 | { |
3eecce52 JB |
913 | int ret; |
914 | ||
6ac2f839 | 915 | lockdep_assert_held(&priv->shrd->mutex); |
88be0264 | 916 | |
3eecce52 JB |
917 | cancel_delayed_work(&priv->scan_check); |
918 | ||
845a9c0d | 919 | if (!iwl_is_ready_rf(priv->shrd)) { |
7cf24421 | 920 | IWL_WARN(priv, "Request scan called when driver not ready.\n"); |
3eecce52 JB |
921 | return -EIO; |
922 | } | |
923 | ||
63013ae3 | 924 | if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) { |
7cf24421 | 925 | IWL_DEBUG_SCAN(priv, |
3eecce52 JB |
926 | "Multiple concurrent scan requests in parallel.\n"); |
927 | return -EBUSY; | |
928 | } | |
929 | ||
63013ae3 | 930 | if (test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status)) { |
7cf24421 | 931 | IWL_DEBUG_SCAN(priv, "Scan request while abort pending.\n"); |
3eecce52 JB |
932 | return -EBUSY; |
933 | } | |
934 | ||
7cf24421 | 935 | IWL_DEBUG_SCAN(priv, "Starting %sscan...\n", |
266af4c7 | 936 | scan_type == IWL_SCAN_NORMAL ? "" : |
c6baf7fb | 937 | scan_type == IWL_SCAN_ROC ? "remain-on-channel " : |
266af4c7 | 938 | "internal short "); |
3eecce52 | 939 | |
63013ae3 | 940 | set_bit(STATUS_SCANNING, &priv->shrd->status); |
266af4c7 | 941 | priv->scan_type = scan_type; |
2a421b91 | 942 | priv->scan_start = jiffies; |
3eecce52 | 943 | priv->scan_band = band; |
2a421b91 | 944 | |
5c3d29fc | 945 | ret = iwlagn_request_scan(priv, vif); |
3eecce52 | 946 | if (ret) { |
63013ae3 | 947 | clear_bit(STATUS_SCANNING, &priv->shrd->status); |
266af4c7 | 948 | priv->scan_type = IWL_SCAN_NORMAL; |
3eecce52 JB |
949 | return ret; |
950 | } | |
b6e4c55a | 951 | |
1ee158d8 | 952 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
3eecce52 | 953 | IWL_SCAN_CHECK_WATCHDOG); |
2a421b91 TW |
954 | |
955 | return 0; | |
956 | } | |
2a421b91 | 957 | |
e9dde6f6 | 958 | |
afbdd69a WYG |
959 | /* |
960 | * internal short scan, this function should only been called while associated. | |
961 | * It will reset and tune the radio to prevent possible RF related problem | |
962 | */ | |
88be0264 | 963 | void iwl_internal_short_hw_scan(struct iwl_priv *priv) |
afbdd69a | 964 | { |
1ee158d8 | 965 | queue_work(priv->workqueue, &priv->start_internal_scan); |
88be0264 JB |
966 | } |
967 | ||
c240879f | 968 | static void iwl_bg_start_internal_scan(struct work_struct *work) |
88be0264 JB |
969 | { |
970 | struct iwl_priv *priv = | |
971 | container_of(work, struct iwl_priv, start_internal_scan); | |
972 | ||
7cf24421 SG |
973 | IWL_DEBUG_SCAN(priv, "Start internal scan\n"); |
974 | ||
6ac2f839 | 975 | mutex_lock(&priv->shrd->mutex); |
afbdd69a | 976 | |
266af4c7 | 977 | if (priv->scan_type == IWL_SCAN_RADIO_RESET) { |
073d5eab RC |
978 | IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n"); |
979 | goto unlock; | |
980 | } | |
981 | ||
63013ae3 | 982 | if (test_bit(STATUS_SCANNING, &priv->shrd->status)) { |
afbdd69a | 983 | IWL_DEBUG_SCAN(priv, "Scan already in progress.\n"); |
88be0264 | 984 | goto unlock; |
afbdd69a | 985 | } |
88be0264 | 986 | |
266af4c7 | 987 | if (iwl_scan_initiate(priv, NULL, IWL_SCAN_RADIO_RESET, priv->band)) |
3eecce52 | 988 | IWL_DEBUG_SCAN(priv, "failed to start internal short scan\n"); |
88be0264 | 989 | unlock: |
6ac2f839 | 990 | mutex_unlock(&priv->shrd->mutex); |
afbdd69a | 991 | } |
afbdd69a | 992 | |
c240879f | 993 | static void iwl_bg_scan_check(struct work_struct *data) |
2a421b91 TW |
994 | { |
995 | struct iwl_priv *priv = | |
996 | container_of(data, struct iwl_priv, scan_check.work); | |
997 | ||
7cf24421 SG |
998 | IWL_DEBUG_SCAN(priv, "Scan check work\n"); |
999 | ||
e7e16b90 SG |
1000 | /* Since we are here firmware does not finish scan and |
1001 | * most likely is in bad shape, so we don't bother to | |
1002 | * send abort command, just force scan complete to mac80211 */ | |
6ac2f839 | 1003 | mutex_lock(&priv->shrd->mutex); |
e7e16b90 | 1004 | iwl_force_scan_end(priv); |
6ac2f839 | 1005 | mutex_unlock(&priv->shrd->mutex); |
2a421b91 | 1006 | } |
77fecfb8 | 1007 | |
2a421b91 TW |
1008 | /** |
1009 | * iwl_fill_probe_req - fill in all required fields and IE for probe request | |
1010 | */ | |
f53696de | 1011 | |
1ecf9fc1 | 1012 | u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, |
3a0b9aad | 1013 | const u8 *ta, const u8 *ies, int ie_len, int left) |
2a421b91 TW |
1014 | { |
1015 | int len = 0; | |
1016 | u8 *pos = NULL; | |
f53696de | 1017 | |
2a421b91 TW |
1018 | /* Make sure there is enough space for the probe request, |
1019 | * two mandatory IEs and the data */ | |
1020 | left -= 24; | |
1021 | if (left < 0) | |
1022 | return 0; | |
2a421b91 TW |
1023 | |
1024 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); | |
1025 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); | |
3a0b9aad | 1026 | memcpy(frame->sa, ta, ETH_ALEN); |
2a421b91 TW |
1027 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
1028 | frame->seq_ctrl = 0; | |
1029 | ||
f53696de TW |
1030 | len += 24; |
1031 | ||
2a421b91 | 1032 | /* ...next IE... */ |
f53696de | 1033 | pos = &frame->u.probe_req.variable[0]; |
2a421b91 | 1034 | |
f53696de | 1035 | /* fill in our indirect SSID IE */ |
2a421b91 TW |
1036 | left -= 2; |
1037 | if (left < 0) | |
1038 | return 0; | |
2a421b91 | 1039 | *pos++ = WLAN_EID_SSID; |
1382c71c RC |
1040 | *pos++ = 0; |
1041 | ||
1042 | len += 2; | |
2a421b91 | 1043 | |
1ecf9fc1 JB |
1044 | if (WARN_ON(left < ie_len)) |
1045 | return len; | |
2a421b91 | 1046 | |
eb2ec0fb | 1047 | if (ies && ie_len) { |
afbdd69a | 1048 | memcpy(pos, ies, ie_len); |
eb2ec0fb SG |
1049 | len += ie_len; |
1050 | } | |
f53696de | 1051 | |
2a421b91 TW |
1052 | return (u16)len; |
1053 | } | |
1054 | ||
c240879f | 1055 | static void iwl_bg_abort_scan(struct work_struct *work) |
2a421b91 TW |
1056 | { |
1057 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); | |
1058 | ||
7cf24421 SG |
1059 | IWL_DEBUG_SCAN(priv, "Abort scan work\n"); |
1060 | ||
e7e16b90 SG |
1061 | /* We keep scan_check work queued in case when firmware will not |
1062 | * report back scan completed notification */ | |
6ac2f839 | 1063 | mutex_lock(&priv->shrd->mutex); |
6bd1758d | 1064 | iwl_scan_cancel_timeout(priv, 200); |
6ac2f839 | 1065 | mutex_unlock(&priv->shrd->mutex); |
2a421b91 TW |
1066 | } |
1067 | ||
f253247a JB |
1068 | static void iwl_bg_scan_completed(struct work_struct *work) |
1069 | { | |
1070 | struct iwl_priv *priv = | |
1071 | container_of(work, struct iwl_priv, scan_completed); | |
52a02d15 | 1072 | |
f253247a JB |
1073 | mutex_lock(&priv->shrd->mutex); |
1074 | iwl_process_scan_complete(priv); | |
6ac2f839 | 1075 | mutex_unlock(&priv->shrd->mutex); |
eedda367 | 1076 | } |
eedda367 | 1077 | |
2a421b91 TW |
1078 | void iwl_setup_scan_deferred_work(struct iwl_priv *priv) |
1079 | { | |
eedda367 | 1080 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); |
2a421b91 | 1081 | INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); |
88be0264 | 1082 | INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan); |
2a421b91 TW |
1083 | INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); |
1084 | } | |
2a421b91 | 1085 | |
e7e16b90 SG |
1086 | void iwl_cancel_scan_deferred_work(struct iwl_priv *priv) |
1087 | { | |
1088 | cancel_work_sync(&priv->start_internal_scan); | |
1089 | cancel_work_sync(&priv->abort_scan); | |
1090 | cancel_work_sync(&priv->scan_completed); | |
1091 | ||
1092 | if (cancel_delayed_work_sync(&priv->scan_check)) { | |
6ac2f839 | 1093 | mutex_lock(&priv->shrd->mutex); |
e7e16b90 | 1094 | iwl_force_scan_end(priv); |
6ac2f839 | 1095 | mutex_unlock(&priv->shrd->mutex); |
e7e16b90 SG |
1096 | } |
1097 | } |