iwlagn: provide heplers to access the transport ops
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / iwl-scan.c
CommitLineData
2a421b91
TW
1/******************************************************************************
2 *
3 * GPL LICENSE SUMMARY
4 *
901069c7 5 * Copyright(c) 2008 - 2011 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"
36#include "iwl-sta.h"
37#include "iwl-io.h"
38#include "iwl-helpers.h"
e80d70e9 39#include "iwl-agn.h"
bdfbf092 40#include "iwl-trans.h"
2a421b91
TW
41
42/* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
43 * sending probe req. This should be set long enough to hear probe responses
44 * from more than one AP. */
fe905f1d
TW
45#define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
46#define IWL_ACTIVE_DWELL_TIME_52 (20)
47
48#define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
49#define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
2a421b91 50
2a421b91
TW
51/* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
52 * Must be set longer than active dwell time.
53 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
54#define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
55#define IWL_PASSIVE_DWELL_TIME_52 (10)
56#define IWL_PASSIVE_DWELL_BASE (100)
57#define IWL_CHANNEL_TUNE_TIME 5
58
cd44600f
SG
59static int iwl_send_scan_abort(struct iwl_priv *priv)
60{
61 int ret;
62 struct iwl_rx_packet *pkt;
63 struct iwl_host_cmd cmd = {
64 .id = REPLY_SCAN_ABORT_CMD,
e419d62d 65 .flags = CMD_SYNC | CMD_WANT_SKB,
cd44600f 66 };
fe905f1d 67
cd44600f
SG
68 /* Exit instantly with error when device is not ready
69 * to receive scan abort command or it does not perform
70 * hardware scan currently */
71 if (!test_bit(STATUS_READY, &priv->status) ||
72 !test_bit(STATUS_GEO_CONFIGURED, &priv->status) ||
73 !test_bit(STATUS_SCAN_HW, &priv->status) ||
74 test_bit(STATUS_FW_ERROR, &priv->status) ||
75 test_bit(STATUS_EXIT_PENDING, &priv->status))
76 return -EIO;
fe905f1d 77
bdfbf092 78 ret = trans_send_cmd(priv, &cmd);
cd44600f
SG
79 if (ret)
80 return ret;
81
82 pkt = (struct iwl_rx_packet *)cmd.reply_page;
83 if (pkt->u.status != CAN_ABORT_STATUS) {
84 /* The scan abort will return 1 for success or
85 * 2 for "failure". A failure condition can be
86 * due to simply not being in an active scan which
87 * can occur if we send the scan abort before we
88 * the microcode has notified us that a scan is
89 * completed. */
7cf24421 90 IWL_DEBUG_SCAN(priv, "SCAN_ABORT ret %d.\n", pkt->u.status);
cd44600f 91 ret = -EIO;
2a421b91
TW
92 }
93
cd44600f
SG
94 iwl_free_pages(priv, cmd.reply_page);
95 return ret;
96}
2a421b91 97
02d8c14b
SG
98static void iwl_complete_scan(struct iwl_priv *priv, bool aborted)
99{
100 /* check if scan was requested from mac80211 */
101 if (priv->scan_request) {
102 IWL_DEBUG_SCAN(priv, "Complete scan in mac80211\n");
103 ieee80211_scan_completed(priv->hw, aborted);
104 }
105
266af4c7 106 priv->scan_type = IWL_SCAN_NORMAL;
02d8c14b
SG
107 priv->scan_vif = NULL;
108 priv->scan_request = NULL;
109}
110
e7e16b90 111void iwl_force_scan_end(struct iwl_priv *priv)
f5354c17 112{
e7e16b90
SG
113 lockdep_assert_held(&priv->mutex);
114
115 if (!test_bit(STATUS_SCANNING, &priv->status)) {
116 IWL_DEBUG_SCAN(priv, "Forcing scan end while not scanning\n");
117 return;
118 }
119
f5354c17
SG
120 IWL_DEBUG_SCAN(priv, "Forcing scan end\n");
121 clear_bit(STATUS_SCANNING, &priv->status);
122 clear_bit(STATUS_SCAN_HW, &priv->status);
123 clear_bit(STATUS_SCAN_ABORTING, &priv->status);
124 iwl_complete_scan(priv, true);
125}
126
cd44600f
SG
127static void iwl_do_scan_abort(struct iwl_priv *priv)
128{
129 int ret;
2a421b91 130
cd44600f
SG
131 lockdep_assert_held(&priv->mutex);
132
133 if (!test_bit(STATUS_SCANNING, &priv->status)) {
134 IWL_DEBUG_SCAN(priv, "Not performing scan to abort\n");
135 return;
2a421b91
TW
136 }
137
cd44600f
SG
138 if (test_and_set_bit(STATUS_SCAN_ABORTING, &priv->status)) {
139 IWL_DEBUG_SCAN(priv, "Scan abort in progress\n");
140 return;
141 }
142
143 ret = iwl_send_scan_abort(priv);
144 if (ret) {
145 IWL_DEBUG_SCAN(priv, "Send scan abort failed %d\n", ret);
f5354c17 146 iwl_force_scan_end(priv);
cd44600f 147 } else
25985edc 148 IWL_DEBUG_SCAN(priv, "Successfully send scan abort\n");
cd44600f
SG
149}
150
151/**
152 * iwl_scan_cancel - Cancel any currently executing HW scan
153 */
154int iwl_scan_cancel(struct iwl_priv *priv)
155{
156 IWL_DEBUG_SCAN(priv, "Queuing abort scan\n");
e693a802 157 queue_work(priv->workqueue, &priv->abort_scan);
2a421b91
TW
158 return 0;
159}
cd44600f 160
2a421b91
TW
161/**
162 * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
163 * @ms: amount of time to wait (in milliseconds) for scan to abort
164 *
2a421b91
TW
165 */
166int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms)
167{
e693a802
SG
168 unsigned long timeout = jiffies + msecs_to_jiffies(ms);
169
170 lockdep_assert_held(&priv->mutex);
2a421b91 171
e693a802 172 IWL_DEBUG_SCAN(priv, "Scan cancel timeout\n");
2a421b91 173
e693a802
SG
174 iwl_do_scan_abort(priv);
175
176 while (time_before_eq(jiffies, timeout)) {
177 if (!test_bit(STATUS_SCAN_HW, &priv->status))
178 break;
179 msleep(20);
2a421b91
TW
180 }
181
e7e16b90 182 return test_bit(STATUS_SCAN_HW, &priv->status);
2a421b91 183}
2a421b91 184
2a421b91
TW
185/* Service response to REPLY_SCAN_CMD (0x80) */
186static void iwl_rx_reply_scan(struct iwl_priv *priv,
187 struct iwl_rx_mem_buffer *rxb)
188{
189#ifdef CONFIG_IWLWIFI_DEBUG
2f301227 190 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2a421b91
TW
191 struct iwl_scanreq_notification *notif =
192 (struct iwl_scanreq_notification *)pkt->u.raw;
193
7cf24421 194 IWL_DEBUG_SCAN(priv, "Scan request status = 0x%x\n", notif->status);
2a421b91
TW
195#endif
196}
197
198/* Service SCAN_START_NOTIFICATION (0x82) */
199static void iwl_rx_scan_start_notif(struct iwl_priv *priv,
200 struct iwl_rx_mem_buffer *rxb)
201{
2f301227 202 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2a421b91
TW
203 struct iwl_scanstart_notification *notif =
204 (struct iwl_scanstart_notification *)pkt->u.raw;
205 priv->scan_start_tsf = le32_to_cpu(notif->tsf_low);
e1623446 206 IWL_DEBUG_SCAN(priv, "Scan start: "
2a421b91
TW
207 "%d [802.11%s] "
208 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
209 notif->channel,
210 notif->band ? "bg" : "a",
fe905f1d
TW
211 le32_to_cpu(notif->tsf_high),
212 le32_to_cpu(notif->tsf_low),
213 notif->status, notif->beacon_timer);
2a421b91
TW
214}
215
216/* Service SCAN_RESULTS_NOTIFICATION (0x83) */
217static void iwl_rx_scan_results_notif(struct iwl_priv *priv,
218 struct iwl_rx_mem_buffer *rxb)
219{
220#ifdef CONFIG_IWLWIFI_DEBUG
2f301227 221 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2a421b91
TW
222 struct iwl_scanresults_notification *notif =
223 (struct iwl_scanresults_notification *)pkt->u.raw;
224
e1623446 225 IWL_DEBUG_SCAN(priv, "Scan ch.res: "
2a421b91
TW
226 "%d [802.11%s] "
227 "(TSF: 0x%08X:%08X) - %d "
220575f7 228 "elapsed=%lu usec\n",
2a421b91
TW
229 notif->channel,
230 notif->band ? "bg" : "a",
231 le32_to_cpu(notif->tsf_high),
232 le32_to_cpu(notif->tsf_low),
233 le32_to_cpu(notif->statistics[0]),
220575f7 234 le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf);
2a421b91 235#endif
2a421b91
TW
236}
237
238/* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
239static void iwl_rx_scan_complete_notif(struct iwl_priv *priv,
240 struct iwl_rx_mem_buffer *rxb)
241{
2f301227 242 struct iwl_rx_packet *pkt = rxb_addr(rxb);
2a421b91
TW
243 struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw;
244
e1623446 245 IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
2a421b91
TW
246 scan_notif->scanned_channels,
247 scan_notif->tsf_low,
248 scan_notif->tsf_high, scan_notif->status);
249
250 /* The HW is no longer scanning */
251 clear_bit(STATUS_SCAN_HW, &priv->status);
252
7cf24421 253 IWL_DEBUG_SCAN(priv, "Scan on %sGHz took %dms\n",
00700ee0 254 (priv->scan_band == IEEE80211_BAND_2GHZ) ? "2.4" : "5.2",
ef1b21f7 255 jiffies_to_msecs(jiffies - priv->scan_start));
2a421b91 256
d5926d9d 257 queue_work(priv->workqueue, &priv->scan_completed);
2a421b91 258
f78e5454 259 if (priv->iw_mode != NL80211_IFTYPE_ADHOC &&
88e58fc5 260 iwl_advanced_bt_coexist(priv) &&
d5926d9d 261 priv->bt_status != scan_notif->bt_status) {
f78e5454
WYG
262 if (scan_notif->bt_status) {
263 /* BT on */
264 if (!priv->bt_ch_announce)
265 priv->bt_traffic_load =
266 IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
267 /*
268 * otherwise, no traffic load information provided
269 * no changes made
270 */
271 } else {
272 /* BT off */
273 priv->bt_traffic_load =
274 IWL_BT_COEX_TRAFFIC_LOAD_NONE;
275 }
276 priv->bt_status = scan_notif->bt_status;
277 queue_work(priv->workqueue, &priv->bt_traffic_change_work);
278 }
2a421b91
TW
279}
280
281void iwl_setup_rx_scan_handlers(struct iwl_priv *priv)
282{
283 /* scan handlers */
284 priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan;
285 priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif;
286 priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] =
287 iwl_rx_scan_results_notif;
288 priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] =
289 iwl_rx_scan_complete_notif;
290}
2a421b91 291
77fecfb8
SO
292inline u16 iwl_get_active_dwell_time(struct iwl_priv *priv,
293 enum ieee80211_band band,
294 u8 n_probes)
2a421b91
TW
295{
296 if (band == IEEE80211_BAND_5GHZ)
fe905f1d
TW
297 return IWL_ACTIVE_DWELL_TIME_52 +
298 IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1);
2a421b91 299 else
fe905f1d
TW
300 return IWL_ACTIVE_DWELL_TIME_24 +
301 IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1);
2a421b91
TW
302}
303
77fecfb8 304u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
1dda6d28
JB
305 enum ieee80211_band band,
306 struct ieee80211_vif *vif)
2a421b91 307{
95c38dd4 308 struct iwl_rxon_context *ctx;
fe905f1d 309 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
2a421b91
TW
310 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
311 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
312
246ed355 313 if (iwl_is_any_associated(priv)) {
95c38dd4
JB
314 /*
315 * If we're associated, we clamp the maximum passive
316 * dwell time to be 98% of the smallest beacon interval
317 * (minus 2 * channel tune time)
318 */
319 for_each_context(priv, ctx) {
320 u16 value;
321
322 if (!iwl_is_associated_ctx(ctx))
323 continue;
324 value = ctx->vif ? ctx->vif->bss_conf.beacon_int : 0;
325 if ((value > IWL_PASSIVE_DWELL_BASE) || !value)
326 value = IWL_PASSIVE_DWELL_BASE;
327 value = (value * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
328 passive = min(value, passive);
329 }
2a421b91
TW
330 }
331
2a421b91
TW
332 return passive;
333}
334
f53696de
TW
335void iwl_init_scan_params(struct iwl_priv *priv)
336{
76eff18b 337 u8 ant_idx = fls(priv->hw_params.valid_tx_ant) - 1;
f53696de 338 if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ])
76eff18b 339 priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx;
f53696de 340 if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ])
76eff18b 341 priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx;
f53696de
TW
342}
343
266af4c7
JB
344int __must_check iwl_scan_initiate(struct iwl_priv *priv,
345 struct ieee80211_vif *vif,
346 enum iwl_scan_type scan_type,
347 enum ieee80211_band band)
2a421b91 348{
3eecce52
JB
349 int ret;
350
a24d52f3 351 lockdep_assert_held(&priv->mutex);
88be0264 352
3eecce52
JB
353 if (WARN_ON(!priv->cfg->ops->utils->request_scan))
354 return -EOPNOTSUPP;
355
356 cancel_delayed_work(&priv->scan_check);
357
74d81b25 358 if (!iwl_is_ready_rf(priv)) {
7cf24421 359 IWL_WARN(priv, "Request scan called when driver not ready.\n");
3eecce52
JB
360 return -EIO;
361 }
362
363 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
7cf24421 364 IWL_DEBUG_SCAN(priv,
3eecce52
JB
365 "Multiple concurrent scan requests in parallel.\n");
366 return -EBUSY;
367 }
368
3eecce52 369 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
7cf24421 370 IWL_DEBUG_SCAN(priv, "Scan request while abort pending.\n");
3eecce52
JB
371 return -EBUSY;
372 }
373
7cf24421 374 IWL_DEBUG_SCAN(priv, "Starting %sscan...\n",
266af4c7
JB
375 scan_type == IWL_SCAN_NORMAL ? "" :
376 scan_type == IWL_SCAN_OFFCH_TX ? "offchan TX " :
377 "internal short ");
3eecce52 378
2a421b91 379 set_bit(STATUS_SCANNING, &priv->status);
266af4c7 380 priv->scan_type = scan_type;
2a421b91 381 priv->scan_start = jiffies;
3eecce52 382 priv->scan_band = band;
2a421b91 383
3eecce52
JB
384 ret = priv->cfg->ops->utils->request_scan(priv, vif);
385 if (ret) {
386 clear_bit(STATUS_SCANNING, &priv->status);
266af4c7 387 priv->scan_type = IWL_SCAN_NORMAL;
3eecce52
JB
388 return ret;
389 }
b6e4c55a 390
3eecce52
JB
391 queue_delayed_work(priv->workqueue, &priv->scan_check,
392 IWL_SCAN_CHECK_WATCHDOG);
2a421b91
TW
393
394 return 0;
395}
2a421b91 396
e9dde6f6 397int iwl_mac_hw_scan(struct ieee80211_hw *hw,
a060bbfe
JB
398 struct ieee80211_vif *vif,
399 struct cfg80211_scan_request *req)
e9dde6f6 400{
e9dde6f6 401 struct iwl_priv *priv = hw->priv;
00700ee0 402 int ret;
e9dde6f6
AK
403
404 IWL_DEBUG_MAC80211(priv, "enter\n");
405
00700ee0
JB
406 if (req->n_channels == 0)
407 return -EINVAL;
408
e9dde6f6 409 mutex_lock(&priv->mutex);
e9dde6f6 410
f84b29ec 411 if (test_bit(STATUS_SCANNING, &priv->status) &&
266af4c7 412 priv->scan_type != IWL_SCAN_NORMAL) {
bbcbb9ef
RC
413 IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
414 ret = -EAGAIN;
415 goto out_unlock;
416 }
417
00700ee0 418 /* mac80211 will only ask for one band at a time */
1ecf9fc1 419 priv->scan_request = req;
f84b29ec 420 priv->scan_vif = vif;
e9dde6f6 421
f84b29ec
JB
422 /*
423 * If an internal scan is in progress, just set
424 * up the scan_request as per above.
425 */
266af4c7 426 if (priv->scan_type != IWL_SCAN_NORMAL) {
7cf24421 427 IWL_DEBUG_SCAN(priv, "SCAN request during internal scan\n");
f84b29ec 428 ret = 0;
7cf24421 429 } else
266af4c7 430 ret = iwl_scan_initiate(priv, vif, IWL_SCAN_NORMAL,
3eecce52 431 req->channels[0]->band);
e9dde6f6
AK
432
433 IWL_DEBUG_MAC80211(priv, "leave\n");
434
435out_unlock:
e9dde6f6
AK
436 mutex_unlock(&priv->mutex);
437
438 return ret;
439}
e9dde6f6 440
afbdd69a
WYG
441/*
442 * internal short scan, this function should only been called while associated.
443 * It will reset and tune the radio to prevent possible RF related problem
444 */
88be0264 445void iwl_internal_short_hw_scan(struct iwl_priv *priv)
afbdd69a 446{
88be0264
JB
447 queue_work(priv->workqueue, &priv->start_internal_scan);
448}
449
c240879f 450static void iwl_bg_start_internal_scan(struct work_struct *work)
88be0264
JB
451{
452 struct iwl_priv *priv =
453 container_of(work, struct iwl_priv, start_internal_scan);
454
7cf24421
SG
455 IWL_DEBUG_SCAN(priv, "Start internal scan\n");
456
88be0264 457 mutex_lock(&priv->mutex);
afbdd69a 458
266af4c7 459 if (priv->scan_type == IWL_SCAN_RADIO_RESET) {
073d5eab
RC
460 IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n");
461 goto unlock;
462 }
463
afbdd69a
WYG
464 if (test_bit(STATUS_SCANNING, &priv->status)) {
465 IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
88be0264 466 goto unlock;
afbdd69a 467 }
88be0264 468
266af4c7 469 if (iwl_scan_initiate(priv, NULL, IWL_SCAN_RADIO_RESET, priv->band))
3eecce52 470 IWL_DEBUG_SCAN(priv, "failed to start internal short scan\n");
88be0264
JB
471 unlock:
472 mutex_unlock(&priv->mutex);
afbdd69a 473}
afbdd69a 474
c240879f 475static void iwl_bg_scan_check(struct work_struct *data)
2a421b91
TW
476{
477 struct iwl_priv *priv =
478 container_of(data, struct iwl_priv, scan_check.work);
479
7cf24421
SG
480 IWL_DEBUG_SCAN(priv, "Scan check work\n");
481
e7e16b90
SG
482 /* Since we are here firmware does not finish scan and
483 * most likely is in bad shape, so we don't bother to
484 * send abort command, just force scan complete to mac80211 */
2a421b91 485 mutex_lock(&priv->mutex);
e7e16b90 486 iwl_force_scan_end(priv);
2a421b91
TW
487 mutex_unlock(&priv->mutex);
488}
77fecfb8 489
2a421b91
TW
490/**
491 * iwl_fill_probe_req - fill in all required fields and IE for probe request
492 */
f53696de 493
1ecf9fc1 494u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame,
3a0b9aad 495 const u8 *ta, const u8 *ies, int ie_len, int left)
2a421b91
TW
496{
497 int len = 0;
498 u8 *pos = NULL;
f53696de 499
2a421b91
TW
500 /* Make sure there is enough space for the probe request,
501 * two mandatory IEs and the data */
502 left -= 24;
503 if (left < 0)
504 return 0;
2a421b91
TW
505
506 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
507 memcpy(frame->da, iwl_bcast_addr, ETH_ALEN);
3a0b9aad 508 memcpy(frame->sa, ta, ETH_ALEN);
2a421b91
TW
509 memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN);
510 frame->seq_ctrl = 0;
511
f53696de
TW
512 len += 24;
513
2a421b91 514 /* ...next IE... */
f53696de 515 pos = &frame->u.probe_req.variable[0];
2a421b91 516
f53696de 517 /* fill in our indirect SSID IE */
2a421b91
TW
518 left -= 2;
519 if (left < 0)
520 return 0;
2a421b91 521 *pos++ = WLAN_EID_SSID;
1382c71c
RC
522 *pos++ = 0;
523
524 len += 2;
2a421b91 525
1ecf9fc1
JB
526 if (WARN_ON(left < ie_len))
527 return len;
2a421b91 528
eb2ec0fb 529 if (ies && ie_len) {
afbdd69a 530 memcpy(pos, ies, ie_len);
eb2ec0fb
SG
531 len += ie_len;
532 }
f53696de 533
2a421b91
TW
534 return (u16)len;
535}
536
c240879f 537static void iwl_bg_abort_scan(struct work_struct *work)
2a421b91
TW
538{
539 struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan);
540
7cf24421
SG
541 IWL_DEBUG_SCAN(priv, "Abort scan work\n");
542
e7e16b90
SG
543 /* We keep scan_check work queued in case when firmware will not
544 * report back scan completed notification */
d28232b4 545 mutex_lock(&priv->mutex);
6bd1758d 546 iwl_scan_cancel_timeout(priv, 200);
2a421b91
TW
547 mutex_unlock(&priv->mutex);
548}
549
c240879f 550static void iwl_bg_scan_completed(struct work_struct *work)
eedda367
TW
551{
552 struct iwl_priv *priv =
553 container_of(work, struct iwl_priv, scan_completed);
02d8c14b 554 bool aborted;
eedda367 555
266af4c7 556 IWL_DEBUG_SCAN(priv, "Completed scan.\n");
eedda367 557
fbc9f97b
RC
558 cancel_delayed_work(&priv->scan_check);
559
073d5eab 560 mutex_lock(&priv->mutex);
d5926d9d
JB
561
562 aborted = test_and_clear_bit(STATUS_SCAN_ABORTING, &priv->status);
563 if (aborted)
7cf24421 564 IWL_DEBUG_SCAN(priv, "Aborted scan completed.\n");
d5926d9d 565
02d8c14b 566 if (!test_and_clear_bit(STATUS_SCANNING, &priv->status)) {
7cf24421 567 IWL_DEBUG_SCAN(priv, "Scan already completed.\n");
3a160a5b 568 goto out_settings;
afbdd69a 569 }
f84b29ec 570
266af4c7
JB
571 if (priv->scan_type == IWL_SCAN_OFFCH_TX && priv->_agn.offchan_tx_skb) {
572 ieee80211_tx_status_irqsafe(priv->hw,
573 priv->_agn.offchan_tx_skb);
574 priv->_agn.offchan_tx_skb = NULL;
575 }
576
577 if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) {
02d8c14b 578 int err;
f84b29ec 579
02d8c14b
SG
580 /* Check if mac80211 requested scan during our internal scan */
581 if (priv->scan_request == NULL)
582 goto out_complete;
3eecce52 583
02d8c14b 584 /* If so request a new scan */
266af4c7 585 err = iwl_scan_initiate(priv, priv->scan_vif, IWL_SCAN_NORMAL,
02d8c14b 586 priv->scan_request->channels[0]->band);
3eecce52
JB
587 if (err) {
588 IWL_DEBUG_SCAN(priv,
589 "failed to initiate pending scan: %d\n", err);
02d8c14b
SG
590 aborted = true;
591 goto out_complete;
592 }
593
594 goto out;
3eecce52 595 }
f84b29ec 596
02d8c14b
SG
597out_complete:
598 iwl_complete_scan(priv, aborted);
599
3a160a5b 600out_settings:
02d8c14b
SG
601 /* Can we still talk to firmware ? */
602 if (!iwl_is_ready_rf(priv))
603 goto out;
604
e80d70e9 605 iwlagn_post_scan(priv);
52a02d15 606
a25a66ac 607out:
073d5eab 608 mutex_unlock(&priv->mutex);
eedda367 609}
eedda367 610
2a421b91
TW
611void iwl_setup_scan_deferred_work(struct iwl_priv *priv)
612{
eedda367 613 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
2a421b91 614 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
88be0264 615 INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan);
2a421b91
TW
616 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
617}
2a421b91 618
e7e16b90
SG
619void iwl_cancel_scan_deferred_work(struct iwl_priv *priv)
620{
621 cancel_work_sync(&priv->start_internal_scan);
622 cancel_work_sync(&priv->abort_scan);
623 cancel_work_sync(&priv->scan_completed);
624
625 if (cancel_delayed_work_sync(&priv->scan_check)) {
626 mutex_lock(&priv->mutex);
627 iwl_force_scan_end(priv);
628 mutex_unlock(&priv->mutex);
629 }
630}
This page took 0.86037 seconds and 5 git commands to generate.