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 | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | |
| 64 | #include <linux/etherdevice.h> |
| 65 | #include <net/mac80211.h> |
| 66 | |
| 67 | #include "mvm.h" |
| 68 | #include "iwl-eeprom-parse.h" |
| 69 | #include "fw-api-scan.h" |
| 70 | |
| 71 | #define IWL_PLCP_QUIET_THRESH 1 |
| 72 | #define IWL_ACTIVE_QUIET_TIME 10 |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 73 | |
| 74 | struct iwl_mvm_scan_params { |
| 75 | u32 max_out_time; |
| 76 | u32 suspend_time; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 77 | bool passive_fragmented; |
| 78 | struct _dwell { |
| 79 | u16 passive; |
| 80 | u16 active; |
| 81 | } dwell[IEEE80211_NUM_BANDS]; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 82 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 83 | |
| 84 | static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm) |
| 85 | { |
| 86 | u16 rx_chain; |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 87 | u8 rx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 88 | |
Oren Givon | 91b05d1 | 2013-08-19 08:36:48 +0300 | [diff] [blame] | 89 | if (mvm->scan_rx_ant != ANT_NONE) |
| 90 | rx_ant = mvm->scan_rx_ant; |
| 91 | else |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 92 | rx_ant = mvm->fw->valid_rx_ant; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 93 | rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS; |
| 94 | rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS; |
| 95 | rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS; |
| 96 | rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS; |
| 97 | return cpu_to_le16(rx_chain); |
| 98 | } |
| 99 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 100 | static inline __le32 |
| 101 | iwl_mvm_scan_rxon_flags(struct cfg80211_scan_request *req) |
| 102 | { |
| 103 | if (req->channels[0]->band == IEEE80211_BAND_2GHZ) |
| 104 | return cpu_to_le32(PHY_BAND_24); |
| 105 | else |
| 106 | return cpu_to_le32(PHY_BAND_5); |
| 107 | } |
| 108 | |
| 109 | static inline __le32 |
| 110 | iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band, |
| 111 | bool no_cck) |
| 112 | { |
| 113 | u32 tx_ant; |
| 114 | |
| 115 | mvm->scan_last_antenna_idx = |
Johannes Berg | 4ed735e | 2014-02-12 21:47:44 +0100 | [diff] [blame] | 116 | iwl_mvm_next_antenna(mvm, mvm->fw->valid_tx_ant, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 117 | mvm->scan_last_antenna_idx); |
| 118 | tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS; |
| 119 | |
| 120 | if (band == IEEE80211_BAND_2GHZ && !no_cck) |
| 121 | return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK | |
| 122 | tx_ant); |
| 123 | else |
| 124 | return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant); |
| 125 | } |
| 126 | |
| 127 | /* |
| 128 | * We insert the SSIDs in an inverted order, because the FW will |
| 129 | * invert it back. The most prioritized SSID, which is first in the |
| 130 | * request list, is not copied here, but inserted directly to the probe |
| 131 | * request. |
| 132 | */ |
| 133 | static void iwl_mvm_scan_fill_ssids(struct iwl_scan_cmd *cmd, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 134 | struct cfg80211_scan_request *req, |
| 135 | int first) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 136 | { |
| 137 | int fw_idx, req_idx; |
| 138 | |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 139 | for (req_idx = req->n_ssids - 1, fw_idx = 0; req_idx >= first; |
David Spinadel | fe04e83 | 2013-07-04 15:17:48 +0300 | [diff] [blame] | 140 | req_idx--, fw_idx++) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 141 | cmd->direct_scan[fw_idx].id = WLAN_EID_SSID; |
| 142 | cmd->direct_scan[fw_idx].len = req->ssids[req_idx].ssid_len; |
| 143 | memcpy(cmd->direct_scan[fw_idx].ssid, |
| 144 | req->ssids[req_idx].ssid, |
| 145 | req->ssids[req_idx].ssid_len); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | /* |
| 150 | * If req->n_ssids > 0, it means we should do an active scan. |
| 151 | * In case of active scan w/o directed scan, we receive a zero-length SSID |
| 152 | * just to notify that this scan is active and not passive. |
| 153 | * In order to notify the FW of the number of SSIDs we wish to scan (including |
| 154 | * the zero-length one), we need to set the corresponding bits in chan->type, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 155 | * one for each SSID, and set the active bit (first). If the first SSID is |
| 156 | * already included in the probe template, so we need to set only |
| 157 | * req->n_ssids - 1 bits in addition to the first bit. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 158 | */ |
| 159 | static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids) |
| 160 | { |
| 161 | if (band == IEEE80211_BAND_2GHZ) |
| 162 | return 30 + 3 * (n_ssids + 1); |
| 163 | return 20 + 2 * (n_ssids + 1); |
| 164 | } |
| 165 | |
| 166 | static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band) |
| 167 | { |
| 168 | return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10; |
| 169 | } |
| 170 | |
| 171 | static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd, |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 172 | struct cfg80211_scan_request *req, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 173 | bool basic_ssid, |
| 174 | struct iwl_mvm_scan_params *params) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 175 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 176 | struct iwl_scan_channel *chan = (struct iwl_scan_channel *) |
| 177 | (cmd->data + le16_to_cpu(cmd->tx_cmd.len)); |
| 178 | int i; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 179 | int type = BIT(req->n_ssids) - 1; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 180 | enum ieee80211_band band = req->channels[0]->band; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 181 | |
| 182 | if (!basic_ssid) |
| 183 | type |= BIT(req->n_ssids); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 184 | |
| 185 | for (i = 0; i < cmd->channel_count; i++) { |
| 186 | chan->channel = cpu_to_le16(req->channels[i]->hw_value); |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 187 | chan->type = cpu_to_le32(type); |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 188 | if (req->channels[i]->flags & IEEE80211_CHAN_NO_IR) |
David Spinadel | bb963c4 | 2013-07-23 14:13:32 +0300 | [diff] [blame] | 189 | chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 190 | chan->active_dwell = cpu_to_le16(params->dwell[band].active); |
| 191 | chan->passive_dwell = cpu_to_le16(params->dwell[band].passive); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 192 | chan->iteration_count = cpu_to_le16(1); |
| 193 | chan++; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Fill in probe request with the following parameters: |
| 199 | * TA is our vif HW address, which mac80211 ensures we have. |
| 200 | * Packet is broadcasted, so this is both SA and DA. |
| 201 | * The probe request IE is made out of two: first comes the most prioritized |
| 202 | * SSID if a directed scan is requested. Second comes whatever extra |
| 203 | * information was given to us as the scan request IE. |
| 204 | */ |
| 205 | static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta, |
| 206 | int n_ssids, const u8 *ssid, int ssid_len, |
| 207 | const u8 *ie, int ie_len, |
| 208 | int left) |
| 209 | { |
| 210 | int len = 0; |
| 211 | u8 *pos = NULL; |
| 212 | |
| 213 | /* Make sure there is enough space for the probe request, |
| 214 | * two mandatory IEs and the data */ |
| 215 | left -= 24; |
| 216 | if (left < 0) |
| 217 | return 0; |
| 218 | |
| 219 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 220 | eth_broadcast_addr(frame->da); |
| 221 | memcpy(frame->sa, ta, ETH_ALEN); |
| 222 | eth_broadcast_addr(frame->bssid); |
| 223 | frame->seq_ctrl = 0; |
| 224 | |
| 225 | len += 24; |
| 226 | |
| 227 | /* for passive scans, no need to fill anything */ |
| 228 | if (n_ssids == 0) |
| 229 | return (u16)len; |
| 230 | |
| 231 | /* points to the payload of the request */ |
| 232 | pos = &frame->u.probe_req.variable[0]; |
| 233 | |
| 234 | /* fill in our SSID IE */ |
| 235 | left -= ssid_len + 2; |
| 236 | if (left < 0) |
| 237 | return 0; |
| 238 | *pos++ = WLAN_EID_SSID; |
| 239 | *pos++ = ssid_len; |
| 240 | if (ssid && ssid_len) { /* ssid_len may be == 0 even if ssid is valid */ |
| 241 | memcpy(pos, ssid, ssid_len); |
| 242 | pos += ssid_len; |
| 243 | } |
| 244 | |
| 245 | len += ssid_len + 2; |
| 246 | |
| 247 | if (WARN_ON(left < ie_len)) |
| 248 | return len; |
| 249 | |
| 250 | if (ie && ie_len) { |
| 251 | memcpy(pos, ie, ie_len); |
| 252 | len += ie_len; |
| 253 | } |
| 254 | |
| 255 | return (u16)len; |
| 256 | } |
| 257 | |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 258 | static void iwl_mvm_scan_condition_iterator(void *data, u8 *mac, |
| 259 | struct ieee80211_vif *vif) |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 260 | { |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 261 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 262 | bool *global_bound = data; |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 263 | |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 264 | if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < MAX_PHYS) |
| 265 | *global_bound = true; |
| 266 | } |
| 267 | |
| 268 | static void iwl_mvm_scan_calc_params(struct iwl_mvm *mvm, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 269 | struct ieee80211_vif *vif, |
| 270 | int n_ssids, |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 271 | struct iwl_mvm_scan_params *params) |
| 272 | { |
| 273 | bool global_bound = false; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 274 | enum ieee80211_band band; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 275 | |
| 276 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 277 | IEEE80211_IFACE_ITER_NORMAL, |
| 278 | iwl_mvm_scan_condition_iterator, |
| 279 | &global_bound); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 280 | |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 281 | if (!global_bound) |
| 282 | goto not_bound; |
| 283 | |
| 284 | params->suspend_time = 100; |
| 285 | params->max_out_time = 600; |
| 286 | |
| 287 | if (iwl_mvm_low_latency(mvm)) { |
| 288 | params->suspend_time = 250; |
| 289 | params->max_out_time = 250; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 292 | not_bound: |
| 293 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 294 | for (band = IEEE80211_BAND_2GHZ; band < IEEE80211_NUM_BANDS; band++) { |
Alexander Bondar | ef67f18d | 2014-03-30 10:47:08 +0300 | [diff] [blame] | 295 | params->dwell[band].passive = iwl_mvm_get_passive_dwell(band); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 296 | params->dwell[band].active = iwl_mvm_get_active_dwell(band, |
| 297 | n_ssids); |
| 298 | } |
Haim Dreyfuss | 61f6325 | 2013-11-03 23:02:59 +0200 | [diff] [blame] | 299 | } |
| 300 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 301 | int iwl_mvm_scan_request(struct iwl_mvm *mvm, |
| 302 | struct ieee80211_vif *vif, |
| 303 | struct cfg80211_scan_request *req) |
| 304 | { |
| 305 | struct iwl_host_cmd hcmd = { |
| 306 | .id = SCAN_REQUEST_CMD, |
| 307 | .len = { 0, }, |
| 308 | .data = { mvm->scan_cmd, }, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 309 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 310 | }; |
| 311 | struct iwl_scan_cmd *cmd = mvm->scan_cmd; |
| 312 | int ret; |
| 313 | u32 status; |
| 314 | int ssid_len = 0; |
| 315 | u8 *ssid = NULL; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 316 | bool basic_ssid = !(mvm->fw->ucode_capa.flags & |
| 317 | IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 318 | struct iwl_mvm_scan_params params = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 319 | |
| 320 | lockdep_assert_held(&mvm->mutex); |
Emmanuel Grumbach | 748fa67c | 2014-03-27 10:06:29 +0200 | [diff] [blame] | 321 | |
| 322 | /* we should have failed registration if scan_cmd was NULL */ |
| 323 | if (WARN_ON(mvm->scan_cmd == NULL)) |
| 324 | return -ENOMEM; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 325 | |
| 326 | IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n"); |
| 327 | mvm->scan_status = IWL_MVM_SCAN_OS; |
David Spinadel | 0564679 | 2014-06-02 09:59:49 +0300 | [diff] [blame^] | 328 | memset(cmd, 0, ksize(cmd)); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 329 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 330 | cmd->channel_count = (u8)req->n_channels; |
| 331 | cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); |
| 332 | cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); |
| 333 | cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 334 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 335 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, ¶ms); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 336 | cmd->max_out_time = cpu_to_le32(params.max_out_time); |
| 337 | cmd->suspend_time = cpu_to_le32(params.suspend_time); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 338 | if (params.passive_fragmented) |
| 339 | cmd->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN; |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 340 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 341 | cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req); |
| 342 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 343 | MAC_FILTER_IN_BEACON); |
Ilan Peer | d91b06d | 2013-02-11 08:50:45 +0200 | [diff] [blame] | 344 | |
| 345 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
| 346 | cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED); |
| 347 | else |
| 348 | cmd->type = cpu_to_le32(SCAN_TYPE_FORCED); |
| 349 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 350 | cmd->repeats = cpu_to_le32(1); |
| 351 | |
| 352 | /* |
| 353 | * If the user asked for passive scan, don't change to active scan if |
| 354 | * you see any activity on the channel - remain passive. |
| 355 | */ |
| 356 | if (req->n_ssids > 0) { |
| 357 | cmd->passive2active = cpu_to_le16(1); |
David Spinadel | 26e05cc | 2013-07-08 13:12:29 +0300 | [diff] [blame] | 358 | cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE; |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 359 | if (basic_ssid) { |
| 360 | ssid = req->ssids[0].ssid; |
| 361 | ssid_len = req->ssids[0].ssid_len; |
| 362 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 363 | } else { |
| 364 | cmd->passive2active = 0; |
David Spinadel | 26e05cc | 2013-07-08 13:12:29 +0300 | [diff] [blame] | 365 | cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 366 | } |
| 367 | |
David Spinadel | 20f1a5d | 2013-08-21 09:14:27 +0300 | [diff] [blame] | 368 | iwl_mvm_scan_fill_ssids(cmd, req, basic_ssid ? 1 : 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 369 | |
Emmanuel Grumbach | 8e2a866 | 2014-01-28 12:27:31 +0200 | [diff] [blame] | 370 | cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL | |
| 371 | TX_CMD_FLG_BT_DIS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 372 | cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id; |
| 373 | cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 374 | cmd->tx_cmd.rate_n_flags = |
| 375 | iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band, |
| 376 | req->no_cck); |
| 377 | |
| 378 | cmd->tx_cmd.len = |
| 379 | cpu_to_le16(iwl_mvm_fill_probe_req( |
| 380 | (struct ieee80211_mgmt *)cmd->data, |
| 381 | vif->addr, |
| 382 | req->n_ssids, ssid, ssid_len, |
| 383 | req->ie, req->ie_len, |
| 384 | mvm->fw->ucode_capa.max_probe_length)); |
| 385 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 386 | iwl_mvm_scan_fill_channels(cmd, req, basic_ssid, ¶ms); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 387 | |
| 388 | cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) + |
| 389 | le16_to_cpu(cmd->tx_cmd.len) + |
| 390 | (cmd->channel_count * sizeof(struct iwl_scan_channel))); |
| 391 | hcmd.len[0] = le16_to_cpu(cmd->len); |
| 392 | |
| 393 | status = SCAN_RESPONSE_OK; |
| 394 | ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status); |
| 395 | if (!ret && status == SCAN_RESPONSE_OK) { |
| 396 | IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n"); |
| 397 | } else { |
| 398 | /* |
| 399 | * If the scan failed, it usually means that the FW was unable |
| 400 | * to allocate the time events. Warn on it, but maybe we |
| 401 | * should try to send the command again with different params. |
| 402 | */ |
| 403 | IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n", |
| 404 | status, ret); |
| 405 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 406 | ret = -EIO; |
| 407 | } |
| 408 | return ret; |
| 409 | } |
| 410 | |
| 411 | int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 412 | struct iwl_device_cmd *cmd) |
| 413 | { |
| 414 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 415 | struct iwl_cmd_response *resp = (void *)pkt->data; |
| 416 | |
| 417 | IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n", |
| 418 | le32_to_cpu(resp->status)); |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, |
| 423 | struct iwl_device_cmd *cmd) |
| 424 | { |
| 425 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 426 | struct iwl_scan_complete_notif *notif = (void *)pkt->data; |
| 427 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 428 | lockdep_assert_held(&mvm->mutex); |
| 429 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 430 | IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n", |
| 431 | notif->status, notif->scanned_channels); |
| 432 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 433 | if (mvm->scan_status == IWL_MVM_SCAN_OS) |
| 434 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 435 | ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK); |
| 436 | |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 437 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
| 438 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 439 | return 0; |
| 440 | } |
| 441 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 442 | int iwl_mvm_rx_sched_scan_results(struct iwl_mvm *mvm, |
| 443 | struct iwl_rx_cmd_buffer *rxb, |
| 444 | struct iwl_device_cmd *cmd) |
| 445 | { |
| 446 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 447 | struct iwl_sched_scan_results *notif = (void *)pkt->data; |
| 448 | |
| 449 | if (notif->client_bitmap & SCAN_CLIENT_SCHED_SCAN) { |
| 450 | IWL_DEBUG_SCAN(mvm, "Scheduled scan results\n"); |
| 451 | ieee80211_sched_scan_results(mvm->hw); |
| 452 | } |
| 453 | |
| 454 | return 0; |
| 455 | } |
| 456 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 457 | static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait, |
| 458 | struct iwl_rx_packet *pkt, void *data) |
| 459 | { |
| 460 | struct iwl_mvm *mvm = |
| 461 | container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 462 | struct iwl_scan_complete_notif *notif; |
| 463 | u32 *resp; |
| 464 | |
| 465 | switch (pkt->hdr.cmd) { |
| 466 | case SCAN_ABORT_CMD: |
| 467 | resp = (void *)pkt->data; |
| 468 | if (*resp == CAN_ABORT_STATUS) { |
| 469 | IWL_DEBUG_SCAN(mvm, |
| 470 | "Scan can be aborted, wait until completion\n"); |
| 471 | return false; |
| 472 | } |
| 473 | |
Emmanuel Grumbach | 5a3e9f7 | 2013-09-15 14:39:02 +0300 | [diff] [blame] | 474 | /* |
| 475 | * If scan cannot be aborted, it means that we had a |
| 476 | * SCAN_COMPLETE_NOTIFICATION in the pipe and it called |
| 477 | * ieee80211_scan_completed already. |
| 478 | */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 479 | IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n", |
| 480 | *resp); |
| 481 | return true; |
| 482 | |
| 483 | case SCAN_COMPLETE_NOTIFICATION: |
| 484 | notif = (void *)pkt->data; |
| 485 | IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n", |
| 486 | notif->status); |
| 487 | return true; |
| 488 | |
| 489 | default: |
| 490 | WARN_ON(1); |
| 491 | return false; |
| 492 | }; |
| 493 | } |
| 494 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 495 | int iwl_mvm_cancel_scan(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 496 | { |
| 497 | struct iwl_notification_wait wait_scan_abort; |
| 498 | static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD, |
| 499 | SCAN_COMPLETE_NOTIFICATION }; |
| 500 | int ret; |
| 501 | |
Emmanuel Grumbach | 5a3e9f7 | 2013-09-15 14:39:02 +0300 | [diff] [blame] | 502 | if (mvm->scan_status == IWL_MVM_SCAN_NONE) |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 503 | return 0; |
Emmanuel Grumbach | 5a3e9f7 | 2013-09-15 14:39:02 +0300 | [diff] [blame] | 504 | |
Emmanuel Grumbach | aaa4e74 | 2013-12-19 22:20:58 +0200 | [diff] [blame] | 505 | if (iwl_mvm_is_radio_killed(mvm)) { |
| 506 | ieee80211_scan_completed(mvm->hw, true); |
Arik Nemtsov | 519e202 | 2013-10-17 17:51:35 +0300 | [diff] [blame] | 507 | iwl_mvm_unref(mvm, IWL_MVM_REF_SCAN); |
Emmanuel Grumbach | aaa4e74 | 2013-12-19 22:20:58 +0200 | [diff] [blame] | 508 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 509 | return 0; |
Emmanuel Grumbach | aaa4e74 | 2013-12-19 22:20:58 +0200 | [diff] [blame] | 510 | } |
| 511 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 512 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, |
| 513 | scan_abort_notif, |
| 514 | ARRAY_SIZE(scan_abort_notif), |
| 515 | iwl_mvm_scan_abort_notif, NULL); |
| 516 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 517 | 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] | 518 | if (ret) { |
| 519 | IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret); |
David Spinadel | 992f81f | 2014-01-09 14:22:55 +0200 | [diff] [blame] | 520 | /* mac80211's state will be cleaned in the nic_restart flow */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 521 | goto out_remove_notif; |
| 522 | } |
| 523 | |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 524 | return iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, HZ); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 525 | |
| 526 | out_remove_notif: |
| 527 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort); |
Arik Nemtsov | 91b8025 | 2014-02-10 12:49:39 +0200 | [diff] [blame] | 528 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 529 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 530 | |
| 531 | int iwl_mvm_rx_scan_offload_complete_notif(struct iwl_mvm *mvm, |
| 532 | struct iwl_rx_cmd_buffer *rxb, |
| 533 | struct iwl_device_cmd *cmd) |
| 534 | { |
| 535 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 536 | struct iwl_scan_offload_complete *scan_notif = (void *)pkt->data; |
| 537 | |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 538 | /* scan status must be locked for proper checking */ |
| 539 | lockdep_assert_held(&mvm->mutex); |
| 540 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 541 | IWL_DEBUG_SCAN(mvm, |
| 542 | "Scheduled scan completed, status %s EBS status %s:%d\n", |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 543 | scan_notif->status == IWL_SCAN_OFFLOAD_COMPLETED ? |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 544 | "completed" : "aborted", scan_notif->ebs_status == |
| 545 | IWL_SCAN_EBS_SUCCESS ? "success" : "failed", |
| 546 | scan_notif->ebs_status); |
| 547 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 548 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 549 | /* only call mac80211 completion if the stop was initiated by FW */ |
| 550 | if (mvm->scan_status == IWL_MVM_SCAN_SCHED) { |
Johannes Berg | a6623e8 | 2014-01-27 15:40:53 +0100 | [diff] [blame] | 551 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 552 | ieee80211_sched_scan_stopped(mvm->hw); |
| 553 | } |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 554 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 555 | mvm->last_ebs_successful = !scan_notif->ebs_status; |
| 556 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | static void iwl_scan_offload_build_tx_cmd(struct iwl_mvm *mvm, |
| 561 | struct ieee80211_vif *vif, |
| 562 | struct ieee80211_sched_scan_ies *ies, |
| 563 | enum ieee80211_band band, |
| 564 | struct iwl_tx_cmd *cmd, |
| 565 | u8 *data) |
| 566 | { |
| 567 | u16 cmd_len; |
| 568 | |
| 569 | cmd->tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL); |
| 570 | cmd->life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); |
| 571 | cmd->sta_id = mvm->aux_sta.sta_id; |
| 572 | |
| 573 | cmd->rate_n_flags = iwl_mvm_scan_rate_n_flags(mvm, band, false); |
| 574 | |
| 575 | cmd_len = iwl_mvm_fill_probe_req((struct ieee80211_mgmt *)data, |
| 576 | vif->addr, |
| 577 | 1, NULL, 0, |
| 578 | ies->ie[band], ies->len[band], |
| 579 | SCAN_OFFLOAD_PROBE_REQ_SIZE); |
| 580 | cmd->len = cpu_to_le16(cmd_len); |
| 581 | } |
| 582 | |
| 583 | static void iwl_build_scan_cmd(struct iwl_mvm *mvm, |
| 584 | struct ieee80211_vif *vif, |
| 585 | struct cfg80211_sched_scan_request *req, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 586 | struct iwl_scan_offload_cmd *scan, |
| 587 | struct iwl_mvm_scan_params *params) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 588 | { |
| 589 | scan->channel_count = |
| 590 | mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels + |
| 591 | mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels; |
| 592 | scan->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); |
| 593 | scan->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); |
| 594 | scan->good_CRC_th = IWL_GOOD_CRC_TH_DEFAULT; |
| 595 | scan->rx_chain = iwl_mvm_scan_rx_chain(mvm); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 596 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 597 | scan->max_out_time = cpu_to_le32(params->max_out_time); |
| 598 | scan->suspend_time = cpu_to_le32(params->suspend_time); |
Alexander Bondar | 8a110d9 | 2014-03-12 17:31:19 +0200 | [diff] [blame] | 599 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 600 | scan->filter_flags |= cpu_to_le32(MAC_FILTER_ACCEPT_GRP | |
| 601 | MAC_FILTER_IN_BEACON); |
| 602 | scan->scan_type = cpu_to_le32(SCAN_TYPE_BACKGROUND); |
| 603 | scan->rep_count = cpu_to_le32(1); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 604 | |
| 605 | if (params->passive_fragmented) |
| 606 | scan->scan_flags |= SCAN_FLAGS_FRAGMENTED_SCAN; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | static int iwl_ssid_exist(u8 *ssid, u8 ssid_len, struct iwl_ssid_ie *ssid_list) |
| 610 | { |
| 611 | int i; |
| 612 | |
| 613 | for (i = 0; i < PROBE_OPTION_MAX; i++) { |
| 614 | if (!ssid_list[i].len) |
| 615 | break; |
| 616 | if (ssid_list[i].len == ssid_len && |
| 617 | !memcmp(ssid_list->ssid, ssid, ssid_len)) |
| 618 | return i; |
| 619 | } |
| 620 | return -1; |
| 621 | } |
| 622 | |
| 623 | static void iwl_scan_offload_build_ssid(struct cfg80211_sched_scan_request *req, |
| 624 | struct iwl_scan_offload_cmd *scan, |
| 625 | u32 *ssid_bitmap) |
| 626 | { |
| 627 | int i, j; |
| 628 | int index; |
| 629 | |
| 630 | /* |
| 631 | * copy SSIDs from match list. |
| 632 | * iwl_config_sched_scan_profiles() uses the order of these ssids to |
| 633 | * config match list. |
| 634 | */ |
| 635 | 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] | 636 | /* skip empty SSID matchsets */ |
| 637 | if (!req->match_sets[i].ssid.ssid_len) |
| 638 | continue; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 639 | scan->direct_scan[i].id = WLAN_EID_SSID; |
| 640 | scan->direct_scan[i].len = req->match_sets[i].ssid.ssid_len; |
| 641 | memcpy(scan->direct_scan[i].ssid, req->match_sets[i].ssid.ssid, |
| 642 | scan->direct_scan[i].len); |
| 643 | } |
| 644 | |
| 645 | /* add SSIDs from scan SSID list */ |
| 646 | *ssid_bitmap = 0; |
| 647 | for (j = 0; j < req->n_ssids && i < PROBE_OPTION_MAX; j++) { |
| 648 | index = iwl_ssid_exist(req->ssids[j].ssid, |
| 649 | req->ssids[j].ssid_len, |
| 650 | scan->direct_scan); |
| 651 | if (index < 0) { |
| 652 | if (!req->ssids[j].ssid_len) |
| 653 | continue; |
| 654 | scan->direct_scan[i].id = WLAN_EID_SSID; |
| 655 | scan->direct_scan[i].len = req->ssids[j].ssid_len; |
| 656 | memcpy(scan->direct_scan[i].ssid, req->ssids[j].ssid, |
| 657 | scan->direct_scan[i].len); |
| 658 | *ssid_bitmap |= BIT(i + 1); |
| 659 | i++; |
| 660 | } else { |
| 661 | *ssid_bitmap |= BIT(index + 1); |
| 662 | } |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | static void iwl_build_channel_cfg(struct iwl_mvm *mvm, |
| 667 | struct cfg80211_sched_scan_request *req, |
| 668 | struct iwl_scan_channel_cfg *channels, |
| 669 | enum ieee80211_band band, |
| 670 | int *head, int *tail, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 671 | u32 ssid_bitmap, |
| 672 | struct iwl_mvm_scan_params *params) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 673 | { |
| 674 | struct ieee80211_supported_band *s_band; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 675 | int n_channels = req->n_channels; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 676 | int i, j, index = 0; |
| 677 | bool partial; |
| 678 | |
| 679 | /* |
| 680 | * We have to configure all supported channels, even if we don't want to |
| 681 | * scan on them, but we have to send channels in the order that we want |
| 682 | * to scan. So add requested channels to head of the list and others to |
| 683 | * the end. |
| 684 | */ |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 685 | s_band = &mvm->nvm_data->bands[band]; |
| 686 | |
| 687 | for (i = 0; i < s_band->n_channels && *head <= *tail; i++) { |
| 688 | partial = false; |
| 689 | for (j = 0; j < n_channels; j++) |
| 690 | if (s_band->channels[i].center_freq == |
| 691 | req->channels[j]->center_freq) { |
| 692 | index = *head; |
| 693 | (*head)++; |
| 694 | /* |
| 695 | * Channels that came with the request will be |
| 696 | * in partial scan . |
| 697 | */ |
| 698 | partial = true; |
| 699 | break; |
| 700 | } |
| 701 | if (!partial) { |
| 702 | index = *tail; |
| 703 | (*tail)--; |
| 704 | } |
| 705 | channels->channel_number[index] = |
| 706 | cpu_to_le16(ieee80211_frequency_to_channel( |
| 707 | s_band->channels[i].center_freq)); |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 708 | channels->dwell_time[index][0] = params->dwell[band].active; |
| 709 | channels->dwell_time[index][1] = params->dwell[band].passive; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 710 | |
| 711 | channels->iter_count[index] = cpu_to_le16(1); |
| 712 | channels->iter_interval[index] = 0; |
| 713 | |
Luis R. Rodriguez | 8fe02e1 | 2013-10-21 19:22:25 +0200 | [diff] [blame] | 714 | if (!(s_band->channels[i].flags & IEEE80211_CHAN_NO_IR)) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 715 | channels->type[index] |= |
| 716 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_ACTIVE); |
| 717 | |
| 718 | channels->type[index] |= |
| 719 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_FULL); |
| 720 | if (partial) |
| 721 | channels->type[index] |= |
| 722 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_PARTIAL); |
| 723 | |
| 724 | if (s_band->channels[i].flags & IEEE80211_CHAN_NO_HT40) |
| 725 | channels->type[index] |= |
| 726 | cpu_to_le32(IWL_SCAN_OFFLOAD_CHANNEL_NARROW); |
| 727 | |
| 728 | /* scan for all SSIDs from req->ssids */ |
| 729 | channels->type[index] |= cpu_to_le32(ssid_bitmap); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | int iwl_mvm_config_sched_scan(struct iwl_mvm *mvm, |
| 734 | struct ieee80211_vif *vif, |
| 735 | struct cfg80211_sched_scan_request *req, |
| 736 | struct ieee80211_sched_scan_ies *ies) |
| 737 | { |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 738 | int band_2ghz = mvm->nvm_data->bands[IEEE80211_BAND_2GHZ].n_channels; |
| 739 | int band_5ghz = mvm->nvm_data->bands[IEEE80211_BAND_5GHZ].n_channels; |
| 740 | int head = 0; |
Eliad Peller | 6479311 | 2014-05-11 19:59:43 +0300 | [diff] [blame] | 741 | int tail = band_2ghz + band_5ghz - 1; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 742 | u32 ssid_bitmap; |
| 743 | int cmd_len; |
| 744 | int ret; |
| 745 | |
| 746 | struct iwl_scan_offload_cfg *scan_cfg; |
| 747 | struct iwl_host_cmd cmd = { |
| 748 | .id = SCAN_OFFLOAD_CONFIG_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 749 | }; |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 750 | struct iwl_mvm_scan_params params = {}; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 751 | |
| 752 | lockdep_assert_held(&mvm->mutex); |
| 753 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 754 | cmd_len = sizeof(struct iwl_scan_offload_cfg) + |
Emmanuel Grumbach | 6609253 | 2014-02-20 14:58:30 +0200 | [diff] [blame] | 755 | 2 * SCAN_OFFLOAD_PROBE_REQ_SIZE; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 756 | |
| 757 | scan_cfg = kzalloc(cmd_len, GFP_KERNEL); |
| 758 | if (!scan_cfg) |
| 759 | return -ENOMEM; |
| 760 | |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 761 | iwl_mvm_scan_calc_params(mvm, vif, req->n_ssids, ¶ms); |
| 762 | iwl_build_scan_cmd(mvm, vif, req, &scan_cfg->scan_cmd, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 763 | scan_cfg->scan_cmd.len = cpu_to_le16(cmd_len); |
| 764 | |
| 765 | iwl_scan_offload_build_ssid(req, &scan_cfg->scan_cmd, &ssid_bitmap); |
| 766 | /* build tx frames for supported bands */ |
| 767 | if (band_2ghz) { |
| 768 | iwl_scan_offload_build_tx_cmd(mvm, vif, ies, |
| 769 | IEEE80211_BAND_2GHZ, |
| 770 | &scan_cfg->scan_cmd.tx_cmd[0], |
| 771 | scan_cfg->data); |
| 772 | iwl_build_channel_cfg(mvm, req, &scan_cfg->channel_cfg, |
| 773 | IEEE80211_BAND_2GHZ, &head, &tail, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 774 | ssid_bitmap, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 775 | } |
| 776 | if (band_5ghz) { |
| 777 | iwl_scan_offload_build_tx_cmd(mvm, vif, ies, |
| 778 | IEEE80211_BAND_5GHZ, |
| 779 | &scan_cfg->scan_cmd.tx_cmd[1], |
| 780 | scan_cfg->data + |
| 781 | SCAN_OFFLOAD_PROBE_REQ_SIZE); |
| 782 | iwl_build_channel_cfg(mvm, req, &scan_cfg->channel_cfg, |
| 783 | IEEE80211_BAND_5GHZ, &head, &tail, |
Alexander Bondar | 50df8a3 | 2014-03-12 20:30:51 +0200 | [diff] [blame] | 784 | ssid_bitmap, ¶ms); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | cmd.data[0] = scan_cfg; |
| 788 | cmd.len[0] = cmd_len; |
| 789 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; |
| 790 | |
| 791 | IWL_DEBUG_SCAN(mvm, "Sending scheduled scan config\n"); |
| 792 | |
| 793 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 794 | kfree(scan_cfg); |
| 795 | return ret; |
| 796 | } |
| 797 | |
| 798 | int iwl_mvm_config_sched_scan_profiles(struct iwl_mvm *mvm, |
| 799 | struct cfg80211_sched_scan_request *req) |
| 800 | { |
| 801 | struct iwl_scan_offload_profile *profile; |
| 802 | struct iwl_scan_offload_profile_cfg *profile_cfg; |
| 803 | struct iwl_scan_offload_blacklist *blacklist; |
| 804 | struct iwl_host_cmd cmd = { |
| 805 | .id = SCAN_OFFLOAD_UPDATE_PROFILES_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 806 | .len[1] = sizeof(*profile_cfg), |
| 807 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 808 | .dataflags[1] = IWL_HCMD_DFL_NOCOPY, |
| 809 | }; |
| 810 | int blacklist_len; |
| 811 | int i; |
| 812 | int ret; |
| 813 | |
| 814 | if (WARN_ON(req->n_match_sets > IWL_SCAN_MAX_PROFILES)) |
| 815 | return -EIO; |
| 816 | |
| 817 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_SHORT_BL) |
| 818 | blacklist_len = IWL_SCAN_SHORT_BLACKLIST_LEN; |
| 819 | else |
| 820 | blacklist_len = IWL_SCAN_MAX_BLACKLIST_LEN; |
| 821 | |
| 822 | blacklist = kzalloc(sizeof(*blacklist) * blacklist_len, GFP_KERNEL); |
| 823 | if (!blacklist) |
| 824 | return -ENOMEM; |
| 825 | |
| 826 | profile_cfg = kzalloc(sizeof(*profile_cfg), GFP_KERNEL); |
| 827 | if (!profile_cfg) { |
| 828 | ret = -ENOMEM; |
| 829 | goto free_blacklist; |
| 830 | } |
| 831 | |
| 832 | cmd.data[0] = blacklist; |
| 833 | cmd.len[0] = sizeof(*blacklist) * blacklist_len; |
| 834 | cmd.data[1] = profile_cfg; |
| 835 | |
| 836 | /* No blacklist configuration */ |
| 837 | |
| 838 | profile_cfg->num_profiles = req->n_match_sets; |
| 839 | profile_cfg->active_clients = SCAN_CLIENT_SCHED_SCAN; |
| 840 | profile_cfg->pass_match = SCAN_CLIENT_SCHED_SCAN; |
| 841 | profile_cfg->match_notify = SCAN_CLIENT_SCHED_SCAN; |
David Spinadel | 6e0bbe5 | 2013-12-30 09:59:45 +0200 | [diff] [blame] | 842 | if (!req->n_match_sets || !req->match_sets[0].ssid.ssid_len) |
| 843 | profile_cfg->any_beacon_notify = SCAN_CLIENT_SCHED_SCAN; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 844 | |
| 845 | for (i = 0; i < req->n_match_sets; i++) { |
| 846 | profile = &profile_cfg->profiles[i]; |
| 847 | profile->ssid_index = i; |
| 848 | /* Support any cipher and auth algorithm */ |
| 849 | profile->unicast_cipher = 0xff; |
| 850 | profile->auth_alg = 0xff; |
| 851 | profile->network_type = IWL_NETWORK_TYPE_ANY; |
| 852 | profile->band_selection = IWL_SCAN_OFFLOAD_SELECT_ANY; |
| 853 | profile->client_bitmap = SCAN_CLIENT_SCHED_SCAN; |
| 854 | } |
| 855 | |
| 856 | IWL_DEBUG_SCAN(mvm, "Sending scheduled scan profile config\n"); |
| 857 | |
| 858 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 859 | kfree(profile_cfg); |
| 860 | free_blacklist: |
| 861 | kfree(blacklist); |
| 862 | |
| 863 | return ret; |
| 864 | } |
| 865 | |
| 866 | int iwl_mvm_sched_scan_start(struct iwl_mvm *mvm, |
| 867 | struct cfg80211_sched_scan_request *req) |
| 868 | { |
| 869 | struct iwl_scan_offload_req scan_req = { |
| 870 | .watchdog = IWL_SCHED_SCAN_WATCHDOG, |
| 871 | |
| 872 | .schedule_line[0].iterations = IWL_FAST_SCHED_SCAN_ITERATIONS, |
| 873 | .schedule_line[0].delay = req->interval / 1000, |
| 874 | .schedule_line[0].full_scan_mul = 1, |
| 875 | |
| 876 | .schedule_line[1].iterations = 0xff, |
| 877 | .schedule_line[1].delay = req->interval / 1000, |
| 878 | .schedule_line[1].full_scan_mul = IWL_FULL_SCAN_MULTIPLIER, |
| 879 | }; |
| 880 | |
| 881 | if (req->n_match_sets && req->match_sets[0].ssid.ssid_len) { |
| 882 | IWL_DEBUG_SCAN(mvm, |
| 883 | "Sending scheduled scan with filtering, filter len %d\n", |
| 884 | req->n_match_sets); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 885 | } else { |
| 886 | IWL_DEBUG_SCAN(mvm, |
| 887 | "Sending Scheduled scan without filtering\n"); |
Eliad Peller | de33fb5 | 2013-11-10 12:59:46 +0200 | [diff] [blame] | 888 | scan_req.flags |= cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_PASS_ALL); |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 889 | } |
| 890 | |
Haim Dreyfuss | e820c2d | 2014-04-06 11:19:09 +0300 | [diff] [blame] | 891 | if (mvm->last_ebs_successful && |
| 892 | mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_EBS_SUPPORT) |
| 893 | scan_req.flags |= |
| 894 | cpu_to_le16(IWL_SCAN_OFFLOAD_FLAG_EBS_ACCURATE_MODE); |
| 895 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 896 | return iwl_mvm_send_cmd_pdu(mvm, SCAN_OFFLOAD_REQUEST_CMD, 0, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 897 | sizeof(scan_req), &scan_req); |
| 898 | } |
| 899 | |
| 900 | static int iwl_mvm_send_sched_scan_abort(struct iwl_mvm *mvm) |
| 901 | { |
| 902 | int ret; |
| 903 | struct iwl_host_cmd cmd = { |
| 904 | .id = SCAN_OFFLOAD_ABORT_CMD, |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 905 | }; |
| 906 | u32 status; |
| 907 | |
| 908 | /* Exit instantly with error when device is not ready |
| 909 | * to receive scan abort command or it does not perform |
| 910 | * scheduled scan currently */ |
| 911 | if (mvm->scan_status != IWL_MVM_SCAN_SCHED) |
| 912 | return -EIO; |
| 913 | |
| 914 | ret = iwl_mvm_send_cmd_status(mvm, &cmd, &status); |
| 915 | if (ret) |
| 916 | return ret; |
| 917 | |
| 918 | if (status != CAN_ABORT_STATUS) { |
| 919 | /* |
| 920 | * The scan abort will return 1 for success or |
| 921 | * 2 for "failure". A failure condition can be |
| 922 | * due to simply not being in an active scan which |
| 923 | * can occur if we send the scan abort before the |
| 924 | * microcode has notified us that a scan is completed. |
| 925 | */ |
| 926 | IWL_DEBUG_SCAN(mvm, "SCAN OFFLOAD ABORT ret %d.\n", status); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 927 | ret = -ENOENT; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | return ret; |
| 931 | } |
| 932 | |
David Spinadel | 636a2cd | 2014-05-01 15:57:22 +0300 | [diff] [blame] | 933 | int iwl_mvm_sched_scan_stop(struct iwl_mvm *mvm, bool notify) |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 934 | { |
| 935 | int ret; |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 936 | struct iwl_notification_wait wait_scan_done; |
| 937 | static const u8 scan_done_notif[] = { SCAN_OFFLOAD_COMPLETE, }; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 938 | |
| 939 | lockdep_assert_held(&mvm->mutex); |
| 940 | |
| 941 | if (mvm->scan_status != IWL_MVM_SCAN_SCHED) { |
| 942 | IWL_DEBUG_SCAN(mvm, "No offloaded scan to stop\n"); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 943 | return 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 944 | } |
| 945 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 946 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_done, |
| 947 | scan_done_notif, |
| 948 | ARRAY_SIZE(scan_done_notif), |
| 949 | NULL, NULL); |
| 950 | |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 951 | ret = iwl_mvm_send_sched_scan_abort(mvm); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 952 | if (ret) { |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 953 | IWL_DEBUG_SCAN(mvm, "Send stop offload scan failed %d\n", ret); |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 954 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_done); |
| 955 | return ret; |
| 956 | } |
| 957 | |
| 958 | IWL_DEBUG_SCAN(mvm, "Successfully sent stop offload scan\n"); |
| 959 | |
| 960 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_done, 1 * HZ); |
| 961 | if (ret) |
| 962 | return ret; |
| 963 | |
| 964 | /* |
| 965 | * Clear the scan status so the next scan requests will succeed. This |
| 966 | * also ensures the Rx handler doesn't do anything, as the scan was |
| 967 | * stopped from above. |
| 968 | */ |
| 969 | mvm->scan_status = IWL_MVM_SCAN_NONE; |
| 970 | |
David Spinadel | 636a2cd | 2014-05-01 15:57:22 +0300 | [diff] [blame] | 971 | if (notify) |
| 972 | ieee80211_sched_scan_stopped(mvm->hw); |
| 973 | |
Arik Nemtsov | 33ea27f | 2014-02-10 15:34:29 +0200 | [diff] [blame] | 974 | return 0; |
David Spinadel | 35a000b | 2013-08-28 09:29:43 +0300 | [diff] [blame] | 975 | } |