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
);
101 iwl_mvm_scan_rxon_flags(struct cfg80211_scan_request
*req
)
103 if (req
->channels
[0]->band
== IEEE80211_BAND_2GHZ
)
104 return cpu_to_le32(PHY_BAND_24
);
106 return cpu_to_le32(PHY_BAND_5
);
110 iwl_mvm_scan_rate_n_flags(struct iwl_mvm
*mvm
, enum ieee80211_band band
,
115 mvm
->scan_last_antenna_idx
=
116 iwl_mvm_next_antenna(mvm
, mvm
->fw
->valid_tx_ant
,
117 mvm
->scan_last_antenna_idx
);
118 tx_ant
= BIT(mvm
->scan_last_antenna_idx
) << RATE_MCS_ANT_POS
;
120 if (band
== IEEE80211_BAND_2GHZ
&& !no_cck
)
121 return cpu_to_le32(IWL_RATE_1M_PLCP
| RATE_MCS_CCK_MSK
|
124 return cpu_to_le32(IWL_RATE_6M_PLCP
| tx_ant
);
128 * We insert the SSIDs in an inverted order, because the FW will
129 * invert it back. The most prioritized SSID, which is first in the
130 * request list, is not copied here, but inserted directly to the probe
133 static void iwl_mvm_scan_fill_ssids(struct iwl_scan_cmd
*cmd
,
134 struct cfg80211_scan_request
*req
,
139 for (req_idx
= req
->n_ssids
- 1, fw_idx
= 0; req_idx
>= first
;
140 req_idx
--, fw_idx
++) {
141 cmd
->direct_scan
[fw_idx
].id
= WLAN_EID_SSID
;
142 cmd
->direct_scan
[fw_idx
].len
= req
->ssids
[req_idx
].ssid_len
;
143 memcpy(cmd
->direct_scan
[fw_idx
].ssid
,
144 req
->ssids
[req_idx
].ssid
,
145 req
->ssids
[req_idx
].ssid_len
);
150 * If req->n_ssids > 0, it means we should do an active scan.
151 * In case of active scan w/o directed scan, we receive a zero-length SSID
152 * just to notify that this scan is active and not passive.
153 * In order to notify the FW of the number of SSIDs we wish to scan (including
154 * the zero-length one), we need to set the corresponding bits in chan->type,
155 * one for each SSID, and set the active bit (first). If the first SSID is
156 * already included in the probe template, so we need to set only
157 * req->n_ssids - 1 bits in addition to the first bit.
159 static u16
iwl_mvm_get_active_dwell(enum ieee80211_band band
, int n_ssids
)
161 if (band
== IEEE80211_BAND_2GHZ
)
162 return 30 + 3 * (n_ssids
+ 1);
163 return 20 + 2 * (n_ssids
+ 1);
166 static u16
iwl_mvm_get_passive_dwell(enum ieee80211_band band
)
168 return band
== IEEE80211_BAND_2GHZ
? 100 + 20 : 100 + 10;
171 static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd
*cmd
,
172 struct cfg80211_scan_request
*req
,
174 struct iwl_mvm_scan_params
*params
)
176 struct iwl_scan_channel
*chan
= (struct iwl_scan_channel
*)
177 (cmd
->data
+ le16_to_cpu(cmd
->tx_cmd
.len
));
179 int type
= BIT(req
->n_ssids
) - 1;
180 enum ieee80211_band band
= req
->channels
[0]->band
;
183 type
|= BIT(req
->n_ssids
);
185 for (i
= 0; i
< cmd
->channel_count
; i
++) {
186 chan
->channel
= cpu_to_le16(req
->channels
[i
]->hw_value
);
187 chan
->type
= cpu_to_le32(type
);
188 if (req
->channels
[i
]->flags
& IEEE80211_CHAN_NO_IR
)
189 chan
->type
&= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE
);
190 chan
->active_dwell
= cpu_to_le16(params
->dwell
[band
].active
);
191 chan
->passive_dwell
= cpu_to_le16(params
->dwell
[band
].passive
);
192 chan
->iteration_count
= cpu_to_le16(1);
198 * Fill in probe request with the following parameters:
199 * TA is our vif HW address, which mac80211 ensures we have.
200 * Packet is broadcasted, so this is both SA and DA.
201 * The probe request IE is made out of two: first comes the most prioritized
202 * SSID if a directed scan is requested. Second comes whatever extra
203 * information was given to us as the scan request IE.
205 static u16
iwl_mvm_fill_probe_req(struct ieee80211_mgmt
*frame
, const u8
*ta
,
206 int n_ssids
, const u8
*ssid
, int ssid_len
,
207 const u8
*ie
, int 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
< ie_len
))
251 memcpy(pos
, ie
, ie_len
);
258 static void iwl_mvm_scan_condition_iterator(void *data
, u8
*mac
,
259 struct ieee80211_vif
*vif
)
261 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
262 bool *global_bound
= data
;
264 if (mvmvif
->phy_ctxt
&& mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
265 *global_bound
= true;
268 static void iwl_mvm_scan_calc_params(struct iwl_mvm
*mvm
,
269 struct ieee80211_vif
*vif
,
271 struct iwl_mvm_scan_params
*params
)
273 bool global_bound
= false;
274 enum ieee80211_band band
;
276 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
277 IEEE80211_IFACE_ITER_NORMAL
,
278 iwl_mvm_scan_condition_iterator
,
284 params
->suspend_time
= 100;
285 params
->max_out_time
= 600;
287 if (iwl_mvm_low_latency(mvm
)) {
288 params
->suspend_time
= 250;
289 params
->max_out_time
= 250;
294 for (band
= IEEE80211_BAND_2GHZ
; band
< IEEE80211_NUM_BANDS
; band
++) {
295 params
->dwell
[band
].passive
= iwl_mvm_get_passive_dwell(band
);
296 params
->dwell
[band
].active
= iwl_mvm_get_active_dwell(band
,
301 int iwl_mvm_scan_request(struct iwl_mvm
*mvm
,
302 struct ieee80211_vif
*vif
,
303 struct cfg80211_scan_request
*req
)
305 struct iwl_host_cmd hcmd
= {
306 .id
= SCAN_REQUEST_CMD
,
308 .data
= { mvm
->scan_cmd
, },
309 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
311 struct iwl_scan_cmd
*cmd
= mvm
->scan_cmd
;
316 bool basic_ssid
= !(mvm
->fw
->ucode_capa
.flags
&
317 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID
);
318 struct iwl_mvm_scan_params params
= {};
320 lockdep_assert_held(&mvm
->mutex
);
322 /* we should have failed registration if scan_cmd was NULL */
323 if (WARN_ON(mvm
->scan_cmd
== NULL
))
326 IWL_DEBUG_SCAN(mvm
, "Handling mac80211 scan request\n");
327 mvm
->scan_status
= IWL_MVM_SCAN_OS
;
328 memset(cmd
, 0, sizeof(struct iwl_scan_cmd
) +
329 mvm
->fw
->ucode_capa
.max_probe_length
+
330 (MAX_NUM_SCAN_CHANNELS
* sizeof(struct iwl_scan_channel
)));
332 cmd
->channel_count
= (u8
)req
->n_channels
;
333 cmd
->quiet_time
= cpu_to_le16(IWL_ACTIVE_QUIET_TIME
);
334 cmd
->quiet_plcp_th
= cpu_to_le16(IWL_PLCP_QUIET_THRESH
);
335 cmd
->rxchain_sel_flags
= iwl_mvm_scan_rx_chain(mvm
);
337 iwl_mvm_scan_calc_params(mvm
, vif
, req
->n_ssids
, ¶ms
);
338 cmd
->max_out_time
= cpu_to_le32(params
.max_out_time
);
339 cmd
->suspend_time
= cpu_to_le32(params
.suspend_time
);
340 if (params
.passive_fragmented
)
341 cmd
->scan_flags
|= SCAN_FLAGS_FRAGMENTED_SCAN
;
343 cmd
->rxon_flags
= iwl_mvm_scan_rxon_flags(req
);
344 cmd
->filter_flags
= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
345 MAC_FILTER_IN_BEACON
);
347 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
)
348 cmd
->type
= cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED
);
350 cmd
->type
= cpu_to_le32(SCAN_TYPE_FORCED
);
352 cmd
->repeats
= cpu_to_le32(1);
355 * If the user asked for passive scan, don't change to active scan if
356 * you see any activity on the channel - remain passive.
358 if (req
->n_ssids
> 0) {
359 cmd
->passive2active
= cpu_to_le16(1);
360 cmd
->scan_flags
|= SCAN_FLAGS_PASSIVE2ACTIVE
;
362 ssid
= req
->ssids
[0].ssid
;
363 ssid_len
= req
->ssids
[0].ssid_len
;
366 cmd
->passive2active
= 0;
367 cmd
->scan_flags
&= ~SCAN_FLAGS_PASSIVE2ACTIVE
;
370 iwl_mvm_scan_fill_ssids(cmd
, req
, basic_ssid
? 1 : 0);
372 cmd
->tx_cmd
.tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
|
374 cmd
->tx_cmd
.sta_id
= mvm
->aux_sta
.sta_id
;
375 cmd
->tx_cmd
.life_time
= cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE
);
376 cmd
->tx_cmd
.rate_n_flags
=
377 iwl_mvm_scan_rate_n_flags(mvm
, req
->channels
[0]->band
,
381 cpu_to_le16(iwl_mvm_fill_probe_req(
382 (struct ieee80211_mgmt
*)cmd
->data
,
384 req
->n_ssids
, ssid
, ssid_len
,
385 req
->ie
, req
->ie_len
,
386 mvm
->fw
->ucode_capa
.max_probe_length
));
388 iwl_mvm_scan_fill_channels(cmd
, req
, basic_ssid
, ¶ms
);
390 cmd
->len
= cpu_to_le16(sizeof(struct iwl_scan_cmd
) +
391 le16_to_cpu(cmd
->tx_cmd
.len
) +
392 (cmd
->channel_count
* sizeof(struct iwl_scan_channel
)));
393 hcmd
.len
[0] = le16_to_cpu(cmd
->len
);
395 status
= SCAN_RESPONSE_OK
;
396 ret
= iwl_mvm_send_cmd_status(mvm
, &hcmd
, &status
);
397 if (!ret
&& status
== SCAN_RESPONSE_OK
) {
398 IWL_DEBUG_SCAN(mvm
, "Scan request was sent successfully\n");
401 * If the scan failed, it usually means that the FW was unable
402 * to allocate the time events. Warn on it, but maybe we
403 * should try to send the command again with different params.
405 IWL_ERR(mvm
, "Scan failed! status 0x%x ret %d\n",
407 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
413 int iwl_mvm_rx_scan_response(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
,
414 struct iwl_device_cmd
*cmd
)
416 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
417 struct iwl_cmd_response
*resp
= (void *)pkt
->data
;
419 IWL_DEBUG_SCAN(mvm
, "Scan response received. status 0x%x\n",
420 le32_to_cpu(resp
->status
));
424 int iwl_mvm_rx_scan_complete(struct iwl_mvm
*mvm
, struct iwl_rx_cmd_buffer
*rxb
,
425 struct iwl_device_cmd
*cmd
)
427 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
428 struct iwl_scan_complete_notif
*notif
= (void *)pkt
->data
;
430 lockdep_assert_held(&mvm
->mutex
);
432 IWL_DEBUG_SCAN(mvm
, "Scan complete: status=0x%x scanned channels=%d\n",
433 notif
->status
, notif
->scanned_channels
);
435 if (mvm
->scan_status
== IWL_MVM_SCAN_OS
)
436 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
437 ieee80211_scan_completed(mvm
->hw
, notif
->status
!= SCAN_COMP_STATUS_OK
);
439 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
444 int iwl_mvm_rx_sched_scan_results(struct iwl_mvm
*mvm
,
445 struct iwl_rx_cmd_buffer
*rxb
,
446 struct iwl_device_cmd
*cmd
)
448 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
449 struct iwl_sched_scan_results
*notif
= (void *)pkt
->data
;
451 if (notif
->client_bitmap
& SCAN_CLIENT_SCHED_SCAN
) {
452 IWL_DEBUG_SCAN(mvm
, "Scheduled scan results\n");
453 ieee80211_sched_scan_results(mvm
->hw
);
459 static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data
*notif_wait
,
460 struct iwl_rx_packet
*pkt
, void *data
)
462 struct iwl_mvm
*mvm
=
463 container_of(notif_wait
, struct iwl_mvm
, notif_wait
);
464 struct iwl_scan_complete_notif
*notif
;
467 switch (pkt
->hdr
.cmd
) {
469 resp
= (void *)pkt
->data
;
470 if (*resp
== CAN_ABORT_STATUS
) {
472 "Scan can be aborted, wait until completion\n");
477 * If scan cannot be aborted, it means that we had a
478 * SCAN_COMPLETE_NOTIFICATION in the pipe and it called
479 * ieee80211_scan_completed already.
481 IWL_DEBUG_SCAN(mvm
, "Scan cannot be aborted, exit now: %d\n",
485 case SCAN_COMPLETE_NOTIFICATION
:
486 notif
= (void *)pkt
->data
;
487 IWL_DEBUG_SCAN(mvm
, "Scan aborted: status 0x%x\n",
497 int iwl_mvm_cancel_scan(struct iwl_mvm
*mvm
)
499 struct iwl_notification_wait wait_scan_abort
;
500 static const u8 scan_abort_notif
[] = { SCAN_ABORT_CMD
,
501 SCAN_COMPLETE_NOTIFICATION
};
504 if (mvm
->scan_status
== IWL_MVM_SCAN_NONE
)
507 if (iwl_mvm_is_radio_killed(mvm
)) {
508 ieee80211_scan_completed(mvm
->hw
, true);
509 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
510 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
514 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_abort
,
516 ARRAY_SIZE(scan_abort_notif
),
517 iwl_mvm_scan_abort_notif
, NULL
);
519 ret
= iwl_mvm_send_cmd_pdu(mvm
, SCAN_ABORT_CMD
, 0, 0, NULL
);
521 IWL_ERR(mvm
, "Couldn't send SCAN_ABORT_CMD: %d\n", ret
);
522 /* mac80211's state will be cleaned in the nic_restart flow */
523 goto out_remove_notif
;
526 return iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_abort
, HZ
);
529 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_abort
);
533 int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm
*mvm
,
534 struct iwl_rx_cmd_buffer
*rxb
,
535 struct iwl_device_cmd
*cmd
)
537 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
538 struct iwl_scan_offload_complete
*scan_notif
= (void *)pkt
->data
;
540 /* scan status must be locked for proper checking */
541 lockdep_assert_held(&mvm
->mutex
);
544 "Scheduled scan completed, status %s EBS status %s:%d\n",
545 scan_notif
->status
== IWL_SCAN_OFFLOAD_COMPLETED
?
546 "completed" : "aborted", scan_notif
->ebs_status
==
547 IWL_SCAN_EBS_SUCCESS
? "success" : "failed",
548 scan_notif
->ebs_status
);
551 /* only call mac80211 completion if the stop was initiated by FW */
552 if (mvm
->scan_status
== IWL_MVM_SCAN_SCHED
) {
553 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
554 ieee80211_sched_scan_stopped(mvm
->hw
);
557 mvm
->last_ebs_successful
= !scan_notif
->ebs_status
;
562 static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm
*mvm
,
563 struct ieee80211_vif
*vif
,
564 struct ieee80211_sched_scan_ies
*ies
,
565 enum ieee80211_band band
,
566 struct iwl_tx_cmd
*cmd
,
571 cmd
->tx_flags
= cpu_to_le32(TX_CMD_FLG_SEQ_CTL
);
572 cmd
->life_time
= cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE
);
573 cmd
->sta_id
= mvm
->aux_sta
.sta_id
;
575 cmd
->rate_n_flags
= iwl_mvm_scan_rate_n_flags(mvm
, band
, false);
577 cmd_len
= iwl_mvm_fill_probe_req((struct ieee80211_mgmt
*)data
,
580 ies
->ie
[band
], ies
->len
[band
],
581 SCAN_OFFLOAD_PROBE_REQ_SIZE
);
582 cmd
->len
= cpu_to_le16(cmd_len
);
585 static void iwl_build_scan_cmd(struct iwl_mvm
*mvm
,
586 struct ieee80211_vif
*vif
,
587 struct cfg80211_sched_scan_request
*req
,
588 struct iwl_scan_offload_cmd
*scan
,
589 struct iwl_mvm_scan_params
*params
)
591 scan
->channel_count
=
592 mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
+
593 mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
;
594 scan
->quiet_time
= cpu_to_le16(IWL_ACTIVE_QUIET_TIME
);
595 scan
->quiet_plcp_th
= cpu_to_le16(IWL_PLCP_QUIET_THRESH
);
596 scan
->good_CRC_th
= IWL_GOOD_CRC_TH_DEFAULT
;
597 scan
->rx_chain
= iwl_mvm_scan_rx_chain(mvm
);
599 scan
->max_out_time
= cpu_to_le32(params
->max_out_time
);
600 scan
->suspend_time
= cpu_to_le32(params
->suspend_time
);
602 scan
->filter_flags
|= cpu_to_le32(MAC_FILTER_ACCEPT_GRP
|
603 MAC_FILTER_IN_BEACON
);
604 scan
->scan_type
= cpu_to_le32(SCAN_TYPE_BACKGROUND
);
605 scan
->rep_count
= cpu_to_le32(1);
607 if (params
->passive_fragmented
)
608 scan
->scan_flags
|= SCAN_FLAGS_FRAGMENTED_SCAN
;
611 static int iwl_ssid_exist(u8
*ssid
, u8 ssid_len
, struct iwl_ssid_ie
*ssid_list
)
615 for (i
= 0; i
< PROBE_OPTION_MAX
; i
++) {
616 if (!ssid_list
[i
].len
)
618 if (ssid_list
[i
].len
== ssid_len
&&
619 !memcmp(ssid_list
->ssid
, ssid
, ssid_len
))
625 static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request
*req
,
626 struct iwl_scan_offload_cmd
*scan
,
633 * copy SSIDs from match list.
634 * iwl_config_sched_scan_profiles() uses the order of these ssids to
637 for (i
= 0; i
< req
->n_match_sets
&& i
< PROBE_OPTION_MAX
; i
++) {
638 /* skip empty SSID matchsets */
639 if (!req
->match_sets
[i
].ssid
.ssid_len
)
641 scan
->direct_scan
[i
].id
= WLAN_EID_SSID
;
642 scan
->direct_scan
[i
].len
= req
->match_sets
[i
].ssid
.ssid_len
;
643 memcpy(scan
->direct_scan
[i
].ssid
, req
->match_sets
[i
].ssid
.ssid
,
644 scan
->direct_scan
[i
].len
);
647 /* add SSIDs from scan SSID list */
649 for (j
= 0; j
< req
->n_ssids
&& i
< PROBE_OPTION_MAX
; j
++) {
650 index
= iwl_ssid_exist(req
->ssids
[j
].ssid
,
651 req
->ssids
[j
].ssid_len
,
654 if (!req
->ssids
[j
].ssid_len
)
656 scan
->direct_scan
[i
].id
= WLAN_EID_SSID
;
657 scan
->direct_scan
[i
].len
= req
->ssids
[j
].ssid_len
;
658 memcpy(scan
->direct_scan
[i
].ssid
, req
->ssids
[j
].ssid
,
659 scan
->direct_scan
[i
].len
);
660 *ssid_bitmap
|= BIT(i
+ 1);
663 *ssid_bitmap
|= BIT(index
+ 1);
668 static void iwl_build_channel_cfg(struct iwl_mvm
*mvm
,
669 struct cfg80211_sched_scan_request
*req
,
670 struct iwl_scan_channel_cfg
*channels
,
671 enum ieee80211_band band
,
672 int *head
, int *tail
,
674 struct iwl_mvm_scan_params
*params
)
676 struct ieee80211_supported_band
*s_band
;
677 int n_channels
= req
->n_channels
;
682 * We have to configure all supported channels, even if we don't want to
683 * scan on them, but we have to send channels in the order that we want
684 * to scan. So add requested channels to head of the list and others to
687 s_band
= &mvm
->nvm_data
->bands
[band
];
689 for (i
= 0; i
< s_band
->n_channels
&& *head
<= *tail
; i
++) {
691 for (j
= 0; j
< n_channels
; j
++)
692 if (s_band
->channels
[i
].center_freq
==
693 req
->channels
[j
]->center_freq
) {
697 * Channels that came with the request will be
707 channels
->channel_number
[index
] =
708 cpu_to_le16(ieee80211_frequency_to_channel(
709 s_band
->channels
[i
].center_freq
));
710 channels
->dwell_time
[index
][0] = params
->dwell
[band
].active
;
711 channels
->dwell_time
[index
][1] = params
->dwell
[band
].passive
;
713 channels
->iter_count
[index
] = cpu_to_le16(1);
714 channels
->iter_interval
[index
] = 0;
716 if (!(s_band
->channels
[i
].flags
& IEEE80211_CHAN_NO_IR
))
717 channels
->type
[index
] |=
718 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE
);
720 channels
->type
[index
] |=
721 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL
);
723 channels
->type
[index
] |=
724 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL
);
726 if (s_band
->channels
[i
].flags
& IEEE80211_CHAN_NO_HT40
)
727 channels
->type
[index
] |=
728 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW
);
730 /* scan for all SSIDs from req->ssids */
731 channels
->type
[index
] |= cpu_to_le32(ssid_bitmap
);
735 int iwl_mvm_config_sched_scan(struct iwl_mvm
*mvm
,
736 struct ieee80211_vif
*vif
,
737 struct cfg80211_sched_scan_request
*req
,
738 struct ieee80211_sched_scan_ies
*ies
)
740 int band_2ghz
= mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
;
741 int band_5ghz
= mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
;
743 int tail
= band_2ghz
+ band_5ghz
- 1;
748 struct iwl_scan_offload_cfg
*scan_cfg
;
749 struct iwl_host_cmd cmd
= {
750 .id
= SCAN_OFFLOAD_CONFIG_CMD
,
752 struct iwl_mvm_scan_params params
= {};
754 lockdep_assert_held(&mvm
->mutex
);
756 cmd_len
= sizeof(struct iwl_scan_offload_cfg
) +
757 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE
;
759 scan_cfg
= kzalloc(cmd_len
, GFP_KERNEL
);
763 iwl_mvm_scan_calc_params(mvm
, vif
, req
->n_ssids
, ¶ms
);
764 iwl_build_scan_cmd(mvm
, vif
, req
, &scan_cfg
->scan_cmd
, ¶ms
);
765 scan_cfg
->scan_cmd
.len
= cpu_to_le16(cmd_len
);
767 iwl_scan_offload_build_ssid(req
, &scan_cfg
->scan_cmd
, &ssid_bitmap
);
768 /* build tx frames for supported bands */
770 iwl_scan_offload_build_tx_cmd(mvm
, vif
, ies
,
772 &scan_cfg
->scan_cmd
.tx_cmd
[0],
774 iwl_build_channel_cfg(mvm
, req
, &scan_cfg
->channel_cfg
,
775 IEEE80211_BAND_2GHZ
, &head
, &tail
,
776 ssid_bitmap
, ¶ms
);
779 iwl_scan_offload_build_tx_cmd(mvm
, vif
, ies
,
781 &scan_cfg
->scan_cmd
.tx_cmd
[1],
783 SCAN_OFFLOAD_PROBE_REQ_SIZE
);
784 iwl_build_channel_cfg(mvm
, req
, &scan_cfg
->channel_cfg
,
785 IEEE80211_BAND_5GHZ
, &head
, &tail
,
786 ssid_bitmap
, ¶ms
);
789 cmd
.data
[0] = scan_cfg
;
790 cmd
.len
[0] = cmd_len
;
791 cmd
.dataflags
[0] = IWL_HCMD_DFL_NOCOPY
;
793 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan config\n");
795 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
800 int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm
*mvm
,
801 struct cfg80211_sched_scan_request
*req
)
803 struct iwl_scan_offload_profile
*profile
;
804 struct iwl_scan_offload_profile_cfg
*profile_cfg
;
805 struct iwl_scan_offload_blacklist
*blacklist
;
806 struct iwl_host_cmd cmd
= {
807 .id
= SCAN_OFFLOAD_UPDATE_PROFILES_CMD
,
808 .len
[1] = sizeof(*profile_cfg
),
809 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
810 .dataflags
[1] = IWL_HCMD_DFL_NOCOPY
,
816 if (WARN_ON(req
->n_match_sets
> IWL_SCAN_MAX_PROFILES
))
819 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SHORT_BL
)
820 blacklist_len
= IWL_SCAN_SHORT_BLACKLIST_LEN
;
822 blacklist_len
= IWL_SCAN_MAX_BLACKLIST_LEN
;
824 blacklist
= kzalloc(sizeof(*blacklist
) * blacklist_len
, GFP_KERNEL
);
828 profile_cfg
= kzalloc(sizeof(*profile_cfg
), GFP_KERNEL
);
834 cmd
.data
[0] = blacklist
;
835 cmd
.len
[0] = sizeof(*blacklist
) * blacklist_len
;
836 cmd
.data
[1] = profile_cfg
;
838 /* No blacklist configuration */
840 profile_cfg
->num_profiles
= req
->n_match_sets
;
841 profile_cfg
->active_clients
= SCAN_CLIENT_SCHED_SCAN
;
842 profile_cfg
->pass_match
= SCAN_CLIENT_SCHED_SCAN
;
843 profile_cfg
->match_notify
= SCAN_CLIENT_SCHED_SCAN
;
844 if (!req
->n_match_sets
|| !req
->match_sets
[0].ssid
.ssid_len
)
845 profile_cfg
->any_beacon_notify
= SCAN_CLIENT_SCHED_SCAN
;
847 for (i
= 0; i
< req
->n_match_sets
; i
++) {
848 profile
= &profile_cfg
->profiles
[i
];
849 profile
->ssid_index
= i
;
850 /* Support any cipher and auth algorithm */
851 profile
->unicast_cipher
= 0xff;
852 profile
->auth_alg
= 0xff;
853 profile
->network_type
= IWL_NETWORK_TYPE_ANY
;
854 profile
->band_selection
= IWL_SCAN_OFFLOAD_SELECT_ANY
;
855 profile
->client_bitmap
= SCAN_CLIENT_SCHED_SCAN
;
858 IWL_DEBUG_SCAN(mvm
, "Sending scheduled scan profile config\n");
860 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
868 int iwl_mvm_sched_scan_start(struct iwl_mvm
*mvm
,
869 struct cfg80211_sched_scan_request
*req
)
871 struct iwl_scan_offload_req scan_req
= {
872 .watchdog
= IWL_SCHED_SCAN_WATCHDOG
,
874 .schedule_line
[0].iterations
= IWL_FAST_SCHED_SCAN_ITERATIONS
,
875 .schedule_line
[0].delay
= req
->interval
/ 1000,
876 .schedule_line
[0].full_scan_mul
= 1,
878 .schedule_line
[1].iterations
= 0xff,
879 .schedule_line
[1].delay
= req
->interval
/ 1000,
880 .schedule_line
[1].full_scan_mul
= IWL_FULL_SCAN_MULTIPLIER
,
883 if (req
->n_match_sets
&& req
->match_sets
[0].ssid
.ssid_len
) {
885 "Sending scheduled scan with filtering, filter len %d\n",
889 "Sending Scheduled scan without filtering\n");
890 scan_req
.flags
|= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL
);
893 if (mvm
->last_ebs_successful
&&
894 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_EBS_SUPPORT
)
896 cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE
);
898 return iwl_mvm_send_cmd_pdu(mvm
, SCAN_OFFLOAD_REQUEST_CMD
, 0,
899 sizeof(scan_req
), &scan_req
);
902 static int iwl_mvm_send_sched_scan_abort(struct iwl_mvm
*mvm
)
905 struct iwl_host_cmd cmd
= {
906 .id
= SCAN_OFFLOAD_ABORT_CMD
,
910 /* Exit instantly with error when device is not ready
911 * to receive scan abort command or it does not perform
912 * scheduled scan currently */
913 if (mvm
->scan_status
!= IWL_MVM_SCAN_SCHED
)
916 ret
= iwl_mvm_send_cmd_status(mvm
, &cmd
, &status
);
920 if (status
!= CAN_ABORT_STATUS
) {
922 * The scan abort will return 1 for success or
923 * 2 for "failure". A failure condition can be
924 * due to simply not being in an active scan which
925 * can occur if we send the scan abort before the
926 * microcode has notified us that a scan is completed.
928 IWL_DEBUG_SCAN(mvm
, "SCAN OFFLOAD ABORT ret %d.\n", status
);
935 int iwl_mvm_sched_scan_stop(struct iwl_mvm
*mvm
, bool notify
)
938 struct iwl_notification_wait wait_scan_done
;
939 static const u8 scan_done_notif
[] = { SCAN_OFFLOAD_COMPLETE
, };
941 lockdep_assert_held(&mvm
->mutex
);
943 if (mvm
->scan_status
!= IWL_MVM_SCAN_SCHED
) {
944 IWL_DEBUG_SCAN(mvm
, "No offloaded scan to stop\n");
948 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
950 ARRAY_SIZE(scan_done_notif
),
953 ret
= iwl_mvm_send_sched_scan_abort(mvm
);
955 IWL_DEBUG_SCAN(mvm
, "Send stop offload scan failed %d\n", ret
);
956 iwl_remove_notification(&mvm
->notif_wait
, &wait_scan_done
);
960 IWL_DEBUG_SCAN(mvm
, "Successfully sent stop offload scan\n");
962 ret
= iwl_wait_notification(&mvm
->notif_wait
, &wait_scan_done
, 1 * HZ
);
967 * Clear the scan status so the next scan requests will succeed. This
968 * also ensures the Rx handler doesn't do anything, as the scan was
969 * stopped from above.
971 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
974 ieee80211_sched_scan_stopped(mvm
->hw
);