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