1 /******************************************************************************
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
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.
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.
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,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28 #include <linux/types.h>
29 #include <linux/etherdevice.h>
30 #include <net/lib80211.h>
31 #include <net/mac80211.h>
33 #include "iwl-eeprom.h"
38 #include "iwl-helpers.h"
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. */
43 #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
44 #define IWL_ACTIVE_DWELL_TIME_52 (20)
46 #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
47 #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
49 /* For faster active scanning, scan will move to the next channel if fewer than
50 * PLCP_QUIET_THRESH packets are heard on this channel within
51 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
52 * time if it's a quiet channel (nothing responded to our probe, and there's
54 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
55 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
56 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */
58 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
59 * Must be set longer than active dwell time.
60 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
61 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
62 #define IWL_PASSIVE_DWELL_TIME_52 (10)
63 #define IWL_PASSIVE_DWELL_BASE (100)
64 #define IWL_CHANNEL_TUNE_TIME 5
66 #define IWL_SCAN_PROBE_MASK(n) cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
70 * iwl_scan_cancel - Cancel any currently executing HW scan
72 * NOTE: priv->mutex is not required before calling this function
74 int iwl_scan_cancel(struct iwl_priv
*priv
)
76 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
77 clear_bit(STATUS_SCANNING
, &priv
->status
);
81 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
82 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
83 IWL_DEBUG_SCAN("Queuing scan abort.\n");
84 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
85 queue_work(priv
->workqueue
, &priv
->abort_scan
);
88 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
90 return test_bit(STATUS_SCANNING
, &priv
->status
);
95 EXPORT_SYMBOL(iwl_scan_cancel
);
97 * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
98 * @ms: amount of time to wait (in milliseconds) for scan to abort
100 * NOTE: priv->mutex must be held before calling this function
102 int iwl_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
104 unsigned long now
= jiffies
;
107 ret
= iwl_scan_cancel(priv
);
109 mutex_unlock(&priv
->mutex
);
110 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
111 test_bit(STATUS_SCANNING
, &priv
->status
))
113 mutex_lock(&priv
->mutex
);
115 return test_bit(STATUS_SCANNING
, &priv
->status
);
120 EXPORT_SYMBOL(iwl_scan_cancel_timeout
);
122 static int iwl_send_scan_abort(struct iwl_priv
*priv
)
125 struct iwl_rx_packet
*res
;
126 struct iwl_host_cmd cmd
= {
127 .id
= REPLY_SCAN_ABORT_CMD
,
128 .meta
.flags
= CMD_WANT_SKB
,
131 /* If there isn't a scan actively going on in the hardware
132 * then we are in between scan bands and not actually
133 * actively scanning, so don't send the abort command */
134 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
135 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
139 ret
= iwl_send_cmd_sync(priv
, &cmd
);
141 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
145 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
146 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
147 /* The scan abort will return 1 for success or
148 * 2 for "failure". A failure condition can be
149 * due to simply not being in an active scan which
150 * can occur if we send the scan abort before we
151 * the microcode has notified us that a scan is
153 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
154 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
155 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
158 priv
->alloc_rxb_skb
--;
159 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
165 /* Service response to REPLY_SCAN_CMD (0x80) */
166 static void iwl_rx_reply_scan(struct iwl_priv
*priv
,
167 struct iwl_rx_mem_buffer
*rxb
)
169 #ifdef CONFIG_IWLWIFI_DEBUG
170 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
171 struct iwl_scanreq_notification
*notif
=
172 (struct iwl_scanreq_notification
*)pkt
->u
.raw
;
174 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
178 /* Service SCAN_START_NOTIFICATION (0x82) */
179 static void iwl_rx_scan_start_notif(struct iwl_priv
*priv
,
180 struct iwl_rx_mem_buffer
*rxb
)
182 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
183 struct iwl_scanstart_notification
*notif
=
184 (struct iwl_scanstart_notification
*)pkt
->u
.raw
;
185 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
186 IWL_DEBUG_SCAN("Scan start: "
188 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
190 notif
->band
? "bg" : "a",
191 le32_to_cpu(notif
->tsf_high
),
192 le32_to_cpu(notif
->tsf_low
),
193 notif
->status
, notif
->beacon_timer
);
196 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
197 static void iwl_rx_scan_results_notif(struct iwl_priv
*priv
,
198 struct iwl_rx_mem_buffer
*rxb
)
200 #ifdef CONFIG_IWLWIFI_DEBUG
201 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
202 struct iwl_scanresults_notification
*notif
=
203 (struct iwl_scanresults_notification
*)pkt
->u
.raw
;
205 IWL_DEBUG_SCAN("Scan ch.res: "
207 "(TSF: 0x%08X:%08X) - %d "
208 "elapsed=%lu usec (%dms since last)\n",
210 notif
->band
? "bg" : "a",
211 le32_to_cpu(notif
->tsf_high
),
212 le32_to_cpu(notif
->tsf_low
),
213 le32_to_cpu(notif
->statistics
[0]),
214 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
215 jiffies_to_msecs(elapsed_jiffies
216 (priv
->last_scan_jiffies
, jiffies
)));
219 priv
->last_scan_jiffies
= jiffies
;
220 priv
->next_scan_jiffies
= 0;
223 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
224 static void iwl_rx_scan_complete_notif(struct iwl_priv
*priv
,
225 struct iwl_rx_mem_buffer
*rxb
)
227 #ifdef CONFIG_IWLWIFI_DEBUG
228 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
229 struct iwl_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
231 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
232 scan_notif
->scanned_channels
,
234 scan_notif
->tsf_high
, scan_notif
->status
);
237 /* The HW is no longer scanning */
238 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
240 /* The scan completion notification came in, so kill that timer... */
241 cancel_delayed_work(&priv
->scan_check
);
243 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
244 (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) ?
246 jiffies_to_msecs(elapsed_jiffies
247 (priv
->scan_pass_start
, jiffies
)));
249 /* Remove this scanned band from the list of pending
250 * bands to scan, band G precedes A in order of scanning
251 * as seen in iwl_bg_request_scan */
252 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
))
253 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_2GHZ
);
254 else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
))
255 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_5GHZ
);
257 /* If a request to abort was given, or the scan did not succeed
258 * then we reset the scan state machine and terminate,
259 * re-queuing another scan if one has been requested */
260 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
261 IWL_DEBUG_INFO("Aborted scan completed.\n");
262 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
264 /* If there are more bands on this scan pass reschedule */
265 if (priv
->scan_bands
)
269 priv
->last_scan_jiffies
= jiffies
;
270 priv
->next_scan_jiffies
= 0;
271 IWL_DEBUG_INFO("Setting scan to off\n");
273 clear_bit(STATUS_SCANNING
, &priv
->status
);
275 IWL_DEBUG_INFO("Scan took %dms\n",
276 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
278 queue_work(priv
->workqueue
, &priv
->scan_completed
);
283 priv
->scan_pass_start
= jiffies
;
284 queue_work(priv
->workqueue
, &priv
->request_scan
);
287 void iwl_setup_rx_scan_handlers(struct iwl_priv
*priv
)
290 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl_rx_reply_scan
;
291 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl_rx_scan_start_notif
;
292 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
293 iwl_rx_scan_results_notif
;
294 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
295 iwl_rx_scan_complete_notif
;
297 EXPORT_SYMBOL(iwl_setup_rx_scan_handlers
);
299 static inline u16
iwl_get_active_dwell_time(struct iwl_priv
*priv
,
300 enum ieee80211_band band
,
303 if (band
== IEEE80211_BAND_5GHZ
)
304 return IWL_ACTIVE_DWELL_TIME_52
+
305 IWL_ACTIVE_DWELL_FACTOR_52GHZ
* (n_probes
+ 1);
307 return IWL_ACTIVE_DWELL_TIME_24
+
308 IWL_ACTIVE_DWELL_FACTOR_24GHZ
* (n_probes
+ 1);
311 static u16
iwl_get_passive_dwell_time(struct iwl_priv
*priv
,
312 enum ieee80211_band band
)
314 u16 passive
= (band
== IEEE80211_BAND_2GHZ
) ?
315 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
316 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
318 if (iwl_is_associated(priv
)) {
319 /* If we're associated, we clamp the maximum passive
320 * dwell time to be 98% of the beacon interval (minus
321 * 2 * channel tune time) */
322 passive
= priv
->beacon_int
;
323 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
324 passive
= IWL_PASSIVE_DWELL_BASE
;
325 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
331 static int iwl_get_channels_for_scan(struct iwl_priv
*priv
,
332 enum ieee80211_band band
,
333 u8 is_active
, u8 n_probes
,
334 struct iwl_scan_channel
*scan_ch
)
336 const struct ieee80211_channel
*channels
= NULL
;
337 const struct ieee80211_supported_band
*sband
;
338 const struct iwl_channel_info
*ch_info
;
339 u16 passive_dwell
= 0;
340 u16 active_dwell
= 0;
344 sband
= iwl_get_hw_mode(priv
, band
);
348 channels
= sband
->channels
;
350 active_dwell
= iwl_get_active_dwell_time(priv
, band
, n_probes
);
351 passive_dwell
= iwl_get_passive_dwell_time(priv
, band
);
353 if (passive_dwell
<= active_dwell
)
354 passive_dwell
= active_dwell
+ 1;
356 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
357 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
361 ieee80211_frequency_to_channel(channels
[i
].center_freq
);
362 scan_ch
->channel
= cpu_to_le16(channel
);
364 ch_info
= iwl_get_channel_info(priv
, band
, channel
);
365 if (!is_channel_valid(ch_info
)) {
366 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
371 if (!is_active
|| is_channel_passive(ch_info
) ||
372 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
373 scan_ch
->type
= SCAN_CHANNEL_TYPE_PASSIVE
;
375 scan_ch
->type
= SCAN_CHANNEL_TYPE_ACTIVE
;
378 scan_ch
->type
|= IWL_SCAN_PROBE_MASK(n_probes
);
380 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
381 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
383 /* Set txpower levels to defaults */
384 scan_ch
->dsp_atten
= 110;
386 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
388 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
390 if (band
== IEEE80211_BAND_5GHZ
)
391 scan_ch
->tx_gain
= ((1 << 5) | (3 << 3)) | 3;
393 scan_ch
->tx_gain
= ((1 << 5) | (5 << 3));
395 IWL_DEBUG_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n",
396 channel
, le32_to_cpu(scan_ch
->type
),
397 (scan_ch
->type
& SCAN_CHANNEL_TYPE_ACTIVE
) ?
398 "ACTIVE" : "PASSIVE",
399 (scan_ch
->type
& SCAN_CHANNEL_TYPE_ACTIVE
) ?
400 active_dwell
: passive_dwell
);
406 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
410 void iwl_init_scan_params(struct iwl_priv
*priv
)
412 u8 ant_idx
= fls(priv
->hw_params
.valid_tx_ant
) - 1;
413 if (!priv
->scan_tx_ant
[IEEE80211_BAND_5GHZ
])
414 priv
->scan_tx_ant
[IEEE80211_BAND_5GHZ
] = ant_idx
;
415 if (!priv
->scan_tx_ant
[IEEE80211_BAND_2GHZ
])
416 priv
->scan_tx_ant
[IEEE80211_BAND_2GHZ
] = ant_idx
;
419 int iwl_scan_initiate(struct iwl_priv
*priv
)
421 if (!iwl_is_ready_rf(priv
)) {
422 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
426 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
427 IWL_DEBUG_SCAN("Scan already in progress.\n");
431 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
432 IWL_DEBUG_SCAN("Scan request while abort pending\n");
436 IWL_DEBUG_INFO("Starting scan...\n");
437 if (priv
->cfg
->sku
& IWL_SKU_G
)
438 priv
->scan_bands
|= BIT(IEEE80211_BAND_2GHZ
);
439 if (priv
->cfg
->sku
& IWL_SKU_A
)
440 priv
->scan_bands
|= BIT(IEEE80211_BAND_5GHZ
);
441 set_bit(STATUS_SCANNING
, &priv
->status
);
442 priv
->scan_start
= jiffies
;
443 priv
->scan_pass_start
= priv
->scan_start
;
445 queue_work(priv
->workqueue
, &priv
->request_scan
);
449 EXPORT_SYMBOL(iwl_scan_initiate
);
451 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
453 static void iwl_bg_scan_check(struct work_struct
*data
)
455 struct iwl_priv
*priv
=
456 container_of(data
, struct iwl_priv
, scan_check
.work
);
458 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
461 mutex_lock(&priv
->mutex
);
462 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
463 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
464 IWL_DEBUG(IWL_DL_SCAN
, "Scan completion watchdog resetting "
466 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
468 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
469 iwl_send_scan_abort(priv
);
471 mutex_unlock(&priv
->mutex
);
474 * iwl_supported_rate_to_ie - fill in the supported rate in IE field
476 * return : set the bit for each supported rate insert in ie
478 static u16
iwl_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
479 u16 basic_rate
, int *left
)
481 u16 ret_rates
= 0, bit
;
486 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
487 if (bit
& supported_rate
) {
489 rates
[*cnt
] = iwl_rates
[i
].ieee
|
490 ((bit
& basic_rate
) ? 0x80 : 0x00);
494 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
503 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
506 struct ieee80211_ht_cap
*ht_cap
;
508 if (!sband
|| !sband
->ht_cap
.ht_supported
)
511 if (*left
< sizeof(struct ieee80211_ht_cap
))
514 *pos
++ = sizeof(struct ieee80211_ht_cap
);
515 ht_cap
= (struct ieee80211_ht_cap
*) pos
;
517 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_cap
.cap
);
518 memcpy(&ht_cap
->mcs
, &sband
->ht_cap
.mcs
, 16);
519 ht_cap
->ampdu_params_info
=
520 (sband
->ht_cap
.ampdu_factor
& IEEE80211_HT_AMPDU_PARM_FACTOR
) |
521 ((sband
->ht_cap
.ampdu_density
<< 2) &
522 IEEE80211_HT_AMPDU_PARM_DENSITY
);
523 *left
-= sizeof(struct ieee80211_ht_cap
);
527 * iwl_fill_probe_req - fill in all required fields and IE for probe request
530 static u16
iwl_fill_probe_req(struct iwl_priv
*priv
,
531 enum ieee80211_band band
,
532 struct ieee80211_mgmt
*frame
,
537 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
538 const struct ieee80211_supported_band
*sband
=
539 iwl_get_hw_mode(priv
, band
);
542 /* Make sure there is enough space for the probe request,
543 * two mandatory IEs and the data */
548 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
549 memcpy(frame
->da
, iwl_bcast_addr
, ETH_ALEN
);
550 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
551 memcpy(frame
->bssid
, iwl_bcast_addr
, ETH_ALEN
);
557 pos
= &frame
->u
.probe_req
.variable
[0];
559 /* fill in our indirect SSID IE */
563 *pos
++ = WLAN_EID_SSID
;
568 /* fill in supported rate */
573 *pos
++ = WLAN_EID_SUPP_RATES
;
576 /* exclude 60M rate */
577 active_rates
= priv
->rates_mask
;
578 active_rates
&= ~IWL_RATE_60M_MASK
;
580 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
582 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
583 ret_rates
= iwl_supported_rate_to_ie(pos
, cck_rates
,
584 active_rate_basic
, &left
);
585 active_rates
&= ~ret_rates
;
587 ret_rates
= iwl_supported_rate_to_ie(pos
, active_rates
,
588 active_rate_basic
, &left
);
589 active_rates
&= ~ret_rates
;
594 if (active_rates
== 0)
597 /* fill in supported extended rate */
602 /* ... fill it in... */
603 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
605 iwl_supported_rate_to_ie(pos
, active_rates
, active_rate_basic
, &left
);
619 *pos
++ = WLAN_EID_HT_CAPABILITY
;
621 iwl_ht_cap_to_ie(sband
, pos
, &left
);
628 static void iwl_bg_request_scan(struct work_struct
*data
)
630 struct iwl_priv
*priv
=
631 container_of(data
, struct iwl_priv
, request_scan
);
632 struct iwl_host_cmd cmd
= {
633 .id
= REPLY_SCAN_CMD
,
634 .len
= sizeof(struct iwl_scan_cmd
),
635 .meta
.flags
= CMD_SIZE_HUGE
,
637 struct iwl_scan_cmd
*scan
;
638 struct ieee80211_conf
*conf
= NULL
;
642 enum ieee80211_band band
;
644 u8 rx_chain
= priv
->hw_params
.valid_rx_ant
;
646 DECLARE_SSID_BUF(ssid
);
648 conf
= ieee80211_get_hw_conf(priv
->hw
);
650 mutex_lock(&priv
->mutex
);
652 if (!iwl_is_ready(priv
)) {
653 IWL_WARNING("request scan called when driver not ready.\n");
657 /* Make sure the scan wasn't canceled before this queued work
658 * was given the chance to run... */
659 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
662 /* This should never be called or scheduled if there is currently
663 * a scan active in the hardware. */
664 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
665 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
666 "Ignoring second request.\n");
671 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
672 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
676 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
677 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
681 if (iwl_is_rfkill(priv
)) {
682 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
686 if (!test_bit(STATUS_READY
, &priv
->status
)) {
687 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
691 if (!priv
->scan_bands
) {
692 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
697 priv
->scan
= kmalloc(sizeof(struct iwl_scan_cmd
) +
698 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
705 memset(scan
, 0, sizeof(struct iwl_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
707 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
708 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
710 if (iwl_is_associated(priv
)) {
713 u32 suspend_time
= 100;
714 u32 scan_suspend_time
= 100;
717 IWL_DEBUG_INFO("Scanning while associated...\n");
719 spin_lock_irqsave(&priv
->lock
, flags
);
720 interval
= priv
->beacon_int
;
721 spin_unlock_irqrestore(&priv
->lock
, flags
);
723 scan
->suspend_time
= 0;
724 scan
->max_out_time
= cpu_to_le32(200 * 1024);
726 interval
= suspend_time
;
728 extra
= (suspend_time
/ interval
) << 22;
729 scan_suspend_time
= (extra
|
730 ((suspend_time
% interval
) * 1024));
731 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
732 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
733 scan_suspend_time
, interval
);
736 /* We should add the ability for user to lock to PASSIVE ONLY */
737 if (priv
->one_direct_scan
) {
738 IWL_DEBUG_SCAN("Start direct scan for '%s'\n",
739 print_ssid(ssid
, priv
->direct_ssid
,
740 priv
->direct_ssid_len
));
741 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
742 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
743 memcpy(scan
->direct_scan
[0].ssid
,
744 priv
->direct_ssid
, priv
->direct_ssid_len
);
747 IWL_DEBUG_SCAN("Start indirect scan.\n");
750 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
751 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
752 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
755 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
756 band
= IEEE80211_BAND_2GHZ
;
757 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
758 if (priv
->active_rxon
.flags
& RXON_FLG_CHANNEL_MODE_PURE_40_MSK
) {
759 rate
= IWL_RATE_6M_PLCP
;
761 rate
= IWL_RATE_1M_PLCP
;
762 rate_flags
= RATE_MCS_CCK_MSK
;
764 scan
->good_CRC_th
= 0;
765 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
766 band
= IEEE80211_BAND_5GHZ
;
767 rate
= IWL_RATE_6M_PLCP
;
768 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
770 /* Force use of chains B and C (0x6) for scan Rx for 4965
771 * Avoid A (0x1) because of its off-channel reception on A-band.
773 if ((priv
->hw_rev
& CSR_HW_REV_TYPE_MSK
) == CSR_HW_REV_TYPE_4965
)
776 IWL_WARNING("Invalid scan band count\n");
780 priv
->scan_tx_ant
[band
] =
781 iwl_toggle_tx_ant(priv
, priv
->scan_tx_ant
[band
]);
782 rate_flags
|= iwl_ant_idx_to_flags(priv
->scan_tx_ant
[band
]);
783 scan
->tx_cmd
.rate_n_flags
= iwl_hw_set_rate_n_flags(rate
, rate_flags
);
785 /* MIMO is not used here, but value is required */
786 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
787 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
788 (rx_chain
<< RXON_RX_CHAIN_FORCE_SEL_POS
) |
789 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
791 cmd_len
= iwl_fill_probe_req(priv
, band
,
792 (struct ieee80211_mgmt
*)scan
->data
,
793 IWL_MAX_SCAN_SIZE
- sizeof(*scan
));
795 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
797 if (priv
->iw_mode
== NL80211_IFTYPE_MONITOR
)
798 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
800 scan
->filter_flags
|= (RXON_FILTER_ACCEPT_GRP_MSK
|
801 RXON_FILTER_BCON_AWARE_MSK
);
803 scan
->channel_count
=
804 iwl_get_channels_for_scan(priv
, band
, 1, /* active */
806 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
808 if (scan
->channel_count
== 0) {
809 IWL_DEBUG_SCAN("channel count %d\n", scan
->channel_count
);
813 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
814 scan
->channel_count
* sizeof(struct iwl_scan_channel
);
816 scan
->len
= cpu_to_le16(cmd
.len
);
818 set_bit(STATUS_SCAN_HW
, &priv
->status
);
819 ret
= iwl_send_cmd_sync(priv
, &cmd
);
823 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
824 IWL_SCAN_CHECK_WATCHDOG
);
826 mutex_unlock(&priv
->mutex
);
830 /* Cannot perform scan. Make sure we clear scanning
831 * bits from status so next scan request can be performed.
832 * If we don't clear scanning status bit here all next scan
835 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
836 clear_bit(STATUS_SCANNING
, &priv
->status
);
837 /* inform mac80211 scan aborted */
838 queue_work(priv
->workqueue
, &priv
->scan_completed
);
839 mutex_unlock(&priv
->mutex
);
842 static void iwl_bg_abort_scan(struct work_struct
*work
)
844 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
846 if (!iwl_is_ready(priv
))
849 mutex_lock(&priv
->mutex
);
851 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
852 iwl_send_scan_abort(priv
);
854 mutex_unlock(&priv
->mutex
);
857 static void iwl_bg_scan_completed(struct work_struct
*work
)
859 struct iwl_priv
*priv
=
860 container_of(work
, struct iwl_priv
, scan_completed
);
862 IWL_DEBUG_SCAN("SCAN complete scan\n");
864 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
867 ieee80211_scan_completed(priv
->hw
);
869 /* Since setting the TXPOWER may have been deferred while
870 * performing the scan, fire one off */
871 mutex_lock(&priv
->mutex
);
872 iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
873 mutex_unlock(&priv
->mutex
);
877 void iwl_setup_scan_deferred_work(struct iwl_priv
*priv
)
879 INIT_WORK(&priv
->scan_completed
, iwl_bg_scan_completed
);
880 INIT_WORK(&priv
->request_scan
, iwl_bg_request_scan
);
881 INIT_WORK(&priv
->abort_scan
, iwl_bg_abort_scan
);
882 INIT_DELAYED_WORK(&priv
->scan_check
, iwl_bg_scan_check
);
884 EXPORT_SYMBOL(iwl_setup_scan_deferred_work
);