Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 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. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 10 | * |
| 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. |
| 14 | * |
| 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. |
| 19 | * |
| 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, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 26 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | * |
| 28 | * Contact Information: |
| 29 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 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 |
| 47 | * distribution. |
| 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. |
| 51 | * |
| 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. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | |
| 66 | #include <linux/etherdevice.h> |
| 67 | #include <net/mac80211.h> |
| 68 | |
| 69 | #include "mvm.h" |
| 70 | #include "iwl-eeprom-parse.h" |
| 71 | #include "fw-api-scan.h" |
| 72 | |
| 73 | #define IWL_PLCP_QUIET_THRESH 1 |
| 74 | #define IWL_ACTIVE_QUIET_TIME 10 |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 75 | |
| 76 | struct iwl_mvm_scan_params { |
| 77 | u32 max_out_time; |
| 78 | u32 suspend_time; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 79 | bool passive_fragmented; |
| 80 | struct _dwell { |
| 81 | u16 passive; |
| 82 | u16 active; |
| 83 | } dwell[IEEE80211_NUM_BANDS]; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 84 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 85 | |
| 86 | static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm) |
| 87 | { |
| 88 | u16 rx_chain; |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 89 | u8 rx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 90 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 91 | if (mvm->scan_rx_ant != ANT_NONE) |
| 92 | rx_ant = mvm->scan_rx_ant; |
| 93 | else |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 94 | rx_ant = mvm->fw->valid_rx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 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); |
| 100 | } |
| 101 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 102 | static __le32 iwl_mvm_scan_rxon_flags(enum ieee80211_band band) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 103 | { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 104 | if (band == IEEE80211_BAND_2GHZ) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 105 | return cpu_to_le32(PHY_BAND_24); |
| 106 | else |
| 107 | return cpu_to_le32(PHY_BAND_5); |
| 108 | } |
| 109 | |
| 110 | static inline __le32 |
| 111 | iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band, |
| 112 | bool no_cck) |
| 113 | { |
| 114 | u32 tx_ant; |
| 115 | |
| 116 | mvm->scan_last_antenna_idx = |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 117 | iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 118 | mvm->scan_last_antenna_idx); |
| 119 | tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS; |
| 120 | |
| 121 | if (band == IEEE80211_BAND_2GHZ && !no_cck) |
| 122 | return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK | |
| 123 | tx_ant); |
| 124 | else |
| 125 | return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant); |
| 126 | } |
| 127 | |
| 128 | /* |
| 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 |
| 132 | * request. |
| 133 | */ |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 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) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 137 | { |
| 138 | int fw_idx, req_idx; |
| 139 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 140 | for (req_idx = n_ssids - 1, fw_idx = 0; req_idx >= first; |
David Spinadel | fe04e83 | 2013-07-04 15:17:48 +0300 | [diff] [blame] | 141 | req_idx--, fw_idx++) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 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, |
| 145 | ssids[req_idx].ssid, |
| 146 | ssids[req_idx].ssid_len); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | /* |
| 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, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 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. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 159 | */ |
| 160 | static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids) |
| 161 | { |
| 162 | if (band == IEEE80211_BAND_2GHZ) |
David Spinadel | 3974533 | 2014-09-10 16:40:41 +0300 | [diff] [blame] | 163 | return 20 + 3 * (n_ssids + 1); |
| 164 | return 10 + 2 * (n_ssids + 1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band) |
| 168 | { |
| 169 | return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10; |
| 170 | } |
| 171 | |
| 172 | static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 173 | struct cfg80211_scan_request *req, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 174 | bool basic_ssid, |
| 175 | struct iwl_mvm_scan_params *params) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 176 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 177 | struct iwl_scan_channel *chan = (struct iwl_scan_channel *) |
| 178 | (cmd->data + le16_to_cpu(cmd->tx_cmd.len)); |
| 179 | int i; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 180 | int type = BIT(req->n_ssids) - 1; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 181 | enum ieee80211_band band = req->channels[0]->band; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 182 | |
| 183 | if (!basic_ssid) |
| 184 | type |= BIT(req->n_ssids); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 185 | |
| 186 | for (i = 0; i < cmd->channel_count; i++) { |
| 187 | chan->channel = cpu_to_le16(req->channels[i]->hw_value); |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 188 | chan->type = cpu_to_le32(type); |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 189 | if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR) |
David Spinadel | bb963c4 | 2013-07-23 14:13:32 +0300 | [diff] [blame] | 190 | chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 191 | chan->active_dwell = cpu_to_le16(params->dwell[band].active); |
| 192 | chan->passive_dwell = cpu_to_le16(params->dwell[band].passive); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 193 | chan->iteration_count = cpu_to_le16(1); |
| 194 | chan++; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | /* |
| 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. |
| 205 | */ |
| 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, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 208 | const u8 *band_ie, int band_ie_len, |
| 209 | const u8 *common_ie, int common_ie_len, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 210 | int left) |
| 211 | { |
| 212 | int len = 0; |
| 213 | u8 *pos = NULL; |
| 214 | |
| 215 | /* Make sure there is enough space for the probe request, |
| 216 | * two mandatory IEs and the data */ |
| 217 | left -= 24; |
| 218 | if (left < 0) |
| 219 | return 0; |
| 220 | |
| 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); |
| 225 | frame->seq_ctrl = 0; |
| 226 | |
| 227 | len += 24; |
| 228 | |
| 229 | /* for passive scans, no need to fill anything */ |
| 230 | if (n_ssids == 0) |
| 231 | return (u16)len; |
| 232 | |
| 233 | /* points to the payload of the request */ |
| 234 | pos = &frame->u.probe_req.variable[0]; |
| 235 | |
| 236 | /* fill in our SSID IE */ |
| 237 | left -= ssid_len + 2; |
| 238 | if (left < 0) |
| 239 | return 0; |
| 240 | *pos++ = WLAN_EID_SSID; |
| 241 | *pos++ = ssid_len; |
| 242 | if (ssid && ssid_len) { /* ssid_len may be == 0 even if ssid is valid */ |
| 243 | memcpy(pos, ssid, ssid_len); |
| 244 | pos += ssid_len; |
| 245 | } |
| 246 | |
| 247 | len += ssid_len + 2; |
| 248 | |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 249 | if (WARN_ON(left < band_ie_len + common_ie_len)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 250 | return len; |
| 251 | |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 252 | if (band_ie && band_ie_len) { |
| 253 | memcpy(pos, band_ie, band_ie_len); |
| 254 | pos += band_ie_len; |
| 255 | len += band_ie_len; |
| 256 | } |
| 257 | |
| 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; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return (u16)len; |
| 265 | } |
| 266 | |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 267 | static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac, |
| 268 | struct ieee80211_vif *vif) |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 269 | { |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 270 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 271 | bool *global_bound = data; |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 272 | |
David Spinadel | 1e2ebe0 | 2014-10-26 15:53:27 +0200 | [diff] [blame] | 273 | if (vif->type != NL80211_IFTYPE_P2P_DEVICE && mvmvif->phy_ctxt && |
| 274 | mvmvif->phy_ctxt->id < MAX_PHYS) |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 275 | *global_bound = true; |
| 276 | } |
| 277 | |
| 278 | static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 279 | struct ieee80211_vif *vif, |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 280 | int n_ssids, u32 flags, |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 281 | struct iwl_mvm_scan_params *params) |
| 282 | { |
| 283 | bool global_bound = false; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 284 | enum ieee80211_band band; |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 285 | u8 frag_passive_dwell = 0; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 286 | |
| 287 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 288 | IEEE80211_IFACE_ITER_NORMAL, |
| 289 | iwl_mvm_scan_condition_iterator, |
| 290 | &global_bound); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 291 | |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 292 | if (!global_bound) |
| 293 | goto not_bound; |
| 294 | |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 295 | params->suspend_time = 30; |
| 296 | params->max_out_time = 170; |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 297 | |
| 298 | if (iwl_mvm_low_latency(mvm)) { |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 299 | if (mvm->fw->ucode_capa.api[0] & |
| 300 | IWL_UCODE_TLV_API_FRAGMENTED_SCAN) { |
| 301 | params->suspend_time = 105; |
| 302 | params->max_out_time = 70; |
| 303 | frag_passive_dwell = 20; |
| 304 | } else { |
| 305 | params->suspend_time = 120; |
| 306 | params->max_out_time = 120; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | if (frag_passive_dwell && (mvm->fw->ucode_capa.api[0] & |
| 311 | IWL_UCODE_TLV_API_FRAGMENTED_SCAN)) { |
| 312 | /* |
| 313 | * P2P device scan should not be fragmented to avoid negative |
| 314 | * impact on P2P device discovery. Configure max_out_time to be |
| 315 | * equal to dwell time on passive channel. Take a longest |
| 316 | * possible value, one that corresponds to 2GHz band |
| 317 | */ |
| 318 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { |
| 319 | u32 passive_dwell = |
| 320 | iwl_mvm_get_passive_dwell(IEEE80211_BAND_2GHZ); |
| 321 | params->max_out_time = passive_dwell; |
| 322 | } else { |
| 323 | params->passive_fragmented = true; |
| 324 | } |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 325 | } |
| 326 | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 327 | if (flags & NL80211_SCAN_FLAG_LOW_PRIORITY) |
| 328 | params->max_out_time = 200; |
| 329 | |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 330 | not_bound: |
| 331 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 332 | for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) { |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 333 | if (params->passive_fragmented) |
| 334 | params->dwell[band].passive = frag_passive_dwell; |
| 335 | else |
| 336 | params->dwell[band].passive = |
| 337 | iwl_mvm_get_passive_dwell(band); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 338 | params->dwell[band].active = iwl_mvm_get_active_dwell(band, |
| 339 | n_ssids); |
| 340 | } |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 341 | } |
| 342 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 343 | static inline bool iwl_mvm_rrm_scan_needed(struct iwl_mvm *mvm) |
| 344 | { |
| 345 | /* require rrm scan whenever the fw supports it */ |
| 346 | return mvm->fw->ucode_capa.capa[0] & |
| 347 | IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT; |
| 348 | } |
| 349 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 350 | static int iwl_mvm_max_scan_ie_fw_cmd_room(struct iwl_mvm *mvm, |
| 351 | bool is_sched_scan) |
| 352 | { |
| 353 | int max_probe_len; |
| 354 | |
| 355 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) |
| 356 | max_probe_len = SCAN_OFFLOAD_PROBE_REQ_SIZE; |
| 357 | else |
| 358 | max_probe_len = mvm->fw->ucode_capa.max_probe_length; |
| 359 | |
| 360 | /* we create the 802.11 header and SSID element */ |
| 361 | max_probe_len -= 24 + 2; |
| 362 | |
| 363 | /* basic ssid is added only for hw_scan with and old api */ |
| 364 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID) && |
| 365 | !(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) && |
| 366 | !is_sched_scan) |
| 367 | max_probe_len -= 32; |
| 368 | |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 369 | /* DS parameter set element is added on 2.4GHZ band if required */ |
| 370 | if (iwl_mvm_rrm_scan_needed(mvm)) |
| 371 | max_probe_len -= 3; |
| 372 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 373 | return max_probe_len; |
| 374 | } |
| 375 | |
| 376 | int iwl_mvm_max_scan_ie_len(struct iwl_mvm *mvm, bool is_sched_scan) |
| 377 | { |
| 378 | int max_ie_len = iwl_mvm_max_scan_ie_fw_cmd_room(mvm, is_sched_scan); |
| 379 | |
| 380 | if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) |
| 381 | return max_ie_len; |
| 382 | |
| 383 | /* TODO: [BUG] This function should return the maximum allowed size of |
| 384 | * scan IEs, however the LMAC scan api contains both 2GHZ and 5GHZ IEs |
| 385 | * in the same command. So the correct implementation of this function |
| 386 | * is just iwl_mvm_max_scan_ie_fw_cmd_room() / 2. Currently the scan |
| 387 | * command has only 512 bytes and it would leave us with about 240 |
| 388 | * bytes for scan IEs, which is clearly not enough. So meanwhile |
| 389 | * we will report an incorrect value. This may result in a failure to |
| 390 | * issue a scan in unified_scan_lmac and unified_sched_scan_lmac |
| 391 | * functions with -ENOBUFS, if a large enough probe will be provided. |
| 392 | */ |
| 393 | return max_ie_len; |
| 394 | } |
| 395 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 396 | int iwl_mvm_scan_request(struct iwl_mvm *mvm, |
| 397 | struct ieee80211_vif *vif, |
| 398 | struct cfg80211_scan_request *req) |
| 399 | { |
| 400 | struct iwl_host_cmd hcmd = { |
| 401 | .id = SCAN_REQUEST_CMD, |
| 402 | .len = { 0, }, |
| 403 | .data = { mvm->scan_cmd, }, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 404 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 405 | }; |
| 406 | struct iwl_scan_cmd *cmd = mvm->scan_cmd; |
| 407 | int ret; |
| 408 | u32 status; |
| 409 | int ssid_len = 0; |
| 410 | u8 *ssid = NULL; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 411 | bool basic_ssid = !(mvm->fw->ucode_capa.flags & |
| 412 | IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 413 | struct iwl_mvm_scan_params params = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 414 | |
| 415 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 748fa67c | 2014-03-27 10:06:29 +0200 | [diff] [blame] | 416 | |
| 417 | /* we should have failed registration if scan_cmd was NULL */ |
| 418 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 419 | return -ENOMEM; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 420 | |
| 421 | IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n"); |
| 422 | mvm->scan_status = IWL_MVM_SCAN_OS; |
David Spinadel | 0564679 | 2014-06-02 09:59:49 +0300 | [diff] [blame] | 423 | memset(cmd, 0, ksize(cmd)); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 424 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 425 | cmd->channel_count = (u8)req->n_channels; |
| 426 | cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); |
| 427 | cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); |
| 428 | cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 429 | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 430 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, req->flags, ¶ms); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 431 | cmd->max_out_time = cpu_to_le32(params.max_out_time); |
| 432 | cmd->suspend_time = cpu_to_le32(params.suspend_time); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 433 | if (params.passive_fragmented) |
| 434 | cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 435 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 436 | cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 437 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 438 | MAC_FILTER_IN_BEACON); |
Ilan Peer | d91b06d | 2013-02-11 08:50:45 +0200 | [diff] [blame] | 439 | |
| 440 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
| 441 | cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED); |
| 442 | else |
| 443 | cmd->type = cpu_to_le32(SCAN_TYPE_FORCED); |
| 444 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 445 | cmd->repeats = cpu_to_le32(1); |
| 446 | |
| 447 | /* |
| 448 | * If the user asked for passive scan, don't change to active scan if |
| 449 | * you see any activity on the channel - remain passive. |
| 450 | */ |
| 451 | if (req->n_ssids > 0) { |
| 452 | cmd->passive2active = cpu_to_le16(1); |
David Spinadel | 26e05cc | 2013-07-08 13:12:29 +0300 | [diff] [blame] | 453 | cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 454 | if (basic_ssid) { |
| 455 | ssid = req->ssids[0].ssid; |
| 456 | ssid_len = req->ssids[0].ssid_len; |
| 457 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 458 | } else { |
| 459 | cmd->passive2active = 0; |
David Spinadel | 26e05cc | 2013-07-08 13:12:29 +0300 | [diff] [blame] | 460 | cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 461 | } |
| 462 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 463 | iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->ssids, req->n_ssids, |
| 464 | basic_ssid ? 1 : 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 465 | |
Emmanuel Grumbach | 8e2a866 | 2014-01-28 12:27:31 +0200 | [diff] [blame] | 466 | cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
Emmanuel Grumbach | 3856b78 | 2014-09-22 12:03:41 +0300 | [diff] [blame] | 467 | 3 << TX_CMD_FLG_BT_PRIO_POS); |
| 468 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 469 | cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id; |
| 470 | cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 471 | cmd->tx_cmd.rate_n_flags = |
| 472 | iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band, |
| 473 | req->no_cck); |
| 474 | |
| 475 | cmd->tx_cmd.len = |
| 476 | cpu_to_le16(iwl_mvm_fill_probe_req( |
| 477 | (struct ieee80211_mgmt *)cmd->data, |
| 478 | vif->addr, |
| 479 | req->n_ssids, ssid, ssid_len, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 480 | req->ie, req->ie_len, NULL, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 481 | mvm->fw->ucode_capa.max_probe_length)); |
| 482 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 483 | iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, ¶ms); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 484 | |
| 485 | cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) + |
| 486 | le16_to_cpu(cmd->tx_cmd.len) + |
| 487 | (cmd->channel_count * sizeof(struct iwl_scan_channel))); |
| 488 | hcmd.len[0] = le16_to_cpu(cmd->len); |
| 489 | |
| 490 | status = SCAN_RESPONSE_OK; |
| 491 | ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status); |
| 492 | if (!ret && status == SCAN_RESPONSE_OK) { |
| 493 | IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n"); |
| 494 | } else { |
| 495 | /* |
| 496 | * If the scan failed, it usually means that the FW was unable |
| 497 | * to allocate the time events. Warn on it, but maybe we |
| 498 | * should try to send the command again with different params. |
| 499 | */ |
| 500 | IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n", |
| 501 | status, ret); |
| 502 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 503 | ret = -EIO; |
| 504 | } |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 509 | struct iwl_device_cmd *cmd) |
| 510 | { |
| 511 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 512 | struct iwl_cmd_response *resp = (void *)pkt->data; |
| 513 | |
| 514 | IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n", |
| 515 | le32_to_cpu(resp->status)); |
| 516 | return 0; |
| 517 | } |
| 518 | |
| 519 | int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 520 | struct iwl_device_cmd *cmd) |
| 521 | { |
| 522 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 523 | struct iwl_scan_complete_notif *notif = (void *)pkt->data; |
| 524 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 525 | lockdep_assert_held(&mvm->mutex); |
| 526 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 527 | IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n", |
| 528 | notif->status, notif->scanned_channels); |
| 529 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 530 | if (mvm->scan_status == IWL_MVM_SCAN_OS) |
| 531 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 532 | ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK); |
| 533 | |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 534 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 535 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 536 | return 0; |
| 537 | } |
| 538 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 539 | int iwl_mvm_rx_scan_offload_results(struct iwl_mvm *mvm, |
| 540 | struct iwl_rx_cmd_buffer *rxb, |
| 541 | struct iwl_device_cmd *cmd) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 542 | { |
| 543 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 544 | u8 client_bitmap = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 545 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 546 | if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) { |
| 547 | struct iwl_sched_scan_results *notif = (void *)pkt->data; |
| 548 | |
| 549 | client_bitmap = notif->client_bitmap; |
| 550 | } |
| 551 | |
| 552 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN || |
| 553 | client_bitmap & SCAN_CLIENT_SCHED_SCAN) { |
| 554 | if (mvm->scan_status == IWL_MVM_SCAN_SCHED) { |
| 555 | IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n"); |
| 556 | ieee80211_sched_scan_results(mvm->hw); |
| 557 | } else { |
| 558 | IWL_DEBUG_SCAN(mvm, "Scan results\n"); |
| 559 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | return 0; |
| 563 | } |
| 564 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 565 | static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait, |
| 566 | struct iwl_rx_packet *pkt, void *data) |
| 567 | { |
| 568 | struct iwl_mvm *mvm = |
| 569 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 570 | struct iwl_scan_complete_notif *notif; |
| 571 | u32 *resp; |
| 572 | |
| 573 | switch (pkt->hdr.cmd) { |
| 574 | case SCAN_ABORT_CMD: |
| 575 | resp = (void *)pkt->data; |
| 576 | if (*resp == CAN_ABORT_STATUS) { |
| 577 | IWL_DEBUG_SCAN(mvm, |
| 578 | "Scan can be aborted, wait until completion\n"); |
| 579 | return false; |
| 580 | } |
| 581 | |
Emmanuel Grumbach | 5a3e9f7 | 2013-09-15 14:39:02 +0300 | [diff] [blame] | 582 | /* |
| 583 | * If scan cannot be aborted, it means that we had a |
| 584 | * SCAN_COMPLETE_NOTIFICATION in the pipe and it called |
| 585 | * ieee80211_scan_completed already. |
| 586 | */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 587 | IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n", |
| 588 | *resp); |
| 589 | return true; |
| 590 | |
| 591 | case SCAN_COMPLETE_NOTIFICATION: |
| 592 | notif = (void *)pkt->data; |
| 593 | IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n", |
| 594 | notif->status); |
| 595 | return true; |
| 596 | |
| 597 | default: |
| 598 | WARN_ON(1); |
| 599 | return false; |
| 600 | }; |
| 601 | } |
| 602 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 603 | static int iwl_mvm_cancel_regular_scan(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 604 | { |
| 605 | struct iwl_notification_wait wait_scan_abort; |
| 606 | static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD, |
| 607 | SCAN_COMPLETE_NOTIFICATION }; |
| 608 | int ret; |
| 609 | |
| 610 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, |
| 611 | scan_abort_notif, |
| 612 | ARRAY_SIZE(scan_abort_notif), |
| 613 | iwl_mvm_scan_abort_notif, NULL); |
| 614 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 615 | ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, 0, 0, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 616 | if (ret) { |
| 617 | IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret); |
David Spinadel | 992f81f | 2014-01-09 14:22:55 +0200 | [diff] [blame] | 618 | /* mac80211's state will be cleaned in the nic_restart flow */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 619 | goto out_remove_notif; |
| 620 | } |
| 621 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 622 | return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 623 | |
| 624 | out_remove_notif: |
| 625 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort); |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 626 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 627 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 628 | |
| 629 | int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm, |
| 630 | struct iwl_rx_cmd_buffer *rxb, |
| 631 | struct iwl_device_cmd *cmd) |
| 632 | { |
| 633 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 634 | u8 status, ebs_status; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 635 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 636 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) { |
| 637 | struct iwl_periodic_scan_complete *scan_notif; |
| 638 | |
| 639 | scan_notif = (void *)pkt->data; |
| 640 | status = scan_notif->status; |
| 641 | ebs_status = scan_notif->ebs_status; |
| 642 | } else { |
| 643 | struct iwl_scan_offload_complete *scan_notif; |
| 644 | |
| 645 | scan_notif = (void *)pkt->data; |
| 646 | status = scan_notif->status; |
| 647 | ebs_status = scan_notif->ebs_status; |
| 648 | } |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 649 | /* scan status must be locked for proper checking */ |
| 650 | lockdep_assert_held(&mvm->mutex); |
| 651 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 652 | IWL_DEBUG_SCAN(mvm, |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 653 | "%s completed, status %s, EBS status %s\n", |
| 654 | mvm->scan_status == IWL_MVM_SCAN_SCHED ? |
| 655 | "Scheduled scan" : "Scan", |
| 656 | status == IWL_SCAN_OFFLOAD_COMPLETED ? |
| 657 | "completed" : "aborted", |
| 658 | ebs_status == IWL_SCAN_EBS_SUCCESS ? |
| 659 | "success" : "failed"); |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 660 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 661 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 662 | /* only call mac80211 completion if the stop was initiated by FW */ |
| 663 | if (mvm->scan_status == IWL_MVM_SCAN_SCHED) { |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 664 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 665 | ieee80211_sched_scan_stopped(mvm->hw); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 666 | } else if (mvm->scan_status == IWL_MVM_SCAN_OS) { |
| 667 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 668 | ieee80211_scan_completed(mvm->hw, |
| 669 | status == IWL_SCAN_OFFLOAD_ABORTED); |
Eliad Peller | 4ff7818 | 2014-06-22 14:44:44 +0300 | [diff] [blame] | 670 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 671 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 672 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 673 | mvm->last_ebs_successful = !ebs_status; |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 674 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm, |
| 679 | struct ieee80211_vif *vif, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 680 | struct ieee80211_scan_ies *ies, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 681 | enum ieee80211_band band, |
| 682 | struct iwl_tx_cmd *cmd, |
| 683 | u8 *data) |
| 684 | { |
| 685 | u16 cmd_len; |
| 686 | |
| 687 | cmd->tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL); |
| 688 | cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 689 | cmd->sta_id = mvm->aux_sta.sta_id; |
| 690 | |
| 691 | cmd->rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, band, false); |
| 692 | |
| 693 | cmd_len = iwl_mvm_fill_probe_req((struct ieee80211_mgmt *)data, |
| 694 | vif->addr, |
| 695 | 1, NULL, 0, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 696 | ies->ies[band], ies->len[band], |
| 697 | ies->common_ies, ies->common_ie_len, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 698 | SCAN_OFFLOAD_PROBE_REQ_SIZE); |
| 699 | cmd->len = cpu_to_le16(cmd_len); |
| 700 | } |
| 701 | |
| 702 | static void iwl_build_scan_cmd(struct iwl_mvm *mvm, |
| 703 | struct ieee80211_vif *vif, |
| 704 | struct cfg80211_sched_scan_request *req, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 705 | struct iwl_scan_offload_cmd *scan, |
| 706 | struct iwl_mvm_scan_params *params) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 707 | { |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 708 | scan->channel_count = req->n_channels; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 709 | scan->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); |
| 710 | scan->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); |
| 711 | scan->good_CRC_th = IWL_GOOD_CRC_TH_DEFAULT; |
| 712 | scan->rx_chain = iwl_mvm_scan_rx_chain(mvm); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 713 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 714 | scan->max_out_time = cpu_to_le32(params->max_out_time); |
| 715 | scan->suspend_time = cpu_to_le32(params->suspend_time); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 716 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 717 | scan->filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 718 | MAC_FILTER_IN_BEACON); |
| 719 | scan->scan_type = cpu_to_le32(SCAN_TYPE_BACKGROUND); |
| 720 | scan->rep_count = cpu_to_le32(1); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 721 | |
| 722 | if (params->passive_fragmented) |
| 723 | scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list) |
| 727 | { |
| 728 | int i; |
| 729 | |
| 730 | for (i = 0; i < PROBE_OPTION_MAX; i++) { |
| 731 | if (!ssid_list[i].len) |
| 732 | break; |
| 733 | if (ssid_list[i].len == ssid_len && |
| 734 | !memcmp(ssid_list->ssid, ssid, ssid_len)) |
| 735 | return i; |
| 736 | } |
| 737 | return -1; |
| 738 | } |
| 739 | |
| 740 | static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req, |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 741 | struct iwl_ssid_ie *direct_scan, |
| 742 | u32 *ssid_bitmap, bool basic_ssid) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 743 | { |
| 744 | int i, j; |
| 745 | int index; |
| 746 | |
| 747 | /* |
| 748 | * copy SSIDs from match list. |
| 749 | * iwl_config_sched_scan_profiles() uses the order of these ssids to |
| 750 | * config match list. |
| 751 | */ |
| 752 | for (i = 0; i < req->n_match_sets && i < PROBE_OPTION_MAX; i++) { |
Johannes Berg | ea73cbc | 2014-01-24 10:53:53 +0100 | [diff] [blame] | 753 | /* skip empty SSID matchsets */ |
| 754 | if (!req->match_sets[i].ssid.ssid_len) |
| 755 | continue; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 756 | direct_scan[i].id = WLAN_EID_SSID; |
| 757 | direct_scan[i].len = req->match_sets[i].ssid.ssid_len; |
| 758 | memcpy(direct_scan[i].ssid, req->match_sets[i].ssid.ssid, |
| 759 | direct_scan[i].len); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | /* add SSIDs from scan SSID list */ |
| 763 | *ssid_bitmap = 0; |
| 764 | for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) { |
| 765 | index = iwl_ssid_exist(req->ssids[j].ssid, |
| 766 | req->ssids[j].ssid_len, |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 767 | direct_scan); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 768 | if (index < 0) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 769 | if (!req->ssids[j].ssid_len && basic_ssid) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 770 | continue; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 771 | direct_scan[i].id = WLAN_EID_SSID; |
| 772 | direct_scan[i].len = req->ssids[j].ssid_len; |
| 773 | memcpy(direct_scan[i].ssid, req->ssids[j].ssid, |
| 774 | direct_scan[i].len); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 775 | *ssid_bitmap |= BIT(i + 1); |
| 776 | i++; |
| 777 | } else { |
| 778 | *ssid_bitmap |= BIT(index + 1); |
| 779 | } |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | static void iwl_build_channel_cfg(struct iwl_mvm *mvm, |
| 784 | struct cfg80211_sched_scan_request *req, |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 785 | u8 *channels_buffer, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 786 | enum ieee80211_band band, |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 787 | int *head, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 788 | u32 ssid_bitmap, |
| 789 | struct iwl_mvm_scan_params *params) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 790 | { |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 791 | u32 n_channels = mvm->fw->ucode_capa.n_scan_channels; |
| 792 | __le32 *type = (__le32 *)channels_buffer; |
| 793 | __le16 *channel_number = (__le16 *)(type + n_channels); |
| 794 | __le16 *iter_count = channel_number + n_channels; |
| 795 | __le32 *iter_interval = (__le32 *)(iter_count + n_channels); |
| 796 | u8 *active_dwell = (u8 *)(iter_interval + n_channels); |
| 797 | u8 *passive_dwell = active_dwell + n_channels; |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 798 | int i, index = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 799 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 800 | for (i = 0; i < req->n_channels; i++) { |
| 801 | struct ieee80211_channel *chan = req->channels[i]; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 802 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 803 | if (chan->band != band) |
| 804 | continue; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 805 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 806 | index = *head; |
| 807 | (*head)++; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 808 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 809 | channel_number[index] = cpu_to_le16(chan->hw_value); |
| 810 | active_dwell[index] = params->dwell[band].active; |
| 811 | passive_dwell[index] = params->dwell[band].passive; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 812 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 813 | iter_count[index] = cpu_to_le16(1); |
| 814 | iter_interval[index] = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 815 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 816 | if (!(chan->flags & IEEE80211_CHAN_NO_IR)) |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 817 | type[index] |= |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 818 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE); |
| 819 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 820 | type[index] |= cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL | |
| 821 | IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 822 | |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 823 | if (chan->flags & IEEE80211_CHAN_NO_HT40) |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 824 | type[index] |= |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 825 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW); |
| 826 | |
| 827 | /* scan for all SSIDs from req->ssids */ |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 828 | type[index] |= cpu_to_le32(ssid_bitmap); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
| 832 | int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm, |
| 833 | struct ieee80211_vif *vif, |
| 834 | struct cfg80211_sched_scan_request *req, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 835 | struct ieee80211_scan_ies *ies) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 836 | { |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 837 | int band_2ghz = mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels; |
| 838 | int band_5ghz = mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels; |
| 839 | int head = 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 840 | u32 ssid_bitmap; |
| 841 | int cmd_len; |
| 842 | int ret; |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 843 | u8 *probes; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 844 | bool basic_ssid = !(mvm->fw->ucode_capa.flags & |
| 845 | IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 846 | |
| 847 | struct iwl_scan_offload_cfg *scan_cfg; |
| 848 | struct iwl_host_cmd cmd = { |
| 849 | .id = SCAN_OFFLOAD_CONFIG_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 850 | }; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 851 | struct iwl_mvm_scan_params params = {}; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 852 | |
| 853 | lockdep_assert_held(&mvm->mutex); |
| 854 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 855 | cmd_len = sizeof(struct iwl_scan_offload_cfg) + |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 856 | mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE + |
Emmanuel Grumbach | 6609253 | 2014-02-20 14:58:30 +0200 | [diff] [blame] | 857 | 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 858 | |
| 859 | scan_cfg = kzalloc(cmd_len, GFP_KERNEL); |
| 860 | if (!scan_cfg) |
| 861 | return -ENOMEM; |
| 862 | |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 863 | probes = scan_cfg->data + |
| 864 | mvm->fw->ucode_capa.n_scan_channels * IWL_SCAN_CHAN_SIZE; |
| 865 | |
Johannes Berg | ab48003 | 2014-06-04 10:13:50 +0200 | [diff] [blame] | 866 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, ¶ms); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 867 | iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 868 | scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len); |
| 869 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 870 | iwl_scan_offload_build_ssid(req, scan_cfg->scan_cmd.direct_scan, |
| 871 | &ssid_bitmap, basic_ssid); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 872 | /* build tx frames for supported bands */ |
| 873 | if (band_2ghz) { |
| 874 | iwl_scan_offload_build_tx_cmd(mvm, vif, ies, |
| 875 | IEEE80211_BAND_2GHZ, |
| 876 | &scan_cfg->scan_cmd.tx_cmd[0], |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 877 | probes); |
| 878 | iwl_build_channel_cfg(mvm, req, scan_cfg->data, |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 879 | IEEE80211_BAND_2GHZ, &head, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 880 | ssid_bitmap, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 881 | } |
| 882 | if (band_5ghz) { |
| 883 | iwl_scan_offload_build_tx_cmd(mvm, vif, ies, |
| 884 | IEEE80211_BAND_5GHZ, |
| 885 | &scan_cfg->scan_cmd.tx_cmd[1], |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 886 | probes + |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 887 | SCAN_OFFLOAD_PROBE_REQ_SIZE); |
David Spinadel | 762533b | 2014-06-05 11:20:43 +0300 | [diff] [blame] | 888 | iwl_build_channel_cfg(mvm, req, scan_cfg->data, |
Eliad Peller | 8987941 | 2014-05-26 18:44:35 +0300 | [diff] [blame] | 889 | IEEE80211_BAND_5GHZ, &head, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 890 | ssid_bitmap, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | cmd.data[0] = scan_cfg; |
| 894 | cmd.len[0] = cmd_len; |
| 895 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; |
| 896 | |
| 897 | IWL_DEBUG_SCAN(mvm, "Sending scheduled scan config\n"); |
| 898 | |
| 899 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 900 | kfree(scan_cfg); |
| 901 | return ret; |
| 902 | } |
| 903 | |
| 904 | int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm, |
| 905 | struct cfg80211_sched_scan_request *req) |
| 906 | { |
| 907 | struct iwl_scan_offload_profile *profile; |
| 908 | struct iwl_scan_offload_profile_cfg *profile_cfg; |
| 909 | struct iwl_scan_offload_blacklist *blacklist; |
| 910 | struct iwl_host_cmd cmd = { |
| 911 | .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 912 | .len[1] = sizeof(*profile_cfg), |
| 913 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 914 | .dataflags[1] = IWL_HCMD_DFL_NOCOPY, |
| 915 | }; |
| 916 | int blacklist_len; |
| 917 | int i; |
| 918 | int ret; |
| 919 | |
| 920 | if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES)) |
| 921 | return -EIO; |
| 922 | |
| 923 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL) |
| 924 | blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN; |
| 925 | else |
| 926 | blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN; |
| 927 | |
| 928 | blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL); |
| 929 | if (!blacklist) |
| 930 | return -ENOMEM; |
| 931 | |
| 932 | profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL); |
| 933 | if (!profile_cfg) { |
| 934 | ret = -ENOMEM; |
| 935 | goto free_blacklist; |
| 936 | } |
| 937 | |
| 938 | cmd.data[0] = blacklist; |
| 939 | cmd.len[0] = sizeof(*blacklist) * blacklist_len; |
| 940 | cmd.data[1] = profile_cfg; |
| 941 | |
| 942 | /* No blacklist configuration */ |
| 943 | |
| 944 | profile_cfg->num_profiles = req->n_match_sets; |
| 945 | profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN; |
| 946 | profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN; |
| 947 | profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN; |
David Spinadel | 6e0bbe5 | 2013-12-30 09:59:45 +0200 | [diff] [blame] | 948 | if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len) |
| 949 | profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 950 | |
| 951 | for (i = 0; i < req->n_match_sets; i++) { |
| 952 | profile = &profile_cfg->profiles[i]; |
| 953 | profile->ssid_index = i; |
| 954 | /* Support any cipher and auth algorithm */ |
| 955 | profile->unicast_cipher = 0xff; |
| 956 | profile->auth_alg = 0xff; |
| 957 | profile->network_type = IWL_NETWORK_TYPE_ANY; |
| 958 | profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY; |
| 959 | profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN; |
| 960 | } |
| 961 | |
| 962 | IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n"); |
| 963 | |
| 964 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 965 | kfree(profile_cfg); |
| 966 | free_blacklist: |
| 967 | kfree(blacklist); |
| 968 | |
| 969 | return ret; |
| 970 | } |
| 971 | |
| 972 | int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm, |
| 973 | struct cfg80211_sched_scan_request *req) |
| 974 | { |
| 975 | struct iwl_scan_offload_req scan_req = { |
| 976 | .watchdog = IWL_SCHED_SCAN_WATCHDOG, |
| 977 | |
| 978 | .schedule_line[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS, |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 979 | .schedule_line[0].delay = cpu_to_le16(req->interval / 1000), |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 980 | .schedule_line[0].full_scan_mul = 1, |
| 981 | |
| 982 | .schedule_line[1].iterations = 0xff, |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 983 | .schedule_line[1].delay = cpu_to_le16(req->interval / 1000), |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 984 | .schedule_line[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER, |
| 985 | }; |
| 986 | |
| 987 | if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) { |
| 988 | IWL_DEBUG_SCAN(mvm, |
| 989 | "Sending scheduled scan with filtering, filter len %d\n", |
| 990 | req->n_match_sets); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 991 | } else { |
| 992 | IWL_DEBUG_SCAN(mvm, |
| 993 | "Sending Scheduled scan without filtering\n"); |
Eliad Peller | de33fb5 | 2013-11-10 12:59:46 +0200 | [diff] [blame] | 994 | scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 995 | } |
| 996 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 997 | if (mvm->last_ebs_successful && |
| 998 | mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) |
| 999 | scan_req.flags |= |
| 1000 | cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE); |
| 1001 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1002 | return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1003 | sizeof(scan_req), &scan_req); |
| 1004 | } |
| 1005 | |
Luciano Coelho | b141c23 | 2014-10-01 13:22:40 +0300 | [diff] [blame] | 1006 | int iwl_mvm_scan_offload_start(struct iwl_mvm *mvm, |
| 1007 | struct ieee80211_vif *vif, |
| 1008 | struct cfg80211_sched_scan_request *req, |
| 1009 | struct ieee80211_scan_ies *ies) |
| 1010 | { |
| 1011 | int ret; |
| 1012 | |
| 1013 | if ((mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN)) { |
| 1014 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1015 | if (ret) |
| 1016 | return ret; |
| 1017 | ret = iwl_mvm_unified_sched_scan_lmac(mvm, vif, req, ies); |
| 1018 | } else { |
| 1019 | ret = iwl_mvm_config_sched_scan(mvm, vif, req, ies); |
| 1020 | if (ret) |
| 1021 | return ret; |
| 1022 | ret = iwl_mvm_config_sched_scan_profiles(mvm, req); |
| 1023 | if (ret) |
| 1024 | return ret; |
| 1025 | ret = iwl_mvm_sched_scan_start(mvm, req); |
| 1026 | } |
| 1027 | |
| 1028 | return ret; |
| 1029 | } |
| 1030 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1031 | static int iwl_mvm_send_scan_offload_abort(struct iwl_mvm *mvm) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1032 | { |
| 1033 | int ret; |
| 1034 | struct iwl_host_cmd cmd = { |
| 1035 | .id = SCAN_OFFLOAD_ABORT_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1036 | }; |
| 1037 | u32 status; |
| 1038 | |
| 1039 | /* Exit instantly with error when device is not ready |
| 1040 | * to receive scan abort command or it does not perform |
| 1041 | * scheduled scan currently */ |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1042 | if (mvm->scan_status != IWL_MVM_SCAN_SCHED && |
| 1043 | (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) || |
| 1044 | mvm->scan_status != IWL_MVM_SCAN_OS)) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1045 | return -EIO; |
| 1046 | |
| 1047 | ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status); |
| 1048 | if (ret) |
| 1049 | return ret; |
| 1050 | |
| 1051 | if (status != CAN_ABORT_STATUS) { |
| 1052 | /* |
| 1053 | * The scan abort will return 1 for success or |
| 1054 | * 2 for "failure". A failure condition can be |
| 1055 | * due to simply not being in an active scan which |
| 1056 | * can occur if we send the scan abort before the |
| 1057 | * microcode has notified us that a scan is completed. |
| 1058 | */ |
| 1059 | IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1060 | ret = -ENOENT; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | return ret; |
| 1064 | } |
| 1065 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1066 | int iwl_mvm_scan_offload_stop(struct iwl_mvm *mvm, bool notify) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1067 | { |
| 1068 | int ret; |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1069 | struct iwl_notification_wait wait_scan_done; |
| 1070 | static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, }; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1071 | bool sched = mvm->scan_status == IWL_MVM_SCAN_SCHED; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1072 | |
| 1073 | lockdep_assert_held(&mvm->mutex); |
| 1074 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1075 | if (mvm->scan_status != IWL_MVM_SCAN_SCHED && |
| 1076 | (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) || |
| 1077 | mvm->scan_status != IWL_MVM_SCAN_OS)) { |
| 1078 | IWL_DEBUG_SCAN(mvm, "No scan to stop\n"); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1079 | return 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1080 | } |
| 1081 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1082 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done, |
| 1083 | scan_done_notif, |
| 1084 | ARRAY_SIZE(scan_done_notif), |
| 1085 | NULL, NULL); |
| 1086 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1087 | ret = iwl_mvm_send_scan_offload_abort(mvm); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1088 | if (ret) { |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1089 | IWL_DEBUG_SCAN(mvm, "Send stop %sscan failed %d\n", |
| 1090 | sched ? "offloaded " : "", ret); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1091 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_done); |
| 1092 | return ret; |
| 1093 | } |
| 1094 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1095 | IWL_DEBUG_SCAN(mvm, "Successfully sent stop %sscan\n", |
| 1096 | sched ? "offloaded " : ""); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1097 | |
| 1098 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ); |
| 1099 | if (ret) |
| 1100 | return ret; |
| 1101 | |
| 1102 | /* |
| 1103 | * Clear the scan status so the next scan requests will succeed. This |
| 1104 | * also ensures the Rx handler doesn't do anything, as the scan was |
Eliad Peller | 4ff7818 | 2014-06-22 14:44:44 +0300 | [diff] [blame] | 1105 | * stopped from above. Since the rx handler won't do anything now, |
| 1106 | * we have to release the scan reference here. |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1107 | */ |
Eliad Peller | 4ff7818 | 2014-06-22 14:44:44 +0300 | [diff] [blame] | 1108 | if (mvm->scan_status == IWL_MVM_SCAN_OS) |
| 1109 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 1110 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1111 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1112 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1113 | if (notify) { |
| 1114 | if (sched) |
| 1115 | ieee80211_sched_scan_stopped(mvm->hw); |
| 1116 | else |
| 1117 | ieee80211_scan_completed(mvm->hw, true); |
| 1118 | } |
David Spinadel | 636a2cd | 2014-05-01 15:57:22 +0300 | [diff] [blame] | 1119 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 1120 | return 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 1121 | } |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1122 | |
| 1123 | static void iwl_mvm_unified_scan_fill_tx_cmd(struct iwl_mvm *mvm, |
| 1124 | struct iwl_scan_req_tx_cmd *tx_cmd, |
| 1125 | bool no_cck) |
| 1126 | { |
| 1127 | tx_cmd[0].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
| 1128 | TX_CMD_FLG_BT_DIS); |
| 1129 | tx_cmd[0].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, |
| 1130 | IEEE80211_BAND_2GHZ, |
| 1131 | no_cck); |
| 1132 | tx_cmd[0].sta_id = mvm->aux_sta.sta_id; |
| 1133 | |
| 1134 | tx_cmd[1].tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
| 1135 | TX_CMD_FLG_BT_DIS); |
| 1136 | tx_cmd[1].rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, |
| 1137 | IEEE80211_BAND_5GHZ, |
| 1138 | no_cck); |
| 1139 | tx_cmd[1].sta_id = mvm->aux_sta.sta_id; |
| 1140 | } |
| 1141 | |
| 1142 | static void |
| 1143 | iwl_mvm_lmac_scan_cfg_channels(struct iwl_mvm *mvm, |
| 1144 | struct ieee80211_channel **channels, |
| 1145 | int n_channels, u32 ssid_bitmap, |
| 1146 | struct iwl_scan_req_unified_lmac *cmd) |
| 1147 | { |
| 1148 | struct iwl_scan_channel_cfg_lmac *channel_cfg = (void *)&cmd->data; |
| 1149 | int i; |
| 1150 | |
| 1151 | for (i = 0; i < n_channels; i++) { |
| 1152 | channel_cfg[i].channel_num = |
| 1153 | cpu_to_le16(channels[i]->hw_value); |
| 1154 | channel_cfg[i].iter_count = cpu_to_le16(1); |
| 1155 | channel_cfg[i].iter_interval = 0; |
| 1156 | channel_cfg[i].flags = |
| 1157 | cpu_to_le32(IWL_UNIFIED_SCAN_CHANNEL_PARTIAL | |
| 1158 | ssid_bitmap); |
| 1159 | } |
| 1160 | } |
| 1161 | |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1162 | static u8 *iwl_mvm_copy_and_insert_ds_elem(struct iwl_mvm *mvm, const u8 *ies, |
| 1163 | size_t len, u8 *const pos) |
| 1164 | { |
| 1165 | static const u8 before_ds_params[] = { |
| 1166 | WLAN_EID_SSID, |
| 1167 | WLAN_EID_SUPP_RATES, |
| 1168 | WLAN_EID_REQUEST, |
| 1169 | WLAN_EID_EXT_SUPP_RATES, |
| 1170 | }; |
| 1171 | size_t offs; |
| 1172 | u8 *newpos = pos; |
| 1173 | |
| 1174 | if (!iwl_mvm_rrm_scan_needed(mvm)) { |
| 1175 | memcpy(newpos, ies, len); |
| 1176 | return newpos + len; |
| 1177 | } |
| 1178 | |
| 1179 | offs = ieee80211_ie_split(ies, len, |
| 1180 | before_ds_params, |
| 1181 | ARRAY_SIZE(before_ds_params), |
| 1182 | 0); |
| 1183 | |
| 1184 | memcpy(newpos, ies, offs); |
| 1185 | newpos += offs; |
| 1186 | |
| 1187 | /* Add a placeholder for DS Parameter Set element */ |
| 1188 | *newpos++ = WLAN_EID_DS_PARAMS; |
| 1189 | *newpos++ = 1; |
| 1190 | *newpos++ = 0; |
| 1191 | |
| 1192 | memcpy(newpos, ies + offs, len - offs); |
| 1193 | newpos += len - offs; |
| 1194 | |
| 1195 | return newpos; |
| 1196 | } |
| 1197 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1198 | static void |
| 1199 | iwl_mvm_build_unified_scan_probe(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1200 | struct ieee80211_scan_ies *ies, |
| 1201 | struct iwl_scan_req_unified_lmac *cmd) |
| 1202 | { |
| 1203 | struct iwl_scan_probe_req *preq = (void *)(cmd->data + |
| 1204 | sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1205 | mvm->fw->ucode_capa.n_scan_channels); |
| 1206 | struct ieee80211_mgmt *frame = (struct ieee80211_mgmt *)preq->buf; |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1207 | u8 *pos, *newpos; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1208 | |
| 1209 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 1210 | eth_broadcast_addr(frame->da); |
| 1211 | memcpy(frame->sa, vif->addr, ETH_ALEN); |
| 1212 | eth_broadcast_addr(frame->bssid); |
| 1213 | frame->seq_ctrl = 0; |
| 1214 | |
| 1215 | pos = frame->u.probe_req.variable; |
| 1216 | *pos++ = WLAN_EID_SSID; |
| 1217 | *pos++ = 0; |
| 1218 | |
| 1219 | preq->mac_header.offset = 0; |
| 1220 | preq->mac_header.len = cpu_to_le16(24 + 2); |
| 1221 | |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1222 | /* Insert ds parameter set element on 2.4 GHz band */ |
| 1223 | newpos = iwl_mvm_copy_and_insert_ds_elem(mvm, |
| 1224 | ies->ies[IEEE80211_BAND_2GHZ], |
| 1225 | ies->len[IEEE80211_BAND_2GHZ], |
| 1226 | pos); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1227 | preq->band_data[0].offset = cpu_to_le16(pos - preq->buf); |
Andrei Otcheretianski | 66dc527 | 2014-09-02 17:55:40 +0300 | [diff] [blame] | 1228 | preq->band_data[0].len = cpu_to_le16(newpos - pos); |
| 1229 | pos = newpos; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1230 | |
| 1231 | memcpy(pos, ies->ies[IEEE80211_BAND_5GHZ], |
| 1232 | ies->len[IEEE80211_BAND_5GHZ]); |
| 1233 | preq->band_data[1].offset = cpu_to_le16(pos - preq->buf); |
| 1234 | preq->band_data[1].len = cpu_to_le16(ies->len[IEEE80211_BAND_5GHZ]); |
| 1235 | pos += ies->len[IEEE80211_BAND_5GHZ]; |
| 1236 | |
| 1237 | memcpy(pos, ies->common_ies, ies->common_ie_len); |
| 1238 | preq->common_data.offset = cpu_to_le16(pos - preq->buf); |
| 1239 | preq->common_data.len = cpu_to_le16(ies->common_ie_len); |
| 1240 | } |
| 1241 | |
| 1242 | static void |
| 1243 | iwl_mvm_build_generic_unified_scan_cmd(struct iwl_mvm *mvm, |
| 1244 | struct iwl_scan_req_unified_lmac *cmd, |
| 1245 | struct iwl_mvm_scan_params *params) |
| 1246 | { |
David Spinadel | af91344 | 2014-06-12 19:29:40 +0300 | [diff] [blame] | 1247 | memset(cmd, 0, ksize(cmd)); |
David Spinadel | 2ce89cd | 2014-07-22 13:11:18 +0300 | [diff] [blame] | 1248 | cmd->active_dwell = params->dwell[IEEE80211_BAND_2GHZ].active; |
| 1249 | cmd->passive_dwell = params->dwell[IEEE80211_BAND_2GHZ].passive; |
| 1250 | if (params->passive_fragmented) |
| 1251 | cmd->fragmented_dwell = |
| 1252 | params->dwell[IEEE80211_BAND_2GHZ].passive; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1253 | cmd->rx_chain_select = iwl_mvm_scan_rx_chain(mvm); |
| 1254 | cmd->max_out_time = cpu_to_le32(params->max_out_time); |
| 1255 | cmd->suspend_time = cpu_to_le32(params->suspend_time); |
| 1256 | cmd->scan_prio = cpu_to_le32(IWL_SCAN_PRIORITY_HIGH); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1257 | cmd->iter_num = cpu_to_le32(1); |
David Spinadel | af91344 | 2014-06-12 19:29:40 +0300 | [diff] [blame] | 1258 | |
| 1259 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT && |
| 1260 | mvm->last_ebs_successful) { |
| 1261 | cmd->channel_opt[0].flags = |
| 1262 | cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1263 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1264 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD); |
| 1265 | cmd->channel_opt[1].flags = |
| 1266 | cpu_to_le16(IWL_SCAN_CHANNEL_FLAG_EBS | |
| 1267 | IWL_SCAN_CHANNEL_FLAG_EBS_ACCURATE | |
| 1268 | IWL_SCAN_CHANNEL_FLAG_CACHE_ADD); |
| 1269 | } |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 1270 | |
| 1271 | if (iwl_mvm_rrm_scan_needed(mvm)) |
| 1272 | cmd->scan_flags |= |
| 1273 | cpu_to_le32(IWL_MVM_LMAC_SCAN_FLAGS_RRM_ENABLED); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | int iwl_mvm_unified_scan_lmac(struct iwl_mvm *mvm, |
| 1277 | struct ieee80211_vif *vif, |
| 1278 | struct ieee80211_scan_request *req) |
| 1279 | { |
| 1280 | struct iwl_host_cmd hcmd = { |
| 1281 | .id = SCAN_OFFLOAD_REQUEST_CMD, |
| 1282 | .len = { sizeof(struct iwl_scan_req_unified_lmac) + |
| 1283 | sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1284 | mvm->fw->ucode_capa.n_scan_channels + |
| 1285 | sizeof(struct iwl_scan_probe_req), }, |
| 1286 | .data = { mvm->scan_cmd, }, |
| 1287 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 1288 | }; |
| 1289 | struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd; |
| 1290 | struct iwl_mvm_scan_params params = {}; |
| 1291 | u32 flags; |
| 1292 | int ssid_bitmap = 0; |
| 1293 | int ret, i; |
| 1294 | |
| 1295 | lockdep_assert_held(&mvm->mutex); |
| 1296 | |
| 1297 | /* we should have failed registration if scan_cmd was NULL */ |
| 1298 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 1299 | return -ENOMEM; |
| 1300 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 1301 | if (req->req.n_ssids > PROBE_OPTION_MAX || |
| 1302 | req->ies.common_ie_len + req->ies.len[NL80211_BAND_2GHZ] + |
| 1303 | req->ies.len[NL80211_BAND_5GHZ] > |
| 1304 | iwl_mvm_max_scan_ie_fw_cmd_room(mvm, false) || |
| 1305 | req->req.n_channels > mvm->fw->ucode_capa.n_scan_channels) |
| 1306 | return -ENOBUFS; |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1307 | |
| 1308 | mvm->scan_status = IWL_MVM_SCAN_OS; |
| 1309 | |
| 1310 | iwl_mvm_scan_calc_params(mvm, vif, req->req.n_ssids, req->req.flags, |
| 1311 | ¶ms); |
| 1312 | |
| 1313 | iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, ¶ms); |
| 1314 | |
| 1315 | cmd->n_channels = (u8)req->req.n_channels; |
| 1316 | |
| 1317 | flags = IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL; |
| 1318 | |
| 1319 | if (req->req.n_ssids == 1 && req->req.ssids[0].ssid_len != 0) |
| 1320 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION; |
| 1321 | |
| 1322 | if (params.passive_fragmented) |
| 1323 | flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED; |
| 1324 | |
| 1325 | if (req->req.n_ssids == 0) |
| 1326 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE; |
| 1327 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 1328 | cmd->scan_flags |= cpu_to_le32(flags); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1329 | |
| 1330 | cmd->flags = iwl_mvm_scan_rxon_flags(req->req.channels[0]->band); |
| 1331 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 1332 | MAC_FILTER_IN_BEACON); |
| 1333 | iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, req->req.no_cck); |
| 1334 | iwl_mvm_scan_fill_ssids(cmd->direct_scan, req->req.ssids, |
| 1335 | req->req.n_ssids, 0); |
| 1336 | |
| 1337 | cmd->schedule[0].delay = 0; |
| 1338 | cmd->schedule[0].iterations = 1; |
| 1339 | cmd->schedule[0].full_scan_mul = 0; |
| 1340 | cmd->schedule[1].delay = 0; |
| 1341 | cmd->schedule[1].iterations = 0; |
| 1342 | cmd->schedule[1].full_scan_mul = 0; |
| 1343 | |
| 1344 | for (i = 1; i <= req->req.n_ssids; i++) |
| 1345 | ssid_bitmap |= BIT(i); |
| 1346 | |
| 1347 | iwl_mvm_lmac_scan_cfg_channels(mvm, req->req.channels, |
| 1348 | req->req.n_channels, ssid_bitmap, |
| 1349 | cmd); |
| 1350 | |
| 1351 | iwl_mvm_build_unified_scan_probe(mvm, vif, &req->ies, cmd); |
| 1352 | |
| 1353 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
| 1354 | if (!ret) { |
| 1355 | IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n"); |
| 1356 | } else { |
| 1357 | /* |
| 1358 | * If the scan failed, it usually means that the FW was unable |
| 1359 | * to allocate the time events. Warn on it, but maybe we |
| 1360 | * should try to send the command again with different params. |
| 1361 | */ |
| 1362 | IWL_ERR(mvm, "Scan failed! ret %d\n", ret); |
| 1363 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1364 | ret = -EIO; |
| 1365 | } |
| 1366 | return ret; |
| 1367 | } |
| 1368 | |
| 1369 | int iwl_mvm_unified_sched_scan_lmac(struct iwl_mvm *mvm, |
| 1370 | struct ieee80211_vif *vif, |
| 1371 | struct cfg80211_sched_scan_request *req, |
| 1372 | struct ieee80211_scan_ies *ies) |
| 1373 | { |
| 1374 | struct iwl_host_cmd hcmd = { |
| 1375 | .id = SCAN_OFFLOAD_REQUEST_CMD, |
| 1376 | .len = { sizeof(struct iwl_scan_req_unified_lmac) + |
| 1377 | sizeof(struct iwl_scan_channel_cfg_lmac) * |
| 1378 | mvm->fw->ucode_capa.n_scan_channels + |
| 1379 | sizeof(struct iwl_scan_probe_req), }, |
| 1380 | .data = { mvm->scan_cmd, }, |
| 1381 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 1382 | }; |
| 1383 | struct iwl_scan_req_unified_lmac *cmd = mvm->scan_cmd; |
| 1384 | struct iwl_mvm_scan_params params = {}; |
| 1385 | int ret; |
| 1386 | u32 flags = 0, ssid_bitmap = 0; |
| 1387 | |
| 1388 | lockdep_assert_held(&mvm->mutex); |
| 1389 | |
| 1390 | /* we should have failed registration if scan_cmd was NULL */ |
| 1391 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 1392 | return -ENOMEM; |
| 1393 | |
Andrei Otcheretianski | 48849a4 | 2014-09-09 10:58:49 +0300 | [diff] [blame] | 1394 | if (req->n_ssids > PROBE_OPTION_MAX || |
| 1395 | ies->common_ie_len + ies->len[NL80211_BAND_2GHZ] + |
| 1396 | ies->len[NL80211_BAND_5GHZ] > |
| 1397 | iwl_mvm_max_scan_ie_fw_cmd_room(mvm, true) || |
| 1398 | req->n_channels > mvm->fw->ucode_capa.n_scan_channels) |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1399 | return -ENOBUFS; |
| 1400 | |
| 1401 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, 0, ¶ms); |
| 1402 | |
| 1403 | iwl_mvm_build_generic_unified_scan_cmd(mvm, cmd, ¶ms); |
| 1404 | |
| 1405 | cmd->n_channels = (u8)req->n_channels; |
| 1406 | |
| 1407 | if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) { |
| 1408 | IWL_DEBUG_SCAN(mvm, |
| 1409 | "Sending scheduled scan with filtering, n_match_sets %d\n", |
| 1410 | req->n_match_sets); |
| 1411 | } else { |
| 1412 | IWL_DEBUG_SCAN(mvm, |
| 1413 | "Sending Scheduled scan without filtering\n"); |
| 1414 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PASS_ALL; |
| 1415 | } |
| 1416 | |
| 1417 | if (req->n_ssids == 1 && req->ssids[0].ssid_len != 0) |
| 1418 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PRE_CONNECTION; |
| 1419 | |
| 1420 | if (params.passive_fragmented) |
| 1421 | flags |= IWL_MVM_LMAC_SCAN_FLAG_FRAGMENTED; |
| 1422 | |
| 1423 | if (req->n_ssids == 0) |
| 1424 | flags |= IWL_MVM_LMAC_SCAN_FLAG_PASSIVE; |
| 1425 | |
Andrei Otcheretianski | 73897bd | 2014-07-09 18:59:14 +0300 | [diff] [blame] | 1426 | cmd->scan_flags |= cpu_to_le32(flags); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1427 | |
| 1428 | cmd->flags = iwl_mvm_scan_rxon_flags(req->channels[0]->band); |
| 1429 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 1430 | MAC_FILTER_IN_BEACON); |
| 1431 | iwl_mvm_unified_scan_fill_tx_cmd(mvm, cmd->tx_cmd, false); |
| 1432 | iwl_scan_offload_build_ssid(req, cmd->direct_scan, &ssid_bitmap, false); |
| 1433 | |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 1434 | cmd->schedule[0].delay = cpu_to_le16(req->interval / MSEC_PER_SEC); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1435 | cmd->schedule[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS; |
| 1436 | cmd->schedule[0].full_scan_mul = 1; |
| 1437 | |
David Spinadel | b14fc2b | 2014-06-25 13:17:53 +0300 | [diff] [blame] | 1438 | cmd->schedule[1].delay = cpu_to_le16(req->interval / MSEC_PER_SEC); |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1439 | cmd->schedule[1].iterations = 0xff; |
| 1440 | cmd->schedule[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER; |
| 1441 | |
| 1442 | iwl_mvm_lmac_scan_cfg_channels(mvm, req->channels, req->n_channels, |
| 1443 | ssid_bitmap, cmd); |
| 1444 | |
| 1445 | iwl_mvm_build_unified_scan_probe(mvm, vif, ies, cmd); |
| 1446 | |
| 1447 | ret = iwl_mvm_send_cmd(mvm, &hcmd); |
| 1448 | if (!ret) { |
| 1449 | IWL_DEBUG_SCAN(mvm, |
| 1450 | "Sched scan request was sent successfully\n"); |
| 1451 | } else { |
| 1452 | /* |
| 1453 | * If the scan failed, it usually means that the FW was unable |
| 1454 | * to allocate the time events. Warn on it, but maybe we |
| 1455 | * should try to send the command again with different params. |
| 1456 | */ |
| 1457 | IWL_ERR(mvm, "Sched scan failed! ret %d\n", ret); |
| 1458 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1459 | ret = -EIO; |
| 1460 | } |
| 1461 | return ret; |
| 1462 | } |
| 1463 | |
| 1464 | |
| 1465 | int iwl_mvm_cancel_scan(struct iwl_mvm *mvm) |
| 1466 | { |
Emmanuel Grumbach | 9b520d8 | 2014-11-04 15:54:11 +0200 | [diff] [blame] | 1467 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
| 1468 | return 0; |
| 1469 | |
| 1470 | if (iwl_mvm_is_radio_killed(mvm)) { |
| 1471 | ieee80211_scan_completed(mvm->hw, true); |
| 1472 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 1473 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
David Spinadel | fb98be5 | 2014-05-04 12:51:10 +0300 | [diff] [blame] | 1477 | if (mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_LMAC_SCAN) |
| 1478 | return iwl_mvm_scan_offload_stop(mvm, true); |
| 1479 | return iwl_mvm_cancel_regular_scan(mvm); |
| 1480 | } |