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 * Tomas Winkler <tomas.winkler@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
28 #include <net/mac80211.h>
29 #include <linux/etherdevice.h>
31 #include "iwl-eeprom.h"
36 #include "iwl-helpers.h"
38 /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after
39 * sending probe req. This should be set long enough to hear probe responses
40 * from more than one AP. */
41 #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */
42 #define IWL_ACTIVE_DWELL_TIME_52 (20)
44 #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3)
45 #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2)
47 /* For faster active scanning, scan will move to the next channel if fewer than
48 * PLCP_QUIET_THRESH packets are heard on this channel within
49 * ACTIVE_QUIET_TIME after sending probe request. This shortens the dwell
50 * time if it's a quiet channel (nothing responded to our probe, and there's
52 * Disable "quiet" feature by setting PLCP_QUIET_THRESH to 0. */
53 #define IWL_PLCP_QUIET_THRESH __constant_cpu_to_le16(1) /* packets */
54 #define IWL_ACTIVE_QUIET_TIME __constant_cpu_to_le16(10) /* msec */
56 /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel.
57 * Must be set longer than active dwell time.
58 * For the most reliable scan, set > AP beacon interval (typically 100msec). */
59 #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */
60 #define IWL_PASSIVE_DWELL_TIME_52 (10)
61 #define IWL_PASSIVE_DWELL_BASE (100)
62 #define IWL_CHANNEL_TUNE_TIME 5
64 #define IWL_SCAN_PROBE_MASK(n) cpu_to_le32((BIT(n) | (BIT(n) - BIT(1))))
67 static int scan_tx_ant
[3] = {
68 RATE_MCS_ANT_A_MSK
, RATE_MCS_ANT_B_MSK
, RATE_MCS_ANT_C_MSK
73 static int iwl_is_empty_essid(const char *essid
, int essid_len
)
75 /* Single white space is for Linksys APs */
76 if (essid_len
== 1 && essid
[0] == ' ')
79 /* Otherwise, if the entire essid is 0, we assume it is hidden */
82 if (essid
[essid_len
] != '\0')
91 const char *iwl_escape_essid(const char *essid
, u8 essid_len
)
93 static char escaped
[IW_ESSID_MAX_SIZE
* 2 + 1];
94 const char *s
= essid
;
97 if (iwl_is_empty_essid(essid
, essid_len
)) {
98 memcpy(escaped
, "<hidden>", sizeof("<hidden>"));
102 essid_len
= min(essid_len
, (u8
) IW_ESSID_MAX_SIZE
);
103 while (essid_len
--) {
114 EXPORT_SYMBOL(iwl_escape_essid
);
117 * iwl_scan_cancel - Cancel any currently executing HW scan
119 * NOTE: priv->mutex is not required before calling this function
121 int iwl_scan_cancel(struct iwl_priv
*priv
)
123 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
124 clear_bit(STATUS_SCANNING
, &priv
->status
);
128 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
129 if (!test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
130 IWL_DEBUG_SCAN("Queuing scan abort.\n");
131 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
132 queue_work(priv
->workqueue
, &priv
->abort_scan
);
135 IWL_DEBUG_SCAN("Scan abort already in progress.\n");
137 return test_bit(STATUS_SCANNING
, &priv
->status
);
142 EXPORT_SYMBOL(iwl_scan_cancel
);
144 * iwl_scan_cancel_timeout - Cancel any currently executing HW scan
145 * @ms: amount of time to wait (in milliseconds) for scan to abort
147 * NOTE: priv->mutex must be held before calling this function
149 int iwl_scan_cancel_timeout(struct iwl_priv
*priv
, unsigned long ms
)
151 unsigned long now
= jiffies
;
154 ret
= iwl_scan_cancel(priv
);
156 mutex_unlock(&priv
->mutex
);
157 while (!time_after(jiffies
, now
+ msecs_to_jiffies(ms
)) &&
158 test_bit(STATUS_SCANNING
, &priv
->status
))
160 mutex_lock(&priv
->mutex
);
162 return test_bit(STATUS_SCANNING
, &priv
->status
);
167 EXPORT_SYMBOL(iwl_scan_cancel_timeout
);
169 static int iwl_send_scan_abort(struct iwl_priv
*priv
)
172 struct iwl_rx_packet
*res
;
173 struct iwl_host_cmd cmd
= {
174 .id
= REPLY_SCAN_ABORT_CMD
,
175 .meta
.flags
= CMD_WANT_SKB
,
178 /* If there isn't a scan actively going on in the hardware
179 * then we are in between scan bands and not actually
180 * actively scanning, so don't send the abort command */
181 if (!test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
182 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
186 ret
= iwl_send_cmd_sync(priv
, &cmd
);
188 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
192 res
= (struct iwl_rx_packet
*)cmd
.meta
.u
.skb
->data
;
193 if (res
->u
.status
!= CAN_ABORT_STATUS
) {
194 /* The scan abort will return 1 for success or
195 * 2 for "failure". A failure condition can be
196 * due to simply not being in an active scan which
197 * can occur if we send the scan abort before we
198 * the microcode has notified us that a scan is
200 IWL_DEBUG_INFO("SCAN_ABORT returned %d.\n", res
->u
.status
);
201 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
202 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
205 dev_kfree_skb_any(cmd
.meta
.u
.skb
);
211 /* Service response to REPLY_SCAN_CMD (0x80) */
212 static void iwl_rx_reply_scan(struct iwl_priv
*priv
,
213 struct iwl_rx_mem_buffer
*rxb
)
215 #ifdef CONFIG_IWLWIFI_DEBUG
216 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
217 struct iwl_scanreq_notification
*notif
=
218 (struct iwl_scanreq_notification
*)pkt
->u
.raw
;
220 IWL_DEBUG_RX("Scan request status = 0x%x\n", notif
->status
);
224 /* Service SCAN_START_NOTIFICATION (0x82) */
225 static void iwl_rx_scan_start_notif(struct iwl_priv
*priv
,
226 struct iwl_rx_mem_buffer
*rxb
)
228 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
229 struct iwl_scanstart_notification
*notif
=
230 (struct iwl_scanstart_notification
*)pkt
->u
.raw
;
231 priv
->scan_start_tsf
= le32_to_cpu(notif
->tsf_low
);
232 IWL_DEBUG_SCAN("Scan start: "
234 "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n",
236 notif
->band
? "bg" : "a",
237 le32_to_cpu(notif
->tsf_high
),
238 le32_to_cpu(notif
->tsf_low
),
239 notif
->status
, notif
->beacon_timer
);
242 /* Service SCAN_RESULTS_NOTIFICATION (0x83) */
243 static void iwl_rx_scan_results_notif(struct iwl_priv
*priv
,
244 struct iwl_rx_mem_buffer
*rxb
)
246 #ifdef CONFIG_IWLWIFI_DEBUG
247 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
248 struct iwl_scanresults_notification
*notif
=
249 (struct iwl_scanresults_notification
*)pkt
->u
.raw
;
251 IWL_DEBUG_SCAN("Scan ch.res: "
253 "(TSF: 0x%08X:%08X) - %d "
254 "elapsed=%lu usec (%dms since last)\n",
256 notif
->band
? "bg" : "a",
257 le32_to_cpu(notif
->tsf_high
),
258 le32_to_cpu(notif
->tsf_low
),
259 le32_to_cpu(notif
->statistics
[0]),
260 le32_to_cpu(notif
->tsf_low
) - priv
->scan_start_tsf
,
261 jiffies_to_msecs(elapsed_jiffies
262 (priv
->last_scan_jiffies
, jiffies
)));
265 priv
->last_scan_jiffies
= jiffies
;
266 priv
->next_scan_jiffies
= 0;
269 /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */
270 static void iwl_rx_scan_complete_notif(struct iwl_priv
*priv
,
271 struct iwl_rx_mem_buffer
*rxb
)
273 struct iwl_rx_packet
*pkt
= (struct iwl_rx_packet
*)rxb
->skb
->data
;
274 struct iwl_scancomplete_notification
*scan_notif
= (void *)pkt
->u
.raw
;
276 IWL_DEBUG_SCAN("Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n",
277 scan_notif
->scanned_channels
,
279 scan_notif
->tsf_high
, scan_notif
->status
);
281 /* The HW is no longer scanning */
282 clear_bit(STATUS_SCAN_HW
, &priv
->status
);
284 /* The scan completion notification came in, so kill that timer... */
285 cancel_delayed_work(&priv
->scan_check
);
287 IWL_DEBUG_INFO("Scan pass on %sGHz took %dms\n",
288 (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) ?
290 jiffies_to_msecs(elapsed_jiffies
291 (priv
->scan_pass_start
, jiffies
)));
293 /* Remove this scanned band from the list of pending
294 * bands to scan, band G precedes A in order of scanning
295 * as seen in iwl_bg_request_scan */
296 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
))
297 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_2GHZ
);
298 else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
))
299 priv
->scan_bands
&= ~BIT(IEEE80211_BAND_5GHZ
);
301 /* If a request to abort was given, or the scan did not succeed
302 * then we reset the scan state machine and terminate,
303 * re-queuing another scan if one has been requested */
304 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
305 IWL_DEBUG_INFO("Aborted scan completed.\n");
306 clear_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
308 /* If there are more bands on this scan pass reschedule */
309 if (priv
->scan_bands
)
313 priv
->last_scan_jiffies
= jiffies
;
314 priv
->next_scan_jiffies
= 0;
315 IWL_DEBUG_INFO("Setting scan to off\n");
317 clear_bit(STATUS_SCANNING
, &priv
->status
);
319 IWL_DEBUG_INFO("Scan took %dms\n",
320 jiffies_to_msecs(elapsed_jiffies(priv
->scan_start
, jiffies
)));
322 queue_work(priv
->workqueue
, &priv
->scan_completed
);
327 priv
->scan_pass_start
= jiffies
;
328 queue_work(priv
->workqueue
, &priv
->request_scan
);
331 void iwl_setup_rx_scan_handlers(struct iwl_priv
*priv
)
334 priv
->rx_handlers
[REPLY_SCAN_CMD
] = iwl_rx_reply_scan
;
335 priv
->rx_handlers
[SCAN_START_NOTIFICATION
] = iwl_rx_scan_start_notif
;
336 priv
->rx_handlers
[SCAN_RESULTS_NOTIFICATION
] =
337 iwl_rx_scan_results_notif
;
338 priv
->rx_handlers
[SCAN_COMPLETE_NOTIFICATION
] =
339 iwl_rx_scan_complete_notif
;
341 EXPORT_SYMBOL(iwl_setup_rx_scan_handlers
);
343 static inline u16
iwl_get_active_dwell_time(struct iwl_priv
*priv
,
344 enum ieee80211_band band
,
347 if (band
== IEEE80211_BAND_5GHZ
)
348 return IWL_ACTIVE_DWELL_TIME_52
+
349 IWL_ACTIVE_DWELL_FACTOR_52GHZ
* (n_probes
+ 1);
351 return IWL_ACTIVE_DWELL_TIME_24
+
352 IWL_ACTIVE_DWELL_FACTOR_24GHZ
* (n_probes
+ 1);
355 static u16
iwl_get_passive_dwell_time(struct iwl_priv
*priv
,
356 enum ieee80211_band band
)
358 u16 passive
= (band
== IEEE80211_BAND_2GHZ
) ?
359 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_24
:
360 IWL_PASSIVE_DWELL_BASE
+ IWL_PASSIVE_DWELL_TIME_52
;
362 if (iwl_is_associated(priv
)) {
363 /* If we're associated, we clamp the maximum passive
364 * dwell time to be 98% of the beacon interval (minus
365 * 2 * channel tune time) */
366 passive
= priv
->beacon_int
;
367 if ((passive
> IWL_PASSIVE_DWELL_BASE
) || !passive
)
368 passive
= IWL_PASSIVE_DWELL_BASE
;
369 passive
= (passive
* 98) / 100 - IWL_CHANNEL_TUNE_TIME
* 2;
375 static int iwl_get_channels_for_scan(struct iwl_priv
*priv
,
376 enum ieee80211_band band
,
377 u8 is_active
, u8 n_probes
,
378 struct iwl_scan_channel
*scan_ch
)
380 const struct ieee80211_channel
*channels
= NULL
;
381 const struct ieee80211_supported_band
*sband
;
382 const struct iwl_channel_info
*ch_info
;
383 u16 passive_dwell
= 0;
384 u16 active_dwell
= 0;
388 sband
= iwl_get_hw_mode(priv
, band
);
392 channels
= sband
->channels
;
394 active_dwell
= iwl_get_active_dwell_time(priv
, band
, n_probes
);
395 passive_dwell
= iwl_get_passive_dwell_time(priv
, band
);
397 if (passive_dwell
<= active_dwell
)
398 passive_dwell
= active_dwell
+ 1;
400 for (i
= 0, added
= 0; i
< sband
->n_channels
; i
++) {
401 if (channels
[i
].flags
& IEEE80211_CHAN_DISABLED
)
405 ieee80211_frequency_to_channel(channels
[i
].center_freq
);
406 scan_ch
->channel
= cpu_to_le16(channel
);
408 ch_info
= iwl_get_channel_info(priv
, band
, channel
);
409 if (!is_channel_valid(ch_info
)) {
410 IWL_DEBUG_SCAN("Channel %d is INVALID for this band.\n",
415 if (!is_active
|| is_channel_passive(ch_info
) ||
416 (channels
[i
].flags
& IEEE80211_CHAN_PASSIVE_SCAN
))
417 scan_ch
->type
= SCAN_CHANNEL_TYPE_PASSIVE
;
419 scan_ch
->type
= SCAN_CHANNEL_TYPE_ACTIVE
;
421 if ((scan_ch
->type
& SCAN_CHANNEL_TYPE_ACTIVE
) && n_probes
)
422 scan_ch
->type
|= IWL_SCAN_PROBE_MASK(n_probes
);
424 scan_ch
->active_dwell
= cpu_to_le16(active_dwell
);
425 scan_ch
->passive_dwell
= cpu_to_le16(passive_dwell
);
427 /* Set txpower levels to defaults */
428 scan_ch
->dsp_atten
= 110;
430 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
432 * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3;
434 if (band
== IEEE80211_BAND_5GHZ
)
435 scan_ch
->tx_gain
= ((1 << 5) | (3 << 3)) | 3;
437 scan_ch
->tx_gain
= ((1 << 5) | (5 << 3));
439 IWL_DEBUG_SCAN("Scanning ch=%d prob=0x%X [%s %d]\n",
440 channel
, le32_to_cpu(scan_ch
->type
),
441 (scan_ch
->type
& SCAN_CHANNEL_TYPE_ACTIVE
) ?
442 "ACTIVE" : "PASSIVE",
443 (scan_ch
->type
& SCAN_CHANNEL_TYPE_ACTIVE
) ?
444 active_dwell
: passive_dwell
);
450 IWL_DEBUG_SCAN("total channels to scan %d \n", added
);
454 void iwl_init_scan_params(struct iwl_priv
*priv
)
456 if (!priv
->scan_tx_ant
[IEEE80211_BAND_5GHZ
])
457 priv
->scan_tx_ant
[IEEE80211_BAND_5GHZ
] = RATE_MCS_ANT_INIT_IND
;
458 if (!priv
->scan_tx_ant
[IEEE80211_BAND_2GHZ
])
459 priv
->scan_tx_ant
[IEEE80211_BAND_2GHZ
] = RATE_MCS_ANT_INIT_IND
;
462 int iwl_scan_initiate(struct iwl_priv
*priv
)
464 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
) {
465 IWL_ERROR("APs don't scan.\n");
469 if (!iwl_is_ready_rf(priv
)) {
470 IWL_DEBUG_SCAN("Aborting scan due to not ready.\n");
474 if (test_bit(STATUS_SCANNING
, &priv
->status
)) {
475 IWL_DEBUG_SCAN("Scan already in progress.\n");
479 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
480 IWL_DEBUG_SCAN("Scan request while abort pending. "
485 IWL_DEBUG_INFO("Starting scan...\n");
486 if (priv
->cfg
->sku
& IWL_SKU_G
)
487 priv
->scan_bands
|= BIT(IEEE80211_BAND_2GHZ
);
488 if (priv
->cfg
->sku
& IWL_SKU_A
)
489 priv
->scan_bands
|= BIT(IEEE80211_BAND_5GHZ
);
490 set_bit(STATUS_SCANNING
, &priv
->status
);
491 priv
->scan_start
= jiffies
;
492 priv
->scan_pass_start
= priv
->scan_start
;
494 queue_work(priv
->workqueue
, &priv
->request_scan
);
498 EXPORT_SYMBOL(iwl_scan_initiate
);
500 #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
502 static void iwl_bg_scan_check(struct work_struct
*data
)
504 struct iwl_priv
*priv
=
505 container_of(data
, struct iwl_priv
, scan_check
.work
);
507 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
510 mutex_lock(&priv
->mutex
);
511 if (test_bit(STATUS_SCANNING
, &priv
->status
) ||
512 test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
513 IWL_DEBUG(IWL_DL_SCAN
, "Scan completion watchdog resetting "
515 jiffies_to_msecs(IWL_SCAN_CHECK_WATCHDOG
));
517 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
518 iwl_send_scan_abort(priv
);
520 mutex_unlock(&priv
->mutex
);
523 * iwl_supported_rate_to_ie - fill in the supported rate in IE field
525 * return : set the bit for each supported rate insert in ie
527 static u16
iwl_supported_rate_to_ie(u8
*ie
, u16 supported_rate
,
528 u16 basic_rate
, int *left
)
530 u16 ret_rates
= 0, bit
;
535 for (bit
= 1, i
= 0; i
< IWL_RATE_COUNT
; i
++, bit
<<= 1) {
536 if (bit
& supported_rate
) {
538 rates
[*cnt
] = iwl_rates
[i
].ieee
|
539 ((bit
& basic_rate
) ? 0x80 : 0x00);
543 (*cnt
>= IWL_SUPPORTED_RATES_IE_LEN
))
552 static void iwl_ht_cap_to_ie(const struct ieee80211_supported_band
*sband
,
555 struct ieee80211_ht_cap
*ht_cap
;
557 if (!sband
|| !sband
->ht_info
.ht_supported
)
560 if (*left
< sizeof(struct ieee80211_ht_cap
))
563 *pos
++ = sizeof(struct ieee80211_ht_cap
);
564 ht_cap
= (struct ieee80211_ht_cap
*) pos
;
566 ht_cap
->cap_info
= cpu_to_le16(sband
->ht_info
.cap
);
567 memcpy(ht_cap
->supp_mcs_set
, sband
->ht_info
.supp_mcs_set
, 16);
568 ht_cap
->ampdu_params_info
=
569 (sband
->ht_info
.ampdu_factor
& IEEE80211_HT_CAP_AMPDU_FACTOR
) |
570 ((sband
->ht_info
.ampdu_density
<< 2) &
571 IEEE80211_HT_CAP_AMPDU_DENSITY
);
572 *left
-= sizeof(struct ieee80211_ht_cap
);
576 * iwl_fill_probe_req - fill in all required fields and IE for probe request
579 static u16
iwl_fill_probe_req(struct iwl_priv
*priv
,
580 enum ieee80211_band band
,
581 struct ieee80211_mgmt
*frame
,
586 u16 active_rates
, ret_rates
, cck_rates
, active_rate_basic
;
587 const struct ieee80211_supported_band
*sband
=
588 iwl_get_hw_mode(priv
, band
);
591 /* Make sure there is enough space for the probe request,
592 * two mandatory IEs and the data */
597 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
598 memcpy(frame
->da
, iwl_bcast_addr
, ETH_ALEN
);
599 memcpy(frame
->sa
, priv
->mac_addr
, ETH_ALEN
);
600 memcpy(frame
->bssid
, iwl_bcast_addr
, ETH_ALEN
);
606 pos
= &frame
->u
.probe_req
.variable
[0];
608 /* fill in our indirect SSID IE */
612 *pos
++ = WLAN_EID_SSID
;
617 /* fill in supported rate */
622 *pos
++ = WLAN_EID_SUPP_RATES
;
625 /* exclude 60M rate */
626 active_rates
= priv
->rates_mask
;
627 active_rates
&= ~IWL_RATE_60M_MASK
;
629 active_rate_basic
= active_rates
& IWL_BASIC_RATES_MASK
;
631 cck_rates
= IWL_CCK_RATES_MASK
& active_rates
;
632 ret_rates
= iwl_supported_rate_to_ie(pos
, cck_rates
,
633 active_rate_basic
, &left
);
634 active_rates
&= ~ret_rates
;
636 ret_rates
= iwl_supported_rate_to_ie(pos
, active_rates
,
637 active_rate_basic
, &left
);
638 active_rates
&= ~ret_rates
;
643 if (active_rates
== 0)
646 /* fill in supported extended rate */
651 /* ... fill it in... */
652 *pos
++ = WLAN_EID_EXT_SUPP_RATES
;
654 iwl_supported_rate_to_ie(pos
, active_rates
, active_rate_basic
, &left
);
668 *pos
++ = WLAN_EID_HT_CAPABILITY
;
670 iwl_ht_cap_to_ie(sband
, pos
, &left
);
677 static u32
iwl_scan_tx_ant(struct iwl_priv
*priv
, enum ieee80211_band band
)
681 ind
= priv
->scan_tx_ant
[band
];
682 for (i
= 0; i
< priv
->hw_params
.tx_chains_num
; i
++) {
683 ind
= (ind
+1) >= priv
->hw_params
.tx_chains_num
? 0 : ind
+1;
684 if (priv
->hw_params
.valid_tx_ant
& (1 << ind
)) {
685 priv
->scan_tx_ant
[band
] = ind
;
689 IWL_DEBUG_SCAN("select TX ANT = %c\n", 'A' + ind
);
690 return scan_tx_ant
[ind
];
694 static void iwl_bg_request_scan(struct work_struct
*data
)
696 struct iwl_priv
*priv
=
697 container_of(data
, struct iwl_priv
, request_scan
);
698 struct iwl_host_cmd cmd
= {
699 .id
= REPLY_SCAN_CMD
,
700 .len
= sizeof(struct iwl_scan_cmd
),
701 .meta
.flags
= CMD_SIZE_HUGE
,
703 struct iwl_scan_cmd
*scan
;
704 struct ieee80211_conf
*conf
= NULL
;
708 enum ieee80211_band band
;
710 u8 rx_chain
= 0x7; /* bitmap: ABC chains */
712 conf
= ieee80211_get_hw_conf(priv
->hw
);
714 mutex_lock(&priv
->mutex
);
716 if (!iwl_is_ready(priv
)) {
717 IWL_WARNING("request scan called when driver not ready.\n");
721 /* Make sure the scan wasn't cancelled before this queued work
722 * was given the chance to run... */
723 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
726 /* This should never be called or scheduled if there is currently
727 * a scan active in the hardware. */
728 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
729 IWL_DEBUG_INFO("Multiple concurrent scan requests in parallel. "
730 "Ignoring second request.\n");
735 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
736 IWL_DEBUG_SCAN("Aborting scan due to device shutdown\n");
740 if (test_bit(STATUS_SCAN_ABORTING
, &priv
->status
)) {
741 IWL_DEBUG_HC("Scan request while abort pending. Queuing.\n");
745 if (iwl_is_rfkill(priv
)) {
746 IWL_DEBUG_HC("Aborting scan due to RF Kill activation\n");
750 if (!test_bit(STATUS_READY
, &priv
->status
)) {
751 IWL_DEBUG_HC("Scan request while uninitialized. Queuing.\n");
755 if (!priv
->scan_bands
) {
756 IWL_DEBUG_HC("Aborting scan due to no requested bands\n");
761 priv
->scan
= kmalloc(sizeof(struct iwl_scan_cmd
) +
762 IWL_MAX_SCAN_SIZE
, GFP_KERNEL
);
769 memset(scan
, 0, sizeof(struct iwl_scan_cmd
) + IWL_MAX_SCAN_SIZE
);
771 scan
->quiet_plcp_th
= IWL_PLCP_QUIET_THRESH
;
772 scan
->quiet_time
= IWL_ACTIVE_QUIET_TIME
;
774 if (iwl_is_associated(priv
)) {
777 u32 suspend_time
= 100;
778 u32 scan_suspend_time
= 100;
781 IWL_DEBUG_INFO("Scanning while associated...\n");
783 spin_lock_irqsave(&priv
->lock
, flags
);
784 interval
= priv
->beacon_int
;
785 spin_unlock_irqrestore(&priv
->lock
, flags
);
787 scan
->suspend_time
= 0;
788 scan
->max_out_time
= cpu_to_le32(200 * 1024);
790 interval
= suspend_time
;
792 extra
= (suspend_time
/ interval
) << 22;
793 scan_suspend_time
= (extra
|
794 ((suspend_time
% interval
) * 1024));
795 scan
->suspend_time
= cpu_to_le32(scan_suspend_time
);
796 IWL_DEBUG_SCAN("suspend_time 0x%X beacon interval %d\n",
797 scan_suspend_time
, interval
);
800 /* We should add the ability for user to lock to PASSIVE ONLY */
801 if (priv
->one_direct_scan
) {
802 IWL_DEBUG_SCAN("Start direct scan for '%s'\n",
803 iwl_escape_essid(priv
->direct_ssid
,
804 priv
->direct_ssid_len
));
805 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
806 scan
->direct_scan
[0].len
= priv
->direct_ssid_len
;
807 memcpy(scan
->direct_scan
[0].ssid
,
808 priv
->direct_ssid
, priv
->direct_ssid_len
);
810 } else if (!iwl_is_associated(priv
) && priv
->essid_len
) {
811 IWL_DEBUG_SCAN("Start direct scan for '%s' (not associated)\n",
812 iwl_escape_essid(priv
->essid
, priv
->essid_len
));
813 scan
->direct_scan
[0].id
= WLAN_EID_SSID
;
814 scan
->direct_scan
[0].len
= priv
->essid_len
;
815 memcpy(scan
->direct_scan
[0].ssid
, priv
->essid
, priv
->essid_len
);
818 IWL_DEBUG_SCAN("Start indirect scan.\n");
821 scan
->tx_cmd
.tx_flags
= TX_CMD_FLG_SEQ_CTL_MSK
;
822 scan
->tx_cmd
.sta_id
= priv
->hw_params
.bcast_sta_id
;
823 scan
->tx_cmd
.stop_time
.life_time
= TX_CMD_LIFE_TIME_INFINITE
;
826 if (priv
->scan_bands
& BIT(IEEE80211_BAND_2GHZ
)) {
827 band
= IEEE80211_BAND_2GHZ
;
828 scan
->flags
= RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
;
829 tx_ant
= iwl_scan_tx_ant(priv
, band
);
830 if (priv
->active_rxon
.flags
& RXON_FLG_CHANNEL_MODE_PURE_40_MSK
)
831 scan
->tx_cmd
.rate_n_flags
=
832 iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
835 scan
->tx_cmd
.rate_n_flags
=
836 iwl_hw_set_rate_n_flags(IWL_RATE_1M_PLCP
,
839 scan
->good_CRC_th
= 0;
840 } else if (priv
->scan_bands
& BIT(IEEE80211_BAND_5GHZ
)) {
841 band
= IEEE80211_BAND_5GHZ
;
842 tx_ant
= iwl_scan_tx_ant(priv
, band
);
843 scan
->tx_cmd
.rate_n_flags
=
844 iwl_hw_set_rate_n_flags(IWL_RATE_6M_PLCP
,
846 scan
->good_CRC_th
= IWL_GOOD_CRC_TH
;
848 /* Force use of chains B and C (0x6) for scan Rx for 4965
849 * Avoid A (0x1) because of its off-channel reception on A-band.
850 * MIMO is not used here, but value is required */
851 if ((priv
->hw_rev
& CSR_HW_REV_TYPE_MSK
) == CSR_HW_REV_TYPE_4965
)
854 IWL_WARNING("Invalid scan band count\n");
858 scan
->rx_chain
= RXON_RX_CHAIN_DRIVER_FORCE_MSK
|
859 cpu_to_le16((0x7 << RXON_RX_CHAIN_VALID_POS
) |
860 (rx_chain
<< RXON_RX_CHAIN_FORCE_SEL_POS
) |
861 (0x7 << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS
));
863 cmd_len
= iwl_fill_probe_req(priv
, band
,
864 (struct ieee80211_mgmt
*)scan
->data
,
865 IWL_MAX_SCAN_SIZE
- sizeof(*scan
));
867 scan
->tx_cmd
.len
= cpu_to_le16(cmd_len
);
869 if (priv
->iw_mode
== IEEE80211_IF_TYPE_MNTR
)
870 scan
->filter_flags
= RXON_FILTER_PROMISC_MSK
;
872 scan
->filter_flags
|= (RXON_FILTER_ACCEPT_GRP_MSK
|
873 RXON_FILTER_BCON_AWARE_MSK
);
875 scan
->channel_count
=
876 iwl_get_channels_for_scan(priv
, band
, 1, /* active */
878 (void *)&scan
->data
[le16_to_cpu(scan
->tx_cmd
.len
)]);
880 if (scan
->channel_count
== 0) {
881 IWL_DEBUG_SCAN("channel count %d\n", scan
->channel_count
);
885 cmd
.len
+= le16_to_cpu(scan
->tx_cmd
.len
) +
886 scan
->channel_count
* sizeof(struct iwl_scan_channel
);
888 scan
->len
= cpu_to_le16(cmd
.len
);
890 set_bit(STATUS_SCAN_HW
, &priv
->status
);
891 ret
= iwl_send_cmd_sync(priv
, &cmd
);
895 queue_delayed_work(priv
->workqueue
, &priv
->scan_check
,
896 IWL_SCAN_CHECK_WATCHDOG
);
898 mutex_unlock(&priv
->mutex
);
902 /* inform mac80211 scan aborted */
903 queue_work(priv
->workqueue
, &priv
->scan_completed
);
904 mutex_unlock(&priv
->mutex
);
907 static void iwl_bg_abort_scan(struct work_struct
*work
)
909 struct iwl_priv
*priv
= container_of(work
, struct iwl_priv
, abort_scan
);
911 if (!iwl_is_ready(priv
))
914 mutex_lock(&priv
->mutex
);
916 set_bit(STATUS_SCAN_ABORTING
, &priv
->status
);
917 iwl_send_scan_abort(priv
);
919 mutex_unlock(&priv
->mutex
);
922 void iwl_setup_scan_deferred_work(struct iwl_priv
*priv
)
924 /* FIXME: move here when resolved PENDING
925 * INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); */
926 INIT_WORK(&priv
->request_scan
, iwl_bg_request_scan
);
927 INIT_WORK(&priv
->abort_scan
, iwl_bg_abort_scan
);
928 INIT_DELAYED_WORK(&priv
->scan_check
, iwl_bg_scan_check
);
930 EXPORT_SYMBOL(iwl_setup_scan_deferred_work
);