]>
Commit | Line | Data |
---|---|---|
8ca151b5 JB |
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 | * | |
8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
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 | |
410dc5aa | 25 | * in the file called COPYING. |
8ca151b5 JB |
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 | * | |
33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
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 | |
73 | ||
74 | static inline __le16 iwl_mvm_scan_rx_chain(struct iwl_mvm *mvm) | |
75 | { | |
76 | u16 rx_chain; | |
91b05d10 | 77 | u8 rx_ant; |
8ca151b5 | 78 | |
91b05d10 OG |
79 | if (mvm->scan_rx_ant != ANT_NONE) |
80 | rx_ant = mvm->scan_rx_ant; | |
81 | else | |
82 | rx_ant = iwl_fw_valid_rx_ant(mvm->fw); | |
8ca151b5 JB |
83 | rx_chain = rx_ant << PHY_RX_CHAIN_VALID_POS; |
84 | rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_MIMO_SEL_POS; | |
85 | rx_chain |= rx_ant << PHY_RX_CHAIN_FORCE_SEL_POS; | |
86 | rx_chain |= 0x1 << PHY_RX_CHAIN_DRIVER_FORCE_POS; | |
87 | return cpu_to_le16(rx_chain); | |
88 | } | |
89 | ||
90 | static inline __le32 iwl_mvm_scan_max_out_time(struct ieee80211_vif *vif) | |
91 | { | |
92 | if (vif->bss_conf.assoc) | |
93 | return cpu_to_le32(200 * 1024); | |
94 | else | |
95 | return 0; | |
96 | } | |
97 | ||
98 | static inline __le32 iwl_mvm_scan_suspend_time(struct ieee80211_vif *vif) | |
99 | { | |
100 | if (vif->bss_conf.assoc) | |
101 | return cpu_to_le32(vif->bss_conf.beacon_int); | |
102 | else | |
103 | return 0; | |
104 | } | |
105 | ||
106 | static inline __le32 | |
107 | iwl_mvm_scan_rxon_flags(struct cfg80211_scan_request *req) | |
108 | { | |
109 | if (req->channels[0]->band == IEEE80211_BAND_2GHZ) | |
110 | return cpu_to_le32(PHY_BAND_24); | |
111 | else | |
112 | return cpu_to_le32(PHY_BAND_5); | |
113 | } | |
114 | ||
115 | static inline __le32 | |
116 | iwl_mvm_scan_rate_n_flags(struct iwl_mvm *mvm, enum ieee80211_band band, | |
117 | bool no_cck) | |
118 | { | |
119 | u32 tx_ant; | |
120 | ||
121 | mvm->scan_last_antenna_idx = | |
33223542 | 122 | iwl_mvm_next_antenna(mvm, iwl_fw_valid_tx_ant(mvm->fw), |
8ca151b5 JB |
123 | mvm->scan_last_antenna_idx); |
124 | tx_ant = BIT(mvm->scan_last_antenna_idx) << RATE_MCS_ANT_POS; | |
125 | ||
126 | if (band == IEEE80211_BAND_2GHZ && !no_cck) | |
127 | return cpu_to_le32(IWL_RATE_1M_PLCP | RATE_MCS_CCK_MSK | | |
128 | tx_ant); | |
129 | else | |
130 | return cpu_to_le32(IWL_RATE_6M_PLCP | tx_ant); | |
131 | } | |
132 | ||
133 | /* | |
134 | * We insert the SSIDs in an inverted order, because the FW will | |
135 | * invert it back. The most prioritized SSID, which is first in the | |
136 | * request list, is not copied here, but inserted directly to the probe | |
137 | * request. | |
138 | */ | |
139 | static void iwl_mvm_scan_fill_ssids(struct iwl_scan_cmd *cmd, | |
140 | struct cfg80211_scan_request *req) | |
141 | { | |
142 | int fw_idx, req_idx; | |
143 | ||
fe04e837 DS |
144 | for (req_idx = req->n_ssids - 1, fw_idx = 0; req_idx > 0; |
145 | req_idx--, fw_idx++) { | |
8ca151b5 JB |
146 | cmd->direct_scan[fw_idx].id = WLAN_EID_SSID; |
147 | cmd->direct_scan[fw_idx].len = req->ssids[req_idx].ssid_len; | |
148 | memcpy(cmd->direct_scan[fw_idx].ssid, | |
149 | req->ssids[req_idx].ssid, | |
150 | req->ssids[req_idx].ssid_len); | |
151 | } | |
152 | } | |
153 | ||
154 | /* | |
155 | * If req->n_ssids > 0, it means we should do an active scan. | |
156 | * In case of active scan w/o directed scan, we receive a zero-length SSID | |
157 | * just to notify that this scan is active and not passive. | |
158 | * In order to notify the FW of the number of SSIDs we wish to scan (including | |
159 | * the zero-length one), we need to set the corresponding bits in chan->type, | |
a590ad41 DS |
160 | * one for each SSID, and set the active bit (first). The first SSID is already |
161 | * included in the probe template, so we need to set only req->n_ssids - 1 bits | |
162 | * in addition to the first bit. | |
8ca151b5 JB |
163 | */ |
164 | static u16 iwl_mvm_get_active_dwell(enum ieee80211_band band, int n_ssids) | |
165 | { | |
166 | if (band == IEEE80211_BAND_2GHZ) | |
167 | return 30 + 3 * (n_ssids + 1); | |
168 | return 20 + 2 * (n_ssids + 1); | |
169 | } | |
170 | ||
171 | static u16 iwl_mvm_get_passive_dwell(enum ieee80211_band band) | |
172 | { | |
173 | return band == IEEE80211_BAND_2GHZ ? 100 + 20 : 100 + 10; | |
174 | } | |
175 | ||
176 | static void iwl_mvm_scan_fill_channels(struct iwl_scan_cmd *cmd, | |
177 | struct cfg80211_scan_request *req) | |
178 | { | |
179 | u16 passive_dwell = iwl_mvm_get_passive_dwell(req->channels[0]->band); | |
180 | u16 active_dwell = iwl_mvm_get_active_dwell(req->channels[0]->band, | |
181 | req->n_ssids); | |
182 | struct iwl_scan_channel *chan = (struct iwl_scan_channel *) | |
183 | (cmd->data + le16_to_cpu(cmd->tx_cmd.len)); | |
184 | int i; | |
8ca151b5 JB |
185 | |
186 | for (i = 0; i < cmd->channel_count; i++) { | |
187 | chan->channel = cpu_to_le16(req->channels[i]->hw_value); | |
bb963c4a | 188 | chan->type = cpu_to_le32(BIT(req->n_ssids) - 1); |
8ca151b5 | 189 | if (req->channels[i]->flags & IEEE80211_CHAN_PASSIVE_SCAN) |
bb963c4a | 190 | chan->type &= cpu_to_le32(~SCAN_CHANNEL_TYPE_ACTIVE); |
8ca151b5 JB |
191 | chan->active_dwell = cpu_to_le16(active_dwell); |
192 | chan->passive_dwell = cpu_to_le16(passive_dwell); | |
193 | chan->iteration_count = cpu_to_le16(1); | |
194 | chan++; | |
195 | } | |
196 | } | |
197 | ||
198 | /* | |
199 | * Fill in probe request with the following parameters: | |
200 | * TA is our vif HW address, which mac80211 ensures we have. | |
201 | * Packet is broadcasted, so this is both SA and DA. | |
202 | * The probe request IE is made out of two: first comes the most prioritized | |
203 | * SSID if a directed scan is requested. Second comes whatever extra | |
204 | * information was given to us as the scan request IE. | |
205 | */ | |
206 | static u16 iwl_mvm_fill_probe_req(struct ieee80211_mgmt *frame, const u8 *ta, | |
207 | int n_ssids, const u8 *ssid, int ssid_len, | |
208 | const u8 *ie, int ie_len, | |
209 | int left) | |
210 | { | |
211 | int len = 0; | |
212 | u8 *pos = NULL; | |
213 | ||
214 | /* Make sure there is enough space for the probe request, | |
215 | * two mandatory IEs and the data */ | |
216 | left -= 24; | |
217 | if (left < 0) | |
218 | return 0; | |
219 | ||
220 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); | |
221 | eth_broadcast_addr(frame->da); | |
222 | memcpy(frame->sa, ta, ETH_ALEN); | |
223 | eth_broadcast_addr(frame->bssid); | |
224 | frame->seq_ctrl = 0; | |
225 | ||
226 | len += 24; | |
227 | ||
228 | /* for passive scans, no need to fill anything */ | |
229 | if (n_ssids == 0) | |
230 | return (u16)len; | |
231 | ||
232 | /* points to the payload of the request */ | |
233 | pos = &frame->u.probe_req.variable[0]; | |
234 | ||
235 | /* fill in our SSID IE */ | |
236 | left -= ssid_len + 2; | |
237 | if (left < 0) | |
238 | return 0; | |
239 | *pos++ = WLAN_EID_SSID; | |
240 | *pos++ = ssid_len; | |
241 | if (ssid && ssid_len) { /* ssid_len may be == 0 even if ssid is valid */ | |
242 | memcpy(pos, ssid, ssid_len); | |
243 | pos += ssid_len; | |
244 | } | |
245 | ||
246 | len += ssid_len + 2; | |
247 | ||
248 | if (WARN_ON(left < ie_len)) | |
249 | return len; | |
250 | ||
251 | if (ie && ie_len) { | |
252 | memcpy(pos, ie, ie_len); | |
253 | len += ie_len; | |
254 | } | |
255 | ||
256 | return (u16)len; | |
257 | } | |
258 | ||
259 | int iwl_mvm_scan_request(struct iwl_mvm *mvm, | |
260 | struct ieee80211_vif *vif, | |
261 | struct cfg80211_scan_request *req) | |
262 | { | |
263 | struct iwl_host_cmd hcmd = { | |
264 | .id = SCAN_REQUEST_CMD, | |
265 | .len = { 0, }, | |
266 | .data = { mvm->scan_cmd, }, | |
267 | .flags = CMD_SYNC, | |
268 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, | |
269 | }; | |
270 | struct iwl_scan_cmd *cmd = mvm->scan_cmd; | |
271 | int ret; | |
272 | u32 status; | |
273 | int ssid_len = 0; | |
274 | u8 *ssid = NULL; | |
275 | ||
276 | lockdep_assert_held(&mvm->mutex); | |
277 | BUG_ON(mvm->scan_cmd == NULL); | |
278 | ||
279 | IWL_DEBUG_SCAN(mvm, "Handling mac80211 scan request\n"); | |
280 | mvm->scan_status = IWL_MVM_SCAN_OS; | |
281 | memset(cmd, 0, sizeof(struct iwl_scan_cmd) + | |
282 | mvm->fw->ucode_capa.max_probe_length + | |
283 | (MAX_NUM_SCAN_CHANNELS * sizeof(struct iwl_scan_channel))); | |
284 | ||
285 | cmd->channel_count = (u8)req->n_channels; | |
286 | cmd->quiet_time = cpu_to_le16(IWL_ACTIVE_QUIET_TIME); | |
287 | cmd->quiet_plcp_th = cpu_to_le16(IWL_PLCP_QUIET_THRESH); | |
288 | cmd->rxchain_sel_flags = iwl_mvm_scan_rx_chain(mvm); | |
289 | cmd->max_out_time = iwl_mvm_scan_max_out_time(vif); | |
290 | cmd->suspend_time = iwl_mvm_scan_suspend_time(vif); | |
291 | cmd->rxon_flags = iwl_mvm_scan_rxon_flags(req); | |
292 | cmd->filter_flags = cpu_to_le32(MAC_FILTER_ACCEPT_GRP | | |
293 | MAC_FILTER_IN_BEACON); | |
d91b06d2 IP |
294 | |
295 | if (vif->type == NL80211_IFTYPE_P2P_DEVICE) | |
296 | cmd->type = cpu_to_le32(SCAN_TYPE_DISCOVERY_FORCED); | |
297 | else | |
298 | cmd->type = cpu_to_le32(SCAN_TYPE_FORCED); | |
299 | ||
8ca151b5 JB |
300 | cmd->repeats = cpu_to_le32(1); |
301 | ||
302 | /* | |
303 | * If the user asked for passive scan, don't change to active scan if | |
304 | * you see any activity on the channel - remain passive. | |
305 | */ | |
306 | if (req->n_ssids > 0) { | |
307 | cmd->passive2active = cpu_to_le16(1); | |
26e05cc3 | 308 | cmd->scan_flags |= SCAN_FLAGS_PASSIVE2ACTIVE; |
8ca151b5 JB |
309 | ssid = req->ssids[0].ssid; |
310 | ssid_len = req->ssids[0].ssid_len; | |
311 | } else { | |
312 | cmd->passive2active = 0; | |
26e05cc3 | 313 | cmd->scan_flags &= ~SCAN_FLAGS_PASSIVE2ACTIVE; |
8ca151b5 JB |
314 | } |
315 | ||
316 | iwl_mvm_scan_fill_ssids(cmd, req); | |
317 | ||
318 | cmd->tx_cmd.tx_flags = cpu_to_le32(TX_CMD_FLG_SEQ_CTL); | |
319 | cmd->tx_cmd.sta_id = mvm->aux_sta.sta_id; | |
320 | cmd->tx_cmd.life_time = cpu_to_le32(TX_CMD_LIFE_TIME_INFINITE); | |
321 | cmd->tx_cmd.rate_n_flags = | |
322 | iwl_mvm_scan_rate_n_flags(mvm, req->channels[0]->band, | |
323 | req->no_cck); | |
324 | ||
325 | cmd->tx_cmd.len = | |
326 | cpu_to_le16(iwl_mvm_fill_probe_req( | |
327 | (struct ieee80211_mgmt *)cmd->data, | |
328 | vif->addr, | |
329 | req->n_ssids, ssid, ssid_len, | |
330 | req->ie, req->ie_len, | |
331 | mvm->fw->ucode_capa.max_probe_length)); | |
332 | ||
333 | iwl_mvm_scan_fill_channels(cmd, req); | |
334 | ||
335 | cmd->len = cpu_to_le16(sizeof(struct iwl_scan_cmd) + | |
336 | le16_to_cpu(cmd->tx_cmd.len) + | |
337 | (cmd->channel_count * sizeof(struct iwl_scan_channel))); | |
338 | hcmd.len[0] = le16_to_cpu(cmd->len); | |
339 | ||
340 | status = SCAN_RESPONSE_OK; | |
341 | ret = iwl_mvm_send_cmd_status(mvm, &hcmd, &status); | |
342 | if (!ret && status == SCAN_RESPONSE_OK) { | |
343 | IWL_DEBUG_SCAN(mvm, "Scan request was sent successfully\n"); | |
344 | } else { | |
345 | /* | |
346 | * If the scan failed, it usually means that the FW was unable | |
347 | * to allocate the time events. Warn on it, but maybe we | |
348 | * should try to send the command again with different params. | |
349 | */ | |
350 | IWL_ERR(mvm, "Scan failed! status 0x%x ret %d\n", | |
351 | status, ret); | |
352 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
353 | ret = -EIO; | |
354 | } | |
355 | return ret; | |
356 | } | |
357 | ||
358 | int iwl_mvm_rx_scan_response(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, | |
359 | struct iwl_device_cmd *cmd) | |
360 | { | |
361 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
362 | struct iwl_cmd_response *resp = (void *)pkt->data; | |
363 | ||
364 | IWL_DEBUG_SCAN(mvm, "Scan response received. status 0x%x\n", | |
365 | le32_to_cpu(resp->status)); | |
366 | return 0; | |
367 | } | |
368 | ||
369 | int iwl_mvm_rx_scan_complete(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb, | |
370 | struct iwl_device_cmd *cmd) | |
371 | { | |
372 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
373 | struct iwl_scan_complete_notif *notif = (void *)pkt->data; | |
374 | ||
375 | IWL_DEBUG_SCAN(mvm, "Scan complete: status=0x%x scanned channels=%d\n", | |
376 | notif->status, notif->scanned_channels); | |
377 | ||
378 | mvm->scan_status = IWL_MVM_SCAN_NONE; | |
379 | ieee80211_scan_completed(mvm->hw, notif->status != SCAN_COMP_STATUS_OK); | |
380 | ||
381 | return 0; | |
382 | } | |
383 | ||
384 | static bool iwl_mvm_scan_abort_notif(struct iwl_notif_wait_data *notif_wait, | |
385 | struct iwl_rx_packet *pkt, void *data) | |
386 | { | |
387 | struct iwl_mvm *mvm = | |
388 | container_of(notif_wait, struct iwl_mvm, notif_wait); | |
389 | struct iwl_scan_complete_notif *notif; | |
390 | u32 *resp; | |
391 | ||
392 | switch (pkt->hdr.cmd) { | |
393 | case SCAN_ABORT_CMD: | |
394 | resp = (void *)pkt->data; | |
395 | if (*resp == CAN_ABORT_STATUS) { | |
396 | IWL_DEBUG_SCAN(mvm, | |
397 | "Scan can be aborted, wait until completion\n"); | |
398 | return false; | |
399 | } | |
400 | ||
401 | IWL_DEBUG_SCAN(mvm, "Scan cannot be aborted, exit now: %d\n", | |
402 | *resp); | |
403 | return true; | |
404 | ||
405 | case SCAN_COMPLETE_NOTIFICATION: | |
406 | notif = (void *)pkt->data; | |
407 | IWL_DEBUG_SCAN(mvm, "Scan aborted: status 0x%x\n", | |
408 | notif->status); | |
409 | return true; | |
410 | ||
411 | default: | |
412 | WARN_ON(1); | |
413 | return false; | |
414 | }; | |
415 | } | |
416 | ||
417 | void iwl_mvm_cancel_scan(struct iwl_mvm *mvm) | |
418 | { | |
419 | struct iwl_notification_wait wait_scan_abort; | |
420 | static const u8 scan_abort_notif[] = { SCAN_ABORT_CMD, | |
421 | SCAN_COMPLETE_NOTIFICATION }; | |
422 | int ret; | |
423 | ||
424 | iwl_init_notification_wait(&mvm->notif_wait, &wait_scan_abort, | |
425 | scan_abort_notif, | |
426 | ARRAY_SIZE(scan_abort_notif), | |
427 | iwl_mvm_scan_abort_notif, NULL); | |
428 | ||
429 | ret = iwl_mvm_send_cmd_pdu(mvm, SCAN_ABORT_CMD, CMD_SYNC, 0, NULL); | |
430 | if (ret) { | |
431 | IWL_ERR(mvm, "Couldn't send SCAN_ABORT_CMD: %d\n", ret); | |
432 | goto out_remove_notif; | |
433 | } | |
434 | ||
435 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_scan_abort, 1 * HZ); | |
436 | if (ret) | |
437 | IWL_ERR(mvm, "%s - failed on timeout\n", __func__); | |
438 | ||
439 | return; | |
440 | ||
441 | out_remove_notif: | |
442 | iwl_remove_notification(&mvm->notif_wait, &wait_scan_abort); | |
443 | } |