1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
64 #include <linux/etherdevice.h>
65 #include <net/mac80211.h>
68 #include "iwl-eeprom-parse.h"
69 #include "fw-api-scan.h"
71 #define IWL_PLCP_QUIET_THRESH 1
72 #define IWL_ACTIVE_QUIET_TIME 10
74 struct iwl_mvm_scan_params
{
77 bool passive_fragmented
;
81 } dwell
[IEEE80211_NUM_BANDS
];
84 static inline __le16
iwl_mvm_scan_rx_chain(struct iwl_mvm
*mvm
)
89 if (mvm
->scan_rx_ant
!= ANT_NONE
)
90 rx_ant
= mvm
->scan_rx_ant
;
92 rx_ant
= mvm
->fw
->valid_rx_ant
;
93 rx_chain
= rx_ant
<< PHY_RX_CHAIN_VALID_POS
;
94 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_MIMO_SEL_POS
;
95 rx_chain
|= rx_ant
<< PHY_RX_CHAIN_FORCE_SEL_POS
;
96 rx_chain
|= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS
;
97 return cpu_to_le16(rx_chain
);
100 static __le32
iwl_mvm_scan_rxon_flags(enum ieee80211_band band
)
102 if (band
== IEEE80211_BAND_2GHZ
)
103 return cpu_to_le32(PHY_BAND_24
);
105 return cpu_to_le32(PHY_BAND_5
);
109 iwl_mvm_scan_rate_n_flags(struct iwl_mvm
*mvm
, enum ieee80211_band band
,
114 mvm
->scan_last_antenna_idx
=
115 iwl_mvm_next_antenna(mvm
, mvm
->fw
->valid_tx_ant
,
116 mvm
->scan_last_antenna_idx
);
117 tx_ant
= BIT(mvm
->scan_last_antenna_idx
) << RATE_MCS_ANT_POS
;
119 if (band
== IEEE80211_BAND_2GHZ
&& !no_cck
)
120 return cpu_to_le32(IWL_RATE_1M_PLCP
| RATE_MCS_CCK_MSK
|
123 return cpu_to_le32(IWL_RATE_6M_PLCP
| tx_ant
);
127 * We insert the SSIDs in an inverted order, because the FW will
128 * invert it back. The most prioritized SSID, which is first in the
129 * request list, is not copied here, but inserted directly to the probe
132 static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie
*cmd_ssid
,
133 struct cfg80211_ssid
*ssids
,
134 int n_ssids
, int first
)
138 for (req_idx
= n_ssids
- 1, fw_idx
= 0; req_idx
>= first
;
139 req_idx
--, fw_idx
++) {
140 cmd_ssid
[fw_idx
].id
= WLAN_EID_SSID
;
141 cmd_ssid
[fw_idx
].len
= ssids
[req_idx
].ssid_len
;
142 memcpy(cmd_ssid
[fw_idx
].ssid
,
144 ssids
[req_idx
].ssid_len
);
149 * If req->n_ssids > 0, it means we should do an active scan.
150 * In case of active scan w/o directed scan, we receive a zero-length SSID
151 * just to notify that this scan is active and not passive.
152 * In order to notify the FW of the number of SSIDs we wish to scan (including
153 * the zero-length one), we need to set the corresponding bits in chan->type,
154 * one for each SSID, and set the active bit (first). If the first SSID is
155 * already included in the probe template, so we need to set only
156 * req->n_ssids - 1 bits in addition to the first bit.
158 static u16
iwl_mvm_get_active_dwell(enum ieee80211_band band
, int n_ssids
)
160 if (band
== IEEE80211_BAND_2GHZ
)
161 return 30 + 3 * (n_ssids
+ 1);
162 return 20 + 2 * (n_ssids
+ 1);
165 static u16
iwl_mvm_get_passive_dwell(enum ieee80211_band band
)
167 return band
== IEEE80211_BAND_2GHZ
? 100 + 20 : 100 + 10;
170 static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd
*cmd
,
171 struct cfg80211_scan_request
*req
,
173 struct iwl_mvm_scan_params
*params
)
175 struct iwl_scan_channel
*chan
= (struct iwl_scan_channel
*)
176 (cmd
->data
+ le16_to_cpu(cmd
->tx_cmd
.len
));
178 int type
= BIT(req
->n_ssids
) - 1;
179 enum ieee80211_band band
= req
->channels
[0]->band
;
182 type
|= BIT(req
->n_ssids
);
184 for (i
= 0; i
< cmd
->channel_count
; i
++) {
185 chan
->channel
= cpu_to_le16(req
->channels
[i
]->hw_value
);
186 chan
->type
= cpu_to_le32(type
);
187 if (req
->channels
[i
]->flags
& IEEE80211_CHAN_NO_IR
)
188 chan
->type
&= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE
);
189 chan
->active_dwell
= cpu_to_le16(params
->dwell
[band
].active
);
190 chan
->passive_dwell
= cpu_to_le16(params
->dwell
[band
].passive
);
191 chan
->iteration_count
= cpu_to_le16(1);
197 * Fill in probe request with the following parameters:
198 * TA is our vif HW address, which mac80211 ensures we have.
199 * Packet is broadcasted, so this is both SA and DA.
200 * The probe request IE is made out of two: first comes the most prioritized
201 * SSID if a directed scan is requested. Second comes whatever extra
202 * information was given to us as the scan request IE.
204 static u16
iwl_mvm_fill_probe_req(struct ieee80211_mgmt
*frame
, const u8
*ta
,
205 int n_ssids
, const u8
*ssid
, int ssid_len
,
206 const u8
*band_ie
, int band_ie_len
,
207 const u8
*common_ie
, int common_ie_len
,
213 /* Make sure there is enough space for the probe request,
214 * two mandatory IEs and the data */
219 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
220 eth_broadcast_addr(frame
->da
);
221 memcpy(frame
->sa
, ta
, ETH_ALEN
);
222 eth_broadcast_addr(frame
->bssid
);
227 /* for passive scans, no need to fill anything */
231 /* points to the payload of the request */
232 pos
= &frame
->u
.probe_req
.variable
[0];
234 /* fill in our SSID IE */
235 left
-= ssid_len
+ 2;
238 *pos
++ = WLAN_EID_SSID
;
240 if (ssid
&& ssid_len
) { /* ssid_len may be == 0 even if ssid is valid */
241 memcpy(pos
, ssid
, ssid_len
);
247 if (WARN_ON(left
< band_ie_len
+ common_ie_len
))
250 if (band_ie
&& band_ie_len
) {
251 memcpy(pos
, band_ie
, band_ie_len
);
256 if (common_ie
&& common_ie_len
) {
257 memcpy(pos
, common_ie
, common_ie_len
);
258 pos
+= common_ie_len
;
259 len
+= common_ie_len
;
265 static void iwl_mvm_scan_condition_iterator(void *data
, u8
*mac
,
266 struct ieee80211_vif
*vif
)
268 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
269 bool *global_bound
= data
;
271 if (mvmvif
->phy_ctxt
&& mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
272 *global_bound
= true;
275 static void iwl_mvm_scan_calc_params(struct iwl_mvm
*mvm
,
276 struct ieee80211_vif
*vif
,
277 int n_ssids
, u32 flags
,
278 struct iwl_mvm_scan_params
*params
)
280 bool global_bound
= false;
281 enum ieee80211_band band
;
282 u8 frag_passive_dwell
= 0;
284 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
285 IEEE80211_IFACE_ITER_NORMAL
,
286 iwl_mvm_scan_condition_iterator
,
292 params
->suspend_time
= 30;
293 params
->max_out_time
= 170;
295 if (iwl_mvm_low_latency(mvm
)) {
296 if (mvm
->fw
->ucode_capa
.api
[0] &
297 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
) {
298 params
->suspend_time
= 105;
299 params
->max_out_time
= 70;
300 frag_passive_dwell
= 20;
302 params
->suspend_time
= 120;
303 params
->max_out_time
= 120;
307 if (frag_passive_dwell
&& (mvm
->fw
->ucode_capa
.api
[0] &
308 IWL_UCODE_TLV_API_FRAGMENTED_SCAN
)) {
310 * P2P device scan should not be fragmented to avoid negative
311 * impact on P2P device discovery. Configure max_out_time to be
312 * equal to dwell time on passive channel. Take a longest
313 * possible value, one that corresponds to 2GHz band
315 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
317 iwl_mvm_get_passive_dwell(IEEE80211_BAND_2GHZ
);
318 params
->max_out_time
= passive_dwell
;
320 params
->passive_fragmented
= true;
324 if (flags
& NL80211_SCAN_FLAG_LOW_PRIORITY
)
325 params
->max_out_time
= 200;
329 for (band
= IEEE80211_BAND_2GHZ
; band
< IEEE80211_NUM_BANDS
; band
++) {
330 if (params
->passive_fragmented
)
331 params
->dwell
[band
].passive
= frag_passive_dwell
;
333 params
->dwell
[band
].passive
=
334 iwl_mvm_get_passive_dwell(band
);
335 params
->dwell
[band
].active
= iwl_mvm_get_active_dwell(band
,
340 int iwl_mvm_scan_request(struct iwl_mvm
*mvm
,
341 struct ieee80211_vif
*vif
,
342 struct cfg80211_scan_request
*req
)
344 struct iwl_host_cmd hcmd
= {
345 .id
= SCAN_REQUEST_CMD
,
347 .data
= { mvm
->scan_cmd
, },
348 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
350 struct iwl_scan_cmd
*cmd
= mvm
->scan_cmd
;
355 bool basic_ssid
= !(mvm
->fw
->ucode_capa
.flags
&
356 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID
);
357 struct iwl_mvm_scan_params params
= {};
359 lockdep_assert_held(&mvm
->mutex
);
361 /* we should have failed registration if scan_cmd was NULL */
362 if (WARN_ON(mvm
->scan_cmd
== NULL
))
365 IWL_DEBUG_SCAN(mvm
, "Handling mac80211 scan request\n");
366 mvm
->scan_status
= IWL_MVM_SCAN_OS
;
367 memset(cmd
, 0, ksize(cmd
));
369 cmd
->channel_count
= (u8
)req
->n_channels
;
370 cmd
->quiet_time
= cpu_to_le16(IWL_ACTIVE_QUIET_TIME
);
371 cmd
->quiet_plcp_th
= cpu_to_le16(IWL_PLCP_QUIET_THRESH
);
372 cmd
->rxchain_sel_flags
= iwl_mvm_scan_rx_chain(mvm
);
374 iwl_mvm_scan_calc_params(mvm
, vif
, req
->n_ssids
, req
->flags
, ¶ms
);
375 cmd
->max_out_time
= cpu_to_le32(params
.max_out_time
);
376 cmd
->suspend_time
= cpu_to_le32(params
.suspend_time
);
377 if (params
.passive_fragmented
)
378 cmd
->scan_flags
|= SCAN_FLAGS_FRAGMENTED_SCAN
;
380 cmd
->rxon_flags
= iwl_mvm_scan_rxon_flags(req
->channels
[0]->band
);
381 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
382 MAC_FILTER_IN_BEACON
);
384 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
385 cmd
->type
= cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED
);
387 cmd
->type
= cpu_to_le32(SCAN_TYPE_FORCED
);
389 cmd
->repeats
= cpu_to_le32(1);
392 * If the user asked for passive scan, don't change to active scan if
393 * you see any activity on the channel - remain passive.
395 if (req
->n_ssids
> 0) {
396 cmd
->passive2active
= cpu_to_le16(1);
397 cmd
->scan_flags
|= SCAN_FLAGS_PASSIVE2ACTIVE
;
399 ssid
= req
->ssids
[0].ssid
;
400 ssid_len
= req
->ssids
[0].ssid_len
;
403 cmd
->passive2active
= 0;
404 cmd
->scan_flags
&= ~SCAN_FLAGS_PASSIVE2ACTIVE
;
407 iwl_mvm_scan_fill_ssids(cmd
->direct_scan
, req
->ssids
, req
->n_ssids
,
410 cmd
->tx_cmd
.tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
412 cmd
->tx_cmd
.sta_id
= mvm
->aux_sta
.sta_id
;
413 cmd
->tx_cmd
.life_time
= cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE
);
414 cmd
->tx_cmd
.rate_n_flags
=
415 iwl_mvm_scan_rate_n_flags(mvm
, req
->channels
[0]->band
,
419 cpu_to_le16(iwl_mvm_fill_probe_req(
420 (struct ieee80211_mgmt
*)cmd
->data
,
422 req
->n_ssids
, ssid
, ssid_len
,
423 req
->ie
, req
->ie_len
, NULL
, 0,
424 mvm
->fw
->ucode_capa
.max_probe_length
));
426 iwl_mvm_scan_fill_channels(cmd
, req
, basic_ssid
, ¶ms
);
428 cmd
->len
= cpu_to_le16(sizeof(struct iwl_scan_cmd
) +
429 le16_to_cpu(cmd
->tx_cmd
.len
) +
430 (cmd
->channel_count
* sizeof(struct iwl_scan_channel
)));
431 hcmd
.len
[0] = le16_to_cpu(cmd
->len
);
433 status
= SCAN_RESPONSE_OK
;
434 ret
= iwl_mvm_send_cmd_status(mvm
, &hcmd
, &status
);
435 if (!ret
&& status
== SCAN_RESPONSE_OK
) {
436 IWL_DEBUG_SCAN(mvm
, "Scan request was sent successfully\n");
439 * If the scan failed, it usually means that the FW was unable
440 * to allocate the time events. Warn on it, but maybe we
441 * should try to send the command again with different params.
443 IWL_ERR(mvm
, "Scan failed! status 0x%x ret %d\n",
445 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
451 int iwl_mvm_rx_scan_response(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
,
452 struct iwl_device_cmd
*cmd
)
454 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
455 struct iwl_cmd_response
*resp
= (void *)pkt
->data
;
457 IWL_DEBUG_SCAN(mvm
, "Scan response received. status 0x%x\n",
458 le32_to_cpu(resp
->status
));
462 int iwl_mvm_rx_scan_complete(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
,
463 struct iwl_device_cmd
*cmd
)
465 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
466 struct iwl_scan_complete_notif
*notif
= (void *)pkt
->data
;
468 lockdep_assert_held(&mvm
->mutex
);
470 IWL_DEBUG_SCAN(mvm
, "Scan complete: status=0x%x scanned channels=%d\n",
471 notif
->status
, notif
->scanned_channels
);
473 if (mvm
->scan_status
== IWL_MVM_SCAN_OS
)
474 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
475 ieee80211_scan_completed(mvm
->hw
, notif
->status
!= SCAN_COMP_STATUS_OK
);
477 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
482 int iwl_mvm_rx_scan_offload_results(struct iwl_mvm
*mvm
,
483 struct iwl_rx_cmd_buffer
*rxb
,
484 struct iwl_device_cmd
*cmd
)
486 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
487 u8 client_bitmap
= 0;
489 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
)) {
490 struct iwl_sched_scan_results
*notif
= (void *)pkt
->data
;
492 client_bitmap
= notif
->client_bitmap
;
495 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
||
496 client_bitmap
& SCAN_CLIENT_SCHED_SCAN
) {
497 if (mvm
->scan_status
== IWL_MVM_SCAN_SCHED
) {
498 IWL_DEBUG_SCAN(mvm
, "Scheduled scan results\n");
499 ieee80211_sched_scan_results(mvm
->hw
);
501 IWL_DEBUG_SCAN(mvm
, "Scan results\n");
508 static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data
*notif_wait
,
509 struct iwl_rx_packet
*pkt
, void *data
)
511 struct iwl_mvm
*mvm
=
512 container_of(notif_wait
, struct iwl_mvm
, notif_wait
);
513 struct iwl_scan_complete_notif
*notif
;
516 switch (pkt
->hdr
.cmd
) {
518 resp
= (void *)pkt
->data
;
519 if (*resp
== CAN_ABORT_STATUS
) {
521 "Scan can be aborted, wait until completion\n");
526 * If scan cannot be aborted, it means that we had a
527 * SCAN_COMPLETE_NOTIFICATION in the pipe and it called
528 * ieee80211_scan_completed already.
530 IWL_DEBUG_SCAN(mvm
, "Scan cannot be aborted, exit now: %d\n",
534 case SCAN_COMPLETE_NOTIFICATION
:
535 notif
= (void *)pkt
->data
;
536 IWL_DEBUG_SCAN(mvm
, "Scan aborted: status 0x%x\n",
546 static int iwl_mvm_cancel_regular_scan(struct iwl_mvm
*mvm
)
548 struct iwl_notification_wait wait_scan_abort
;
549 static const u8 scan_abort_notif
[] = { SCAN_ABORT_CMD
,
550 SCAN_COMPLETE_NOTIFICATION
};
553 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
556 if (iwl_mvm_is_radio_killed(mvm
)) {
557 ieee80211_scan_completed(mvm
->hw
, true);
558 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
559 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
563 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_abort
,
565 ARRAY_SIZE(scan_abort_notif
),
566 iwl_mvm_scan_abort_notif
, NULL
);
568 ret
= iwl_mvm_send_cmd_pdu(mvm
, SCAN_ABORT_CMD
, 0, 0, NULL
);
570 IWL_ERR(mvm
, "Couldn't send SCAN_ABORT_CMD: %d\n", ret
);
571 /* mac80211's state will be cleaned in the nic_restart flow */
572 goto out_remove_notif
;
575 return iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_abort
, HZ
);
578 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_abort
);
582 int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm
*mvm
,
583 struct iwl_rx_cmd_buffer
*rxb
,
584 struct iwl_device_cmd
*cmd
)
586 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
587 u8 status
, ebs_status
;
589 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
) {
590 struct iwl_periodic_scan_complete
*scan_notif
;
592 scan_notif
= (void *)pkt
->data
;
593 status
= scan_notif
->status
;
594 ebs_status
= scan_notif
->ebs_status
;
596 struct iwl_scan_offload_complete
*scan_notif
;
598 scan_notif
= (void *)pkt
->data
;
599 status
= scan_notif
->status
;
600 ebs_status
= scan_notif
->ebs_status
;
602 /* scan status must be locked for proper checking */
603 lockdep_assert_held(&mvm
->mutex
);
606 "%s completed, status %s, EBS status %s\n",
607 mvm
->scan_status
== IWL_MVM_SCAN_SCHED
?
608 "Scheduled scan" : "Scan",
609 status
== IWL_SCAN_OFFLOAD_COMPLETED
?
610 "completed" : "aborted",
611 ebs_status
== IWL_SCAN_EBS_SUCCESS
?
612 "success" : "failed");
615 /* only call mac80211 completion if the stop was initiated by FW */
616 if (mvm
->scan_status
== IWL_MVM_SCAN_SCHED
) {
617 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
618 ieee80211_sched_scan_stopped(mvm
->hw
);
619 } else if (mvm
->scan_status
== IWL_MVM_SCAN_OS
) {
620 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
621 ieee80211_scan_completed(mvm
->hw
,
622 status
== IWL_SCAN_OFFLOAD_ABORTED
);
625 mvm
->last_ebs_successful
= !ebs_status
;
630 static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm
*mvm
,
631 struct ieee80211_vif
*vif
,
632 struct ieee80211_scan_ies
*ies
,
633 enum ieee80211_band band
,
634 struct iwl_tx_cmd
*cmd
,
639 cmd
->tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
);
640 cmd
->life_time
= cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE
);
641 cmd
->sta_id
= mvm
->aux_sta
.sta_id
;
643 cmd
->rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
, band
, false);
645 cmd_len
= iwl_mvm_fill_probe_req((struct ieee80211_mgmt
*)data
,
648 ies
->ies
[band
], ies
->len
[band
],
649 ies
->common_ies
, ies
->common_ie_len
,
650 SCAN_OFFLOAD_PROBE_REQ_SIZE
);
651 cmd
->len
= cpu_to_le16(cmd_len
);
654 static void iwl_build_scan_cmd(struct iwl_mvm
*mvm
,
655 struct ieee80211_vif
*vif
,
656 struct cfg80211_sched_scan_request
*req
,
657 struct iwl_scan_offload_cmd
*scan
,
658 struct iwl_mvm_scan_params
*params
)
660 scan
->channel_count
= req
->n_channels
;
661 scan
->quiet_time
= cpu_to_le16(IWL_ACTIVE_QUIET_TIME
);
662 scan
->quiet_plcp_th
= cpu_to_le16(IWL_PLCP_QUIET_THRESH
);
663 scan
->good_CRC_th
= IWL_GOOD_CRC_TH_DEFAULT
;
664 scan
->rx_chain
= iwl_mvm_scan_rx_chain(mvm
);
666 scan
->max_out_time
= cpu_to_le32(params
->max_out_time
);
667 scan
->suspend_time
= cpu_to_le32(params
->suspend_time
);
669 scan
->filter_flags
|= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
670 MAC_FILTER_IN_BEACON
);
671 scan
->scan_type
= cpu_to_le32(SCAN_TYPE_BACKGROUND
);
672 scan
->rep_count
= cpu_to_le32(1);
674 if (params
->passive_fragmented
)
675 scan
->scan_flags
|= SCAN_FLAGS_FRAGMENTED_SCAN
;
678 static int iwl_ssid_exist(u8
*ssid
, u8 ssid_len
, struct iwl_ssid_ie
*ssid_list
)
682 for (i
= 0; i
< PROBE_OPTION_MAX
; i
++) {
683 if (!ssid_list
[i
].len
)
685 if (ssid_list
[i
].len
== ssid_len
&&
686 !memcmp(ssid_list
->ssid
, ssid
, ssid_len
))
692 static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request
*req
,
693 struct iwl_ssid_ie
*direct_scan
,
694 u32
*ssid_bitmap
, bool basic_ssid
)
700 * copy SSIDs from match list.
701 * iwl_config_sched_scan_profiles() uses the order of these ssids to
704 for (i
= 0; i
< req
->n_match_sets
&& i
< PROBE_OPTION_MAX
; i
++) {
705 /* skip empty SSID matchsets */
706 if (!req
->match_sets
[i
].ssid
.ssid_len
)
708 direct_scan
[i
].id
= WLAN_EID_SSID
;
709 direct_scan
[i
].len
= req
->match_sets
[i
].ssid
.ssid_len
;
710 memcpy(direct_scan
[i
].ssid
, req
->match_sets
[i
].ssid
.ssid
,
714 /* add SSIDs from scan SSID list */
716 for (j
= 0; j
< req
->n_ssids
&& i
< PROBE_OPTION_MAX
; j
++) {
717 index
= iwl_ssid_exist(req
->ssids
[j
].ssid
,
718 req
->ssids
[j
].ssid_len
,
721 if (!req
->ssids
[j
].ssid_len
&& basic_ssid
)
723 direct_scan
[i
].id
= WLAN_EID_SSID
;
724 direct_scan
[i
].len
= req
->ssids
[j
].ssid_len
;
725 memcpy(direct_scan
[i
].ssid
, req
->ssids
[j
].ssid
,
727 *ssid_bitmap
|= BIT(i
+ 1);
730 *ssid_bitmap
|= BIT(index
+ 1);
735 static void iwl_build_channel_cfg(struct iwl_mvm
*mvm
,
736 struct cfg80211_sched_scan_request
*req
,
738 enum ieee80211_band band
,
741 struct iwl_mvm_scan_params
*params
)
743 u32 n_channels
= mvm
->fw
->ucode_capa
.n_scan_channels
;
744 __le32
*type
= (__le32
*)channels_buffer
;
745 __le16
*channel_number
= (__le16
*)(type
+ n_channels
);
746 __le16
*iter_count
= channel_number
+ n_channels
;
747 __le32
*iter_interval
= (__le32
*)(iter_count
+ n_channels
);
748 u8
*active_dwell
= (u8
*)(iter_interval
+ n_channels
);
749 u8
*passive_dwell
= active_dwell
+ n_channels
;
752 for (i
= 0; i
< req
->n_channels
; i
++) {
753 struct ieee80211_channel
*chan
= req
->channels
[i
];
755 if (chan
->band
!= band
)
761 channel_number
[index
] = cpu_to_le16(chan
->hw_value
);
762 active_dwell
[index
] = params
->dwell
[band
].active
;
763 passive_dwell
[index
] = params
->dwell
[band
].passive
;
765 iter_count
[index
] = cpu_to_le16(1);
766 iter_interval
[index
] = 0;
768 if (!(chan
->flags
& IEEE80211_CHAN_NO_IR
))
770 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE
);
772 type
[index
] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL
|
773 IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL
);
775 if (chan
->flags
& IEEE80211_CHAN_NO_HT40
)
777 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW
);
779 /* scan for all SSIDs from req->ssids */
780 type
[index
] |= cpu_to_le32(ssid_bitmap
);
784 int iwl_mvm_config_sched_scan(struct iwl_mvm
*mvm
,
785 struct ieee80211_vif
*vif
,
786 struct cfg80211_sched_scan_request
*req
,
787 struct ieee80211_scan_ies
*ies
)
789 int band_2ghz
= mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
;
790 int band_5ghz
= mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
;
796 bool basic_ssid
= !(mvm
->fw
->ucode_capa
.flags
&
797 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID
);
799 struct iwl_scan_offload_cfg
*scan_cfg
;
800 struct iwl_host_cmd cmd
= {
801 .id
= SCAN_OFFLOAD_CONFIG_CMD
,
803 struct iwl_mvm_scan_params params
= {};
805 lockdep_assert_held(&mvm
->mutex
);
807 cmd_len
= sizeof(struct iwl_scan_offload_cfg
) +
808 mvm
->fw
->ucode_capa
.n_scan_channels
* IWL_SCAN_CHAN_SIZE
+
809 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE
;
811 scan_cfg
= kzalloc(cmd_len
, GFP_KERNEL
);
815 probes
= scan_cfg
->data
+
816 mvm
->fw
->ucode_capa
.n_scan_channels
* IWL_SCAN_CHAN_SIZE
;
818 iwl_mvm_scan_calc_params(mvm
, vif
, req
->n_ssids
, 0, ¶ms
);
819 iwl_build_scan_cmd(mvm
, vif
, req
, &scan_cfg
->scan_cmd
, ¶ms
);
820 scan_cfg
->scan_cmd
.len
= cpu_to_le16(cmd_len
);
822 iwl_scan_offload_build_ssid(req
, scan_cfg
->scan_cmd
.direct_scan
,
823 &ssid_bitmap
, basic_ssid
);
824 /* build tx frames for supported bands */
826 iwl_scan_offload_build_tx_cmd(mvm
, vif
, ies
,
828 &scan_cfg
->scan_cmd
.tx_cmd
[0],
830 iwl_build_channel_cfg(mvm
, req
, scan_cfg
->data
,
831 IEEE80211_BAND_2GHZ
, &head
,
832 ssid_bitmap
, ¶ms
);
835 iwl_scan_offload_build_tx_cmd(mvm
, vif
, ies
,
837 &scan_cfg
->scan_cmd
.tx_cmd
[1],
839 SCAN_OFFLOAD_PROBE_REQ_SIZE
);
840 iwl_build_channel_cfg(mvm
, req
, scan_cfg
->data
,
841 IEEE80211_BAND_5GHZ
, &head
,
842 ssid_bitmap
, ¶ms
);
845 cmd
.data
[0] = scan_cfg
;
846 cmd
.len
[0] = cmd_len
;
847 cmd
.dataflags
[0] = IWL_HCMD_DFL_NOCOPY
;
849 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan config\n");
851 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
856 int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm
*mvm
,
857 struct cfg80211_sched_scan_request
*req
)
859 struct iwl_scan_offload_profile
*profile
;
860 struct iwl_scan_offload_profile_cfg
*profile_cfg
;
861 struct iwl_scan_offload_blacklist
*blacklist
;
862 struct iwl_host_cmd cmd
= {
863 .id
= SCAN_OFFLOAD_UPDATE_PROFILES_CMD
,
864 .len
[1] = sizeof(*profile_cfg
),
865 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
866 .dataflags
[1] = IWL_HCMD_DFL_NOCOPY
,
872 if (WARN_ON(req
->n_match_sets
> IWL_SCAN_MAX_PROFILES
))
875 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SHORT_BL
)
876 blacklist_len
= IWL_SCAN_SHORT_BLACKLIST_LEN
;
878 blacklist_len
= IWL_SCAN_MAX_BLACKLIST_LEN
;
880 blacklist
= kzalloc(sizeof(*blacklist
) * blacklist_len
, GFP_KERNEL
);
884 profile_cfg
= kzalloc(sizeof(*profile_cfg
), GFP_KERNEL
);
890 cmd
.data
[0] = blacklist
;
891 cmd
.len
[0] = sizeof(*blacklist
) * blacklist_len
;
892 cmd
.data
[1] = profile_cfg
;
894 /* No blacklist configuration */
896 profile_cfg
->num_profiles
= req
->n_match_sets
;
897 profile_cfg
->active_clients
= SCAN_CLIENT_SCHED_SCAN
;
898 profile_cfg
->pass_match
= SCAN_CLIENT_SCHED_SCAN
;
899 profile_cfg
->match_notify
= SCAN_CLIENT_SCHED_SCAN
;
900 if (!req
->n_match_sets
|| !req
->match_sets
[0].ssid
.ssid_len
)
901 profile_cfg
->any_beacon_notify
= SCAN_CLIENT_SCHED_SCAN
;
903 for (i
= 0; i
< req
->n_match_sets
; i
++) {
904 profile
= &profile_cfg
->profiles
[i
];
905 profile
->ssid_index
= i
;
906 /* Support any cipher and auth algorithm */
907 profile
->unicast_cipher
= 0xff;
908 profile
->auth_alg
= 0xff;
909 profile
->network_type
= IWL_NETWORK_TYPE_ANY
;
910 profile
->band_selection
= IWL_SCAN_OFFLOAD_SELECT_ANY
;
911 profile
->client_bitmap
= SCAN_CLIENT_SCHED_SCAN
;
914 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan profile config\n");
916 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
924 int iwl_mvm_sched_scan_start(struct iwl_mvm
*mvm
,
925 struct cfg80211_sched_scan_request
*req
)
927 struct iwl_scan_offload_req scan_req
= {
928 .watchdog
= IWL_SCHED_SCAN_WATCHDOG
,
930 .schedule_line
[0].iterations
= IWL_FAST_SCHED_SCAN_ITERATIONS
,
931 .schedule_line
[0].delay
= cpu_to_le16(req
->interval
/ 1000),
932 .schedule_line
[0].full_scan_mul
= 1,
934 .schedule_line
[1].iterations
= 0xff,
935 .schedule_line
[1].delay
= cpu_to_le16(req
->interval
/ 1000),
936 .schedule_line
[1].full_scan_mul
= IWL_FULL_SCAN_MULTIPLIER
,
939 if (req
->n_match_sets
&& req
->match_sets
[0].ssid
.ssid_len
) {
941 "Sending scheduled scan with filtering, filter len %d\n",
945 "Sending Scheduled scan without filtering\n");
946 scan_req
.flags
|= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL
);
949 if (mvm
->last_ebs_successful
&&
950 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_EBS_SUPPORT
)
952 cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE
);
954 return iwl_mvm_send_cmd_pdu(mvm
, SCAN_OFFLOAD_REQUEST_CMD
, 0,
955 sizeof(scan_req
), &scan_req
);
958 static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm
*mvm
)
961 struct iwl_host_cmd cmd
= {
962 .id
= SCAN_OFFLOAD_ABORT_CMD
,
966 /* Exit instantly with error when device is not ready
967 * to receive scan abort command or it does not perform
968 * scheduled scan currently */
969 if (mvm
->scan_status
!= IWL_MVM_SCAN_SCHED
&&
970 (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
) ||
971 mvm
->scan_status
!= IWL_MVM_SCAN_OS
))
974 ret
= iwl_mvm_send_cmd_status(mvm
, &cmd
, &status
);
978 if (status
!= CAN_ABORT_STATUS
) {
980 * The scan abort will return 1 for success or
981 * 2 for "failure". A failure condition can be
982 * due to simply not being in an active scan which
983 * can occur if we send the scan abort before the
984 * microcode has notified us that a scan is completed.
986 IWL_DEBUG_SCAN(mvm
, "SCAN OFFLOAD ABORT ret %d.\n", status
);
993 int iwl_mvm_scan_offload_stop(struct iwl_mvm
*mvm
, bool notify
)
996 struct iwl_notification_wait wait_scan_done
;
997 static const u8 scan_done_notif
[] = { SCAN_OFFLOAD_COMPLETE
, };
998 bool sched
= mvm
->scan_status
== IWL_MVM_SCAN_SCHED
;
1000 lockdep_assert_held(&mvm
->mutex
);
1002 if (mvm
->scan_status
!= IWL_MVM_SCAN_SCHED
&&
1003 (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
) ||
1004 mvm
->scan_status
!= IWL_MVM_SCAN_OS
)) {
1005 IWL_DEBUG_SCAN(mvm
, "No scan to stop\n");
1009 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
1011 ARRAY_SIZE(scan_done_notif
),
1014 ret
= iwl_mvm_send_scan_offload_abort(mvm
);
1016 IWL_DEBUG_SCAN(mvm
, "Send stop %sscan failed %d\n",
1017 sched
? "offloaded " : "", ret
);
1018 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_done
);
1022 IWL_DEBUG_SCAN(mvm
, "Successfully sent stop %sscan\n",
1023 sched
? "offloaded " : "");
1025 ret
= iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_done
, 1 * HZ
);
1030 * Clear the scan status so the next scan requests will succeed. This
1031 * also ensures the Rx handler doesn't do anything, as the scan was
1032 * stopped from above.
1034 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1038 ieee80211_sched_scan_stopped(mvm
->hw
);
1040 ieee80211_scan_completed(mvm
->hw
, true);
1046 static void iwl_mvm_unified_scan_fill_tx_cmd(struct iwl_mvm
*mvm
,
1047 struct iwl_scan_req_tx_cmd
*tx_cmd
,
1050 tx_cmd
[0].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
1052 tx_cmd
[0].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
1053 IEEE80211_BAND_2GHZ
,
1055 tx_cmd
[0].sta_id
= mvm
->aux_sta
.sta_id
;
1057 tx_cmd
[1].tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
1059 tx_cmd
[1].rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
,
1060 IEEE80211_BAND_5GHZ
,
1062 tx_cmd
[1].sta_id
= mvm
->aux_sta
.sta_id
;
1066 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm
*mvm
,
1067 struct ieee80211_channel
**channels
,
1068 int n_channels
, u32 ssid_bitmap
,
1069 struct iwl_scan_req_unified_lmac
*cmd
)
1071 struct iwl_scan_channel_cfg_lmac
*channel_cfg
= (void *)&cmd
->data
;
1074 for (i
= 0; i
< n_channels
; i
++) {
1075 channel_cfg
[i
].channel_num
=
1076 cpu_to_le16(channels
[i
]->hw_value
);
1077 channel_cfg
[i
].iter_count
= cpu_to_le16(1);
1078 channel_cfg
[i
].iter_interval
= 0;
1079 channel_cfg
[i
].flags
=
1080 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL
|
1086 iwl_mvm_build_unified_scan_probe(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
1087 struct ieee80211_scan_ies
*ies
,
1088 struct iwl_scan_req_unified_lmac
*cmd
)
1090 struct iwl_scan_probe_req
*preq
= (void *)(cmd
->data
+
1091 sizeof(struct iwl_scan_channel_cfg_lmac
) *
1092 mvm
->fw
->ucode_capa
.n_scan_channels
);
1093 struct ieee80211_mgmt
*frame
= (struct ieee80211_mgmt
*)preq
->buf
;
1096 frame
->frame_control
= cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
);
1097 eth_broadcast_addr(frame
->da
);
1098 memcpy(frame
->sa
, vif
->addr
, ETH_ALEN
);
1099 eth_broadcast_addr(frame
->bssid
);
1100 frame
->seq_ctrl
= 0;
1102 pos
= frame
->u
.probe_req
.variable
;
1103 *pos
++ = WLAN_EID_SSID
;
1106 preq
->mac_header
.offset
= 0;
1107 preq
->mac_header
.len
= cpu_to_le16(24 + 2);
1109 memcpy(pos
, ies
->ies
[IEEE80211_BAND_2GHZ
],
1110 ies
->len
[IEEE80211_BAND_2GHZ
]);
1111 preq
->band_data
[0].offset
= cpu_to_le16(pos
- preq
->buf
);
1112 preq
->band_data
[0].len
= cpu_to_le16(ies
->len
[IEEE80211_BAND_2GHZ
]);
1113 pos
+= ies
->len
[IEEE80211_BAND_2GHZ
];
1115 memcpy(pos
, ies
->ies
[IEEE80211_BAND_5GHZ
],
1116 ies
->len
[IEEE80211_BAND_5GHZ
]);
1117 preq
->band_data
[1].offset
= cpu_to_le16(pos
- preq
->buf
);
1118 preq
->band_data
[1].len
= cpu_to_le16(ies
->len
[IEEE80211_BAND_5GHZ
]);
1119 pos
+= ies
->len
[IEEE80211_BAND_5GHZ
];
1121 memcpy(pos
, ies
->common_ies
, ies
->common_ie_len
);
1122 preq
->common_data
.offset
= cpu_to_le16(pos
- preq
->buf
);
1123 preq
->common_data
.len
= cpu_to_le16(ies
->common_ie_len
);
1127 iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm
*mvm
,
1128 struct iwl_scan_req_unified_lmac
*cmd
,
1129 struct iwl_mvm_scan_params
*params
)
1131 memset(cmd
, 0, ksize(cmd
));
1132 cmd
->active_dwell
= params
->dwell
[IEEE80211_BAND_2GHZ
].active
;
1133 cmd
->passive_dwell
= params
->dwell
[IEEE80211_BAND_2GHZ
].passive
;
1134 if (params
->passive_fragmented
)
1135 cmd
->fragmented_dwell
=
1136 params
->dwell
[IEEE80211_BAND_2GHZ
].passive
;
1137 cmd
->rx_chain_select
= iwl_mvm_scan_rx_chain(mvm
);
1138 cmd
->max_out_time
= cpu_to_le32(params
->max_out_time
);
1139 cmd
->suspend_time
= cpu_to_le32(params
->suspend_time
);
1140 cmd
->scan_prio
= cpu_to_le32(IWL_SCAN_PRIORITY_HIGH
);
1141 cmd
->iter_num
= cpu_to_le32(1);
1143 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_EBS_SUPPORT
&&
1144 mvm
->last_ebs_successful
) {
1145 cmd
->channel_opt
[0].flags
=
1146 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
1147 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1148 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
1149 cmd
->channel_opt
[1].flags
=
1150 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS
|
1151 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE
|
1152 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD
);
1156 int iwl_mvm_unified_scan_lmac(struct iwl_mvm
*mvm
,
1157 struct ieee80211_vif
*vif
,
1158 struct ieee80211_scan_request
*req
)
1160 struct iwl_host_cmd hcmd
= {
1161 .id
= SCAN_OFFLOAD_REQUEST_CMD
,
1162 .len
= { sizeof(struct iwl_scan_req_unified_lmac
) +
1163 sizeof(struct iwl_scan_channel_cfg_lmac
) *
1164 mvm
->fw
->ucode_capa
.n_scan_channels
+
1165 sizeof(struct iwl_scan_probe_req
), },
1166 .data
= { mvm
->scan_cmd
, },
1167 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
1169 struct iwl_scan_req_unified_lmac
*cmd
= mvm
->scan_cmd
;
1170 struct iwl_mvm_scan_params params
= {};
1172 int ssid_bitmap
= 0;
1175 lockdep_assert_held(&mvm
->mutex
);
1177 /* we should have failed registration if scan_cmd was NULL */
1178 if (WARN_ON(mvm
->scan_cmd
== NULL
))
1181 if (WARN_ON_ONCE(req
->req
.n_ssids
> PROBE_OPTION_MAX
||
1182 req
->ies
.common_ie_len
+ req
->ies
.len
[0] +
1183 req
->ies
.len
[1] + 24 + 2 >
1184 SCAN_OFFLOAD_PROBE_REQ_SIZE
||
1185 req
->req
.n_channels
>
1186 mvm
->fw
->ucode_capa
.n_scan_channels
))
1189 mvm
->scan_status
= IWL_MVM_SCAN_OS
;
1191 iwl_mvm_scan_calc_params(mvm
, vif
, req
->req
.n_ssids
, req
->req
.flags
,
1194 iwl_mvm_build_generic_unified_scan_cmd(mvm
, cmd
, ¶ms
);
1196 cmd
->n_channels
= (u8
)req
->req
.n_channels
;
1198 flags
= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL
;
1200 if (req
->req
.n_ssids
== 1 && req
->req
.ssids
[0].ssid_len
!= 0)
1201 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION
;
1203 if (params
.passive_fragmented
)
1204 flags
|= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED
;
1206 if (req
->req
.n_ssids
== 0)
1207 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE
;
1209 cmd
->scan_flags
= cpu_to_le32(flags
);
1211 cmd
->flags
= iwl_mvm_scan_rxon_flags(req
->req
.channels
[0]->band
);
1212 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
1213 MAC_FILTER_IN_BEACON
);
1214 iwl_mvm_unified_scan_fill_tx_cmd(mvm
, cmd
->tx_cmd
, req
->req
.no_cck
);
1215 iwl_mvm_scan_fill_ssids(cmd
->direct_scan
, req
->req
.ssids
,
1216 req
->req
.n_ssids
, 0);
1218 cmd
->schedule
[0].delay
= 0;
1219 cmd
->schedule
[0].iterations
= 1;
1220 cmd
->schedule
[0].full_scan_mul
= 0;
1221 cmd
->schedule
[1].delay
= 0;
1222 cmd
->schedule
[1].iterations
= 0;
1223 cmd
->schedule
[1].full_scan_mul
= 0;
1225 for (i
= 1; i
<= req
->req
.n_ssids
; i
++)
1226 ssid_bitmap
|= BIT(i
);
1228 iwl_mvm_lmac_scan_cfg_channels(mvm
, req
->req
.channels
,
1229 req
->req
.n_channels
, ssid_bitmap
,
1232 iwl_mvm_build_unified_scan_probe(mvm
, vif
, &req
->ies
, cmd
);
1234 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1236 IWL_DEBUG_SCAN(mvm
, "Scan request was sent successfully\n");
1239 * If the scan failed, it usually means that the FW was unable
1240 * to allocate the time events. Warn on it, but maybe we
1241 * should try to send the command again with different params.
1243 IWL_ERR(mvm
, "Scan failed! ret %d\n", ret
);
1244 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1250 int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm
*mvm
,
1251 struct ieee80211_vif
*vif
,
1252 struct cfg80211_sched_scan_request
*req
,
1253 struct ieee80211_scan_ies
*ies
)
1255 struct iwl_host_cmd hcmd
= {
1256 .id
= SCAN_OFFLOAD_REQUEST_CMD
,
1257 .len
= { sizeof(struct iwl_scan_req_unified_lmac
) +
1258 sizeof(struct iwl_scan_channel_cfg_lmac
) *
1259 mvm
->fw
->ucode_capa
.n_scan_channels
+
1260 sizeof(struct iwl_scan_probe_req
), },
1261 .data
= { mvm
->scan_cmd
, },
1262 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
1264 struct iwl_scan_req_unified_lmac
*cmd
= mvm
->scan_cmd
;
1265 struct iwl_mvm_scan_params params
= {};
1267 u32 flags
= 0, ssid_bitmap
= 0;
1269 lockdep_assert_held(&mvm
->mutex
);
1271 /* we should have failed registration if scan_cmd was NULL */
1272 if (WARN_ON(mvm
->scan_cmd
== NULL
))
1275 if (WARN_ON_ONCE(req
->n_ssids
> PROBE_OPTION_MAX
||
1276 ies
->common_ie_len
+ ies
->len
[0] + ies
->len
[1] + 24 + 2
1277 > SCAN_OFFLOAD_PROBE_REQ_SIZE
||
1278 req
->n_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
))
1281 iwl_mvm_scan_calc_params(mvm
, vif
, req
->n_ssids
, 0, ¶ms
);
1283 iwl_mvm_build_generic_unified_scan_cmd(mvm
, cmd
, ¶ms
);
1285 cmd
->n_channels
= (u8
)req
->n_channels
;
1287 if (req
->n_match_sets
&& req
->match_sets
[0].ssid
.ssid_len
) {
1289 "Sending scheduled scan with filtering, n_match_sets %d\n",
1293 "Sending Scheduled scan without filtering\n");
1294 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL
;
1297 if (req
->n_ssids
== 1 && req
->ssids
[0].ssid_len
!= 0)
1298 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION
;
1300 if (params
.passive_fragmented
)
1301 flags
|= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED
;
1303 if (req
->n_ssids
== 0)
1304 flags
|= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE
;
1306 cmd
->scan_flags
= cpu_to_le32(flags
);
1308 cmd
->flags
= iwl_mvm_scan_rxon_flags(req
->channels
[0]->band
);
1309 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
1310 MAC_FILTER_IN_BEACON
);
1311 iwl_mvm_unified_scan_fill_tx_cmd(mvm
, cmd
->tx_cmd
, false);
1312 iwl_scan_offload_build_ssid(req
, cmd
->direct_scan
, &ssid_bitmap
, false);
1314 cmd
->schedule
[0].delay
= cpu_to_le16(req
->interval
/ MSEC_PER_SEC
);
1315 cmd
->schedule
[0].iterations
= IWL_FAST_SCHED_SCAN_ITERATIONS
;
1316 cmd
->schedule
[0].full_scan_mul
= 1;
1318 cmd
->schedule
[1].delay
= cpu_to_le16(req
->interval
/ MSEC_PER_SEC
);
1319 cmd
->schedule
[1].iterations
= 0xff;
1320 cmd
->schedule
[1].full_scan_mul
= IWL_FULL_SCAN_MULTIPLIER
;
1322 iwl_mvm_lmac_scan_cfg_channels(mvm
, req
->channels
, req
->n_channels
,
1325 iwl_mvm_build_unified_scan_probe(mvm
, vif
, ies
, cmd
);
1327 ret
= iwl_mvm_send_cmd(mvm
, &hcmd
);
1330 "Sched scan request was sent successfully\n");
1333 * If the scan failed, it usually means that the FW was unable
1334 * to allocate the time events. Warn on it, but maybe we
1335 * should try to send the command again with different params.
1337 IWL_ERR(mvm
, "Sched scan failed! ret %d\n", ret
);
1338 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1345 int iwl_mvm_cancel_scan(struct iwl_mvm
*mvm
)
1347 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
)
1348 return iwl_mvm_scan_offload_stop(mvm
, true);
1349 return iwl_mvm_cancel_regular_scan(mvm
);