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.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 *****************************************************************************/
66 #include <linux/etherdevice.h>
67 #include <net/mac80211.h>
70 #include "iwl-eeprom-parse.h"
71 #include "fw-api-scan.h"
73 #define IWL_PLCP_QUIET_THRESH 1
74 #define IWL_ACTIVE_QUIET_TIME 10
76 struct iwl_mvm_scan_params {
79 bool passive_fragmented;
83 } dwell[IEEE80211_NUM_BANDS];
86 static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm)
91 if (mvm->scan_rx_ant != ANT_NONE)
92 rx_ant = mvm->scan_rx_ant;
94 rx_ant = mvm->fw->valid_rx_ant;
95 rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS;
96 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS;
97 rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS;
98 rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS;
99 return cpu_to_le16(rx_chain);
102 static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band)
104 if (band == IEEE80211_BAND_2GHZ)
105 return cpu_to_le32(PHY_BAND_24);
107 return cpu_to_le32(PHY_BAND_5);
111 iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band,
116 mvm->scan_last_antenna_idx =
117 iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant,
118 mvm->scan_last_antenna_idx);
119 tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS;
121 if (band == IEEE80211_BAND_2GHZ && !no_cck)
122 return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK |
125 return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant);
129 * We insert the SSIDs in an inverted order, because the FW will
130 * invert it back. The most prioritized SSID, which is first in the
131 * request list, is not copied here, but inserted directly to the probe
134 static void iwl_mvm_scan_fill_ssids(struct iwl_ssid_ie *cmd_ssid,
135 struct cfg80211_ssid *ssids,
136 int n_ssids, int first)
140 for (req_idx = n_ssids - 1, fw_idx = 0; req_idx >= first;
141 req_idx--, fw_idx++) {
142 cmd_ssid[fw_idx].id = WLAN_EID_SSID;
143 cmd_ssid[fw_idx].len = ssids[req_idx].ssid_len;
144 memcpy(cmd_ssid[fw_idx].ssid,
146 ssids[req_idx].ssid_len);
151 * If req->n_ssids > 0, it means we should do an active scan.
152 * In case of active scan w/o directed scan, we receive a zero-length SSID
153 * just to notify that this scan is active and not passive.
154 * In order to notify the FW of the number of SSIDs we wish to scan (including
155 * the zero-length one), we need to set the corresponding bits in chan->type,
156 * one for each SSID, and set the active bit (first). If the first SSID is
157 * already included in the probe template, so we need to set only
158 * req->n_ssids - 1 bits in addition to the first bit.
160 static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids)
162 if (band == IEEE80211_BAND_2GHZ)
163 return 20 + 3 * (n_ssids + 1);
164 return 10 + 2 * (n_ssids + 1);
167 static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band)
169 return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10;
172 static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd,
173 struct cfg80211_scan_request *req,
175 struct iwl_mvm_scan_params *params)
177 struct iwl_scan_channel *chan = (struct iwl_scan_channel *)
178 (cmd->data + le16_to_cpu(cmd->tx_cmd.len));
180 int type = BIT(req->n_ssids) - 1;
181 enum ieee80211_band band = req->channels[0]->band;
184 type |= BIT(req->n_ssids);
186 for (i = 0; i < cmd->channel_count; i++) {
187 chan->channel = cpu_to_le16(req->channels[i]->hw_value);
188 chan->type = cpu_to_le32(type);
189 if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR)
190 chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE);
191 chan->active_dwell = cpu_to_le16(params->dwell[band].active);
192 chan->passive_dwell = cpu_to_le16(params->dwell[band].passive);
193 chan->iteration_count = cpu_to_le16(1);
199 * Fill in probe request with the following parameters:
200 * TA is our vif HW address, which mac80211 ensures we have.
201 * Packet is broadcasted, so this is both SA and DA.
202 * The probe request IE is made out of two: first comes the most prioritized
203 * SSID if a directed scan is requested. Second comes whatever extra
204 * information was given to us as the scan request IE.
206 static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta,
207 int n_ssids, const u8 *ssid, int ssid_len,
208 const u8 *band_ie, int band_ie_len,
209 const u8 *common_ie, int common_ie_len,
215 /* Make sure there is enough space for the probe request,
216 * two mandatory IEs and the data */
221 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
222 eth_broadcast_addr(frame->da);
223 memcpy(frame->sa, ta, ETH_ALEN);
224 eth_broadcast_addr(frame->bssid);
229 /* for passive scans, no need to fill anything */
233 /* points to the payload of the request */
234 pos = &frame->u.probe_req.variable[0];
236 /* fill in our SSID IE */
237 left -= ssid_len + 2;
240 *pos++ = WLAN_EID_SSID;
242 if (ssid && ssid_len) { /* ssid_len may be == 0 even if ssid is valid */
243 memcpy(pos, ssid, ssid_len);
249 if (WARN_ON(left < band_ie_len + common_ie_len))
252 if (band_ie && band_ie_len) {
253 memcpy(pos, band_ie, band_ie_len);
258 if (common_ie && common_ie_len) {
259 memcpy(pos, common_ie, common_ie_len);
260 pos += common_ie_len;
261 len += common_ie_len;
267 static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac,
268 struct ieee80211_vif *vif)
270 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
271 bool *global_bound = data;
273 if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < MAX_PHYS)
274 *global_bound = true;
277 static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm,
278 struct ieee80211_vif *vif,
279 int n_ssids, u32 flags,
280 struct iwl_mvm_scan_params *params)
282 bool global_bound = false;
283 enum ieee80211_band band;
284 u8 frag_passive_dwell = 0;
286 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
287 IEEE80211_IFACE_ITER_NORMAL,
288 iwl_mvm_scan_condition_iterator,
294 params->suspend_time = 30;
295 params->max_out_time = 170;
297 if (iwl_mvm_low_latency(mvm)) {
298 if (mvm->fw->ucode_capa.api[0] &
299 IWL_UCODE_TLV_API_FRAGMENTED_SCAN) {
300 params->suspend_time = 105;
301 params->max_out_time = 70;
302 frag_passive_dwell = 20;
304 params->suspend_time = 120;
305 params->max_out_time = 120;
309 if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] &
310 IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) {
312 * P2P device scan should not be fragmented to avoid negative
313 * impact on P2P device discovery. Configure max_out_time to be
314 * equal to dwell time on passive channel. Take a longest
315 * possible value, one that corresponds to 2GHz band
317 if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
319 iwl_mvm_get_passive_dwell(IEEE80211_BAND_2GHZ);
320 params->max_out_time = passive_dwell;
322 params->passive_fragmented = true;
326 if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
327 params->max_out_time = 200;
331 for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) {
332 if (params->passive_fragmented)
333 params->dwell[band].passive = frag_passive_dwell;
335 params->dwell[band].passive =
336 iwl_mvm_get_passive_dwell(band);
337 params->dwell[band].active = iwl_mvm_get_active_dwell(band,
342 static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm)
344 /* require rrm scan whenever the fw supports it */
345 return mvm->fw->ucode_capa.capa[0] &
346 IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT;
349 static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm,
354 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
355 max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE;
357 max_probe_len = mvm->fw->ucode_capa.max_probe_length;
359 /* we create the 802.11 header and SSID element */
360 max_probe_len -= 24 + 2;
362 /* basic ssid is added only for hw_scan with and old api */
363 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID) &&
364 !(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) &&
368 return max_probe_len;
371 int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm, bool is_sched_scan)
373 int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm, is_sched_scan);
375 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN))
378 /* TODO: [BUG] This function should return the maximum allowed size of
379 * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs
380 * in the same command. So the correct implementation of this function
381 * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan
382 * command has only 512 bytes and it would leave us with about 240
383 * bytes for scan IEs, which is clearly not enough. So meanwhile
384 * we will report an incorrect value. This may result in a failure to
385 * issue a scan in unified_scan_lmac and unified_sched_scan_lmac
386 * functions with -ENOBUFS, if a large enough probe will be provided.
391 int iwl_mvm_scan_request(struct iwl_mvm *mvm,
392 struct ieee80211_vif *vif,
393 struct cfg80211_scan_request *req)
395 struct iwl_host_cmd hcmd = {
396 .id = SCAN_REQUEST_CMD,
398 .data = { mvm->scan_cmd, },
399 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
401 struct iwl_scan_cmd *cmd = mvm->scan_cmd;
406 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
407 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
408 struct iwl_mvm_scan_params params = {};
410 lockdep_assert_held(&mvm->mutex);
412 /* we should have failed registration if scan_cmd was NULL */
413 if (WARN_ON(mvm->scan_cmd == NULL))
416 IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n");
417 mvm->scan_status = IWL_MVM_SCAN_OS;
418 memset(cmd, 0, ksize(cmd));
420 cmd->channel_count = (u8)req->n_channels;
421 cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME);
422 cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH);
423 cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm);
425 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, ¶ms);
426 cmd->max_out_time = cpu_to_le32(params.max_out_time);
427 cmd->suspend_time = cpu_to_le32(params.suspend_time);
428 if (params.passive_fragmented)
429 cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
431 cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band);
432 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
433 MAC_FILTER_IN_BEACON);
435 if (vif->type == NL80211_IFTYPE_P2P_DEVICE)
436 cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED);
438 cmd->type = cpu_to_le32(SCAN_TYPE_FORCED);
440 cmd->repeats = cpu_to_le32(1);
443 * If the user asked for passive scan, don't change to active scan if
444 * you see any activity on the channel - remain passive.
446 if (req->n_ssids > 0) {
447 cmd->passive2active = cpu_to_le16(1);
448 cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE;
450 ssid = req->ssids[0].ssid;
451 ssid_len = req->ssids[0].ssid_len;
454 cmd->passive2active = 0;
455 cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE;
458 iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->ssids, req->n_ssids,
461 cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
462 3 << TX_CMD_FLG_BT_PRIO_POS);
464 cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id;
465 cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
466 cmd->tx_cmd.rate_n_flags =
467 iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band,
471 cpu_to_le16(iwl_mvm_fill_probe_req(
472 (struct ieee80211_mgmt *)cmd->data,
474 req->n_ssids, ssid, ssid_len,
475 req->ie, req->ie_len, NULL, 0,
476 mvm->fw->ucode_capa.max_probe_length));
478 iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, ¶ms);
480 cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) +
481 le16_to_cpu(cmd->tx_cmd.len) +
482 (cmd->channel_count * sizeof(struct iwl_scan_channel)));
483 hcmd.len[0] = le16_to_cpu(cmd->len);
485 status = SCAN_RESPONSE_OK;
486 ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status);
487 if (!ret && status == SCAN_RESPONSE_OK) {
488 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
491 * If the scan failed, it usually means that the FW was unable
492 * to allocate the time events. Warn on it, but maybe we
493 * should try to send the command again with different params.
495 IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n",
497 mvm->scan_status = IWL_MVM_SCAN_NONE;
503 int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
504 struct iwl_device_cmd *cmd)
506 struct iwl_rx_packet *pkt = rxb_addr(rxb);
507 struct iwl_cmd_response *resp = (void *)pkt->data;
509 IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n",
510 le32_to_cpu(resp->status));
514 int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
515 struct iwl_device_cmd *cmd)
517 struct iwl_rx_packet *pkt = rxb_addr(rxb);
518 struct iwl_scan_complete_notif *notif = (void *)pkt->data;
520 lockdep_assert_held(&mvm->mutex);
522 IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n",
523 notif->status, notif->scanned_channels);
525 if (mvm->scan_status == IWL_MVM_SCAN_OS)
526 mvm->scan_status = IWL_MVM_SCAN_NONE;
527 ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK);
529 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
534 int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm,
535 struct iwl_rx_cmd_buffer *rxb,
536 struct iwl_device_cmd *cmd)
538 struct iwl_rx_packet *pkt = rxb_addr(rxb);
539 u8 client_bitmap = 0;
541 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) {
542 struct iwl_sched_scan_results *notif = (void *)pkt->data;
544 client_bitmap = notif->client_bitmap;
547 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN ||
548 client_bitmap & SCAN_CLIENT_SCHED_SCAN) {
549 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
550 IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n");
551 ieee80211_sched_scan_results(mvm->hw);
553 IWL_DEBUG_SCAN(mvm, "Scan results\n");
560 static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait,
561 struct iwl_rx_packet *pkt, void *data)
563 struct iwl_mvm *mvm =
564 container_of(notif_wait, struct iwl_mvm, notif_wait);
565 struct iwl_scan_complete_notif *notif;
568 switch (pkt->hdr.cmd) {
570 resp = (void *)pkt->data;
571 if (*resp == CAN_ABORT_STATUS) {
573 "Scan can be aborted, wait until completion\n");
578 * If scan cannot be aborted, it means that we had a
579 * SCAN_COMPLETE_NOTIFICATION in the pipe and it called
580 * ieee80211_scan_completed already.
582 IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n",
586 case SCAN_COMPLETE_NOTIFICATION:
587 notif = (void *)pkt->data;
588 IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n",
598 static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm)
600 struct iwl_notification_wait wait_scan_abort;
601 static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD,
602 SCAN_COMPLETE_NOTIFICATION };
605 if (mvm->scan_status == IWL_MVM_SCAN_NONE)
608 if (iwl_mvm_is_radio_killed(mvm)) {
609 ieee80211_scan_completed(mvm->hw, true);
610 iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN);
611 mvm->scan_status = IWL_MVM_SCAN_NONE;
615 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort,
617 ARRAY_SIZE(scan_abort_notif),
618 iwl_mvm_scan_abort_notif, NULL);
620 ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, 0, 0, NULL);
622 IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret);
623 /* mac80211's state will be cleaned in the nic_restart flow */
624 goto out_remove_notif;
627 return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ);
630 iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort);
634 int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm,
635 struct iwl_rx_cmd_buffer *rxb,
636 struct iwl_device_cmd *cmd)
638 struct iwl_rx_packet *pkt = rxb_addr(rxb);
639 u8 status, ebs_status;
641 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) {
642 struct iwl_periodic_scan_complete *scan_notif;
644 scan_notif = (void *)pkt->data;
645 status = scan_notif->status;
646 ebs_status = scan_notif->ebs_status;
648 struct iwl_scan_offload_complete *scan_notif;
650 scan_notif = (void *)pkt->data;
651 status = scan_notif->status;
652 ebs_status = scan_notif->ebs_status;
654 /* scan status must be locked for proper checking */
655 lockdep_assert_held(&mvm->mutex);
658 "%s completed, status %s, EBS status %s\n",
659 mvm->scan_status == IWL_MVM_SCAN_SCHED ?
660 "Scheduled scan" : "Scan",
661 status == IWL_SCAN_OFFLOAD_COMPLETED ?
662 "completed" : "aborted",
663 ebs_status == IWL_SCAN_EBS_SUCCESS ?
664 "success" : "failed");
667 /* only call mac80211 completion if the stop was initiated by FW */
668 if (mvm->scan_status == IWL_MVM_SCAN_SCHED) {
669 mvm->scan_status = IWL_MVM_SCAN_NONE;
670 ieee80211_sched_scan_stopped(mvm->hw);
671 } else if (mvm->scan_status == IWL_MVM_SCAN_OS) {
672 mvm->scan_status = IWL_MVM_SCAN_NONE;
673 ieee80211_scan_completed(mvm->hw,
674 status == IWL_SCAN_OFFLOAD_ABORTED);
677 mvm->last_ebs_successful = !ebs_status;
682 static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm,
683 struct ieee80211_vif *vif,
684 struct ieee80211_scan_ies *ies,
685 enum ieee80211_band band,
686 struct iwl_tx_cmd *cmd,
691 cmd->tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL);
692 cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE);
693 cmd->sta_id = mvm->aux_sta.sta_id;
695 cmd->rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, band, false);
697 cmd_len = iwl_mvm_fill_probe_req((struct ieee80211_mgmt *)data,
700 ies->ies[band], ies->len[band],
701 ies->common_ies, ies->common_ie_len,
702 SCAN_OFFLOAD_PROBE_REQ_SIZE);
703 cmd->len = cpu_to_le16(cmd_len);
706 static void iwl_build_scan_cmd(struct iwl_mvm *mvm,
707 struct ieee80211_vif *vif,
708 struct cfg80211_sched_scan_request *req,
709 struct iwl_scan_offload_cmd *scan,
710 struct iwl_mvm_scan_params *params)
712 scan->channel_count = req->n_channels;
713 scan->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME);
714 scan->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH);
715 scan->good_CRC_th = IWL_GOOD_CRC_TH_DEFAULT;
716 scan->rx_chain = iwl_mvm_scan_rx_chain(mvm);
718 scan->max_out_time = cpu_to_le32(params->max_out_time);
719 scan->suspend_time = cpu_to_le32(params->suspend_time);
721 scan->filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
722 MAC_FILTER_IN_BEACON);
723 scan->scan_type = cpu_to_le32(SCAN_TYPE_BACKGROUND);
724 scan->rep_count = cpu_to_le32(1);
726 if (params->passive_fragmented)
727 scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN;
730 static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list)
734 for (i = 0; i < PROBE_OPTION_MAX; i++) {
735 if (!ssid_list[i].len)
737 if (ssid_list[i].len == ssid_len &&
738 !memcmp(ssid_list->ssid, ssid, ssid_len))
744 static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req,
745 struct iwl_ssid_ie *direct_scan,
746 u32 *ssid_bitmap, bool basic_ssid)
752 * copy SSIDs from match list.
753 * iwl_config_sched_scan_profiles() uses the order of these ssids to
756 for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) {
757 /* skip empty SSID matchsets */
758 if (!req->match_sets[i].ssid.ssid_len)
760 direct_scan[i].id = WLAN_EID_SSID;
761 direct_scan[i].len = req->match_sets[i].ssid.ssid_len;
762 memcpy(direct_scan[i].ssid, req->match_sets[i].ssid.ssid,
766 /* add SSIDs from scan SSID list */
768 for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) {
769 index = iwl_ssid_exist(req->ssids[j].ssid,
770 req->ssids[j].ssid_len,
773 if (!req->ssids[j].ssid_len && basic_ssid)
775 direct_scan[i].id = WLAN_EID_SSID;
776 direct_scan[i].len = req->ssids[j].ssid_len;
777 memcpy(direct_scan[i].ssid, req->ssids[j].ssid,
779 *ssid_bitmap |= BIT(i + 1);
782 *ssid_bitmap |= BIT(index + 1);
787 static void iwl_build_channel_cfg(struct iwl_mvm *mvm,
788 struct cfg80211_sched_scan_request *req,
790 enum ieee80211_band band,
793 struct iwl_mvm_scan_params *params)
795 u32 n_channels = mvm->fw->ucode_capa.n_scan_channels;
796 __le32 *type = (__le32 *)channels_buffer;
797 __le16 *channel_number = (__le16 *)(type + n_channels);
798 __le16 *iter_count = channel_number + n_channels;
799 __le32 *iter_interval = (__le32 *)(iter_count + n_channels);
800 u8 *active_dwell = (u8 *)(iter_interval + n_channels);
801 u8 *passive_dwell = active_dwell + n_channels;
804 for (i = 0; i < req->n_channels; i++) {
805 struct ieee80211_channel *chan = req->channels[i];
807 if (chan->band != band)
813 channel_number[index] = cpu_to_le16(chan->hw_value);
814 active_dwell[index] = params->dwell[band].active;
815 passive_dwell[index] = params->dwell[band].passive;
817 iter_count[index] = cpu_to_le16(1);
818 iter_interval[index] = 0;
820 if (!(chan->flags & IEEE80211_CHAN_NO_IR))
822 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE);
824 type[index] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL |
825 IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL);
827 if (chan->flags & IEEE80211_CHAN_NO_HT40)
829 cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW);
831 /* scan for all SSIDs from req->ssids */
832 type[index] |= cpu_to_le32(ssid_bitmap);
836 int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm,
837 struct ieee80211_vif *vif,
838 struct cfg80211_sched_scan_request *req,
839 struct ieee80211_scan_ies *ies)
841 int band_2ghz = mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels;
842 int band_5ghz = mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels;
848 bool basic_ssid = !(mvm->fw->ucode_capa.flags &
849 IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID);
851 struct iwl_scan_offload_cfg *scan_cfg;
852 struct iwl_host_cmd cmd = {
853 .id = SCAN_OFFLOAD_CONFIG_CMD,
855 struct iwl_mvm_scan_params params = {};
857 lockdep_assert_held(&mvm->mutex);
859 cmd_len = sizeof(struct iwl_scan_offload_cfg) +
860 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE +
861 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE;
863 scan_cfg = kzalloc(cmd_len, GFP_KERNEL);
867 probes = scan_cfg->data +
868 mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE;
870 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, ¶ms);
871 iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, ¶ms);
872 scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len);
874 iwl_scan_offload_build_ssid(req, scan_cfg->scan_cmd.direct_scan,
875 &ssid_bitmap, basic_ssid);
876 /* build tx frames for supported bands */
878 iwl_scan_offload_build_tx_cmd(mvm, vif, ies,
880 &scan_cfg->scan_cmd.tx_cmd[0],
882 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
883 IEEE80211_BAND_2GHZ, &head,
884 ssid_bitmap, ¶ms);
887 iwl_scan_offload_build_tx_cmd(mvm, vif, ies,
889 &scan_cfg->scan_cmd.tx_cmd[1],
891 SCAN_OFFLOAD_PROBE_REQ_SIZE);
892 iwl_build_channel_cfg(mvm, req, scan_cfg->data,
893 IEEE80211_BAND_5GHZ, &head,
894 ssid_bitmap, ¶ms);
897 cmd.data[0] = scan_cfg;
898 cmd.len[0] = cmd_len;
899 cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
901 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan config\n");
903 ret = iwl_mvm_send_cmd(mvm, &cmd);
908 int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm,
909 struct cfg80211_sched_scan_request *req)
911 struct iwl_scan_offload_profile *profile;
912 struct iwl_scan_offload_profile_cfg *profile_cfg;
913 struct iwl_scan_offload_blacklist *blacklist;
914 struct iwl_host_cmd cmd = {
915 .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD,
916 .len[1] = sizeof(*profile_cfg),
917 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
918 .dataflags[1] = IWL_HCMD_DFL_NOCOPY,
924 if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES))
927 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL)
928 blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN;
930 blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN;
932 blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL);
936 profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL);
942 cmd.data[0] = blacklist;
943 cmd.len[0] = sizeof(*blacklist) * blacklist_len;
944 cmd.data[1] = profile_cfg;
946 /* No blacklist configuration */
948 profile_cfg->num_profiles = req->n_match_sets;
949 profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN;
950 profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN;
951 profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN;
952 if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len)
953 profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN;
955 for (i = 0; i < req->n_match_sets; i++) {
956 profile = &profile_cfg->profiles[i];
957 profile->ssid_index = i;
958 /* Support any cipher and auth algorithm */
959 profile->unicast_cipher = 0xff;
960 profile->auth_alg = 0xff;
961 profile->network_type = IWL_NETWORK_TYPE_ANY;
962 profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY;
963 profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN;
966 IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n");
968 ret = iwl_mvm_send_cmd(mvm, &cmd);
976 int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm,
977 struct cfg80211_sched_scan_request *req)
979 struct iwl_scan_offload_req scan_req = {
980 .watchdog = IWL_SCHED_SCAN_WATCHDOG,
982 .schedule_line[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS,
983 .schedule_line[0].delay = cpu_to_le16(req->interval / 1000),
984 .schedule_line[0].full_scan_mul = 1,
986 .schedule_line[1].iterations = 0xff,
987 .schedule_line[1].delay = cpu_to_le16(req->interval / 1000),
988 .schedule_line[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER,
991 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
993 "Sending scheduled scan with filtering, filter len %d\n",
997 "Sending Scheduled scan without filtering\n");
998 scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL);
1001 if (mvm->last_ebs_successful &&
1002 mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT)
1004 cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE);
1006 return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0,
1007 sizeof(scan_req), &scan_req);
1010 static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm)
1013 struct iwl_host_cmd cmd = {
1014 .id = SCAN_OFFLOAD_ABORT_CMD,
1018 /* Exit instantly with error when device is not ready
1019 * to receive scan abort command or it does not perform
1020 * scheduled scan currently */
1021 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
1022 (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) ||
1023 mvm->scan_status != IWL_MVM_SCAN_OS))
1026 ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status);
1030 if (status != CAN_ABORT_STATUS) {
1032 * The scan abort will return 1 for success or
1033 * 2 for "failure". A failure condition can be
1034 * due to simply not being in an active scan which
1035 * can occur if we send the scan abort before the
1036 * microcode has notified us that a scan is completed.
1038 IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status);
1045 int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify)
1048 struct iwl_notification_wait wait_scan_done;
1049 static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, };
1050 bool sched = mvm->scan_status == IWL_MVM_SCAN_SCHED;
1052 lockdep_assert_held(&mvm->mutex);
1054 if (mvm->scan_status != IWL_MVM_SCAN_SCHED &&
1055 (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) ||
1056 mvm->scan_status != IWL_MVM_SCAN_OS)) {
1057 IWL_DEBUG_SCAN(mvm, "No scan to stop\n");
1061 iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done,
1063 ARRAY_SIZE(scan_done_notif),
1066 ret = iwl_mvm_send_scan_offload_abort(mvm);
1068 IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n",
1069 sched ? "offloaded " : "", ret);
1070 iwl_remove_notification(&mvm->notif_wait, &wait_scan_done);
1074 IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n",
1075 sched ? "offloaded " : "");
1077 ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ);
1082 * Clear the scan status so the next scan requests will succeed. This
1083 * also ensures the Rx handler doesn't do anything, as the scan was
1084 * stopped from above.
1086 mvm->scan_status = IWL_MVM_SCAN_NONE;
1090 ieee80211_sched_scan_stopped(mvm->hw);
1092 ieee80211_scan_completed(mvm->hw, true);
1098 static void iwl_mvm_unified_scan_fill_tx_cmd(struct iwl_mvm *mvm,
1099 struct iwl_scan_req_tx_cmd *tx_cmd,
1102 tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
1104 tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
1105 IEEE80211_BAND_2GHZ,
1107 tx_cmd[0].sta_id = mvm->aux_sta.sta_id;
1109 tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL |
1111 tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm,
1112 IEEE80211_BAND_5GHZ,
1114 tx_cmd[1].sta_id = mvm->aux_sta.sta_id;
1118 iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm,
1119 struct ieee80211_channel **channels,
1120 int n_channels, u32 ssid_bitmap,
1121 struct iwl_scan_req_unified_lmac *cmd)
1123 struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data;
1126 for (i = 0; i < n_channels; i++) {
1127 channel_cfg[i].channel_num =
1128 cpu_to_le16(channels[i]->hw_value);
1129 channel_cfg[i].iter_count = cpu_to_le16(1);
1130 channel_cfg[i].iter_interval = 0;
1131 channel_cfg[i].flags =
1132 cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL |
1138 iwl_mvm_build_unified_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
1139 struct ieee80211_scan_ies *ies,
1140 struct iwl_scan_req_unified_lmac *cmd)
1142 struct iwl_scan_probe_req *preq = (void *)(cmd->data +
1143 sizeof(struct iwl_scan_channel_cfg_lmac) *
1144 mvm->fw->ucode_capa.n_scan_channels);
1145 struct ieee80211_mgmt *frame = (struct ieee80211_mgmt *)preq->buf;
1148 frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
1149 eth_broadcast_addr(frame->da);
1150 memcpy(frame->sa, vif->addr, ETH_ALEN);
1151 eth_broadcast_addr(frame->bssid);
1152 frame->seq_ctrl = 0;
1154 pos = frame->u.probe_req.variable;
1155 *pos++ = WLAN_EID_SSID;
1158 preq->mac_header.offset = 0;
1159 preq->mac_header.len = cpu_to_le16(24 + 2);
1161 memcpy(pos, ies->ies[IEEE80211_BAND_2GHZ],
1162 ies->len[IEEE80211_BAND_2GHZ]);
1163 preq->band_data[0].offset = cpu_to_le16(pos - preq->buf);
1164 preq->band_data[0].len = cpu_to_le16(ies->len[IEEE80211_BAND_2GHZ]);
1165 pos += ies->len[IEEE80211_BAND_2GHZ];
1167 memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ],
1168 ies->len[IEEE80211_BAND_5GHZ]);
1169 preq->band_data[1].offset = cpu_to_le16(pos - preq->buf);
1170 preq->band_data[1].len = cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]);
1171 pos += ies->len[IEEE80211_BAND_5GHZ];
1173 memcpy(pos, ies->common_ies, ies->common_ie_len);
1174 preq->common_data.offset = cpu_to_le16(pos - preq->buf);
1175 preq->common_data.len = cpu_to_le16(ies->common_ie_len);
1179 iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm *mvm,
1180 struct iwl_scan_req_unified_lmac *cmd,
1181 struct iwl_mvm_scan_params *params)
1183 memset(cmd, 0, ksize(cmd));
1184 cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active;
1185 cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive;
1186 if (params->passive_fragmented)
1187 cmd->fragmented_dwell =
1188 params->dwell[IEEE80211_BAND_2GHZ].passive;
1189 cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm);
1190 cmd->max_out_time = cpu_to_le32(params->max_out_time);
1191 cmd->suspend_time = cpu_to_le32(params->suspend_time);
1192 cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH);
1193 cmd->iter_num = cpu_to_le32(1);
1195 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT &&
1196 mvm->last_ebs_successful) {
1197 cmd->channel_opt[0].flags =
1198 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
1199 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1200 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
1201 cmd->channel_opt[1].flags =
1202 cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS |
1203 IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE |
1204 IWL_SCAN_CHANNEL_FLAG_CACHE_ADD);
1207 if (iwl_mvm_rrm_scan_needed(mvm))
1209 cpu_to_le32(IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED);
1212 int iwl_mvm_unified_scan_lmac(struct iwl_mvm *mvm,
1213 struct ieee80211_vif *vif,
1214 struct ieee80211_scan_request *req)
1216 struct iwl_host_cmd hcmd = {
1217 .id = SCAN_OFFLOAD_REQUEST_CMD,
1218 .len = { sizeof(struct iwl_scan_req_unified_lmac) +
1219 sizeof(struct iwl_scan_channel_cfg_lmac) *
1220 mvm->fw->ucode_capa.n_scan_channels +
1221 sizeof(struct iwl_scan_probe_req), },
1222 .data = { mvm->scan_cmd, },
1223 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1225 struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd;
1226 struct iwl_mvm_scan_params params = {};
1228 int ssid_bitmap = 0;
1231 lockdep_assert_held(&mvm->mutex);
1233 /* we should have failed registration if scan_cmd was NULL */
1234 if (WARN_ON(mvm->scan_cmd == NULL))
1237 if (req->req.n_ssids > PROBE_OPTION_MAX ||
1238 req->ies.common_ie_len + req->ies.len[NL80211_BAND_2GHZ] +
1239 req->ies.len[NL80211_BAND_5GHZ] >
1240 iwl_mvm_max_scan_ie_fw_cmd_room(mvm, false) ||
1241 req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels)
1244 mvm->scan_status = IWL_MVM_SCAN_OS;
1246 iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags,
1249 iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, ¶ms);
1251 cmd->n_channels = (u8)req->req.n_channels;
1253 flags = IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
1255 if (req->req.n_ssids == 1 && req->req.ssids[0].ssid_len != 0)
1256 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
1258 if (params.passive_fragmented)
1259 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
1261 if (req->req.n_ssids == 0)
1262 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
1264 cmd->scan_flags |= cpu_to_le32(flags);
1266 cmd->flags = iwl_mvm_scan_rxon_flags(req->req.channels[0]->band);
1267 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
1268 MAC_FILTER_IN_BEACON);
1269 iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, req->req.no_cck);
1270 iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->req.ssids,
1271 req->req.n_ssids, 0);
1273 cmd->schedule[0].delay = 0;
1274 cmd->schedule[0].iterations = 1;
1275 cmd->schedule[0].full_scan_mul = 0;
1276 cmd->schedule[1].delay = 0;
1277 cmd->schedule[1].iterations = 0;
1278 cmd->schedule[1].full_scan_mul = 0;
1280 for (i = 1; i <= req->req.n_ssids; i++)
1281 ssid_bitmap |= BIT(i);
1283 iwl_mvm_lmac_scan_cfg_channels(mvm, req->req.channels,
1284 req->req.n_channels, ssid_bitmap,
1287 iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, cmd);
1289 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1291 IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n");
1294 * If the scan failed, it usually means that the FW was unable
1295 * to allocate the time events. Warn on it, but maybe we
1296 * should try to send the command again with different params.
1298 IWL_ERR(mvm, "Scan failed! ret %d\n", ret);
1299 mvm->scan_status = IWL_MVM_SCAN_NONE;
1305 int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm,
1306 struct ieee80211_vif *vif,
1307 struct cfg80211_sched_scan_request *req,
1308 struct ieee80211_scan_ies *ies)
1310 struct iwl_host_cmd hcmd = {
1311 .id = SCAN_OFFLOAD_REQUEST_CMD,
1312 .len = { sizeof(struct iwl_scan_req_unified_lmac) +
1313 sizeof(struct iwl_scan_channel_cfg_lmac) *
1314 mvm->fw->ucode_capa.n_scan_channels +
1315 sizeof(struct iwl_scan_probe_req), },
1316 .data = { mvm->scan_cmd, },
1317 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
1319 struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd;
1320 struct iwl_mvm_scan_params params = {};
1322 u32 flags = 0, ssid_bitmap = 0;
1324 lockdep_assert_held(&mvm->mutex);
1326 /* we should have failed registration if scan_cmd was NULL */
1327 if (WARN_ON(mvm->scan_cmd == NULL))
1330 if (req->n_ssids > PROBE_OPTION_MAX ||
1331 ies->common_ie_len + ies->len[NL80211_BAND_2GHZ] +
1332 ies->len[NL80211_BAND_5GHZ] >
1333 iwl_mvm_max_scan_ie_fw_cmd_room(mvm, true) ||
1334 req->n_channels > mvm->fw->ucode_capa.n_scan_channels)
1337 iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, ¶ms);
1339 iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, ¶ms);
1341 cmd->n_channels = (u8)req->n_channels;
1343 if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) {
1345 "Sending scheduled scan with filtering, n_match_sets %d\n",
1349 "Sending Scheduled scan without filtering\n");
1350 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL;
1353 if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0)
1354 flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION;
1356 if (params.passive_fragmented)
1357 flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED;
1359 if (req->n_ssids == 0)
1360 flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE;
1362 cmd->scan_flags |= cpu_to_le32(flags);
1364 cmd->flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band);
1365 cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP |
1366 MAC_FILTER_IN_BEACON);
1367 iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, false);
1368 iwl_scan_offload_build_ssid(req, cmd->direct_scan, &ssid_bitmap, false);
1370 cmd->schedule[0].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
1371 cmd->schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS;
1372 cmd->schedule[0].full_scan_mul = 1;
1374 cmd->schedule[1].delay = cpu_to_le16(req->interval / MSEC_PER_SEC);
1375 cmd->schedule[1].iterations = 0xff;
1376 cmd->schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER;
1378 iwl_mvm_lmac_scan_cfg_channels(mvm, req->channels, req->n_channels,
1381 iwl_mvm_build_unified_scan_probe(mvm, vif, ies, cmd);
1383 ret = iwl_mvm_send_cmd(mvm, &hcmd);
1386 "Sched scan request was sent successfully\n");
1389 * If the scan failed, it usually means that the FW was unable
1390 * to allocate the time events. Warn on it, but maybe we
1391 * should try to send the command again with different params.
1393 IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret);
1394 mvm->scan_status = IWL_MVM_SCAN_NONE;
1401 int iwl_mvm_cancel_scan(struct iwl_mvm *mvm)
1403 if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)
1404 return iwl_mvm_scan_offload_stop(mvm, true);
1405 return iwl_mvm_cancel_regular_scan(mvm);